• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdbool.h>
22 #include <sys/types.h>
23 
24 #include <string>
25 
26 #include <backtrace/Backtrace.h>
27 
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"
33 #elif defined(__mips__) && !defined(__LP64__)
34 #define ABI_STRING "mips"
35 #elif defined(__mips__) && defined(__LP64__)
36 #define ABI_STRING "mips64"
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 
46 struct log_t{
47     // Tombstone file descriptor.
48     int tfd;
49     // Data to be sent to the Activity Manager.
50     std::string* amfd_data;
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;
55     // logd daemon crash, can block asking for logcat data, allow suppression.
56     bool should_retrieve_logcat;
57 
log_tlog_t58     log_t()
59         : tfd(-1), amfd_data(nullptr), crashed_tid(-1), current_tid(-1),
60           should_retrieve_logcat(true) {}
61 };
62 
63 // List of types of logs to simplify the logging decision in _LOG
64 enum logtype {
65   HEADER,
66   THREAD,
67   REGISTERS,
68   FP_REGISTERS,
69   BACKTRACE,
70   MAPS,
71   MEMORY,
72   STACK,
73   LOGS
74 };
75 
76 // Log information onto the tombstone.
77 void _LOG(log_t* log, logtype ltype, const char *fmt, ...)
78         __attribute__ ((format(printf, 3, 4)));
79 
80 int wait_for_signal(pid_t tid, int* total_sleep_time_usec);
81 
82 void dump_memory(log_t* log, Backtrace* backtrace, uintptr_t addr, const char* fmt, ...);
83 
84 #endif // _DEBUGGERD_UTILITY_H
85