diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-13 19:26:04 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-13 19:26:04 +0200 |
| commit | 9991c3526cd0d4a773e17064327fd41fd091129d (patch) | |
| tree | 36567562f8be540fb1bfbf8fb8d102a72a5eccf2 | |
| parent | upgrade winapi-common (diff) | |
| download | winapi-debug-9991c3526cd0d4a773e17064327fd41fd091129d.tar.gz winapi-debug-9991c3526cd0d4a773e17064327fd41fd091129d.zip | |
finally, perfect .clang-format settings?
| -rw-r--r-- | .clang-format | 3 | ||||
| -rw-r--r-- | include/winapi/debug/call_stack.hpp | 6 | ||||
| -rw-r--r-- | include/winapi/debug/symbol.hpp | 6 | ||||
| -rw-r--r-- | src/dbghelp.cpp | 33 | ||||
| -rw-r--r-- | src/module.cpp | 20 | ||||
| -rw-r--r-- | src/post_mortem.cpp | 27 | ||||
| -rw-r--r-- | src/utils/addr2name.cpp | 17 | ||||
| -rw-r--r-- | src/utils/command_line.hpp | 12 | ||||
| -rw-r--r-- | src/utils/enum_symbols.cpp | 12 | ||||
| -rw-r--r-- | src/utils/name2addr.cpp | 11 | ||||
| -rw-r--r-- | src/utils/pdb_descr.hpp | 20 | ||||
| -rw-r--r-- | test/unit_tests/call_stack.cpp | 17 | ||||
| -rw-r--r-- | test/unit_tests/fixtures.hpp | 13 |
13 files changed, 123 insertions, 74 deletions
diff --git a/.clang-format b/.clang-format index d75ff99..dfbae98 100644 --- a/.clang-format +++ b/.clang-format @@ -5,14 +5,17 @@ BasedOnStyle: Chromium IndentWidth: 4 AccessModifierOffset: -4 +AlignAfterOpenBracket: BlockIndent AlignConsecutiveMacros: AcrossComments AllowShortFunctionsOnASingleLine: Empty BinPackArguments: false +BinPackParameters: OnePerLine BreakConstructorInitializers: BeforeComma BreakInheritanceList: BeforeComma BreakStringLiterals: false ColumnLimit: 100 IncludeBlocks: Regroup +PenaltyReturnTypeOnItsOwnLine: 1000 SpacesBeforeTrailingComments: 1 WrapNamespaceBodyWithEmptyLines: Always diff --git a/include/winapi/debug/call_stack.hpp b/include/winapi/debug/call_stack.hpp index caa9226..1f53ded 100644 --- a/include/winapi/debug/call_stack.hpp +++ b/include/winapi/debug/call_stack.hpp @@ -26,8 +26,10 @@ public: // Imposed by CaptureStackBackTrace: static constexpr std::size_t max_length = 62; - static_assert(frames_to_skip + frames_to_capture <= max_length, - "Call stack length is too large"); + static_assert( + frames_to_skip + frames_to_capture <= max_length, + "Call stack length is too large" + ); static CallStack capture(); diff --git a/include/winapi/debug/symbol.hpp b/include/winapi/debug/symbol.hpp index cefb6c2..0320765 100644 --- a/include/winapi/debug/symbol.hpp +++ b/include/winapi/debug/symbol.hpp @@ -26,8 +26,10 @@ using Tag = ULONG; constexpr Tag SYM_TAG_FUNCTION = 5; #ifdef _MSC_VER -static_assert(static_cast<Tag>(SymTagFunction) == SYM_TAG_FUNCTION, - "unexpected SymTagFunction value"); +static_assert( + static_cast<Tag>(SymTagFunction) == SYM_TAG_FUNCTION, + "unexpected SymTagFunction value" +); #endif } // namespace symbol diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp index 20f23c3..77509af 100644 --- a/src/dbghelp.cpp +++ b/src/dbghelp.cpp @@ -45,7 +45,8 @@ Address gen_next_offline_base(std::size_t pdb_size) { const auto max_addr = std::numeric_limits<decltype(next_offline_base)>::max(); if (max_addr - next_offline_base < pdb_size) throw std::runtime_error{ - "no more PDB files can be added, the internal address space is exhausted"}; + "no more PDB files can be added, the internal address space is exhausted" + }; next_offline_base += pdb_size; return base; @@ -79,15 +80,19 @@ BOOL CALLBACK enum_symbols_callback(SYMBOL_INFOW* info, ULONG, VOID* raw_callbac return TRUE; } -void enum_symbols(HANDLE id, - Address module_base, - std::string_view mask, - const DbgHelp::OnSymbol& callback) { - if (!SymEnumSymbolsW(id, - module_base, - winapi::widen(mask).c_str(), - &enum_symbols_callback, - const_cast<DbgHelp::OnSymbol*>(&callback))) +void enum_symbols( + HANDLE id, + Address module_base, + std::string_view mask, + const DbgHelp::OnSymbol& callback +) { + if (!SymEnumSymbolsW( + id, + module_base, + winapi::widen(mask).c_str(), + &enum_symbols_callback, + const_cast<DbgHelp::OnSymbol*>(&callback) + )) throw winapi::error::windows(GetLastError(), "SymEnumSymbolsW"); } @@ -159,9 +164,11 @@ ModuleInfo DbgHelp::resolve_module(Address offline) const { return get_module_info(id, offline); } -void DbgHelp::enum_symbols(const ModuleInfo& module, - std::string_view mask, - const OnSymbol& callback) const { +void DbgHelp::enum_symbols( + const ModuleInfo& module, + std::string_view mask, + const OnSymbol& callback +) const { winapi::enum_symbols(id, module.get_offline_base(), mask, callback); } diff --git a/src/module.cpp b/src/module.cpp index ae4a95f..ca76cf5 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -59,17 +59,21 @@ Address Module::translate_online_address(Address online) const { } std::string Module::invalid_offline_address(Address offline) const { - return std::format("offline address {} doesn't belong to module {} (base offline address {})", - address::format(offline), - get_name(), - address::format(get_offline_base())); + 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 { - return std::format("online address {} doesn't belong to module {} (base online address {})", - address::format(online), - get_name(), - address::format(get_online_base())); + 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 84da809..e7a1e8e 100644 --- a/src/post_mortem.cpp +++ b/src/post_mortem.cpp @@ -16,9 +16,11 @@ namespace winapi { namespace { 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); + return std::format( + "module with online base address {} has already been loaded: {}", + address::format(online_base), + path + ); } std::string pdb_already_loaded(std::string_view path) { @@ -28,7 +30,8 @@ std::string pdb_already_loaded(std::string_view path) { std::string offline_base_already_used(Address base) { return std::format( "module with offline base address {} has already been loaded (shouldn't happen)", - address::format(base)); + address::format(base) + ); } std::string module_not_found(Address base) { @@ -36,13 +39,16 @@ std::string module_not_found(Address base) { } std::string guess_module_no_modules(Address pivot) { - return std::format("couldn't select a module for address {}: no modules have been loaded yet", - address::format(pivot)); + 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) { - return std::format("couldn't select a module for address {}: it's too low", - address::format(pivot)); + return std::format( + "couldn't select a module for address {}: it's too low", address::format(pivot) + ); } template <typename Value> @@ -111,8 +117,9 @@ void PostMortem::enum_symbols(Address offline_base, const OnSymbol& callback) co } void PostMortem::enum_symbols(const Module& module, const OnSymbol& callback) const { - dbghelp.enum_symbols( - module, [&](const SymbolInfo& impl) { callback(symbol_from_buffer(module, impl)); }); + dbghelp.enum_symbols(module, [&](const SymbolInfo& impl) { + callback(symbol_from_buffer(module, impl)); + }); } Symbol PostMortem::resolve_symbol(Address online) const { diff --git a/src/utils/addr2name.cpp b/src/utils/addr2name.cpp index 98b53b9..28cc464 100644 --- a/src/utils/addr2name.cpp +++ b/src/utils/addr2name.cpp @@ -25,13 +25,16 @@ public: namespace po = boost::program_options; visible.add_options()( - "pdb", po::value<std::vector<PDB>>(&pdbs)->value_name("ADDR,PATH"), "load a PDB file"); + "pdb", po::value<std::vector<PDB>>(&pdbs)->value_name("ADDR,PATH"), "load a PDB file" + ); visible.add_options()( - "lines,l", po::bool_switch(&lines), "try to resolve source files & line numbers"); + "lines,l", po::bool_switch(&lines), "try to resolve source files & line numbers" + ); hidden.add_options()( "address", po::value<std::vector<winapi::Address>>(&addresses)->value_name("ADDR"), - "add an address to resolve"); + "add an address to resolve" + ); positional.add("address", -1); } @@ -60,9 +63,11 @@ void dump_error(const std::exception& e) { std::cerr << std::format("error: {}\n", e.what()); } -void resolve_symbol(const winapi::PostMortem& analysis, - winapi::Address address, - bool lines = false) { +void resolve_symbol( + const winapi::PostMortem& analysis, + winapi::Address address, + bool lines = false +) { try { const auto symbol = analysis.resolve_symbol(address); const auto& module = analysis.module_with_offline_base(symbol.get_offline_base()); diff --git a/src/utils/command_line.hpp b/src/utils/command_line.hpp index d3178f1..434e6e8 100644 --- a/src/utils/command_line.hpp +++ b/src/utils/command_line.hpp @@ -30,11 +30,13 @@ public: boost::program_options::options_description all; all.add(hidden).add(visible); boost::program_options::variables_map vm; - boost::program_options::store(boost::program_options::command_line_parser{argc, argv} - .options(all) - .positional(positional) - .run(), - vm); + boost::program_options::store( + boost::program_options::command_line_parser{argc, argv} + .options(all) + .positional(positional) + .run(), + vm + ); if (vm.count("help")) exit_with_usage = true; else diff --git a/src/utils/enum_symbols.cpp b/src/utils/enum_symbols.cpp index 645bc13..9ce11e6 100644 --- a/src/utils/enum_symbols.cpp +++ b/src/utils/enum_symbols.cpp @@ -21,15 +21,17 @@ public: explicit EnumSymbols(int argc, char** argv) : SettingsParser{argc, argv} { namespace po = boost::program_options; - visible.add_options()("pdb", - po::value<std::vector<std::string>>(&pdbs)->value_name("PATH"), - "load a PDB file"); + visible.add_options()( + "pdb", po::value<std::vector<std::string>>(&pdbs)->value_name("PATH"), "load a PDB file" + ); visible.add_options()( "functions", po::value<winapi::symbol::Tag>(&tag)->implicit_value(function_tag)->zero_tokens(), - "only list functions"); + "only list functions" + ); visible.add_options()( - "mask", po::value<std::string>(&symbol_mask)->value_name("MASK"), "symbol mask"); + "mask", po::value<std::string>(&symbol_mask)->value_name("MASK"), "symbol mask" + ); } const char* get_short_description() const override { diff --git a/src/utils/name2addr.cpp b/src/utils/name2addr.cpp index d253aa9..2988c26 100644 --- a/src/utils/name2addr.cpp +++ b/src/utils/name2addr.cpp @@ -24,10 +24,13 @@ public: namespace po = boost::program_options; visible.add_options()( - "pdb", po::value<std::vector<PDB>>(&pdbs)->value_name("ADDR,PATH"), "load a PDB file"); - hidden.add_options()("name", - po::value<std::vector<std::string>>(&names)->value_name("NAME"), - "add a name to resolve"); + "pdb", po::value<std::vector<PDB>>(&pdbs)->value_name("ADDR,PATH"), "load a PDB file" + ); + hidden.add_options()( + "name", + po::value<std::vector<std::string>>(&names)->value_name("NAME"), + "add a name to resolve" + ); positional.add("name", -1); } diff --git a/src/utils/pdb_descr.hpp b/src/utils/pdb_descr.hpp index c2e720a..586f73a 100644 --- a/src/utils/pdb_descr.hpp +++ b/src/utils/pdb_descr.hpp @@ -39,10 +39,12 @@ struct PDB { }; template <typename charT> -void validate(boost::any& dest, - const std::vector<std::basic_string<charT>>& src_tokens, - PDB*, - int) { +void validate( + boost::any& dest, + const std::vector<std::basic_string<charT>>& src_tokens, + PDB*, + int +) { namespace po = boost::program_options; po::validators::check_first_occurrence(dest); const auto& src_token = po::validators::get_single_string(src_tokens); @@ -50,10 +52,12 @@ void validate(boost::any& dest, } template <typename charT> -void validate(boost::any& dest, - const std::vector<std::basic_string<charT>>& src_tokens, - winapi::Address*, - int) { +void validate( + boost::any& dest, + const std::vector<std::basic_string<charT>>& src_tokens, + winapi::Address*, + int +) { namespace po = boost::program_options; po::validators::check_first_occurrence(dest); const auto& src_token = po::validators::get_single_string(src_tokens); diff --git a/test/unit_tests/call_stack.cpp b/test/unit_tests/call_stack.cpp index 84cfc2a..05557bd 100644 --- a/test/unit_tests/call_stack.cpp +++ b/test/unit_tests/call_stack.cpp @@ -43,13 +43,17 @@ BOOST_AUTO_TEST_CASE(call_stack) { for (const auto& addr : call_stack) { try { auto symbol = dbghelp.resolve_symbol(addr); - BOOST_TEST_MESSAGE('\t' << winapi::address::format(symbol.get_offline_address()) - << ' ' << symbol.get_name()); + 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(std::nullopt); - BOOST_TEST_MESSAGE('\t' << winapi::address::format(addr) - << " Couldn't resolve symbol: " << e.what()); + BOOST_TEST_MESSAGE( + '\t' << winapi::address::format(addr) + << " Couldn't resolve symbol: " << e.what() + ); } } @@ -64,8 +68,9 @@ BOOST_AUTO_TEST_CASE(call_stack) { return false; }; for (const auto& addr : expected) { - BOOST_TEST(check(addr), - "Function frame captured: " << winapi::address::format(addr)); + BOOST_TEST( + check(addr), "Function frame captured: " << winapi::address::format(addr) + ); } } diff --git a/test/unit_tests/fixtures.hpp b/test/unit_tests/fixtures.hpp index 8233f95..0c24b37 100644 --- a/test/unit_tests/fixtures.hpp +++ b/test/unit_tests/fixtures.hpp @@ -51,9 +51,11 @@ public: using AddressList = Set<winapi::Address>; static AddressList expected_function_addresses() { - return cast({reinterpret_cast<void*>(&test_ns::foo), - reinterpret_cast<void*>(&test_ns::bar), - reinterpret_cast<void*>(&test_ns::baz)}); + return cast( + {reinterpret_cast<void*>(&test_ns::foo), + reinterpret_cast<void*>(&test_ns::bar), + reinterpret_cast<void*>(&test_ns::baz)} + ); } static SymbolList expected_functions() { @@ -128,8 +130,9 @@ private: // That's pretty ad-hoc, but seems to work; based on // https://www.boost.org/doc/libs/1_70_0/libs/test/doc/html/boost_test/runtime_config/custom_command_line_arguments.html BOOST_TEST_REQUIRE(boost::unit_test::framework::master_test_suite().argc == 3); - BOOST_TEST_REQUIRE(boost::unit_test::framework::master_test_suite().argv[1] == - "--test_lib_pdb"); + BOOST_TEST_REQUIRE( + boost::unit_test::framework::master_test_suite().argv[1] == "--test_lib_pdb" + ); return boost::unit_test::framework::master_test_suite().argv[2]; } }; |
