1dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/* system/debuggerd/utility.h
2dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
3dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** Copyright 2008, The Android Open Source Project
4dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
5aae5d437556d877f2a198601394ba8ea7a559a70Elliott Hughes** Licensed under the Apache License, Version 2.0 (the "License");
6aae5d437556d877f2a198601394ba8ea7a559a70Elliott Hughes** you may not use this file except in compliance with the License.
7aae5d437556d877f2a198601394ba8ea7a559a70Elliott Hughes** You may obtain a copy of the License at
8dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
9aae5d437556d877f2a198601394ba8ea7a559a70Elliott Hughes**     http://www.apache.org/licenses/LICENSE-2.0
10dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
11aae5d437556d877f2a198601394ba8ea7a559a70Elliott Hughes** Unless required by applicable law or agreed to in writing, software
12aae5d437556d877f2a198601394ba8ea7a559a70Elliott Hughes** distributed under the License is distributed on an "AS IS" BASIS,
13aae5d437556d877f2a198601394ba8ea7a559a70Elliott Hughes** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14aae5d437556d877f2a198601394ba8ea7a559a70Elliott Hughes** See the License for the specific language governing permissions and
15dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** limitations under the License.
16dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project*/
17dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
1813e715b491e876865e752a3a69dd6f347049a488Jeff Brown#ifndef _DEBUGGERD_UTILITY_H
1913e715b491e876865e752a3a69dd6f347049a488Jeff Brown#define _DEBUGGERD_UTILITY_H
20dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
21dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <stdbool.h>
22c6c194ced095df5e777b8fa24527ebd29c8fef54Pavel Chupin#include <sys/types.h>
23053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
2480f596984e3a941353a7d179efdf86ff0181d412Michael Wright// Figure out the abi based on defined macros.
2580f596984e3a941353a7d179efdf86ff0181d412Michael Wright#if defined(__arm__)
2680f596984e3a941353a7d179efdf86ff0181d412Michael Wright#define ABI_STRING "arm"
2780f596984e3a941353a7d179efdf86ff0181d412Michael Wright#elif defined(__aarch64__)
2880f596984e3a941353a7d179efdf86ff0181d412Michael Wright#define ABI_STRING "arm64"
2980f596984e3a941353a7d179efdf86ff0181d412Michael Wright#elif defined(__mips__)
3080f596984e3a941353a7d179efdf86ff0181d412Michael Wright#define ABI_STRING "mips"
3180f596984e3a941353a7d179efdf86ff0181d412Michael Wright#elif defined(__i386__)
3280f596984e3a941353a7d179efdf86ff0181d412Michael Wright#define ABI_STRING "x86"
3380f596984e3a941353a7d179efdf86ff0181d412Michael Wright#elif defined(__x86_64__)
3480f596984e3a941353a7d179efdf86ff0181d412Michael Wright#define ABI_STRING "x86_64"
3580f596984e3a941353a7d179efdf86ff0181d412Michael Wright#else
3680f596984e3a941353a7d179efdf86ff0181d412Michael Wright#error "Unsupported ABI"
3780f596984e3a941353a7d179efdf86ff0181d412Michael Wright#endif
3880f596984e3a941353a7d179efdf86ff0181d412Michael Wright
3980f596984e3a941353a7d179efdf86ff0181d412Michael Wright
40166cfe68c3b0212f8e9714a0acd470d488817093Brigid Smithstruct log_t{
41053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    /* tombstone file descriptor */
42053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    int tfd;
43ded2e5acfcf0c705f08577d0ccb720bd5037f4baChristopher Tate    /* Activity Manager socket file descriptor */
44ded2e5acfcf0c705f08577d0ccb720bd5037f4baChristopher Tate    int amfd;
4562ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith    // The tid of the thread that crashed.
4662ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith    pid_t crashed_tid;
4762ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith    // The tid of the thread we are currently working with.
4862ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith    pid_t current_tid;
492f2e79de0c5cdf5494a54b44b8bee24c5cf2851dMark Salyzyn    // logd daemon crash, can block asking for logcat data, allow suppression.
502f2e79de0c5cdf5494a54b44b8bee24c5cf2851dMark Salyzyn    bool should_retrieve_logcat;
51166cfe68c3b0212f8e9714a0acd470d488817093Brigid Smith
52166cfe68c3b0212f8e9714a0acd470d488817093Brigid Smith    log_t()
532f2e79de0c5cdf5494a54b44b8bee24c5cf2851dMark Salyzyn        : tfd(-1), amfd(-1), crashed_tid(-1), current_tid(-1), should_retrieve_logcat(true) {}
54166cfe68c3b0212f8e9714a0acd470d488817093Brigid Smith};
55dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
5662ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith// List of types of logs to simplify the logging decision in _LOG
5762ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smithenum logtype {
5862ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith  ERROR,
5962ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith  HEADER,
6062ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith  THREAD,
6162ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith  REGISTERS,
62aae5d437556d877f2a198601394ba8ea7a559a70Elliott Hughes  FP_REGISTERS,
6362ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith  BACKTRACE,
6462ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith  MAPS,
6562ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith  MEMORY,
6662ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith  STACK,
6762ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith  LOGS
6862ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith};
6962ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smith
7084ddb34a3af77dbe490aaa07b738bbfd7109d5baChristopher Ferris// Log information onto the tombstone.
7162ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smithvoid _LOG(log_t* log, logtype ltype, const char *fmt, ...)
7213e715b491e876865e752a3a69dd6f347049a488Jeff Brown        __attribute__ ((format(printf, 3, 4)));
73136dcc5ce628a1ba600a6818e5cb24d5f15eb016Andy McFadden
7484ddb34a3af77dbe490aaa07b738bbfd7109d5baChristopher Ferrisint wait_for_sigstop(pid_t, int*, bool*);
7513e715b491e876865e752a3a69dd6f347049a488Jeff Brown
7662ba489ba00a2689d4e257bc178cff87495f99d7Brigid Smithvoid dump_memory(log_t* log, pid_t tid, uintptr_t addr);
774bb477205a2446c3ba9db8df0b0446173065d9ebKévin PETIT
7813e715b491e876865e752a3a69dd6f347049a488Jeff Brown#endif // _DEBUGGERD_UTILITY_H
79