typedef struct _BB_info BB_info;
struct _BB_info {
- Addr BB_addr; // key
+ Addr BB_addr; // key; MUST BE FIRST
Int n_instrs;
InstrInfo instrs[0];
};
/*--- Instrumentation main ---*/
/*------------------------------------------------------------*/
+// Note that origAddr is the real origAddr, not the address of the first
+// instruction in the block (they can be different due to redirection).
static
BB_info* get_BB_info(IRBB* bbIn, Addr origAddr)
{
////////////////////////////////////////////////////////////
-static IRBB* cg_instrument ( IRBB* bbIn, VexGuestLayout* layout,
- IRType gWordTy, IRType hWordTy )
+static
+IRBB* cg_instrument ( IRBB* bbIn, VexGuestLayout* layout,
+ Addr64 orig_addr_noredir, VexGuestExtents* vge,
+ IRType gWordTy, IRType hWordTy )
{
Int i, isize;
IRStmt* st;
// Set up running state and get block info
cgs.events_used = 0;
- cgs.bbInfo = get_BB_info(bbIn, (Addr)cia);
+ cgs.bbInfo = get_BB_info(bbIn, (Addr)orig_addr_noredir);
cgs.bbInfo_i = 0;
if (DEBUG_CG)
// Called when a translation is removed from the translation cache for
// any reason at all: to free up space, because the guest code was
// unmapped or modified, or for any arbitrary reason.
-static void cg_discard_basic_block_info ( VexGuestExtents vge )
+static
+void cg_discard_basic_block_info ( Addr64 orig_addr64, VexGuestExtents vge )
{
BB_info* bbInfo;
+ Addr orig_addr = (Addr)orig_addr64;
tl_assert(vge.n_used > 0);
if (DEBUG_CG)
- VG_(printf)( "discard_basic_block_info: %p, %llu\n",
+ VG_(printf)( "discard_basic_block_info: %p, %p, %llu\n",
+ (void*)(Addr)orig_addr,
(void*)(Addr)vge.base[0], (ULong)vge.len[0]);
- // Get BB info, remove from table, free BB info. Simple!
- bbInfo = VG_(OSet_Remove)(instrInfoTable, &(vge.base[0]));
+ // Get BB info, remove from table, free BB info. Simple! Note that we
+ // use orig_addr, not the first instruction address in vge.
+ bbInfo = VG_(OSet_Remove)(instrInfoTable, &orig_addr);
tl_assert(NULL != bbInfo);
VG_(OSet_FreeNode)(instrInfoTable, bbInfo);
}
CC_table = VG_(OSet_Create)(offsetof(LineCC, loc),
cmp_CodeLoc_LineCC,
VG_(malloc), VG_(free));
- instrInfoTable = VG_(OSet_Create)(offsetof(BB_info, BB_addr),
+ instrInfoTable = VG_(OSet_Create)(/*keyOff*/0,
NULL,
VG_(malloc), VG_(free));
stringTable = VG_(OSet_Create)(/*keyOff*/0,
void VG_(basic_tool_funcs)(
void(*post_clo_init)(void),
- IRBB*(*instrument)(IRBB*, VexGuestLayout*, IRType, IRType ),
+ IRBB*(*instrument)(IRBB*, VexGuestLayout*,
+ Addr64, VexGuestExtents*, IRType, IRType ),
void(*fini)(Int)
)
{
NEEDS(data_syms)
void VG_(needs_basic_block_discards)(
- void (*discard)(VexGuestExtents)
+ void (*discard)(Addr64, VexGuestExtents)
)
{
VG_(needs).basic_block_discards = True;
*/
static
-IRBB* vg_SP_update_pass ( IRBB* bb_in, VexGuestLayout* layout,
- IRType gWordTy, IRType hWordTy )
+IRBB* vg_SP_update_pass ( IRBB* bb_in,
+ VexGuestLayout* layout,
+ Addr64 orig_addr_noredir,
+ VexGuestExtents* vge,
+ IRType gWordTy,
+ IRType hWordTy )
{
Int i, j, minoff_ST, maxoff_ST, sizeof_SP, offset_SP;
IRDirty *dcall, *d;
Int debugging_verbosity,
ULong bbs_done )
{
- Addr64 redir, orig_addr0 = orig_addr;
+ Addr64 redir, orig_addr_noredir = orig_addr;
Int tmpbuf_used, verbosity, i;
Bool notrace_until_done, do_self_check;
UInt notrace_until_limit = 0;
vex_arch, &vex_archinfo,
(UChar*)ULong_to_Ptr(orig_addr),
(Addr64)orig_addr,
+ (Addr64)orig_addr_noredir,
chase_into_ok,
&vge,
tmpbuf, N_TMPBUF, &tmpbuf_used,
// If debugging, don't do anything with the translated block; we
// only did this for the debugging output produced along the way.
if (!debugging_translation) {
- // Note that we use orig_addr0, not orig_addr, which might have been
- // changed by the redirection
+ // Note that we use orig_addr_noredir, not orig_addr, which
+ // might have been changed by the redirection
VG_(add_to_transtab)( &vge,
- orig_addr0,
+ orig_addr_noredir,
(Addr)(&tmpbuf[0]),
tmpbuf_used,
do_self_check );
/* Tell the tool too. */
if (VG_(needs).basic_block_discards) {
VG_TDICT_CALL( tool_discard_basic_block_info,
+ sec->tt[i].entry,
sec->tt[i].vge );
}
} else {
/* Tell the tool too. */
if (VG_(needs).basic_block_discards) {
VG_TDICT_CALL( tool_discard_basic_block_info,
+ tte->entry,
tte->vge );
}
}
// Basic functions
void (*tool_pre_clo_init) (void);
void (*tool_post_clo_init)(void);
- IRBB* (*tool_instrument) (IRBB*, VexGuestLayout*, IRType, IRType);
+ IRBB* (*tool_instrument) (IRBB*, VexGuestLayout*,
+ Addr64, VexGuestExtents*, IRType, IRType);
void (*tool_fini) (Int);
// VG_(needs).core_errors
void (*tool_print_extra_suppression_info)(Error*);
// VG_(needs).basic_block_discards
- void (*tool_discard_basic_block_info)(VexGuestExtents);
+ void (*tool_discard_basic_block_info)(Addr64, VexGuestExtents);
// VG_(needs).command_line_options
Bool (*tool_process_cmd_line_option)(Char*);
return cb;
}
#endif
-static IRBB* hg_instrument ( IRBB* bb_in, VexGuestLayout* layout,
- IRType gWordTy, IRType hWordTy )
+static
+IRBB* hg_instrument ( IRBB* bb_in, VexGuestLayout* layout,
+ Addr64 orig_addr_noredir, VexGuestExtents* vge,
+ IRType gWordTy, IRType hWordTy )
{
tl_assert(0); // Need to convert to Vex
}
// processing.
void (*post_clo_init)(void),
- // Instrument a basic block. Must be a true function, ie. the same input
- // always results in the same output, because basic blocks can be
- // retranslated. Unless you're doing something really strange...
- IRBB* (*instrument)(IRBB* bb_in, VexGuestLayout* layout,
+ // Instrument a basic block. Must be a true function, ie. the same
+ // input always results in the same output, because basic blocks
+ // can be retranslated. Unless you're doing something really
+ // strange... Note that orig_addr_noredir is not necessarily the
+ // same as the address of the first instruction in the IR, due to
+ // function redirection.
+ IRBB* (*instrument)(IRBB* bb_in, VexGuestLayout* layout,
+ Addr64 orig_addr_noredir, VexGuestExtents* vge,
IRType gWordTy, IRType hWordTy ),
// Finish up, print out any results, etc. `exitcode' is program's exit
reused for new translations. */
extern void VG_(needs_basic_block_discards) (
// Discard any information that pertains to specific translations
- // or instructions within the address range given. The "extents"
- // arg can be used in two ways.
- // - If info is being stored at a per-translation level, the first
- // address in the extents can be used to identify which translation
- // is being discarded. Each translation will be discarded exactly
- // once.
+ // or instructions within the address range given. There are two
+ // possible approaches.
+ // - If info is being stored at a per-translation level, use orig_addr
+ // to identify which translation is being discarded. Each translation
+ // will be discarded exactly once.
+ // This orig_addr will match the orig_addr which was passed to
+ // to instrument() when this translation was made. Note that orig_addr
+ // won't necessarily be the same as the first address in "extents".
// - If info is being stored at a per-instruction level, you can get
// the address range(s) being discarded by stepping through "extents".
// Note that any single instruction may belong to more than one
// translation, and so could be covered by the "extents" of more than
// one call to this function.
// Doing it the first way (as eg. Cachegrind does) is probably easier.
- void (*discard_basic_block_info)(VexGuestExtents vge)
+ void (*discard_basic_block_info)(Addr64 orig_addr, VexGuestExtents extents)
);
/* Tool defines its own command line options? */
Which gives us the right answer. And just to avoid two C calls, we fold
the basic-block-beginning call in with add_one_BB(). Phew.
*/
-static IRBB* lk_instrument(IRBB* bb_in, VexGuestLayout* layout,
- IRType gWordTy, IRType hWordTy )
+static
+IRBB* lk_instrument( IRBB* bb_in, VexGuestLayout* layout,
+ Addr64 orig_addr_noredir, VexGuestExtents* vge,
+ IRType gWordTy, IRType hWordTy )
{
IRDirty* di;
Int i;
/*--- Instrumentation ---*/
/*------------------------------------------------------------*/
-static IRBB* ms_instrument ( IRBB* bb_in, VexGuestLayout* layout,
- IRType gWordTy, IRType hWordTy )
+static
+IRBB* ms_instrument ( IRBB* bb_in, VexGuestLayout* layout,
+ Addr64 orig_addr_noredir, VexGuestExtents* vge,
+ IRType gWordTy, IRType hWordTy )
{
/* XXX Will Massif work when gWordTy != hWordTy ? */
return bb_in;
extern void MC_(helperc_MAKE_STACK_UNINIT) ( Addr base, UWord len );
/* Functions defined in mc_translate.c */
-extern IRBB* MC_(instrument) ( IRBB* bb_in, VexGuestLayout* layout,
- IRType gWordTy, IRType hWordTy );
-
+extern
+IRBB* MC_(instrument) ( IRBB* bb_in, VexGuestLayout* layout,
+ Addr64 orig_addr_noredir, VexGuestExtents* vge,
+ IRType gWordTy, IRType hWordTy );
#endif /* ndef __MC_INCLUDE_H */
IRBB* MC_(instrument) ( IRBB* bb_in, VexGuestLayout* layout,
+ Addr64 orig_addr_noredir, VexGuestExtents* vge,
IRType gWordTy, IRType hWordTy )
{
Bool verboze = False; //True;
{
}
-static IRBB* nl_instrument(IRBB* bb, VexGuestLayout* layout,
- IRType gWordTy, IRType hWordTy)
+static
+IRBB* nl_instrument(IRBB* bb, VexGuestLayout* layout,
+ Addr64 orig_addr_noredir, VexGuestExtents* vge,
+ IRType gWordTy, IRType hWordTy)
{
return bb;
}