-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunpack.c
More file actions
61 lines (55 loc) · 1.58 KB
/
unpack.c
File metadata and controls
61 lines (55 loc) · 1.58 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "mtrace.h"
#define NENTRIES 1024
void unpack(char *fname) {
FILE *fp = fopen(fname, "r");
if (!fp) {
perror("fopen");
exit(EXIT_FAILURE);
}
struct entry *entries =
calloc(NENTRIES, sizeof(*entries));
assert(entries);
size_t ne;
while ((ne = fread(entries, sizeof(*entries), NENTRIES, fp))) {
for (ul i = 0; i < ne; i++) {
struct entry *e = &entries[i];
switch (e->op) {
case OP_MALLOC: {
printf("%lu m %lu %p\n",
e->tsc, e->args.ma.size,
e->args.ma.ptr);
} break;
case OP_FREE: {
printf("%lu f %p\n",
e->tsc, e->args.fr.ptr);
} break;
case OP_CALLOC: {
printf("%lu c %lu %lu %p\n",
e->tsc, e->args.ca.nmemb,
e->args.ca.size, e->args.ca.ret);
} break;
case OP_REALLOC: {
printf("%lu r %p %lu %p\n",
e->tsc, e->args.re.ptr,
e->args.re.size, e->args.re.ret);
} break;
default: abort();
}
}
clearerr(fp);
}
if (ne == 0) {
if (ferror(fp)) {
perror("fread");
exit(EXIT_FAILURE);
}
}
fclose(fp);
}
int main() {
unpack("mtrace.log");
return EXIT_SUCCESS;
}