blob: 164615ce2b3b524747adc714a6046988deb60a1e [file] [log] [blame]
njnd01fef72005-03-25 23:35:48 +00001/*--------------------------------------------------------------------*/
2/*--- ExeContexts: long-lived stack traces. pub_tool_execontext.h ---*/
3/*--------------------------------------------------------------------*/
4
5/*
6 This file is part of Valgrind, a dynamic binary instrumentation
7 framework.
8
sewardj4d474d02008-02-11 11:34:59 +00009 Copyright (C) 2000-2008 Julian Seward
njnd01fef72005-03-25 23:35:48 +000010 jseward@acm.org
11
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 02111-1307, USA.
26
27 The GNU General Public License is contained in the file COPYING.
28*/
29
30#ifndef __PUB_TOOL_EXECONTEXT_H
31#define __PUB_TOOL_EXECONTEXT_H
32
33// It's an abstract type.
34typedef
35 struct _ExeContext
36 ExeContext;
37
38// Resolution type used to decide how closely to compare two errors for
39// equality.
40typedef
41 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
42 VgRes;
43
44// Take a snapshot of the client's stack. Search our collection of
45// ExeContexts to see if we already have it, and if not, allocate a
46// new one. Either way, return a pointer to the context. Context size
47// controlled by --num-callers option.
48//
49// This should only be used for long-lived stack traces. If you want a
50// short-lived stack trace, use VG_(get_StackTrace)().
51//
52// If called from generated code, use VG_(get_running_tid)() to get the
53// current ThreadId. If called from non-generated code, the current
sewardj39f34232007-11-09 23:02:28 +000054// ThreadId should be passed in by the core. The initial IP value to
55// use is adjusted by first_ip_delta before the stack is unwound.
56// A safe value to pass is zero.
57extern
58ExeContext* VG_(record_ExeContext) ( ThreadId tid, Word first_ip_delta );
njnd01fef72005-03-25 23:35:48 +000059
sewardj3059d272007-12-21 01:24:59 +000060// Trivial version of VG_(record_ExeContext), which just records the
61// thread's current program counter but does not do any stack
62// unwinding. This is useful in some rare cases when we suspect the
63// stack might be outside mapped storage, and so unwinding
64// might cause a segfault. In this case we can at least safely
65// produce a one-element stack trace, which is better than nothing.
66extern
67ExeContext* VG_(record_depth_1_ExeContext)( ThreadId tid );
68
njnd01fef72005-03-25 23:35:48 +000069// Apply a function to every element in the ExeContext. The parameter 'n'
70// gives the index of the passed ip. Doesn't go below main() unless
71// --show-below-main=yes is set.
72extern void VG_(apply_ExeContext)( void(*action)(UInt n, Addr ip),
73 ExeContext* ec, UInt n_ips );
74
75// Compare two ExeContexts. Number of callers considered depends on `res':
76// Vg_LowRes: 2
77// Vg_MedRes: 4
78// Vg_HighRes: all
79extern Bool VG_(eq_ExeContext) ( VgRes res, ExeContext* e1, ExeContext* e2 );
80
81// Print an ExeContext.
82extern void VG_(pp_ExeContext) ( ExeContext* ec );
83
sewardj7cf4e6b2008-05-01 20:24:26 +000084// Get the 32-bit unique reference number for this ExeContext
85// (the "ExeContext Unique"). Guaranteed to be nonzero and to be a
86// multiple of four (iow, the lowest two bits are guaranteed to
87// be zero, so that callers can store other information there.
88extern UInt VG_(get_ECU_from_ExeContext)( ExeContext* e );
89
90// How many entries (frames) in this ExeContext?
91extern Int VG_(get_ExeContext_n_ips)( ExeContext* e );
92
93// Find the ExeContext that has the given ECU, if any.
94// NOTE: very slow. Do not call often.
95extern ExeContext* VG_(get_ExeContext_from_ECU)( UInt uniq );
96
97// Make an ExeContext containing just 'a', and nothing else
98ExeContext* VG_(make_depth_1_ExeContext_from_Addr)( Addr a );
99
100// Is this a plausible-looking ECU ? Catches some obvious stupid
101// cases, but does not guarantee that the ECU is really valid, that
102// is, has an associated ExeContext.
103static inline Bool VG_(is_plausible_ECU)( UInt ecu ) {
104 return (ecu > 0) && ((ecu & 3) == 0);
105}
106
107
njnd01fef72005-03-25 23:35:48 +0000108#endif // __PUB_TOOL_EXECONTEXT_H
109
110/*--------------------------------------------------------------------*/
111/*--- end ---*/
112/*--------------------------------------------------------------------*/