|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* Copyright (C) 2011 The Android Open Source Project
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit |
1fb8d4 |
* you may not use this file except in compliance with the License.
|
|
Packit |
1fb8d4 |
* You may obtain a copy of the License at
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
1fb8d4 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
1fb8d4 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
1fb8d4 |
* See the License for the specific language governing permissions and
|
|
Packit |
1fb8d4 |
* limitations under the License.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* A stack unwinder. */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#ifndef _CORKSCREW_BACKTRACE_H
|
|
Packit |
1fb8d4 |
#define _CORKSCREW_BACKTRACE_H
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#ifdef __cplusplus
|
|
Packit Service |
5a9772 |
extern "C"
|
|
Packit Service |
5a9772 |
{
|
|
Packit |
1fb8d4 |
#endif
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <sys/types.h>
|
|
Packit |
1fb8d4 |
#include <corkscrew/ptrace.h>
|
|
Packit |
1fb8d4 |
#include <corkscrew/map_info.h>
|
|
Packit |
1fb8d4 |
#include <corkscrew/symbol_table.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* Describes a single frame of a backtrace.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit |
1fb8d4 |
typedef struct
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
uintptr_t absolute_pc; /* absolute PC offset */
|
|
Packit Service |
5a9772 |
uintptr_t stack_top; /* top of stack for this frame */
|
|
Packit Service |
5a9772 |
size_t stack_size; /* size of this stack frame */
|
|
Packit |
1fb8d4 |
} backtrace_frame_t;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* Describes the symbols associated with a backtrace frame.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit |
1fb8d4 |
typedef struct
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
uintptr_t relative_pc; /* relative frame PC offset from the start of the library,
|
|
Packit Service |
5a9772 |
or the absolute PC if the library is unknown */
|
|
Packit |
1fb8d4 |
uintptr_t relative_symbol_addr; /* relative offset of the symbol from the start of the
|
|
Packit Service |
5a9772 |
library or 0 if the library is unknown */
|
|
Packit Service |
5a9772 |
char* map_name; /* executable or library name, or NULL if unknown */
|
|
Packit Service |
5a9772 |
char* symbol_name; /* symbol name, or NULL if unknown */
|
|
Packit Service |
5a9772 |
char* demangled_name; /* demangled symbol name, or NULL if unknown */
|
|
Packit |
1fb8d4 |
} backtrace_symbol_t;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* Unwinds the call stack for the current thread of execution.
|
|
Packit |
1fb8d4 |
* Populates the backtrace array with the program counters from the call stack.
|
|
Packit |
1fb8d4 |
* Returns the number of frames collected, or -1 if an error occurred.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit Service |
5a9772 |
ssize_t unwind_backtrace(backtrace_frame_t* backtrace, size_t ignore_depth, size_t max_depth);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* Unwinds the call stack for a thread within this process.
|
|
Packit |
1fb8d4 |
* Populates the backtrace array with the program counters from the call stack.
|
|
Packit |
1fb8d4 |
* Returns the number of frames collected, or -1 if an error occurred.
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* The task is briefly suspended while the backtrace is being collected.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit Service |
5a9772 |
ssize_t unwind_backtrace_thread(pid_t tid, backtrace_frame_t* backtrace, size_t ignore_depth,
|
|
Packit Service |
5a9772 |
size_t max_depth);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* Unwinds the call stack of a task within a remote process using ptrace().
|
|
Packit |
1fb8d4 |
* Populates the backtrace array with the program counters from the call stack.
|
|
Packit |
1fb8d4 |
* Returns the number of frames collected, or -1 if an error occurred.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit Service |
5a9772 |
ssize_t unwind_backtrace_ptrace(pid_t tid, const ptrace_context_t* context,
|
|
Packit Service |
5a9772 |
backtrace_frame_t* backtrace, size_t ignore_depth,
|
|
Packit Service |
5a9772 |
size_t max_depth);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* Gets the symbols for each frame of a backtrace.
|
|
Packit |
1fb8d4 |
* The symbols array must be big enough to hold one symbol record per frame.
|
|
Packit |
1fb8d4 |
* The symbols must later be freed using free_backtrace_symbols.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit Service |
5a9772 |
void get_backtrace_symbols(const backtrace_frame_t* backtrace, size_t frames,
|
|
Packit Service |
5a9772 |
backtrace_symbol_t* backtrace_symbols);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* Gets the symbols for each frame of a backtrace from a remote process.
|
|
Packit |
1fb8d4 |
* The symbols array must be big enough to hold one symbol record per frame.
|
|
Packit |
1fb8d4 |
* The symbols must later be freed using free_backtrace_symbols.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit Service |
5a9772 |
void get_backtrace_symbols_ptrace(const ptrace_context_t* context,
|
|
Packit Service |
5a9772 |
const backtrace_frame_t* backtrace, size_t frames,
|
|
Packit Service |
5a9772 |
backtrace_symbol_t* backtrace_symbols);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* Frees the storage associated with backtrace symbols.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit Service |
5a9772 |
void free_backtrace_symbols(backtrace_symbol_t* backtrace_symbols, size_t frames);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
enum
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
// A hint for how big to make the line buffer for format_backtrace_line
|
|
Packit |
1fb8d4 |
MAX_BACKTRACE_LINE_LENGTH = 800,
|
|
Packit |
1fb8d4 |
};
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/**
|
|
Packit |
1fb8d4 |
* Formats a line from a backtrace as a zero-terminated string into the specified buffer.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit Service |
5a9772 |
void format_backtrace_line(unsigned frameNumber, const backtrace_frame_t* frame,
|
|
Packit Service |
5a9772 |
const backtrace_symbol_t* symbol, char* buffer, size_t bufferSize);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#ifdef __cplusplus
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
#endif
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#endif // _CORKSCREW_BACKTRACE_H
|