File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change
1
+ #include < dlfcn.h>
1
2
#include < execinfo.h>
3
+ #include < inttypes.h>
4
+ #include < stdio.h>
5
+ #include < unistd.h>
2
6
#include < unwind.h>
3
7
4
8
#include < bits/ensure.h>
@@ -49,7 +53,24 @@ char **backtrace_symbols(void *const *, int) {
49
53
__builtin_unreachable ();
50
54
}
51
55
52
- void backtrace_symbols_fd (void *const *, int , int ) {
53
- __ensure (!" Not implemented" );
54
- __builtin_unreachable ();
56
+ void backtrace_symbols_fd (void *const *buffer, int size, int fd) {
57
+ if (size <= 0 || fd < 0 ) {
58
+ return ;
59
+ }
60
+
61
+ for (int frame_num = 0 ; frame_num < size; frame_num++) {
62
+ Dl_info info;
63
+ if (dladdr (buffer[frame_num], &info) != 0 ) {
64
+ if (info.dli_fname != nullptr )
65
+ write (fd, info.dli_fname , strlen (info.dli_fname ));
66
+
67
+ if (info.dli_sname != nullptr )
68
+ dprintf (fd, " (%s+0x%" PRIxPTR " ) " , info.dli_sname ,
69
+ reinterpret_cast <uintptr_t >(buffer[frame_num]) - reinterpret_cast <uintptr_t >(info.dli_saddr ));
70
+ else
71
+ dprintf (fd, " (+%p) " , info.dli_saddr );
72
+ }
73
+
74
+ dprintf (fd, " [%p]\n " , buffer[frame_num]);
75
+ }
55
76
}
You can’t perform that action at this time.
0 commit comments