MPQC  3.0.0-alpha
sc::Debugger Class Reference

The Debugger class describes what should be done when a catastrophic error causes unexpected program termination. More...

#include <util/misc/bug.h>

Inheritance diagram for sc::Debugger:
sc::SavableState sc::DescribedClass sc::RefCount

Classes

class  Backtrace
 Creates a backtrace of a running program/thread. More...
 

Public Member Functions

 Debugger (const char *exec=0)
 
 Debugger (const Ref< KeyVal > &)
 The KeyVal constructor understands the following keywords: More...
 
 Debugger (StateIn &)
 
virtual void debug (const char *reason=0)
 The debug member attempts to start a debugger running on the current process.
 
virtual void traceback (const char *reason=0)
 The traceback member attempts to produce a Backtrace for the current process. More...
 
virtual void set_debug_on_signal (int)
 Turn on or off debugging on a signel. The default is on.
 
virtual void set_traceback_on_signal (int)
 Turn on or off traceback on a signel. The default is on.
 
virtual void set_exit_on_signal (int)
 Turn on or off exit after a signel. The default is on.
 
virtual void set_wait_for_debugger (int)
 Turn on or off running an infinite loop after the debugger is started. More...
 
virtual void handle (int sig)
 The Debugger will be actived when sig is caught.
 
virtual void handle_defaults ()
 This calls handle(int) with all of the major signals.
 
virtual void set_prefix (const char *p)
 This sets a prefix which preceeds all messages printing by Debugger.
 
virtual void set_prefix (int p)
 Set the prefix to the decimal represention of p followed by a ": ".
 
virtual void set_cmd (const char *)
 Sets the command to be exectuted when debug is called. More...
 
virtual void default_cmd ()
 Calls set_cmd with a hopefully suitable default.
 
virtual void set_exec (const char *)
 Set the name of the exectuble for the current process. More...
 
virtual void got_signal (int sig)
 Called when signal sig is received. This is mainly for internal use.
 
void save_data_state (StateOut &)
 Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR initializes them. More...
 
- Public Member Functions inherited from sc::SavableState
SavableStateoperator= (const SavableState &)
 
void save_state (StateOut &)
 Save the state of the object as specified by the StateOut object. More...
 
void save_object_state (StateOut &)
 This can be used for saving state when the exact type of the object is known for both the save and the restore. More...
 
virtual void save_vbase_state (StateOut &)
 Save the virtual bases for the object. More...
 
- Public Member Functions inherited from sc::DescribedClass
 DescribedClass (const DescribedClass &)
 
DescribedClassoperator= (const DescribedClass &)
 
ClassDescclass_desc () const MPQC__NOEXCEPT
 This returns the unique pointer to the ClassDesc corresponding to the given type_info object. More...
 
const char * class_name () const
 Return the name of the object's exact type.
 
int class_version () const
 Return the version of the class.
 
virtual void print (std::ostream &=ExEnv::out0()) const
 Print the object.
 
Ref< DescribedClassref ()
 Return this object wrapped up in a Ref smart pointer. More...
 
- Public Member Functions inherited from sc::RefCount
size_t identifier () const
 Return the unique identifier for this object that can be compared for different objects of different types. More...
 
int lock_ptr () const
 Lock this object.
 
int unlock_ptr () const
 Unlock this object.
 
void use_locks (bool inVal)
 start and stop using locks on this object
 
refcount_t nreference () const
 Return the reference count.
 
refcount_t reference ()
 Increment the reference count and return the new count.
 
refcount_t dereference ()
 Decrement the reference count and return the new count.
 
int managed () const
 
void unmanage ()
 Turn off the reference counting mechanism for this object. More...
 

Static Public Member Functions

static void set_default_debugger (const Ref< Debugger > &)
 Set the global default debugger. The initial value is null.
 
static Debuggerdefault_debugger ()
 Return the global default debugger.
 
- Static Public Member Functions inherited from sc::SavableState
static void save_state (SavableState *s, StateOut &)
 
static SavableStaterestore_state (StateIn &si)
 Restores objects saved with save_state. More...
 
