blob: 49b46e81a1944e1502d6e537305a1c0f989431a6 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/* system/debuggerd/utility.h
2**
3** Copyright 2008, The Android Open Source Project
4**
Elliott Hughesb40c5032014-07-14 16:10:15 -07005** 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 Projectdd7bc332009-03-03 19:32:55 -08008**
Elliott Hughesb40c5032014-07-14 16:10:15 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080010**
Elliott Hughesb40c5032014-07-14 16:10:15 -070011** 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 Projectdd7bc332009-03-03 19:32:55 -080015** limitations under the License.
16*/
17
Jeff Brown13e715b2011-10-21 12:14:56 -070018#ifndef _DEBUGGERD_UTILITY_H
19#define _DEBUGGERD_UTILITY_H
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080020
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080021#include <stdbool.h>
Pavel Chupinc6c194c2013-11-21 23:17:20 +040022#include <sys/types.h>
Jeff Brown053b8652012-06-06 16:25:03 -070023
Michael Wright80f59692014-06-20 16:19:58 -070024// Figure out the abi based on defined macros.
25#if defined(__arm__)
26#define ABI_STRING "arm"
27#elif defined(__aarch64__)
28#define ABI_STRING "arm64"
Douglas Leung2ea9a322015-03-09 18:41:32 -070029#elif defined(__mips__) && !defined(__LP64__)
Michael Wright80f59692014-06-20 16:19:58 -070030#define ABI_STRING "mips"
Douglas Leung2ea9a322015-03-09 18:41:32 -070031#elif defined(__mips__) && defined(__LP64__)
32#define ABI_STRING "mips64"
Michael Wright80f59692014-06-20 16:19:58 -070033#elif defined(__i386__)
34#define ABI_STRING "x86"
35#elif defined(__x86_64__)
36#define ABI_STRING "x86_64"
37#else
38#error "Unsupported ABI"
39#endif
40
41
Brigid Smithc75a02f2014-07-17 14:52:33 -070042struct log_t{
Jeff Brown053b8652012-06-06 16:25:03 -070043 /* tombstone file descriptor */
44 int tfd;
Christopher Tateded2e5a2013-03-19 13:12:23 -070045 /* Activity Manager socket file descriptor */
46 int amfd;
Brigid Smith62ba4892014-06-10 11:53:08 -070047 // The tid of the thread that crashed.
48 pid_t crashed_tid;
49 // The tid of the thread we are currently working with.
50 pid_t current_tid;
Mark Salyzyn45ae4462014-07-25 12:25:48 -070051 // logd daemon crash, can block asking for logcat data, allow suppression.
52 bool should_retrieve_logcat;
Brigid Smithc75a02f2014-07-17 14:52:33 -070053
54 log_t()
Mark Salyzyn45ae4462014-07-25 12:25:48 -070055 : tfd(-1), amfd(-1), crashed_tid(-1), current_tid(-1), should_retrieve_logcat(true) {}
Brigid Smithc75a02f2014-07-17 14:52:33 -070056};
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080057
Brigid Smith62ba4892014-06-10 11:53:08 -070058// List of types of logs to simplify the logging decision in _LOG
59enum logtype {
60 ERROR,
61 HEADER,
62 THREAD,
63 REGISTERS,
Elliott Hughesb40c5032014-07-14 16:10:15 -070064 FP_REGISTERS,
Brigid Smith62ba4892014-06-10 11:53:08 -070065 BACKTRACE,
66 MAPS,
67 MEMORY,
68 STACK,
69 LOGS
70};
71
Christopher Ferris1072f912014-10-31 21:34:38 -070072// Log information onto the tombstone.
Brigid Smith62ba4892014-06-10 11:53:08 -070073void _LOG(log_t* log, logtype ltype, const char *fmt, ...)
Jeff Brown13e715b2011-10-21 12:14:56 -070074 __attribute__ ((format(printf, 3, 4)));
Andy McFadden136dcc52011-09-22 16:37:06 -070075
Christopher Ferris1072f912014-10-31 21:34:38 -070076int wait_for_sigstop(pid_t, int*, bool*);
Jeff Brown13e715b2011-10-21 12:14:56 -070077
Brigid Smith62ba4892014-06-10 11:53:08 -070078void dump_memory(log_t* log, pid_t tid, uintptr_t addr);
Kévin PETIT4bb47722013-12-18 16:44:24 +000079
Jeff Brown13e715b2011-10-21 12:14:56 -070080#endif // _DEBUGGERD_UTILITY_H