diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-20 04:12:31 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-20 04:12:31 +0300 |
commit | 9e68f4ed53ac6972474e2d0e4b00574cd374cd82 (patch) | |
tree | dbc3294ef862d35f985f78b83804a29fe165ccce /src | |
parent | code style (diff) | |
download | winapi-debug-9e68f4ed53ac6972474e2d0e4b00574cd374cd82.tar.gz winapi-debug-9e68f4ed53ac6972474e2d0e4b00574cd374cd82.zip |
code style
Diffstat (limited to 'src')
-rw-r--r-- | src/dbghelp.cpp | 98 | ||||
-rw-r--r-- | src/module.cpp | 2 |
2 files changed, 44 insertions, 56 deletions
diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp index 7d94f8b..30829d4 100644 --- a/src/dbghelp.cpp +++ b/src/dbghelp.cpp @@ -12,7 +12,6 @@ #include <cstddef> -#include <limits> #include <stdexcept> #include <string> @@ -28,15 +27,14 @@ namespace pdb void initialize(HANDLE id) { enable_debug_output(); - const auto ret = SymInitialize(id, NULL, FALSE); - if (!ret) + + if (!SymInitialize(id, NULL, FALSE)) throw error::windows(GetLastError()); } void clean_up(HANDLE id) { - const auto ret = SymCleanup(id); - if (!ret) + if (!SymCleanup(id)) throw error::windows(GetLastError()); } @@ -45,10 +43,8 @@ namespace pdb Address gen_next_offline_base(std::size_t pdb_size) { const auto base = next_offline_base; - if (!msl::utilities::SafeAdd( - next_offline_base, - pdb_size, - next_offline_base)) + using msl::utilities::SafeAdd; + if (!SafeAdd(next_offline_base, pdb_size, next_offline_base)) throw std::runtime_error{"no more PDB files can be added, the internal address space is exhausted"}; return base; } @@ -70,6 +66,25 @@ namespace pdb initialize(id); } + DbgHelp::~DbgHelp() + { + try + { + close(); + } + catch (...) + { } + } + + void DbgHelp::close() + { + if (!closed) + { + clean_up(id); + closed = true; + } + } + ModuleInfo DbgHelp::load_pdb(const std::string& path) const { DWORD size = 0; @@ -94,12 +109,10 @@ namespace pdb { ModuleInfo info; - const auto ret = SymGetModuleInfo64( - id, - offline_base, - &static_cast<ModuleInfo::Raw&>(info)); - - if (!ret) + if (!SymGetModuleInfo64( + id, + offline_base, + &static_cast<ModuleInfo::Raw&>(info))) throw error::windows(GetLastError()); return info; @@ -107,14 +120,12 @@ namespace pdb void DbgHelp::enum_symbols(const ModuleInfo& module, const OnSymbol& callback) const { - const auto ret = SymEnumSymbols( - id, - module.get_offline_base(), - NULL, - &enum_symbols_callback, - const_cast<OnSymbol*>(&callback)); - - if (!ret) + if (!SymEnumSymbols( + id, + module.get_offline_base(), + NULL, + &enum_symbols_callback, + const_cast<OnSymbol*>(&callback))) throw error::windows(GetLastError()); } @@ -123,13 +134,11 @@ namespace pdb Address displacement = 0; SymbolInfo symbol; - const auto ret = SymFromAddr( - id, - online, - &displacement, - &static_cast<SYMBOL_INFO&>(symbol)); - - if (!ret) + if (!SymFromAddr( + id, + online, + &displacement, + &static_cast<SYMBOL_INFO&>(symbol))) throw error::windows(GetLastError()); symbol.set_displacement(displacement); @@ -140,33 +149,12 @@ namespace pdb { SymbolInfo symbol; - const auto ret = SymFromName( - id, - name.c_str(), - &static_cast<SYMBOL_INFO&>(symbol)); - - if (!ret) + if (!SymFromName( + id, + name.c_str(), + &static_cast<SYMBOL_INFO&>(symbol))) throw error::windows(GetLastError()); return symbol; } - - void DbgHelp::close() - { - if (!closed) - { - clean_up(id); - closed = true; - } - } - - DbgHelp::~DbgHelp() - { - try - { - close(); - } - catch (...) - { } - } } diff --git a/src/module.cpp b/src/module.cpp index 3694e5f..2c1d26c 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -23,7 +23,7 @@ namespace pdb : raw{raw} { if (raw.SizeOfStruct != sizeof(raw)) - throw std::runtime_error{"unexpected module structure size"}; + throw std::runtime_error{"invalid IMAGEHLP_MODULE64.SizeOfStruct"}; } ModuleInfo::Raw ModuleInfo::create_raw() |