mirror of
https://github.com/facebook/zstd.git
synced 2025-07-30 22:23:13 +03:00
Print a stack trace on unexpected term signal (e.g. SIGABRT)
For OSX and Linux, add a signal handler to SIGABRT, SGIFPE, SIGILL, SIGSEGV, and SIGBUS. When the program terminates unexpectedly the handler will print the current stack to the terminal to help determine the location of the failure. On OSX the output will look like: ``` Stack trace: 4 zstd 0x000000010927ed96 main + 16886 5 libdyld.dylib 0x00007fff767d1015 start + 1 6 ??? 0x0000000000000001 0x0 + 1 ``` On Linux the output will look like: ``` Stack trace: ./zstd() [0x4b8e1b] ./zstd() [0x4b928a] ./zstd() [0x403dc2] /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f5e0fbb0445] ./zstd() [0x405754] ``` As is, the code does not function on WIN32. See also: https://oroboro.com/stack-trace-on-crash/
This commit is contained in:
@ -39,6 +39,7 @@
|
||||
#endif
|
||||
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_maxCLevel */
|
||||
#include "zstd.h" /* ZSTD_VERSION_STRING */
|
||||
#include "zstd_internal.h" /* ZSTD_addAbortHandler */
|
||||
|
||||
|
||||
/*-************************************
|
||||
@ -511,6 +512,9 @@ int main(int argCount, const char* argv[])
|
||||
if (exeNameMatch(programName, ZSTD_UNLZ4)) { operation=zom_decompress; FIO_setCompressionType(FIO_lz4Compression); } /* behave like unlz4, also supports multiple formats */
|
||||
memset(&compressionParams, 0, sizeof(compressionParams));
|
||||
|
||||
/* init crash handler */
|
||||
ZSTD_addAbortHandler();
|
||||
|
||||
/* command switches */
|
||||
for (argNb=1; argNb<argCount; argNb++) {
|
||||
const char* argument = argv[argNb];
|
||||
|
Reference in New Issue
Block a user