1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:57:47 +00:00

LibDebug: Don't expose AttributeValue internals, use getters instead

This will be needed when we add `DW_FORM_strx*` and `DW_FORM_addrx*`
support, which requires us to fetch `DW_AT_str_offsets_base` and
`DW_AT_addr_base` attributes from the parent compilation unit. This
can't be done as we read the values, because it would create infinite
recursion (as we might try to parse the compilation unit's
`DW_FORM_strx*` encoded name before we get to the attribute). Having
getters ensures that we will perform lookups if they are needed.
This commit is contained in:
Daniel Bertalan 2021-10-09 16:58:48 +02:00 committed by Linus Groh
parent 1b63c8f3b0
commit 8e5b70a0ba
6 changed files with 101 additions and 80 deletions

View file

@ -6,12 +6,18 @@
#pragma once
#include <AK/Span.h>
#include <AK/Types.h>
#include <LibDebug/Dwarf/DwarfTypes.h>
namespace Debug::Dwarf {
struct AttributeValue {
class CompilationUnit;
class AttributeValue {
friend class DwarfInfo;
public:
enum class Type : u8 {
UnsignedNumber,
SignedNumber,
@ -21,21 +27,33 @@ struct AttributeValue {
DwarfExpression,
SecOffset,
RawBytes,
} type;
Address
};
Type type() const { return m_type; }
AttributeDataForm form() const { return m_form; }
FlatPtr as_addr() const { return m_data.as_addr; }
u64 as_unsigned() const { return m_data.as_unsigned; }
i64 as_signed() const { return m_data.as_signed; }
const char* as_string() const { return m_data.as_string; }
bool as_bool() const { return m_data.as_bool; }
ReadonlyBytes as_raw_bytes() const { return m_data.as_raw_bytes; }
private:
Type m_type;
union {
FlatPtr as_addr;
u64 as_unsigned;
i64 as_signed;
const char* as_string; // points to bytes in the memory mapped elf image
bool as_bool;
struct {
u32 length;
const u8* bytes; // points to bytes in the memory mapped elf image
} as_raw_bytes;
} data {};
ReadonlyBytes as_raw_bytes;
} m_data {};
AttributeDataForm form {};
AttributeDataForm m_form {};
CompilationUnit const* m_compilation_unit { nullptr };
};
}