Skip to content
Snippets Groups Projects
Commit e3503bc2 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Vladislav Shpilevoy
Browse files

backtrace: allow to specify destination buffer


This will allow to reuse this routine in crash reports.

Part-of #5261

Acked-by: default avatarSerge Petrenko <sergepetrenko@tarantool.org>
Signed-off-by: default avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 125d444f
No related branches found
No related tags found
No related merge requests found
......@@ -131,7 +131,7 @@ get_proc_name(unw_cursor_t *unw_cur, unw_word_t *offset, bool skip_cache)
}
char *
backtrace(void)
backtrace(char *start, size_t size)
{
int frame_no = 0;
unw_word_t sp = 0, old_sp = 0, ip, offset;
......@@ -139,10 +139,9 @@ backtrace(void)
unw_getcontext(&unw_context);
unw_cursor_t unw_cur;
unw_init_local(&unw_cur, &unw_context);
char *backtrace_buf = (char *)static_alloc(SMALL_STATIC_SIZE);
char *p = backtrace_buf;
char *end = p + SMALL_STATIC_SIZE - 1;
int unw_status;
char *p = start;
char *end = start + size - 1;
*p = '\0';
while ((unw_status = unw_step(&unw_cur)) > 0) {
const char *proc;
......@@ -174,7 +173,7 @@ backtrace(void)
say_debug("unwinding error: %i", unw_status);
#endif
out:
return backtrace_buf;
return start;
}
/*
......@@ -436,7 +435,8 @@ backtrace_foreach(backtrace_cb cb, coro_context *coro_ctx, void *cb_ctx)
void
print_backtrace(void)
{
fdprintf(STDERR_FILENO, "%s", backtrace());
char *start = (char *)static_alloc(SMALL_STATIC_SIZE);
fdprintf(STDERR_FILENO, "%s", backtrace(start, SMALL_STATIC_SIZE));
}
#endif /* ENABLE_BACKTRACE */
......
......@@ -40,6 +40,9 @@ extern "C" {
#ifdef ENABLE_BACKTRACE
#include <coro.h>
char *
backtrace(char *start, size_t size);
void print_backtrace(void);
typedef int (backtrace_cb)(int frameno, void *frameret,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment