blob: 542cf8dab945c78ae5e87a0fbbcfac0c3cea10c4 [file] [log] [blame]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001#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
13void notify_gdb_of_libraries();
14
15void debugger_signal_handler(int n)
16{
17 unsigned tid;
18 int s;
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080019
20 /* avoid picking up GC interrupts */
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070021 signal(SIGUSR1, SIG_IGN);
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080022
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070023 tid = gettid();
24 s = socket_local_client("android:debuggerd",
25 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080026
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070027 if(s >= 0) {
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080028 /* 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 */
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070033 write(s, &tid, sizeof(unsigned));
34
35 read(s, &tid, 1);
36 notify_gdb_of_libraries();
37 close(s);
38 }
39
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080040 /* remove our net so we fault for real when we return */
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070041 signal(n, SIG_IGN);
42}
43
44void 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}