LibSymbolication+Utilities: Show inlined functions for bt

This commit is contained in:
Gunnar Beutner 2021-06-19 13:21:04 +02:00 committed by Andreas Kling
parent c31392510a
commit a6ba05b02b
Notes: sideshowbarker 2024-07-18 12:00:48 +09:00
3 changed files with 39 additions and 27 deletions

View File

@ -49,20 +49,23 @@ Optional<Symbol> symbolicate(String const& path, u32 address)
u32 offset = 0; u32 offset = 0;
auto symbol = cached_elf->debug_info->elf().symbolicate(address, &offset); auto symbol = cached_elf->debug_info->elf().symbolicate(address, &offset);
auto source_position = cached_elf->debug_info->get_source_position(address); auto source_position_with_inlines = cached_elf->debug_info->get_source_position_with_inlines(address);
String filename;
u32 line_number = 0; Vector<Debug::DebugInfo::SourcePosition> positions;
if (source_position.has_value()) { for (auto& position : source_position_with_inlines.inline_chain) {
filename = source_position.value().file_path; if (!positions.contains_slow(position))
line_number = source_position.value().line_number; 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 { return Symbol {
.address = address, .address = address,
.name = move(symbol), .name = move(symbol),
.offset = offset, .offset = offset,
.filename = move(filename), .source_positions = move(positions),
.line_number = line_number
}; };
} }
@ -166,10 +169,13 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid)
else else
adjusted_address = address; adjusted_address = address;
auto result = symbolicate(found_region->path, adjusted_address); // We're subtracting 1 from the address because this is the return address,
// i.e. it is one instruction past the call instruction.
auto result = symbolicate(found_region->path, adjusted_address - 1);
if (!result.has_value()) { if (!result.has_value()) {
symbols.append(Symbol { symbols.append(Symbol {
.address = address, .address = address,
.source_positions = {},
}); });
continue; continue;
} }

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#include <AK/String.h> #include <AK/String.h>
#include <LibDebug/DebugInfo.h>
namespace Symbolication { namespace Symbolication {
@ -14,8 +15,7 @@ struct Symbol {
FlatPtr address { 0 }; FlatPtr address { 0 };
String name {}; String name {};
u32 offset { 0 }; u32 offset { 0 };
String filename {}; Vector<Debug::DebugInfo::SourcePosition> source_positions;
u32 line_number { 0 };
}; };
Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid); Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid);

View File

@ -48,26 +48,32 @@ int main(int argc, char** argv)
out("{:3}: \033[{};1m{:p}\033[0m | ", frame_number, color, symbol.address); out("{:3}: \033[{};1m{:p}\033[0m | ", frame_number, color, symbol.address);
if (!symbol.name.is_empty()) if (!symbol.name.is_empty())
out("{} ", symbol.name); out("{} ", symbol.name);
if (!symbol.filename.is_empty()) { if (!symbol.source_positions.is_empty()) {
bool linked = false;
out("("); out("(");
// See if we can find the sources in /usr/src for (size_t i = 0; i < symbol.source_positions.size(); i++) {
// FIXME: I'm sure this can be improved! auto& source_position = symbol.source_positions[i];
auto full_path = LexicalPath::canonicalized_path(String::formatted("/usr/src/serenity/dummy/dummy/{}", symbol.filename)); bool linked = false;
if (access(full_path.characters(), F_OK) == 0) {
linked = true; // See if we can find the sources in /usr/src
auto url = URL::create_with_file_scheme(full_path, {}, hostname); // FIXME: I'm sure this can be improved!
url.set_query(String::formatted("line_number={}", symbol.line_number)); auto full_path = LexicalPath::canonicalized_path(String::formatted("/usr/src/serenity/dummy/dummy/{}", source_position.file_path));
out("\033]8;;{}\033\\", url.serialize()); if (access(full_path.characters(), F_OK) == 0) {
linked = true;
auto url = URL::create_with_file_scheme(full_path, {}, hostname);
url.set_query(String::formatted("line_number={}", source_position.line_number));
out("\033]8;;{}\033\\", url.serialize());
}
out("\033[34;1m{}:{}\033[0m", LexicalPath(source_position.file_path).basename(), source_position.line_number);
if (linked)
out("\033]8;;\033\\");
if (i != symbol.source_positions.size() - 1)
out(" => ");
} }
out("\033[34;1m{}:{}\033[0m", LexicalPath(symbol.filename).basename(), symbol.line_number);
if (linked)
out("\033]8;;\033\\");
out(")"); out(")");
} }
outln(""); outln("");