Skip to content

Commit

Permalink
Always print both raw and resolved stack trace, helps in release buil…
Browse files Browse the repository at this point in the history
…ds (#540)

* Always print both raw and resolved stack trace, helps in release builds
  • Loading branch information
Justin Boswell authored Nov 7, 2019
1 parent 4bd17cf commit 1906857
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions source/posix/system_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,28 @@ 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: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
* or: <exe-or-shared-lib> [0x<addr>]
* or: [0x<addr>]
*/
(void)addr;
const char *open_paren = strstr(symbol, "(");
const char *close_paren = strstr(symbol, ")");
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;
Expand Down Expand Up @@ -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: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
* or: <exe-or-shared-lib> [0x<addr>]
* or: [0x<addr>]
* 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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 1906857

Please sign in to comment.