summaryrefslogtreecommitdiffstats
path: root/linker/debugger.c
blob: 68997c57654b6e9918d64ecd7ee55a4756a9a38b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <signal.h>
#include <sys/mman.h>

#include "linker.h"

#include <sys/socket.h>
#include <cutils/sockets.h>

void notify_gdb_of_libraries();

void debugger_signal_handler(int n)
{
    unsigned tid;
    int s;
           
        /* avoid picking up GC interrupts */
    signal(SIGUSR1, SIG_IGN);
    
    tid = gettid();
    s = socket_local_client("android:debuggerd", 
            ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
    
    if(s >= 0) {
            /* debugger knows our pid from the credentials on the
            ** local socket but we need to tell it our tid.  It
            ** is paranoid and will verify that we are giving a tid
            ** that's actually in our process
            */
        write(s, &tid, sizeof(unsigned));

        read(s, &tid, 1);
        notify_gdb_of_libraries();
        close(s);
    }

        /* remove our net so we fault for real when we return */
    signal(n, SIG_IGN);
}

void debugger_init()
{
    signal(SIGILL, debugger_signal_handler);
    signal(SIGABRT, debugger_signal_handler);
    signal(SIGBUS, debugger_signal_handler);
    signal(SIGFPE, debugger_signal_handler);
    signal(SIGSEGV, debugger_signal_handler);
    signal(SIGSTKFLT, debugger_signal_handler);
}