From 08428aadad19b01f3d3b5a9f8c2247fc5ed50aea Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Thu, 14 Oct 2021 21:36:22 +0800 Subject: [PATCH] LibSymbolication: Skip source position calculation if requested Calculating source code positions can be expensive, and some applications (like SystemMonitor's Stack tab) don't even show this information, making these calculations wasteful. This commit adds a new enumerated flag to the `symbolicate` functions for callers to specify whether source positions should be included in the results; it defaults to "Yes" to preserve old behavior for existing applications. --- .../LibSymbolication/Symbolication.cpp | 23 +++++++++++-------- .../LibSymbolication/Symbolication.h | 9 ++++++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibSymbolication/Symbolication.cpp b/Userland/Libraries/LibSymbolication/Symbolication.cpp index 50f78acb528..ef883044292 100644 --- a/Userland/Libraries/LibSymbolication/Symbolication.cpp +++ b/Userland/Libraries/LibSymbolication/Symbolication.cpp @@ -61,7 +61,7 @@ Optional kernel_base() return s_kernel_base; } -Optional symbolicate(String const& path, FlatPtr address) +Optional symbolicate(String const& path, FlatPtr address, IncludeSourcePosition include_source_positions) { String full_path = path; if (!path.starts_with('/')) { @@ -106,16 +106,19 @@ Optional symbolicate(String const& path, FlatPtr address) u32 offset = 0; auto symbol = cached_elf->debug_info->elf().symbolicate(address, &offset); - auto source_position_with_inlines = cached_elf->debug_info->get_source_position_with_inlines(address); Vector positions; - for (auto& position : source_position_with_inlines.inline_chain) { - if (!positions.contains_slow(position)) - positions.append(position); - } + if (include_source_positions == IncludeSourcePosition::Yes) { + auto source_position_with_inlines = cached_elf->debug_info->get_source_position_with_inlines(address); - if (source_position_with_inlines.source_position.has_value() && !positions.contains_slow(source_position_with_inlines.source_position.value())) { - positions.insert(0, source_position_with_inlines.source_position.value()); + for (auto& position : source_position_with_inlines.inline_chain) { + if (!positions.contains_slow(position)) + positions.append(position); + } + + if (source_position_with_inlines.source_position.has_value() && !positions.contains_slow(source_position_with_inlines.source_position.value())) { + positions.insert(0, source_position_with_inlines.source_position.value()); + } } return Symbol { @@ -127,7 +130,7 @@ Optional symbolicate(String const& path, FlatPtr address) }; } -Vector symbolicate_thread(pid_t pid, pid_t tid) +Vector symbolicate_thread(pid_t pid, pid_t tid, IncludeSourcePosition include_source_positions) { struct RegionWithSymbols { FlatPtr base { 0 }; @@ -245,7 +248,7 @@ Vector symbolicate_thread(pid_t pid, pid_t tid) // However, because the first frame represents the current // instruction pointer rather than the return address we don't // subtract 1 for that. - auto result = symbolicate(found_region->path, adjusted_address - (first_frame ? 0 : 1)); + auto result = symbolicate(found_region->path, adjusted_address - (first_frame ? 0 : 1), include_source_positions); first_frame = false; if (!result.has_value()) { symbols.append(Symbol { diff --git a/Userland/Libraries/LibSymbolication/Symbolication.h b/Userland/Libraries/LibSymbolication/Symbolication.h index 7b5535c4f5c..b52af72487b 100644 --- a/Userland/Libraries/LibSymbolication/Symbolication.h +++ b/Userland/Libraries/LibSymbolication/Symbolication.h @@ -20,8 +20,13 @@ struct Symbol { bool operator==(Symbol const&) const = default; }; +enum class IncludeSourcePosition { + Yes, + No +}; + Optional kernel_base(); -Vector symbolicate_thread(pid_t pid, pid_t tid); -Optional symbolicate(String const& path, FlatPtr address); +Vector symbolicate_thread(pid_t pid, pid_t tid, IncludeSourcePosition = IncludeSourcePosition::Yes); +Optional symbolicate(String const& path, FlatPtr address, IncludeSourcePosition = IncludeSourcePosition::Yes); }