diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-03-21 20:18:19 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-03-21 20:19:38 +0300 |
commit | 5dc92e796291992dd81567cf5cb58624f58d0e43 (patch) | |
tree | e67905a908486d1aa55fefc15df40b40f43346e6 /src | |
parent | test: foobar -> symbols (diff) | |
download | winapi-debug-5dc92e796291992dd81567cf5cb58624f58d0e43.tar.gz winapi-debug-5dc92e796291992dd81567cf5cb58624f58d0e43.zip |
CallStack: overhaul the API
Diffstat (limited to '')
-rw-r--r-- | src/call_stack.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
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 <algorithm> #include <array> +#include <cstddef> +#include <ostream> #include <sstream> #include <stdexcept> #include <string> #include <system_error> namespace pdb { -namespace call_stack { namespace { template <typename T> @@ -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<void*, max_length> 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 |