[llvm-exegesis] Print signal name when the snippet crashed.
authorClement Courbet <courbet@google.com>
Fri, 30 Oct 2020 10:35:47 +0000 (11:35 +0100)
committerClement Courbet <courbet@google.com>
Mon, 2 Nov 2020 09:41:17 +0000 (10:41 +0100)
Differential Revision: https://reviews.llvm.org/D90453

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp

index f015147..1bbad20 100644 (file)
@@ -101,9 +101,19 @@ private:
           Counter->stop();
         });
         CrashRecoveryContext::Disable();
-        // FIXME: Better diagnosis.
-        if (Crashed)
-          return make_error<SnippetCrash>("snippet crashed while running");
+        if (Crashed) {
+          std::string Msg = "snippet crashed while running";
+#ifdef LLVM_ON_UNIX
+          // See "Exit Status for Commands":
+          // https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html
+          constexpr const int kSigOffset = 128;
+          if (const char *const SigName = strsignal(CRC.RetCode - kSigOffset)) {
+            Msg += ": ";
+            Msg += SigName;
+          }
+#endif
+          return make_error<SnippetCrash>(std::move(Msg));
+        }
       }
 
       auto ValueOrError = Counter->readOrError(Function.getFunctionBytes());