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