[llvm-branch-commits] [llvm] 592ab21 - [llvm-exegesis] Add explicit error message with segfault address
Aiden Grossman via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Dec 2 13:34:27 PST 2023
Author: Aiden Grossman
Date: 2023-12-02T13:33:18-08:00
New Revision: 592ab2122dbe5c38712b5b9fc17126308783467a
URL: https://github.com/llvm/llvm-project/commit/592ab2122dbe5c38712b5b9fc17126308783467a
DIFF: https://github.com/llvm/llvm-project/commit/592ab2122dbe5c38712b5b9fc17126308783467a.diff
LOG: [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.
Added:
Modified:
llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/Error.cpp
llvm/tools/llvm-exegesis/lib/Error.h
Removed:
################################################################################
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-branch-commits
mailing list