diff options
| -rw-r--r-- | include/winapi/debug/address.hpp | 5 | ||||
| -rw-r--r-- | include/winapi/debug/dbghelp.hpp | 10 | ||||
| -rw-r--r-- | include/winapi/debug/post_mortem.hpp | 6 | ||||
| -rw-r--r-- | src/call_stack.cpp | 5 | ||||
| -rw-r--r-- | src/dbghelp.cpp | 10 | ||||
| -rw-r--r-- | src/post_mortem.cpp | 8 | ||||
| -rw-r--r-- | utils/name2addr.cpp | 3 | ||||
| -rw-r--r-- | utils/pdb_descr.hpp | 3 |
8 files changed, 27 insertions, 23 deletions
diff --git a/include/winapi/debug/address.hpp b/include/winapi/debug/address.hpp index a5f186e..9fe6e2b 100644 --- a/include/winapi/debug/address.hpp +++ b/include/winapi/debug/address.hpp @@ -10,6 +10,7 @@ #include <charconv> #include <format> #include <string> +#include <string_view> namespace winapi { @@ -25,9 +26,9 @@ inline std::string format(void* address) { return format(reinterpret_cast<Address>(address)); } -inline bool parse(Address& dest, const std::string& src) { +inline bool parse(Address& dest, std::string_view src) { Address result; - const auto [ptr, ec] = std::from_chars(src.c_str(), src.c_str() + src.length(), result, 16); + const auto [ptr, ec] = std::from_chars(src.data(), src.data() + src.length(), result, 16); if (ec == std::errc()) { dest = result; return true; diff --git a/include/winapi/debug/dbghelp.hpp b/include/winapi/debug/dbghelp.hpp index fb179f3..29e56e7 100644 --- a/include/winapi/debug/dbghelp.hpp +++ b/include/winapi/debug/dbghelp.hpp @@ -12,7 +12,7 @@ #include <windows.h> #include <functional> -#include <string> +#include <string_view> namespace winapi { @@ -27,7 +27,7 @@ public: DbgHelp& operator=(DbgHelp) noexcept; ~DbgHelp(); - ModuleInfo load_pdb(const std::string& path) const; + ModuleInfo load_pdb(std::string_view path) const; typedef std::function<void(const ModuleInfo&)> OnModule; void enum_modules(const OnModule&) const; @@ -36,13 +36,13 @@ public: typedef std::function<void(const SymbolInfo&)> OnSymbol; static constexpr auto all_symbols = "*!*"; - void enum_symbols(const ModuleInfo&, const std::string& mask, const OnSymbol&) const; + void enum_symbols(const ModuleInfo&, std::string_view mask, const OnSymbol&) const; void enum_symbols(const ModuleInfo&, const OnSymbol&) const; - void enum_symbols(const std::string& mask, const OnSymbol&) const; + void enum_symbols(std::string_view mask, const OnSymbol&) const; void enum_symbols(const OnSymbol&) const; SymbolInfo resolve_symbol(Address) const; - SymbolInfo resolve_symbol(const std::string&) const; + SymbolInfo resolve_symbol(std::string_view) const; LineInfo resolve_line(Address) const; diff --git a/include/winapi/debug/post_mortem.hpp b/include/winapi/debug/post_mortem.hpp index bf4ad83..5ddc85e 100644 --- a/include/winapi/debug/post_mortem.hpp +++ b/include/winapi/debug/post_mortem.hpp @@ -14,7 +14,7 @@ #include <functional> #include <map> -#include <string> +#include <string_view> #include <unordered_set> namespace winapi { @@ -23,7 +23,7 @@ class PostMortem { public: PostMortem() = default; - Address add_pdb(Address online_base, const std::string& path); + Address add_pdb(Address online_base, std::string_view path); typedef std::function<void(const Symbol&)> OnSymbol; void enum_symbols(const OnSymbol&) const; @@ -31,7 +31,7 @@ public: void enum_symbols(const Module&, const OnSymbol&) const; Symbol resolve_symbol(Address) const; - Symbol resolve_symbol(const std::string&) const; + Symbol resolve_symbol(std::string_view) const; LineInfo resolve_line(Address) const; diff --git a/src/call_stack.cpp b/src/call_stack.cpp index 6e4bd29..b79a32b 100644 --- a/src/call_stack.cpp +++ b/src/call_stack.cpp @@ -14,6 +14,7 @@ #include <ostream> #include <stdexcept> #include <string> +#include <string_view> #include <system_error> namespace winapi { @@ -28,11 +29,11 @@ std::string format_address_fallback(Address addr) { return put_between_brackets(address::format(addr)); } -std::string offset_from(const std::string& thing, Address offset) { +std::string offset_from(std::string_view thing, Address offset) { if (offset == 0) return put_between_brackets(thing); else - return put_between_brackets(thing + "+" + address::format(offset)); + return put_between_brackets(std::format("{}+{}", thing, "+", address::format(offset))); } std::string offset_from_module(const ModuleInfo& module, Address addr) { diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp index 46905c5..20f23c3 100644 --- a/src/dbghelp.cpp +++ b/src/dbghelp.cpp @@ -81,7 +81,7 @@ BOOL CALLBACK enum_symbols_callback(SYMBOL_INFOW* info, ULONG, VOID* raw_callbac void enum_symbols(HANDLE id, Address module_base, - const std::string& mask, + std::string_view mask, const DbgHelp::OnSymbol& callback) { if (!SymEnumSymbolsW(id, module_base, @@ -123,7 +123,7 @@ void DbgHelp::close() { clean_up(id); } -ModuleInfo DbgHelp::load_pdb(const std::string& path) const { +ModuleInfo DbgHelp::load_pdb(std::string_view path) const { DWORD size = 0; { @@ -160,7 +160,7 @@ ModuleInfo DbgHelp::resolve_module(Address offline) const { } void DbgHelp::enum_symbols(const ModuleInfo& module, - const std::string& mask, + std::string_view mask, const OnSymbol& callback) const { winapi::enum_symbols(id, module.get_offline_base(), mask, callback); } @@ -169,7 +169,7 @@ void DbgHelp::enum_symbols(const ModuleInfo& module, const OnSymbol& callback) c enum_symbols(module, all_symbols, callback); } -void DbgHelp::enum_symbols(const std::string& mask, const OnSymbol& callback) const { +void DbgHelp::enum_symbols(std::string_view mask, const OnSymbol& callback) const { winapi::enum_symbols(id, 0, mask, callback); } @@ -188,7 +188,7 @@ SymbolInfo DbgHelp::resolve_symbol(Address offline) const { return symbol; } -SymbolInfo DbgHelp::resolve_symbol(const std::string& name) const { +SymbolInfo DbgHelp::resolve_symbol(std::string_view name) const { SymbolInfo symbol; if (!SymFromNameW(id, winapi::widen(name).c_str(), &static_cast<SYMBOL_INFOW&>(symbol))) diff --git a/src/post_mortem.cpp b/src/post_mortem.cpp index 2db7ee9..84da809 100644 --- a/src/post_mortem.cpp +++ b/src/post_mortem.cpp @@ -15,13 +15,13 @@ namespace winapi { namespace { -std::string pdb_already_loaded(Address online_base, const std::string& path) { +std::string pdb_already_loaded(Address online_base, std::string_view path) { return std::format("module with online base address {} has already been loaded: {}", address::format(online_base), path); } -std::string pdb_already_loaded(const std::string& path) { +std::string pdb_already_loaded(std::string_view path) { return std::format("module has already been loaded: {}", path); } @@ -77,7 +77,7 @@ const Module& guess_module(const std::map<Address, Value>& modules, Address pivo } // namespace -Address PostMortem::add_pdb(Address online_base, const std::string& path) { +Address PostMortem::add_pdb(Address online_base, std::string_view path) { if (online_bases.find(online_base) != online_bases.cend()) throw std::runtime_error{pdb_already_loaded(online_base, path)}; @@ -119,7 +119,7 @@ Symbol PostMortem::resolve_symbol(Address online) const { return symbol_from_buffer(dbghelp.resolve_symbol(address_online_to_offline(online))); } -Symbol PostMortem::resolve_symbol(const std::string& name) const { +Symbol PostMortem::resolve_symbol(std::string_view name) const { return symbol_from_buffer(dbghelp.resolve_symbol(name)); } diff --git a/utils/name2addr.cpp b/utils/name2addr.cpp index 105b94e..d17919b 100644 --- a/utils/name2addr.cpp +++ b/utils/name2addr.cpp @@ -13,6 +13,7 @@ #include <exception> #include <iostream> #include <string> +#include <string_view> #include <vector> namespace { @@ -42,7 +43,7 @@ void dump_error(const std::exception& e) { std::cerr << "error: " << e.what() << '\n'; } -void resolve_symbol(const winapi::PostMortem& analysis, const std::string& name) { +void resolve_symbol(const winapi::PostMortem& analysis, std::string_view name) { try { const auto address = analysis.resolve_symbol(name).get_online_address(); std::cout << winapi::address::format(address) << '\n'; diff --git a/utils/pdb_descr.hpp b/utils/pdb_descr.hpp index fbf0950..3e24f2c 100644 --- a/utils/pdb_descr.hpp +++ b/utils/pdb_descr.hpp @@ -10,13 +10,14 @@ #include <boost/program_options.hpp> #include <string> +#include <string_view> #include <vector> struct PDB { winapi::Address online_base; std::string path; - static PDB parse(std::string src) { + static PDB parse(const std::string& src) { static constexpr auto sep = ','; const auto sep_pos = src.find(sep); |
