Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | #ifndef __CUTILS_DEBUGGER_H |
| 18 | #define __CUTILS_DEBUGGER_H |
| 19 | |
| 20 | #include <sys/types.h> |
| 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Christopher Ferris | 6bcc4ac | 2014-09-12 14:44:20 -0700 | [diff] [blame] | 26 | #define DEBUGGER32_SOCKET_NAME "android:debuggerd" |
| 27 | #define DEBUGGER64_SOCKET_NAME "android:debuggerd64" |
| 28 | |
| 29 | #if defined(__LP64__) |
| 30 | #define DEBUGGER_SOCKET_NAME DEBUGGER64_SOCKET_NAME |
Elliott Hughes | e9edf7a | 2014-01-31 17:15:10 -0800 | [diff] [blame] | 31 | #else |
Christopher Ferris | 6bcc4ac | 2014-09-12 14:44:20 -0700 | [diff] [blame] | 32 | #define DEBUGGER_SOCKET_NAME DEBUGGER32_SOCKET_NAME |
Elliott Hughes | e9edf7a | 2014-01-31 17:15:10 -0800 | [diff] [blame] | 33 | #endif |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 34 | |
| 35 | typedef enum { |
| 36 | // dump a crash |
| 37 | DEBUGGER_ACTION_CRASH, |
| 38 | // dump a tombstone file |
| 39 | DEBUGGER_ACTION_DUMP_TOMBSTONE, |
| 40 | // dump a backtrace only back to the socket |
| 41 | DEBUGGER_ACTION_DUMP_BACKTRACE, |
| 42 | } debugger_action_t; |
| 43 | |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 44 | typedef struct { |
| 45 | debugger_action_t action; |
| 46 | pid_t tid; |
Elliott Hughes | 707b8bb | 2013-04-04 13:52:01 -0700 | [diff] [blame] | 47 | uintptr_t abort_msg_address; |
Elliott Hughes | 855fcc3 | 2014-04-25 16:05:34 -0700 | [diff] [blame] | 48 | int32_t original_si_code; |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 49 | } debugger_msg_t; |
| 50 | |
Christopher Ferris | 6bcc4ac | 2014-09-12 14:44:20 -0700 | [diff] [blame] | 51 | #if defined(__LP64__) |
| 52 | // For a 64 bit process to contact the 32 bit debuggerd. |
| 53 | typedef struct { |
| 54 | debugger_action_t action; |
| 55 | pid_t tid; |
| 56 | uint32_t abort_msg_address; |
| 57 | int32_t original_si_code; |
| 58 | } debugger32_msg_t; |
| 59 | #endif |
| 60 | |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 61 | /* Dumps a process backtrace, registers, and stack to a tombstone file (requires root). |
| 62 | * Stores the tombstone path in the provided buffer. |
| 63 | * Returns 0 on success, -1 on error. |
| 64 | */ |
| 65 | int dump_tombstone(pid_t tid, char* pathbuf, size_t pathlen); |
| 66 | |
Christopher Ferris | fa41e0f | 2015-01-13 19:07:12 -0800 | [diff] [blame] | 67 | /* Dumps a process backtrace, registers, and stack to a tombstone file (requires root). |
| 68 | * Stores the tombstone path in the provided buffer. |
| 69 | * If reading debugger data from debuggerd ever takes longer than timeout_secs |
| 70 | * seconds, then stop and return an error. |
| 71 | * Returns 0 on success, -1 on error. |
| 72 | */ |
| 73 | int dump_tombstone_timeout(pid_t tid, char* pathbuf, size_t pathlen, int timeout_secs); |
| 74 | |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 75 | /* Dumps a process backtrace only to the specified file (requires root). |
| 76 | * Returns 0 on success, -1 on error. |
| 77 | */ |
| 78 | int dump_backtrace_to_file(pid_t tid, int fd); |
| 79 | |
Christopher Ferris | fa41e0f | 2015-01-13 19:07:12 -0800 | [diff] [blame] | 80 | /* Dumps a process backtrace only to the specified file (requires root). |
| 81 | * If reading debugger data from debuggerd ever takes longer than timeout_secs |
| 82 | * seconds, then stop and return an error. |
| 83 | * Returns 0 on success, -1 on error. |
| 84 | */ |
| 85 | int dump_backtrace_to_file_timeout(pid_t tid, int fd, int timeout_secs); |
| 86 | |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 87 | #ifdef __cplusplus |
| 88 | } |
| 89 | #endif |
| 90 | |
| 91 | #endif /* __CUTILS_DEBUGGER_H */ |