-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsubseq.cpp
65 lines (55 loc) · 1.84 KB
/
subseq.cpp
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
#include <fstream>
#include <fileno.hpp>
#include <dwarfpp/lib.hpp>
#include <dwarfpp/attr.hpp>
#include <srk31/selective_iterator.hpp>
using std::cout;
using std::cerr;
using std::endl;
using namespace dwarf;
using dwarf::core::iterator_sibs;
using dwarf::core::base_type_die;
int main(int argc, char **argv)
{
assert(argc > 1);
std::ifstream in(argv[1]);
core::root_die root(fileno(in));
/* Get the sequence of children of the first CU. */
auto iter = root.begin();
++iter;
assert(iter.tag_here() == DW_TAG_compile_unit);
auto first_cu_children = iter.children();
cerr << "First child is at " << first_cu_children.first.offset_here() << std::endl;
cerr << "Now just the odd-offset ones" << std::endl;
auto first_cu_odd_children = first_cu_children.subseq_with(
[](const iterator_sibs<>& it) {
bool ret = (it.offset_here() % 2 == 1);
//cerr << "Pred called at 0x" << std::hex << it.offset_here() << std::dec
// << "; returning " << std::boolalpha << ret << std::endl;
return ret;
}
);
auto i = first_cu_odd_children.first;
cerr << "Are they null? " << std::boolalpha <<
!first_cu_odd_children.first << ", " << !first_cu_odd_children.second
<< std::endl;
for (; i != first_cu_odd_children.second; ++i)
{
cout << i << std::endl;
}
cerr << "Now just the base types" << std::endl;
auto pred = [](const decltype(first_cu_children.first)& arg) {
return arg.is_a<base_type_die>();
};
typedef srk31::selective_iterator<
decltype(pred),
decltype(first_cu_children.first)
> my_selective_iterator;
my_selective_iterator first_sel(first_cu_children.first, first_cu_children.second, /*first_cu_children.first, */ pred),
last_sel(first_cu_children./*first*/second, first_cu_children.second, /* first_cu_children.second, */ pred);
for (auto i = first_sel; i != last_sel; ++i)
{
cout << i << std::endl;
}
return 0;
}