1 /* system/debuggerd/utility.h 2 ** 3 ** Copyright 2008, The Android Open Source Project 4 ** 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 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 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 15 ** limitations under the License. 16 */ 17 18 #ifndef _DEBUGGERD_UTILITY_H 19 #define _DEBUGGERD_UTILITY_H 20 21 #include <signal.h> 22 #include <stdbool.h> 23 #include <sys/types.h> 24 25 #include <string> 26 27 #include <backtrace/Backtrace.h> 28 29 // Figure out the abi based on defined macros. 30 #if defined(__arm__) 31 #define ABI_STRING "arm" 32 #elif defined(__aarch64__) 33 #define ABI_STRING "arm64" 34 #elif defined(__mips__) && !defined(__LP64__) 35 #define ABI_STRING "mips" 36 #elif defined(__mips__) && defined(__LP64__) 37 #define ABI_STRING "mips64" 38 #elif defined(__i386__) 39 #define ABI_STRING "x86" 40 #elif defined(__x86_64__) 41 #define ABI_STRING "x86_64" 42 #else 43 #error "Unsupported ABI" 44 #endif 45 46 47 struct log_t{ 48 // Tombstone file descriptor. 49 int tfd; 50 // Data to be sent to the Activity Manager. 51 std::string* amfd_data; 52 // The tid of the thread that crashed. 53 pid_t crashed_tid; 54 // The tid of the thread we are currently working with. 55 pid_t current_tid; 56 // logd daemon crash, can block asking for logcat data, allow suppression. 57 bool should_retrieve_logcat; 58 59 log_t() 60 : tfd(-1), amfd_data(nullptr), crashed_tid(-1), current_tid(-1), 61 should_retrieve_logcat(true) {} 62 }; 63 64 // List of types of logs to simplify the logging decision in _LOG 65 enum logtype { 66 HEADER, 67 THREAD, 68 REGISTERS, 69 FP_REGISTERS, 70 BACKTRACE, 71 MAPS, 72 MEMORY, 73 STACK, 74 LOGS, 75 OPEN_FILES 76 }; 77 78 // Log information onto the tombstone. 79 void _LOG(log_t* log, logtype ltype, const char *fmt, ...) 80 __attribute__ ((format(printf, 3, 4))); 81 82 bool wait_for_signal(pid_t tid, siginfo_t* siginfo); 83 84 void dump_memory(log_t* log, Backtrace* backtrace, uintptr_t addr, const char* fmt, ...); 85 86 void read_with_default(const char* path, char* buf, size_t len, const char* default_value); 87 88 #endif // _DEBUGGERD_UTILITY_H 89