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

Parse (<function>+<addr>) backtrace format on POSIX systems #422

Merged
merged 4 commits into from
Jun 17, 2019
Merged
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
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