PStack  2.0
Stack trace printer for MSVC and GCC binaries
proclib::process_debugger Class Reference

Debugging facility for an individual process. More...

#include <process_debugger.hpp>

Inheritance diagram for proclib::process_debugger:
Collaboration diagram for proclib::process_debugger:

Classes

struct  dispatching_event_listener
 The implementation class for passing debugger events to registered listeners. More...
 

Type Definitions

using event_listener_id_t = int32_t
 An unique ID for events registered with add_event_listener()
 
static constexpr event_listener_id_t invalid_event_listener_id = -1
 Indicates that the value stored in a process_debugger::event_listener_id_t is not valid.
 

Construction / Destruction

 process_debugger (psystem::process_id_t pid)
 Create an instance of the debugger with a given process ID. More...
 
 ~process_debugger ()
 Detach the debugger from the process. More...
 

Public Accessors

base_debug_event_listenerget_events () const noexcept
 Access the main event handler for this process. More...
 
psystem::process_id_t get_process_id () const noexcept
 Get the ID of the process being debugged here. More...
 

Public Interface

event_listener_id_t add_event_listener (std::shared_ptr< base_debug_event_listener > const &l)
 Add a listener for debugger events sent to this process. More...
 
bool remove_event_listener (event_listener_id_t id)
 Remove an already registered event listener. More...
 
void set_kill_process_on_exit (bool kill_on_exit)
 Determine the fate of a process after the debugger detaches. More...
 

Member Data

psystem::process_id_t const m_process_id
 The Process ID (PID) of the process debugged by this instance.
 
std::unique_ptr< dispatching_event_listener > const m_events
 Debug events will be passed here, and forwarded to added custom versions of the listeners.
 

Additional Inherited Members

- Private Member Functions inherited from psystem::not_copyable
 not_copyable (not_copyable const &)=delete
 Delete the copy constructor.
 
not_copyableoperator= (not_copyable const &)=delete
 Delete the assignment operator.
 
constexpr not_copyable () noexcept
 A simple CTOR suitable for noexcept and constexpr uses.
 
 ~not_copyable () noexcept
 A simple CTOR suitable for noexcept uses.
 

Detailed Description

Debugging facility for an individual process.

This class ties the debugger to a specific debuggee process. The process_debugger responds to all debug events that pertain to its debuggee. Clients may receive (and deal with) these events using the add_event_listener() method with a custom base_debug_event_listener.

Author
Matt Bisson
Date
5 August, 2014
Since
ProcLib 2.0
Version
ProcLib 2.0
Todo:
This doesn't do much right now. Maybe it should automatically add the (currently) pstack::pstack_event_handler and provide access to process_info, etc?

Constructor & Destructor Documentation

proclib::process_debugger::process_debugger ( psystem::process_id_t  pid)
explicit

Create an instance of the debugger with a given process ID.

Parameters
[in]pidThe numerical ID of a process that is currently active to attach to the debugger.
Exceptions
psystem::exception::system_exceptionIf the debugger cannot attach to the specified running process (including if the process with the given ID does not exist).
proclib::process_debugger::~process_debugger ( )

Detach the debugger from the process.

Based on prior calls to set_kill_process_on_exit(), this method may allow the debugged process to continue normal execution, or it may terminate the process.

Note
If the debugger could not detach from the process that was previously attached, this method will log the error.
Postcondition
All registered listeners will be released, possibly causing deletion.
Todo:
Replace this when we have a logging facility.

Member Function Documentation

process_debugger::event_listener_id_t proclib::process_debugger::add_event_listener ( std::shared_ptr< base_debug_event_listener > const &  l)

Add a listener for debugger events sent to this process.

This method inserts a listener for debugger events that are relevent for the process managed by this process_debugger instance. The event handlers are not guaranteed to be fired in any order. Event handlers must not throw exceptions.

Handlers must neither add nor remove listener while handling an event. Doing so results in undefined behavior.

Parameters
[in]lThe custom listener to register.
Returns
A "token" that uniquely identifies the listener that was successfully added. If the listener was not added, this method returns process_debugger::invalid_event_listener_id.
Precondition
An event is not currently being processed.
l has not already been registered with this process_debugger.
Postcondition
l will begin receiving debugger events pertaining to this process.
Todo:
Deal with double-adds of the same listener
Todo:
Need a way to generate an ID
base_debug_event_listener & proclib::process_debugger::get_events ( ) const
noexcept

Access the main event handler for this process.

This is mostly useful for the proclib::debug_engine to pass process-specific events to this class (for distribution to listeners registered via add_event_listener()).

Returns
A reference to the process's events. It is valid until this instance is destroyed.
psystem::process_id_t proclib::process_debugger::get_process_id ( ) const
noexcept

Get the ID of the process being debugged here.

Returns
The numerical process ID (PID).
bool proclib::process_debugger::remove_event_listener ( event_listener_id_t  id)

Remove an already registered event listener.

This method removes a listener that was previously registered with add_event_listener() by its ID. If the ID was not found, this method does nothing.

Parameters
[in]idThe ID received on addition of the listener instance (from add_event_listener()).
Returns
true if the listener was found and removed; false if not.
Precondition
An event is not currently being processed.
A listener with an ID of id has already been registered with this process_debugger.
Postcondition
The listener with an ID of id will no longer receive debugger events pertaining to this process.
Todo:
This is not implemented!
void proclib::process_debugger::set_kill_process_on_exit ( bool  kill_on_exit)

Determine the fate of a process after the debugger detaches.

When the debugger detaches from a process or teminates, the process being debugged may either continue normal execution or terminate. The default action is to terminate the debuggee. Typical debugger behavior is to terminate a process that was created by the debugger, and allow a process to which the debugger attached to continue normal execution.

Parameters
[in]kill_on_exitIf true, the debugger should terminate the debuggee when detaching. Otherwise, the debuggee will continue normal execution.
Attention
This is a global flag for all debuggers. If not called, processes will be set to be killed on exit. This is a member function because you must have connected to at least one debugger before even calling it.

The documentation for this class was generated from the following files: