From aa03f73c2e39f7b900409e91d83ddea5711f81d8 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 2 Sep 2023 21:07:45 +0200 Subject: [PATCH] AK: Demangle symbols on assertion failure on Linux as well While macOS backtrace(3) puts a space directly after the mangled symbol name, some versions of glibc put a + directly after it. This new logic accounts for both situations when trying to demangle. Co-Authored-By: Andreas Kling --- AK/Assertions.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/AK/Assertions.cpp b/AK/Assertions.cpp index 95d46626387..45fb1b97e5f 100644 --- a/AK/Assertions.cpp +++ b/AK/Assertions.cpp @@ -38,8 +38,9 @@ ALWAYS_INLINE void dump_backtrace() syms[i][idx.value() - 1] = '\0'; (void)fprintf(stderr, "%s ", syms[i]); - auto end_of_sym = sym.find(' ', idx.value()).value_or(sym.length() - 1); - syms[i][end_of_sym] = '\0'; + auto sym_substring = sym.substring_view(idx.value()); + auto end_of_sym = sym_substring.find_any_of("+ "sv).value_or(sym_substring.length() - 1); + syms[i][idx.value() + end_of_sym] = '\0'; size_t buf_size = 128u; char* buf = static_cast(malloc(buf_size)); @@ -49,7 +50,7 @@ ALWAYS_INLINE void dump_backtrace() (void)fputs(buf ? buf : raw_str, stderr); free(buf); - (void)fprintf(stderr, " %s", &syms[i][end_of_sym + 1]); + (void)fprintf(stderr, " %s", &syms[i][idx.value() + end_of_sym + 1]); } else { (void)fputs(sym.characters_without_null_termination(), stderr); }