-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbcount.c
executable file
·59 lines (49 loc) · 1.74 KB
/
bbcount.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
48
49
50
51
52
53
54
55
56
57
58
59
/* **********************************************************
* Copyright (c) 2012 Google, Inc. All rights reserved.
* **********************************************************/
/* Basic block count. */
#include "dr_api.h"
/* Forward decls. */
static void event_exit(void);
static dr_emit_flags_t
event_basic_block(void *drcontext, void *tag,
instrlist_t *bb, bool for_trace,
bool translating);
/* Exported entry point. */
DR_EXPORT void
dr_init(client_id_t id)
{
/* Can't use libc printf: conflict with app! */
dr_printf("Client 'bbcount' initializing\n");
/* Register events. */
dr_register_bb_event(event_basic_block);
dr_register_exit_event(event_exit);
}
/************************************************************
* Basic block counting.
*/
static uint bbs_instrumented;
static uint bbs_executed;
/* Basic block execution callback, aka Pin's "analysis" callback. */
static void bb_count(void) { bbs_executed++; }
/* Basic block instrumentation callback. */
static dr_emit_flags_t
event_basic_block(void *drcontext, void *tag, instrlist_t *bb,
bool for_trace, bool translating)
{
/* bb event called again for tracing and translating, don't count those. */
if (!for_trace && !translating)
bbs_instrumented++;
dr_insert_clean_call(drcontext, bb, instrlist_first(bb),
(void *)bb_count, false/*fpstate*/, 0/*num args*/);
return DR_EMIT_DEFAULT;
}
static void
event_exit(void)
{
dr_messagebox("Instrumentation results:\n"
"%10u bbs instrumented\n"
"%10u bbs executed\n",
bbs_instrumented,
bbs_executed);
}