diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-03-16 17:19:24 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-03-16 17:19:24 +0300 |
commit | c151774911b4ea658410cc6593dd40390862a168 (patch) | |
tree | 2d364e74bfb9923236fdc53d8cc7b64df3dcc883 | |
parent | Travis: ignore everything in .dockerignore (diff) | |
download | winapi-debug-c151774911b4ea658410cc6593dd40390862a168.tar.gz winapi-debug-c151774911b4ea658410cc6593dd40390862a168.zip |
DbgHelp: start fixing the API
-rw-r--r-- | include/pdb/dbghelp.hpp | 31 | ||||
-rw-r--r-- | include/pdb/repo.hpp | 2 | ||||
-rw-r--r-- | src/dbghelp.cpp | 19 | ||||
-rw-r--r-- | test/call_stack.cpp | 2 | ||||
-rw-r--r-- | utils/enum_symbols.cpp | 2 |
5 files changed, 43 insertions, 13 deletions
diff --git a/include/pdb/dbghelp.hpp b/include/pdb/dbghelp.hpp index af10789..328df2d 100644 --- a/include/pdb/dbghelp.hpp +++ b/include/pdb/dbghelp.hpp @@ -18,10 +18,14 @@ namespace pdb { class DbgHelp { public: - DbgHelp(bool invade_current_process = false); - ~DbgHelp(); + static DbgHelp current_process() { return DbgHelp{true}; } + static DbgHelp post_mortem() { return DbgHelp{false}; } - void close(); + void swap(DbgHelp& other) noexcept; + + DbgHelp(DbgHelp&& other) noexcept; + DbgHelp& operator=(DbgHelp) noexcept; + ~DbgHelp(); ModuleInfo load_pdb(const std::string& path) const; @@ -43,11 +47,26 @@ public: LineInfo resolve_line(Address) const; private: - const HANDLE id = GetCurrentProcess(); - bool closed = false; + explicit DbgHelp(bool invade_current_process); + + void close(); + + HANDLE id = GetCurrentProcess(); DbgHelp(const DbgHelp&) = delete; - DbgHelp& operator=(const DbgHelp&) = delete; }; +inline void swap(DbgHelp& a, DbgHelp& b) noexcept { + a.swap(b); +} + } // namespace pdb + +namespace std { + +template <> +inline void swap(pdb::DbgHelp& a, pdb::DbgHelp& b) noexcept { + a.swap(b); +} + +} // namespace std diff --git a/include/pdb/repo.hpp b/include/pdb/repo.hpp index 8bc5596..74a86a8 100644 --- a/include/pdb/repo.hpp +++ b/include/pdb/repo.hpp @@ -47,7 +47,7 @@ private: Address address_offline_to_online(Address) const; Address address_online_to_offline(Address) const; - const DbgHelp dbghelp; + const DbgHelp dbghelp{DbgHelp::post_mortem()}; std::unordered_set<file::ID> file_ids; std::map<Address, Module> online_bases; diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp index efbdede..cb71282 100644 --- a/src/dbghelp.cpp +++ b/src/dbghelp.cpp @@ -91,6 +91,20 @@ DbgHelp::DbgHelp(bool invade_current_process) { initialize(id, invade_current_process); } +void DbgHelp::swap(DbgHelp& other) noexcept { + using std::swap; + swap(id, other.id); +} + +DbgHelp::DbgHelp(DbgHelp&& other) noexcept { + swap(other); +} + +DbgHelp& DbgHelp::operator=(DbgHelp other) noexcept { + swap(other); + return *this; +} + DbgHelp::~DbgHelp() { try { close(); @@ -99,10 +113,7 @@ DbgHelp::~DbgHelp() { } void DbgHelp::close() { - if (!closed) { - clean_up(id); - closed = true; - } + clean_up(id); } ModuleInfo DbgHelp::load_pdb(const std::string& path) const { diff --git a/test/call_stack.cpp b/test/call_stack.cpp index c1fb0fd..e193b01 100644 --- a/test/call_stack.cpp +++ b/test/call_stack.cpp @@ -6,7 +6,7 @@ namespace test { void call_stack() { - pdb::DbgHelp dbghelp{true}; + const auto dbghelp = pdb::DbgHelp::current_process(); const auto call_stack = pdb::CallStack::capture(); for (std::size_t i = 0; i < call_stack.length; ++i) std::cout << pdb::format_address(call_stack.frames[i]) << ' ' diff --git a/utils/enum_symbols.cpp b/utils/enum_symbols.cpp index d7f4c37..123c9d1 100644 --- a/utils/enum_symbols.cpp +++ b/utils/enum_symbols.cpp @@ -72,7 +72,7 @@ int main(int argc, char* argv[]) { return 0; } - pdb::DbgHelp dbghelp; + const auto dbghelp = pdb::DbgHelp::post_mortem(); for (const auto& pdb : settings.pdbs) { const auto id = dbghelp.load_pdb(pdb); |