From 9e68f4ed53ac6972474e2d0e4b00574cd374cd82 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 20 May 2017 04:12:31 +0300 Subject: code style --- src/dbghelp.cpp | 98 +++++++++++++++++++++++++-------------------------------- 1 file changed, 43 insertions(+), 55 deletions(-) (limited to 'src/dbghelp.cpp') 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 -#include #include #include @@ -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(info)); - - if (!ret) + if (!SymGetModuleInfo64( + id, + offline_base, + &static_cast(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(&callback)); - - if (!ret) + if (!SymEnumSymbols( + id, + module.get_offline_base(), + NULL, + &enum_symbols_callback, + const_cast(&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)); - - if (!ret) + if (!SymFromAddr( + id, + online, + &displacement, + &static_cast(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)); - - if (!ret) + if (!SymFromName( + id, + name.c_str(), + &static_cast(symbol))) throw error::windows(GetLastError()); return symbol; } - - void DbgHelp::close() - { - if (!closed) - { - clean_up(id); - closed = true; - } - } - - DbgHelp::~DbgHelp() - { - try - { - close(); - } - catch (...) - { } - } } -- cgit v1.2.3