[Lldb-commits] [lldb] df90a15 - [lldb] Clear all settings during a test's setUp

Tatyana Krasnukha via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 12 06:43:18 PDT 2020


Author: Tatyana Krasnukha
Date: 2020-03-12T16:30:26+03:00
New Revision: df90a15b1ac938559a8c3af12126559c1e1e9558

URL: https://github.com/llvm/llvm-project/commit/df90a15b1ac938559a8c3af12126559c1e1e9558
DIFF: https://github.com/llvm/llvm-project/commit/df90a15b1ac938559a8c3af12126559c1e1e9558.diff

LOG: [lldb] Clear all settings during a test's setUp

Global properties are shared between debugger instances and
if a test doesn't clear changes in settings it made,
this leads to side effects in other tests.

Differential Revision: https://reviews.llvm.org/D75537

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/lldbtest.py
    lldb/source/Commands/CommandObjectSettings.cpp
    lldb/source/Commands/Options.td
    lldb/test/API/commands/settings/TestSettings.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index a9d6e50ce01f..cd48747c3557 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -687,6 +687,9 @@ def getSourcePath(self, name):
     @classmethod
     def setUpCommands(cls):
         commands = [
+            # First of all, clear all settings to have clean state of global properties.
+            "settings clear -all",
+
             # Disable Spotlight lookup. The testsuite creates
             # 
diff erent binaries with the same UUID, because they only
             # 
diff er in the debug info, which is not being hashed.

diff  --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp
index 4d64ae428bad..cc1080c8cc0c 100644
--- a/lldb/source/Commands/CommandObjectSettings.cpp
+++ b/lldb/source/Commands/CommandObjectSettings.cpp
@@ -1043,13 +1043,16 @@ class CommandObjectSettingsAppend : public CommandObjectRaw {
 };
 
 // CommandObjectSettingsClear
+#define LLDB_OPTIONS_settings_clear
+#include "CommandOptions.inc"
 
 class CommandObjectSettingsClear : public CommandObjectParsed {
 public:
   CommandObjectSettingsClear(CommandInterpreter &interpreter)
       : CommandObjectParsed(
             interpreter, "settings clear",
-            "Clear a debugger setting array, dictionary, or string.", nullptr) {
+            "Clear a debugger setting array, dictionary, or string. "
+            "If '-a' option is specified, it clears all settings.", nullptr) {
     CommandArgumentEntry arg;
     CommandArgumentData var_name_arg;
 
@@ -1077,11 +1080,53 @@ class CommandObjectSettingsClear : public CommandObjectParsed {
           request, nullptr);
   }
 
+   Options *GetOptions() override { return &m_options; }
+
+  class CommandOptions : public Options {
+  public:
+    CommandOptions() = default;
+
+    ~CommandOptions() override = default;
+
+    Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+                          ExecutionContext *execution_context) override {
+      const int short_option = m_getopt_table[option_idx].val;
+      switch (short_option) {
+      case 'a':
+        m_clear_all = true;
+        break;
+      default:
+        llvm_unreachable("Unimplemented option");
+      }
+      return Status();
+    }
+
+    void OptionParsingStarting(ExecutionContext *execution_context) override {
+      m_clear_all = false;
+    }
+
+    llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+      return llvm::makeArrayRef(g_settings_clear_options);
+    }
+
+    bool m_clear_all = false;
+  };
+
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
     const size_t argc = command.GetArgumentCount();
 
+    if (m_options.m_clear_all) {
+      if (argc != 0) {
+        result.AppendError("'settings clear --all' doesn't take any arguments");
+        result.SetStatus(eReturnStatusFailed);
+        return false;
+      }
+      GetDebugger().GetValueProperties()->Clear();
+      return result.Succeeded();
+    }
+
     if (argc != 1) {
       result.AppendError("'settings clear' takes exactly one argument");
       result.SetStatus(eReturnStatusFailed);
@@ -1106,6 +1151,9 @@ class CommandObjectSettingsClear : public CommandObjectParsed {
 
     return result.Succeeded();
   }
+
+  private:
+    CommandOptions m_options;
 };
 
 // CommandObjectMultiwordSettings

diff  --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index 1456630c892f..fa8f5224cf53 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -39,6 +39,11 @@ let Command = "settings read" in {
     Desc<"The file from which to read the settings.">;
 }
 
+let Command = "settings clear" in {
+  def setclear_all : Option<"all", "a">,
+    Desc<"Clear all settings.">;
+}
+
 let Command = "breakpoint list" in {
   // FIXME: We need to add an "internal" command, and then add this sort of
   // thing to it. But I need to see it for now, and don't want to wait.

diff  --git a/lldb/test/API/commands/settings/TestSettings.py b/lldb/test/API/commands/settings/TestSettings.py
index 571ada823864..ffb194fda808 100644
--- a/lldb/test/API/commands/settings/TestSettings.py
+++ b/lldb/test/API/commands/settings/TestSettings.py
@@ -520,6 +520,32 @@ def test_settings_remove_empty_arg(self):
         self.expect("settings remove ''", error=True,
                     substrs=["'settings remove' command requires a valid variable name"])
 
+    def test_settings_clear_all(self):
+        # Change a dictionary.
+        self.runCmd("settings set target.env-vars a=1 b=2 c=3")
+        # Change an array.
+        self.runCmd("settings set target.run-args a1 b2 c3")
+        # Change a single boolean value.
+        self.runCmd("settings set auto-confirm true")
+        # Change a single integer value.
+        self.runCmd("settings set tab-size 2")
+
+        # Clear everything.
+        self.runCmd("settings clear --all")
+
+        # Check that settings have their default values after clearing.
+        self.expect("settings show target.env-vars", patterns=['^target.env-vars \(dictionary of strings\) =\s*$'])
+        self.expect("settings show target.run-args", patterns=['^target.run-args \(arguments\) =\s*$'])
+        self.expect("settings show auto-confirm", substrs=["false"])
+        self.expect("settings show tab-size", substrs=["4"])
+
+        # Check that the command fails if we combine '--all' option with any arguments.
+        self.expect(
+            "settings clear --all auto-confirm",
+            COMMAND_FAILED_AS_EXPECTED,
+            error=True,
+            substrs=["'settings clear --all' doesn't take any arguments"])
+
     def test_all_settings_exist(self):
         self.expect("settings show",
                     substrs=["auto-confirm",


        


More information about the lldb-commits mailing list