From c151774911b4ea658410cc6593dd40390862a168 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 16 Mar 2020 17:19:24 +0300 Subject: DbgHelp: start fixing the API --- include/pdb/dbghelp.hpp | 31 +++++++++++++++++++++++++------ include/pdb/repo.hpp | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'include/pdb') 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_ids; std::map online_bases; -- cgit v1.2.3