aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/call_stack.cpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-01-15 19:20:50 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-01-16 01:21:32 +0300
commit3dc0b9a3ae90dcac2f1150e6b2dfb0a5a310355b (patch)
treefca7da94fdc0f4693a8b49b765738b9e842a1407 /test/call_stack.cpp
parentlab_rat -> foobar (diff)
downloadwinapi-debug-3dc0b9a3ae90dcac2f1150e6b2dfb0a5a310355b.tar.gz
winapi-debug-3dc0b9a3ae90dcac2f1150e6b2dfb0a5a310355b.zip
add call stack collection support
Diffstat (limited to 'test/call_stack.cpp')
-rw-r--r--test/call_stack.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/call_stack.cpp b/test/call_stack.cpp
new file mode 100644
index 0000000..c1fb0fd
--- /dev/null
+++ b/test/call_stack.cpp
@@ -0,0 +1,41 @@
+#include "pdb/all.hpp"
+
+#include <exception>
+#include <iostream>
+
+namespace test {
+
+void call_stack() {
+ pdb::DbgHelp dbghelp{true};
+ const auto call_stack = pdb::CallStack::capture();
+ for (std::size_t i = 0; i < call_stack.length; ++i)
+ std::cout << pdb::format_address(call_stack.frames[i]) << ' '
+ << pdb::call_stack::pretty_print_address(dbghelp, call_stack.frames[i]) << '\n';
+}
+
+void __declspec(noinline) baz() {
+ std::cout << "baz\n";
+ call_stack();
+}
+
+void __declspec(noinline) bar() {
+ std::cout << "bar\n";
+ baz();
+}
+
+void __declspec(noinline) foo() {
+ std::cout << "foo\n";
+ bar();
+}
+
+} // namespace test
+
+int main() {
+ try {
+ test::foo();
+ } catch (const std::exception& e) {
+ std::cerr << e.what() << '\n';
+ return 1;
+ }
+ return 0;
+}