From 965d285ed2dd71331107e82b1b919ce292cb841a Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 14 Sep 2020 16:10:41 +0300 Subject: unit_tests: fix the tests Sometimes, 0x0 would creep into a call stack for some reason. --- test/unit_tests/call_stack.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/unit_tests/call_stack.cpp b/test/unit_tests/call_stack.cpp index 481ab6e..cc5b74e 100644 --- a/test/unit_tests/call_stack.cpp +++ b/test/unit_tests/call_stack.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -30,15 +31,21 @@ BOOST_AUTO_TEST_CASE(call_stack) { } // Second, resolve the symbols: - std::vector symbols; + std::vector> symbols; symbols.reserve(call_stack.length); BOOST_TEST_MESSAGE("Resolved symbols:"); for (const auto& addr : call_stack) { - symbols.emplace_back(dbghelp.resolve_symbol(addr)); - const auto& symbol = symbols.back(); - BOOST_TEST_MESSAGE('\t' << pdb::format_address(symbol.get_offline_address()) << ' ' - << symbol.get_name()); + try { + auto symbol = dbghelp.resolve_symbol(addr); + BOOST_TEST_MESSAGE('\t' << pdb::format_address(symbol.get_offline_address()) << ' ' + << symbol.get_name()); + symbols.emplace_back(std::move(symbol)); + } catch (const std::system_error& e) { + symbols.emplace_back(boost::none); + BOOST_TEST_MESSAGE('\t' << pdb::format_address(addr) + << " Couldn't resolve symbol: " << e.what()); + } } { @@ -47,7 +54,7 @@ BOOST_AUTO_TEST_CASE(call_stack) { const auto check = [&](pdb::Address addr) { for (const auto& symbol : symbols) - if (symbol.get_offline_address() == addr) + if (symbol && symbol->get_offline_address() == addr) return true; return false; }; -- cgit v1.2.3