static SavableStatekey_restore_state (StateIn &si, const char *keyword)
 Like restore_state, but keyword is used to override values while restoring.
 
static SavableStatedir_restore_state (StateIn &si, const char *objectname, const char *keyword=0)
 

Protected Member Functions

void init ()
 
- Protected Member Functions inherited from sc::SavableState
 SavableState (const SavableState &)
 
 SavableState (StateIn &)
 Each derived class StateIn CTOR handles the restore corresponding to calling save_object_state, save_vbase_state, and save_data_state listed above. More...
 
- Protected Member Functions inherited from sc::RefCount
 RefCount (const RefCount &)
 
RefCountoperator= (const RefCount &)
 

Static Protected Member Functions

static void __traceback (const std::string &prefix, const char *reason=0)
 prints out a backtrace More...
 

Protected Attributes

std::string prefix_
 
std::string exec_
 
std::string cmd_
 
volatile int debugger_ready_
 
int debug_
 
int traceback_
 
int exit_on_signal_
 
int sleep_
 
int wait_for_debugger_
 
int handle_sigint_
 
int * mysigs_
 

Static Protected Attributes

static Debuggerdefault_debugger_
 

Detailed Description

The Debugger class describes what should be done when a catastrophic error causes unexpected program termination.

It can try things such as start a debugger running where the program died or it can attempt to produce a stack traceback showing roughly where the program died. These attempts will not always succeed.

Constructor & Destructor Documentation

◆ Debugger()

sc::Debugger::Debugger ( const Ref< KeyVal > &  )

The KeyVal constructor understands the following keywords:

debug

Try to start a debugger when an error occurs. Doesn't work on all machines. The default is true, if possible.

traceback

Try to print out a traceback extracting return addresses from the call stack. Doesn't work on most machines. The default is true, if possible.

exit

Exit on errors. The default is true.

wait_for_debugger

When starting a debugger go into an infinite loop to give the debugger a chance to attach to the process. The default is true.

sleep

When starting a debugger wait this many seconds to give the debugger a chance to attach to the process. The default is 0.

handle_defaults

Handle a standard set of signals such as SIGBUS, SIGSEGV, etc. The default is true.

prefix

Gives a string that is printed before each line that is printed by Debugger. The default is nothing.

cmd

Gives a command to be executed to start the debugger. The default varies with machine.

Member Function Documentation

◆ __traceback()

static void sc::Debugger::__traceback ( const std::string &  prefix,
const char *  reason = 0 
)
staticprotected

prints out a backtrace

Parameters
prefixthis string will be prepended at the beginning of each line of Backtrace
reasonoptional string specifying the reason for traceback
Returns
backtrace

◆ save_data_state()

void sc::Debugger::save_data_state ( StateOut )
virtual

Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR initializes them.

This must be implemented by the derived class if the class has data.

Reimplemented from sc::SavableState.

◆ set_cmd()

virtual void sc::Debugger::set_cmd ( const char *  )
virtual

Sets the command to be exectuted when debug is called.

The character sequence "$(EXEC)" is replaced by the executable name (see set_exec), "$(PID)" is replaced by the current process id, and "$(PREFIX)" is replaced by the prefix.

◆ set_exec()

virtual void sc::Debugger::set_exec ( const char *  )
virtual

Set the name of the exectuble for the current process.

It is up to the programmer to set this, even if the Debugger is initialized with the KeyVal constructor.

◆ set_wait_for_debugger()

virtual void sc::Debugger::set_wait_for_debugger ( int  )
virtual

Turn on or off running an infinite loop after the debugger is started.

This loop gives the debugger a chance to attack to the process. The default is on.

◆ traceback()

virtual void sc::Debugger::traceback ( const char *  reason = 0)
virtual

The traceback member attempts to produce a Backtrace for the current process.

A symbol table must be saved for the executable if any sense is to be made of the traceback. This feature is available on platforms with (1) libunwind, (2) backtrace, or (3) certain platforms with hardwired unwinding.

Parameters
reasonoptional string specifying the reason for traceback

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

Generated at Sun Jan 26 2020 23:24:04 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.