diff options
| -rw-r--r-- | include/winapi/debug/address.hpp | 18 | ||||
| -rw-r--r-- | src/call_stack.cpp | 6 | ||||
| -rw-r--r-- | src/module.cpp | 18 | ||||
| -rw-r--r-- | src/post_mortem.cpp | 35 | ||||
| -rw-r--r-- | utils/addr2name.cpp | 14 | ||||
| -rw-r--r-- | utils/pdb_descr.hpp | 1 |
6 files changed, 40 insertions, 52 deletions
diff --git a/include/winapi/debug/address.hpp b/include/winapi/debug/address.hpp index e5db42d..a5f186e 100644 --- a/include/winapi/debug/address.hpp +++ b/include/winapi/debug/address.hpp @@ -7,7 +7,8 @@ #include <windows.h> -#include <sstream> +#include <charconv> +#include <format> #include <string> namespace winapi { @@ -17,9 +18,7 @@ typedef DWORD64 Address; namespace address { inline std::string format(Address address) { - std::ostringstream oss; - oss << std::hex << std::showbase << address; - return oss.str(); + return std::format("{:#x}", address); } inline std::string format(void* address) { @@ -27,10 +26,13 @@ inline std::string format(void* address) { } inline bool parse(Address& dest, const std::string& src) { - std::istringstream iss{src}; - iss >> std::hex; - char c; - return iss >> dest && !iss.get(c); + Address result; + const auto [ptr, ec] = std::from_chars(src.c_str(), src.c_str() + src.length(), result, 16); + if (ec == std::errc()) { + dest = result; + return true; + } + return false; } } // namespace address diff --git a/src/call_stack.cpp b/src/call_stack.cpp index e69c10d..6e4bd29 100644 --- a/src/call_stack.cpp +++ b/src/call_stack.cpp @@ -10,8 +10,8 @@ #include <algorithm> #include <array> #include <cstddef> +#include <format> #include <ostream> -#include <sstream> #include <stdexcept> #include <string> #include <system_error> @@ -21,9 +21,7 @@ namespace { template <typename T> static std::string put_between_brackets(const T& x) { - std::ostringstream oss; - oss << "[" << x << "]"; - return oss.str(); + return std::format("[{}]", x); } std::string format_address_fallback(Address addr) { diff --git a/src/module.cpp b/src/module.cpp index 47d8eaf..ae4a95f 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -7,8 +7,8 @@ #include <winapi/utf8.hpp> #include <cstring> +#include <format> #include <limits> -#include <sstream> #include <stdexcept> #include <string> @@ -59,17 +59,17 @@ Address Module::translate_online_address(Address online) const { } std::string Module::invalid_offline_address(Address offline) const { - std::ostringstream oss; - oss << "offline address " << address::format(offline) << " doesn't belong to module " - << get_name() << " (base offline address " << address::format(get_offline_base()) << ')'; - return oss.str(); + return std::format("offline address {} doesn't belong to module {} (base offline address {})", + address::format(offline), + get_name(), + address::format(get_offline_base())); } std::string Module::invalid_online_address(Address online) const { - std::ostringstream oss; - oss << "online address " << address::format(online) << " doesn't belong to module " - << get_name() << " (base online address " << address::format(get_online_base()) << ')'; - return oss.str(); + return std::format("online address {} doesn't belong to module {} (base online address {})", + address::format(online), + get_name(), + address::format(get_online_base())); } } // namespace winapi diff --git a/src/post_mortem.cpp b/src/post_mortem.cpp index 01f180a..2db7ee9 100644 --- a/src/post_mortem.cpp +++ b/src/post_mortem.cpp @@ -6,8 +6,8 @@ #include <winapi/debug.hpp> #include <winapi/file.hpp> +#include <format> #include <map> -#include <sstream> #include <stdexcept> #include <string> #include <utility> @@ -16,42 +16,33 @@ namespace winapi { namespace { std::string pdb_already_loaded(Address online_base, const std::string& path) { - std::ostringstream oss; - oss << "module with online base address " << address::format(online_base) - << " has already been loaded: " << path; - return oss.str(); + 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::ostringstream oss; - oss << "module has already been loaded: " << path; - return oss.str(); + return std::format("module has already been loaded: {}", path); } std::string offline_base_already_used(Address base) { - std::ostringstream oss; - oss << "module with offline base address " << address::format(base) - << " has already been loaded (shouldn't happen)"; - return oss.str(); + return std::format( + "module with offline base address {} has already been loaded (shouldn't happen)", + address::format(base)); } std::string module_not_found(Address base) { - std::ostringstream oss; - oss << "module with base address " << address::format(base) << " wasn't found"; - return oss.str(); + return std::format("module with base address {} wasn't found", address::format(base)); } std::string guess_module_no_modules(Address pivot) { - std::ostringstream oss; - oss << "couldn't select a module for address " << address::format(pivot) - << ": no modules have been loaded yet"; - return oss.str(); + return std::format("couldn't select a module for address {}: no modules have been loaded yet", + address::format(pivot)); } std::string guess_module_address_too_low(Address pivot) { - std::ostringstream oss; - oss << "couldn't select a module for address " << address::format(pivot) << ": it's too low"; - return oss.str(); + return std::format("couldn't select a module for address {}: it's too low", + address::format(pivot)); } template <typename Value> diff --git a/utils/addr2name.cpp b/utils/addr2name.cpp index 333ef29..4f1f686 100644 --- a/utils/addr2name.cpp +++ b/utils/addr2name.cpp @@ -11,6 +11,7 @@ #include <boost/program_options.hpp> #include <exception> +#include <format> #include <iostream> #include <sstream> #include <string> @@ -44,18 +45,15 @@ public: }; std::string format_symbol(const winapi::Module& module, const winapi::Symbol& symbol) { - std::ostringstream oss; - oss << module.get_name() << '!' << symbol.get_name(); + const auto symbol_str = std::format("{}!{}", module.get_name(), symbol.get_name()); const auto displacement = symbol.get_displacement(); - if (displacement) - oss << '+' << winapi::address::format(displacement); - return oss.str(); + if (!displacement) + return symbol_str; + return std::format("{}+{}", symbol_str, winapi::address::format(displacement)); } std::string format_line_info(const winapi::LineInfo& line_info) { - std::ostringstream oss; - oss << '[' << line_info.file_path << " @ " << line_info.line_number << ']'; - return oss.str(); + return std::format("[{} @ {}]", line_info.file_path, line_info.line_number); } void dump_error(const std::exception& e) { diff --git a/utils/pdb_descr.hpp b/utils/pdb_descr.hpp index e00020f..fbf0950 100644 --- a/utils/pdb_descr.hpp +++ b/utils/pdb_descr.hpp @@ -9,7 +9,6 @@ #include <boost/program_options.hpp> -#include <sstream> #include <string> #include <vector> |
