ftmemsim-valgrind/include/pub_tool_execontext.h
Julian Seward ba2ece03b8 This commit subtly changes the meaning of the values obtained via the
stack unwind mechanism (the function VG_(record_ExeContext) et al),
clears up some associated kludges, and makes suppression matching work
more reliably.

Prior to this commit, a stack snapshot contained, at [0], the IP of
the relevant thread, and at all positions [1] and above, the return
addresses for the open calls.

When showing a snapshot to the user (in VG_(apply_StackTrace)), and
searching the stack for stack blocks (in VG_(get_data_description)), 1
is subtracted from positions [1] and above, so as to move these return
addresses back to the last byte of the calling instruction.  This
subtraction is also done even in VG_(get_StackTrace_wrk) itself, in
order to make the stack unwinding work at all.

It turns out that suppression-vs-function-name matching requires the
same hack, and sometimes failed to match suppressions that should
match, because of this self-same problem.

So the commit changes the stack unwinder itself, so that entries [1]
and above point to the last byte of the call instruction, rather than
the return address.  The associated kludges in VG_(apply_StackTrace)
and VG_(get_StackTrace_wrk) are removed, and suppression matching is
observed to work in a case where it failed before.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8818
2008-12-12 13:23:03 +00:00

118 lines
4.7 KiB
C

/*--------------------------------------------------------------------*/
/*--- ExeContexts: long-lived stack traces. pub_tool_execontext.h ---*/
/*--------------------------------------------------------------------*/
/*
This file is part of Valgrind, a dynamic binary instrumentation
framework.
Copyright (C) 2000-2008 Julian Seward
jseward@acm.org
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
The GNU General Public License is contained in the file COPYING.
*/
#ifndef __PUB_TOOL_EXECONTEXT_H
#define __PUB_TOOL_EXECONTEXT_H
// It's an abstract type.
typedef
struct _ExeContext
ExeContext;
// Resolution type used to decide how closely to compare two errors for
// equality.
typedef
enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
VgRes;
// Take a snapshot of the client's stack. Search our collection of
// ExeContexts to see if we already have it, and if not, allocate a
// new one. Either way, return a pointer to the context. Context size
// controlled by --num-callers option.
//
// This should only be used for long-lived stack traces. If you want a
// short-lived stack trace, use VG_(get_StackTrace)().
//
// If called from generated code, use VG_(get_running_tid)() to get the
// current ThreadId. If called from non-generated code, the current
// ThreadId should be passed in by the core. The initial IP value to
// use is adjusted by first_ip_delta before the stack is unwound.
// A safe value to pass is zero.
//
// See comments in pub_tool_stacktrace.h for precise definition of
// the meaning of the code addresses in the returned ExeContext.
extern
ExeContext* VG_(record_ExeContext) ( ThreadId tid, Word first_ip_delta );
// Trivial version of VG_(record_ExeContext), which just records the
// thread's current program counter but does not do any stack
// unwinding. This is useful in some rare cases when we suspect the
// stack might be outside mapped storage, and so unwinding
// might cause a segfault. In this case we can at least safely
// produce a one-element stack trace, which is better than nothing.
extern
ExeContext* VG_(record_depth_1_ExeContext)( ThreadId tid );
// Apply a function to every element in the ExeContext. The parameter 'n'
// gives the index of the passed ip. Doesn't go below main() unless
// --show-below-main=yes is set.
extern void VG_(apply_ExeContext)( void(*action)(UInt n, Addr ip),
ExeContext* ec, UInt n_ips );
// Compare two ExeContexts. Number of callers considered depends on `res':
// Vg_LowRes: 2
// Vg_MedRes: 4
// Vg_HighRes: all
extern Bool VG_(eq_ExeContext) ( VgRes res, ExeContext* e1, ExeContext* e2 );
// Print an ExeContext.
extern void VG_(pp_ExeContext) ( ExeContext* ec );
// Get the 32-bit unique reference number for this ExeContext
// (the "ExeContext Unique"). Guaranteed to be nonzero and to be a
// multiple of four (iow, the lowest two bits are guaranteed to
// be zero, so that callers can store other information there.
extern UInt VG_(get_ECU_from_ExeContext)( ExeContext* e );
// How many entries (frames) in this ExeContext?
extern Int VG_(get_ExeContext_n_ips)( ExeContext* e );
// Find the ExeContext that has the given ECU, if any.
// NOTE: very slow. Do not call often.
extern ExeContext* VG_(get_ExeContext_from_ECU)( UInt uniq );
// Make an ExeContext containing just 'a', and nothing else
ExeContext* VG_(make_depth_1_ExeContext_from_Addr)( Addr a );
// Is this a plausible-looking ECU ? Catches some obvious stupid
// cases, but does not guarantee that the ECU is really valid, that
// is, has an associated ExeContext.
static inline Bool VG_(is_plausible_ECU)( UInt ecu ) {
return (ecu > 0) && ((ecu & 3) == 0);
}
// Make an ExeContext containing exactly the specified stack frames.
ExeContext* VG_(make_ExeContext_from_StackTrace)( Addr* ips, UInt n_ips );
#endif // __PUB_TOOL_EXECONTEXT_H
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/