• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <ctype.h>
33 #include <signal.h>
34 #include <sys/mman.h>
35 
36 #include "linker.h"
37 
38 #include <sys/socket.h>
39 #include <cutils/sockets.h>
40 
41 void notify_gdb_of_libraries();
42 
debugger_signal_handler(int n)43 void debugger_signal_handler(int n)
44 {
45     unsigned tid;
46     int s;
47 
48     /* avoid picking up GC interrupts */
49     signal(SIGUSR1, SIG_IGN);
50 
51     tid = gettid();
52     s = socket_local_client("android:debuggerd",
53             ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
54 
55     if(s >= 0) {
56         /* debugger knows our pid from the credentials on the
57          * local socket but we need to tell it our tid.  It
58          * is paranoid and will verify that we are giving a tid
59          * that's actually in our process
60          */
61         write(s, &tid, sizeof(unsigned));
62 
63         read(s, &tid, 1);
64         notify_gdb_of_libraries();
65         close(s);
66     }
67 
68     /* remove our net so we fault for real when we return */
69     signal(n, SIG_IGN);
70 }
71 
debugger_init()72 void debugger_init()
73 {
74     signal(SIGILL, debugger_signal_handler);
75     signal(SIGABRT, debugger_signal_handler);
76     signal(SIGBUS, debugger_signal_handler);
77     signal(SIGFPE, debugger_signal_handler);
78     signal(SIGSEGV, debugger_signal_handler);
79     signal(SIGSTKFLT, debugger_signal_handler);
80     signal(SIGPIPE, debugger_signal_handler);
81 }
82