TwiceAsNice  2019-02-18
Public Types | Static Public Member Functions | Static Protected Attributes | Static Private Attributes | List of all members
Nice::CrashHandler Class Reference

This class handles segmentation-faults. More...

#include <CrashHandler.h>

Collaboration diagram for Nice::CrashHandler:
Collaboration graph

Public Types

typedef void(* HandlerType) (int)
 This function type is a pointer to a crash handler function. More...
 
typedef void(* HandlerType) (int)
 This function type is a pointer to a crash handler function. More...
 

Static Public Member Functions

static void defaultCrashHandler (int signal)
 The default crash handler. More...
 
static void setCrashHandler (HandlerType handler=defaultCrashHandler)
 Install a function to be called in case a SIGSEGV is caught. More...
 
static HandlerType crashHandler ()
 Returns the installed crash handler. More...
 
static void setEmergencySaveFunction (HandlerType saveFunction=(HandlerType) 0)
 Installs a function which should try to save the applications data. More...
 
static HandlerType emergencySaveFunction ()
 Return the currently set emergency save function. More...
 
static void setApplicationPath (const char *path)
 Sets the application path. More...
 
static void setApplicationName (const char *name)
 Sets the application name name. More...
 
static void defaultCrashHandler (int signal)
 The default crash handler. More...
 
static void setCrashHandler (HandlerType handler=defaultCrashHandler)
 Install a function to be called in case a SIGSEGV is caught. More...
 
static HandlerType crashHandler ()
 Returns the installed crash handler. More...
 
static void setEmergencySaveFunction (HandlerType saveFunction=(HandlerType) 0)
 Installs a function which should try to save the applications data. More...
 
static HandlerType emergencySaveFunction ()
 Return the currently set emergency save function. More...
 
static void setApplicationPath (const char *path)
 Sets the application path. More...
 
static void setApplicationName (const char *name)
 Sets the application name name. More...
 

Static Protected Attributes

static HandlerType _crashHandler = 0
 Pointer to the crash handler. More...
 
static HandlerType _emergencySaveFunction = 0
 Pointer to the emergency save function. More...
 

Static Private Attributes

static char * appName = 0
 
static char * appPath = 0
 
static bool safer
 

Detailed Description

This class handles segmentation-faults.

By default it dumps a gdb traceback of the segfaulting application. This default can be overridden by setting a custom crash handler with setCrashHandler(). If a function is specified with setEmergencySaveFunction() it will be called by the default crash handler, giving the application a chance to save its data.

Member Typedef Documentation

◆ HandlerType [1/2]

typedef void(* Nice::CrashHandler::HandlerType) (int)

This function type is a pointer to a crash handler function.

The function's argument is the number of the signal.

◆ HandlerType [2/2]

typedef void(* Nice::CrashHandler::HandlerType) (int)

This function type is a pointer to a crash handler function.

The function's argument is the number of the signal.

Member Function Documentation

◆ crashHandler() [1/2]

static HandlerType Nice::CrashHandler::crashHandler ( )
inlinestatic

Returns the installed crash handler.

Returns
the crash handler

◆ crashHandler() [2/2]

static HandlerType Nice::CrashHandler::crashHandler ( )
inlinestatic

Returns the installed crash handler.

Returns
the crash handler

◆ defaultCrashHandler() [1/2]

static void Nice::CrashHandler::defaultCrashHandler ( int  signal)
static

The default crash handler.

Parameters
signalthe signal number

◆ defaultCrashHandler() [2/2]

void Nice::CrashHandler::defaultCrashHandler ( int  signal)
static

The default crash handler.

Parameters
signalthe signal number

◆ emergencySaveFunction() [1/2]

static HandlerType Nice::CrashHandler::emergencySaveFunction ( )
inlinestatic

Return the currently set emergency save function.

Returns
the emergency save function

◆ emergencySaveFunction() [2/2]

static HandlerType Nice::CrashHandler::emergencySaveFunction ( )
inlinestatic

Return the currently set emergency save function.

Returns
the emergency save function

◆ setApplicationName() [1/2]

static void Nice::CrashHandler::setApplicationName ( const char *  name)
inlinestatic

Sets the application name name.

Parameters
namethe name of the application

◆ setApplicationName() [2/2]

static void Nice::CrashHandler::setApplicationName ( const char *  name)
inlinestatic

Sets the application name name.

Parameters
namethe name of the application

◆ setApplicationPath() [1/2]

static void Nice::CrashHandler::setApplicationPath ( const char *  path)
inlinestatic

Sets the application path.

Parameters
paththe application path.

◆ setApplicationPath() [2/2]

static void Nice::CrashHandler::setApplicationPath ( const char *  path)
inlinestatic

Sets the application path.

Parameters
paththe application path.

◆ setCrashHandler() [1/2]

void Nice::CrashHandler::setCrashHandler ( HandlerType  handler = defaultCrashHandler)
static

Install a function to be called in case a SIGSEGV is caught.

Parameters
handlerHandlerType handler can be one of
  • null in which case signal-catching is disabled (by calling signal(SIGSEGV, SIG_DFL))
  • if handler is omitted the default crash handler is installed.
  • an user defined function in the form: static (if in a class) void myCrashHandler(int);
handlerthe crash handler

◆ setCrashHandler() [2/2]

static void Nice::CrashHandler::setCrashHandler ( HandlerType  handler = defaultCrashHandler)
static

Install a function to be called in case a SIGSEGV is caught.

Parameters
handlerHandlerType handler can be one of
  • null in which case signal-catching is disabled (by calling signal(SIGSEGV, SIG_DFL))
  • if handler is omitted the default crash handler is installed.
  • an user defined function in the form: static (if in a class) void myCrashHandler(int);
handlerthe crash handler

◆ setEmergencySaveFunction() [1/2]

void Nice::CrashHandler::setEmergencySaveFunction ( HandlerType  saveFunction = (HandlerType)0)
static

Installs a function which should try to save the applications data.

It is the crash handlers responsibility to call this function. Therefore, if no crash handler is set, the default crash handler is installed to ensure the save function is called.

Parameters
saveFunctionthe handler to install

◆ setEmergencySaveFunction() [2/2]

static void Nice::CrashHandler::setEmergencySaveFunction ( HandlerType  saveFunction = (HandlerType) 0)
static

Installs a function which should try to save the applications data.

It is the crash handlers responsibility to call this function. Therefore, if no crash handler is set, the default crash handler is installed to ensure the save function is called.

Parameters
saveFunctionthe handler to install

Member Data Documentation

◆ _crashHandler

static HandlerType Nice::CrashHandler::_crashHandler = 0
staticprotected

Pointer to the crash handler.

◆ _emergencySaveFunction

static HandlerType Nice::CrashHandler::_emergencySaveFunction = 0
staticprotected

Pointer to the emergency save function.

◆ appName

static char * Nice::CrashHandler::appName = 0
staticprivate

◆ appPath

static char * Nice::CrashHandler::appPath = 0
staticprivate

◆ safer

static bool Nice::CrashHandler::safer
staticprivate

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