summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibDebug/Dwarf/DIE.h
blob: 7062b6f3d556c617c74118cc6930aa07577ecc5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Copyright (c) 2020-2021, Itamar S. <itamar8910@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include "AttributeValue.h"
#include "DwarfTypes.h"
#include <AK/Function.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/Optional.h>
#include <AK/Types.h>

namespace Debug::Dwarf {

class CompilationUnit;

// DIE = Debugging Information Entry
class DIE {
public:
    DIE(CompilationUnit const&, u32 offset, Optional<u32> parent_offset = {});

    u32 offset() const { return m_offset; }
    u32 size() const { return m_size; }
    bool has_children() const { return m_has_children; }
    EntryTag tag() const { return m_tag; }

    Optional<AttributeValue> get_attribute(Attribute const&) const;

    void for_each_child(Function<void(DIE const& child)> callback) const;

    bool is_null() const { return m_tag == EntryTag::None; }
    CompilationUnit const& compilation_unit() const { return m_compilation_unit; }
    Optional<u32> parent_offset() const { return m_parent_offset; }

private:
    CompilationUnit const& m_compilation_unit;
    u32 m_offset { 0 };
    u32 m_data_offset { 0 };
    size_t m_abbreviation_code { 0 };
    EntryTag m_tag { EntryTag::None };
    bool m_has_children { false };
    u32 m_size { 0 };
    Optional<u32> m_parent_offset;
};

}