Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support libunwind #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ AC_CHECK_HEADERS_ONCE(m4_flatten([
grp.h
inttypes.h
libgen.h
libunwind.h
limits.h
memory.h
pthread.h
Expand Down
4 changes: 4 additions & 0 deletions headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#ifdef HAVE_LIBGEN_H
# include <libgen.h>
#endif
#if !defined(HAVE_EXECINFO_H) && defined(HAVE_LIBUNWIND_H)
#define UNW_LOCAL_ONLY
# include <libunwind.h>
#endif
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
Expand Down
13 changes: 13 additions & 0 deletions libsbutil/sb_efuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,23 @@ void sb_eraw(const char *format, ...)
void sb_dump_backtrace(void)
{
#ifdef HAVE_BACKTRACE
#if defined(HAVE_EXECINFO_H)
void *funcs[10];
int num_funcs;
num_funcs = backtrace(funcs, ARRAY_SIZE(funcs));
backtrace_symbols_fd(funcs, num_funcs, STDERR_FILENO);
#elif defined(HAVE_LIBUNWIND_H)
unw_cursor_t cursor; unw_context_t uc;
unw_word_t ip, sp;

unw_getcontext(&uc);
unw_init_local(&cursor, &uc);
while (unw_step(&cursor) > 0) {
unw_get_reg(&cursor, UNW_REG_IP, &ip);
unw_get_reg(&cursor, UNW_REG_SP, &sp);
fprintf(STDERR_FILENO, "ip = %lx, sp = %lx\n", (long) ip, (long) sp);
}
#endif
#endif
__sb_dump_backtrace();
}
Expand Down