1 /*--------------------------------------------------------------------*/
2 /*--- ExeContexts: long-lived stack traces. pub_tool_execontext.h ---*/
3 /*--------------------------------------------------------------------*/
6 This file is part of Valgrind, a dynamic binary instrumentation
9 Copyright (C) 2000-2017 Julian Seward
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.
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.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, see <http://www.gnu.org/licenses/>.
25 The GNU General Public License is contained in the file COPYING.
28 #ifndef __PUB_TOOL_EXECONTEXT_H
29 #define __PUB_TOOL_EXECONTEXT_H
31 #include "pub_tool_basics.h" // ThreadID
32 #include "pub_tool_debuginfo.h" // DiEpoch
35 /*====================================================================*/
36 /*=== ExeContext ===*/
37 /*====================================================================*/
39 // It's an abstract type.
44 // Resolution type used to decide how closely to compare two errors for
47 enum { Vg_LowRes
, Vg_MedRes
, Vg_HighRes
}
50 // Take a snapshot of the client's stack. Search our collection of
51 // ExeContexts to see if we already have it, and if not, allocate a
52 // new one. Either way, return a pointer to the context. Context size
53 // controlled by --num-callers option.
55 // This should only be used for long-lived stack traces. If you want a
56 // short-lived stack trace, use VG_(get_StackTrace)().
58 // If called from generated code, use VG_(get_running_tid)() to get the
59 // current ThreadId. If called from non-generated code, the current
60 // ThreadId should be passed in by the core. The initial IP value to
61 // use is adjusted by first_ip_delta before the stack is unwound.
62 // A safe value to pass is zero.
64 // See comments in pub_tool_stacktrace.h for precise definition of
65 // the meaning of the code addresses in the returned ExeContext.
67 ExeContext
* VG_(record_ExeContext
) ( ThreadId tid
, Word first_ip_delta
);
69 // Trivial version of VG_(record_ExeContext), which just records the
70 // thread's current program counter but does not do any stack
71 // unwinding. This is useful in some rare cases when we suspect the
72 // stack might be outside mapped storage, and so unwinding
73 // might cause a segfault. In this case we can at least safely
74 // produce a one-element stack trace, which is better than nothing.
76 ExeContext
* VG_(record_depth_1_ExeContext
)(ThreadId tid
, Word first_ip_delta
);
78 // Apply a function to every element in the ExeContext. The parameter 'n'
79 // gives the index of the passed ip. Doesn't go below main() unless
80 // --show-below-main=yes is set.
81 extern void VG_(apply_ExeContext
)(
82 void(*action
)(UInt n
, DiEpoch ep
, Addr ip
, void* opaque
),
83 void* opaque
, ExeContext
* ec
);
85 // Compare two ExeContexts. Number of callers considered depends on `res':
89 extern Bool
VG_(eq_ExeContext
) ( VgRes res
, const ExeContext
* e1
,
90 const ExeContext
* e2
);
92 // Print an ExeContext.
93 extern void VG_(pp_ExeContext
) ( ExeContext
* ec
);
95 // Get the 32-bit unique reference number for this ExeContext
96 // (the "ExeContext Unique"). Guaranteed to be nonzero and to be a
97 // multiple of four (iow, the lowest two bits are guaranteed to
98 // be zero, so that callers can store other information there.
99 extern UInt
VG_(get_ECU_from_ExeContext
)( const ExeContext
* e
);
101 // Returns the epoch in which the ips of e can be symbolised.
102 extern DiEpoch
VG_(get_ExeContext_epoch
)( const ExeContext
* e
);
104 // How many entries (frames) in this ExeContext?
105 extern Int
VG_(get_ExeContext_n_ips
)( const ExeContext
* e
);
107 // Find the ExeContext that has the given ECU, if any.
108 // NOTE: very slow. Do not call often.
109 extern ExeContext
* VG_(get_ExeContext_from_ECU
)( UInt uniq
);
111 // Make an ExeContext containing just 'a', and nothing else
112 ExeContext
* VG_(make_depth_1_ExeContext_from_Addr
)( Addr a
);
114 // Is this a plausible-looking ECU ? Catches some obvious stupid
115 // cases, but does not guarantee that the ECU is really valid, that
116 // is, has an associated ExeContext.
117 static inline Bool
VG_(is_plausible_ECU
)( UInt ecu
) {
118 return (ecu
> 0) && ((ecu
& 3) == 0);
121 // Make an ExeContext containing exactly the specified stack frames.
122 ExeContext
* VG_(make_ExeContext_from_StackTrace
)( const Addr
* ips
, UInt n_ips
);
124 // Returns the "null" exe context. The null execontext is an artificial
125 // exe context, with a stack trace made of one Addr (the NULL address).
127 ExeContext
* VG_(null_ExeContext
) (void);
129 #endif // __PUB_TOOL_EXECONTEXT_H
131 /*--------------------------------------------------------------------*/
133 /*--------------------------------------------------------------------*/