]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: libc backtrace_append() - Remove directory paths from binary names
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 27 Dec 2022 15:44:28 +0000 (10:44 -0500)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 11 Jan 2023 21:50:37 +0000 (23:50 +0200)
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

index a2806a47fb0f4feecfff866a7002995e70c907d1..b50827c381618fc4c0fbd7551af49857af6f14c8 100644 (file)
@@ -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;