Skip to content

Commit d576b29

Browse files
committed
i#573,i#1636 annotations: add leak check annotation handling
Adds a handler for the VALGRIND_DO_LEAK_CHECK annotation, for use in our tests. Requires DR 4050f4f. Review-URL: https://codereview.appspot.com/262490044
1 parent 75ebe12 commit d576b29

5 files changed

Lines changed: 24 additions & 6 deletions

File tree

drheapstat/drheapstat.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,8 +1954,8 @@ event_post_syscall(void *drcontext, int sysnum)
19541954
handle_post_alloc_syscall(drcontext, sysnum, mc);
19551955
}
19561956

1957-
static void
1958-
check_for_leaks(bool at_exit)
1957+
void
1958+
check_reachability(bool at_exit)
19591959
{
19601960
if (options.check_leaks) {
19611961
void *drcontext = dr_get_current_drcontext();
@@ -2032,7 +2032,7 @@ event_nudge(void *drcontext, uint64 argument)
20322032
dr_fprintf(f_nudge, "%d,%"INT64_FORMAT"u,%"INT64_FORMAT"u\n",
20332033
nudge_count, snapshot_fpos, staleness_fpos);
20342034
malloc_unlock();
2035-
check_for_leaks(false/*!at_exit*/);
2035+
check_reachability(false/*!at_exit*/);
20362036
print_nudge_header(f_global);
20372037
NOTIFY("Received nudge"NL, logsubdir);
20382038
}
@@ -2132,7 +2132,7 @@ event_exit(void)
21322132
}
21332133
snapshot_exit();
21342134
if (options.check_leaks) {
2135-
check_for_leaks(true/*at_exit*/);
2135+
check_reachability(true/*at_exit*/);
21362136
leak_exit();
21372137
}
21382138

drmemory/alloc_drmem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#ifndef _ALLOC_DRMEM_H_
2828
#define _ALLOC_DRMEM_H_ 1
2929

30+
#include "callstack.h" /* app_loc_t */
31+
3032
#ifdef UNIX
3133
extern hashtable_t sighand_table;
3234
#endif

drmemory/annotations.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
#include "utils.h"
3939
#include "shadow.h"
4040
#include "options.h"
41+
#ifdef TOOL_DR_MEMORY
42+
# include "alloc_drmem.h"
43+
#else
44+
extern void check_reachability(bool at_exit);
45+
#endif
4146

4247
#ifndef ARM /* FIXME DRi#1672: add ARM annotation support to DR */
4348
static ptr_uint_t
@@ -61,6 +66,14 @@ handle_make_mem_defined_if_addressable(dr_vg_client_request_t *request)
6166
*/
6267
return 1;
6368
}
69+
70+
static ptr_uint_t
71+
handle_do_leak_check(dr_vg_client_request_t *request)
72+
{
73+
LOG(2, "%s\n", __FUNCTION__);
74+
check_reachability(false/*!at_exit*/);
75+
return 0;
76+
}
6477
#endif
6578

6679
void
@@ -71,6 +84,8 @@ annotate_init(void)
7184
# ifndef ARM /* FIXME DRi#1672: add ARM annotation support to DR */
7285
dr_annotation_register_valgrind(DR_VG_ID__MAKE_MEM_DEFINED_IF_ADDRESSABLE,
7386
handle_make_mem_defined_if_addressable);
87+
dr_annotation_register_valgrind(DR_VG_ID__DO_LEAK_CHECK,
88+
handle_do_leak_check);
7489
# endif
7590
#endif
7691
}

drmemory/docs/release.dox

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ The changes between \TOOL_VERSION and version 1.8.0 include:
7070
- Switched the Windows installer from an NSIS-based executable to
7171
a WIX-based .msi file. The new installer automatically adds
7272
Dr. Memory to the PATH for the current user.
73-
- Added unaddressable warning report on write-to-readonly-memory.
73+
- Added an unaddressable warning report on a write to read-only memory.
74+
- Added support for the VALGRIND_DO_LEAK_CHECK annotation.
7475

7576
The changes between version 1.8.0 and version 1.7.0 include:
7677
- Dropped official support for Windows 2000.

third_party/valgrind/memcheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ typedef
184184

185185
/* Do a full memory leak check (like --leak-check=full) mid-execution. */
186186
#define VALGRIND_DO_LEAK_CHECK \
187-
{unsigned long _qzz_res; \
187+
{__attribute__((unused)) unsigned long _qzz_res; \
188188
VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \
189189
VG_USERREQ__DO_LEAK_CHECK, \
190190
0, 0, 0, 0, 0); \

0 commit comments

Comments
 (0)