DIE.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include "CompilationUnit.h"
  28. #include "DwarfTypes.h"
  29. #include <AK/Function.h>
  30. #include <AK/NonnullOwnPtr.h>
  31. #include <AK/Optional.h>
  32. #include <AK/Types.h>
  33. namespace Dwarf {
  34. class CompilationUnit;
  35. // DIE = Debugging Information Entry
  36. class DIE {
  37. public:
  38. DIE(const CompilationUnit&, u32 offset);
  39. struct AttributeValue {
  40. enum class Type {
  41. UnsignedNumber,
  42. SignedNumber,
  43. String,
  44. DieReference, // Reference to another DIE in the same compilation unit
  45. Boolean,
  46. DwarfExpression,
  47. SecOffset,
  48. RawBytes,
  49. } type;
  50. union {
  51. u32 as_u32;
  52. i32 as_i32;
  53. const char* as_string; // points to bytes in the memory mapped elf image
  54. bool as_bool;
  55. struct {
  56. u32 length;
  57. const u8* bytes; // points to bytes in the memory mapped elf image
  58. } as_raw_bytes;
  59. } data {};
  60. };
  61. u32 offset() const { return m_offset; }
  62. u32 size() const { return m_size; }
  63. bool has_children() const { return m_has_children; }
  64. EntryTag tag() const { return m_tag; }
  65. Optional<AttributeValue> get_attribute(const Attribute&) const;
  66. void for_each_child(Function<void(const DIE& child)> callback) const;
  67. bool is_null() const { return m_tag == EntryTag::None; }
  68. DIE get_die_at_offset(u32 offset) const;
  69. private:
  70. AttributeValue get_attribute_value(AttributeDataForm form,
  71. InputMemoryStream& debug_info_stream) const;
  72. const CompilationUnit& m_compilation_unit;
  73. u32 m_offset { 0 };
  74. u32 m_data_offset { 0 };
  75. size_t m_abbreviation_code { 0 };
  76. EntryTag m_tag { EntryTag::None };
  77. bool m_has_children { false };
  78. u32 m_size { 0 };
  79. };
  80. }