aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-05-19 05:02:06 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-05-19 05:02:06 +0300
commit8e646ba31d9023db342ec0deae59abfc5683b4ef (patch)
tree560fd0c3ed88216134cbf5b1ec0b6c6ccbd8ce6a
parentinitial commit (diff)
downloadwinapi-debug-8e646ba31d9023db342ec0deae59abfc5683b4ef.tar.gz
winapi-debug-8e646ba31d9023db342ec0deae59abfc5683b4ef.zip
add displacement to symbols
-rw-r--r--include/pdb/symbol.hpp10
-rw-r--r--src/dbghelp.cpp4
-rw-r--r--utils/addr2name.cpp12
3 files changed, 22 insertions, 4 deletions
diff --git a/include/pdb/symbol.hpp b/include/pdb/symbol.hpp
index 9e11d04..8cb66d1 100644
--- a/include/pdb/symbol.hpp
+++ b/include/pdb/symbol.hpp
@@ -28,7 +28,7 @@ namespace pdb
raw.MaxNameLen = MAX_SYM_NAME;
}
- SymbolInfo(const Raw& raw)
+ explicit SymbolInfo(const Raw& raw)
: SymbolInfo{}
{
std::memcpy(buffer, &raw, raw.SizeOfStruct + raw.NameLen - 1);
@@ -38,6 +38,13 @@ namespace pdb
explicit operator const Raw&() const { return raw; }
+ Address get_displacement() const { return displacement; }
+
+ void set_displacement(Address new_value)
+ {
+ displacement = new_value;
+ }
+
std::string get_name() const { return {raw.Name, raw.NameLen}; }
Address get_offline_base() const { return raw.ModBase; }
@@ -60,6 +67,7 @@ namespace pdb
private:
unsigned char buffer[sizeof(Raw) + MAX_SYM_NAME - 1];
+ Address displacement = 0;
protected:
Raw& raw;
diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp
index c319fee..ff8618f 100644
--- a/src/dbghelp.cpp
+++ b/src/dbghelp.cpp
@@ -9,7 +9,6 @@
#include <DbgHelp.h>
#include <cstddef>
-#include <cstring>
#include <limits>
#include <stdexcept>
@@ -115,7 +114,7 @@ namespace pdb
SymbolInfo DbgHelp::resolve_symbol(Address online) const
{
- DWORD64 displacement = 0;
+ Address displacement = 0;
SymbolInfo symbol;
const auto ret = SymFromAddr(
@@ -127,6 +126,7 @@ namespace pdb
if (!ret)
throw error::windows(GetLastError());
+ symbol.set_displacement(displacement);
return symbol;
}
diff --git a/utils/addr2name.cpp b/utils/addr2name.cpp
index a01f61e..9719b60 100644
--- a/utils/addr2name.cpp
+++ b/utils/addr2name.cpp
@@ -72,6 +72,16 @@ namespace
return oss.str();
}
+ std::string format_symbol(const pdb::Symbol& symbol)
+ {
+ std::ostringstream oss;
+ oss << symbol.get_name();
+ const auto displacement = symbol.get_displacement();
+ if (displacement)
+ oss << '+' << format_address(displacement);
+ return oss.str();
+ }
+
void dump_error(const std::exception& e)
{
std::cerr << "error: " << e.what() << '\n';
@@ -81,7 +91,7 @@ namespace
{
try
{
- std::cout << repo.resolve_symbol(address).get_name() << '\n';
+ std::cout << format_symbol(repo.resolve_symbol(address)) << '\n';
}
catch (const std::exception& e)
{