diff --git a/build/has_windbg.cpp b/build/has_windbg.cpp index e13f4f7..32724cb 100644 --- a/build/has_windbg.cpp +++ b/build/has_windbg.cpp @@ -7,8 +7,10 @@ #include #include -#include "DbgHelp.h" -#include -#pragma comment(lib, "Dbghelp.lib") +#include "Dbgeng.h" +#pragma comment(lib, "ole32.lib") +#pragma comment(lib, "Dbgeng.lib") -int main() {} +int main() { + CoInitializeEx(0, COINIT_MULTITHREADED); +} diff --git a/include/boost/stacktrace/detail/backtrace_holder_windows.hpp b/include/boost/stacktrace/detail/backtrace_holder_windows.hpp index 0bad8a6..25df391 100644 --- a/include/boost/stacktrace/detail/backtrace_holder_windows.hpp +++ b/include/boost/stacktrace/detail/backtrace_holder_windows.hpp @@ -73,12 +73,69 @@ struct backtrace_holder { return buffer[frame]; } - inline std::string get_source_file(std::size_t /*frame*/) const { - return std::string(); + inline std::string get_source_file(std::size_t frame) const { + std::string result; + if (frame >= frames_count) { + return result; + } + + com_holder idebug_; + if (!try_init_com(idebug_)) { + return result; + } + const ULONG64 offset = reinterpret_cast(buffer[frame]); + + char name[256]; + name[0] = 0; + ULONG size = 0; + bool res = (S_OK == idebug_->GetLineByOffset( + offset, + 0, + name, + sizeof(name), + &size, + 0 + )); + + if (!res && size != 0) { + result.resize(size); + res = (S_OK == idebug_->GetLineByOffset( + offset, + 0, + &result[0], + static_cast(result.size()), + &size, + 0 + )); + } else if (res) { + result = name; + } + + + if (!res) { + result.clear(); + } + + return result; } - inline std::size_t get_source_line(std::size_t /*frame*/) const BOOST_NOEXCEPT { - return 0; + inline std::size_t get_source_line(std::size_t frame) const BOOST_NOEXCEPT { + ULONG line_num = 0; + + if (!try_init_com()) { + return 0; + } + + const bool is_ok = (S_OK == idebug_->GetLineByOffset( + reinterpret_cast(buffer[frame]), + &line_num, + 0, + 0, + 0, + 0 + )); + + return (is_ok ? line_num : 0); } static bool try_init_com(com_holder& idebug_) BOOST_NOEXCEPT { @@ -94,7 +151,6 @@ struct backtrace_holder { com_holder icontrol; iclient->QueryInterface(__uuidof(IDebugControl), icontrol.to_void_ptr_ptr()); - const bool res1 = (S_OK == iclient->AttachProcess( 0, GetCurrentProcessId(),