Skip to content

Commit d307bf5

Browse files
kitaisrealkraj
authored andcommitted
libunwind: Added unw_backtrace method
Source: ClickHouse/libunwind@52f0f78#diff-a82fc885e2e4facf4b92d26171c13aa4aa5db296f77e1158ba2f8664e3bd1f5c Upstream-Status: Pending Signed-off-by: Khem Raj <[email protected]>
1 parent 0df5255 commit d307bf5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

libunwind/include/libunwind.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
130130
extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
131131
extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
132132
//extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
133+
extern int unw_backtrace(void **, int) LIBUNWIND_AVAIL;
133134

134135
extern unw_addr_space_t unw_local_addr_space;
135136

libunwind/src/libunwind.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,26 @@ int __unw_remove_find_dynamic_unwind_sections(
431431

432432
#endif // __APPLE__
433433

434+
int unw_backtrace(void **buffer, int size) {
435+
unw_context_t context;
436+
unw_cursor_t cursor;
437+
if (unw_getcontext(&context) || unw_init_local(&cursor, &context)) {
438+
return 0;
439+
}
440+
441+
unw_word_t ip;
442+
int current = 0;
443+
while (unw_step(&cursor) > 0) {
444+
if (current >= size || unw_get_reg(&cursor, UNW_REG_IP, &ip)) {
445+
break;
446+
}
447+
448+
buffer[current++] = reinterpret_cast<void *>(static_cast<uintptr_t>(ip));
449+
}
450+
451+
return current;
452+
}
453+
434454
// Add logging hooks in Debug builds only
435455
#ifndef NDEBUG
436456
#include <stdlib.h>

0 commit comments

Comments
 (0)