Skip to content

Commit 7f8f712

Browse files
committed
Various bugfixes, conveniences, and better DWARF4 support.
--HG-- rename : tests/iterator-comp/iterator-comp.cpp => tests/Rotted/iterator-comp/iterator-comp.cpp rename : tests/visible-named/visible-named.cpp => tests/Rotted/visible-named/visible-named.cpp
1 parent a6fe03f commit 7f8f712

27 files changed

+792
-639
lines changed

examples/print_spec.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
int main(int argc, char **argv)
55
{
6-
std::cout << dwarf::spec::dwarf3_def::inst;
6+
std::cout << dwarf::spec::dwarf4;
77
}

include/dwarfpp/adt.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ namespace dwarf
212212
bool move_to_next_sibling(iterator_base& arg)
213213
{
214214
// handle root DIE specially
215-
int start_depth = arg.path_from_root.size() - 1;
216-
assert(start_depth >= 0);
215+
unsigned start_depth = arg.path_from_root.size() - 1;
217216
if (arg.p_d->get_offset() == 0) return false;
218217
// handle CU DIEs specially
219218
assert(start_depth >= 1);

include/dwarfpp/attr.hpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ namespace dwarf
132132
* address data type. */
133133
{
134134
Dwarf_Addr addr;
135+
address(Dwarf_Addr val) { this->addr = val; }
135136
bool operator==(const address& arg) const { return this->addr == arg.addr; }
136137
bool operator!=(const address& arg) const { return !(*this == arg); }
137138
bool operator<(const address& arg) const { return this->addr < arg.addr; }
@@ -214,11 +215,17 @@ namespace dwarf
214215
public:
215216

216217
Dwarf_Bool get_flag() const { assert(f == FLAG); return v_flag; }
217-
Dwarf_Unsigned get_unsigned() const { assert(f == UNSIGNED); return v_u; }
218-
Dwarf_Signed get_signed() const { assert(f == SIGNED); return v_s; }
218+
// allow mix-and-match among signed and unsigned
219+
Dwarf_Unsigned get_unsigned() const
220+
{ assert(f == UNSIGNED || f == SIGNED); return (f == UNSIGNED) ? v_u : static_cast<Dwarf_Unsigned>(v_s); }
221+
Dwarf_Signed get_signed() const
222+
{ assert(f == SIGNED || f == UNSIGNED); return (f == SIGNED) ? v_s : static_cast<Dwarf_Signed>(v_u); }
219223
const std::vector<unsigned char> *get_block() const { assert(f == BLOCK); return v_block; }
220224
const std::string& get_string() const { assert(f == STRING); return *v_string; }
221-
address get_address() const { assert(f == ADDR); return v_addr; }
225+
/* I added the tolerance of UNSIGNED here because sometimes high_pc is an address,
226+
* other times it's unsigned... BUT it means something different in the latter
227+
* case (lopc-relative) so it's best to handle this difference higher up. */
228+
address get_address() const { assert(f == ADDR/* || f == UNSIGNED*/); return/* (f == ADDR) ?*/ v_addr /*: address(static_cast<Dwarf_Addr>(v_u))*/; }
222229
const loclist& get_loclist() const { assert(f == LOCLIST); return *v_loclist; }
223230
const rangelist& get_rangelist() const { assert(f == RANGELIST); return *v_rangelist; }
224231

include/dwarfpp/encap.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,9 @@ namespace dwarf {
695695
for (auto i = p_seq->begin(/*p_seq*/); i != p_seq->end(/*p_seq*/); i++)
696696
{
697697
Dwarf_Off target = i->second.get_ref().off;
698-
bool abs = i->second.get_ref().abs;
699-
700-
//assert(abs);
698+
699+
// bool abs = i->second.get_ref().abs;
700+
// assert(abs);
701701

702702
bool is_valid = this->get_ds().map_find(target) != this->get_ds().map_end();
703703
retval &= is_valid;

include/dwarfpp/expr.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace dwarf
1515
{
16-
namespace core { struct LocdescList; struct RangesList; }
16+
namespace core { struct LocdescList; struct Locdesc; struct RangesList; }
1717
namespace encap
1818
{
1919
using namespace dwarf::lib;
@@ -105,7 +105,7 @@ namespace dwarf
105105

106106
/* This template parses a location expression out of an array of unsigneds. */
107107
template<size_t s>
108-
loc_expr(Dwarf_Unsigned (&arr)[s], Dwarf_Addr lopc, Dwarf_Addr hipc,
108+
loc_expr(Dwarf_Unsigned const (&arr)[s], Dwarf_Addr lopc, Dwarf_Addr hipc,
109109
const spec::abstract_def& spec = spec::dwarf3)
110110
: spec(spec), hipc(hipc), lopc(lopc)
111111
{
@@ -189,15 +189,15 @@ namespace dwarf
189189
friend class ::dwarf::lib::evaluator;
190190
friend class attribute_value;
191191
static loclist NO_LOCATION;
192-
private:
193-
loclist() {}
194-
public:
192+
193+
loclist() {} // empty loclist
195194
loclist(const dwarf::lib::loclist& dll);
196195
/* We can construct a loc_expr from a Loc_Desc.
197196
* So we can construct a loclist from a LocdescList. */
198197
loclist(const core::LocdescList& ll);
199198
// would ideally repeat all vector constructors
200199
template <class In> loclist(In first, In last) : std::vector<loc_expr>(first, last) {}
200+
loclist(const core::Locdesc& l);
201201
loclist(const std::vector<loc_expr>& v) : std::vector<loc_expr>(v) {}
202202
loclist(const loc_expr& loc) : std::vector<loc_expr>(1, loc) {}
203203
//bool operator==(const loclist& oll) const { return *this == oll; }

0 commit comments

Comments
 (0)