Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce TraceResolver::load_addresses() for raw address array #162

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 28 additions & 32 deletions backward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,19 +944,16 @@ class StackTrace : public StackTraceImpl<system_tag::current_tag> {};

/*************** TRACE RESOLVER ***************/

template <typename TAG> class TraceResolverImpl;

#ifdef BACKWARD_SYSTEM_UNKNOWN

template <> class TraceResolverImpl<system_tag::unknown_tag> {
class TraceResolverImplBase {
public:
template <class ST> void load_stacktrace(ST &) {}
ResolvedTrace resolve(ResolvedTrace t) { return t; }
};
virtual void load_addresses(void *const*addresses, int address_count) {}

#endif
template <class ST> void load_stacktrace(ST &st) {
load_addresses(st.begin(), (int)st.size());
}

virtual ResolvedTrace resolve(ResolvedTrace t) { return t; }

class TraceResolverImplBase {
protected:
std::string demangle(const char *funcname) {
return _demangler.demangle(funcname);
Expand All @@ -966,6 +963,15 @@ class TraceResolverImplBase {
details::demangler _demangler;
};

template <typename TAG> class TraceResolverImpl;

#ifdef BACKWARD_SYSTEM_UNKNOWN

template <> class TraceResolverImpl<system_tag::unknown_tag>
: public TraceResolverImplBase {};

#endif

#ifdef BACKWARD_SYSTEM_LINUX

class TraceResolverLinuxBase
Expand Down Expand Up @@ -1029,15 +1035,14 @@ template <>
class TraceResolverLinuxImpl<trace_resolver_tag::backtrace_symbol>
: public TraceResolverLinuxBase {
public:
template <class ST> void load_stacktrace(ST &st) {
using namespace details;
if (st.size() == 0) {
void load_addresses(void *const*addresses, int address_count) override {
if (address_count == 0) {
return;
}
_symbols.reset(backtrace_symbols(st.begin(), (int)st.size()));
_symbols.reset(backtrace_symbols(addresses, address_count));
}

ResolvedTrace resolve(ResolvedTrace trace) {
ResolvedTrace resolve(ResolvedTrace trace) override {
char *filename = _symbols[trace.idx];
char *funcname = filename;
while (*funcname && *funcname != '(') {
Expand Down Expand Up @@ -1074,9 +1079,7 @@ class TraceResolverLinuxImpl<trace_resolver_tag::libbfd>
public:
TraceResolverLinuxImpl() : _bfd_loaded(false) {}

template <class ST> void load_stacktrace(ST &) {}

ResolvedTrace resolve(ResolvedTrace trace) {
ResolvedTrace resolve(ResolvedTrace trace) override {
Dl_info symbol_info;

// trace.addr is a virtual address in memory pointing to some code.
Expand Down Expand Up @@ -1438,9 +1441,7 @@ class TraceResolverLinuxImpl<trace_resolver_tag::libdw>
public:
TraceResolverLinuxImpl() : _dwfl_handle_initialized(false) {}

template <class ST> void load_stacktrace(ST &) {}

ResolvedTrace resolve(ResolvedTrace trace) {
ResolvedTrace resolve(ResolvedTrace trace) override {
using namespace details;

Dwarf_Addr trace_addr = (Dwarf_Addr)trace.addr;
Expand Down Expand Up @@ -1767,9 +1768,7 @@ class TraceResolverLinuxImpl<trace_resolver_tag::libdwarf>
public:
TraceResolverLinuxImpl() : _dwarf_loaded(false) {}

template <class ST> void load_stacktrace(ST &) {}

ResolvedTrace resolve(ResolvedTrace trace) {
ResolvedTrace resolve(ResolvedTrace trace) override {
// trace.addr is a virtual address in memory pointing to some code.
// Let's try to find from which loaded object it comes from.
// The loaded object can be yourself btw.
Expand Down Expand Up @@ -3148,15 +3147,14 @@ template <>
class TraceResolverDarwinImpl<trace_resolver_tag::backtrace_symbol>
: public TraceResolverImplBase {
public:
template <class ST> void load_stacktrace(ST &st) {
using namespace details;
if (st.size() == 0) {
void load_addresses(void *const*addresses, int address_count) override {
if (address_count == 0) {
return;
}
_symbols.reset(backtrace_symbols(st.begin(), st.size()));
_symbols.reset(backtrace_symbols(addresses, address_count));
}

ResolvedTrace resolve(ResolvedTrace trace) {
ResolvedTrace resolve(ResolvedTrace trace) override {
// parse:
// <n> <file> <addr> <mangled-name> + <offset>
char *filename = _symbols[trace.idx];
Expand Down Expand Up @@ -3291,8 +3289,6 @@ template <> class TraceResolverImpl<system_tag::windows_tag> {
image_type = h->FileHeader.Machine;
}

template <class ST> void load_stacktrace(ST &) {}

static const int max_sym_len = 255;
struct symbol_t {
SYMBOL_INFO sym;
Expand All @@ -3301,7 +3297,7 @@ template <> class TraceResolverImpl<system_tag::windows_tag> {

DWORD64 displacement;

ResolvedTrace resolve(ResolvedTrace t) {
ResolvedTrace resolve(ResolvedTrace t) override {
HANDLE process = GetCurrentProcess();

char name[256];
Expand Down