1053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown/*
2053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * Copyright (C) 2012 The Android Open Source Project
3053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown *
4053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * Licensed under the Apache License, Version 2.0 (the "License");
5053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * you may not use this file except in compliance with the License.
6053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * You may obtain a copy of the License at
7053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown *
8053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown *      http://www.apache.org/licenses/LICENSE-2.0
9053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown *
10053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * Unless required by applicable law or agreed to in writing, software
11053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * distributed under the License is distributed on an "AS IS" BASIS,
12053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * See the License for the specific language governing permissions and
14053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * limitations under the License.
15053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown */
16053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
17053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown#ifndef __CUTILS_DEBUGGER_H
18053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown#define __CUTILS_DEBUGGER_H
19053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
20053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown#include <sys/types.h>
21053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
22053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown#ifdef __cplusplus
23053b865412d1982ad1dc0e840898d82527deeb99Jeff Brownextern "C" {
24053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown#endif
25053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
26053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown#define DEBUGGER_SOCKET_NAME "android:debuggerd"
27053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
28053b865412d1982ad1dc0e840898d82527deeb99Jeff Browntypedef enum {
29053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    // dump a crash
30053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    DEBUGGER_ACTION_CRASH,
31053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    // dump a tombstone file
32053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    DEBUGGER_ACTION_DUMP_TOMBSTONE,
33053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    // dump a backtrace only back to the socket
34053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    DEBUGGER_ACTION_DUMP_BACKTRACE,
35053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown} debugger_action_t;
36053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
37053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown/* message sent over the socket */
38053b865412d1982ad1dc0e840898d82527deeb99Jeff Browntypedef struct {
39053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    debugger_action_t action;
40053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown    pid_t tid;
41053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown} debugger_msg_t;
42053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
43053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown/* Dumps a process backtrace, registers, and stack to a tombstone file (requires root).
44053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * Stores the tombstone path in the provided buffer.
45053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * Returns 0 on success, -1 on error.
46053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown */
47053b865412d1982ad1dc0e840898d82527deeb99Jeff Brownint dump_tombstone(pid_t tid, char* pathbuf, size_t pathlen);
48053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
49053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown/* Dumps a process backtrace only to the specified file (requires root).
50053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown * Returns 0 on success, -1 on error.
51053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown */
52053b865412d1982ad1dc0e840898d82527deeb99Jeff Brownint dump_backtrace_to_file(pid_t tid, int fd);
53053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
54053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown#ifdef __cplusplus
55053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown}
56053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown#endif
57053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown
58053b865412d1982ad1dc0e840898d82527deeb99Jeff Brown#endif /* __CUTILS_DEBUGGER_H */
59