aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/call_stack.cpp29
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