-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbacktrace.c
More file actions
41 lines (33 loc) · 825 Bytes
/
backtrace.c
File metadata and controls
41 lines (33 loc) · 825 Bytes
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 <stdint.h>
#include <stdio.h>
#include <unistd.h>
void print_newline(){
printf("\n");
}
void backtrace() {
void **ebp = __builtin_frame_address(0);
uint32_t *values;
for (int i=1; ebp[0] != NULL; i++) {
values = *ebp + 8;
printf("#%d [%p] %p ( %#x %#x %#x )\n", i, ebp[0], ebp[1], values[0], values[1], values[2]);
ebp = ebp[0];
}
print_newline(); //Para poder hacer until con gdb
}
void my_write(int fd, const void *msg, size_t count) {
backtrace();
fprintf(stderr, "=> write(%d, %p, %zu)\n", fd, msg, count);
write(fd, msg, count);
}
void recurse(int level) {
if (level > 0)
recurse(level - 1);
else
my_write(2, "Hello, world!\n", 15);
}
void start_call_tree() {
recurse(5);
}
int main(void) {
start_call_tree();
}