From 6a100cc1b1dd3f101bf367873b1b75595b144a3a Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 27 Dec 2022 10:44:28 -0500 Subject: [PATCH] lib: libc backtrace_append() - Remove directory paths from binary names The backtrace unnecessarily contained directory paths, causing the backtrace to become excessively large just repeating the directories. This change is only for libc backtrace, not for libunwind backtrace. --- src/lib/backtrace-string.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/backtrace-string.c b/src/lib/backtrace-string.c index a2806a47fb..b50827c381 100644 --- a/src/lib/backtrace-string.c +++ b/src/lib/backtrace-string.c @@ -83,8 +83,18 @@ static int backtrace_append_libc(string_t *str) /* out of memory case */ str_printfa(str, "0x%p", stack[i]); } else if (str_len(str) != str_orig_size || - !str_begins_with(strings[i], BACKTRACE_SKIP_PREFIX)) - str_append(str, strings[i]); + !str_begins_with(strings[i], BACKTRACE_SKIP_PREFIX)) { + /* String often contains a full path to the binary, + followed by the function name. The path causes the + backtrace to be excessively large and we don't + especially care about it, so just skip over it. */ + const char *suffix = strrchr(strings[i], '/'); + if (suffix != NULL) + suffix++; + else + suffix = strings[i]; + str_append(str, suffix); + } } free(strings); return 0; -- 2.47.3