31
31
// Author: Sanjay Ghemawat
33
// Routine to extract the current stack trace.
35
#ifndef _GOOGLE_STACKTRACE_H
36
#define _GOOGLE_STACKTRACE_H
38
// Skip the most recent "skip_count" stack frames (also skips the
39
// frame generated for the "GetStackTrace" routine itself), and then
40
// record the pc values for upto the next "max_depth" frames in
41
// "result". Returns the number of values recorded in "result".
33
// Routines to extract the current stack trace. These functions are
36
#ifndef GOOGLE_STACKTRACE_H_
37
#define GOOGLE_STACKTRACE_H_
39
// Annoying stuff for windows -- makes sure clients can import these functions
40
#ifndef PERFTOOLS_DLL_DECL
42
# define PERFTOOLS_DLL_DECL __declspec(dllimport)
44
# define PERFTOOLS_DLL_DECL
49
// Skips the most recent "skip_count" stack frames (also skips the
50
// frame generated for the "GetStackFrames" routine itself), and then
51
// records the pc values for up to the next "max_depth" frames in
52
// "pcs", and the corresponding stack frame sizes in "sizes". Returns
53
// the number of values recorded in "pcs"/"sizes".
44
56
// main() { foo(); }
45
57
// foo() { bar(); }
48
// int depth = GetStackTrace(result, 10, 1);
61
// int depth = GetStackFrames(pcs, sizes, 10, 1);
51
// The GetStackTrace call will skip the frame for "bar". It will
64
// The GetStackFrames call will skip the frame for "bar". It will
52
65
// return 2 and will produce pc values that map to the following
69
// (Actually, there may be a few more entries after "main" to account for
70
// startup procedures.)
71
// And corresponding stack frame sizes will also be recorded:
74
// (Stack frame sizes of 16 above are just for illustration purposes.)
75
// Stack frame sizes of 0 or less indicate that those frame sizes couldn't
78
// This routine may return fewer stack frame entries than are
79
// available. Also note that "pcs" and "sizes" must both be non-NULL.
80
extern PERFTOOLS_DLL_DECL int GetStackFrames(void** pcs, int* sizes, int max_depth,
83
// This is similar to the GetStackFrames routine, except that it returns
84
// the stack trace only, and not the stack frame sizes as well.
90
// int depth = GetStackFrames(result, 10, 1);
56
// (Actually, there may be a few more entries after "main" to account for
57
// startup procedures.)
59
// This routine currently produces non-empty stack traces only for
60
// Linux/x86 machines.
61
extern int GetStackTrace(void** result, int max_depth, int skip_count);
63
// Compute the extent of the function call stack by traversing it up.
64
// Input: "sp" is either NULL, or is a stack pointer
65
// (e.g., a value of the ebp register for x86).
66
// If "sp == NULL", the stack pointer for the current thread is implied.
68
// Stores the range of addresses covered by the specified stack
69
// in *stack_top and *stack_bottom. Returns true if successful,
70
// false on failure (e.g., an inability to walk the stack).
72
// If it returns true, *stack_top and *stack_bottom respectively correspond
73
// to the most-recetly pushed frame of the call stack
74
// and the intial frame that started the call stack.
75
// Their relative ordering as integers though
76
// depends on the underlying machine's architecture.
77
extern bool GetStackExtent(void* sp,
81
#endif /* _GOOGLE_STACKTRACE_H */
98
// "result" must not be NULL.
99
extern PERFTOOLS_DLL_DECL int GetStackTrace(void** result, int max_depth,
102
#endif /* GOOGLE_STACKTRACE_H_ */