mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-13 10:42:56 +01:00
Handle that the signal type might be too big for an int if we are running on Windows
(signal is int, but exceptioncode is unsigned long)
This commit is contained in:
parent
1329a1d807
commit
55d91601b8
@ -15,12 +15,16 @@
|
||||
// implementationsfilen kan vara den samma
|
||||
namespace g2 {
|
||||
|
||||
|
||||
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
|
||||
typedef unsigned long SignalType;
|
||||
/// SIGFPE, SIGILL, and SIGSEGV handling must be installed per thread
|
||||
/// on Windows. This is automatically done if you do at least one LOG(...) call
|
||||
/// you can also use this function call, per thread so make sure these three
|
||||
/// fatal signals are covered in your thread (even if you don't do a LOG(...) call
|
||||
void installSignalHandlerForThread();
|
||||
#else
|
||||
typedef int SignalType;
|
||||
#endif
|
||||
|
||||
|
||||
@ -34,7 +38,7 @@ bool blockForFatalHandling();
|
||||
|
||||
/** \return signal_name Ref: signum.hpp and \ref installSignalHandler
|
||||
* or for Windows exception name */
|
||||
std::string exitReasonName(const LEVELS& level, size_t signal_number);
|
||||
std::string exitReasonName(const LEVELS& level, g2::SignalType signal_number);
|
||||
|
||||
/** return calling thread's stackdump*/
|
||||
std::string stackdump(const char *dump = nullptr);
|
||||
@ -42,7 +46,7 @@ std::string stackdump(const char *dump = nullptr);
|
||||
/** Re-"throw" a fatal signal, previously caught. This will exit the application
|
||||
* This is an internal only function. Do not use it elsewhere. It is triggered
|
||||
* from g2log, g2LogWorker after flushing messages to file */
|
||||
void exitWithDefaultSignalHandler(const LEVELS& level, size_t signal_number);
|
||||
void exitWithDefaultSignalHandler(const LEVELS& level, g2::SignalType signal_number);
|
||||
} // end g2::internal
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ void signalHandler(int signal_number, siginfo_t *info, void *unused_context) {
|
||||
std::ostringstream fatal_stream;
|
||||
fatal_stream << oss.str() << std::endl;
|
||||
fatal_stream << "\n***** SIGNAL " << exitReasonName(signal_number) << "(" << signal_number << ")" << std::endl;
|
||||
LogCapture trigger(FATAL_SIGNAL, signal_number, stackdump());
|
||||
LogCapture trigger(FATAL_SIGNAL, static_cast<g2::SignalType>(signal_number), stackdump());
|
||||
trigger.stream() << fatal_stream.str();
|
||||
} // message sent to g2LogWorker
|
||||
// wait to die
|
||||
@ -180,7 +180,8 @@ std::string exitReasonName(size_t signal_number) {
|
||||
// Triggered by g2log->g2LogWorker after receiving a FATAL trigger
|
||||
// which is LOG(FATAL), CHECK(false) or a fatal signal our signalhandler caught.
|
||||
// --- If LOG(FATAL) or CHECK(false) the signal_number will be SIGABRT
|
||||
void exitWithDefaultSignalHandler(int signal_number) {
|
||||
void exitWithDefaultSignalHandler(SignalType fatal_signal_id) {
|
||||
const int signal_number = static_cast<int>(fatal_signal_id);
|
||||
std::cerr << "Exiting - FATAL SIGNAL: " << signal_number << " " << std::flush;
|
||||
struct sigaction action;
|
||||
memset(&action, 0, sizeof (action)); //
|
||||
|
@ -71,7 +71,7 @@ void signalHandler(int signal_number) {
|
||||
const auto dump = sttrace.to_string();
|
||||
/************ STOP HACk ***********/
|
||||
|
||||
LogCapture trigger(FATAL_SIGNAL, signal_number, dump.c_str());
|
||||
LogCapture trigger(FATAL_SIGNAL, static_cast<g2::SignalType>(signal_number), dump.c_str());
|
||||
trigger.stream() << fatal_stream.str();
|
||||
} // scope exit - message sent to LogWorker, wait to die...
|
||||
|
||||
@ -149,7 +149,7 @@ std::string stackdump(const char *dump) {
|
||||
|
||||
|
||||
/// string representation of signal ID or Windows exception id
|
||||
std::string exitReasonName(const LEVELS &level, size_t fatal_id) {
|
||||
std::string exitReasonName(const LEVELS &level, g2::SignalType fatal_id) {
|
||||
//
|
||||
std::cout << __FUNCTION__ << " exit reason: " << fatal_id << std::endl;
|
||||
if (level == g2::internal::FATAL_EXCEPTION) {
|
||||
@ -178,7 +178,7 @@ std::string exitReasonName(const LEVELS &level, size_t fatal_id) {
|
||||
// Triggered by g2log::LogWorker after receiving a FATAL trigger
|
||||
// which is LOG(FATAL), CHECK(false) or a fatal signal our signalhandler caught.
|
||||
// --- If LOG(FATAL) or CHECK(false) the signal_number will be SIGABRT
|
||||
void exitWithDefaultSignalHandler(const LEVELS &level, size_t signal_number) {
|
||||
void exitWithDefaultSignalHandler(const LEVELS &level, g2::SignalType fatal_signal_id) {
|
||||
|
||||
ReverseToOriginalFatalHandling();
|
||||
// For windows exceptions we want to continue the possibility of exception handling
|
||||
@ -190,6 +190,8 @@ void exitWithDefaultSignalHandler(const LEVELS &level, size_t signal_number) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const int signal_number = static_cast<int>(fatal_signal_id);
|
||||
raise(signal_number);
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ std::string LogMessage::threadID() const {
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
FatalMessage::FatalMessage(const LogMessage &details, size_t signal_id)
|
||||
FatalMessage::FatalMessage(const LogMessage &details, g2::SignalType signal_id)
|
||||
: LogMessage(details), _signal_id(signal_id) { }
|
||||
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include "g2loglevels.hpp"
|
||||
#include "g2time.hpp"
|
||||
#include "g2moveoncopy.hpp"
|
||||
#include "crashhandler.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace g2 {
|
||||
|
||||
/** LogMessage contains all the data collected from the LOG(...) call.
|
||||
@ -86,14 +86,14 @@ namespace g2 {
|
||||
* A thread that causes a FatalMessage will sleep forever until the
|
||||
* application has exited (after message flush) */
|
||||
struct FatalMessage : public LogMessage {
|
||||
FatalMessage(const LogMessage& details, size_t signal_id);
|
||||
FatalMessage(const LogMessage& details, g2::SignalType signal_id);
|
||||
FatalMessage(const FatalMessage&);
|
||||
virtual ~FatalMessage(){};
|
||||
|
||||
LogMessage copyToLogMessage() const;
|
||||
std::string reason() const;
|
||||
|
||||
const size_t _signal_id;
|
||||
const SignalType _signal_id;
|
||||
static const int FATAL_EXCEPTION_EXIT = 1243;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user