diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/CMakeLists.txt | 2 | ||||
-rw-r--r-- | utils/addr2name.cpp | 11 | ||||
-rw-r--r-- | utils/command_line.hpp | 28 | ||||
-rw-r--r-- | utils/enum_symbols.cpp | 9 | ||||
-rw-r--r-- | utils/name2addr.cpp | 11 |
5 files changed, 41 insertions, 20 deletions
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index ee5c5ba..a34d72a 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -3,7 +3,7 @@ find_package(Boost REQUIRED COMPONENTS filesystem program_options) function(add_util name src) add_executable("${name}" ${src}) target_link_libraries("${name}" PRIVATE pdb_repo) - target_link_libraries("${name}" PRIVATE Boost::filesystem Boost::program_options) + target_link_libraries("${name}" PRIVATE Boost::filesystem Boost::nowide Boost::program_options) install(TARGETS "${name}" RUNTIME DESTINATION bin) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") install(FILES "$<TARGET_PDB_FILE:${name}>" DESTINATION bin OPTIONAL) diff --git a/utils/addr2name.cpp b/utils/addr2name.cpp index bac508e..710a2ff 100644 --- a/utils/addr2name.cpp +++ b/utils/addr2name.cpp @@ -7,6 +7,7 @@ #include "pdb/all.hpp" #include "pdb_descr.hpp" +#include <boost/nowide/iostream.hpp> #include <boost/program_options.hpp> #include <exception> @@ -19,7 +20,7 @@ namespace { class Addr2Name : public SettingsParser { public: - explicit Addr2Name(const std::string& argv0) : SettingsParser{argv0} { + explicit Addr2Name(int argc, char** argv) : SettingsParser{argc, argv} { namespace po = boost::program_options; visible.add_options()( @@ -57,7 +58,7 @@ std::string format_line_info(const pdb::LineInfo& line_info) { } void dump_error(const std::exception& e) { - std::cerr << "error: " << e.what() << '\n'; + boost::nowide::cerr << "error: " << e.what() << '\n'; } void resolve_symbol(const pdb::Repo& repo, pdb::Address address, bool lines = false) { @@ -77,10 +78,10 @@ void resolve_symbol(const pdb::Repo& repo, pdb::Address address, bool lines = fa } } - std::cout << msg.str() << '\n'; + boost::nowide::cout << msg.str() << '\n'; } catch (const std::exception& e) { dump_error(e); - std::cout << pdb::format_address(address) << '\n'; + boost::nowide::cout << pdb::format_address(address) << '\n'; } } @@ -88,7 +89,7 @@ void resolve_symbol(const pdb::Repo& repo, pdb::Address address, bool lines = fa int main(int argc, char* argv[]) { try { - Addr2Name settings{argv[0]}; + Addr2Name settings{argc, argv}; try { settings.parse(argc, argv); diff --git a/utils/command_line.hpp b/utils/command_line.hpp index f99c3c1..9fe6b98 100644 --- a/utils/command_line.hpp +++ b/utils/command_line.hpp @@ -6,6 +6,9 @@ #pragma once #include <boost/filesystem.hpp> +#include <boost/nowide/args.hpp> +#include <boost/nowide/filesystem.hpp> +#include <boost/nowide/iostream.hpp> #include <boost/program_options.hpp> #include <exception> @@ -13,9 +16,23 @@ #include <ostream> #include <string> +class Args { +public: + Args(int argc, char** argv) : argc{argc}, argv{argv}, impl{this->argc, this->argv} { + boost::nowide::nowide_filesystem(); + } + + int argc; + char** argv; + +private: + const boost::nowide::args impl; +}; + class SettingsParser { public: - explicit SettingsParser(const std::string& argv0) : prog_name{extract_filename(argv0)} { + explicit SettingsParser(int argc, char** argv) + : args{argc, argv}, prog_name{extract_filename(args.argv[0])} { visible.add_options()("help,h", "show this message and exit"); } @@ -40,11 +57,11 @@ public: bool exit_with_usage = false; - void usage() const { std::cout << *this; } + void usage() const { boost::nowide::cout << *this; } void usage_error(const std::exception& e) const { - std::cerr << "usage error: " << e.what() << '\n'; - std::cerr << *this; + boost::nowide::cerr << "usage error: " << e.what() << '\n'; + boost::nowide::cerr << *this; } protected: @@ -53,10 +70,11 @@ protected: boost::program_options::positional_options_description positional; private: - static std::string extract_filename(const std::string& path) { + static std::string extract_filename(char* path) { return boost::filesystem::path{path}.filename().string(); } + const Args args; const std::string prog_name; friend std::ostream& operator<<(std::ostream& os, const SettingsParser& parser) { diff --git a/utils/enum_symbols.cpp b/utils/enum_symbols.cpp index 123c9d1..49dbfed 100644 --- a/utils/enum_symbols.cpp +++ b/utils/enum_symbols.cpp @@ -6,6 +6,7 @@ #include "command_line.hpp" #include "pdb/all.hpp" +#include <boost/nowide/iostream.hpp> #include <boost/program_options.hpp> #include <exception> @@ -17,7 +18,7 @@ namespace { class EnumSymbols : public SettingsParser { public: - explicit EnumSymbols(const std::string& argv0) : SettingsParser{argv0} { + explicit EnumSymbols(int argc, char** argv) : SettingsParser{argc, argv} { namespace po = boost::program_options; visible.add_options()("pdb", @@ -58,7 +59,7 @@ constexpr pdb::symbol::Tag EnumSymbols::function_tag; int main(int argc, char* argv[]) { try { - EnumSymbols settings{argv[0]}; + EnumSymbols settings{argc, argv}; try { settings.parse(argc, argv); @@ -79,11 +80,11 @@ int main(int argc, char* argv[]) { dbghelp.enum_symbols(id, settings.get_mask(), [&](const pdb::SymbolInfo& symbol) { if (!settings.type_specified() || settings.get_type() == symbol.get_type()) - std::cout << symbol.get_name() << '\n'; + boost::nowide::cout << symbol.get_name() << '\n'; }); } } catch (const std::exception& e) { - std::cerr << "error: " << e.what() << '\n'; + boost::nowide::cerr << "error: " << e.what() << '\n'; return 1; } return 0; diff --git a/utils/name2addr.cpp b/utils/name2addr.cpp index aeaa13a..4b83757 100644 --- a/utils/name2addr.cpp +++ b/utils/name2addr.cpp @@ -7,6 +7,7 @@ #include "pdb/all.hpp" #include "pdb_descr.hpp" +#include <boost/nowide/iostream.hpp> #include <boost/program_options.hpp> #include <exception> @@ -18,7 +19,7 @@ namespace { class Name2Addr : public SettingsParser { public: - explicit Name2Addr(const std::string& argv0) : SettingsParser{argv0} { + explicit Name2Addr(int argc, char** argv) : SettingsParser{argc, argv} { namespace po = boost::program_options; visible.add_options()( @@ -38,16 +39,16 @@ public: }; void dump_error(const std::exception& e) { - std::cerr << "error: " << e.what() << '\n'; + boost::nowide::cerr << "error: " << e.what() << '\n'; } void resolve_symbol(const pdb::Repo& repo, const std::string& name) { try { const auto address = repo.resolve_symbol(name).get_online_address(); - std::cout << pdb::format_address(address) << '\n'; + boost::nowide::cout << pdb::format_address(address) << '\n'; } catch (const std::exception& e) { dump_error(e); - std::cout << name << '\n'; + boost::nowide::cout << name << '\n'; } } @@ -55,7 +56,7 @@ void resolve_symbol(const pdb::Repo& repo, const std::string& name) { int main(int argc, char* argv[]) { try { - Name2Addr settings{argv[0]}; + Name2Addr settings{argc, argv}; try { settings.parse(argc, argv); |