Skip to content

Commit 592ab21

Browse files
[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.
1 parent bb6497f commit 592ab21

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mode=latency -snippets-file=%s -execution-mode=subprocess | FileCheck %s
44

5-
# CHECK: error: 'The benchmarking subprocess sent unexpected signal: Segmentation fault'
5+
# CHECK: error: The snippet crashed with signal Segmentation fault at address 10000
66

7-
# LLVM-EXEGESIS-DEFREG RBX 0
7+
# LLVM-EXEGESIS-DEFREG RBX 10000
88
movq (%rbx), %rax

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ class SubProcessFunctionExecutorImpl
374374
}
375375

376376
return make_error<SnippetCrash>(
377-
"The benchmarking subprocess sent unexpected signal: " +
378-
Twine(strsignal(ChildSignalInfo.si_signo)));
377+
ChildSignalInfo.si_signo,
378+
reinterpret_cast<intptr_t>(ChildSignalInfo.si_addr));
379379
}
380380

381381
[[noreturn]] void prepareAndRunBenchmark(int Pipe,

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
#include "Error.h"
1010

11+
#ifdef LLVM_ON_UNIX
12+
#include <string.h>
13+
#endif // LLVM_ON_UNIX
14+
1115
namespace llvm {
1216
namespace exegesis {
1317

@@ -21,7 +25,18 @@ std::error_code ClusteringError::convertToErrorCode() const {
2125

2226
char SnippetCrash::ID;
2327

24-
void SnippetCrash::log(raw_ostream &OS) const { OS << Msg; }
28+
void SnippetCrash::log(raw_ostream &OS) const {
29+
if (SISignalNumber == -1) {
30+
OS << Msg;
31+
return;
32+
}
33+
#ifdef LLVM_ON_UNIX
34+
OS << "The snippet crashed with signal " << strsignal(SISignalNumber)
35+
<< " at address " << Twine::utohexstr(SIAddress);
36+
#else
37+
OS << "The snippet crashed with a signal";
38+
#endif // LLVM_ON_UNIX
39+
}
2540

2641
std::error_code SnippetCrash::convertToErrorCode() const {
2742
return inconvertibleErrorCode();

llvm/tools/llvm-exegesis/lib/Error.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "llvm/ADT/Twine.h"
1313
#include "llvm/Support/Error.h"
1414

15+
#include <cstdint>
16+
1517
namespace llvm {
1618
namespace exegesis {
1719

@@ -41,14 +43,19 @@ class ClusteringError : public ErrorInfo<ClusteringError> {
4143
class SnippetCrash : public ErrorInfo<SnippetCrash> {
4244
public:
4345
static char ID;
44-
SnippetCrash(const Twine &S) : Msg(S.str()) {}
46+
SnippetCrash(const Twine &S)
47+
: Msg(S.str()), SIAddress(-1), SISignalNumber(-1) {}
48+
SnippetCrash(int SISignalNumber_, intptr_t SIAddress_)
49+
: Msg(""), SIAddress(SIAddress_), SISignalNumber(SISignalNumber_) {}
4550

4651
void log(raw_ostream &OS) const override;
4752

4853
std::error_code convertToErrorCode() const override;
4954

5055
private:
5156
std::string Msg;
57+
intptr_t SIAddress;
58+
int SISignalNumber;
5259
};
5360

5461
} // namespace exegesis

0 commit comments

Comments
 (0)