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;
auto symbol = cached_elf->debug_info->elf().symbolicate(address, &offset);
auto source_position = cached_elf->debug_info->get_source_position(address);
String filename;
u32 line_number = 0;
if (source_position.has_value()) {
filename = source_position.value().file_path;
line_number = source_position.value().line_number;
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 (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 {
.address = address,
.name = move(symbol),
.offset = offset,
.filename = move(filename),
.line_number = line_number
.source_positions = move(positions),
};
}
@ -166,10 +169,13 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid)
else
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()) {
symbols.append(Symbol {
.address = address,
.source_positions = {},
});
continue;
}

View File

@ -7,6 +7,7 @@
#pragma once
#include <AK/String.h>
#include <LibDebug/DebugInfo.h>
namespace Symbolication {
@ -14,8 +15,7 @@ struct Symbol {
FlatPtr address { 0 };
String name {};
u32 offset { 0 };
String filename {};
u32 line_number { 0 };
Vector<Debug::DebugInfo::SourcePosition> source_positions;
};
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);
if (!symbol.name.is_empty())
out("{} ", symbol.name);
if (!symbol.filename.is_empty()) {
bool linked = false;
if (!symbol.source_positions.is_empty()) {
out("(");
// See if we can find the sources in /usr/src
// FIXME: I'm sure this can be improved!
auto full_path = LexicalPath::canonicalized_path(String::formatted("/usr/src/serenity/dummy/dummy/{}", symbol.filename));
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={}", symbol.line_number));
out("\033]8;;{}\033\\", url.serialize());
for (size_t i = 0; i < symbol.source_positions.size(); i++) {
auto& source_position = symbol.source_positions[i];
bool linked = false;
// See if we can find the sources in /usr/src
// FIXME: I'm sure this can be improved!
auto full_path = LexicalPath::canonicalized_path(String::formatted("/usr/src/serenity/dummy/dummy/{}", source_position.file_path));
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(")");
}
outln("");