From 3dc0b9a3ae90dcac2f1150e6b2dfb0a5a310355b Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 15 Jan 2020 19:20:50 +0300 Subject: add call stack collection support --- include/pdb/all.hpp | 1 + include/pdb/call_stack.hpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/pdb/dbghelp.hpp | 4 +++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 include/pdb/call_stack.hpp (limited to 'include/pdb') diff --git a/include/pdb/all.hpp b/include/pdb/all.hpp index 84be09e..36a68d3 100644 --- a/include/pdb/all.hpp +++ b/include/pdb/all.hpp @@ -6,6 +6,7 @@ #pragma once #include "address.hpp" +#include "call_stack.hpp" #include "dbghelp.hpp" #include "error.hpp" #include "handle.hpp" diff --git a/include/pdb/call_stack.hpp b/include/pdb/call_stack.hpp new file mode 100644 index 0000000..7f0c8b0 --- /dev/null +++ b/include/pdb/call_stack.hpp @@ -0,0 +1,46 @@ +// Copyright (c) 2020 Egor Tensin +// This file is part of the "PDB repository" project. +// For details, see https://github.com/egor-tensin/pdb-repo. +// Distributed under the MIT License. + +#pragma once + +#include "address.hpp" +#include "dbghelp.hpp" + +#include + +#include + +#include +#include +#include + +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(); + + const std::array frames; + const std::size_t length; + +private: + CallStack() = default; +}; + +namespace call_stack { + +std::string pretty_print_address(const DbgHelp& dbghelp, Address addr); + +} // namespace call_stack +} // namespace pdb diff --git a/include/pdb/dbghelp.hpp b/include/pdb/dbghelp.hpp index 2809eac..db9638e 100644 --- a/include/pdb/dbghelp.hpp +++ b/include/pdb/dbghelp.hpp @@ -18,7 +18,7 @@ namespace pdb { class DbgHelp { public: - DbgHelp(); + DbgHelp(bool invade_current_process = false); ~DbgHelp(); void close(); @@ -28,6 +28,8 @@ public: typedef std::function OnModule; void enum_modules(const OnModule&) const; + ModuleInfo resolve_module(Address) const; + typedef std::function OnSymbol; static constexpr auto all_symbols = "*!*"; void enum_symbols(const ModuleInfo&, const std::string& mask, const OnSymbol&) const; -- cgit v1.2.3