1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:47:44 +00:00

LibDebug: Convert LibDebug to east-const style

This commit is contained in:
Itamar 2021-06-19 15:33:03 +03:00 committed by Andreas Kling
parent 03ef2a479a
commit 3a4017b419
17 changed files with 68 additions and 68 deletions

View file

@ -27,15 +27,15 @@ DebugInfo::DebugInfo(NonnullOwnPtr<const ELF::Image> elf, String source_root, Fl
void DebugInfo::prepare_variable_scopes() void DebugInfo::prepare_variable_scopes()
{ {
m_dwarf_info.for_each_compilation_unit([&](const Dwarf::CompilationUnit& unit) { m_dwarf_info.for_each_compilation_unit([&](Dwarf::CompilationUnit const& unit) {
auto root = unit.root_die(); auto root = unit.root_die();
parse_scopes_impl(root); parse_scopes_impl(root);
}); });
} }
void DebugInfo::parse_scopes_impl(const Dwarf::DIE& die) void DebugInfo::parse_scopes_impl(Dwarf::DIE const& die)
{ {
die.for_each_child([&](const Dwarf::DIE& child) { die.for_each_child([&](Dwarf::DIE const& child) {
if (child.is_null()) if (child.is_null())
return; return;
if (!(child.tag() == Dwarf::EntryTag::SubProgram || child.tag() == Dwarf::EntryTag::LexicalBlock)) if (!(child.tag() == Dwarf::EntryTag::SubProgram || child.tag() == Dwarf::EntryTag::LexicalBlock))
@ -64,7 +64,7 @@ void DebugInfo::parse_scopes_impl(const Dwarf::DIE& die)
// The attribute name HighPc is confusing. In this context, it seems to actually be a positive offset from LowPc // The attribute name HighPc is confusing. In this context, it seems to actually be a positive offset from LowPc
scope.address_high = scope.address_low + child.get_attribute(Dwarf::Attribute::HighPc).value().data.as_u32; scope.address_high = scope.address_low + child.get_attribute(Dwarf::Attribute::HighPc).value().data.as_u32;
child.for_each_child([&](const Dwarf::DIE& variable_entry) { child.for_each_child([&](Dwarf::DIE const& variable_entry) {
if (!(variable_entry.tag() == Dwarf::EntryTag::Variable if (!(variable_entry.tag() == Dwarf::EntryTag::Variable
|| variable_entry.tag() == Dwarf::EntryTag::FormalParameter)) || variable_entry.tag() == Dwarf::EntryTag::FormalParameter))
return; return;
@ -80,7 +80,7 @@ void DebugInfo::prepare_lines()
{ {
Vector<Dwarf::LineProgram::LineInfo> all_lines; Vector<Dwarf::LineProgram::LineInfo> all_lines;
m_dwarf_info.for_each_compilation_unit([&all_lines](const Dwarf::CompilationUnit& unit) { m_dwarf_info.for_each_compilation_unit([&all_lines](Dwarf::CompilationUnit const& unit) {
all_lines.extend(unit.line_program().lines()); all_lines.extend(unit.line_program().lines());
}); });
@ -131,7 +131,7 @@ Optional<DebugInfo::SourcePosition> DebugInfo::get_source_position(u32 target_ad
return {}; return {};
} }
Optional<DebugInfo::SourcePositionAndAddress> DebugInfo::get_address_from_source_position(const String& file, size_t line) const Optional<DebugInfo::SourcePositionAndAddress> DebugInfo::get_address_from_source_position(String const& file, size_t line) const
{ {
String file_path = file; String file_path = file;
if (!file_path.starts_with("/")) if (!file_path.starts_with("/"))
@ -180,7 +180,7 @@ NonnullOwnPtrVector<DebugInfo::VariableInfo> DebugInfo::get_variables_in_current
return variables; return variables;
} }
static Optional<Dwarf::DIE> parse_variable_type_die(const Dwarf::DIE& variable_die, DebugInfo::VariableInfo& variable_info) static Optional<Dwarf::DIE> parse_variable_type_die(Dwarf::DIE const& variable_die, DebugInfo::VariableInfo& variable_info)
{ {
auto type_die_offset = variable_die.get_attribute(Dwarf::Attribute::Type); auto type_die_offset = variable_die.get_attribute(Dwarf::Attribute::Type);
if (!type_die_offset.has_value()) if (!type_die_offset.has_value())
@ -200,7 +200,7 @@ static Optional<Dwarf::DIE> parse_variable_type_die(const Dwarf::DIE& variable_d
return type_die; return type_die;
} }
static void parse_variable_location(const Dwarf::DIE& variable_die, DebugInfo::VariableInfo& variable_info, const PtraceRegisters& regs) static void parse_variable_location(Dwarf::DIE const& variable_die, DebugInfo::VariableInfo& variable_info, PtraceRegisters const& regs)
{ {
auto location_info = variable_die.get_attribute(Dwarf::Attribute::Location); auto location_info = variable_die.get_attribute(Dwarf::Attribute::Location);
if (!location_info.has_value()) { if (!location_info.has_value()) {
@ -231,7 +231,7 @@ static void parse_variable_location(const Dwarf::DIE& variable_die, DebugInfo::V
} }
} }
OwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters& regs, u32 address_offset) const OwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(Dwarf::DIE const& variable_die, PtraceRegisters const& regs, u32 address_offset) const
{ {
VERIFY(is_variable_tag_supported(variable_die.tag())); VERIFY(is_variable_tag_supported(variable_die.tag()));
@ -275,7 +275,7 @@ OwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(const Dwarf::DIE
return variable_info; return variable_info;
} }
void DebugInfo::add_type_info_to_variable(const Dwarf::DIE& type_die, const PtraceRegisters& regs, DebugInfo::VariableInfo* parent_variable) const void DebugInfo::add_type_info_to_variable(Dwarf::DIE const& type_die, PtraceRegisters const& regs, DebugInfo::VariableInfo* parent_variable) const
{ {
OwnPtr<VariableInfo> type_info; OwnPtr<VariableInfo> type_info;
auto is_array_type = type_die.tag() == Dwarf::EntryTag::ArrayType; auto is_array_type = type_die.tag() == Dwarf::EntryTag::ArrayType;
@ -286,7 +286,7 @@ void DebugInfo::add_type_info_to_variable(const Dwarf::DIE& type_die, const Ptra
type_info = create_variable_info(type_die, regs); type_info = create_variable_info(type_die, regs);
} }
type_die.for_each_child([&](const Dwarf::DIE& member) { type_die.for_each_child([&](Dwarf::DIE const& member) {
if (member.is_null()) if (member.is_null())
return; return;
@ -332,7 +332,7 @@ void DebugInfo::add_type_info_to_variable(const Dwarf::DIE& type_die, const Ptra
} }
} }
bool DebugInfo::is_variable_tag_supported(const Dwarf::EntryTag& tag) bool DebugInfo::is_variable_tag_supported(Dwarf::EntryTag const& tag)
{ {
return tag == Dwarf::EntryTag::Variable return tag == Dwarf::EntryTag::Variable
|| tag == Dwarf::EntryTag::Member || tag == Dwarf::EntryTag::Member
@ -361,7 +361,7 @@ Optional<DebugInfo::VariablesScope> DebugInfo::get_containing_function(u32 addre
return {}; return {};
} }
Vector<DebugInfo::SourcePosition> DebugInfo::source_lines_in_scope(const VariablesScope& scope) const Vector<DebugInfo::SourcePosition> DebugInfo::source_lines_in_scope(VariablesScope const& scope) const
{ {
Vector<DebugInfo::SourcePosition> source_lines; Vector<DebugInfo::SourcePosition> source_lines;
for (const auto& line : m_sorted_lines) { for (const auto& line : m_sorted_lines) {
@ -375,7 +375,7 @@ Vector<DebugInfo::SourcePosition> DebugInfo::source_lines_in_scope(const Variabl
return source_lines; return source_lines;
} }
DebugInfo::SourcePosition DebugInfo::SourcePosition::from_line_info(const Dwarf::LineProgram::LineInfo& line) DebugInfo::SourcePosition DebugInfo::SourcePosition::from_line_info(Dwarf::LineProgram::LineInfo const& line)
{ {
return { line.file, line.line, { line.address } }; return { line.file, line.line, { line.address } };
} }
@ -393,7 +393,7 @@ DebugInfo::SourcePositionWithInlines DebugInfo::get_source_position_with_inlines
Vector<SourcePosition> inline_chain; Vector<SourcePosition> inline_chain;
auto insert_to_chain = [&](const Dwarf::DIE& die) { auto insert_to_chain = [&](Dwarf::DIE const& die) {
auto caller_source_path = get_source_path_of_inline(die); auto caller_source_path = get_source_path_of_inline(die);
auto caller_line = get_line_of_inline(die); auto caller_line = get_line_of_inline(die);
@ -421,7 +421,7 @@ DebugInfo::SourcePositionWithInlines DebugInfo::get_source_position_with_inlines
return SourcePositionWithInlines { inner_source_position, inline_chain }; return SourcePositionWithInlines { inner_source_position, inline_chain };
} }
Optional<Dwarf::LineProgram::DirectoryAndFile> DebugInfo::get_source_path_of_inline(const Dwarf::DIE& die) const Optional<Dwarf::LineProgram::DirectoryAndFile> DebugInfo::get_source_path_of_inline(Dwarf::DIE const& die) const
{ {
auto caller_file = die.get_attribute(Dwarf::Attribute::CallFile); auto caller_file = die.get_attribute(Dwarf::Attribute::CallFile);
if (caller_file.has_value()) { if (caller_file.has_value()) {
@ -442,7 +442,7 @@ Optional<Dwarf::LineProgram::DirectoryAndFile> DebugInfo::get_source_path_of_inl
return {}; return {};
} }
Optional<uint32_t> DebugInfo::get_line_of_inline(const Dwarf::DIE& die) const Optional<uint32_t> DebugInfo::get_line_of_inline(Dwarf::DIE const& die) const
{ {
auto caller_line = die.get_attribute(Dwarf::Attribute::CallLine); auto caller_line = die.get_attribute(Dwarf::Attribute::CallLine);
if (!caller_line.has_value()) if (!caller_line.has_value())

View file

@ -26,7 +26,7 @@ class DebugInfo {
public: public:
explicit DebugInfo(NonnullOwnPtr<const ELF::Image>, String source_root = {}, FlatPtr base_address = 0); explicit DebugInfo(NonnullOwnPtr<const ELF::Image>, String source_root = {}, FlatPtr base_address = 0);
const ELF::Image& elf() const { return *m_elf; } ELF::Image const& elf() const { return *m_elf; }
struct SourcePosition { struct SourcePosition {
FlyString file_path; FlyString file_path;
@ -49,10 +49,10 @@ public:
{ {
} }
bool operator==(const SourcePosition& other) const { return file_path == other.file_path && line_number == other.line_number; } bool operator==(SourcePosition const& other) const { return file_path == other.file_path && line_number == other.line_number; }
bool operator!=(const SourcePosition& other) const { return !(*this == other); } bool operator!=(SourcePosition const& other) const { return !(*this == other); }
static SourcePosition from_line_info(const Dwarf::LineProgram::LineInfo&); static SourcePosition from_line_info(Dwarf::LineProgram::LineInfo const&);
}; };
struct VariableInfo { struct VariableInfo {
@ -91,7 +91,7 @@ public:
Vector<Dwarf::DIE> dies_of_variables; Vector<Dwarf::DIE> dies_of_variables;
}; };
NonnullOwnPtrVector<VariableInfo> get_variables_in_current_scope(const PtraceRegisters&) const; NonnullOwnPtrVector<VariableInfo> get_variables_in_current_scope(PtraceRegisters const&) const;
Optional<SourcePosition> get_source_position(u32 address) const; Optional<SourcePosition> get_source_position(u32 address) const;

View file

@ -43,7 +43,7 @@ DebugSession::~DebugSession()
} }
} }
OwnPtr<DebugSession> DebugSession::exec_and_attach(const String& command, String source_root) OwnPtr<DebugSession> DebugSession::exec_and_attach(String const& command, String source_root)
{ {
auto pid = fork(); auto pid = fork();
@ -285,7 +285,7 @@ PtraceRegisters DebugSession::get_registers() const
return regs; return regs;
} }
void DebugSession::set_registers(const PtraceRegisters& regs) void DebugSession::set_registers(PtraceRegisters const& regs)
{ {
if (ptrace(PT_SETREGS, m_debuggee_pid, reinterpret_cast<void*>(&const_cast<PtraceRegisters&>(regs)), 0) < 0) { if (ptrace(PT_SETREGS, m_debuggee_pid, reinterpret_cast<void*>(&const_cast<PtraceRegisters&>(regs)), 0) < 0) {
perror("PT_SETREGS"); perror("PT_SETREGS");
@ -349,7 +349,7 @@ void DebugSession::detach()
continue_debuggee(); continue_debuggee();
} }
Optional<DebugSession::InsertBreakpointAtSymbolResult> DebugSession::insert_breakpoint(const String& symbol_name) Optional<DebugSession::InsertBreakpointAtSymbolResult> DebugSession::insert_breakpoint(String const& symbol_name)
{ {
Optional<InsertBreakpointAtSymbolResult> result; Optional<InsertBreakpointAtSymbolResult> result;
for_each_loaded_library([this, symbol_name, &result](auto& lib) { for_each_loaded_library([this, symbol_name, &result](auto& lib) {
@ -372,7 +372,7 @@ Optional<DebugSession::InsertBreakpointAtSymbolResult> DebugSession::insert_brea
return result; return result;
} }
Optional<DebugSession::InsertBreakpointAtSourcePositionResult> DebugSession::insert_breakpoint(const String& filename, size_t line_number) Optional<DebugSession::InsertBreakpointAtSourcePositionResult> DebugSession::insert_breakpoint(String const& filename, size_t line_number)
{ {
auto address_and_source_position = get_address_from_source_position(filename, line_number); auto address_and_source_position = get_address_from_source_position(filename, line_number);
if (!address_and_source_position.has_value()) if (!address_and_source_position.has_value())
@ -402,7 +402,7 @@ void DebugSession::update_loaded_libs()
auto vm_entries = json.value().as_array(); auto vm_entries = json.value().as_array();
Regex<PosixExtended> re("(.+): \\.text"); Regex<PosixExtended> re("(.+): \\.text");
auto get_path_to_object = [&re](const String& vm_name) -> Optional<String> { auto get_path_to_object = [&re](String const& vm_name) -> Optional<String> {
if (vm_name == "/usr/lib/Loader.so") if (vm_name == "/usr/lib/Loader.so")
return vm_name; return vm_name;
RegexResult result; RegexResult result;
@ -470,7 +470,7 @@ Optional<DebugSession::SymbolicationResult> DebugSession::symbolicate(FlatPtr ad
return { { lib->name, symbol } }; return { { lib->name, symbol } };
} }
Optional<DebugInfo::SourcePositionAndAddress> DebugSession::get_address_from_source_position(const String& file, size_t line) const Optional<DebugInfo::SourcePositionAndAddress> DebugSession::get_address_from_source_position(String const& file, size_t line) const
{ {
Optional<DebugInfo::SourcePositionAndAddress> result; Optional<DebugInfo::SourcePositionAndAddress> result;
for_each_loaded_library([this, file, line, &result](auto& lib) { for_each_loaded_library([this, file, line, &result](auto& lib) {

View file

@ -25,7 +25,7 @@ namespace Debug {
class DebugSession { class DebugSession {
public: public:
static OwnPtr<DebugSession> exec_and_attach(const String& command, String source_root = {}); static OwnPtr<DebugSession> exec_and_attach(String const& command, String source_root = {});
~DebugSession(); ~DebugSession();
@ -53,7 +53,7 @@ public:
FlatPtr address { 0 }; FlatPtr address { 0 };
}; };
Optional<InsertBreakpointAtSymbolResult> insert_breakpoint(const String& symbol_name); Optional<InsertBreakpointAtSymbolResult> insert_breakpoint(String const& symbol_name);
struct InsertBreakpointAtSourcePositionResult { struct InsertBreakpointAtSourcePositionResult {
String library_name; String library_name;
@ -62,7 +62,7 @@ public:
FlatPtr address { 0 }; FlatPtr address { 0 };
}; };
Optional<InsertBreakpointAtSourcePositionResult> insert_breakpoint(const String& filename, size_t line_number); Optional<InsertBreakpointAtSourcePositionResult> insert_breakpoint(String const& filename, size_t line_number);
bool insert_breakpoint(void* address); bool insert_breakpoint(void* address);
bool disable_breakpoint(void* address); bool disable_breakpoint(void* address);
@ -89,7 +89,7 @@ public:
} }
PtraceRegisters get_registers() const; PtraceRegisters get_registers() const;
void set_registers(const PtraceRegisters&); void set_registers(PtraceRegisters const&);
enum class ContinueType { enum class ContinueType {
FreeRun, FreeRun,
@ -132,7 +132,7 @@ public:
NonnullOwnPtr<DebugInfo> debug_info; NonnullOwnPtr<DebugInfo> debug_info;
FlatPtr base_address; FlatPtr base_address;
LoadedLibrary(const String& name, NonnullRefPtr<MappedFile> file, NonnullOwnPtr<DebugInfo>&& debug_info, FlatPtr base_address) LoadedLibrary(String const& name, NonnullRefPtr<MappedFile> file, NonnullOwnPtr<DebugInfo>&& debug_info, FlatPtr base_address)
: name(name) : name(name)
, file(move(file)) , file(move(file))
, debug_info(move(debug_info)) , debug_info(move(debug_info))
@ -159,7 +159,7 @@ public:
}; };
Optional<SymbolicationResult> symbolicate(FlatPtr address) const; Optional<SymbolicationResult> symbolicate(FlatPtr address) const;
Optional<DebugInfo::SourcePositionAndAddress> get_address_from_source_position(const String& file, size_t line) const; Optional<DebugInfo::SourcePositionAndAddress> get_address_from_source_position(String const& file, size_t line) const;
Optional<DebugInfo::SourcePosition> get_source_position(FlatPtr address) const; Optional<DebugInfo::SourcePosition> get_source_position(FlatPtr address) const;

View file

@ -11,7 +11,7 @@
namespace Debug::Dwarf { namespace Debug::Dwarf {
AbbreviationsMap::AbbreviationsMap(const DwarfInfo& dwarf_info, u32 offset) AbbreviationsMap::AbbreviationsMap(DwarfInfo const& dwarf_info, u32 offset)
: m_dwarf_info(dwarf_info) : m_dwarf_info(dwarf_info)
, m_offset(offset) , m_offset(offset)
{ {

View file

@ -17,7 +17,7 @@ class DwarfInfo;
class AbbreviationsMap { class AbbreviationsMap {
public: public:
AbbreviationsMap(const DwarfInfo& dwarf_info, u32 offset); AbbreviationsMap(DwarfInfo const& dwarf_info, u32 offset);
struct AbbreviationEntry { struct AbbreviationEntry {
@ -32,7 +32,7 @@ public:
private: private:
void populate_map(); void populate_map();
const DwarfInfo& m_dwarf_info; DwarfInfo const& m_dwarf_info;
u32 m_offset { 0 }; u32 m_offset { 0 };
HashMap<u32, AbbreviationEntry> m_entries; HashMap<u32, AbbreviationEntry> m_entries;
}; };

View file

@ -9,7 +9,7 @@
namespace Debug::Dwarf { namespace Debug::Dwarf {
CompilationUnit::CompilationUnit(const DwarfInfo& dwarf_info, u32 offset, const CompilationUnitHeader& header, NonnullOwnPtr<LineProgram>&& line_program) CompilationUnit::CompilationUnit(DwarfInfo const& dwarf_info, u32 offset, CompilationUnitHeader const& header, NonnullOwnPtr<LineProgram>&& line_program)
: m_dwarf_info(dwarf_info) : m_dwarf_info(dwarf_info)
, m_offset(offset) , m_offset(offset)
, m_header(header) , m_header(header)

View file

@ -23,7 +23,7 @@ class CompilationUnit {
AK_MAKE_NONMOVABLE(CompilationUnit); AK_MAKE_NONMOVABLE(CompilationUnit);
public: public:
CompilationUnit(const DwarfInfo& dwarf_info, u32 offset, const CompilationUnitHeader&, NonnullOwnPtr<LineProgram>&& line_program); CompilationUnit(DwarfInfo const& dwarf_info, u32 offset, CompilationUnitHeader const&, NonnullOwnPtr<LineProgram>&& line_program);
u32 offset() const { return m_offset; } u32 offset() const { return m_offset; }
u32 size() const { return m_header.length() + sizeof(u32); } u32 size() const { return m_header.length() + sizeof(u32); }
@ -31,12 +31,12 @@ public:
DIE root_die() const; DIE root_die() const;
DIE get_die_at_offset(u32 offset) const; DIE get_die_at_offset(u32 offset) const;
const DwarfInfo& dwarf_info() const { return m_dwarf_info; } DwarfInfo const& dwarf_info() const { return m_dwarf_info; }
const AbbreviationsMap& abbreviations_map() const { return m_abbreviations; } AbbreviationsMap const& abbreviations_map() const { return m_abbreviations; }
const LineProgram& line_program() const { return *m_line_program; } LineProgram const& line_program() const { return *m_line_program; }
private: private:
const DwarfInfo& m_dwarf_info; DwarfInfo const& m_dwarf_info;
u32 m_offset { 0 }; u32 m_offset { 0 };
CompilationUnitHeader m_header; CompilationUnitHeader m_header;
AbbreviationsMap m_abbreviations; AbbreviationsMap m_abbreviations;

View file

@ -12,7 +12,7 @@
namespace Debug::Dwarf { namespace Debug::Dwarf {
DIE::DIE(const CompilationUnit& unit, u32 offset, Optional<u32> parent_offset) DIE::DIE(CompilationUnit const& unit, u32 offset, Optional<u32> parent_offset)
: m_compilation_unit(unit) : m_compilation_unit(unit)
, m_offset(offset) , m_offset(offset)
{ {
@ -40,7 +40,7 @@ DIE::DIE(const CompilationUnit& unit, u32 offset, Optional<u32> parent_offset)
m_parent_offset = parent_offset; m_parent_offset = parent_offset;
} }
Optional<AttributeValue> DIE::get_attribute(const Attribute& attribute) const Optional<AttributeValue> DIE::get_attribute(Attribute const& attribute) const
{ {
InputMemoryStream stream { m_compilation_unit.dwarf_info().debug_info_data() }; InputMemoryStream stream { m_compilation_unit.dwarf_info().debug_info_data() };
stream.discard_or_error(m_data_offset); stream.discard_or_error(m_data_offset);
@ -57,7 +57,7 @@ Optional<AttributeValue> DIE::get_attribute(const Attribute& attribute) const
return {}; return {};
} }
void DIE::for_each_child(Function<void(const DIE& child)> callback) const void DIE::for_each_child(Function<void(DIE const& child)> callback) const
{ {
if (!m_has_children) if (!m_has_children)
return; return;
@ -81,7 +81,7 @@ void DIE::for_each_child(Function<void(const DIE& child)> callback) const
if (!sibling.has_value()) { if (!sibling.has_value()) {
// NOTE: According to the spec, the compiler doesn't have to supply the sibling information. // NOTE: According to the spec, the compiler doesn't have to supply the sibling information.
// When it doesn't, we have to recursively iterate the current child's children to find where they end // When it doesn't, we have to recursively iterate the current child's children to find where they end
current_child->for_each_child([&](const DIE& sub_child) { current_child->for_each_child([&](DIE const& sub_child) {
sibling_offset = sub_child.offset() + sub_child.size(); sibling_offset = sub_child.offset() + sub_child.size();
}); });
} }

View file

@ -20,23 +20,23 @@ class CompilationUnit;
// DIE = Debugging Information Entry // DIE = Debugging Information Entry
class DIE { class DIE {
public: public:
DIE(const CompilationUnit&, u32 offset, Optional<u32> parent_offset = {}); DIE(CompilationUnit const&, u32 offset, Optional<u32> parent_offset = {});
u32 offset() const { return m_offset; } u32 offset() const { return m_offset; }
u32 size() const { return m_size; } u32 size() const { return m_size; }
bool has_children() const { return m_has_children; } bool has_children() const { return m_has_children; }
EntryTag tag() const { return m_tag; } EntryTag tag() const { return m_tag; }
Optional<AttributeValue> get_attribute(const Attribute&) const; Optional<AttributeValue> get_attribute(Attribute const&) const;
void for_each_child(Function<void(const DIE& child)> callback) const; void for_each_child(Function<void(DIE const& child)> callback) const;
bool is_null() const { return m_tag == EntryTag::None; } bool is_null() const { return m_tag == EntryTag::None; }
const CompilationUnit& compilation_unit() const { return m_compilation_unit; } CompilationUnit const& compilation_unit() const { return m_compilation_unit; }
Optional<u32> parent_offset() const { return m_parent_offset; } Optional<u32> parent_offset() const { return m_parent_offset; }
private: private:
const CompilationUnit& m_compilation_unit; CompilationUnit const& m_compilation_unit;
u32 m_offset { 0 }; u32 m_offset { 0 };
u32 m_data_offset { 0 }; u32 m_data_offset { 0 };
size_t m_abbreviation_code { 0 }; size_t m_abbreviation_code { 0 };

View file

@ -13,7 +13,7 @@
namespace Debug::Dwarf { namespace Debug::Dwarf {
DwarfInfo::DwarfInfo(const ELF::Image& elf) DwarfInfo::DwarfInfo(ELF::Image const& elf)
: m_elf(elf) : m_elf(elf)
{ {
m_debug_info_data = section_data(".debug_info"sv); m_debug_info_data = section_data(".debug_info"sv);
@ -25,7 +25,7 @@ DwarfInfo::DwarfInfo(const ELF::Image& elf)
populate_compilation_units(); populate_compilation_units();
} }
ReadonlyBytes DwarfInfo::section_data(const StringView& section_name) const ReadonlyBytes DwarfInfo::section_data(StringView const& section_name) const
{ {
auto section = m_elf.lookup_section(section_name); auto section = m_elf.lookup_section(section_name);
if (!section.has_value()) if (!section.has_value())
@ -237,11 +237,11 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
void DwarfInfo::build_cached_dies() const void DwarfInfo::build_cached_dies() const
{ {
auto insert_to_cache = [this](const DIE& die, DIERange& range) { auto insert_to_cache = [this](DIE const& die, DIERange const& range) {
m_cached_dies_by_range.insert(range.start_address, DIEAndRange { die, range }); m_cached_dies_by_range.insert(range.start_address, DIEAndRange { die, range });
m_cached_dies_by_offset.insert(die.offset(), die); m_cached_dies_by_offset.insert(die.offset(), die);
}; };
auto get_ranges_of_die = [this](const DIE& die) -> Vector<DIERange> { auto get_ranges_of_die = [this](DIE const& die) -> Vector<DIERange> {
// TODO support DW_AT_ranges (appears when range is non-contiguous) // TODO support DW_AT_ranges (appears when range is non-contiguous)
auto start = die.get_attribute(Attribute::LowPc); auto start = die.get_attribute(Attribute::LowPc);
@ -266,22 +266,22 @@ void DwarfInfo::build_cached_dies() const
}; };
// If we simply use a lambda, type deduction fails because it's used recursively. // If we simply use a lambda, type deduction fails because it's used recursively.
Function<void(const DIE& die)> insert_to_cache_recursively; Function<void(DIE const& die)> insert_to_cache_recursively;
insert_to_cache_recursively = [&](const DIE& die) { insert_to_cache_recursively = [&](DIE const& die) {
if (die.offset() == 0 || die.parent_offset().has_value()) { if (die.offset() == 0 || die.parent_offset().has_value()) {
auto ranges = get_ranges_of_die(die); auto ranges = get_ranges_of_die(die);
for (auto& range : ranges) { for (auto& range : ranges) {
insert_to_cache(die, range); insert_to_cache(die, range);
} }
} }
die.for_each_child([&](const DIE& child) { die.for_each_child([&](DIE const& child) {
if (!child.is_null()) { if (!child.is_null()) {
insert_to_cache_recursively(child); insert_to_cache_recursively(child);
} }
}); });
}; };
for_each_compilation_unit([&](const CompilationUnit& compilation_unit) { for_each_compilation_unit([&](CompilationUnit const& compilation_unit) {
insert_to_cache_recursively(compilation_unit.root_die()); insert_to_cache_recursively(compilation_unit.root_die());
}); });

View file

@ -24,7 +24,7 @@ class DwarfInfo {
AK_MAKE_NONMOVABLE(DwarfInfo); AK_MAKE_NONMOVABLE(DwarfInfo);
public: public:
explicit DwarfInfo(const ELF::Image&); explicit DwarfInfo(ELF::Image const&);
ReadonlyBytes debug_info_data() const { return m_debug_info_data; } ReadonlyBytes debug_info_data() const { return m_debug_info_data; }
ReadonlyBytes abbreviation_data() const { return m_abbreviation_data; } ReadonlyBytes abbreviation_data() const { return m_abbreviation_data; }
@ -50,9 +50,9 @@ private:
void populate_compilation_units(); void populate_compilation_units();
void build_cached_dies() const; void build_cached_dies() const;
ReadonlyBytes section_data(const StringView& section_name) const; ReadonlyBytes section_data(StringView const& section_name) const;
const ELF::Image& m_elf; ELF::Image const& m_elf;
ReadonlyBytes m_debug_info_data; ReadonlyBytes m_debug_info_data;
ReadonlyBytes m_abbreviation_data; ReadonlyBytes m_abbreviation_data;
ReadonlyBytes m_debug_strings_data; ReadonlyBytes m_debug_strings_data;

View file

@ -12,7 +12,7 @@
namespace Debug::Dwarf::Expression { namespace Debug::Dwarf::Expression {
Value evaluate(ReadonlyBytes bytes, const PtraceRegisters& regs) Value evaluate(ReadonlyBytes bytes, PtraceRegisters const& regs)
{ {
InputMemoryStream stream(bytes); InputMemoryStream stream(bytes);

View file

@ -31,6 +31,6 @@ enum class Operations : u8 {
FbReg = 0x91, FbReg = 0x91,
}; };
Value evaluate(ReadonlyBytes, const PtraceRegisters&); Value evaluate(ReadonlyBytes, PtraceRegisters const&);
} }

View file

@ -114,7 +114,7 @@ public:
size_t line { 0 }; size_t line { 0 };
}; };
const Vector<LineInfo>& lines() const { return m_lines; } Vector<LineInfo> const& lines() const { return m_lines; }
struct DirectoryAndFile { struct DirectoryAndFile {
FlyString directory; FlyString directory;

View file

@ -8,7 +8,7 @@
namespace Debug::StackFrameUtils { namespace Debug::StackFrameUtils {
Optional<StackFrameInfo> get_info(const DebugSession& session, FlatPtr current_ebp) Optional<StackFrameInfo> get_info(DebugSession const& session, FlatPtr current_ebp)
{ {
auto return_address = session.peek(reinterpret_cast<u32*>(current_ebp + sizeof(FlatPtr))); auto return_address = session.peek(reinterpret_cast<u32*>(current_ebp + sizeof(FlatPtr)));
auto next_ebp = session.peek(reinterpret_cast<u32*>(current_ebp)); auto next_ebp = session.peek(reinterpret_cast<u32*>(current_ebp));

View file

@ -18,6 +18,6 @@ struct StackFrameInfo {
FlatPtr next_ebp; FlatPtr next_ebp;
}; };
Optional<StackFrameInfo> get_info(const DebugSession&, FlatPtr current_ebp); Optional<StackFrameInfo> get_info(DebugSession const&, FlatPtr current_ebp);
} }