2020-05-04 12:14:39 +03:00
|
|
|
/*
|
2021-06-19 11:50:24 +03:00
|
|
|
* Copyright (c) 2020-2021, Itamar S. <itamar8910@gmail.com>
|
2020-05-04 12:14:39 +03:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-04 12:14:39 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DwarfInfo.h"
|
2021-09-28 13:35:28 +03:00
|
|
|
#include "AddressRanges.h"
|
2021-06-19 11:34:59 +03:00
|
|
|
#include "AttributeValue.h"
|
2021-06-19 11:50:24 +03:00
|
|
|
#include "CompilationUnit.h"
|
2020-05-04 12:14:39 +03:00
|
|
|
|
2020-09-01 11:43:32 +02:00
|
|
|
#include <AK/MemoryStream.h>
|
2021-06-19 11:50:24 +03:00
|
|
|
#include <LibDebug/DebugInfo.h>
|
2020-08-05 10:55:36 +02:00
|
|
|
|
2020-08-25 04:33:07 +01:00
|
|
|
namespace Debug::Dwarf {
|
2020-05-04 12:14:39 +03:00
|
|
|
|
2021-06-19 15:33:03 +03:00
|
|
|
DwarfInfo::DwarfInfo(ELF::Image const& elf)
|
2020-05-04 12:14:39 +03:00
|
|
|
: m_elf(elf)
|
|
|
|
|
{
|
2021-05-30 23:44:02 -07:00
|
|
|
m_debug_info_data = section_data(".debug_info"sv);
|
|
|
|
|
m_abbreviation_data = section_data(".debug_abbrev"sv);
|
|
|
|
|
m_debug_strings_data = section_data(".debug_str"sv);
|
2021-06-18 15:25:27 +03:00
|
|
|
m_debug_line_data = section_data(".debug_line"sv);
|
2021-05-30 23:44:02 -07:00
|
|
|
m_debug_line_strings_data = section_data(".debug_line_str"sv);
|
2021-09-28 13:35:28 +03:00
|
|
|
m_debug_range_lists_data = section_data(".debug_rnglists"sv);
|
2021-10-09 17:38:26 +02:00
|
|
|
m_debug_str_offsets_data = section_data(".debug_str_offsets"sv);
|
|
|
|
|
m_debug_addr_data = section_data(".debug_addr"sv);
|
2020-05-04 12:14:39 +03:00
|
|
|
|
|
|
|
|
populate_compilation_units();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 15:33:03 +03:00
|
|
|
ReadonlyBytes DwarfInfo::section_data(StringView const& section_name) const
|
2020-05-04 12:14:39 +03:00
|
|
|
{
|
2020-12-25 02:14:56 +01:00
|
|
|
auto section = m_elf.lookup_section(section_name);
|
2021-05-15 00:13:44 +02:00
|
|
|
if (!section.has_value())
|
2020-05-23 14:55:39 +03:00
|
|
|
return {};
|
2021-05-15 00:13:44 +02:00
|
|
|
return section->bytes();
|
2020-05-04 12:14:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DwarfInfo::populate_compilation_units()
|
|
|
|
|
{
|
2020-12-19 13:14:00 +01:00
|
|
|
if (!m_debug_info_data.data())
|
2020-05-23 14:55:39 +03:00
|
|
|
return;
|
2020-08-05 10:55:36 +02:00
|
|
|
|
2021-06-18 15:25:27 +03:00
|
|
|
InputMemoryStream debug_info_stream { m_debug_info_data };
|
|
|
|
|
InputMemoryStream line_info_stream { m_debug_line_data };
|
|
|
|
|
|
|
|
|
|
while (!debug_info_stream.eof()) {
|
|
|
|
|
auto unit_offset = debug_info_stream.offset();
|
2020-05-04 12:14:39 +03:00
|
|
|
CompilationUnitHeader compilation_unit_header {};
|
|
|
|
|
|
2021-06-18 15:25:27 +03:00
|
|
|
debug_info_stream >> compilation_unit_header;
|
2021-04-28 22:13:58 +02:00
|
|
|
VERIFY(compilation_unit_header.common.version <= 5);
|
2021-07-13 18:16:36 +02:00
|
|
|
VERIFY(compilation_unit_header.address_size() == sizeof(FlatPtr));
|
2020-05-04 12:14:39 +03:00
|
|
|
|
2021-04-28 22:13:58 +02:00
|
|
|
u32 length_after_header = compilation_unit_header.length() - (compilation_unit_header.header_size() - offsetof(CompilationUnitHeader, common.version));
|
2021-06-18 15:25:27 +03:00
|
|
|
|
|
|
|
|
auto line_program = make<LineProgram>(*this, line_info_stream);
|
|
|
|
|
|
|
|
|
|
m_compilation_units.append(make<CompilationUnit>(*this, unit_offset, compilation_unit_header, move(line_program)));
|
|
|
|
|
debug_info_stream.discard_or_error(length_after_header);
|
2020-05-04 12:14:39 +03:00
|
|
|
}
|
2021-06-18 15:25:27 +03:00
|
|
|
|
|
|
|
|
VERIFY(line_info_stream.eof());
|
2020-05-04 12:14:39 +03:00
|
|
|
}
|
|
|
|
|
|
2021-04-29 00:51:54 +02:00
|
|
|
AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t implicit_const_value,
|
2021-04-28 20:12:21 +02:00
|
|
|
InputMemoryStream& debug_info_stream, const CompilationUnit* unit) const
|
|
|
|
|
{
|
|
|
|
|
AttributeValue value;
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_form = form;
|
|
|
|
|
value.m_compilation_unit = unit;
|
2021-04-28 20:12:21 +02:00
|
|
|
|
|
|
|
|
auto assign_raw_bytes_value = [&](size_t length) {
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_data.as_raw_bytes = { reinterpret_cast<const u8*>(debug_info_data().data() + debug_info_stream.offset()), length };
|
2021-04-28 20:12:21 +02:00
|
|
|
|
|
|
|
|
debug_info_stream.discard_or_error(length);
|
2021-10-09 16:58:48 +02:00
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-04-28 20:12:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch (form) {
|
|
|
|
|
case AttributeDataForm::StringPointer: {
|
|
|
|
|
u32 offset;
|
|
|
|
|
debug_info_stream >> offset;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::String;
|
2021-04-28 20:12:21 +02:00
|
|
|
|
|
|
|
|
auto strings_data = debug_strings_data();
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_data.as_string = reinterpret_cast<const char*>(strings_data.data() + offset);
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Data1: {
|
|
|
|
|
u8 data;
|
|
|
|
|
debug_info_stream >> data;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::UnsignedNumber;
|
|
|
|
|
value.m_data.as_unsigned = data;
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Data2: {
|
|
|
|
|
u16 data;
|
|
|
|
|
debug_info_stream >> data;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::UnsignedNumber;
|
|
|
|
|
value.m_data.as_signed = data;
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Addr: {
|
2021-07-13 18:16:36 +02:00
|
|
|
FlatPtr address;
|
2021-04-28 20:12:21 +02:00
|
|
|
debug_info_stream >> address;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::Address;
|
|
|
|
|
value.m_data.as_addr = address;
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::SData: {
|
2021-07-27 11:03:24 +02:00
|
|
|
i64 data;
|
2021-04-28 20:12:21 +02:00
|
|
|
debug_info_stream.read_LEB128_signed(data);
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::SignedNumber;
|
|
|
|
|
value.m_data.as_signed = data;
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2021-04-28 22:15:51 +02:00
|
|
|
case AttributeDataForm::UData: {
|
2021-07-27 11:03:24 +02:00
|
|
|
u64 data;
|
2021-04-28 22:15:51 +02:00
|
|
|
debug_info_stream.read_LEB128_unsigned(data);
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::UnsignedNumber;
|
|
|
|
|
value.m_data.as_unsigned = data;
|
2021-04-28 22:15:51 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2021-04-28 20:12:21 +02:00
|
|
|
case AttributeDataForm::SecOffset: {
|
|
|
|
|
u32 data;
|
|
|
|
|
debug_info_stream >> data;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::SecOffset;
|
|
|
|
|
value.m_data.as_unsigned = data;
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Data4: {
|
|
|
|
|
u32 data;
|
|
|
|
|
debug_info_stream >> data;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::UnsignedNumber;
|
|
|
|
|
value.m_data.as_unsigned = data;
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Data8: {
|
|
|
|
|
u64 data;
|
|
|
|
|
debug_info_stream >> data;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::UnsignedNumber;
|
|
|
|
|
value.m_data.as_unsigned = data;
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Ref4: {
|
|
|
|
|
u32 data;
|
|
|
|
|
debug_info_stream >> data;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::DieReference;
|
2021-04-28 20:12:21 +02:00
|
|
|
VERIFY(unit);
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_data.as_unsigned = data + unit->offset();
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::FlagPresent: {
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::Boolean;
|
|
|
|
|
value.m_data.as_bool = true;
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::ExprLoc: {
|
|
|
|
|
size_t length;
|
|
|
|
|
debug_info_stream.read_LEB128_unsigned(length);
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::DwarfExpression;
|
2021-04-28 20:12:21 +02:00
|
|
|
assign_raw_bytes_value(length);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::String: {
|
|
|
|
|
String str;
|
|
|
|
|
u32 str_offset = debug_info_stream.offset();
|
|
|
|
|
debug_info_stream >> str;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::String;
|
|
|
|
|
value.m_data.as_string = reinterpret_cast<const char*>(str_offset + debug_info_data().data());
|
2021-04-28 20:12:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Block1: {
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::RawBytes;
|
2021-04-28 20:12:21 +02:00
|
|
|
u8 length;
|
|
|
|
|
debug_info_stream >> length;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
assign_raw_bytes_value(length);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Block2: {
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::RawBytes;
|
2021-04-28 20:12:21 +02:00
|
|
|
u16 length;
|
|
|
|
|
debug_info_stream >> length;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
assign_raw_bytes_value(length);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Block4: {
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::RawBytes;
|
2021-04-28 20:12:21 +02:00
|
|
|
u32 length;
|
|
|
|
|
debug_info_stream >> length;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
assign_raw_bytes_value(length);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::Block: {
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::RawBytes;
|
2021-04-28 20:12:21 +02:00
|
|
|
size_t length;
|
|
|
|
|
debug_info_stream.read_LEB128_unsigned(length);
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
assign_raw_bytes_value(length);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-04-28 22:15:51 +02:00
|
|
|
case AttributeDataForm::LineStrP: {
|
|
|
|
|
u32 offset;
|
|
|
|
|
debug_info_stream >> offset;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::String;
|
2021-04-28 22:15:51 +02:00
|
|
|
|
|
|
|
|
auto strings_data = debug_line_strings_data();
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_data.as_string = reinterpret_cast<const char*>(strings_data.data() + offset);
|
2021-04-28 22:15:51 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2021-04-29 00:51:54 +02:00
|
|
|
case AttributeDataForm::ImplicitConst: {
|
|
|
|
|
/* Value is part of the abbreviation record. */
|
2021-10-09 16:58:48 +02:00
|
|
|
value.m_type = AttributeValue::Type::SignedNumber;
|
|
|
|
|
value.m_data.as_signed = implicit_const_value;
|
2021-04-29 00:51:54 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2021-10-09 17:38:26 +02:00
|
|
|
case AttributeDataForm::StrX1: {
|
|
|
|
|
u8 index;
|
|
|
|
|
debug_info_stream >> index;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
value.m_type = AttributeValue::Type::String;
|
|
|
|
|
value.m_data.as_unsigned = index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::StrX2: {
|
|
|
|
|
u16 index;
|
|
|
|
|
debug_info_stream >> index;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
value.m_type = AttributeValue::Type::String;
|
|
|
|
|
value.m_data.as_unsigned = index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::StrX4: {
|
|
|
|
|
u32 index;
|
|
|
|
|
debug_info_stream >> index;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
value.m_type = AttributeValue::Type::String;
|
|
|
|
|
value.m_data.as_unsigned = index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::StrX: {
|
|
|
|
|
size_t index;
|
|
|
|
|
debug_info_stream.read_LEB128_unsigned(index);
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
value.m_type = AttributeValue::Type::String;
|
|
|
|
|
value.m_data.as_unsigned = index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::AddrX1: {
|
|
|
|
|
u8 index;
|
|
|
|
|
debug_info_stream >> index;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
value.m_type = AttributeValue::Type::Address;
|
|
|
|
|
value.m_data.as_unsigned = index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::AddrX2: {
|
|
|
|
|
u16 index;
|
|
|
|
|
debug_info_stream >> index;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
value.m_type = AttributeValue::Type::Address;
|
|
|
|
|
value.m_data.as_unsigned = index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::AddrX4: {
|
|
|
|
|
u32 index;
|
|
|
|
|
debug_info_stream >> index;
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
value.m_type = AttributeValue::Type::Address;
|
|
|
|
|
value.m_data.as_unsigned = index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::AddrX: {
|
|
|
|
|
size_t index;
|
|
|
|
|
debug_info_stream.read_LEB128_unsigned(index);
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
value.m_type = AttributeValue::Type::Address;
|
|
|
|
|
value.m_data.as_unsigned = index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AttributeDataForm::RngListX: {
|
|
|
|
|
size_t index;
|
|
|
|
|
debug_info_stream.read_LEB128_unsigned(index);
|
|
|
|
|
VERIFY(!debug_info_stream.has_any_error());
|
|
|
|
|
value.m_type = AttributeValue::Type::UnsignedNumber;
|
|
|
|
|
value.m_data.as_unsigned = index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-04-28 20:12:21 +02:00
|
|
|
default:
|
|
|
|
|
dbgln("Unimplemented AttributeDataForm: {}", (u32)form);
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 11:50:24 +03:00
|
|
|
void DwarfInfo::build_cached_dies() const
|
|
|
|
|
{
|
2021-06-19 15:33:03 +03:00
|
|
|
auto insert_to_cache = [this](DIE const& die, DIERange const& range) {
|
2021-06-19 11:50:24 +03:00
|
|
|
m_cached_dies_by_range.insert(range.start_address, DIEAndRange { die, range });
|
|
|
|
|
m_cached_dies_by_offset.insert(die.offset(), die);
|
|
|
|
|
};
|
2021-09-28 13:35:28 +03:00
|
|
|
auto get_ranges_of_die = [this](DIE const& die) -> Vector<DIERange> {
|
|
|
|
|
auto ranges = die.get_attribute(Attribute::Ranges);
|
|
|
|
|
if (ranges.has_value()) {
|
|
|
|
|
// TODO Support DW_FORM_rnglistx
|
2021-10-09 16:58:48 +02:00
|
|
|
if (ranges->form() != AttributeDataForm::SecOffset)
|
2021-09-28 13:35:28 +03:00
|
|
|
return {};
|
2021-10-09 16:58:48 +02:00
|
|
|
auto offset = ranges->as_unsigned();
|
2021-09-28 13:35:28 +03:00
|
|
|
AddressRanges address_ranges(debug_range_lists_data(), offset, die.compilation_unit());
|
|
|
|
|
Vector<DIERange> entries;
|
|
|
|
|
address_ranges.for_each_range([&entries](auto range) {
|
|
|
|
|
entries.empend(range.start, range.end);
|
|
|
|
|
});
|
|
|
|
|
return entries;
|
|
|
|
|
}
|
2021-06-19 11:50:24 +03:00
|
|
|
|
|
|
|
|
auto start = die.get_attribute(Attribute::LowPc);
|
|
|
|
|
auto end = die.get_attribute(Attribute::HighPc);
|
|
|
|
|
|
|
|
|
|
if (!start.has_value() || !end.has_value())
|
|
|
|
|
return {};
|
|
|
|
|
|
2021-10-09 16:58:48 +02:00
|
|
|
VERIFY(start->type() == Dwarf::AttributeValue::Type::Address);
|
2021-06-19 11:50:24 +03:00
|
|
|
|
|
|
|
|
// DW_AT_high_pc attribute can have different meanings depending on the attribute form.
|
|
|
|
|
// (Dwarf version 5, section 2.17.2).
|
|
|
|
|
|
|
|
|
|
uint32_t range_end = 0;
|
2021-10-09 16:58:48 +02:00
|
|
|
if (end->form() == Dwarf::AttributeDataForm::Addr)
|
|
|
|
|
range_end = end->as_addr();
|
2021-06-19 11:50:24 +03:00
|
|
|
else
|
2021-10-09 16:58:48 +02:00
|
|
|
range_end = start->as_addr() + end->as_unsigned();
|
2021-06-19 11:50:24 +03:00
|
|
|
|
2021-10-09 16:58:48 +02:00
|
|
|
return { DIERange { start.value().as_addr(), range_end } };
|
2021-06-19 11:50:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// If we simply use a lambda, type deduction fails because it's used recursively.
|
2021-06-19 15:33:03 +03:00
|
|
|
Function<void(DIE const& die)> insert_to_cache_recursively;
|
|
|
|
|
insert_to_cache_recursively = [&](DIE const& die) {
|
2021-06-19 11:50:24 +03:00
|
|
|
if (die.offset() == 0 || die.parent_offset().has_value()) {
|
|
|
|
|
auto ranges = get_ranges_of_die(die);
|
|
|
|
|
for (auto& range : ranges) {
|
|
|
|
|
insert_to_cache(die, range);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-19 15:33:03 +03:00
|
|
|
die.for_each_child([&](DIE const& child) {
|
2021-06-19 11:50:24 +03:00
|
|
|
if (!child.is_null()) {
|
|
|
|
|
insert_to_cache_recursively(child);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-19 15:33:03 +03:00
|
|
|
for_each_compilation_unit([&](CompilationUnit const& compilation_unit) {
|
2021-06-19 11:50:24 +03:00
|
|
|
insert_to_cache_recursively(compilation_unit.root_die());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
m_built_cached_dies = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 11:59:48 +03:00
|
|
|
Optional<DIE> DwarfInfo::get_die_at_address(FlatPtr address) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_built_cached_dies)
|
|
|
|
|
build_cached_dies();
|
|
|
|
|
|
|
|
|
|
auto iter = m_cached_dies_by_range.find_largest_not_above_iterator(address);
|
|
|
|
|
while (!iter.is_end() && !iter.is_begin() && iter->range.end_address < address) {
|
|
|
|
|
--iter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (iter.is_end())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
if (iter->range.start_address > address || iter->range.end_address < address) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return iter->die;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 12:03:14 +03:00
|
|
|
Optional<DIE> DwarfInfo::get_cached_die_at_offset(FlatPtr offset) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_built_cached_dies)
|
|
|
|
|
build_cached_dies();
|
|
|
|
|
|
|
|
|
|
auto* die = m_cached_dies_by_offset.find(offset);
|
|
|
|
|
if (!die)
|
|
|
|
|
return {};
|
|
|
|
|
return *die;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 12:14:39 +03:00
|
|
|
}
|