Merge pull request #1626 from mc-server/StackTraceOnFailure
Stack trace on failure
This commit is contained in:
commit
d8e6931fe6
@ -46,6 +46,7 @@ set(SHARED_HDR
|
|||||||
../../src/ByteBuffer.h
|
../../src/ByteBuffer.h
|
||||||
../../src/StringUtils.h
|
../../src/StringUtils.h
|
||||||
)
|
)
|
||||||
|
|
||||||
flatten_files(SHARED_SRC)
|
flatten_files(SHARED_SRC)
|
||||||
flatten_files(SHARED_HDR)
|
flatten_files(SHARED_HDR)
|
||||||
source_group("Shared" FILES ${SHARED_SRC} ${SHARED_HDR})
|
source_group("Shared" FILES ${SHARED_SRC} ${SHARED_HDR})
|
||||||
@ -54,15 +55,22 @@ set(SHARED_OSS_SRC
|
|||||||
../../src/OSSupport/CriticalSection.cpp
|
../../src/OSSupport/CriticalSection.cpp
|
||||||
../../src/OSSupport/File.cpp
|
../../src/OSSupport/File.cpp
|
||||||
../../src/OSSupport/IsThread.cpp
|
../../src/OSSupport/IsThread.cpp
|
||||||
|
../../src/OSSupport/StackTrace.cpp
|
||||||
../../src/OSSupport/Timer.cpp
|
../../src/OSSupport/Timer.cpp
|
||||||
)
|
)
|
||||||
set(SHARED_OSS_HDR
|
set(SHARED_OSS_HDR
|
||||||
../../src/OSSupport/CriticalSection.h
|
../../src/OSSupport/CriticalSection.h
|
||||||
../../src/OSSupport/File.h
|
../../src/OSSupport/File.h
|
||||||
../../src/OSSupport/IsThread.h
|
../../src/OSSupport/IsThread.h
|
||||||
|
../../src/OSSupport/StackTrace.h
|
||||||
../../src/OSSupport/Timer.h
|
../../src/OSSupport/Timer.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
list (APPEND SHARED_OSS_SRC ../../src/StackWalker.cpp)
|
||||||
|
list (APPEND SHARED_OSS_HDR ../../src/StackWalker.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
flatten_files(SHARED_OSS_SRC)
|
flatten_files(SHARED_OSS_SRC)
|
||||||
flatten_files(SHARED_OSS_HDR)
|
flatten_files(SHARED_OSS_HDR)
|
||||||
|
|
||||||
|
@ -57,14 +57,22 @@ set(SHARED_OSS_SRC
|
|||||||
../../src/OSSupport/CriticalSection.cpp
|
../../src/OSSupport/CriticalSection.cpp
|
||||||
../../src/OSSupport/File.cpp
|
../../src/OSSupport/File.cpp
|
||||||
../../src/OSSupport/IsThread.cpp
|
../../src/OSSupport/IsThread.cpp
|
||||||
|
../../src/OSSupport/StackTrace.cpp
|
||||||
../../src/OSSupport/Timer.cpp
|
../../src/OSSupport/Timer.cpp
|
||||||
)
|
)
|
||||||
set(SHARED_OSS_HDR
|
set(SHARED_OSS_HDR
|
||||||
../../src/OSSupport/CriticalSection.h
|
../../src/OSSupport/CriticalSection.h
|
||||||
../../src/OSSupport/File.h
|
../../src/OSSupport/File.h
|
||||||
../../src/OSSupport/IsThread.h
|
../../src/OSSupport/IsThread.h
|
||||||
|
../../src/OSSupport/StackTrace.h
|
||||||
../../src/OSSupport/Timer.h
|
../../src/OSSupport/Timer.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
list (APPEND SHARED_OSS_SRC ../../src/StackWalker.cpp)
|
||||||
|
list (APPEND SHARED_OSS_HDR ../../src/StackWalker.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
flatten_files(SHARED_SRC)
|
flatten_files(SHARED_SRC)
|
||||||
flatten_files(SHARED_HDR)
|
flatten_files(SHARED_HDR)
|
||||||
flatten_files(SHARED_OSS_SRC)
|
flatten_files(SHARED_OSS_SRC)
|
||||||
|
@ -17,7 +17,7 @@ SOURCES += \
|
|||||||
BiomeView.cpp \
|
BiomeView.cpp \
|
||||||
../../src/Generating/BioGen.cpp \
|
../../src/Generating/BioGen.cpp \
|
||||||
../../src/VoronoiMap.cpp \
|
../../src/VoronoiMap.cpp \
|
||||||
../../src/Noise.cpp \
|
../../src/Noise/Noise.cpp \
|
||||||
../../src/StringUtils.cpp \
|
../../src/StringUtils.cpp \
|
||||||
../../src/LoggerListeners.cpp \
|
../../src/LoggerListeners.cpp \
|
||||||
../../src/Logger.cpp \
|
../../src/Logger.cpp \
|
||||||
@ -25,7 +25,9 @@ SOURCES += \
|
|||||||
../../src/OSSupport/File.cpp \
|
../../src/OSSupport/File.cpp \
|
||||||
../../src/OSSupport/CriticalSection.cpp \
|
../../src/OSSupport/CriticalSection.cpp \
|
||||||
../../src/OSSupport/IsThread.cpp \
|
../../src/OSSupport/IsThread.cpp \
|
||||||
|
../../src/OSSupport/StackTrace.cpp \
|
||||||
../../src/BiomeDef.cpp \
|
../../src/BiomeDef.cpp \
|
||||||
|
../../src/StackWalker.cpp \
|
||||||
../../src/StringCompression.cpp \
|
../../src/StringCompression.cpp \
|
||||||
../../src/WorldStorage/FastNBT.cpp \
|
../../src/WorldStorage/FastNBT.cpp \
|
||||||
../../lib/zlib/adler32.c \
|
../../lib/zlib/adler32.c \
|
||||||
@ -62,7 +64,7 @@ HEADERS += \
|
|||||||
../../src/Generating/IntGen.h \
|
../../src/Generating/IntGen.h \
|
||||||
../../src/Generating/ProtIntGen.h \
|
../../src/Generating/ProtIntGen.h \
|
||||||
../../src/VoronoiMap.h \
|
../../src/VoronoiMap.h \
|
||||||
../../src/Noise.h \
|
../../src/Noise/Noise.h \
|
||||||
../../src/StringUtils.h \
|
../../src/StringUtils.h \
|
||||||
../../src/LoggerListeners.h \
|
../../src/LoggerListeners.h \
|
||||||
../../src/Logger.h \
|
../../src/Logger.h \
|
||||||
@ -70,7 +72,9 @@ HEADERS += \
|
|||||||
../../src/OSSupport/File.h \
|
../../src/OSSupport/File.h \
|
||||||
../../src/OSSupport/CriticalSection.h \
|
../../src/OSSupport/CriticalSection.h \
|
||||||
../../src/OSSupport/IsThread.h \
|
../../src/OSSupport/IsThread.h \
|
||||||
|
../../src/OSSupport/StackTrace.h \
|
||||||
../../src/BiomeDef.h \
|
../../src/BiomeDef.h \
|
||||||
|
../../src/StackWalker.h \
|
||||||
../../src/StringCompression.h \
|
../../src/StringCompression.h \
|
||||||
../../src/WorldStorage/FastNBT.h \
|
../../src/WorldStorage/FastNBT.h \
|
||||||
../../lib/zlib/crc32.h \
|
../../lib/zlib/crc32.h \
|
||||||
@ -107,4 +111,15 @@ CONFIG += C++11
|
|||||||
|
|
||||||
OTHER_FILES +=
|
OTHER_FILES +=
|
||||||
|
|
||||||
|
win* {
|
||||||
|
# Add the advapi32 library for windows compiles; needed for the StackWalker:
|
||||||
|
LIBS += advapi32.lib
|
||||||
|
|
||||||
|
# StackWalker doesn't like how Qt inconsistently defines only UNICODE, but not _UNICODE:
|
||||||
|
DEFINES -= UNICODE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,6 +264,7 @@ template class SizeChecker<UInt16, 2>;
|
|||||||
#include "OSSupport/Thread.h"
|
#include "OSSupport/Thread.h"
|
||||||
#include "OSSupport/File.h"
|
#include "OSSupport/File.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "OSSupport/StackTrace.h"
|
||||||
#else
|
#else
|
||||||
// Logging functions
|
// Logging functions
|
||||||
void inline LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2);
|
void inline LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2);
|
||||||
@ -349,14 +350,14 @@ void inline LOGD(const char* a_Format, ...)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define ASSERT( x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), assert(0), 0))
|
#define ASSERT( x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), PrintStackTrace(), assert(0), 0))
|
||||||
#else
|
#else
|
||||||
#define ASSERT(x) ((void)(x))
|
#define ASSERT(x) ((void)(x))
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Pretty much the same as ASSERT() but stays in Release builds
|
// Pretty much the same as ASSERT() but stays in Release builds
|
||||||
#define VERIFY( x) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), exit(1), 0))
|
#define VERIFY( x) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), PrintStackTrace(), exit(1), 0))
|
||||||
|
|
||||||
// Same as assert but in all Self test builds
|
// Same as assert but in all Self test builds
|
||||||
#ifdef SELF_TEST
|
#ifdef SELF_TEST
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||||
|
|
||||||
#include "Noise.h"
|
#include "Noise.h"
|
||||||
#include "OSSupport/Timer.h"
|
|
||||||
|
|
||||||
#define FAST_FLOOR(x) (((x) < 0) ? (((int)x) - 1) : ((int)x))
|
#define FAST_FLOOR(x) (((x) < 0) ? (((int)x) - 1) : ((int)x))
|
||||||
|
|
||||||
|
@ -16,8 +16,10 @@ SET (SRCS
|
|||||||
Sleep.cpp
|
Sleep.cpp
|
||||||
Socket.cpp
|
Socket.cpp
|
||||||
SocketThreads.cpp
|
SocketThreads.cpp
|
||||||
|
StackTrace.cpp
|
||||||
Thread.cpp
|
Thread.cpp
|
||||||
Timer.cpp)
|
Timer.cpp
|
||||||
|
)
|
||||||
|
|
||||||
SET (HDRS
|
SET (HDRS
|
||||||
CriticalSection.h
|
CriticalSection.h
|
||||||
@ -32,8 +34,10 @@ SET (HDRS
|
|||||||
Sleep.h
|
Sleep.h
|
||||||
Socket.h
|
Socket.h
|
||||||
SocketThreads.h
|
SocketThreads.h
|
||||||
|
StackTrace.h
|
||||||
Thread.h
|
Thread.h
|
||||||
Timer.h)
|
Timer.h
|
||||||
|
)
|
||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
add_library(OSSupport ${SRCS} ${HDRS})
|
add_library(OSSupport ${SRCS} ${HDRS})
|
||||||
|
43
src/OSSupport/StackTrace.cpp
Normal file
43
src/OSSupport/StackTrace.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
// StackTrace.cpp
|
||||||
|
|
||||||
|
// Implements the functions to print current stack traces
|
||||||
|
|
||||||
|
#include "Globals.h"
|
||||||
|
#include "StackTrace.h"
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "../StackWalker.h"
|
||||||
|
#else
|
||||||
|
#include <execinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void PrintStackTrace(void)
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Reuse the StackWalker from the LeakFinder project already bound to MCS
|
||||||
|
// Define a subclass of the StackWalker that outputs everything to stdout
|
||||||
|
class PrintingStackWalker :
|
||||||
|
public StackWalker
|
||||||
|
{
|
||||||
|
virtual void OnOutput(LPCSTR szText) override
|
||||||
|
{
|
||||||
|
puts(szText);
|
||||||
|
}
|
||||||
|
} sw;
|
||||||
|
sw.ShowCallstack();
|
||||||
|
#else
|
||||||
|
// Use the backtrace() function to get and output the stackTrace:
|
||||||
|
// Code adapted from http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes
|
||||||
|
void * stackTrace[30];
|
||||||
|
size_t numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace));
|
||||||
|
backtrace_symbols_fd(stackTrace, numItems, STDERR_FILENO);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
15
src/OSSupport/StackTrace.h
Normal file
15
src/OSSupport/StackTrace.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
// StackTrace.h
|
||||||
|
|
||||||
|
// Declares the functions to print current stack trace
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Prints the stacktrace for the current thread. */
|
||||||
|
extern void PrintStackTrace(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -61,6 +61,7 @@ void NonCtrlHandler(int a_Signal)
|
|||||||
std::signal(SIGSEGV, SIG_DFL);
|
std::signal(SIGSEGV, SIG_DFL);
|
||||||
LOGERROR(" D: | MCServer has encountered an error and needs to close");
|
LOGERROR(" D: | MCServer has encountered an error and needs to close");
|
||||||
LOGERROR("Details | SIGSEGV: Segmentation fault");
|
LOGERROR("Details | SIGSEGV: Segmentation fault");
|
||||||
|
PrintStackTrace();
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
case SIGABRT:
|
case SIGABRT:
|
||||||
@ -71,6 +72,7 @@ void NonCtrlHandler(int a_Signal)
|
|||||||
std::signal(a_Signal, SIG_DFL);
|
std::signal(a_Signal, SIG_DFL);
|
||||||
LOGERROR(" D: | MCServer has encountered an error and needs to close");
|
LOGERROR(" D: | MCServer has encountered an error and needs to close");
|
||||||
LOGERROR("Details | SIGABRT: Server self-terminated due to an internal fault");
|
LOGERROR("Details | SIGABRT: Server self-terminated due to an internal fault");
|
||||||
|
PrintStackTrace();
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
@ -137,6 +139,9 @@ LONG WINAPI LastChanceExceptionFilter(__in struct _EXCEPTION_POINTERS * a_Except
|
|||||||
g_WriteMiniDump(GetCurrentProcess(), GetCurrentProcessId(), dumpFile, g_DumpFlags, (a_ExceptionInfo) ? &ExcInformation : nullptr, nullptr, nullptr);
|
g_WriteMiniDump(GetCurrentProcess(), GetCurrentProcessId(), dumpFile, g_DumpFlags, (a_ExceptionInfo) ? &ExcInformation : nullptr, nullptr, nullptr);
|
||||||
CloseHandle(dumpFile);
|
CloseHandle(dumpFile);
|
||||||
|
|
||||||
|
// Print the stack trace for the basic debugging:
|
||||||
|
PrintStackTrace();
|
||||||
|
|
||||||
// Revert to old stack:
|
// Revert to old stack:
|
||||||
_asm
|
_asm
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user