AttributeValue.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Span.h>
  8. #include <AK/Types.h>
  9. #include <LibDebug/Dwarf/DwarfTypes.h>
  10. namespace Debug::Dwarf {
  11. class CompilationUnit;
  12. class AttributeValue {
  13. friend class DwarfInfo;
  14. public:
  15. enum class Type : u8 {
  16. UnsignedNumber,
  17. SignedNumber,
  18. String,
  19. DieReference, // Reference to another DIE in the same compilation unit
  20. Boolean,
  21. DwarfExpression,
  22. SecOffset,
  23. RawBytes,
  24. Address
  25. };
  26. Type type() const { return m_type; }
  27. AttributeDataForm form() const { return m_form; }
  28. ErrorOr<FlatPtr> as_addr() const;
  29. u64 as_unsigned() const { return m_data.as_unsigned; }
  30. i64 as_signed() const { return m_data.as_signed; }
  31. ErrorOr<char const*> as_string() const;
  32. bool as_bool() const { return m_data.as_bool; }
  33. ReadonlyBytes as_raw_bytes() const { return m_data.as_raw_bytes; }
  34. private:
  35. Type m_type;
  36. union {
  37. FlatPtr as_addr;
  38. u64 as_unsigned;
  39. i64 as_signed;
  40. char const* as_string; // points to bytes in the memory mapped elf image
  41. bool as_bool;
  42. ReadonlyBytes as_raw_bytes;
  43. } m_data {};
  44. AttributeDataForm m_form {};
  45. CompilationUnit const* m_compilation_unit { nullptr };
  46. };
  47. }