summaryrefslogtreecommitdiffstatshomepage
path: root/include/winapi/debug/call_stack.hpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-05-29 01:03:28 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-05-29 01:03:28 +0300
commita38dacc6489ff3c7a0748a01ed7cc2bd0cdaaa7c (patch)
treede48e7d8b3f9d66c9e11dd048ac9062921b05801 /include/winapi/debug/call_stack.hpp
parentadd .clang-tidy, `make check` (diff)
downloadwinapi-debug-a38dacc6489ff3c7a0748a01ed7cc2bd0cdaaa7c.tar.gz
winapi-debug-a38dacc6489ff3c7a0748a01ed7cc2bd0cdaaa7c.zip
include/pdb/ -> include/winapi/debug/
Diffstat (limited to 'include/winapi/debug/call_stack.hpp')
-rw-r--r--include/winapi/debug/call_stack.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/include/winapi/debug/call_stack.hpp b/include/winapi/debug/call_stack.hpp
new file mode 100644
index 0000000..30f642c
--- /dev/null
+++ b/include/winapi/debug/call_stack.hpp
@@ -0,0 +1,53 @@
+// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
+// This file is part of the "winapi-debug" project.
+// For details, see https://github.com/egor-tensin/winapi-debug.
+// Distributed under the MIT License.
+
+#pragma once
+
+#include "address.hpp"
+#include "dbghelp.hpp"
+
+#include <windows.h>
+
+#include <array>
+#include <cstddef>
+#include <functional>
+#include <ostream>
+#include <string>
+
+namespace pdb {
+
+class CallStack {
+public:
+ static constexpr std::size_t frames_to_skip = 0;
+ static constexpr std::size_t frames_to_capture = 62;
+
+ // Imposed by CaptureStackBackTrace:
+ static constexpr std::size_t max_length = 62;
+
+ static_assert(frames_to_skip + frames_to_capture <= max_length,
+ "Call stack length is too large");
+
+ static CallStack capture();
+
+ using AddressCallback = std::function<bool(Address)>;
+ bool for_each_address(const AddressCallback& callback) const;
+
+ static std::string pretty_print_address(const DbgHelp& dbghelp, Address addr);
+
+ void dump(std::ostream& os, const DbgHelp&) const;
+
+ const std::array<Address, max_length> frames;
+ const std::size_t length;
+
+ const Address* begin() const { return frames.data(); }
+ const Address* cbegin() const { return begin(); }
+ const Address* end() const { return begin() + length; }
+ const Address* cend() const { return end(); }
+
+private:
+ CallStack() = default;
+};
+
+} // namespace pdb