[llvm] 95abdeb - llvm-reduce: Disable crash reports, symbolization and core dumps
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 20 16:01:31 PST 2022
Author: Matt Arsenault
Date: 2022-12-20T19:01:26-05:00
New Revision: 95abdeba6152c3fa15e96b4bababe6311bc9c118
URL: https://github.com/llvm/llvm-project/commit/95abdeba6152c3fa15e96b4bababe6311bc9c118
DIFF: https://github.com/llvm/llvm-project/commit/95abdeba6152c3fa15e96b4bababe6311bc9c118.diff
LOG: llvm-reduce: Disable crash reports, symbolization and core dumps
These are going to waste a lot of time and produce clutter when we're
bulk introducing crashes. Add a flag to disable this behavior in case
this matters to a reproducer.
Added:
llvm/test/tools/llvm-reduce/Inputs/test-crash-vars.py
llvm/test/tools/llvm-reduce/disable-crash-reports.test
Modified:
llvm/tools/llvm-reduce/llvm-reduce.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-reduce/Inputs/test-crash-vars.py b/llvm/test/tools/llvm-reduce/Inputs/test-crash-vars.py
new file mode 100755
index 0000000000000..2d239a6e46343
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/Inputs/test-crash-vars.py
@@ -0,0 +1,9 @@
+import os
+import sys
+
+disable_crash_report = os.getenv("LLVM_DISABLE_CRASH_REPORT")
+disable_symbolization = os.getenv("LLVM_DISABLE_SYMBOLIZATION")
+
+# Test that this is an explicitly set true value. If we preserve the
+# debug environment a pre-set explicit 0 should work.
+sys.exit(disable_crash_report != "1" or disable_symbolization != "1")
diff --git a/llvm/test/tools/llvm-reduce/disable-crash-reports.test b/llvm/test/tools/llvm-reduce/disable-crash-reports.test
new file mode 100644
index 0000000000000..af0c73a239b7a
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/disable-crash-reports.test
@@ -0,0 +1,12 @@
+# RUN: llvm-reduce --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=INTERESTING %s
+
+# RUN: LLVM_DISABLE_CRASH_REPORT=0 llvm-reduce --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=INTERESTING %s
+
+# RUN: not llvm-reduce --preserve-debug-environment --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=NOTINTERESTING %s
+
+# RUN: LLVM_DISABLE_CRASH_REPORT=0 not llvm-reduce --preserve-debug-environment --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=NOTINTERESTING %s
+
+# RUN: LLVM_DISABLE_CRASH_REPORT=1 LLVM_DISABLE_SYMBOLIZATION=1 llvm-reduce --preserve-debug-environment --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=INTERESTING %s
+
+INTERESTING: Done reducing! Reduced testcase:
+NOTINTERESTING: Input isn't interesting! Verify interesting-ness test
diff --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp
index 07b54034f5c45..3be603da3487c 100644
--- a/llvm/tools/llvm-reduce/llvm-reduce.cpp
+++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp
@@ -18,14 +18,18 @@
#include "ReducerWorkItem.h"
#include "TestRunner.h"
#include "llvm/CodeGen/CommandFlags.h"
-
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <system_error>
#include <vector>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
using namespace llvm;
cl::OptionCategory LLVMReduceOptions("llvm-reduce options");
@@ -35,6 +39,12 @@ static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden,
static cl::opt<bool> Version("v", cl::desc("Alias for -version"), cl::Hidden,
cl::cat(LLVMReduceOptions));
+static cl::opt<bool> PreserveDebugEnvironment(
+ "preserve-debug-environment",
+ cl::desc("Don't disable features used for crash "
+ "debugging (crash reports, llvm-symbolizer and core dumps)"),
+ cl::cat(LLVMReduceOptions));
+
static cl::opt<bool>
PrintDeltaPasses("print-delta-passes",
cl::desc("Print list of delta passes, passable to "
@@ -93,6 +103,23 @@ static codegen::RegisterCodeGenFlags CGF;
bool isReduced(ReducerWorkItem &M, const TestRunner &Test);
+/// Turn off crash debugging features
+///
+/// Crash is expected, so disable crash reports and symbolization to reduce
+/// output clutter and avoid potentially slow symbolization.
+static void disableEnvironmentDebugFeatures() {
+ sys::Process::PreventCoreFiles();
+
+ // TODO: Copied from not. Should have a wrapper around setenv.
+#ifdef _WIN32
+ SetEnvironmentVariableA("LLVM_DISABLE_CRASH_REPORT", "1");
+ SetEnvironmentVariableA("LLVM_DISABLE_SYMBOLIZATION", "1");
+#else
+ setenv("LLVM_DISABLE_CRASH_REPORT", "1", /*overwrite=*/1);
+ setenv("LLVM_DISABLE_SYMBOLIZATION", "1", /*overwrite=*/1);
+#endif
+}
+
static std::pair<StringRef, bool> determineOutputType(bool IsMIR,
bool InputIsBitcode) {
bool OutputBitcode = ForceOutputBitcode || InputIsBitcode;
@@ -146,6 +173,9 @@ int main(int Argc, char **Argv) {
return 0;
}
+ if (!PreserveDebugEnvironment)
+ disableEnvironmentDebugFeatures();
+
LLVMContext Context;
std::unique_ptr<TargetMachine> TM;
More information about the llvm-commits
mailing list