diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-01-15 03:30:56 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-01-15 03:35:11 +0300 |
commit | eeac54304af4a06ab9e4e3ce944944a609c68a8a (patch) | |
tree | 1dc85b8464e41c47d7463c5d7fc281628f9995b1 | |
parent | add test/ to test, for starters, enum_symbols (diff) | |
download | winapi-debug-eeac54304af4a06ab9e4e3ce944944a609c68a8a.tar.gz winapi-debug-eeac54304af4a06ab9e4e3ce944944a609c68a8a.zip |
refactoring
-rw-r--r-- | include/pdb/module.hpp | 16 | ||||
-rw-r--r-- | include/pdb/symbol.hpp | 46 | ||||
-rw-r--r-- | src/dbghelp.cpp | 12 | ||||
-rw-r--r-- | src/module.cpp | 16 | ||||
-rw-r--r-- | src/repo.cpp | 12 |
5 files changed, 51 insertions, 51 deletions
diff --git a/include/pdb/module.hpp b/include/pdb/module.hpp index db6722e..bff8bd6 100644 --- a/include/pdb/module.hpp +++ b/include/pdb/module.hpp @@ -16,22 +16,22 @@ namespace pdb { class ModuleInfo { public: - typedef IMAGEHLP_MODULE64 Raw; + typedef IMAGEHLP_MODULE64 Impl; ModuleInfo(); - explicit ModuleInfo(const Raw& raw); + explicit ModuleInfo(const Impl& impl); - explicit operator Raw&() { return raw; } - explicit operator const Raw&() const { return raw; } + explicit operator Impl&() { return impl; } + explicit operator const Impl&() const { return impl; } - Address get_offline_base() const { return raw.BaseOfImage; } + Address get_offline_base() const { return impl.BaseOfImage; } - std::string get_name() const { return raw.ModuleName; } + std::string get_name() const { return impl.ModuleName; } private: - static Raw create_raw(); + static Impl create_impl(); - Raw raw; + Impl impl; }; class Module : public ModuleInfo { diff --git a/include/pdb/symbol.hpp b/include/pdb/symbol.hpp index 98379d8..6c36092 100644 --- a/include/pdb/symbol.hpp +++ b/include/pdb/symbol.hpp @@ -36,37 +36,37 @@ static_assert(static_cast<Tag>(SymTagFunction) == SYM_TAG_FUNCTION, class SymbolInfo { public: - typedef SYMBOL_INFO Raw; + typedef SYMBOL_INFO Impl; - SymbolInfo() : raw{*reinterpret_cast<Raw*>(buffer)} { - raw.SizeOfStruct = sizeof(Raw); - raw.MaxNameLen = MAX_SYM_NAME; + SymbolInfo() : impl{*reinterpret_cast<Impl*>(buffer)} { + impl.SizeOfStruct = sizeof(Impl); + impl.MaxNameLen = MAX_SYM_NAME; } - explicit SymbolInfo(const Raw& raw) : SymbolInfo{} { - if (raw.SizeOfStruct != sizeof(raw)) + explicit SymbolInfo(const Impl& impl) : SymbolInfo{} { + if (impl.SizeOfStruct != sizeof(impl)) throw std::runtime_error{"invalid SYMBOL_INFO.SizeOfStruct"}; - const auto raw_size = calc_size(raw); + const auto raw_size = calc_size(impl); if (raw_size > sizeof(buffer)) throw std::runtime_error{"SYMBOL_INFO is too large"}; - std::memcpy(buffer, &raw, raw_size); + std::memcpy(buffer, &impl, raw_size); } - explicit operator Raw&() { return raw; } + explicit operator Impl&() { return impl; } - explicit operator const Raw&() const { return raw; } + explicit operator const Impl&() const { return impl; } 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}; } + std::string get_name() const { return {impl.Name, impl.NameLen}; } - Address get_offline_base() const { return raw.ModBase; } + Address get_offline_base() const { return impl.ModBase; } - Address get_offline_address() const { return raw.Address; } + Address get_offline_address() const { return impl.Address; } - symbol::Tag get_tag() const { return raw.Tag; } + symbol::Tag get_tag() const { return impl.Tag; } enum class Type : symbol::Tag { Function = symbol::SYM_TAG_FUNCTION, @@ -78,11 +78,11 @@ public: bool is_function() const { return get_type() == Type::Function; } private: - static constexpr std::size_t max_buffer_size = sizeof(Raw) + MAX_SYM_NAME - 1; + static constexpr std::size_t max_buffer_size = sizeof(Impl) + MAX_SYM_NAME - 1; - static std::size_t calc_size(const Raw& raw) { + static std::size_t calc_size(const Impl& impl) { try { - return SafeInt<std::size_t>{raw.SizeOfStruct} + raw.NameLen - 1; + return SafeInt<std::size_t>{impl.SizeOfStruct} + impl.NameLen - 1; } catch (const SafeIntException&) { throw std::runtime_error{"invalid SYMBOL_INFO size"}; } @@ -92,7 +92,7 @@ private: Address displacement = 0; protected: - Raw& raw; + Impl& impl; }; class Symbol : public SymbolInfo { @@ -108,19 +108,19 @@ private: class LineInfo { public: - typedef IMAGEHLP_LINE64 Raw; + typedef IMAGEHLP_LINE64 Impl; - explicit LineInfo(const Raw& raw) - : file_path{raw.FileName}, line_number{cast_line_number(raw.LineNumber)} {} + explicit LineInfo(const Impl& impl) + : file_path{impl.FileName}, line_number{cast_line_number(impl.LineNumber)} {} const std::string file_path; const unsigned long line_number; private: - static unsigned long cast_line_number(DWORD raw) { + static unsigned long cast_line_number(DWORD impl) { unsigned long dest = 0; - if (!SafeCast(raw, dest)) + if (!SafeCast(impl, dest)) throw std::runtime_error{"invalid line number"}; return dest; diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp index 94fa7ab..26eff79 100644 --- a/src/dbghelp.cpp +++ b/src/dbghelp.cpp @@ -96,7 +96,7 @@ ModuleInfo DbgHelp::load_pdb(const std::string& path) const { ModuleInfo DbgHelp::get_module_info(Address offline_base) const { ModuleInfo info; - if (!SymGetModuleInfo64(id, offline_base, &static_cast<ModuleInfo::Raw&>(info))) + if (!SymGetModuleInfo64(id, offline_base, &static_cast<ModuleInfo::Impl&>(info))) throw error::windows(GetLastError()); return info; @@ -132,16 +132,16 @@ SymbolInfo DbgHelp::resolve_symbol(const std::string& name) const { } LineInfo DbgHelp::resolve_line(Address offline) const { - IMAGEHLP_LINE64 raw; - std::memset(&raw, 0, sizeof(raw)); - raw.SizeOfStruct = sizeof(raw); + IMAGEHLP_LINE64 impl; + std::memset(&impl, 0, sizeof(impl)); + impl.SizeOfStruct = sizeof(impl); DWORD displacement = 0; - if (!SymGetLineFromAddr64(id, offline, &displacement, &raw)) + if (!SymGetLineFromAddr64(id, offline, &displacement, &impl)) throw error::windows(GetLastError()); - return LineInfo{raw}; + return LineInfo{impl}; } } // namespace pdb diff --git a/src/module.cpp b/src/module.cpp index 9f12599..6ee0c08 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -14,18 +14,18 @@ namespace pdb { -ModuleInfo::ModuleInfo() : ModuleInfo{create_raw()} {} +ModuleInfo::ModuleInfo() : ModuleInfo{create_impl()} {} -ModuleInfo::ModuleInfo(const Raw& raw) : raw{raw} { - if (raw.SizeOfStruct != sizeof(raw)) +ModuleInfo::ModuleInfo(const Impl& impl) : impl{impl} { + if (impl.SizeOfStruct != sizeof(impl)) throw std::runtime_error{"invalid IMAGEHLP_MODULE64.SizeOfStruct"}; } -ModuleInfo::Raw ModuleInfo::create_raw() { - Raw raw; - std::memset(&raw, 0, sizeof(raw)); - raw.SizeOfStruct = sizeof(raw); - return raw; +ModuleInfo::Impl ModuleInfo::create_impl() { + Impl impl; + std::memset(&impl, 0, sizeof(impl)); + impl.SizeOfStruct = sizeof(impl); + return impl; } Address Module::translate_offline_address(Address offline) const { diff --git a/src/repo.cpp b/src/repo.cpp index d7f2c74..6ef5252 100644 --- a/src/repo.cpp +++ b/src/repo.cpp @@ -119,8 +119,8 @@ void Repo::enum_symbols(Address offline_base, const OnSymbol& callback) const { } void Repo::enum_symbols(const Module& module, const OnSymbol& callback) const { - dbghelp.enum_symbols(module, - [&](const SymbolInfo& raw) { callback(symbol_from_buffer(module, raw)); }); + dbghelp.enum_symbols( + module, [&](const SymbolInfo& impl) { callback(symbol_from_buffer(module, impl)); }); } Symbol Repo::resolve_symbol(Address online) const { @@ -143,12 +143,12 @@ const Module& Repo::module_with_offline_base(Address base) const { return lookup_module(offline_bases, base); } -Symbol Repo::symbol_from_buffer(const SymbolInfo& raw) const { - return symbol_from_buffer(module_with_offline_base(raw.get_offline_base()), raw); +Symbol Repo::symbol_from_buffer(const SymbolInfo& impl) const { + return symbol_from_buffer(module_with_offline_base(impl.get_offline_base()), impl); } -Symbol Repo::symbol_from_buffer(const Module& module, const SymbolInfo& raw) { - return {module.translate_offline_address(raw.get_offline_address()), raw}; +Symbol Repo::symbol_from_buffer(const Module& module, const SymbolInfo& impl) { + return {module.translate_offline_address(impl.get_offline_address()), impl}; } Address Repo::address_online_to_offline(Address online) const { |