blob: 98419629f0e181bf601d9749a840a91bbb3eec46 [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
Elliott Hughesed398002017-06-21 14:41:24 -07009 Copyright (C) 2000-2017 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
florian535fb1b2013-09-15 13:54:34 +000033#include "pub_tool_basics.h" // ThreadID
34
njnd01fef72005-03-25 23:35:48 +000035// It's an abstract type.
36typedef
37 struct _ExeContext
38 ExeContext;
39
40// Resolution type used to decide how closely to compare two errors for
41// equality.
42typedef
43 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
44 VgRes;
45
46// Take a snapshot of the client's stack. Search our collection of
47// ExeContexts to see if we already have it, and if not, allocate a
48// new one. Either way, return a pointer to the context. Context size
49// controlled by --num-callers option.
50//
51// This should only be used for long-lived stack traces. If you want a
52// short-lived stack trace, use VG_(get_StackTrace)().
53//
54// If called from generated code, use VG_(get_running_tid)() to get the
55// current ThreadId. If called from non-generated code, the current
sewardj39f34232007-11-09 23:02:28 +000056// ThreadId should be passed in by the core. The initial IP value to
57// use is adjusted by first_ip_delta before the stack is unwound.
58// A safe value to pass is zero.
sewardjb1ae15d2008-12-12 13:23:03 +000059//
60// See comments in pub_tool_stacktrace.h for precise definition of
61// the meaning of the code addresses in the returned ExeContext.
sewardj39f34232007-11-09 23:02:28 +000062extern
63ExeContext* VG_(record_ExeContext) ( ThreadId tid, Word first_ip_delta );
njnd01fef72005-03-25 23:35:48 +000064
sewardj3059d272007-12-21 01:24:59 +000065// Trivial version of VG_(record_ExeContext), which just records the
66// thread's current program counter but does not do any stack
67// unwinding. This is useful in some rare cases when we suspect the
68// stack might be outside mapped storage, and so unwinding
69// might cause a segfault. In this case we can at least safely
70// produce a one-element stack trace, which is better than nothing.
71extern
florianbb4f5da2012-07-23 15:40:41 +000072ExeContext* VG_(record_depth_1_ExeContext)(ThreadId tid, Word first_ip_delta);
sewardj3059d272007-12-21 01:24:59 +000073
njnd01fef72005-03-25 23:35:48 +000074// Apply a function to every element in the ExeContext. The parameter 'n'
75// gives the index of the passed ip. Doesn't go below main() unless
76// --show-below-main=yes is set.
77extern void VG_(apply_ExeContext)( void(*action)(UInt n, Addr ip),
78 ExeContext* ec, UInt n_ips );
79
80// Compare two ExeContexts. Number of callers considered depends on `res':
81// Vg_LowRes: 2
82// Vg_MedRes: 4
83// Vg_HighRes: all
florian518850b2014-10-22 22:25:30 +000084extern Bool VG_(eq_ExeContext) ( VgRes res, const ExeContext* e1,
85 const ExeContext* e2 );
njnd01fef72005-03-25 23:35:48 +000086
87// Print an ExeContext.
88extern void VG_(pp_ExeContext) ( ExeContext* ec );
89
sewardj7cf4e6b2008-05-01 20:24:26 +000090// Get the 32-bit unique reference number for this ExeContext
91// (the "ExeContext Unique"). Guaranteed to be nonzero and to be a
92// multiple of four (iow, the lowest two bits are guaranteed to
93// be zero, so that callers can store other information there.
florian518850b2014-10-22 22:25:30 +000094extern UInt VG_(get_ECU_from_ExeContext)( const ExeContext* e );
sewardj7cf4e6b2008-05-01 20:24:26 +000095
96// How many entries (frames) in this ExeContext?
florian518850b2014-10-22 22:25:30 +000097extern Int VG_(get_ExeContext_n_ips)( const ExeContext* e );
sewardj7cf4e6b2008-05-01 20:24:26 +000098
99// Find the ExeContext that has the given ECU, if any.
100// NOTE: very slow. Do not call often.
101extern ExeContext* VG_(get_ExeContext_from_ECU)( UInt uniq );
102
103// Make an ExeContext containing just 'a', and nothing else
104ExeContext* VG_(make_depth_1_ExeContext_from_Addr)( Addr a );
105
106// Is this a plausible-looking ECU ? Catches some obvious stupid
107// cases, but does not guarantee that the ECU is really valid, that
108// is, has an associated ExeContext.
109static inline Bool VG_(is_plausible_ECU)( UInt ecu ) {
110 return (ecu > 0) && ((ecu & 3) == 0);
111}
112
sewardjf98e1c02008-10-25 16:22:41 +0000113// Make an ExeContext containing exactly the specified stack frames.
florian518850b2014-10-22 22:25:30 +0000114ExeContext* VG_(make_ExeContext_from_StackTrace)( const Addr* ips, UInt n_ips );
sewardj7cf4e6b2008-05-01 20:24:26 +0000115
philippe8617b5b2013-01-12 19:53:08 +0000116// Returns the "null" exe context. The null execontext is an artificial
117// exe context, with a stack trace made of one Addr (the NULL address).
118extern
119ExeContext* VG_(null_ExeContext) (void);
120
njnd01fef72005-03-25 23:35:48 +0000121#endif // __PUB_TOOL_EXECONTEXT_H
122
123/*--------------------------------------------------------------------*/
124/*--- end ---*/
125/*--------------------------------------------------------------------*/