blob: 285e1afcd7d28e4d7a800cce41b3a80074c57909 [file] [log] [blame]
Jeff Brown053b8652012-06-06 16:25:03 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __CUTILS_DEBUGGER_H
18#define __CUTILS_DEBUGGER_H
19
Christopher Ferris9774df62015-01-15 14:47:36 -080020#include <sys/cdefs.h>
Jeff Brown053b8652012-06-06 16:25:03 -070021#include <sys/types.h>
22
Christopher Ferris9774df62015-01-15 14:47:36 -080023__BEGIN_DECLS
Jeff Brown053b8652012-06-06 16:25:03 -070024
Christopher Ferris9774df62015-01-15 14:47:36 -080025#define DEBUGGER_SOCKET_NAME "android:debuggerd"
26#define DEBUGGER32_SOCKET_NAME "android:debuggerd32"
27#define DEBUGGER64_SOCKET_NAME DEBUGGER_SOCKET_NAME
Jeff Brown053b8652012-06-06 16:25:03 -070028
29typedef enum {
30 // dump a crash
31 DEBUGGER_ACTION_CRASH,
32 // dump a tombstone file
33 DEBUGGER_ACTION_DUMP_TOMBSTONE,
34 // dump a backtrace only back to the socket
35 DEBUGGER_ACTION_DUMP_BACKTRACE,
36} debugger_action_t;
37
Christopher Ferris9774df62015-01-15 14:47:36 -080038// Make sure that all values have a fixed size so that this structure
39// is the same for 32 bit and 64 bit processes.
40// NOTE: Any changes to this structure must also be reflected in
41// bionic/linker/debugger.cpp.
42typedef struct __attribute__((packed)) {
43 int32_t action;
Jeff Brown053b8652012-06-06 16:25:03 -070044 pid_t tid;
Christopher Ferris9774df62015-01-15 14:47:36 -080045 uint64_t abort_msg_address;
Elliott Hughes855fcc32014-04-25 16:05:34 -070046 int32_t original_si_code;
Jeff Brown053b8652012-06-06 16:25:03 -070047} debugger_msg_t;
48
Jeff Brown053b8652012-06-06 16:25:03 -070049/* Dumps a process backtrace, registers, and stack to a tombstone file (requires root).
50 * Stores the tombstone path in the provided buffer.
51 * Returns 0 on success, -1 on error.
52 */
53int dump_tombstone(pid_t tid, char* pathbuf, size_t pathlen);
54
Christopher Ferrisfa41e0f2015-01-13 19:07:12 -080055/* Dumps a process backtrace, registers, and stack to a tombstone file (requires root).
56 * Stores the tombstone path in the provided buffer.
57 * If reading debugger data from debuggerd ever takes longer than timeout_secs
58 * seconds, then stop and return an error.
59 * Returns 0 on success, -1 on error.
60 */
61int dump_tombstone_timeout(pid_t tid, char* pathbuf, size_t pathlen, int timeout_secs);
62
Jeff Brown053b8652012-06-06 16:25:03 -070063/* Dumps a process backtrace only to the specified file (requires root).
64 * Returns 0 on success, -1 on error.
65 */
66int dump_backtrace_to_file(pid_t tid, int fd);
67
Christopher Ferrisfa41e0f2015-01-13 19:07:12 -080068/* Dumps a process backtrace only to the specified file (requires root).
69 * If reading debugger data from debuggerd ever takes longer than timeout_secs
70 * seconds, then stop and return an error.
71 * Returns 0 on success, -1 on error.
72 */
73int dump_backtrace_to_file_timeout(pid_t tid, int fd, int timeout_secs);
74
Christopher Ferris9774df62015-01-15 14:47:36 -080075__END_DECLS
Jeff Brown053b8652012-06-06 16:25:03 -070076
77#endif /* __CUTILS_DEBUGGER_H */