File Coverage

src/panda/dwarf.h
Criterion Covered Total %
statement 1 5 20.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 1 5 20.0


line stmt bran cond sub pod time code
1             #pragma once
2              
3             #include "SharedObjectInfo.h"
4             #include
5             #include
6             #include
7             #include
8             #include
9             #include
10             #include
11             #include
12              
13             namespace panda { namespace backtrace {
14              
15             namespace dwarf {
16              
17             struct HighLow {
18             Dwarf_Addr high;
19             Dwarf_Addr low;
20             };
21              
22             enum class Match { yes, no, unknown };
23             enum class Scan { found, not_found, dead_end };
24              
25             struct DieHolder;
26             struct LookupResult;
27             struct DieRC;
28             using DieSP = panda::iptr;
29             struct CU;
30             using CUSP = panda::iptr;
31             using DieCollection = std::list;
32              
33 0           struct FunctionDetails {
34             panda::string name;
35             DieSP name_die = nullptr;
36             std::uint64_t line_no = 0;
37             panda::string source;
38             };
39              
40             struct DieRC: panda::Refcnt {
41             Dwarf_Die die;
42             Dwarf_Debug debug;
43             DieSP parent;
44             DieCollection context;
45              
46 0           struct FQN {
47             string full_name;
48             DieSP source_die;
49             };
50              
51             DieRC(Dwarf_Die die_, Dwarf_Debug debug_, DieSP parent_);
52             ~DieRC();
53              
54             Dwarf_Die resolve_ref(Dwarf_Die source, Dwarf_Half attribute) noexcept;
55             DieSP discover(Dwarf_Die target) noexcept;
56             DieSP discover(Dwarf_Off target_offset, DieHolder& node) noexcept;
57             FQN gather_fqn() noexcept;
58             DieSP refine_location(std::uint64_t offset) noexcept;
59             FunctionDetails refine_fn(LookupResult& lr) noexcept;
60             void refine_fn_ao(Dwarf_Die abstract_origin, FunctionDetails& details) noexcept;
61             void refine_fn_name(Dwarf_Die it, FunctionDetails& details) noexcept;
62             void refine_fn_line(Dwarf_Die die, std::uint64_t offset, FunctionDetails& details) noexcept;
63             void refine_fn_line_fallback(Dwarf_Die it, FunctionDetails& details) noexcept;
64             void refine_fn_source(Dwarf_Die it, FunctionDetails& details, CU& cu) noexcept;
65             void refine_fn_spec(Dwarf_Die specification, FunctionDetails& details) noexcept;
66             };
67              
68             struct DieHolder {
69             Dwarf_Die die;
70             Dwarf_Debug debug;
71             DieHolder *parent;
72             DieSP owner;
73              
74             DieHolder(DieSP owner);
75             DieHolder(Dwarf_Die die_, Dwarf_Debug debug_, DieHolder* parent);
76             DieHolder(const DieHolder&) = delete;
77             DieHolder(DieHolder&&) = delete;
78              
79             DieSP detach();
80              
81             panda::optional get_addr() noexcept;
82             Match contains(std::uint64_t offset) noexcept;
83             ~DieHolder();
84             };
85              
86 0           struct LookupResult {
87 0           LookupResult(CU& root_) noexcept: root{CUSP{&root_}} {}
88             LookupResult(const LookupResult&) = delete;
89             LookupResult(LookupResult&&);
90              
91             bool is_complete() noexcept;
92             bool get_frames(std::uint64_t ip, const SharedObjectInfo& so, StackFrames& frames) noexcept;
93              
94             CUSP root;
95             DieSP cu;
96             DieSP subprogram;
97             std::uint64_t offset{0};
98             };
99              
100             struct CU: panda::Refcnt {
101             Dwarf_Debug debug;
102             int number;
103              
104             Dwarf_Unsigned header_length = 0;
105             Dwarf_Unsigned abbrev_offset = 0;
106             Dwarf_Half address_size = 0;
107             Dwarf_Half version_stamp = 0;
108             Dwarf_Half offset_size = 0;
109             Dwarf_Half extension_size = 0;
110             Dwarf_Unsigned typeoffset = 0;
111             Dwarf_Half header_type = DW_UT_compile;
112             Dwarf_Sig8 signature;
113             Dwarf_Off cu_offset = 0;
114             DieSP cu_die;
115              
116             char **sources = nullptr;
117             Dwarf_Signed sources_count = 0;
118              
119             CU(Dwarf_Debug debug, int number_);
120             ~CU();
121              
122             LookupResult resolve(std::uint64_t offset) noexcept;
123             Scan resolve(std::uint64_t offset, DieHolder& die, LookupResult& lr) noexcept;
124             Scan examine(std::uint64_t offset, DieHolder& die, LookupResult& lr) noexcept;
125              
126             string get_source(size_t index) noexcept;
127             };
128             }
129              
130              
131             struct DwarfInfo;
132              
133             struct DwarfInfo {
134             using file_guard_t = std::unique_ptr>;
135              
136             SharedObjectInfo so_info;
137             Dwarf_Ptr err_arg = nullptr;
138             Dwarf_Debug debug = nullptr;
139             std::list CUs;
140             file_guard_t guard;
141              
142 1054           DwarfInfo(const SharedObjectInfo& info_):so_info{info_}{}
143             ~DwarfInfo();
144              
145             bool load(file_guard_t&& guard) noexcept;
146             bool resolve(std::uint64_t ip, StackFrames& frames) noexcept;
147             };
148             using DwarfInfoMap = std::map>;
149              
150              
151             void install_backtracer();
152              
153             }}