Skip to content

Commit

Permalink
[lldb] Fix Recognizer/assert.test with glibc-2.33.9000-31.fc35.x86_64
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jankratochvil committed Jul 1, 2021
1 parent 333d3a3 commit e825c24
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions lldb/source/Target/AssertFrameRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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));
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;

Expand Down

0 comments on commit e825c24

Please sign in to comment.