-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_type.cc
More file actions
132 lines (114 loc) · 2.08 KB
/
base_type.cc
File metadata and controls
132 lines (114 loc) · 2.08 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <cassert>
#include <dwarf.h>
#include <libdwarf.h>
#include "base_type.h"
#include "common.h"
using std::map;
using std::ostream;
BaseType::BaseType(Dwarf_Off id)
: Type(id)
{
}
int
BaseType::init(Dwarf_Debug dbg, map<Dwarf_Off, Type*>& types)
{
Dwarf_Error err;
Dwarf_Die die;
int rc;
char* str;
(void) types;
rc = dwarf_offdie(dbg, id(), &die, &err);
assert(rc == DW_DLV_OK);
rc = dwarf_diename(die, &str, &err);
assert(rc == DW_DLV_OK);
name_ = str;
dwarf_dealloc(dbg, str, DW_DLA_STRING);
rc = get_size(die, &size_);
assert(rc == 0);
rc = get_attr_udata(die, DW_AT_encoding, &encoding_);
assert(rc == 0);
return 0;
}
int
BaseType::dumpData(void* data, int indent UNUSED, ostream& out)
{
if (size_ == 1)
{
if (encoding_ == DW_ATE_boolean)
{
bool val = *reinterpret_cast<bool *>(data);
out << (val ? "true" : "false");
}
else if (encoding_ == DW_ATE_signed_char ||
encoding_ == DW_ATE_unsigned_char)
{
char ch = *reinterpret_cast<char *>(data);
out << '\'';
print_char_repr(ch, out);
out << '\'';
}
}
else if (size_ == 2)
{
if (encoding_ == DW_ATE_signed)
{
out << *reinterpret_cast<short *>(data);
}
else
{
out << *reinterpret_cast<unsigned short *>(data);
}
}
else if (size_ == 4)
{
if (encoding_ == DW_ATE_signed)
{
out << *reinterpret_cast<int *>(data);
}
else if (encoding_ == DW_ATE_unsigned)
{
out << *reinterpret_cast<unsigned int *>(data);
}
else
{
assert(0);
}
}
else if (size_ == 8)
{
if (encoding_ == DW_ATE_signed)
{
out << *reinterpret_cast<long long *>(data);
}
else if (encoding_ == DW_ATE_unsigned)
{
out << *reinterpret_cast<unsigned long long *>(data);
}
else
{
assert(0);
}
}
return 0;
}
Dwarf_Unsigned
BaseType::size() const
{
return size_;
}
bool
BaseType::isCharacter() const
{
bool ret;
switch (encoding_)
{
case DW_ATE_signed_char:
case DW_ATE_unsigned_char:
ret = true;
break;
default:
ret = false;
break;
}
return ret;
}