SIGTRAP breakpoint in emulator?

684 views
Skip to first unread message

Chris Peterson

unread,
Mar 17, 2009, 9:25:22 PM3/17/09
to andro...@googlegroups.com

I'm trying to implement an assert macro that breaks into gdb, but does not call abort(). I would like to be able to continue running after the assert debugger break, which abort() will not allow me to do.

 

My Linux desktop code uses raise(SIGTRAP) and it works perfectly. But SIGTRAP on the Android emulator kills the signaling thread and *then* breaks into the debugger. I can't get a stack backtrace or continue running. I've found some web forums that say this as a known limitation of QEMU, but they don't provide any other suggestions.

 

I then tried using asm("bkpt") to break into gdb. This pauses the thread that hits the asm("bkpt"), but it does not break into gdb.

 

Are there any alternatives for implementing a software breakpoint?

 

thanks,

chris

 

 

David Turner

unread,
Mar 18, 2009, 2:05:31 PM3/18/09
to andro...@googlegroups.com
Interesting point. I can reproduce the problem with the source code below. Or more accurately, it seems that the debugger only stops the main thread, while keeping the other one running.
I have the feeling that this may be due to bad interactions between gdserver, and our version of libthread_db. We had some really curious bugs in the past due to weird things that gdbserver
does on a debugged process (e.g. putting a 32-bit ARM trap instructions on a 16-bit Thumb address -> BAAAAD :-)) so this would not surprise me.

I'll try to post something about it in about a week.

------------------ cut here ----------------------------------------------
/* Checks that if the program is debugged through gdb
 * then raise(SIGTRAP) properly interrupts the current
 * program without killing it.
 *
 * run the program with gdbserver test_sigtrap
 * then attach to it remotely, you should be
 * able to walk up the stack trace to the main function.
 */
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

int volatile x;

static void*
thread_func(void* dummy)
{
    printf("before sigtrap\n");
    raise(SIGTRAP);
    printf("after sigtrap\n");
    x = 1;
    return NULL;
}

int  main(void)
{
    pthread_t  thread;

    x = 0;
    pthread_create(&thread, NULL, thread_func, NULL);

    while (x == 0) {
        printf("tick!\n");
        sleep(3);
    }
    printf("exiting");
    return 0;
}
----------------------- cut here ------------------------
Reply all
Reply to author
Forward
0 new messages