Skip to content

Commit dfe9a79

Browse files
committed
[lldb/Reproducers] Override capture with LLDB_CAPTURE_REPRODUCER env var
Make it possible to override reproducer capture with the LLDB_CAPTURE_REPRODUCER environment variable. The goal of this change is twofold. (1) I want to be able to enable capturing reproducers during regular test runs, both locally and on the bots. To do so I need a way to force capture. I cannot do this through the Python API, because reproducer capture must be enabled *before* the debugger initialized, which happens automatically when doing `import lldb`. (2) I want to provide an escape hatch for when reproducers are enabled by default. Downstream we have reproducer capture enabled by default in the driver. This patch solves both problems by overriding the reproducer mode based on the environment variable. Acceptable values are 0/1 and ON/OFF.
1 parent f65267e commit dfe9a79

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lldb/source/Utility/Reproducer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ llvm::Error Reproducer::Initialize(ReproducerMode mode,
2525
lldbassert(!InstanceImpl() && "Already initialized.");
2626
InstanceImpl().emplace();
2727

28+
// The environment can override the capture mode.
29+
if (mode != ReproducerMode::Replay) {
30+
std::string env =
31+
llvm::StringRef(getenv("LLDB_CAPTURE_REPRODUCER")).lower();
32+
if (env == "0" || env == "off")
33+
mode = ReproducerMode::Off;
34+
else if (env == "1" || env == "on")
35+
mode = ReproducerMode::Capture;
36+
}
37+
2838
switch (mode) {
2939
case ReproducerMode::Capture: {
3040
if (!root) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# UNSUPPORTED: system-windows
2+
# This tests the LLDB_CAPTURE_REPRODUCER override.
3+
4+
# RUN: %lldb -b -o 'reproducer status' --capture --capture-path %t.repro /bin/ls | FileCheck %s --check-prefix CAPTURE
5+
# RUN: %lldb -b -o 'reproducer status' --capture | FileCheck %s --check-prefix CAPTURE
6+
7+
# RUN: LLDB_CAPTURE_REPRODUCER=1 %lldb -b -o 'reproducer status' | FileCheck %s --check-prefix CAPTURE
8+
# RUN: LLDB_CAPTURE_REPRODUCER=ON %lldb -b -o 'reproducer status' | FileCheck %s --check-prefix CAPTURE
9+
# RUN: LLDB_CAPTURE_REPRODUCER=on %lldb -b -o 'reproducer status' | FileCheck %s --check-prefix CAPTURE
10+
11+
# RUN: LLDB_CAPTURE_REPRODUCER=0 %lldb -b -o 'reproducer status' --capture --capture-path %t.repro | FileCheck %s --check-prefix OFF
12+
# RUN: LLDB_CAPTURE_REPRODUCER=0 %lldb -b -o 'reproducer status' --capture | FileCheck %s --check-prefix OFF
13+
# RUN: LLDB_CAPTURE_REPRODUCER=OFF %lldb -b -o 'reproducer status' --capture --capture-path %t.repro | FileCheck %s --check-prefix OFF
14+
# RUN: LLDB_CAPTURE_REPRODUCER=off %lldb -b -o 'reproducer status' --capture | FileCheck %s --check-prefix OFF
15+
16+
# RUN: LLDB_CAPTURE_REPRODUCER=bogus %lldb -b -o 'reproducer status' --capture | FileCheck %s --check-prefix CAPTURE
17+
# RUN: LLDB_CAPTURE_REPRODUCER=bogus %lldb -b -o 'reproducer status' | FileCheck %s --check-prefix OFF
18+
19+
# CAPTURE: Reproducer is in capture mode.
20+
# OFF: Reproducer is off.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Enable crash reports for the reproducer tests.
22
del config.environment['LLVM_DISABLE_CRASH_REPORT']
3+
del config.environment['LLDB_CAPTURE_REPRODUCER']

0 commit comments

Comments
 (0)