From 5dc92e796291992dd81567cf5cb58624f58d0e43 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 21 Mar 2020 20:18:19 +0300 Subject: CallStack: overhaul the API --- src/call_stack.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/call_stack.cpp b/src/call_stack.cpp index 4edba46..d9e0637 100644 --- a/src/call_stack.cpp +++ b/src/call_stack.cpp @@ -11,13 +11,14 @@ #include #include +#include +#include #include #include #include #include namespace pdb { -namespace call_stack { namespace { template @@ -80,12 +81,6 @@ std::string resolve_and_format(const DbgHelp& dbghelp, Address addr) { } // namespace -std::string pretty_print_address(const DbgHelp& dbghelp, Address addr) { - return resolve_and_format(dbghelp, addr); -} - -} // namespace call_stack - CallStack CallStack::capture() { std::array frames_impl{nullptr}; const auto length = @@ -98,4 +93,24 @@ CallStack CallStack::capture() { return {frames, length}; } +bool CallStack::for_each_address(const AddressCallback& callback) const { + for (std::size_t i = 0; i < length; ++i) { + if (!callback(frames[i])) { + return false; + } + } + return true; +} + +std::string CallStack::pretty_print_address(const DbgHelp& dbghelp, Address addr) { + return resolve_and_format(dbghelp, addr); +} + +void CallStack::dump(std::ostream& os, const DbgHelp& dbghelp) const { + for_each_address([&](Address addr) { + os << format_address(addr) << ' ' << pretty_print_address(dbghelp, addr) << '\n'; + return true; + }); +} + } // namespace pdb -- cgit v1.2.3