diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-15 22:18:00 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-15 22:40:36 +0300 |
commit | 79c19c6a1c400b28f27ca6f44dd11e07ac43ec85 (patch) | |
tree | c934d0c0e2e2abd4fc85324a37d2e402d01a1200 | |
parent | get rid of SafeInt (diff) | |
download | winapi-debug-79c19c6a1c400b28f27ca6f44dd11e07ac43ec85.tar.gz winapi-debug-79c19c6a1c400b28f27ca6f44dd11e07ac43ec85.zip |
switch from Boost.Nowide to winapi-utf8
-rw-r--r-- | .clang-format | 8 | ||||
-rw-r--r-- | .gitmodules | 6 | ||||
m--------- | 3rdparty/boost/nowide | 0 | ||||
m--------- | 3rdparty/winapi/utf8 | 0 | ||||
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/dbghelp.cpp | 6 | ||||
-rw-r--r-- | src/error.cpp | 4 | ||||
-rw-r--r-- | src/module.cpp | 4 | ||||
-rw-r--r-- | src/process.cpp | 6 | ||||
-rw-r--r-- | src/symbol.cpp | 7 | ||||
-rw-r--r-- | src/utils/file.cpp | 6 | ||||
-rw-r--r-- | test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/call_stack.cpp | 5 | ||||
-rw-r--r-- | test/test_lib.cpp | 10 | ||||
-rw-r--r-- | test/unit_tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/unit_tests/paths.hpp | 7 | ||||
-rw-r--r-- | utils/CMakeLists.txt | 2 | ||||
-rw-r--r-- | utils/addr2name.cpp | 7 | ||||
-rw-r--r-- | utils/command_line.hpp | 26 | ||||
-rw-r--r-- | utils/enum_symbols.cpp | 5 | ||||
-rw-r--r-- | utils/name2addr.cpp | 7 |
21 files changed, 47 insertions, 78 deletions
diff --git a/.clang-format b/.clang-format index 21ec554..e2ecaef 100644 --- a/.clang-format +++ b/.clang-format @@ -14,10 +14,12 @@ IncludeCategories: Priority: 1 - Regex: '^<test_lib\.|^<pdb\/' Priority: 2 - - Regex: '^<boost\/' + - Regex: '^<winapi\/' Priority: 3 - - Regex: '^<.*\.h>$' + - Regex: '^<boost\/' Priority: 4 - - Regex: '.*' + - Regex: '^<.*\.h>$' Priority: 5 + - Regex: '.*' + Priority: 6 ... diff --git a/.gitmodules b/.gitmodules index 7a1b1cb..9ea0616 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "cmake"] path = cmake url = https://github.com/egor-tensin/cmake-common.git -[submodule "3rdparty/boost/nowide"] - path = 3rdparty/boost/nowide - url = https://github.com/boostorg/nowide.git +[submodule "3rdparty/winapi/utf8"] + path = 3rdparty/winapi/utf8 + url = https://github.com/egor-tensin/winapi-utf8.git diff --git a/3rdparty/boost/nowide b/3rdparty/boost/nowide deleted file mode 160000 -Subproject 7cf83cf3fcaaf0ee496300d8814fa03f627365e diff --git a/3rdparty/winapi/utf8 b/3rdparty/winapi/utf8 new file mode 160000 +Subproject 1d6ff271a9826c5f205fee0ef29b34f5e49190c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a08d9f..4fcad15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,17 +27,17 @@ endif() include(cmake/common.cmake) find_package(Boost REQUIRED) -add_subdirectory(3rdparty/boost/nowide) +add_subdirectory(3rdparty/winapi/utf8) file(GLOB_RECURSE pdb_repo_include "include/*.hpp") file(GLOB_RECURSE pdb_repo_src "src/*.cpp") add_library(pdb_repo ${pdb_repo_include} ${pdb_repo_src}) target_compile_definitions(pdb_repo PUBLIC _NO_CVCONST_H) target_include_directories(pdb_repo PUBLIC include/) -target_include_directories(pdb_repo SYSTEM PUBLIC 3rdparty/microsoft/SafeInt) +target_link_libraries(pdb_repo PRIVATE winapi_utf8) target_link_libraries(pdb_repo PUBLIC Boost::boost - PRIVATE Boost::disable_autolinking Boost::nowide) + PRIVATE Boost::disable_autolinking) target_link_libraries(pdb_repo PRIVATE dbghelp) if(MINGW) diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp index 78b8e88..254ad15 100644 --- a/src/dbghelp.cpp +++ b/src/dbghelp.cpp @@ -5,7 +5,7 @@ #include <pdb/all.hpp> -#include <boost/nowide/convert.hpp> +#include <winapi/utf8.hpp> #include <dbghelp.h> #include <windows.h> @@ -84,7 +84,7 @@ void enum_symbols(HANDLE id, const DbgHelp::OnSymbol& callback) { if (!SymEnumSymbolsW(id, module_base, - boost::nowide::widen(mask).c_str(), + winapi::widen(mask).c_str(), &enum_symbols_callback, const_cast<DbgHelp::OnSymbol*>(&callback))) throw error::windows(GetLastError(), "SymEnumSymbolsW"); @@ -190,7 +190,7 @@ SymbolInfo DbgHelp::resolve_symbol(Address offline) const { SymbolInfo DbgHelp::resolve_symbol(const std::string& name) const { SymbolInfo symbol; - if (!SymFromNameW(id, boost::nowide::widen(name).c_str(), &static_cast<SYMBOL_INFOW&>(symbol))) + if (!SymFromNameW(id, winapi::widen(name).c_str(), &static_cast<SYMBOL_INFOW&>(symbol))) throw error::windows(GetLastError(), "SymFromNameW"); return symbol; diff --git a/src/error.cpp b/src/error.cpp index 368feb7..00252e9 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -5,7 +5,7 @@ #include <pdb/all.hpp> -#include <boost/nowide/convert.hpp> +#include <winapi/utf8.hpp> #include <windows.h> @@ -49,7 +49,7 @@ std::string format_message(int code) { std::wstring msg{buf, len}; LocalFree(buf); - return boost::nowide::narrow(trim_trailing_newline(msg)); + return winapi::narrow(trim_trailing_newline(msg)); } } // namespace diff --git a/src/module.cpp b/src/module.cpp index f05ef03..e43f942 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -5,7 +5,7 @@ #include <pdb/all.hpp> -#include <boost/nowide/convert.hpp> +#include <winapi/utf8.hpp> #include <cstring> #include <limits> @@ -30,7 +30,7 @@ ModuleInfo::Impl ModuleInfo::create_impl() { } std::string ModuleInfo::get_name() const { - return boost::nowide::narrow(impl.ModuleName); + return winapi::narrow(impl.ModuleName); } Address Module::translate_offline_address(Address offline) const { diff --git a/src/process.cpp b/src/process.cpp index adb4b96..022a1b3 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -5,7 +5,7 @@ #include <pdb/all.hpp> -#include <boost/nowide/convert.hpp> +#include <winapi/utf8.hpp> #include <windows.h> @@ -70,7 +70,7 @@ std::string get_current_executable_path(PathBuffer& buffer) { return get_current_executable_path(buffer); } - return boost::nowide::narrow(buffer.get_data()); + return winapi::narrow(buffer.get_data()); } std::string get_current_executable_path() { @@ -84,7 +84,7 @@ std::string get_executable_path(const Handle& process, PathBuffer& buffer) { const auto ec = ::QueryFullProcessImageNameW(process.get(), 0, buffer.get_data(), &size); if (ec != 0) { - return boost::nowide::narrow(buffer.get_data()); + return winapi::narrow(buffer.get_data()); } if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { diff --git a/src/symbol.cpp b/src/symbol.cpp index 9f5e11d..eff9a03 100644 --- a/src/symbol.cpp +++ b/src/symbol.cpp @@ -5,7 +5,7 @@ #include <pdb/all.hpp> -#include <boost/nowide/convert.hpp> +#include <winapi/utf8.hpp> #include <dbghelp.h> #include <windows.h> @@ -54,11 +54,10 @@ SymbolInfo::SymbolInfo(const Impl& impl) : SymbolInfo{} { std::string SymbolInfo::get_name() const { // SymFromAddrW, contrary to SymFromAddrA, seems to include the terminating // null character in NameLen. - return boost::nowide::narrow(get_impl().Name); + return winapi::narrow(get_impl().Name); } LineInfo::LineInfo(const Impl& impl) - : file_path{boost::nowide::narrow(impl.FileName)}, - line_number{cast_line_number(impl.LineNumber)} {} + : file_path{winapi::narrow(impl.FileName)}, line_number{cast_line_number(impl.LineNumber)} {} } // namespace pdb diff --git a/src/utils/file.cpp b/src/utils/file.cpp index 3f37cfc..9584de3 100644 --- a/src/utils/file.cpp +++ b/src/utils/file.cpp @@ -5,7 +5,7 @@ #include <pdb/all.hpp> -#include <boost/nowide/convert.hpp> +#include <winapi/utf8.hpp> #include <windows.h> @@ -18,7 +18,7 @@ namespace pdb { namespace file { std::size_t get_size(const std::string& path) { - const Handle handle{CreateFileW(boost::nowide::widen(path).c_str(), + const Handle handle{CreateFileW(winapi::widen(path).c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, @@ -40,7 +40,7 @@ std::size_t get_size(const std::string& path) { } ID query_id(const std::string& path) { - const Handle handle{CreateFileW(boost::nowide::widen(path).c_str(), + const Handle handle{CreateFileW(winapi::widen(path).c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3b415a8..86f7d1a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,5 @@ add_library(test_lib SHARED test_lib.cpp) target_link_libraries(test_lib PRIVATE pdb_repo) -target_link_libraries(test_lib PRIVATE Boost::nowide) target_include_directories(test_lib PUBLIC .) target_compile_definitions(test_lib PRIVATE TEST_LIB_EXPORTS) install(TARGETS test_lib RUNTIME DESTINATION bin/test) @@ -8,7 +7,6 @@ install_pdbs(TARGETS test_lib DESTINATION bin/test) add_executable(call_stack call_stack.cpp) target_link_libraries(call_stack PRIVATE test_lib) -target_link_libraries(call_stack PRIVATE Boost::nowide) install(TARGETS call_stack RUNTIME DESTINATION bin/test) install_pdbs(TARGETS call_stack DESTINATION bin/test) diff --git a/test/call_stack.cpp b/test/call_stack.cpp index b094aac..fb5f7b8 100644 --- a/test/call_stack.cpp +++ b/test/call_stack.cpp @@ -5,15 +5,14 @@ #include <test_lib.hpp> -#include <boost/nowide/iostream.hpp> - #include <exception> +#include <iostream> int main() { try { test_ns::print_call_stack(); } catch (const std::exception& e) { - boost::nowide::cerr << e.what() << '\n'; + std::cerr << e.what() << '\n'; return 1; } return 0; diff --git a/test/test_lib.cpp b/test/test_lib.cpp index ee02ffb..0c4bd27 100644 --- a/test/test_lib.cpp +++ b/test/test_lib.cpp @@ -7,7 +7,7 @@ #include <pdb/all.hpp> -#include <boost/nowide/iostream.hpp> +#include <iostream> // Prevent frame pointer omission (FPO) and/or inlining. #ifdef _MSC_VER @@ -20,7 +20,7 @@ namespace { void do_print_call_stack() { const auto dbghelp = pdb::DbgHelp::current_process(); const auto call_stack = pdb::CallStack::capture(); - call_stack.dump(boost::nowide::cout, dbghelp); + call_stack.dump(std::cout, dbghelp); } void do_throw_call_stack() { @@ -32,17 +32,17 @@ void do_throw_call_stack() { volatile int var = 42; void baz(F f) { - boost::nowide::cout << "baz " << pdb::format_address(reinterpret_cast<void*>(&baz)) << '\n'; + std::cout << "baz " << pdb::format_address(reinterpret_cast<void*>(&baz)) << '\n'; f(); } void bar(F f) { - boost::nowide::cout << "bar " << pdb::format_address(reinterpret_cast<void*>(&bar)) << '\n'; + std::cout << "bar " << pdb::format_address(reinterpret_cast<void*>(&bar)) << '\n'; baz(f); } void foo(F f) { - boost::nowide::cout << "foo " << pdb::format_address(reinterpret_cast<void*>(&foo)) << '\n'; + std::cout << "foo " << pdb::format_address(reinterpret_cast<void*>(&foo)) << '\n'; bar(f); } diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt index bfeab62..309333d 100644 --- a/test/unit_tests/CMakeLists.txt +++ b/test/unit_tests/CMakeLists.txt @@ -5,7 +5,6 @@ target_link_libraries(unit_tests PRIVATE pdb_repo test_lib) target_link_libraries(unit_tests PRIVATE Boost::disable_autolinking Boost::filesystem - Boost::nowide Boost::unit_test_framework) install(TARGETS unit_tests RUNTIME DESTINATION bin/test) install_pdbs(TARGETS unit_tests DESTINATION bin/test) diff --git a/test/unit_tests/paths.hpp b/test/unit_tests/paths.hpp index 3eb2fd6..afc15ec 100644 --- a/test/unit_tests/paths.hpp +++ b/test/unit_tests/paths.hpp @@ -6,22 +6,15 @@ #pragma once #include <boost/filesystem.hpp> -#include <boost/nowide/filesystem.hpp> #include <boost/test/unit_test.hpp> using path = boost::filesystem::path; -class FixFilesystem { -public: - FixFilesystem() { boost::nowide::nowide_filesystem(); } -}; - class Paths { public: typedef boost::filesystem::path path; static Paths& get() { - static FixFilesystem fix_filesystem; static Paths instance; return instance; } diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 6a345c9..70b3c82 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::disable_autolinking Boost::filesystem Boost::nowide Boost::program_options) + target_link_libraries("${name}" PRIVATE Boost::disable_autolinking Boost::filesystem Boost::program_options) install(TARGETS "${name}" RUNTIME DESTINATION bin) install_pdbs(TARGETS "${name}" DESTINATION bin) endfunction() diff --git a/utils/addr2name.cpp b/utils/addr2name.cpp index 710a2ff..acb992c 100644 --- a/utils/addr2name.cpp +++ b/utils/addr2name.cpp @@ -7,7 +7,6 @@ #include "pdb/all.hpp" #include "pdb_descr.hpp" -#include <boost/nowide/iostream.hpp> #include <boost/program_options.hpp> #include <exception> @@ -58,7 +57,7 @@ std::string format_line_info(const pdb::LineInfo& line_info) { } void dump_error(const std::exception& e) { - boost::nowide::cerr << "error: " << e.what() << '\n'; + std::cerr << "error: " << e.what() << '\n'; } void resolve_symbol(const pdb::Repo& repo, pdb::Address address, bool lines = false) { @@ -78,10 +77,10 @@ void resolve_symbol(const pdb::Repo& repo, pdb::Address address, bool lines = fa } } - boost::nowide::cout << msg.str() << '\n'; + std::cout << msg.str() << '\n'; } catch (const std::exception& e) { dump_error(e); - boost::nowide::cout << pdb::format_address(address) << '\n'; + std::cout << pdb::format_address(address) << '\n'; } } diff --git a/utils/command_line.hpp b/utils/command_line.hpp index 9fe6b98..d1f6e2e 100644 --- a/utils/command_line.hpp +++ b/utils/command_line.hpp @@ -6,9 +6,6 @@ #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> @@ -16,23 +13,9 @@ #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(int argc, char** argv) - : args{argc, argv}, prog_name{extract_filename(args.argv[0])} { + explicit SettingsParser(int, char** argv) : prog_name{extract_filename(argv[0])} { visible.add_options()("help,h", "show this message and exit"); } @@ -57,11 +40,11 @@ public: bool exit_with_usage = false; - void usage() const { boost::nowide::cout << *this; } + void usage() const { std::cout << *this; } void usage_error(const std::exception& e) const { - boost::nowide::cerr << "usage error: " << e.what() << '\n'; - boost::nowide::cerr << *this; + std::cerr << "usage error: " << e.what() << '\n'; + std::cerr << *this; } protected: @@ -74,7 +57,6 @@ private: 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 49dbfed..626816e 100644 --- a/utils/enum_symbols.cpp +++ b/utils/enum_symbols.cpp @@ -6,7 +6,6 @@ #include "command_line.hpp" #include "pdb/all.hpp" -#include <boost/nowide/iostream.hpp> #include <boost/program_options.hpp> #include <exception> @@ -80,11 +79,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()) - boost::nowide::cout << symbol.get_name() << '\n'; + std::cout << symbol.get_name() << '\n'; }); } } catch (const std::exception& e) { - boost::nowide::cerr << "error: " << e.what() << '\n'; + std::cerr << "error: " << e.what() << '\n'; return 1; } return 0; diff --git a/utils/name2addr.cpp b/utils/name2addr.cpp index 4b83757..d0c4293 100644 --- a/utils/name2addr.cpp +++ b/utils/name2addr.cpp @@ -7,7 +7,6 @@ #include "pdb/all.hpp" #include "pdb_descr.hpp" -#include <boost/nowide/iostream.hpp> #include <boost/program_options.hpp> #include <exception> @@ -39,16 +38,16 @@ public: }; void dump_error(const std::exception& e) { - boost::nowide::cerr << "error: " << e.what() << '\n'; + std::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(); - boost::nowide::cout << pdb::format_address(address) << '\n'; + std::cout << pdb::format_address(address) << '\n'; } catch (const std::exception& e) { dump_error(e); - boost::nowide::cout << name << '\n'; + std::cout << name << '\n'; } } |