-
Notifications
You must be signed in to change notification settings - Fork 35
/
dwarf_reader.cc
86 lines (78 loc) · 1.86 KB
/
dwarf_reader.cc
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "libpstack/dwarf.h"
#include "libpstack/dwarf_reader.h"
namespace pstack::Dwarf {
void
DWARFReader::readForm(const Info &info, Unit &unit, Form form)
{
switch (form) {
case DW_FORM_string:
case DW_FORM_line_strp:
case DW_FORM_strp:
readFormString(info, unit, form);
break;
case DW_FORM_data16:
skip(16); // line info uses this for LNCT_MD5
return;
default:
abort();
}
}
std::string
DWARFReader::readFormString(const Info &dwarf, Unit &unit, Form form)
{
switch (form) {
case DW_FORM_string:
return getstring();
default:
abort();
case DW_FORM_line_strp: {
auto off = getuint(unit.dwarfLen);
return dwarf.debugLineStrings.io()->readString(off);
}
case DW_FORM_strp: {
auto off = getuint(unit.dwarfLen);
return dwarf.debugStrings.io()->readString(off);
}
case DW_FORM_strx: {
size_t off = getuleb128();
return unit.strx(off);
}
}
}
uintmax_t
DWARFReader::readFormUnsigned(Form form)
{
switch (form) {
case DW_FORM_udata:
return getuleb128();
case DW_FORM_data1:
return getu8();
case DW_FORM_data2:
return getu16();
case DW_FORM_data4:
return getu32();
default:
abort();
}
}
intmax_t
DWARFReader::readFormSigned(Form form)
{
(void)this; // avoid warnings about making this static.
switch (form) {
default:
abort();
}
}
std::pair <Elf::Off, Elf::Off>
DWARFReader::getlength() {
size_t length = getu32();
if (length == 0xffffffff) {
return { getuint(8), 8 };
}
if (length >= 0xfffffff0) {
return { 0, 0 };
}
return { length, 4 };
}
}