source: XIOS3/trunk/extern/cpptrace/src/symbols_with_dl.cpp @ 2573

Last change on this file since 2573 was 2573, checked in by ymipsl, 9 months ago

create new external source lib : cpptrace, for statck trace output
YM

File size: 1.3 KB
Line 
1#ifdef CPPTRACE_GET_SYMBOLS_WITH_LIBDL
2
3#include "cpptrace.hpp"
4#include "symbols.hpp"
5
6#include <cstdint>
7#include <memory>
8#include <vector>
9
10#include <dlfcn.h>
11
12namespace cpptrace {
13    namespace detail {
14        namespace libdl {
15            stacktrace_frame resolve_frame(const void* addr) {
16                Dl_info info;
17                if(dladdr(addr, &info)) { // thread-safe
18                    return {
19                        reinterpret_cast<uintptr_t>(addr),
20                        0,
21                        0,
22                        info.dli_fname ? info.dli_fname : "",
23                        info.dli_sname ? info.dli_sname : ""
24                    };
25                } else {
26                    return {
27                        reinterpret_cast<uintptr_t>(addr),
28                        0,
29                        0,
30                        "",
31                        ""
32                    };
33                }
34            }
35
36            std::vector<stacktrace_frame> resolve_frames(const std::vector<void*>& frames) {
37                std::vector<stacktrace_frame> trace;
38                trace.reserve(frames.size());
39                for(const void* frame : frames) {
40                    trace.push_back(resolve_frame(frame));
41                }
42                return trace;
43            }
44        }
45    }
46}
47
48#endif
Note: See TracBrowser for help on using the repository browser.