diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-29 01:33:39 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-29 01:34:04 +0300 |
commit | bc78e3308f8bf74a8935f9ef8fd28825d6b48c2f (patch) | |
tree | e496012c405316287ef67ebcfecf5f40d4a9a656 | |
parent | rename class Repo to PostMortem (diff) | |
download | winapi-debug-bc78e3308f8bf74a8935f9ef8fd28825d6b48c2f.tar.gz winapi-debug-bc78e3308f8bf74a8935f9ef8fd28825d6b48c2f.zip |
move _address functions to winapi::address
-rw-r--r-- | include/winapi/debug/address.hpp | 11 | ||||
-rw-r--r-- | src/call_stack.cpp | 6 | ||||
-rw-r--r-- | src/module.cpp | 8 | ||||
-rw-r--r-- | src/post_mortem.cpp | 10 | ||||
-rw-r--r-- | test/test_lib.cpp | 6 | ||||
-rw-r--r-- | test/unit_tests/call_stack.cpp | 8 | ||||
-rw-r--r-- | utils/addr2name.cpp | 4 | ||||
-rw-r--r-- | utils/name2addr.cpp | 2 | ||||
-rw-r--r-- | utils/pdb_descr.hpp | 4 |
9 files changed, 31 insertions, 28 deletions
diff --git a/include/winapi/debug/address.hpp b/include/winapi/debug/address.hpp index 1370ed4..e5db42d 100644 --- a/include/winapi/debug/address.hpp +++ b/include/winapi/debug/address.hpp @@ -14,21 +14,24 @@ namespace winapi { typedef DWORD64 Address; -inline std::string format_address(Address address) { +namespace address { + +inline std::string format(Address address) { std::ostringstream oss; oss << std::hex << std::showbase << address; return oss.str(); } -inline std::string format_address(void* address) { - return format_address(reinterpret_cast<Address>(address)); +inline std::string format(void* address) { + return format(reinterpret_cast<Address>(address)); } -inline bool parse_address(Address& dest, const std::string& src) { +inline bool parse(Address& dest, const std::string& src) { std::istringstream iss{src}; iss >> std::hex; char c; return iss >> dest && !iss.get(c); } +} // namespace address } // namespace winapi diff --git a/src/call_stack.cpp b/src/call_stack.cpp index 30abaad..4a13b3a 100644 --- a/src/call_stack.cpp +++ b/src/call_stack.cpp @@ -27,14 +27,14 @@ static std::string put_between_brackets(const T& x) { } std::string format_address_fallback(Address addr) { - return put_between_brackets(format_address(addr)); + return put_between_brackets(address::format(addr)); } std::string offset_from(const std::string& thing, Address offset) { if (offset == 0) return put_between_brackets(thing); else - return put_between_brackets(thing + "+" + format_address(offset)); + return put_between_brackets(thing + "+" + address::format(offset)); } std::string offset_from_module(const ModuleInfo& module, Address addr) { @@ -107,7 +107,7 @@ std::string CallStack::pretty_print_address(const DbgHelp& dbghelp, Address addr void CallStack::dump(std::ostream& os, const DbgHelp& dbghelp) const { for_each_address([&](Address addr) { - os << format_address(addr) << ' ' << pretty_print_address(dbghelp, addr) << '\n'; + os << address::format(addr) << ' ' << pretty_print_address(dbghelp, addr) << '\n'; return true; }); } diff --git a/src/module.cpp b/src/module.cpp index d676151..47d8eaf 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -60,15 +60,15 @@ Address Module::translate_online_address(Address online) const { std::string Module::invalid_offline_address(Address offline) const { std::ostringstream oss; - oss << "offline address " << format_address(offline) << " doesn't belong to module " - << get_name() << " (base offline address " << format_address(get_offline_base()) << ')'; + oss << "offline address " << address::format(offline) << " doesn't belong to module " + << get_name() << " (base offline address " << address::format(get_offline_base()) << ')'; return oss.str(); } std::string Module::invalid_online_address(Address online) const { std::ostringstream oss; - oss << "online address " << format_address(online) << " doesn't belong to module " << get_name() - << " (base online address " << format_address(get_online_base()) << ')'; + oss << "online address " << address::format(online) << " doesn't belong to module " + << get_name() << " (base online address " << address::format(get_online_base()) << ')'; return oss.str(); } diff --git a/src/post_mortem.cpp b/src/post_mortem.cpp index d365b02..01f180a 100644 --- a/src/post_mortem.cpp +++ b/src/post_mortem.cpp @@ -17,7 +17,7 @@ namespace { std::string pdb_already_loaded(Address online_base, const std::string& path) { std::ostringstream oss; - oss << "module with online base address " << format_address(online_base) + oss << "module with online base address " << address::format(online_base) << " has already been loaded: " << path; return oss.str(); } @@ -30,27 +30,27 @@ std::string pdb_already_loaded(const std::string& path) { std::string offline_base_already_used(Address base) { std::ostringstream oss; - oss << "module with offline base address " << format_address(base) + oss << "module with offline base address " << address::format(base) << " has already been loaded (shouldn't happen)"; return oss.str(); } std::string module_not_found(Address base) { std::ostringstream oss; - oss << "module with base address " << format_address(base) << " wasn't found"; + oss << "module with base address " << address::format(base) << " wasn't found"; return oss.str(); } std::string guess_module_no_modules(Address pivot) { std::ostringstream oss; - oss << "couldn't select a module for address " << format_address(pivot) + oss << "couldn't select a module for address " << address::format(pivot) << ": no modules have been loaded yet"; return oss.str(); } std::string guess_module_address_too_low(Address pivot) { std::ostringstream oss; - oss << "couldn't select a module for address " << format_address(pivot) << ": it's too low"; + oss << "couldn't select a module for address " << address::format(pivot) << ": it's too low"; return oss.str(); } diff --git a/test/test_lib.cpp b/test/test_lib.cpp index bdb7bbf..caecc8b 100644 --- a/test/test_lib.cpp +++ b/test/test_lib.cpp @@ -32,17 +32,17 @@ void do_throw_call_stack() { volatile int var = 42; void baz(F f) { - std::cout << "baz " << winapi::format_address(reinterpret_cast<void*>(&baz)) << '\n'; + std::cout << "baz " << winapi::address::format(reinterpret_cast<void*>(&baz)) << '\n'; f(); } void bar(F f) { - std::cout << "bar " << winapi::format_address(reinterpret_cast<void*>(&bar)) << '\n'; + std::cout << "bar " << winapi::address::format(reinterpret_cast<void*>(&bar)) << '\n'; baz(f); } void foo(F f) { - std::cout << "foo " << winapi::format_address(reinterpret_cast<void*>(&foo)) << '\n'; + std::cout << "foo " << winapi::address::format(reinterpret_cast<void*>(&foo)) << '\n'; bar(f); } diff --git a/test/unit_tests/call_stack.cpp b/test/unit_tests/call_stack.cpp index 2f022c6..039e8f9 100644 --- a/test/unit_tests/call_stack.cpp +++ b/test/unit_tests/call_stack.cpp @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(call_stack) { BOOST_TEST_MESSAGE("Call stack:"); for (const auto& addr : call_stack) { pretty.emplace_back(call_stack.pretty_print_address(dbghelp, addr)); - BOOST_TEST_MESSAGE('\t' << winapi::format_address(addr) << ' ' << pretty.back()); + BOOST_TEST_MESSAGE('\t' << winapi::address::format(addr) << ' ' << pretty.back()); } // Second, resolve the symbols: @@ -43,12 +43,12 @@ BOOST_AUTO_TEST_CASE(call_stack) { for (const auto& addr : call_stack) { try { auto symbol = dbghelp.resolve_symbol(addr); - BOOST_TEST_MESSAGE('\t' << winapi::format_address(symbol.get_offline_address()) + BOOST_TEST_MESSAGE('\t' << winapi::address::format(symbol.get_offline_address()) << ' ' << symbol.get_name()); symbols.emplace_back(std::move(symbol)); } catch (const std::system_error& e) { symbols.emplace_back(boost::none); - BOOST_TEST_MESSAGE('\t' << winapi::format_address(addr) + BOOST_TEST_MESSAGE('\t' << winapi::address::format(addr) << " Couldn't resolve symbol: " << e.what()); } } @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(call_stack) { }; for (const auto& addr : expected) { BOOST_TEST(check(addr), - "Function frame captured: " << winapi::format_address(addr)); + "Function frame captured: " << winapi::address::format(addr)); } } diff --git a/utils/addr2name.cpp b/utils/addr2name.cpp index 5a8cbc3..333ef29 100644 --- a/utils/addr2name.cpp +++ b/utils/addr2name.cpp @@ -48,7 +48,7 @@ std::string format_symbol(const winapi::Module& module, const winapi::Symbol& sy oss << module.get_name() << '!' << symbol.get_name(); const auto displacement = symbol.get_displacement(); if (displacement) - oss << '+' << winapi::format_address(displacement); + oss << '+' << winapi::address::format(displacement); return oss.str(); } @@ -84,7 +84,7 @@ void resolve_symbol(const winapi::PostMortem& analysis, std::cout << msg.str() << '\n'; } catch (const std::exception& e) { dump_error(e); - std::cout << winapi::format_address(address) << '\n'; + std::cout << winapi::address::format(address) << '\n'; } } diff --git a/utils/name2addr.cpp b/utils/name2addr.cpp index c113a9a..105b94e 100644 --- a/utils/name2addr.cpp +++ b/utils/name2addr.cpp @@ -45,7 +45,7 @@ void dump_error(const std::exception& e) { void resolve_symbol(const winapi::PostMortem& analysis, const std::string& name) { try { const auto address = analysis.resolve_symbol(name).get_online_address(); - std::cout << winapi::format_address(address) << '\n'; + std::cout << winapi::address::format(address) << '\n'; } catch (const std::exception& e) { dump_error(e); std::cout << name << '\n'; diff --git a/utils/pdb_descr.hpp b/utils/pdb_descr.hpp index 5925b93..e00020f 100644 --- a/utils/pdb_descr.hpp +++ b/utils/pdb_descr.hpp @@ -25,7 +25,7 @@ struct PDB { boost::throw_exception(boost::program_options::invalid_option_value{src}); winapi::Address online_base; - if (!winapi::parse_address(online_base, src.substr(0, sep_pos))) + if (!winapi::address::parse(online_base, src.substr(0, sep_pos))) boost::throw_exception(boost::program_options::invalid_option_value{src}); return {online_base, src.substr(sep_pos + 1)}; @@ -33,7 +33,7 @@ struct PDB { static winapi::Address parse_address(const std::string& src) { winapi::Address dest; - if (!winapi::parse_address(dest, src)) + if (!winapi::address::parse(dest, src)) boost::throw_exception(boost::program_options::invalid_option_value{src}); return dest; } |