Skip to content

Commit

Permalink
Parse (<function>+<addr>) backtrace format on POSIX systems (#422)
Browse files Browse the repository at this point in the history
* Parse (<function>+<addr>) backgtrace format on POSIX systems #356
  • Loading branch information
Justin Boswell authored Jun 17, 2019
1 parent 76e2a61 commit 8b7d8fd
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions source/posix/system_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) {
}
# else
int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) {
/* symbols look like: <exe-or-shared-lib>(<function>) [0x<addr>]
/* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
* or: <exe-or-shared-lib> [0x<addr>]
*/
(void)addr;
Expand All @@ -182,16 +182,28 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *
ptrdiff_t exe_len = exe_end - symbol;
strncpy(frame->exe, symbol, exe_len);

const char *addr_start = strstr(exe_end, "[") + 1;
char *addr_end = strstr(addr_start, "]");
if (!addr_end) {
return AWS_OP_ERR;
}
strncpy(frame->addr, addr_start, addr_end - addr_start);

long function_len = (open_paren && close_paren) ? close_paren - open_paren - 1 : 0;
if (function_len > 0) { /* dynamic symbol was found */
strncpy(frame->function, open_paren + 1, function_len);
/* there might be (<function>+<addr>) or just (<function>) */
const char *function_start = open_paren + 1;
const char *plus = strstr(function_start, "+");
const char *function_end = (plus) ? plus : close_paren;
if (function_end > function_start) {
function_len = function_end - function_start;
strncpy(frame->function, function_start, function_len);
} else if (plus) {
long addr_len = close_paren - plus - 1;
strncpy(frame->addr, plus + 1, addr_len);
}
}
if (frame->addr[0] == 0) {
/* use the address in []'s, since it's all we have */
const char *addr_start = strstr(exe_end, "[") + 1;
char *addr_end = strstr(addr_start, "]");
if (!addr_end) {
return AWS_OP_ERR;
}
strncpy(frame->addr, addr_start, addr_end - addr_start);
}

return AWS_OP_SUCCESS;
Expand All @@ -218,7 +230,7 @@ void aws_backtrace_print(FILE *fp, void *call_site_data) {
return;
}

/* symbols look like: <exe-or-shared-lib>(<function>) [0x<addr>]
/* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
* or: <exe-or-shared-lib> [0x<addr>]
* start at 1 to skip the current frame (this function) */
for (int frame_idx = 1; frame_idx < stack_depth; ++frame_idx) {
Expand Down

0 comments on commit 8b7d8fd

Please sign in to comment.