|
From: <sv...@va...> - 2005-08-11 00:47:20
|
Author: njn
Date: 2005-08-11 01:47:10 +0100 (Thu, 11 Aug 2005)
New Revision: 4379
Log:
Get rid of some stupidity: =20
- Added some useful hash table functions (vanilla lookup() and remove()).
[Actually, I accidentally added them with my previous commit]
=20
Replaced various simple uses of VG_(HT_get_node) with these new functio=
ns.=20
- Passing record_freemismatch_error() the MAC_Chunk of the freed heap blo=
ck.
So now we don't need to call describe_addr() to re-find that block, whi=
ch
means that we can remove the MAC_Chunk from the malloc_list earlier, ra=
ther
than having to do a lookup and then later remove it with the stupid rem=
oval
handle returned by VG_(HT_get_node)().
Modified:
trunk/cachegrind/cg_main.c
trunk/memcheck/mac_malloc_wrappers.c
trunk/memcheck/mac_shared.c
trunk/memcheck/mac_shared.h
trunk/memcheck/mc_main.c
Modified: trunk/cachegrind/cg_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/cachegrind/cg_main.c 2005-08-11 00:06:36 UTC (rev 4378)
+++ trunk/cachegrind/cg_main.c 2005-08-11 00:47:10 UTC (rev 4379)
@@ -358,10 +358,9 @@
static
BB_info* get_BB_info(IRBB* bbIn, Addr origAddr, Bool* bbSeenBefore)
{
- Int i, n_instrs;
- IRStmt* st;
- BB_info* bbInfo;
- VgHashNode** dummy;
+ Int i, n_instrs;
+ IRStmt* st;
+ BB_info* bbInfo;
=20
// Count number of original instrs in BB
n_instrs =3D 0;
@@ -371,7 +370,7 @@
}
=20
// Get the BB_info
- bbInfo =3D (BB_info*)VG_(HT_get_node)(instr_info_table, origAddr, &du=
mmy);
+ bbInfo =3D (BB_info*)VG_(HT_lookup)(instr_info_table, origAddr);
*bbSeenBefore =3D ( NULL =3D=3D bbInfo ? False : True );
if (*bbSeenBefore) {
// BB must have been translated before, but flushed from the TT
@@ -1078,15 +1077,13 @@
// Called when a translation is invalidated due to code unloading.
static void cg_discard_basic_block_info ( Addr a, SizeT size )
{
- VgHashNode** prev_next_ptr;
VgHashNode* bbInfo;
=20
if (0) VG_(printf)( "discard_basic_block_info: %p, %llu\n", a, (ULong=
)size);
=20
// Get BB info, remove from table, free BB info. Simple!
- bbInfo =3D VG_(HT_get_node)(instr_info_table, a, &prev_next_ptr);
+ bbInfo =3D VG_(HT_remove)(instr_info_table, a);
tl_assert(NULL !=3D bbInfo);
- *prev_next_ptr =3D bbInfo->next;
VG_(free)(bbInfo);
}
=20
Modified: trunk/memcheck/mac_malloc_wrappers.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/mac_malloc_wrappers.c 2005-08-11 00:06:36 UTC (rev 437=
8)
+++ trunk/memcheck/mac_malloc_wrappers.c 2005-08-11 00:47:10 UTC (rev 437=
9)
@@ -295,22 +295,21 @@
/* Record where freed */
mc->where =3D VG_(record_ExeContext) ( tid );
add_to_freed_queue ( mc );
- } else
+ } else {
VG_(free) ( mc );
+ }
}
=20
__inline__
void MAC_(handle_free) ( ThreadId tid, Addr p, UInt rzB, MAC_AllocKind k=
ind )
{
MAC_Chunk* mc;
- MAC_Chunk** prev_chunks_next_ptr;
=20
VGP_PUSHCC(VgpCliMalloc);
=20
cmalloc_n_frees++;
=20
- mc =3D (MAC_Chunk*)VG_(HT_get_node) ( MAC_(malloc_list), (UWord)p,
- (void*)&prev_chunks_next_ptr );
+ mc =3D (MAC_Chunk*)VG_(HT_remove) ( MAC_(malloc_list), (UWord)p );
if (mc =3D=3D NULL) {
MAC_(record_free_error) ( tid, p );
VGP_POPCC(VgpCliMalloc);
@@ -319,14 +318,9 @@
=20
/* check if its a matching free() / delete / delete [] */
if (kind !=3D mc->allockind) {
- MAC_(record_freemismatch_error) ( tid, p );
+ MAC_(record_freemismatch_error) ( tid, p, mc );
}
=20
- /* Remove mc from the malloclist using prev_chunks_next_ptr to
- avoid repeating the hash table lookup. Can't remove until at leas=
t
- after free_mismatch errors are done because they use
- describe_addr() which looks for it in malloclist. */
- *prev_chunks_next_ptr =3D mc->next;
die_and_free_mem ( tid, mc, rzB );
=20
VGP_POPCC(VgpCliMalloc);
@@ -378,7 +372,7 @@
/* check if its a matching free() / delete / delete [] */
if (MAC_AllocMalloc !=3D mc->allockind) {
/* can not realloc a range that was allocated with new or new [] *=
/
- MAC_(record_freemismatch_error) ( tid, (Addr)p );
+ MAC_(record_freemismatch_error) ( tid, (Addr)p, mc );
/* but keep going anyway */
}
=20
@@ -472,20 +466,15 @@
void MAC_(destroy_mempool)(Addr pool)
{
MAC_Mempool* mp;
- MAC_Mempool** prev_next;
=20
- mp =3D (MAC_Mempool*)VG_(HT_get_node) ( MAC_(mempool_list),
- (UWord)pool,
- (void*)&prev_next );
+ mp =3D (MAC_Mempool*)VG_(HT_remove) ( MAC_(mempool_list), (UWord)pool=
);
=20
if (mp =3D=3D NULL) {
ThreadId tid =3D VG_(get_running_tid)();
-
MAC_(record_illegal_mempool_error) ( tid, pool );
return;
}
=20
- *prev_next =3D mp->next;
VG_(HT_apply_to_all_nodes)(mp->chunks, destroy_mempool_nuke_chunk, mp=
);
VG_(HT_destruct)(mp->chunks);
=20
Modified: trunk/memcheck/mac_shared.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/mac_shared.c 2005-08-11 00:06:36 UTC (rev 4378)
+++ trunk/memcheck/mac_shared.c 2005-08-11 00:47:10 UTC (rev 4379)
@@ -475,6 +475,19 @@
return;
}
=20
+/* Describe an address as best you can, for FreeMismatch error messages.
+ By the time this is called 'ai' is already setup with all the relevan=
t
+ info. So the only thing this can do is change that to UserG if 'a' i=
s in
+ a user block, otherwise change it from 'Mallocd' to 'Freed'.
+*/
+static void describe_addr_FreeMismatch ( Addr a, AddrInfo* ai )
+{
+ /* Perhaps it's a user-def'd block ? (only check if requested, thoug=
h) */
+ if (NULL !=3D MAC_(describe_addr_supp)) {
+ (void)MAC_(describe_addr_supp)( a, ai );
+ }
+}
+
/* Is this address within some small distance below %ESP? Used only
for the --workaround-gcc296-bugs kludge. */
static Bool is_just_below_ESP( Addr esp, Addr aa )
@@ -571,13 +584,18 @@
VG_(maybe_record_error)( tid, IllegalMempoolErr, a, /*s*/NULL, &err_e=
xtra );
}
=20
-void MAC_(record_freemismatch_error) ( ThreadId tid, Addr a )
+void MAC_(record_freemismatch_error) ( ThreadId tid, Addr a, MAC_Chunk* =
mc )
{
MAC_Error err_extra;
+ AddrInfo* ai;
=20
tl_assert(VG_INVALID_THREADID !=3D tid);
MAC_(clear_MAC_Error)( &err_extra );
- err_extra.addrinfo.akind =3D Undescribed;
+ ai =3D &err_extra.addrinfo;
+ ai->akind =3D Mallocd; // Nb: not 'Freed'
+ ai->blksize =3D mc->size;
+ ai->rwoffset =3D (Int)a - (Int)mc->data;
+ ai->lastchange =3D mc->where;
VG_(maybe_record_error)( tid, FreeMismatchErr, a, /*s*/NULL, &err_ext=
ra );
}
=20
@@ -599,14 +617,21 @@
case ParamErr:
case UserErr:
case FreeErr:
- case IllegalMempoolErr:
- case FreeMismatchErr: {
+ case IllegalMempoolErr: {
MAC_Error* extra =3D VG_(get_error_extra)(err);
if (extra !=3D NULL && Undescribed =3D=3D extra->addrinfo.akind) {
describe_addr ( VG_(get_error_address)(err), &(extra->addrinfo)=
);
}
return sizeof(MAC_Error);
}
+
+ case FreeMismatchErr: {
+ MAC_Error* extra =3D VG_(get_error_extra)(err);
+ tl_assert(extra && Mallocd =3D=3D extra->addrinfo.akind);
+ describe_addr_FreeMismatch ( VG_(get_error_address)(err), &(extra-=
>addrinfo) );
+ return sizeof(MAC_Error);
+ }
+
/* Don't need to return the correct size -- LeakErrs are always shown=
with
VG_(unique_error)() so they're not copied anyway. */
case LeakErr: return 0;
Modified: trunk/memcheck/mac_shared.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/mac_shared.h 2005-08-11 00:06:36 UTC (rev 4378)
+++ trunk/memcheck/mac_shared.h 2005-08-11 00:47:10 UTC (rev 4379)
@@ -394,7 +394,8 @@
Bool isUnaddr, Char* msg );
extern void MAC_(record_jump_error) ( ThreadId tid, Addr a );
extern void MAC_(record_free_error) ( ThreadId tid, Addr a );
-extern void MAC_(record_freemismatch_error)( ThreadId tid, Addr a );
+extern void MAC_(record_freemismatch_error)( ThreadId tid, Addr a,
+ MAC_Chunk* mc);
extern void MAC_(record_overlap_error) ( ThreadId tid,=20
Char* function, OverlapExtr=
a* oe );
extern void MAC_(record_illegal_mempool_error) ( ThreadId tid, Addr pool=
);
Modified: trunk/memcheck/mc_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/mc_main.c 2005-08-11 00:06:36 UTC (rev 4378)
+++ trunk/memcheck/mc_main.c 2005-08-11 00:47:10 UTC (rev 4379)
@@ -2327,12 +2327,9 @@
continue;
// Use zero as the redzone for client blocks.
if (VG_(addr_is_in_block)(a, cgbs[i].start, cgbs[i].size, 0)) {
- MAC_Mempool **d, *mp;
-
/* OK - maybe it's a mempool, too? */
- mp =3D (MAC_Mempool*)VG_(HT_get_node)(MAC_(mempool_list),
- (UWord)cgbs[i].start,
- (void*)&d);
+ MAC_Mempool* mp =3D (MAC_Mempool*)VG_(HT_lookup)(MAC_(mempool_l=
ist),
+ (UWord)cgbs[i].s=
tart);
if(mp !=3D NULL) {
if(mp->chunks !=3D NULL) {
MAC_Chunk *mc;
|