line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#if !defined(__APPLE__) && !defined(_WIN32) |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#include |
4
|
|
|
|
|
|
|
#include // PATH_MAX |
5
|
|
|
|
|
|
|
#include |
6
|
|
|
|
|
|
|
#include |
7
|
|
|
|
|
|
|
#include "dl.h" |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
namespace panda { namespace backtrace { |
11
|
|
|
|
|
|
|
|
12
|
527
|
|
|
|
|
|
int dl_iterate(struct dl_phdr_info *info, size_t, void* data){ |
13
|
|
|
|
|
|
|
//printf("so: %s at %lx\n", info->dlpi_name, info->dlpi_addr); |
14
|
527
|
50
|
|
|
|
|
if (info->dlpi_name) { |
15
|
1054
|
|
|
|
|
|
string name = string(info->dlpi_name); |
16
|
|
|
|
|
|
|
/* special case - read self */ |
17
|
527
|
100
|
|
|
|
|
if (name.length() == 0) { |
18
|
34
|
50
|
|
|
|
|
name.reserve(PATH_MAX); |
19
|
34
|
50
|
|
|
|
|
auto len = readlink("/proc/self/exe", name.buf(), PATH_MAX); |
20
|
34
|
50
|
|
|
|
|
if (len > 0) { |
21
|
34
|
|
|
|
|
|
name.length(static_cast(len)); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
527
|
50
|
|
|
|
|
if (!name) { return 0; } |
25
|
|
|
|
|
|
|
|
26
|
527
|
|
|
|
|
|
auto container = reinterpret_cast(data); |
27
|
527
|
|
|
|
|
|
auto end = info->dlpi_addr; |
28
|
4318
|
100
|
|
|
|
|
for (int j = 0; j < info->dlpi_phnum; j++) { |
29
|
3791
|
|
|
|
|
|
auto& header = info->dlpi_phdr[j]; |
30
|
3791
|
|
|
|
|
|
auto s = info->dlpi_addr + header.p_vaddr; |
31
|
3791
|
|
|
|
|
|
auto e = s + header.p_memsz; |
32
|
3791
|
100
|
|
|
|
|
if (e > end) { end = e; } |
33
|
|
|
|
|
|
|
//printf("\t\t header %2d: address=%10p .. %10p [%s at %10p]\n", j, (void *) start, (void*) end, info->dlpi_name, info->dlpi_addr); |
34
|
|
|
|
|
|
|
} |
35
|
527
|
|
|
|
|
|
auto begin = static_cast(info->dlpi_addr); |
36
|
527
|
50
|
|
|
|
|
container->emplace_back(SharedObjectInfo{begin, static_cast(end), false, name}); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
527
|
|
|
|
|
|
return 0; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
17
|
|
|
|
|
|
void gather_info(SharedObjectMap& map) { |
44
|
17
|
|
|
|
|
|
dl_iterate_phdr(dl_iterate, &map); |
45
|
17
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
}} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#endif |