From b6919562ab09fc18dfa90c4588636b4f6ffcd76c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 22 May 2017 02:10:22 +0300 Subject: add line numbers to symbols --- src/dbghelp.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'src/dbghelp.cpp') diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp index 30829d4..0a78e4d 100644 --- a/src/dbghelp.cpp +++ b/src/dbghelp.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -19,14 +20,17 @@ namespace pdb { namespace { - void enable_debug_output() + void set_dbghelp_options() { - SymSetOptions(SymGetOptions() | SYMOPT_DEBUG | SYMOPT_UNDNAME); + SymSetOptions(SymGetOptions() + | SYMOPT_DEBUG + | SYMOPT_LOAD_LINES + | SYMOPT_UNDNAME); } void initialize(HANDLE id) { - enable_debug_output(); + set_dbghelp_options(); if (!SymInitialize(id, NULL, FALSE)) throw error::windows(GetLastError()); @@ -129,14 +133,14 @@ namespace pdb throw error::windows(GetLastError()); } - SymbolInfo DbgHelp::resolve_symbol(Address online) const + SymbolInfo DbgHelp::resolve_symbol(Address offline) const { Address displacement = 0; SymbolInfo symbol; if (!SymFromAddr( id, - online, + offline, &displacement, &static_cast(symbol))) throw error::windows(GetLastError()); @@ -157,4 +161,22 @@ namespace pdb return symbol; } + + LineInfo DbgHelp::resolve_line(Address offline) const + { + IMAGEHLP_LINE64 raw; + std::memset(&raw, 0, sizeof(raw)); + raw.SizeOfStruct = sizeof(raw); + + DWORD displacement = 0; + + if (!SymGetLineFromAddr64( + id, + offline, + &displacement, + &raw)) + throw error::windows(GetLastError()); + + return LineInfo{raw}; + } } -- cgit v1.2.3