OpenShot Library | libopenshot  0.1.9
CrashHandler.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for CrashHandler class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @section LICENSE
7  *
8  * Copyright (c) 2008-2014 OpenShot Studios, LLC
9  * <http://www.openshotstudios.com/>. This file is part of
10  * OpenShot Library (libopenshot), an open-source project dedicated to
11  * delivering high quality video editing and animation solutions to the
12  * world. For more information visit <http://www.openshot.org/>.
13  *
14  * OpenShot Library (libopenshot) is free software: you can redistribute it
15  * and/or modify it under the terms of the GNU Lesser General Public License
16  * as published by the Free Software Foundation, either version 3 of the
17  * License, or (at your option) any later version.
18  *
19  * OpenShot Library (libopenshot) is distributed in the hope that it will be
20  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef OPENSHOT_CRASH_HANDLER_H
29 #define OPENSHOT_CRASH_HANDLER_H
30 
31 #include <cstdlib>
32 #include <stdio.h>
33 #include <signal.h>
34 #ifdef __MINGW32__
35  #include <winsock2.h>
36  #include <windows.h>
37  #include <DbgHelp.h>
38 #else
39  #include <execinfo.h>
40 #endif
41 #include <errno.h>
42 #include <cxxabi.h>
43 #include "ZmqLogger.h"
44 
45 namespace openshot {
46 
47  /**
48  * @brief This class is designed to catch exceptions thrown by libc (SIGABRT, SIGSEGV, SIGILL, SIGFPE)
49  *
50  * This class is a singleton which only needs to be instantiated 1 time, and it will register as a signal
51  * handler with libc, and log errors using the ZmqLogger class.
52  */
53  class CrashHandler {
54  private:
55  /// Default constructor
56  CrashHandler(){}; // Don't allow user to create an instance of this singleton
57 
58  /// Default copy method
59  CrashHandler(CrashHandler const&){}; // Don't allow the user to copy this instance
60 
61  /// Default assignment operator
62  CrashHandler & operator=(CrashHandler const&){}; // Don't allow the user to assign this instance
63 
64  /// Private variable to keep track of singleton instance
65  static CrashHandler *m_pInstance;
66 
67  public:
68  /// Create or get an instance of this crash handler singleton (invoke the class with this method). This also
69  /// registers the instance as a signal handler for libc
70  static CrashHandler *Instance();
71 
72 #ifdef __MINGW32__
73  // TODO: Windows exception handling methods
74  static void abortHandler(int signum);
75 #else
76  /// Method which handles crashes and logs error
77  static void abortHandler(int signum, siginfo_t* si, void* unused);
78 #endif
79 
80  /// Method which prints a stacktrace
81  static void printStackTrace(FILE *out, unsigned int max_frames);
82  };
83 
84 }
85 
86 #endif
static void abortHandler(int signum, siginfo_t *si, void *unused)
Method which handles crashes and logs error.
static void printStackTrace(FILE *out, unsigned int max_frames)
Method which prints a stacktrace.
This class is designed to catch exceptions thrown by libc (SIGABRT, SIGSEGV, SIGILL, SIGFPE)
Definition: CrashHandler.h:53
static CrashHandler * Instance()
Header file for ZeroMQ-based Logger class.
This namespace is the default namespace for all code in the openshot library.