mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 18:13:01 +00:00
Changed behaviour of VALGRIND_COUNT_LEAKS slightly. Previously, the numbers it
returned (bytes leaked, dubious, etc) were incremented for every leak check performed. So if you called VALGRIND_DO_LEAK_CHECK twice in a row, the totals would be updated twice by the same amount. This was a bit silly. So now COUNT_LEAKS just returns the numbers of bytes leaked found from the previous leak check. I even updated the docs, and changed the regression test so old version fail but the new version passes (by doing two DO_LEAK_CHECKS in a row). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1778
This commit is contained in:
parent
9a5e615c4b
commit
aca466757f
@ -1017,9 +1017,9 @@ A brief description of the available macros:
|
||||
occur.
|
||||
<p>
|
||||
<li><code>VALGRIND_COUNT_LEAKS</code>: fills in the four arguments with
|
||||
the number of bytes of memory found by all previous leak checks that
|
||||
were leaked, dubious, reachable and suppressed. Again, useful for
|
||||
test harness code.
|
||||
the number of bytes of memory found by the previous leak check to
|
||||
be leaked, dubious, reachable and suppressed. Again, useful in
|
||||
test harness code, after calling <code>VALGRIND_DO_LEAK_CHECK</code>.
|
||||
<p>
|
||||
<li><code>VALGRIND_MALLOCLIKE_BLOCK</code>: If your program manages its own
|
||||
memory instead of using the standard
|
||||
|
||||
@ -356,10 +356,10 @@ void MAC_(pp_LeakError)(void* vl, UInt n_this_record, UInt n_total_records)
|
||||
VG_(pp_ExeContext)(l->allocated_at);
|
||||
}
|
||||
|
||||
Int MAC_(total_bytes_leaked) = 0;
|
||||
Int MAC_(total_bytes_dubious) = 0;
|
||||
Int MAC_(total_bytes_reachable) = 0;
|
||||
Int MAC_(total_bytes_suppressed) = 0;
|
||||
Int MAC_(bytes_leaked) = 0;
|
||||
Int MAC_(bytes_dubious) = 0;
|
||||
Int MAC_(bytes_reachable) = 0;
|
||||
Int MAC_(bytes_suppressed) = 0;
|
||||
|
||||
/* Top level entry point to leak detector. Call here, passing in
|
||||
suitable address-validating functions (see comment at top of
|
||||
@ -376,10 +376,10 @@ void MAC_(do_detect_memory_leaks) (
|
||||
)
|
||||
{
|
||||
Int i;
|
||||
Int blocks_leaked, bytes_leaked;
|
||||
Int blocks_dubious, bytes_dubious;
|
||||
Int blocks_reachable, bytes_reachable;
|
||||
Int blocks_suppressed, bytes_suppressed;
|
||||
Int blocks_leaked;
|
||||
Int blocks_dubious;
|
||||
Int blocks_reachable;
|
||||
Int blocks_suppressed;
|
||||
Int n_lossrecords;
|
||||
UInt bytes_notified;
|
||||
Bool is_suppressed;
|
||||
@ -457,10 +457,10 @@ void MAC_(do_detect_memory_leaks) (
|
||||
}
|
||||
|
||||
/* Print out the commoned-up blocks and collect summary stats. */
|
||||
blocks_leaked = bytes_leaked = 0;
|
||||
blocks_dubious = bytes_dubious = 0;
|
||||
blocks_reachable = bytes_reachable = 0;
|
||||
blocks_suppressed = bytes_suppressed = 0;
|
||||
blocks_leaked = MAC_(bytes_leaked) = 0;
|
||||
blocks_dubious = MAC_(bytes_dubious) = 0;
|
||||
blocks_reachable = MAC_(bytes_reachable) = 0;
|
||||
blocks_suppressed = MAC_(bytes_suppressed) = 0;
|
||||
|
||||
for (i = 0; i < n_lossrecords; i++) {
|
||||
Bool print_record;
|
||||
@ -488,20 +488,20 @@ void MAC_(do_detect_memory_leaks) (
|
||||
/*allow_GDB_attach*/False, /*count_error*/False );
|
||||
|
||||
if (is_suppressed) {
|
||||
blocks_suppressed += p_min->num_blocks;
|
||||
bytes_suppressed += p_min->total_bytes;
|
||||
blocks_suppressed += p_min->num_blocks;
|
||||
MAC_(bytes_suppressed) += p_min->total_bytes;
|
||||
|
||||
} else if (Unreached == p_min->loss_mode) {
|
||||
blocks_leaked += p_min->num_blocks;
|
||||
bytes_leaked += p_min->total_bytes;
|
||||
} else if (Unreached == p_min->loss_mode) {
|
||||
blocks_leaked += p_min->num_blocks;
|
||||
MAC_(bytes_leaked) += p_min->total_bytes;
|
||||
|
||||
} else if (Interior == p_min->loss_mode) {
|
||||
blocks_dubious += p_min->num_blocks;
|
||||
bytes_dubious += p_min->total_bytes;
|
||||
} else if (Interior == p_min->loss_mode) {
|
||||
blocks_dubious += p_min->num_blocks;
|
||||
MAC_(bytes_dubious) += p_min->total_bytes;
|
||||
|
||||
} else if (Proper == p_min->loss_mode) {
|
||||
blocks_reachable += p_min->num_blocks;
|
||||
bytes_reachable += p_min->total_bytes;
|
||||
} else if (Proper == p_min->loss_mode) {
|
||||
blocks_reachable += p_min->num_blocks;
|
||||
MAC_(bytes_reachable) += p_min->total_bytes;
|
||||
|
||||
} else {
|
||||
VG_(skin_panic)("generic_detect_memory_leaks: unknown loss mode");
|
||||
@ -512,13 +512,13 @@ void MAC_(do_detect_memory_leaks) (
|
||||
VG_(message)(Vg_UserMsg, "");
|
||||
VG_(message)(Vg_UserMsg, "LEAK SUMMARY:");
|
||||
VG_(message)(Vg_UserMsg, " definitely lost: %d bytes in %d blocks.",
|
||||
bytes_leaked, blocks_leaked );
|
||||
MAC_(bytes_leaked), blocks_leaked );
|
||||
VG_(message)(Vg_UserMsg, " possibly lost: %d bytes in %d blocks.",
|
||||
bytes_dubious, blocks_dubious );
|
||||
MAC_(bytes_dubious), blocks_dubious );
|
||||
VG_(message)(Vg_UserMsg, " still reachable: %d bytes in %d blocks.",
|
||||
bytes_reachable, blocks_reachable );
|
||||
MAC_(bytes_reachable), blocks_reachable );
|
||||
VG_(message)(Vg_UserMsg, " suppressed: %d bytes in %d blocks.",
|
||||
bytes_suppressed, blocks_suppressed );
|
||||
MAC_(bytes_suppressed), blocks_suppressed );
|
||||
if (!MAC_(clo_show_reachable)) {
|
||||
VG_(message)(Vg_UserMsg,
|
||||
"Reachable blocks (those to which a pointer was found) are not shown.");
|
||||
@ -527,11 +527,6 @@ void MAC_(do_detect_memory_leaks) (
|
||||
}
|
||||
VG_(message)(Vg_UserMsg, "");
|
||||
|
||||
MAC_(total_bytes_leaked) += bytes_leaked;
|
||||
MAC_(total_bytes_dubious) += bytes_dubious;
|
||||
MAC_(total_bytes_reachable) += bytes_reachable;
|
||||
MAC_(total_bytes_suppressed) += bytes_suppressed;
|
||||
|
||||
VG_(free) ( lc_shadows );
|
||||
VG_(free) ( lc_reachedness );
|
||||
}
|
||||
|
||||
@ -801,10 +801,12 @@ Bool MAC_(handle_common_client_requests)(ThreadState* tst, UInt* arg,
|
||||
switch (arg[0]) {
|
||||
case VG_USERREQ__COUNT_LEAKS: { /* count leaked bytes */
|
||||
UInt** argp = (UInt**)arg;
|
||||
*argp[1] = MAC_(total_bytes_leaked);
|
||||
*argp[2] = MAC_(total_bytes_dubious);
|
||||
*argp[3] = MAC_(total_bytes_reachable);
|
||||
*argp[4] = MAC_(total_bytes_suppressed);
|
||||
// MAC_(bytes_leaked) et al were set by the last leak check (or zero
|
||||
// if no prior leak checks performed).
|
||||
*argp[1] = MAC_(bytes_leaked);
|
||||
*argp[2] = MAC_(bytes_dubious);
|
||||
*argp[3] = MAC_(bytes_reachable);
|
||||
*argp[4] = MAC_(bytes_suppressed);
|
||||
*ret = 0;
|
||||
return True;
|
||||
}
|
||||
|
||||
@ -274,10 +274,10 @@ extern Bool (*MAC_(check_noaccess))( Addr a, UInt len, Addr* bad_addr );
|
||||
extern Bool (*MAC_(describe_addr_supp)) ( Addr a, AddrInfo* ai );
|
||||
|
||||
/* For VALGRIND_COUNT_LEAKS client request */
|
||||
extern Int MAC_(total_bytes_leaked);
|
||||
extern Int MAC_(total_bytes_dubious);
|
||||
extern Int MAC_(total_bytes_reachable);
|
||||
extern Int MAC_(total_bytes_suppressed);
|
||||
extern Int MAC_(bytes_leaked);
|
||||
extern Int MAC_(bytes_dubious);
|
||||
extern Int MAC_(bytes_reachable);
|
||||
extern Int MAC_(bytes_suppressed);
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
/*--- Functions ---*/
|
||||
|
||||
@ -40,6 +40,7 @@ int main(void)
|
||||
|
||||
reachable = malloc(99);
|
||||
|
||||
VALGRIND_DO_LEAK_CHECK;
|
||||
VALGRIND_DO_LEAK_CHECK;
|
||||
VALGRIND_COUNT_LEAKS(n_leaked, n_dubious, n_reachable, n_suppressed);
|
||||
if (n_reachable == 147) n_reachable = 99; /* handle glibc differences */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user