Skip to content

Commit

Permalink
[llvm-exegesis] Add explicit error message with segfault address
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
boomanaiden154 committed Dec 2, 2023
1 parent bb6497f commit 592ab21
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion llvm/tools/llvm-exegesis/lib/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#include "Error.h"

#ifdef LLVM_ON_UNIX
#include <string.h>
#endif // LLVM_ON_UNIX

namespace llvm {
namespace exegesis {

Expand All @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion llvm/tools/llvm-exegesis/lib/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"

#include <cstdint>

namespace llvm {
namespace exegesis {

Expand Down Expand Up @@ -41,14 +43,19 @@ 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;

std::error_code convertToErrorCode() const override;

private:
std::string Msg;
intptr_t SIAddress;
int SISignalNumber;
};

} // namespace exegesis
Expand Down

0 comments on commit 592ab21

Please sign in to comment.