From 11899ae01a6057528041156c952b565cbc086455 Mon Sep 17 00:00:00 2001 From: peter23 Date: Sat, 14 Sep 2024 02:26:54 +0300 Subject: [PATCH 1/2] If we call SymInitialize in TraceResolverImpl constructor then it is logical to call SymCleanup in destructor --- backward.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backward.hpp b/backward.hpp index 670aa45..63ae0d7 100644 --- a/backward.hpp +++ b/backward.hpp @@ -3633,6 +3633,10 @@ template <> class TraceResolverImpl image_type = h->FileHeader.Machine; } + ~TraceResolverImpl() { + SymCleanup(GetCurrentProcess()); + } + static const int max_sym_len = 255; struct symbol_t { SYMBOL_INFO sym; From 319a3e3b36a2309cac1d7d2bd2972fef33eb8e99 Mon Sep 17 00:00:00 2001 From: peter23 Date: Sat, 14 Sep 2024 02:33:45 +0300 Subject: [PATCH 2/2] 1. We can provide some additional info about module in cases when SymGetLineFromAddr failed. 2. In constructor we call SymInitialize with fInvadeProcess=false. Therefore we should call SymLoadModule before SymFromAddr. get_mod_info does that. --- backward.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backward.hpp b/backward.hpp index 63ae0d7..360e363 100644 --- a/backward.hpp +++ b/backward.hpp @@ -3648,6 +3648,15 @@ template <> class TraceResolverImpl ResolvedTrace resolve(ResolvedTrace t) override { HANDLE process = GetCurrentProcess(); + std::string mod_info_str = ""; + HMODULE hmod = (HMODULE)SymGetModuleBase64(process, (DWORD64)t.addr); + if(hmod) { + const auto mod_info = get_mod_info(process)(hmod); + std::stringstream stream; + stream << mod_info.module_name << " (base 0x" << std::hex << (DWORD64)mod_info.base_address << ")"; + mod_info_str = stream.str(); + } + char name[256]; memset(&sym, 0, sizeof(sym)); @@ -3682,7 +3691,7 @@ template <> class TraceResolverImpl } t.source.function = name; - t.object_filename = ""; + t.object_filename = mod_info_str; t.object_function = name; return t;