PStack  2.0
Stack trace printer for MSVC and GCC binaries
thread_info.hpp
Go to the documentation of this file.
1 // ===-- include/psystem/thread_info.hpp ------------------ -*- C++ -*- --=== //
2 // Copyright (c) 2014 Matt Bisson. All rights reserved.
3 
18 #pragma once
19 #ifndef PSYSTEM_THREAD_INFO_HPP
20 #define PSYSTEM_THREAD_INFO_HPP
21 
22 #include "psystem_ns.hpp"
23 #include "stack_frame.hpp"
24 
25 #include <mutex>
26 #include <vector>
27 
30 
31 namespace psystem {
32 
33 class dbghelp_symbol_engine;
34 class process_info;
35 
53 {
57 public:
66  typedef void* (__stdcall *address_to_symbol_func)(HANDLE, DWORD64);
67 
76  typedef DWORD64(__stdcall *get_module_base_func)(HANDLE, DWORD64);
77 
85  using stack_trace = std::vector<stack_frame>;
86 
90 public:
101  thread_info(
102  process_id_t pid,
103  thread_id_t tid,
104  CREATE_PROCESS_DEBUG_INFO const& info) noexcept;
105 
116  thread_info(
117  process_id_t pid,
118  thread_id_t tid,
119  CREATE_THREAD_DEBUG_INFO const& info) noexcept;
120 
124 public:
130 
139  HANDLE get_thread_handle() const noexcept;
140 
145  thread_id_t get_thread_id() const noexcept;
146 
150 public:
185  process_info const& proc,
186  address_to_symbol_func address_to_symbol,
187  get_module_base_func get_module_base) const;
188 
192 private:
220  static void generate_stack_trace(
221  HANDLE process_handle,
222  HANDLE thread_handle,
223  address_to_symbol_func address_to_symbol,
224  get_module_base_func get_module_base,
225  std::unique_ptr<stack_trace> *out);
226 
230 private:
233 
236 
239 
245  std::unique_ptr<stack_trace> mutable m_stack_trace;
246 
254  std::once_flag mutable m_stack_trace_lock;
255 };
256 
257 } // namespace psystem
258 
259 #endif // PSYSTEM_THREAD_INFO_HPP
stack_trace const & get_stack_trace(process_info const &proc, address_to_symbol_func address_to_symbol, get_module_base_func get_module_base) const
Retrieve a list of the stack frames that are active in the current thread.
Definition: thread_info.cpp:133
Defines the psystem::not_assignable interface.
Definition: shared_handle.hpp:782
std::vector< stack_frame > stack_trace
The container for the entire stack trace.
Definition: thread_info.hpp:85
std::once_flag m_stack_trace_lock
Mutex for lazy generation of thread_info::m_stack_trace.
Definition: thread_info.hpp:254
A container for a single thread of execution in a process.
Definition: thread_info.hpp:51
#define noexcept
Replace keyword with something useful.
Definition: platform.hpp:71
thread_id_t get_thread_id() const noexcept
Access the ID of this thread.
Definition: thread_info.cpp:117
process_id_t get_process_id() const noexcept
Access the ID of the process that owns this thread.
Definition: thread_info.cpp:111
Removes the ability to use an assignment operation on derived classes.
Definition: not_assignable.hpp:42
thread_info(process_id_t pid, thread_id_t tid, CREATE_PROCESS_DEBUG_INFO const &info) noexcept
Construct an instance of thread_info based on a process.
Definition: thread_info.cpp:86
void *(__stdcall * address_to_symbol_func)(HANDLE, DWORD64)
Function pointer to a function that maps addresses to symbol information.
Definition: thread_info.hpp:66
DWORD process_id_t
Data-type that stores a process ID (PID).
Definition: platform.hpp:241
A container object for a process's information.
Definition: process_info.hpp:50
static void generate_stack_trace(HANDLE process_handle, HANDLE thread_handle, address_to_symbol_func address_to_symbol, get_module_base_func get_module_base, std::unique_ptr< stack_trace > *out)
Generate a stack trace for this thread.
Definition: thread_info.cpp:164
DWORD64(__stdcall * get_module_base_func)(HANDLE, DWORD64)
Function pointer to a function that determines the module base address from any input address...
Definition: thread_info.hpp:76
The basic header file for the PSystem namespce.
Declare a container for a single frame in a stack trace.
Contains the process examination "system" and basic frameworks.
Definition: pstack_event_handler.hpp:28
HANDLE get_thread_handle() const noexcept
Retrieve the system handle to this thread.
Definition: thread_info.cpp:123
HANDLE m_thread_handle
The system debug API handle to this thread.
Definition: thread_info.hpp:232
process_id_t const m_process_id
The unique ID of the process that owns this thread.
Definition: thread_info.hpp:238
std::unique_ptr< stack_trace > m_stack_trace
A list of the stack frames executing in this thread.
Definition: thread_info.hpp:245
Information logging as well as error.
Wraps the C++ standard header, memory, to provide a uniform interface.
DWORD thread_id_t
Data-type that stores a thread ID (TID).
Definition: platform.hpp:247
thread_id_t const m_thread_id
An unique ID for a thread of execution in a process.
Definition: thread_info.hpp:235