diff options
author | Itamar <itamar8910@gmail.com> | 2021-06-11 14:39:16 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-19 14:51:18 +0200 |
commit | 03ef2a479a121cef5de5ca33792f4cf997e6ee71 (patch) | |
tree | c3c713e2c3fb62aa0545e315d71ca840108f9e24 /Userland | |
parent | a45b5ccd969443aef7a4afce8bd43d512ca74b1a (diff) | |
download | serenity-03ef2a479a121cef5de5ca33792f4cf997e6ee71.zip |
LibCoreDump: Include source locations of inlined functions in backtrace
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibCoreDump/Backtrace.cpp | 33 | ||||
-rw-r--r-- | Userland/Libraries/LibCoreDump/Backtrace.h | 2 | ||||
-rw-r--r-- | Userland/Services/CrashDaemon/main.cpp | 14 |
3 files changed, 41 insertions, 8 deletions
diff --git a/Userland/Libraries/LibCoreDump/Backtrace.cpp b/Userland/Libraries/LibCoreDump/Backtrace.cpp index ea16b7c68b..c91922a3e2 100644 --- a/Userland/Libraries/LibCoreDump/Backtrace.cpp +++ b/Userland/Libraries/LibCoreDump/Backtrace.cpp @@ -84,8 +84,10 @@ void Backtrace::add_entry(const Reader& coredump, FlatPtr eip) auto* object_info = object_info_for_region(*region); if (!object_info) return; - auto function_name = object_info->debug_info.elf().symbolicate(eip - region->region_start); - auto source_position = object_info->debug_info.get_source_position(eip - region->region_start); + + auto function_name = object_info->debug_info->elf().symbolicate(eip - region->region_start); + auto source_position = object_info->debug_info->get_source_position_with_inlines(eip - region->region_start); + m_entries.append({ eip, object_name, function_name, source_position }); } @@ -98,11 +100,30 @@ String Backtrace::Entry::to_string(bool color) const return builder.build(); } builder.appendff("[{}] {}", object_name, function_name.is_empty() ? "???" : function_name); - if (source_position.has_value()) { - auto& source_position = this->source_position.value(); - auto fmt = color ? " (\033[34;1m{}\033[0m:{})" : " ({}:{})"; - builder.appendff(fmt, LexicalPath(source_position.file_path).basename(), source_position.line_number); + builder.append(" ("); + + Vector<Debug::DebugInfo::SourcePosition> source_positions; + + for (auto& position : source_position_with_inlines.inline_chain) { + if (!source_positions.contains_slow(position)) + source_positions.append(position); + } + + if (source_position_with_inlines.source_position.has_value() && !source_positions.contains_slow(source_position_with_inlines.source_position.value())) { + source_positions.insert(0, source_position_with_inlines.source_position.value()); + } + + for (size_t i = 0; i < source_positions.size(); ++i) { + auto& position = source_positions[i]; + auto fmt = color ? "\033[34;1m{}\033[0m:{}" : "{}:{}"; + builder.appendff(fmt, LexicalPath(position.file_path).basename(), position.line_number); + if (i != source_positions.size() - 1) { + builder.append(" => "); + } } + + builder.append(")"); + return builder.build(); } diff --git a/Userland/Libraries/LibCoreDump/Backtrace.h b/Userland/Libraries/LibCoreDump/Backtrace.h index 32b32d0c28..a1a008213b 100644 --- a/Userland/Libraries/LibCoreDump/Backtrace.h +++ b/Userland/Libraries/LibCoreDump/Backtrace.h @@ -30,7 +30,7 @@ public: FlatPtr eip; String object_name; String function_name; - Optional<Debug::DebugInfo::SourcePosition> source_position; + Debug::DebugInfo::SourcePositionWithInlines source_position_with_inlines; String to_string(bool color = false) const; }; diff --git a/Userland/Services/CrashDaemon/main.cpp b/Userland/Services/CrashDaemon/main.cpp index 5f6ea14fdf..c8b314b10e 100644 --- a/Userland/Services/CrashDaemon/main.cpp +++ b/Userland/Services/CrashDaemon/main.cpp @@ -74,8 +74,20 @@ static void print_backtrace(const String& coredump_path) if (thread_index > 0) dbgln(); dbgln("--- Backtrace for thread #{} (TID {}) ---", thread_index, thread_info.tid); - for (auto& entry : backtrace.entries()) + for (auto& entry : backtrace.entries()) { +#ifndef BACKTRACE_DEBUG dbgln("{}", entry.to_string(true)); +#else + auto region = coredump->region_containing(entry.eip); + String name; + u32 base_addr { 0 }; + if (region) { + name = region->region_name; + base_addr = region->region_start; + } + dbgln("{} ({} base: {:p}, offset: {:p})", entry.to_string(true), name, base_addr, entry.eip - base_addr); +#endif + } ++thread_index; return IterationDecision::Continue; }); |