aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/CMakeLists.txt11
-rw-r--r--test/call_stack.cpp41
2 files changed, 51 insertions, 1 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 619a51e..656caa9 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,4 +1,13 @@
-set(CC_STATIC_RUNTIME OFF)
+add_executable(call_stack call_stack.cpp)
+target_link_libraries(call_stack PRIVATE pdb_repo)
+
+install(TARGETS call_stack RUNTIME DESTINATION bin)
+if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
+ install(FILES "$<TARGET_PDB_FILE:call_stack>" DESTINATION bin OPTIONAL)
+endif()
+
+set(CC_STATIC_RUNTIME OFF) # Reduce the number of symbols in this test utility
+
add_executable(foobar foobar.cpp)
install(TARGETS foobar RUNTIME DESTINATION bin)
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;
+}