blob: 5bb065c6c3870657aa26140da6cc7de1d0bcbb31 [file] [log] [blame]
The Android Open Source Project9f65adf2009-02-10 15:43:56 -08001/*
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
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070029#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
41void notify_gdb_of_libraries();
42
43void debugger_signal_handler(int n)
44{
45 unsigned tid;
46 int s;
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080047
48 /* avoid picking up GC interrupts */
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070049 signal(SIGUSR1, SIG_IGN);
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080050
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070051 tid = gettid();
The Android Open Source Project9f65adf2009-02-10 15:43:56 -080052 s = socket_local_client("android:debuggerd",
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070053 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080054
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070055 if(s >= 0) {
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080056 /* 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 */
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070061 write(s, &tid, sizeof(unsigned));
62
63 read(s, &tid, 1);
64 notify_gdb_of_libraries();
65 close(s);
66 }
67
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080068 /* remove our net so we fault for real when we return */
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070069 signal(n, SIG_IGN);
70}
71
72void 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);
The Android Open Source Project9f65adf2009-02-10 15:43:56 -080080 signal(SIGPIPE, debugger_signal_handler);
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070081}