-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbpt_main.cpp
67 lines (58 loc) · 1.91 KB
/
bpt_main.cpp
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
60
61
62
63
64
65
66
67
#include <fstream>
#include <iostream>
#include <pin.H>
#include "bpt.hpp"
#include "bpt_inst_counter.hpp"
#include "bpt_writer_text.hpp"
#include "bpt_writer_frames.hpp"
KNOB<string> tracefile(KNOB_MODE_WRITEONCE, "pintool",
"o", "trace.frames",
"Trace file to output to "
"(filename.{frames | txt | cnt})");
INT32 usage() {
PIN_ERROR( "This Pintool trace "
"instructions memory and registers usage\n"
+ KNOB_BASE::StringKnobSummary() + "\n");
return -1;
}
VOID fini(INT32 code, VOID* ptr) {
bpt::visitor* out = static_cast<bpt::visitor*>(ptr);
bpt::fini(code, out);
delete out;
}
VOID trace(TRACE trace, VOID* ptr) {
bpt::visitor* out = static_cast<bpt::visitor*>(ptr);
bpt::trace(trace, out);
}
VOID modload(IMG img, VOID*) {
bpt::modload(img);
}
VOID syscall_entry(THREADID tid, CONTEXT* ctx,
SYSCALL_STANDARD std, VOID*) {
bpt::syscall_entry(tid, ctx, std);
}
extern char** environ;
int main(int argc, char *argv[]) {
PIN_InitSymbols();
if (PIN_Init(argc, argv)) return usage();
bpt::visitor* out;
std::string file = tracefile.Value();
std::string fmt = file.substr(file.find_last_of(".") + 1);
if (fmt == "txt") {
out = new bpt::writer_text(file.c_str(), argc, argv, environ);
} else if (fmt == "frames") {
out = new bpt::writer_frames(file.c_str(), argc, argv, environ);
} else if (fmt == "cnt") {
out = new bpt::inst_counter(file.c_str());
} else {
std::cerr << "unknown trace format " << fmt << std::endl;
exit(0);
}
TRACE_AddInstrumentFunction(trace, static_cast<VOID*>(out));
IMG_AddInstrumentFunction(modload, 0);
PIN_AddSyscallEntryFunction(syscall_entry, 0);
PIN_AddFiniFunction(fini, static_cast<VOID*>(out));
PIN_StartProgram(); //never returns
abort();
return 0;
}