From e825c244b6063344ae726600d6a1225a05788dfa Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Thu, 1 Jul 2021 09:14:28 +0200 Subject: [PATCH] [lldb] Fix Recognizer/assert.test with glibc-2.33.9000-31.fc35.x86_64 While on regular Linux system (Fedora 34 GA, not updated): * thread #1, name = '1', stop reason = hit program assert frame #0: 0x00007ffff7e242a2 libc.so.6`raise + 322 frame #1: 0x00007ffff7e0d8a4 libc.so.6`abort + 278 frame #2: 0x00007ffff7e0d789 libc.so.6`__assert_fail_base.cold + 15 frame #3: 0x00007ffff7e1ca16 libc.so.6`__assert_fail + 70 * frame #4: 0x00000000004011bd 1`main at assert.c:7:3 On Fedora 35 pre-release one gets: * thread #1, name = '1', stop reason = signal SIGABRT * frame #0: 0x00007ffff7e48ee3 libc.so.6`pthread_kill@GLIBC_2.2.5 + 67 frame #1: 0x00007ffff7dfb986 libc.so.6`raise + 22 frame #2: 0x00007ffff7de5806 libc.so.6`abort + 230 frame #3: 0x00007ffff7de571b libc.so.6`__assert_fail_base.cold + 15 frame #4: 0x00007ffff7df4646 libc.so.6`__assert_fail + 70 frame #5: 0x00000000004011bd 1`main at assert.c:7:3 I did not write a testcase as one needs the specific glibc. An artificial test would just copy the changed source. Reviewed By: mib Differential Revision: https://reviews.llvm.org/D105133 --- lldb/source/Target/AssertFrameRecognizer.cpp | 36 ++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/lldb/source/Target/AssertFrameRecognizer.cpp b/lldb/source/Target/AssertFrameRecognizer.cpp index cb671040d14fae..a2315b6d63c699 100644 --- a/lldb/source/Target/AssertFrameRecognizer.cpp +++ b/lldb/source/Target/AssertFrameRecognizer.cpp @@ -22,6 +22,10 @@ namespace lldb_private { struct SymbolLocation { FileSpec module_spec; std::vector symbols; + + // The symbols are regular expressions. In such case all symbols are matched + // with their trailing @VER symbol version stripped. + bool symbols_are_regex = false; }; /// Fetches the abort frame location depending on the current platform. @@ -45,6 +49,8 @@ bool GetAbortLocation(llvm::Triple::OSType os, SymbolLocation &location) { location.symbols.push_back(ConstString("raise")); location.symbols.push_back(ConstString("__GI_raise")); location.symbols.push_back(ConstString("gsignal")); + location.symbols.push_back(ConstString("pthread_kill")); + location.symbols_are_regex = true; break; default: Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_UNWIND)); @@ -93,9 +99,33 @@ void RegisterAssertFrameRecognizer(Process *process) { if (!GetAbortLocation(os, location)) return; + if (!location.symbols_are_regex) { + target.GetFrameRecognizerManager().AddRecognizer( + std::make_shared(), + location.module_spec.GetFilename(), location.symbols, + /*first_instruction_only*/ false); + return; + } + std::string module_re = "^"; + for (char c : location.module_spec.GetFilename().GetStringRef()) { + if (c == '.') + module_re += '\\'; + module_re += c; + } + module_re += '$'; + std::string symbol_re = "^("; + for (auto it = location.symbols.cbegin(); it != location.symbols.cend(); + ++it) { + if (it != location.symbols.cbegin()) + symbol_re += '|'; + symbol_re += it->GetStringRef(); + } + // Strip the trailing @VER symbol version. + symbol_re += ")(@.*)?$"; target.GetFrameRecognizerManager().AddRecognizer( - StackFrameRecognizerSP(new AssertFrameRecognizer()), - location.module_spec.GetFilename(), location.symbols, + std::make_shared(), + std::make_shared(std::move(module_re)), + std::make_shared(std::move(symbol_re)), /*first_instruction_only*/ false); } @@ -112,7 +142,7 @@ AssertFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) { if (!GetAssertLocation(os, location)) return RecognizedStackFrameSP(); - const uint32_t frames_to_fetch = 5; + const uint32_t frames_to_fetch = 6; const uint32_t last_frame_index = frames_to_fetch - 1; StackFrameSP prev_frame_sp = nullptr;