Skip to content

Commit 8165089

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 393485b commit 8165089

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
@@ -234,6 +234,7 @@ extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
234234
extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
235235
extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
236236
//extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
237+
extern int unw_backtrace(void **, int) LIBUNWIND_AVAIL;
237238

238239
extern unw_addr_space_t unw_local_addr_space;
239240

libunwind/src/libunwind.cpp

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

474474
#endif // __APPLE__
475475

476+
int unw_backtrace(void **buffer, int size) {
477+
unw_context_t context;
478+
unw_cursor_t cursor;
479+
if (unw_getcontext(&context) || unw_init_local(&cursor, &context)) {
480+
return 0;
481+
}
482+
483+
unw_word_t ip;
484+
int current = 0;
485+
while (unw_step(&cursor) > 0) {
486+
if (current >= size || unw_get_reg(&cursor, UNW_REG_IP, &ip)) {
487+
break;
488+
}
489+
490+
buffer[current++] = reinterpret_cast<void *>(static_cast<uintptr_t>(ip));
491+
}
492+
493+
return current;
494+
}
495+
476496
// Add logging hooks in Debug builds only
477497
#ifndef NDEBUG
478498
#include <stdlib.h>

0 commit comments

Comments
 (0)