-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcount_bb_unique.c
47 lines (39 loc) · 1.07 KB
/
count_bb_unique.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "dr_api.h"
#include "drmgr.h"
// Global variable
static int bb_counter;
// Function prototypes for events
static void
event_exit(void);
static dr_emit_flags_t
event_bb_analysis(void *drcontext, void *tag, instrlist_t *bb, bool for_trace,
bool translating, OUT void **user_data);
// Called on process start
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
dr_printf("Process started\n");
// Initialization
drmgr_init();
bb_counter = 0;
// Register functions for events
drmgr_register_bb_instrumentation_event(event_bb_analysis, NULL, NULL);
dr_register_exit_event(event_exit);
}
// Called on process end
static void
event_exit(void)
{
dr_printf("Process exited\n");
dr_printf("Total basic blocks: %d\n", bb_counter);
// Free drmgr resources
drmgr_exit();
}
// Called on new BB
static dr_emit_flags_t
event_bb_analysis(void *drcontext, void *tag, instrlist_t *bb, bool for_trace,
bool translating, OUT void **user_data)
{
bb_counter++;
return DR_EMIT_DEFAULT;
}