HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_CrashHandler.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_CrashHandler.h (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_CrashHandler__
12 #define __UT_CrashHandler__
13 
14 #include "UT_API.h"
15 #include "UT_UniquePtr.h"
16 #include "UT_Signal.h"
17 #include "UT_String.h"
18 
19 
20 /// This class handles crashing signals
21 ///
22 /// This must be a singleton object. It traps crashing signals and handles
23 /// them properly.
24 /// a) When a thread catches a signal, the signal is passed to the main thread
25 /// b) A stack trace is can be printed
26 /// This detects recursion into the signal handler and takes appropriate action
27 ///
28 /// Depending on the environment variable HOUDINI_COREDUMP, houdini will generate a core or
30 {
31 public:
32  /// Construct using an array of signals. The array should be terminated by
33  /// a zero.
34  explicit UT_CrashHandler(const char *app_name);
35  virtual ~UT_CrashHandler();
36 
37  /// Access to the singleton
38  static const UT_CrashHandler *getCrashHandler();
39 
40  /// A subclass gets a chance to handle the signal before the base class
41  /// takes any action. If the method returns @c true, the signal handler
42  /// will just return from the signal handler and the process will continue.
43  /// The default method returns @c false, letting the signal be processed
44  /// properly.
45  ///
46  /// Also, please note that this method may be called multiple times. It
47  /// may be called from a thread, then from the main thread, even for the
48  /// same signal. When called for a thread, the same signal will always be
49  /// invoked for the main thread, so you may only want to do your processing
50  /// when UT_Thread::isMainThread() is true.
51  ///
52  /// Please note that this is called from within a signal handler. The
53  /// signal might have been raised within Python, so don't call Python from
54  /// the handler. The signal handler might have been called within
55  /// malloc()/free(), so there might be a system lock on malloc, so try not
56  /// to call malloc/free from within your handler.
57  virtual bool handledSignal(UTsignalHandlerArg arg);
58 
59  /// This virtual allows the signal handler to have a "chaser" function, one
60  /// which gets called after the stack trace has been printed out, but
61  /// before core is actually dumped.
62  virtual void chaser(UTsignalHandlerArg arg);
63 
64  /// Indicate whether the stack trace should be printed to stderr on a crash
65  /// Defaults to @c true
66  virtual bool traceToStderr() const;
67 
68  /// Return the application name
69  const char *applicationName() const
70  { return myAppName; }
71 
72  /// Set the application name
73  void setApplicationName(const char *app_name)
74  { myAppName = app_name; }
75 
76  /// Access to signals
77  const UT_Signal *signals() const
78  { return mySignals.get(); }
79 
80  /// Access to signal handler function
81  UTsigHandler signalFunction() const;
82 
83 private:
84  UT_String myAppName;
85  UT_UniquePtr<UT_Signal> mySignals;
86 };
87 
88 #endif
#define UT_API
Definition: UT_API.h:13
const UT_Signal * signals() const
Access to signals.
const char * applicationName() const
Return the application name.
void setApplicationName(const char *app_name)
Set the application name.
void(* UTsigHandler)(UTsignalHandlerArg)
Definition: UT_Signal.h:169