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