• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <signal.h>
20 #include <stdint.h>
21 #include <sys/cdefs.h>
22 #include <sys/types.h>
23 
24 __BEGIN_DECLS
25 
26 // These callbacks are called in a signal handler, and thus must be async signal safe.
27 // If null, the callbacks will not be called.
28 typedef struct {
29   struct abort_msg_t* (*get_abort_message)();
30   void (*post_dump)();
31 } debuggerd_callbacks_t;
32 
33 void debuggerd_init(debuggerd_callbacks_t* callbacks);
34 
35 // DEBUGGER_ACTION_DUMP_TOMBSTONE and DEBUGGER_ACTION_DUMP_BACKTRACE are both
36 // triggered via DEBUGGER_SIGNAL. The debugger_action_t is sent via si_value
37 // using sigqueue(2) or equivalent. If no si_value is specified (e.g. if the
38 // signal is sent by kill(2)), the default behavior is to print the backtrace
39 // to the log.
40 #define DEBUGGER_SIGNAL (__SIGRTMIN + 3)
41 
debuggerd_register_handlers(struct sigaction * action)42 static void __attribute__((__unused__)) debuggerd_register_handlers(struct sigaction* action) {
43   sigaction(SIGABRT, action, nullptr);
44   sigaction(SIGBUS, action, nullptr);
45   sigaction(SIGFPE, action, nullptr);
46   sigaction(SIGILL, action, nullptr);
47   sigaction(SIGSEGV, action, nullptr);
48 #if defined(SIGSTKFLT)
49   sigaction(SIGSTKFLT, action, nullptr);
50 #endif
51   sigaction(SIGSYS, action, nullptr);
52   sigaction(SIGTRAP, action, nullptr);
53   sigaction(DEBUGGER_SIGNAL, action, nullptr);
54 }
55 
56 __END_DECLS
57