The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* system/debuggerd/utility.h |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
Elliott Hughes | b40c503 | 2014-07-14 16:10:15 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 8 | ** |
Elliott Hughes | b40c503 | 2014-07-14 16:10:15 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 10 | ** |
Elliott Hughes | b40c503 | 2014-07-14 16:10:15 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 18 | #ifndef _DEBUGGERD_UTILITY_H |
| 19 | #define _DEBUGGERD_UTILITY_H |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 20 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 21 | #include <stdbool.h> |
Pavel Chupin | c6c194c | 2013-11-21 23:17:20 +0400 | [diff] [blame] | 22 | #include <sys/types.h> |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 23 | |
Christopher Ferris | 9818bd2 | 2016-05-03 16:32:13 -0700 | [diff] [blame] | 24 | #include <string> |
| 25 | |
Christopher Ferris | e8bc77e | 2015-05-22 14:26:13 -0700 | [diff] [blame] | 26 | #include <backtrace/Backtrace.h> |
| 27 | |
Michael Wright | 80f5969 | 2014-06-20 16:19:58 -0700 | [diff] [blame] | 28 | // Figure out the abi based on defined macros. |
| 29 | #if defined(__arm__) |
| 30 | #define ABI_STRING "arm" |
| 31 | #elif defined(__aarch64__) |
| 32 | #define ABI_STRING "arm64" |
Douglas Leung | 2ea9a32 | 2015-03-09 18:41:32 -0700 | [diff] [blame] | 33 | #elif defined(__mips__) && !defined(__LP64__) |
Michael Wright | 80f5969 | 2014-06-20 16:19:58 -0700 | [diff] [blame] | 34 | #define ABI_STRING "mips" |
Douglas Leung | 2ea9a32 | 2015-03-09 18:41:32 -0700 | [diff] [blame] | 35 | #elif defined(__mips__) && defined(__LP64__) |
| 36 | #define ABI_STRING "mips64" |
Michael Wright | 80f5969 | 2014-06-20 16:19:58 -0700 | [diff] [blame] | 37 | #elif defined(__i386__) |
| 38 | #define ABI_STRING "x86" |
| 39 | #elif defined(__x86_64__) |
| 40 | #define ABI_STRING "x86_64" |
| 41 | #else |
| 42 | #error "Unsupported ABI" |
| 43 | #endif |
| 44 | |
| 45 | |
Brigid Smith | c75a02f | 2014-07-17 14:52:33 -0700 | [diff] [blame] | 46 | struct log_t{ |
Christopher Ferris | 9818bd2 | 2016-05-03 16:32:13 -0700 | [diff] [blame] | 47 | // Tombstone file descriptor. |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 48 | int tfd; |
Christopher Ferris | 9818bd2 | 2016-05-03 16:32:13 -0700 | [diff] [blame] | 49 | // Data to be sent to the Activity Manager. |
| 50 | std::string* amfd_data; |
Brigid Smith | 62ba489 | 2014-06-10 11:53:08 -0700 | [diff] [blame] | 51 | // The tid of the thread that crashed. |
| 52 | pid_t crashed_tid; |
| 53 | // The tid of the thread we are currently working with. |
| 54 | pid_t current_tid; |
Mark Salyzyn | 45ae446 | 2014-07-25 12:25:48 -0700 | [diff] [blame] | 55 | // logd daemon crash, can block asking for logcat data, allow suppression. |
| 56 | bool should_retrieve_logcat; |
Brigid Smith | c75a02f | 2014-07-17 14:52:33 -0700 | [diff] [blame] | 57 | |
| 58 | log_t() |
Christopher Ferris | 9818bd2 | 2016-05-03 16:32:13 -0700 | [diff] [blame] | 59 | : tfd(-1), amfd_data(nullptr), crashed_tid(-1), current_tid(-1), |
| 60 | should_retrieve_logcat(true) {} |
Brigid Smith | c75a02f | 2014-07-17 14:52:33 -0700 | [diff] [blame] | 61 | }; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 62 | |
Brigid Smith | 62ba489 | 2014-06-10 11:53:08 -0700 | [diff] [blame] | 63 | // List of types of logs to simplify the logging decision in _LOG |
| 64 | enum logtype { |
Brigid Smith | 62ba489 | 2014-06-10 11:53:08 -0700 | [diff] [blame] | 65 | HEADER, |
| 66 | THREAD, |
| 67 | REGISTERS, |
Elliott Hughes | b40c503 | 2014-07-14 16:10:15 -0700 | [diff] [blame] | 68 | FP_REGISTERS, |
Brigid Smith | 62ba489 | 2014-06-10 11:53:08 -0700 | [diff] [blame] | 69 | BACKTRACE, |
| 70 | MAPS, |
| 71 | MEMORY, |
| 72 | STACK, |
| 73 | LOGS |
| 74 | }; |
| 75 | |
Christopher Ferris | 1072f91 | 2014-10-31 21:34:38 -0700 | [diff] [blame] | 76 | // Log information onto the tombstone. |
Brigid Smith | 62ba489 | 2014-06-10 11:53:08 -0700 | [diff] [blame] | 77 | void _LOG(log_t* log, logtype ltype, const char *fmt, ...) |
Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 78 | __attribute__ ((format(printf, 3, 4))); |
Andy McFadden | 136dcc5 | 2011-09-22 16:37:06 -0700 | [diff] [blame] | 79 | |
Josh Gao | 7c89f9e | 2016-01-13 17:57:14 -0800 | [diff] [blame] | 80 | int wait_for_signal(pid_t tid, int* total_sleep_time_usec); |
Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 81 | |
Christopher Ferris | e8bc77e | 2015-05-22 14:26:13 -0700 | [diff] [blame] | 82 | void dump_memory(log_t* log, Backtrace* backtrace, uintptr_t addr, const char* fmt, ...); |
Kévin PETIT | 4bb4772 | 2013-12-18 16:44:24 +0000 | [diff] [blame] | 83 | |
Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 84 | #endif // _DEBUGGERD_UTILITY_H |