-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgdb.c
More file actions
45 lines (40 loc) · 1.04 KB
/
Copy pathgdb.c
File metadata and controls
45 lines (40 loc) · 1.04 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
#include "dynamics.h"
#include "jitc_internal.h"
typedef struct {
const char* name;
void* from;
void* to;
} jitc_funcmap_t;
static list(jitc_funcmap_t)* funcmap;
void jitc_gdb_map_function(void* from, void* to, const char* name) {
if (!funcmap) funcmap = list_new(jitc_funcmap_t);
list_add(funcmap) = (jitc_funcmap_t){
.name = name,
.from = from,
.to = to,
};
}
const char* jitc_gdb_whereami(void* rip) {
if (!funcmap) return NULL;
for (size_t i = 0; i < list_size(funcmap); i++) {
jitc_funcmap_t* func = &list_get(funcmap, i);
if (rip >= func->from && rip < func->to) return func->name;
}
return NULL;
}
void jitc_gdb_backtrace(void* rip, void* rbp) {
int index = 0;
const char* name;
while ((name = jitc_gdb_whereami(rip))) {
printf("#%d: %s\n", index, name);
#ifdef _WIN32
rip = ((void**)rbp)[8];
#else
rip = ((void**)rbp)[6];
#endif
rbp = ((void**)rbp)[0];
index++;
}
printf("%d frames\n", index);
fflush(stdout);
}