Author: Jonas Devlieghere Date: 2020-01-15T19:14:28-08:00 New Revision: b54a50f52e9427f250c192a8618b881732e5d7a4
URL: https://github.com/llvm/llvm-project/commit/b54a50f52e9427f250c192a8618b881732e5d7a4 DIFF: https://github.com/llvm/llvm-project/commit/b54a50f52e9427f250c192a8618b881732e5d7a4.diff LOG: [lldb/Reproducers] Extract function for reading environment override (NFC) Create a helper function for reading reproducer overrides from environment variables. Added: Modified: lldb/source/Utility/Reproducer.cpp Removed: ################################################################################ diff --git a/lldb/source/Utility/Reproducer.cpp b/lldb/source/Utility/Reproducer.cpp index b11e1a577ed2..e243d784d185 100644 --- a/lldb/source/Utility/Reproducer.cpp +++ b/lldb/source/Utility/Reproducer.cpp @@ -18,6 +18,15 @@ using namespace lldb_private::repro; using namespace llvm; using namespace llvm::yaml; +static llvm::Optional<bool> GetEnv(const char *var) { + std::string val = llvm::StringRef(getenv(var)).lower(); + if (val == "0" || val == "off") + return false; + if (val == "1" || val == "on") + return true; + return {}; +} + Reproducer &Reproducer::Instance() { return *InstanceImpl(); } llvm::Error Reproducer::Initialize(ReproducerMode mode, @@ -27,12 +36,12 @@ llvm::Error Reproducer::Initialize(ReproducerMode mode, // The environment can override the capture mode. if (mode != ReproducerMode::Replay) { - std::string env = - llvm::StringRef(getenv("LLDB_CAPTURE_REPRODUCER")).lower(); - if (env == "0" || env == "off") - mode = ReproducerMode::Off; - else if (env == "1" || env == "on") - mode = ReproducerMode::Capture; + if (llvm::Optional<bool> override = GetEnv("LLDB_CAPTURE_REPRODUCER")) { + if (*override) + mode = ReproducerMode::Capture; + else + mode = ReproducerMode::Off; + } } switch (mode) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits