• 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 <inttypes.h>
22 #include <signal.h>
23 #include <stdbool.h>
24 #include <sys/types.h>
25 
26 #include <string>
27 
28 #include <android-base/macros.h>
29 
30 struct log_t {
31   // Tombstone file descriptor.
32   int tfd;
33   // Data to be sent to the Activity Manager.
34   std::string* amfd_data;
35   // The tid of the thread that crashed.
36   pid_t crashed_tid;
37   // The tid of the thread we are currently working with.
38   pid_t current_tid;
39   // logd daemon crash, can block asking for logcat data, allow suppression.
40   bool should_retrieve_logcat;
41 
log_tlog_t42   log_t()
43       : tfd(-1),
44         amfd_data(nullptr),
45         crashed_tid(-1),
46         current_tid(-1),
47         should_retrieve_logcat(true) {}
48 };
49 
50 // List of types of logs to simplify the logging decision in _LOG
51 enum logtype {
52   HEADER,
53   THREAD,
54   REGISTERS,
55   FP_REGISTERS,
56   BACKTRACE,
57   MAPS,
58   MEMORY,
59   STACK,
60   LOGS,
61   OPEN_FILES
62 };
63 
64 #if defined(__LP64__)
65 #define PRIPTR "016" PRIx64
66 typedef uint64_t word_t;
67 #else
68 #define PRIPTR "08" PRIx64
69 typedef uint32_t word_t;
70 #endif
71 
72 // Log information onto the tombstone.
73 void _LOG(log_t* log, logtype ltype, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
74 
75 namespace unwindstack {
76 class Unwinder;
77 class Memory;
78 }
79 
80 void log_backtrace(log_t* log, unwindstack::Unwinder* unwinder, const char* prefix);
81 
82 void dump_memory(log_t* log, unwindstack::Memory* backtrace, uint64_t addr, const std::string&);
83 
84 void read_with_default(const char* path, char* buf, size_t len, const char* default_value);
85 
86 void drop_capabilities();
87 
88 bool signal_has_sender(const siginfo_t*, pid_t caller_pid);
89 bool signal_has_si_addr(const siginfo_t*);
90 void get_signal_sender(char* buf, size_t n, const siginfo_t*);
91 const char* get_signame(const siginfo_t*);
92 const char* get_sigcode(const siginfo_t*);
93 
94 #endif // _DEBUGGERD_UTILITY_H
95