mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
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.
This commit is contained in:
parent
85a28a6555
commit
08428aadad
Notes:
sideshowbarker
2024-07-18 02:12:07 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/08428aadad1 Pull-request: https://github.com/SerenityOS/serenity/pull/10481 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/bgianfo
@ -61,7 +61,7 @@ Optional<FlatPtr> kernel_base()
|
||||
return s_kernel_base;
|
||||
}
|
||||
|
||||
Optional<Symbol> symbolicate(String const& path, FlatPtr address)
|
||||
Optional<Symbol> symbolicate(String const& path, FlatPtr address, IncludeSourcePosition include_source_positions)
|
||||
{
|
||||
String full_path = path;
|
||||
if (!path.starts_with('/')) {
|
||||
@ -106,16 +106,19 @@ Optional<Symbol> 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<Debug::DebugInfo::SourcePosition> 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<Symbol> symbolicate(String const& path, FlatPtr address)
|
||||
};
|
||||
}
|
||||
|
||||
Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid)
|
||||
Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid, IncludeSourcePosition include_source_positions)
|
||||
{
|
||||
struct RegionWithSymbols {
|
||||
FlatPtr base { 0 };
|
||||
@ -245,7 +248,7 @@ Vector<Symbol> 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 {
|
||||
|
@ -20,8 +20,13 @@ struct Symbol {
|
||||
bool operator==(Symbol const&) const = default;
|
||||
};
|
||||
|
||||
enum class IncludeSourcePosition {
|
||||
Yes,
|
||||
No
|
||||
};
|
||||
|
||||
Optional<FlatPtr> kernel_base();
|
||||
Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid);
|
||||
Optional<Symbol> symbolicate(String const& path, FlatPtr address);
|
||||
Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid, IncludeSourcePosition = IncludeSourcePosition::Yes);
|
||||
Optional<Symbol> symbolicate(String const& path, FlatPtr address, IncludeSourcePosition = IncludeSourcePosition::Yes);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user