diff --git a/source/posix/system_info.c b/source/posix/system_info.c index 95d556ffe..4d7bc2362 100644 --- a/source/posix/system_info.c +++ b/source/posix/system_info.c @@ -191,6 +191,7 @@ void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) { int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) { /* symbols look like: (+) [0x] * or: [0x] + * or: [0x] */ (void)addr; const char *open_paren = strstr(symbol, "("); @@ -198,14 +199,20 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info * const char *exe_end = open_paren; /* there may not be a function in parens, or parens at all */ if (open_paren == NULL || close_paren == NULL) { - exe_end = strstr(symbol, "[") - 1; + exe_end = strstr(symbol, "["); if (!exe_end) { return AWS_OP_ERR; } + /* if exe_end == symbol, there's no exe */ + if (exe_end != symbol) { + exe_end -= 1; + } } ptrdiff_t exe_len = exe_end - symbol; - strncpy(frame->exe, symbol, exe_len); + if (exe_len > 0) { + strncpy(frame->exe, symbol, exe_len); + } s_whitelist_chars(frame->exe); long function_len = (open_paren && close_paren) ? close_paren - open_paren - 1 : 0; @@ -313,8 +320,12 @@ void aws_backtrace_print(FILE *fp, void *call_site_data) { return; } + fprintf(fp, "################################################################################"); + fprintf(fp, "Resolved stacktrace:\n"); + fprintf(fp, "################################################################################"); /* symbols look like: (+) [0x] * or: [0x] + * or: [0x] * start at 1 to skip the current frame (this function) */ for (size_t frame_idx = 1; frame_idx < stack_depth; ++frame_idx) { struct aws_stack_frame_info frame; @@ -344,6 +355,15 @@ void aws_backtrace_print(FILE *fp, void *call_site_data) { parse_failed: fprintf(fp, "%s%s", symbol, (symbol == symbols[frame_idx]) ? "\n" : ""); } + + fprintf(fp, "################################################################################"); + fprintf(fp, "Raw stacktrace:\n"); + fprintf(fp, "################################################################################"); + for (size_t frame_idx = 1; frame_idx < stack_depth; ++frame_idx) { + const char *symbol = symbols[frame_idx]; + fprintf(fp, "%s\n", symbol); + } + free(symbols); }