[llvm] [llvm-exegesis] Add explicit error message with segfault address (PR #74210)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 2 14:23:19 PST 2023


https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/74210

This patch special cases the segfault case for the subprocess executor, giving the exact address of a segfault when one occurs in the subprocess. This makes it a lot easier to debug where things are going wrong in the snippet.

>From 592ab2122dbe5c38712b5b9fc17126308783467a Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Sat, 18 Nov 2023 19:41:29 -0800
Subject: [PATCH] [llvm-exegesis] Add explicit error message with segfault
 address

This patch special cases the segfault case for the subprocess executor,
giving the exact address of a segfault when one occurs in the
subprocess. This makes it a lot easier to debug where things are going
wrong in the snippet.
---
 .../X86/latency/subprocess-segfault.s           |  4 ++--
 .../tools/llvm-exegesis/lib/BenchmarkRunner.cpp |  4 ++--
 llvm/tools/llvm-exegesis/lib/Error.cpp          | 17 ++++++++++++++++-
 llvm/tools/llvm-exegesis/lib/Error.h            |  9 ++++++++-
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s b/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
index 92b08e1c18c62..db04f8522e4e0 100644
--- a/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
+++ b/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
@@ -2,7 +2,7 @@
 
 # RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mode=latency -snippets-file=%s -execution-mode=subprocess | FileCheck %s
 
-# CHECK: error:           'The benchmarking subprocess sent unexpected signal: Segmentation fault'
+# CHECK: error:           The snippet crashed with signal Segmentation fault at address 10000
 
-# LLVM-EXEGESIS-DEFREG RBX 0
+# LLVM-EXEGESIS-DEFREG RBX 10000
 movq (%rbx), %rax
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 85375dec2a44c..f5d73a8bd6a31 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -374,8 +374,8 @@ class SubProcessFunctionExecutorImpl
     }
 
     return make_error<SnippetCrash>(
-        "The benchmarking subprocess sent unexpected signal: " +
-        Twine(strsignal(ChildSignalInfo.si_signo)));
+        ChildSignalInfo.si_signo,
+        reinterpret_cast<intptr_t>(ChildSignalInfo.si_addr));
   }
 
   [[noreturn]] void prepareAndRunBenchmark(int Pipe,
diff --git a/llvm/tools/llvm-exegesis/lib/Error.cpp b/llvm/tools/llvm-exegesis/lib/Error.cpp
index 51ce41bf00bf5..213e54e3bcf53 100644
--- a/llvm/tools/llvm-exegesis/lib/Error.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Error.cpp
@@ -8,6 +8,10 @@
 
 #include "Error.h"
 
+#ifdef LLVM_ON_UNIX
+#include <string.h>
+#endif // LLVM_ON_UNIX
+
 namespace llvm {
 namespace exegesis {
 
@@ -21,7 +25,18 @@ std::error_code ClusteringError::convertToErrorCode() const {
 
 char SnippetCrash::ID;
 
-void SnippetCrash::log(raw_ostream &OS) const { OS << Msg; }
+void SnippetCrash::log(raw_ostream &OS) const {
+  if (SISignalNumber == -1) {
+    OS << Msg;
+    return;
+  }
+#ifdef LLVM_ON_UNIX
+  OS << "The snippet crashed with signal " << strsignal(SISignalNumber)
+     << " at address " << Twine::utohexstr(SIAddress);
+#else
+  OS << "The snippet crashed with a signal";
+#endif // LLVM_ON_UNIX
+}
 
 std::error_code SnippetCrash::convertToErrorCode() const {
   return inconvertibleErrorCode();
diff --git a/llvm/tools/llvm-exegesis/lib/Error.h b/llvm/tools/llvm-exegesis/lib/Error.h
index e5fa093e6e125..8d3f394ed8d6e 100644
--- a/llvm/tools/llvm-exegesis/lib/Error.h
+++ b/llvm/tools/llvm-exegesis/lib/Error.h
@@ -12,6 +12,8 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Error.h"
 
+#include <cstdint>
+
 namespace llvm {
 namespace exegesis {
 
@@ -41,7 +43,10 @@ class ClusteringError : public ErrorInfo<ClusteringError> {
 class SnippetCrash : public ErrorInfo<SnippetCrash> {
 public:
   static char ID;
-  SnippetCrash(const Twine &S) : Msg(S.str()) {}
+  SnippetCrash(const Twine &S)
+      : Msg(S.str()), SIAddress(-1), SISignalNumber(-1) {}
+  SnippetCrash(int SISignalNumber_, intptr_t SIAddress_)
+      : Msg(""), SIAddress(SIAddress_), SISignalNumber(SISignalNumber_) {}
 
   void log(raw_ostream &OS) const override;
 
@@ -49,6 +54,8 @@ class SnippetCrash : public ErrorInfo<SnippetCrash> {
 
 private:
   std::string Msg;
+  intptr_t SIAddress;
+  int SISignalNumber;
 };
 
 } // namespace exegesis



More information about the llvm-commits mailing list