[Lldb-commits] [lldb] e825c24 - [lldb] Fix Recognizer/assert.test with glibc-2.33.9000-31.fc35.x86_64

Jan Kratochvil via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 1 00:16:14 PDT 2021


Author: Jan Kratochvil
Date: 2021-07-01T09:16:07+02:00
New Revision: e825c244b6063344ae726600d6a1225a05788dfa

URL: https://github.com/llvm/llvm-project/commit/e825c244b6063344ae726600d6a1225a05788dfa
DIFF: https://github.com/llvm/llvm-project/commit/e825c244b6063344ae726600d6a1225a05788dfa.diff

LOG: [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 at 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

Added: 
    

Modified: 
    lldb/source/Target/AssertFrameRecognizer.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/AssertFrameRecognizer.cpp b/lldb/source/Target/AssertFrameRecognizer.cpp
index cb671040d14fa..a2315b6d63c69 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<ConstString> 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<AssertFrameRecognizer>(),
+        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<AssertFrameRecognizer>(),
+      std::make_shared<RegularExpression>(std::move(module_re)),
+      std::make_shared<RegularExpression>(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;
 


        


More information about the lldb-commits mailing list