aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-01-15 05:04:51 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-01-15 05:05:51 +0300
commit52dba9e60ea7712da45d889159acc0a30f2fbf82 (patch)
treebaba0876a46939de5815f31116a4143ae4ef97c8
parentsplit symbol.hpp (diff)
downloadwinapi-debug-52dba9e60ea7712da45d889159acc0a30f2fbf82.tar.gz
winapi-debug-52dba9e60ea7712da45d889159acc0a30f2fbf82.zip
DbgHelp: add more enum_* methods
-rw-r--r--include/pdb/dbghelp.hpp6
-rw-r--r--src/dbghelp.cpp39
2 files changed, 36 insertions, 9 deletions
diff --git a/include/pdb/dbghelp.hpp b/include/pdb/dbghelp.hpp
index 4f11e22..edb095c 100644
--- a/include/pdb/dbghelp.hpp
+++ b/include/pdb/dbghelp.hpp
@@ -25,8 +25,12 @@ public:
ModuleInfo load_pdb(const std::string& path) const;
+ typedef std::function<void(const ModuleInfo&)> OnModule;
+ void enum_modules(const OnModule&) const;
+
typedef std::function<void(const SymbolInfo&)> OnSymbol;
void enum_symbols(const ModuleInfo&, const OnSymbol&) const;
+ void enum_symbols(const OnSymbol&) const;
SymbolInfo resolve_symbol(Address) const;
SymbolInfo resolve_symbol(const std::string&) const;
@@ -34,8 +38,6 @@ public:
LineInfo resolve_line(Address) const;
private:
- ModuleInfo get_module_info(Address offline_base) const;
-
const HANDLE id = GetCurrentProcess();
bool closed = false;
diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp
index 26eff79..8268673 100644
--- a/src/dbghelp.cpp
+++ b/src/dbghelp.cpp
@@ -45,6 +45,27 @@ Address gen_next_offline_base(std::size_t pdb_size) {
return base;
}
+ModuleInfo get_module_info(HANDLE id, Address offline_base) {
+ ModuleInfo info;
+
+ if (!SymGetModuleInfo64(id, offline_base, &static_cast<ModuleInfo::Impl&>(info)))
+ throw error::windows(GetLastError());
+
+ return info;
+}
+
+struct ModuleEnumerator {
+ HANDLE id;
+ DbgHelp::OnModule callback;
+};
+
+BOOL CALLBACK enum_modules_callback(PCSTR, DWORD64 offline_base, PVOID raw_enumerator_ptr) {
+ const auto enumerator_ptr = reinterpret_cast<ModuleEnumerator*>(raw_enumerator_ptr);
+ const auto& enumerator = *enumerator_ptr;
+ enumerator.callback(get_module_info(enumerator.id, offline_base));
+ return TRUE;
+}
+
BOOL CALLBACK enum_symbols_callback(SYMBOL_INFO* info, ULONG, VOID* raw_callback_ptr) {
const auto callback_ptr = reinterpret_cast<DbgHelp::OnSymbol*>(raw_callback_ptr);
const auto& callback = *callback_ptr;
@@ -90,16 +111,13 @@ ModuleInfo DbgHelp::load_pdb(const std::string& path) const {
if (!offline_base)
throw error::windows(GetLastError());
- return get_module_info(offline_base);
+ return get_module_info(id, offline_base);
}
-ModuleInfo DbgHelp::get_module_info(Address offline_base) const {
- ModuleInfo info;
-
- if (!SymGetModuleInfo64(id, offline_base, &static_cast<ModuleInfo::Impl&>(info)))
+void DbgHelp::enum_modules(const OnModule& callback) const {
+ ModuleEnumerator enumerator{id, callback};
+ if (!SymEnumerateModules64(id, &enum_modules_callback, &enumerator))
throw error::windows(GetLastError());
-
- return info;
}
void DbgHelp::enum_symbols(const ModuleInfo& module, const OnSymbol& callback) const {
@@ -111,6 +129,13 @@ void DbgHelp::enum_symbols(const ModuleInfo& module, const OnSymbol& callback) c
throw error::windows(GetLastError());
}
+void DbgHelp::enum_symbols(const OnSymbol& callback) const {
+ static constexpr auto all_symbols = "*!*";
+ if (!SymEnumSymbols(
+ id, 0, all_symbols, &enum_symbols_callback, const_cast<OnSymbol*>(&callback)))
+ throw error::windows(GetLastError());
+}
+
SymbolInfo DbgHelp::resolve_symbol(Address offline) const {
Address displacement = 0;
SymbolInfo symbol;