-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibDynInstrument.cpp
41 lines (32 loc) · 1.04 KB
/
libDynInstrument.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
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <sys/types.h>
#include <sys/shm.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
using namespace std;
/* Prints current block's transfer type, address,
* and destination address (if conditional jump). */
void Patch_cft(char * type, unsigned long addr, unsigned long dest){
char addrStr[64];
char destStr[64];
sprintf(addrStr, "%06X", (int)addr & 0xffffff);
sprintf(destStr, "%06X", (int)dest & 0xffffff);
printf("%s, %s, %s\n", type, addrStr, destStr);
}
/* Same as Patch_cft except trace is recorded to
* the file passed in as tracePath. */
void Patch_cftToLog(char * type, unsigned long addr, unsigned long dest, char * tracePath){
char addrStr[64];
char destStr[64];
sprintf(addrStr, "%06X", (int)addr & 0xffffff);
sprintf(destStr, "%06X", (int)dest & 0xffffff);
static FILE *traceFile = fopen(tracePath, "a+");
fprintf(traceFile, "%s, %s, %s\n", type, addrStr, destStr);
}