summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-05-03 19:37:47 -0700
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-12 20:12:45 +0000
commit96bf7b01f6adfe042630953eafa66942773be068 (patch)
tree7a71509ef76cabd61a046bd218db8aa83ddc748e /src/testlib
parentc3ad3ad4195665cf06db09159580cd52dde53901 (diff)
FatalSignalHandler: print the signal name on crash
It's easier to remember what "SIGSEGV" means instead of "11". GNU libc has offered sigabbrev_np() (non-portable) since 2.32; for older libcs, we'll be happy with a hardcoded list. Selftest updated to match... though it didn't seem to be necessary. Change-Id: I5ff8e16fcdcb4ffd9ab6fffd16ebc66ecf6e9465 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 17454bf9c60d9a7f836461234f48e1bb9d7d5bf9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtestcase.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 2d329477c8..ed9b52244a 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -1910,9 +1910,40 @@ using FatalSignalHandler = WindowsFaultHandler;
class FatalSignalHandler
{
public:
+# define OUR_SIGNALS(F) \
+ F(HUP) \
+ F(INT) \
+ F(QUIT) \
+ F(ABRT) \
+ F(ILL) \
+ F(BUS) \
+ F(FPE) \
+ F(SEGV) \
+ F(PIPE) \
+ F(TERM) \
+ /**/
+# define CASE_LABEL(S) case SIG ## S: return QT_STRINGIFY(S);
+# define ENUMERATE_SIGNALS(S) SIG ## S,
+ static const char *signalName(int signum) noexcept
+ {
+ switch (signum) {
+ OUR_SIGNALS(CASE_LABEL)
+ }
+
+# if defined(__GLIBC_MINOR__) && (__GLIBC_MINOR__ >= 32 || __GLIBC__ > 2)
+ // get the other signal names from glibc 2.32
+ // (accessing the sys_sigabbrev variable causes linker warnings)
+ if (const char *p = sigabbrev_np(signum))
+ return p;
+# endif
+ return "???";
+ }
static constexpr std::array fatalSignals = {
- SIGHUP, SIGINT, SIGQUIT, SIGABRT, SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM
+ OUR_SIGNALS(ENUMERATE_SIGNALS)
};
+# undef CASE_LABEL
+# undef ENUMERATE_SIGNALS
+
static constexpr std::array crashingSignals = {
// Crash signals are special, because if we return from the handler
// without adjusting the machine state, the same instruction that
@@ -2047,7 +2078,8 @@ private:
static void actionHandler(int signum, siginfo_t * /* info */, void * /* ucontext */)
{
- writeToStderr("Received signal ", asyncSafeToString(signum), "\n");
+ writeToStderr("Received signal ", asyncSafeToString(signum),
+ " (SIG", signalName(signum), ")\n");
printTestRunTime();
if (signum != SIGINT) {