The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <ctype.h> |
| 5 | #include <signal.h> |
| 6 | #include <sys/mman.h> |
| 7 | |
| 8 | #include "linker.h" |
| 9 | |
| 10 | #include <sys/socket.h> |
| 11 | #include <cutils/sockets.h> |
| 12 | |
| 13 | void notify_gdb_of_libraries(); |
| 14 | |
| 15 | void debugger_signal_handler(int n) |
| 16 | { |
| 17 | unsigned tid; |
| 18 | int s; |
| 19 | |
| 20 | /* avoid picking up GC interrupts */ |
| 21 | signal(SIGUSR1, SIG_IGN); |
| 22 | |
| 23 | tid = gettid(); |
| 24 | s = socket_local_client("android:debuggerd", |
| 25 | ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); |
| 26 | |
| 27 | if(s >= 0) { |
| 28 | /* debugger knows our pid from the credentials on the |
| 29 | ** local socket but we need to tell it our tid. It |
| 30 | ** is paranoid and will verify that we are giving a tid |
| 31 | ** that's actually in our process |
| 32 | */ |
| 33 | write(s, &tid, sizeof(unsigned)); |
| 34 | |
| 35 | read(s, &tid, 1); |
| 36 | notify_gdb_of_libraries(); |
| 37 | close(s); |
| 38 | } |
| 39 | |
| 40 | /* remove our net so we fault for real when we return */ |
| 41 | signal(n, SIG_IGN); |
| 42 | } |
| 43 | |
| 44 | void debugger_init() |
| 45 | { |
| 46 | signal(SIGILL, debugger_signal_handler); |
| 47 | signal(SIGABRT, debugger_signal_handler); |
| 48 | signal(SIGBUS, debugger_signal_handler); |
| 49 | signal(SIGFPE, debugger_signal_handler); |
| 50 | signal(SIGSEGV, debugger_signal_handler); |
| 51 | signal(SIGSTKFLT, debugger_signal_handler); |
| 52 | } |