1 /*--------------------------------------------------------------------*/
2 /*--- Stack traces: getting, traversing, printing. ---*/
3 /*--- tool_stacktrace.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2017 Julian Seward
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 The GNU General Public License is contained in the file COPYING.
31 #ifndef __PUB_TOOL_STACKTRACE_H
32 #define __PUB_TOOL_STACKTRACE_H
34 #include "pub_tool_basics.h" // Addr, DiEpoch
36 // The basic stack trace type: just an array of code addresses.
37 typedef Addr
* StackTrace
;
39 // Walks the stack to get instruction pointers from the top stack frames
40 // for thread 'tid'. Maximum of 'n_ips' addresses put into 'ips';
41 // 0 is the top of the stack, 1 is its caller, etc. Everything from
42 // ips[return_value] onwards is undefined and should not be read.
43 // The initial IP value to use is adjusted by first_ip_delta before
44 // the stack is unwound. A safe value to pass is zero.
46 // The specific meaning of the returned addresses is:
48 // [0] is the IP of thread 'tid'
49 // [1] points to the last byte of the call instruction that called [0].
50 // [2] points to the last byte of the call instruction that called [1].
53 // Hence ips[0 .. return_value-1] should all point to currently
54 // 'active' (in the sense of a stack of unfinished function calls)
55 // instructions. [0] points to the start of an arbitrary instruction.#
56 // [1 ..] point to the last byte of a chain of call instructions.
58 // If sps and fps are non-NULL, the corresponding frame-pointer and
59 // stack-pointer values for each frame are stored there.
61 extern UInt
VG_(get_StackTrace
) ( ThreadId tid
,
62 /*OUT*/StackTrace ips
, UInt n_ips
,
63 /*OUT*/StackTrace sps
,
64 /*OUT*/StackTrace fps
,
65 Word first_ip_delta
);
67 // Same as VG_(get_StackTrace), but applies a delta to the first SP used for
68 // unwinding the first frame.
69 extern UInt
VG_(get_StackTrace_with_deltas
)(
71 /*OUT*/StackTrace ips
, UInt n_ips
,
72 /*OUT*/StackTrace sps
,
73 /*OUT*/StackTrace fps
,
78 // Apply a function to every element in the StackTrace. The parameter 'n'
79 // gives the index of the passed ip. 'opaque' is an arbitrary pointer
80 // provided to each invocation of 'action' (a poor man's closure). 'ep' is
81 // the debuginfo epoch assumed to apply to all code addresses in the stack
82 // trace. Doesn't go below main() unless --show-below-main=yes is set.
83 extern void VG_(apply_StackTrace
)(
84 void(*action
)(UInt n
, DiEpoch ep
, Addr ip
, void* opaque
),
86 DiEpoch ep
, StackTrace ips
, UInt n_ips
89 // Print a StackTrace.
90 extern void VG_(pp_StackTrace
) ( DiEpoch ep
, StackTrace ips
, UInt n_ips
);
92 // Gets and immediately prints a StackTrace. Just a bit simpler than
93 // calling VG_(get_StackTrace)() then VG_(pp_StackTrace)().
94 extern void VG_(get_and_pp_StackTrace
) ( ThreadId tid
, UInt n_ips
);
96 #endif // __PUB_TOOL_STACKTRACE_H
98 /*--------------------------------------------------------------------*/
100 /*--------------------------------------------------------------------*/