[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 30 15:11:56 PDT 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff a41b149f481e2bcba24e81f208a1938247f040e0 7bb11d65e11329cdde801d04a1900a45b6cd6d19 -- lldb/include/lldb/Interpreter/CommandObject.h lldb/include/lldb/Interpreter/ScriptInterpreter.h lldb/source/Commands/CommandObjectCommands.cpp lldb/source/Interpreter/CommandObject.cpp lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h
index c2f17f374fe5..c8084d9bbcf6 100644
--- a/lldb/include/lldb/Interpreter/CommandObject.h
+++ b/lldb/include/lldb/Interpreter/CommandObject.h
@@ -226,8 +226,8 @@ public:
 
   static bool IsPairType(ArgumentRepetitionType arg_repeat_type);
 
-  static std::optional<ArgumentRepetitionType> 
-    ArgRepetitionFromString(llvm::StringRef string);
+  static std::optional<ArgumentRepetitionType>
+  ArgRepetitionFromString(llvm::StringRef string);
 
   bool ParseOptions(Args &args, CommandReturnObject &result);
 
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 4dce5f40328d..2a7dcf73a429 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -476,11 +476,12 @@ public:
     return false;
   }
 
-  virtual bool RunScriptBasedParsedCommand(
-      StructuredData::GenericSP impl_obj_sp, Args& args,
-      ScriptedCommandSynchronicity synchronicity,
-      lldb_private::CommandReturnObject &cmd_retobj, Status &error,
-      const lldb_private::ExecutionContext &exe_ctx) {
+  virtual bool
+  RunScriptBasedParsedCommand(StructuredData::GenericSP impl_obj_sp, Args &args,
+                              ScriptedCommandSynchronicity synchronicity,
+                              lldb_private::CommandReturnObject &cmd_retobj,
+                              Status &error,
+                              const lldb_private::ExecutionContext &exe_ctx) {
     return false;
   }
 
@@ -528,7 +529,7 @@ public:
     dest.clear();
     return false;
   }
-  
+
   virtual StructuredData::ObjectSP
   GetOptionsForCommandObject(StructuredData::GenericSP cmd_obj_sp) {
     return {};
@@ -538,15 +539,15 @@ public:
   GetArgumentsForCommandObject(StructuredData::GenericSP cmd_obj_sp) {
     return {};
   }
-  
+
   virtual bool SetOptionValueForCommandObject(
-      StructuredData::GenericSP cmd_obj_sp, ExecutionContext *exe_ctx, 
+      StructuredData::GenericSP cmd_obj_sp, ExecutionContext *exe_ctx,
       llvm::StringRef long_option, llvm::StringRef value) {
     return false;
   }
 
-  virtual void OptionParsingStartedForCommandObject(
-      StructuredData::GenericSP cmd_obj_sp) {
+  virtual void
+  OptionParsingStartedForCommandObject(StructuredData::GenericSP cmd_obj_sp) {
     return;
   }
 
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index 1e7227767eb9..96d7455499f3 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -1258,7 +1258,6 @@ private:
   CompletionType m_completion_type = eNoCompletion;
 };
 
-
 /// This command implements a lldb parsed scripted command.  The command
 /// provides a definition of the options and arguments, and a option value
 /// setting callback, and then the command's execution function gets passed
@@ -1270,22 +1269,22 @@ private:
 /// So I've also added a base class in Python that provides a table-driven
 /// way of defining the options and arguments, which automatically fills the
 /// option values, making them available as properties in Python.
-/// 
+///
 class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
-private: 
+private:
   class CommandOptions : public Options {
   public:
-    CommandOptions(CommandInterpreter &interpreter, 
-        StructuredData::GenericSP cmd_obj_sp) : m_interpreter(interpreter), 
-            m_cmd_obj_sp(cmd_obj_sp) {}
+    CommandOptions(CommandInterpreter &interpreter,
+                   StructuredData::GenericSP cmd_obj_sp)
+        : m_interpreter(interpreter), m_cmd_obj_sp(cmd_obj_sp) {}
 
     ~CommandOptions() override = default;
 
     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
                           ExecutionContext *execution_context) override {
       Status error;
-      ScriptInterpreter *scripter = 
-        m_interpreter.GetDebugger().GetScriptInterpreter();
+      ScriptInterpreter *scripter =
+          m_interpreter.GetDebugger().GetScriptInterpreter();
       if (!scripter) {
         error.SetErrorString("No script interpreter for SetOptionValue.");
         return error;
@@ -1302,10 +1301,10 @@ private:
       // Pass the long option, since you aren't actually required to have a
       // short_option, and for those options the index or short option character
       // aren't meaningful on the python side.
-      const char * long_option = 
-        m_options_definition_up.get()[option_idx].long_option;
-      bool success = scripter->SetOptionValueForCommandObject(m_cmd_obj_sp, 
-        execution_context, long_option, option_arg);
+      const char *long_option =
+          m_options_definition_up.get()[option_idx].long_option;
+      bool success = scripter->SetOptionValueForCommandObject(
+          m_cmd_obj_sp, execution_context, long_option, option_arg);
       if (!success)
         error.SetErrorStringWithFormatv("Error setting option: {0} to {1}",
                                         long_option, option_arg);
@@ -1313,8 +1312,8 @@ private:
     }
 
     void OptionParsingStarting(ExecutionContext *execution_context) override {
-      ScriptInterpreter *scripter = 
-        m_interpreter.GetDebugger().GetScriptInterpreter();
+      ScriptInterpreter *scripter =
+          m_interpreter.GetDebugger().GetScriptInterpreter();
       if (!scripter) {
         return;
       }
@@ -1329,9 +1328,10 @@ private:
         return {};
       return llvm::ArrayRef(m_options_definition_up.get(), m_num_options);
     }
-    
-    static bool ParseUsageMaskFromArray(StructuredData::ObjectSP obj_sp, 
-        size_t counter, uint32_t &usage_mask, Status &error) {
+
+    static bool ParseUsageMaskFromArray(StructuredData::ObjectSP obj_sp,
+                                        size_t counter, uint32_t &usage_mask,
+                                        Status &error) {
       // If the usage entry is not provided, we use LLDB_OPT_SET_ALL.
       // If the usage mask is a UINT, the option belongs to that group.
       // If the usage mask is a vector of UINT's, the option belongs to all the
@@ -1342,10 +1342,10 @@ private:
         usage_mask = LLDB_OPT_SET_ALL;
         return true;
       }
-      
+
       usage_mask = 0;
-      
-      StructuredData::UnsignedInteger *uint_val = 
+
+      StructuredData::UnsignedInteger *uint_val =
           obj_sp->GetAsUnsignedInteger();
       if (uint_val) {
         // If this is an integer, then this specifies a single group:
@@ -1367,9 +1367,8 @@ private:
       }
       // This is the array ForEach for accumulating a group usage mask from
       // an array of string descriptions of groups.
-      auto groups_accumulator 
-          = [counter, &usage_mask, &error] 
-            (StructuredData::Object *obj) -> bool {
+      auto groups_accumulator = [counter, &usage_mask,
+                                 &error](StructuredData::Object *obj) -> bool {
         StructuredData::UnsignedInteger *int_val = obj->GetAsUnsignedInteger();
         if (int_val) {
           uint32_t value = int_val->GetValue();
@@ -1384,34 +1383,38 @@ private:
         StructuredData::Array *arr_val = obj->GetAsArray();
         if (!arr_val) {
           error.SetErrorStringWithFormatv(
-              "Group element not an int or array of integers for element {0}", 
+              "Group element not an int or array of integers for element {0}",
               counter);
-          return false; 
+          return false;
         }
         size_t num_range_elem = arr_val->GetSize();
         if (num_range_elem != 2) {
           error.SetErrorStringWithFormatv(
-              "Subranges of a group not a start and a stop for element {0}", 
+              "Subranges of a group not a start and a stop for element {0}",
               counter);
-          return false; 
+          return false;
         }
         int_val = arr_val->GetItemAtIndex(0)->GetAsUnsignedInteger();
         if (!int_val) {
-          error.SetErrorStringWithFormatv("Start element of a subrange of a "
-              "group not unsigned int for element {0}", counter);
-          return false; 
+          error.SetErrorStringWithFormatv(
+              "Start element of a subrange of a "
+              "group not unsigned int for element {0}",
+              counter);
+          return false;
         }
         uint32_t start = int_val->GetValue();
         int_val = arr_val->GetItemAtIndex(1)->GetAsUnsignedInteger();
         if (!int_val) {
           error.SetErrorStringWithFormatv("End element of a subrange of a group"
-              " not unsigned int for element {0}", counter);
-          return false; 
+                                          " not unsigned int for element {0}",
+                                          counter);
+          return false;
         }
         uint32_t end = int_val->GetValue();
         if (start == 0 || end == 0 || start > end) {
           error.SetErrorStringWithFormatv("Invalid subrange of a group: {0} - "
-              "{1} for element {2}", start, end, counter);
+                                          "{1} for element {2}",
+                                          start, end, counter);
           return false;
         }
         for (uint32_t i = start; i <= end; i++) {
@@ -1421,8 +1424,7 @@ private:
       };
       return array_val->ForEach(groups_accumulator);
     }
-    
-    
+
     Status SetOptionsFromArray(StructuredData::Array &options, Status &error) {
       m_num_options = options.GetSize();
       m_options_definition_up.reset(new OptionDefinition[m_num_options]);
@@ -1431,35 +1433,35 @@ private:
       m_usage_container.reserve(m_num_options);
       m_enum_storage.reserve(m_num_options);
       m_enum_vector.reserve(m_num_options);
-      
+
       size_t counter = 0;
       size_t short_opt_counter = 0;
       // This is the Array::ForEach function for adding option elements:
-      auto add_element = [this, &error, &counter, &short_opt_counter] 
-          (StructuredData::Object *object) -> bool {
+      auto add_element = [this, &error, &counter, &short_opt_counter](
+                             StructuredData::Object *object) -> bool {
         StructuredData::Dictionary *opt_dict = object->GetAsDictionary();
         if (!opt_dict) {
           error.SetErrorString("Object in options array is not a dictionary");
           return false;
         }
         OptionDefinition &option_def = m_options_definition_up.get()[counter];
-        
+
         // We aren't exposing the validator yet, set it to null
         option_def.validator = nullptr;
         // We don't require usage masks, so set it to one group by default:
         option_def.usage_mask = 1;
-        
+
         // Now set the fields of the OptionDefinition Array from the dictionary:
         //
         // Note that I don't check for unknown fields in the option dictionaries
         // so a scriptor can add extra elements that are helpful when they go to
         // do "set_option_value"
-        
+
         // Usage Mask:
         StructuredData::ObjectSP obj_sp = opt_dict->GetValueForKey("groups");
         if (obj_sp) {
-          ParseUsageMaskFromArray(obj_sp, counter, option_def.usage_mask, 
-              error);
+          ParseUsageMaskFromArray(obj_sp, counter, option_def.usage_mask,
+                                  error);
           if (error.Fail())
             return false;
         }
@@ -1471,170 +1473,183 @@ private:
           StructuredData::Boolean *boolean_val = obj_sp->GetAsBoolean();
           if (!boolean_val) {
             error.SetErrorStringWithFormatv("'required' field is not a boolean "
-                "for option {0}", counter);
+                                            "for option {0}",
+                                            counter);
             return false;
-          } 
-          option_def.required = boolean_val->GetValue();      
+          }
+          option_def.required = boolean_val->GetValue();
         }
-        
+
         // Short Option:
         int short_option;
         obj_sp = opt_dict->GetValueForKey("short_option");
         if (obj_sp) {
-          // The value is a string, so pull the 
+          // The value is a string, so pull the
           llvm::StringRef short_str = obj_sp->GetStringValue();
           if (short_str.empty()) {
             error.SetErrorStringWithFormatv("short_option field empty for "
-                "option {0}", counter);
+                                            "option {0}",
+                                            counter);
             return false;
           } else if (short_str.size() != 1) {
             error.SetErrorStringWithFormatv("short_option field has extra "
-                "characters for option {0}", counter);
+                                            "characters for option {0}",
+                                            counter);
             return false;
           }
-          short_option = (int) short_str[0];
+          short_option = (int)short_str[0];
         } else {
-          // If the short option is not provided, then we need a unique value 
+          // If the short option is not provided, then we need a unique value
           // less than the lowest printable ASCII character.
           short_option = short_opt_counter++;
         }
         option_def.short_option = short_option;
-        
+
         // Long Option:
         std::string long_option;
         obj_sp = opt_dict->GetValueForKey("long_option");
         if (!obj_sp) {
           error.SetErrorStringWithFormatv("required long_option missing from "
-          "option {0}", counter);
+                                          "option {0}",
+                                          counter);
           return false;
         }
         llvm::StringRef long_stref = obj_sp->GetStringValue();
         if (long_stref.empty()) {
-          error.SetErrorStringWithFormatv("empty long_option for option {0}", 
-              counter);
+          error.SetErrorStringWithFormatv("empty long_option for option {0}",
+                                          counter);
           return false;
         }
         auto inserted = g_string_storer.insert(long_stref.str());
         option_def.long_option = ((*(inserted.first)).data());
-        
+
         // Value Type:
         obj_sp = opt_dict->GetValueForKey("value_type");
         if (obj_sp) {
-          StructuredData::UnsignedInteger *uint_val 
-              = obj_sp->GetAsUnsignedInteger();
+          StructuredData::UnsignedInteger *uint_val =
+              obj_sp->GetAsUnsignedInteger();
           if (!uint_val) {
             error.SetErrorStringWithFormatv("Value type must be an unsigned "
-                "integer");
+                                            "integer");
             return false;
           }
           uint64_t val_type = uint_val->GetValue();
           if (val_type >= eArgTypeLastArg) {
             error.SetErrorStringWithFormatv("Value type {0} beyond the "
-                "CommandArgumentType bounds", val_type);
+                                            "CommandArgumentType bounds",
+                                            val_type);
             return false;
           }
-          option_def.argument_type = (CommandArgumentType) val_type;
+          option_def.argument_type = (CommandArgumentType)val_type;
           option_def.option_has_arg = true;
         } else {
           option_def.argument_type = eArgTypeNone;
           option_def.option_has_arg = false;
         }
-        
+
         // Completion Type:
         obj_sp = opt_dict->GetValueForKey("completion_type");
         if (obj_sp) {
-          StructuredData::UnsignedInteger *uint_val = obj_sp->GetAsUnsignedInteger();
+          StructuredData::UnsignedInteger *uint_val =
+              obj_sp->GetAsUnsignedInteger();
           if (!uint_val) {
             error.SetErrorStringWithFormatv("Completion type must be an "
-                "unsigned integer for option {0}", counter);
+                                            "unsigned integer for option {0}",
+                                            counter);
             return false;
           }
           uint64_t completion_type = uint_val->GetValue();
           if (completion_type > eCustomCompletion) {
             error.SetErrorStringWithFormatv("Completion type for option {0} "
-                "beyond the CompletionType bounds", completion_type);
+                                            "beyond the CompletionType bounds",
+                                            completion_type);
             return false;
           }
-          option_def.completion_type = (CommandArgumentType) completion_type;
+          option_def.completion_type = (CommandArgumentType)completion_type;
         } else
           option_def.completion_type = eNoCompletion;
-        
+
         // Usage Text:
         std::string usage_text;
         obj_sp = opt_dict->GetValueForKey("usage");
         if (!obj_sp) {
           error.SetErrorStringWithFormatv("required usage missing from option "
-              "{0}", counter);
+                                          "{0}",
+                                          counter);
           return false;
         }
         long_stref = obj_sp->GetStringValue();
         if (long_stref.empty()) {
-          error.SetErrorStringWithFormatv("empty usage text for option {0}", 
-              counter);
+          error.SetErrorStringWithFormatv("empty usage text for option {0}",
+                                          counter);
           return false;
         }
         m_usage_container[counter] = long_stref.str().c_str();
         option_def.usage_text = m_usage_container[counter].data();
 
         // Enum Values:
-        
+
         obj_sp = opt_dict->GetValueForKey("enum_values");
         if (obj_sp) {
           StructuredData::Array *array = obj_sp->GetAsArray();
           if (!array) {
             error.SetErrorStringWithFormatv("enum values must be an array for "
-                "option {0}", counter);
+                                            "option {0}",
+                                            counter);
             return false;
           }
           size_t num_elem = array->GetSize();
           size_t enum_ctr = 0;
           m_enum_storage[counter] = std::vector<EnumValueStorer>(num_elem);
           std::vector<EnumValueStorer> &curr_elem = m_enum_storage[counter];
-          
+
           // This is the Array::ForEach function for adding enum elements:
           // Since there are only two fields to specify the enum, use a simple
           // two element array with value first, usage second.
           // counter is only used for reporting so I pass it by value here.
-          auto add_enum = [&enum_ctr, &curr_elem, counter, &error] 
-              (StructuredData::Object *object) -> bool {
+          auto add_enum = [&enum_ctr, &curr_elem, counter,
+                           &error](StructuredData::Object *object) -> bool {
             StructuredData::Array *enum_arr = object->GetAsArray();
             if (!enum_arr) {
               error.SetErrorStringWithFormatv("Enum values for option {0} not "
-                  "an array", counter);
+                                              "an array",
+                                              counter);
               return false;
             }
             size_t num_enum_elements = enum_arr->GetSize();
             if (num_enum_elements != 2) {
               error.SetErrorStringWithFormatv("Wrong number of elements: {0} "
-                  "for enum {1} in option {2}",
-                  num_enum_elements, enum_ctr, counter);
+                                              "for enum {1} in option {2}",
+                                              num_enum_elements, enum_ctr,
+                                              counter);
               return false;
             }
             // Enum Value:
             StructuredData::ObjectSP obj_sp = enum_arr->GetItemAtIndex(0);
             llvm::StringRef val_stref = obj_sp->GetStringValue();
             std::string value_cstr_str = val_stref.str().c_str();
-            
+
             // Enum Usage:
             obj_sp = enum_arr->GetItemAtIndex(1);
             if (!obj_sp) {
               error.SetErrorStringWithFormatv("No usage for enum {0} in option "
-                  "{1}",  enum_ctr, counter);
+                                              "{1}",
+                                              enum_ctr, counter);
               return false;
             }
             llvm::StringRef usage_stref = obj_sp->GetStringValue();
             std::string usage_cstr_str = usage_stref.str().c_str();
-            curr_elem[enum_ctr] = EnumValueStorer(value_cstr_str, 
-                usage_cstr_str, enum_ctr);
-            
+            curr_elem[enum_ctr] =
+                EnumValueStorer(value_cstr_str, usage_cstr_str, enum_ctr);
+
             enum_ctr++;
             return true;
           }; // end of add_enum
-          
+
           array->ForEach(add_enum);
           if (!error.Success())
             return false;
-          // We have to have a vector of elements to set in the options, make 
+          // We have to have a vector of elements to set in the options, make
           // that here:
           for (auto &elem : curr_elem)
             m_enum_vector[counter].emplace_back(elem.element);
@@ -1644,11 +1659,11 @@ private:
         counter++;
         return true;
       }; // end of add_element
-      
+
       options.ForEach(add_element);
       return error;
     }
-    
+
   private:
     struct EnumValueStorer {
       EnumValueStorer() {
@@ -1656,30 +1671,31 @@ private:
         element.usage = "usage not set";
         element.value = 0;
       }
-      
-      EnumValueStorer(std::string &in_str_val, std::string &in_usage, 
-          size_t in_value) : value(in_str_val), usage(in_usage) {
+
+      EnumValueStorer(std::string &in_str_val, std::string &in_usage,
+                      size_t in_value)
+          : value(in_str_val), usage(in_usage) {
         SetElement(in_value);
       }
-      
-      EnumValueStorer(const EnumValueStorer &in) : value(in.value), 
-          usage(in.usage) {
+
+      EnumValueStorer(const EnumValueStorer &in)
+          : value(in.value), usage(in.usage) {
         SetElement(in.element.value);
       }
-      
+
       EnumValueStorer &operator=(const EnumValueStorer &in) {
         value = in.value;
         usage = in.usage;
         SetElement(in.element.value);
         return *this;
       }
-      
+
       void SetElement(size_t in_value) {
         element.value = in_value;
         element.string_value = value.data();
-        element.usage = usage.data(); 
+        element.usage = usage.data();
       }
-      
+
       std::string value;
       std::string usage;
       OptionEnumValueElement element;
@@ -1690,10 +1706,10 @@ private:
     // commands, so those are stored in a global set: g_string_storer.
     // But the usages are much less likely to be reused, so those are stored in
     // a vector in the command instance.  It gets resized to the correct size
-    // and then filled with null-terminated strings in the std::string, so the 
+    // and then filled with null-terminated strings in the std::string, so the
     // are valid C-strings that won't move around.
     // The enum values and descriptions are treated similarly - these aren't
-    // all that common so it's not worth the effort to dedup them.  
+    // all that common so it's not worth the effort to dedup them.
     size_t m_num_options = 0;
     std::unique_ptr<OptionDefinition> m_options_definition_up;
     std::vector<std::vector<EnumValueStorer>> m_enum_storage;
@@ -1706,12 +1722,12 @@ private:
 
 public:
   CommandObjectScriptingObjectParsed(CommandInterpreter &interpreter,
-                               std::string name,
-                               StructuredData::GenericSP cmd_obj_sp,
-                               ScriptedCommandSynchronicity synch)
-      : CommandObjectParsed(interpreter, name.c_str()), 
-        m_cmd_obj_sp(cmd_obj_sp), m_synchro(synch), 
-        m_options(interpreter, cmd_obj_sp), m_fetched_help_short(false), 
+                                     std::string name,
+                                     StructuredData::GenericSP cmd_obj_sp,
+                                     ScriptedCommandSynchronicity synch)
+      : CommandObjectParsed(interpreter, name.c_str()),
+        m_cmd_obj_sp(cmd_obj_sp), m_synchro(synch),
+        m_options(interpreter, cmd_obj_sp), m_fetched_help_short(false),
         m_fetched_help_long(false) {
     StreamString stream;
     ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
@@ -1724,8 +1740,8 @@ public:
     GetFlags().Set(scripter->GetFlagsForCommandObject(cmd_obj_sp));
 
     // Now set up the options definitions from the options:
-    StructuredData::ObjectSP options_object_sp 
-        = scripter->GetOptionsForCommandObject(cmd_obj_sp);
+    StructuredData::ObjectSP options_object_sp =
+        scripter->GetOptionsForCommandObject(cmd_obj_sp);
     // It's okay not to have an options array.
     if (options_object_sp) {
       StructuredData::Array *options_array = options_object_sp->GetAsArray();
@@ -1742,49 +1758,51 @@ public:
     }
     // Then fetch the args.  Since the arguments can have usage masks you need
     // an array of arrays.
-    StructuredData::ObjectSP args_object_sp 
-      = scripter->GetArgumentsForCommandObject(cmd_obj_sp);
+    StructuredData::ObjectSP args_object_sp =
+        scripter->GetArgumentsForCommandObject(cmd_obj_sp);
     if (args_object_sp) {
-      StructuredData::Array *args_array = args_object_sp->GetAsArray();        
+      StructuredData::Array *args_array = args_object_sp->GetAsArray();
       if (!args_array) {
         m_args_error.SetErrorString("Argument specification is not an array");
         return;
       }
       size_t counter = 0;
-      
+
       // This is the Array::ForEach function that handles the
       // CommandArgumentEntry arrays one by one:
-      auto arg_array_adder = [this, &counter] (StructuredData::Object *object) 
-          -> bool {
+      auto arg_array_adder =
+          [this, &counter](StructuredData::Object *object) -> bool {
         // This is the Array::ForEach function to add argument entries:
         CommandArgumentEntry this_entry;
         size_t elem_counter = 0;
-        auto args_adder = [this, counter, &elem_counter, &this_entry] 
-            (StructuredData::Object *object) -> bool {
+        auto args_adder = [this, counter, &elem_counter, &this_entry](
+                              StructuredData::Object *object) -> bool {
           // The arguments definition has three fields, the argument type, the
-          // repeat and the usage mask. 
+          // repeat and the usage mask.
           CommandArgumentType arg_type = eArgTypeNone;
           ArgumentRepetitionType arg_repetition = eArgRepeatOptional;
           uint32_t arg_opt_set_association;
-          
-          auto report_error = [this, elem_counter, counter] 
-              (const char *err_txt) -> bool {
+
+          auto report_error = [this, elem_counter,
+                               counter](const char *err_txt) -> bool {
             m_args_error.SetErrorStringWithFormatv("Element {0} of arguments "
-                "list element {1}: %s.", elem_counter, counter, err_txt);
+                                                   "list element {1}: %s.",
+                                                   elem_counter, counter,
+                                                   err_txt);
             return false;
           };
-          
+
           StructuredData::Dictionary *arg_dict = object->GetAsDictionary();
           if (!arg_dict) {
             report_error("is not a dictionary.");
             return false;
           }
           // Argument Type:
-          StructuredData::ObjectSP obj_sp 
-              = arg_dict->GetValueForKey("arg_type");
+          StructuredData::ObjectSP obj_sp =
+              arg_dict->GetValueForKey("arg_type");
           if (obj_sp) {
-            StructuredData::UnsignedInteger *uint_val 
-                = obj_sp->GetAsUnsignedInteger();
+            StructuredData::UnsignedInteger *uint_val =
+                obj_sp->GetAsUnsignedInteger();
             if (!uint_val) {
               report_error("value type must be an unsigned integer");
               return false;
@@ -1794,7 +1812,7 @@ public:
               report_error("value type beyond ArgumentRepetitionType bounds");
               return false;
             }
-            arg_type = (CommandArgumentType) arg_type_int;
+            arg_type = (CommandArgumentType)arg_type_int;
           }
           // Repeat Value:
           obj_sp = arg_dict->GetValueForKey("repeat");
@@ -1811,29 +1829,31 @@ public:
               return false;
             }
             arg_repetition = *repeat;
-          } 
-          
+          }
+
           // Usage Mask:
           obj_sp = arg_dict->GetValueForKey("groups");
-          CommandOptions::ParseUsageMaskFromArray(obj_sp, counter, 
-              arg_opt_set_association, m_args_error);
-          this_entry.emplace_back(arg_type, arg_repetition, 
-              arg_opt_set_association);
+          CommandOptions::ParseUsageMaskFromArray(
+              obj_sp, counter, arg_opt_set_association, m_args_error);
+          this_entry.emplace_back(arg_type, arg_repetition,
+                                  arg_opt_set_association);
           elem_counter++;
           return true;
         };
         StructuredData::Array *args_array = object->GetAsArray();
         if (!args_array) {
           m_args_error.SetErrorStringWithFormatv("Argument definition element "
-              "{0} is not an array", counter);
+                                                 "{0} is not an array",
+                                                 counter);
         }
-        
+
         args_array->ForEach(args_adder);
         if (m_args_error.Fail())
           return false;
         if (this_entry.empty()) {
           m_args_error.SetErrorStringWithFormatv("Argument definition element "
-              "{0} is empty", counter);
+                                                 "{0} is empty",
+                                                 counter);
           return false;
         }
         m_arguments.push_back(this_entry);
@@ -1885,22 +1905,20 @@ public:
       SetHelpLong(docstring);
     return CommandObjectParsed::GetHelpLong();
   }
-  
-  Options *GetOptions() override { return &m_options; }
 
+  Options *GetOptions() override { return &m_options; }
 
 protected:
-  bool DoExecute(Args &args,
-                 CommandReturnObject &result) override {
+  bool DoExecute(Args &args, CommandReturnObject &result) override {
     ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
 
     Status error;
 
     result.SetStatus(eReturnStatusInvalid);
-    
+
     if (!scripter ||
-        !scripter->RunScriptBasedParsedCommand(m_cmd_obj_sp, args,
-                                         m_synchro, result, error, m_exe_ctx)) {
+        !scripter->RunScriptBasedParsedCommand(m_cmd_obj_sp, args, m_synchro,
+                                               result, error, m_exe_ctx)) {
       result.AppendError(error.AsCString());
     } else {
       // Don't change the status if the command already set it...
@@ -2317,15 +2335,16 @@ protected:
                                       "'{0}'", m_options.m_class_name);
         return false;
       }
-      
+
       if (m_options.m_parsed_command) {
         new_cmd_sp.reset(new CommandObjectScriptingObjectParsed(
             m_interpreter, m_cmd_name, cmd_obj_sp, m_synchronicity));
-        Status options_error 
-            = static_cast<CommandObjectScriptingObjectParsed *>(new_cmd_sp.get())->GetOptionsError();
+        Status options_error =
+            static_cast<CommandObjectScriptingObjectParsed *>(new_cmd_sp.get())
+                ->GetOptionsError();
         if (options_error.Fail()) {
           result.AppendErrorWithFormat("failed to parse option definitions: %s",
-                             options_error.AsCString());
+                                       options_error.AsCString());
           return false;
         }
       } else
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index 43b0b611a57c..0f03f3f71f4f 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -447,19 +447,30 @@ bool CommandObject::IsPairType(ArgumentRepetitionType arg_repeat_type) {
          (arg_repeat_type == eArgRepeatPairRangeOptional);
 }
 
-std::optional<ArgumentRepetitionType> 
+std::optional<ArgumentRepetitionType>
 CommandObject::ArgRepetitionFromString(llvm::StringRef string) {
-  if (string == "plain") return eArgRepeatPlain ;   
-  if (string ==  "optional") return eArgRepeatOptional;
-  if (string ==  "plus") return eArgRepeatPlus;
-  if (string ==  "star") return eArgRepeatStar; 
-  if (string ==  "range") return eArgRepeatRange;
-  if (string ==  "pair-plain") return eArgRepeatPairPlain;
-  if (string ==  "pair-optional") return eArgRepeatPairOptional;
-  if (string ==  "pair-plus") return eArgRepeatPairPlus;
-  if (string ==  "pair-star") return eArgRepeatPairStar;
-  if (string ==  "pair-range") return eArgRepeatPairRange;
-  if (string ==  "pair-range-optional") return eArgRepeatPairRangeOptional;
+  if (string == "plain")
+    return eArgRepeatPlain;
+  if (string == "optional")
+    return eArgRepeatOptional;
+  if (string == "plus")
+    return eArgRepeatPlus;
+  if (string == "star")
+    return eArgRepeatStar;
+  if (string == "range")
+    return eArgRepeatRange;
+  if (string == "pair-plain")
+    return eArgRepeatPairPlain;
+  if (string == "pair-optional")
+    return eArgRepeatPairOptional;
+  if (string == "pair-plus")
+    return eArgRepeatPairPlus;
+  if (string == "pair-star")
+    return eArgRepeatPairStar;
+  if (string == "pair-range")
+    return eArgRepeatPairRange;
+  if (string == "pair-range-optional")
+    return eArgRepeatPairRangeOptional;
   return {};
 }
 
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 460cd1209dc6..30bdc127ede9 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -194,8 +194,8 @@ template <typename T, char F> struct PassthroughFormat {
 };
 
 template <> struct PythonFormat<char *> : PassthroughFormat<char *, 's'> {};
-template <> struct PythonFormat<const char *> : 
-    PassthroughFormat<const char *, 's'> {};
+template <>
+struct PythonFormat<const char *> : PassthroughFormat<const char *, 's'> {};
 template <> struct PythonFormat<char> : PassthroughFormat<char, 'b'> {};
 template <>
 struct PythonFormat<unsigned char> : PassthroughFormat<unsigned char, 'B'> {};
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
index c1a11b9134d6..781061c0563b 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
@@ -213,12 +213,11 @@ public:
                                   lldb::DebuggerSP debugger, const char *args,
                                   lldb_private::CommandReturnObject &cmd_retobj,
                                   lldb::ExecutionContextRefSP exe_ctx_ref_sp);
-  static bool
-  LLDBSwigPythonCallParsedCommandObject(PyObject *implementor,
-                                  lldb::DebuggerSP debugger,  
-                                  StructuredDataImpl &args_impl,
-                                  lldb_private::CommandReturnObject &cmd_retobj,
-                                  lldb::ExecutionContextRefSP exe_ctx_ref_sp);
+  static bool LLDBSwigPythonCallParsedCommandObject(
+      PyObject *implementor, lldb::DebuggerSP debugger,
+      StructuredDataImpl &args_impl,
+      lldb_private::CommandReturnObject &cmd_retobj,
+      lldb::ExecutionContextRefSP exe_ctx_ref_sp);
 
   static bool LLDBSwigPythonCallModuleInit(const char *python_module_name,
                                            const char *session_dictionary_name,
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index ae888f45446e..feea0879bb1e 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -2791,7 +2791,7 @@ bool ScriptInterpreterPythonImpl::RunScriptBasedParsedCommand(
       args_arr_sp->AddStringItem(entry.ref());
     }
     StructuredDataImpl args_impl(args_arr_sp);
-    
+
     ret_val = SWIGBridge::LLDBSwigPythonCallParsedCommandObject(
         static_cast<PyObject *>(impl_obj_sp->GetValue()), debugger_sp,
         args_impl, cmd_retobj, exe_ctx_ref_sp);
@@ -2806,7 +2806,6 @@ bool ScriptInterpreterPythonImpl::RunScriptBasedParsedCommand(
   return ret_val;
 }
 
-
 /// In Python, a special attribute __doc__ contains the docstring for an object
 /// (function, method, class, ...) if any is defined Otherwise, the attribute's
 /// value is None.
@@ -2925,7 +2924,7 @@ uint32_t ScriptInterpreterPythonImpl::GetFlagsForCommandObject(
   return result;
 }
 
-StructuredData::ObjectSP 
+StructuredData::ObjectSP
 ScriptInterpreterPythonImpl::GetOptionsForCommandObject(
     StructuredData::GenericSP cmd_obj_sp) {
   StructuredData::ObjectSP result = {};
@@ -2970,10 +2969,10 @@ ScriptInterpreterPythonImpl::GetOptionsForCommandObject(
     PyErr_Clear();
     return {};
   }
-    return py_return.CreateStructuredObject();
+  return py_return.CreateStructuredObject();
 }
 
-StructuredData::ObjectSP 
+StructuredData::ObjectSP
 ScriptInterpreterPythonImpl::GetArgumentsForCommandObject(
     StructuredData::GenericSP cmd_obj_sp) {
   StructuredData::ObjectSP result = {};
@@ -3018,11 +3017,10 @@ ScriptInterpreterPythonImpl::GetArgumentsForCommandObject(
     PyErr_Clear();
     return {};
   }
-    return py_return.CreateStructuredObject();
+  return py_return.CreateStructuredObject();
 }
 
-void 
-ScriptInterpreterPythonImpl::OptionParsingStartedForCommandObject(
+void ScriptInterpreterPythonImpl::OptionParsingStartedForCommandObject(
     StructuredData::GenericSP cmd_obj_sp) {
 
   Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
@@ -3030,7 +3028,7 @@ ScriptInterpreterPythonImpl::OptionParsingStartedForCommandObject(
   static char callee_name[] = "option_parsing_started";
 
   if (!cmd_obj_sp)
-    return ;
+    return;
 
   PythonObject implementor(PyRefType::Borrowed,
                            (PyObject *)cmd_obj_sp->GetValue());
@@ -3057,8 +3055,8 @@ ScriptInterpreterPythonImpl::OptionParsingStartedForCommandObject(
     PyErr_Clear();
 
   // FIXME: this should really be a void function
-  bool py_return = unwrapOrSetPythonException(
-      As<bool>(implementor.CallMethod(callee_name)));
+  bool py_return =
+      unwrapOrSetPythonException(As<bool>(implementor.CallMethod(callee_name)));
 
   // if it fails, print the error but otherwise go on
   if (PyErr_Occurred()) {
@@ -3068,8 +3066,7 @@ ScriptInterpreterPythonImpl::OptionParsingStartedForCommandObject(
   }
 }
 
-bool
-ScriptInterpreterPythonImpl::SetOptionValueForCommandObject(
+bool ScriptInterpreterPythonImpl::SetOptionValueForCommandObject(
     StructuredData::GenericSP cmd_obj_sp, ExecutionContext *exe_ctx,
     llvm::StringRef long_option, llvm::StringRef value) {
   StructuredData::ObjectSP result = {};
@@ -3104,15 +3101,15 @@ ScriptInterpreterPythonImpl::SetOptionValueForCommandObject(
 
   if (PyErr_Occurred())
     PyErr_Clear();
-    
+
   lldb::ExecutionContextRefSP exe_ctx_ref_sp;
   if (exe_ctx)
     exe_ctx_ref_sp.reset(new ExecutionContextRef(exe_ctx));
   PythonObject ctx_ref_obj = SWIGBridge::ToSWIGWrapper(exe_ctx_ref_sp);
-    
-  bool py_return = unwrapOrSetPythonException(
-      As<bool>(implementor.CallMethod(callee_name, ctx_ref_obj, long_option.str().c_str(), 
-                                      value.str().c_str())));
+
+  bool py_return = unwrapOrSetPythonException(As<bool>(
+      implementor.CallMethod(callee_name, ctx_ref_obj,
+                             long_option.str().c_str(), value.str().c_str())));
 
   // if it fails, print the error but otherwise go on
   if (PyErr_Occurred()) {
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
index fcd21dff612b..a89b121754c8 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -182,13 +182,12 @@ public:
       lldb_private::CommandReturnObject &cmd_retobj, Status &error,
       const lldb_private::ExecutionContext &exe_ctx) override;
 
-    virtual bool RunScriptBasedParsedCommand(
-      StructuredData::GenericSP impl_obj_sp, Args& args,
+  virtual bool RunScriptBasedParsedCommand(
+      StructuredData::GenericSP impl_obj_sp, Args &args,
       ScriptedCommandSynchronicity synchronicity,
       lldb_private::CommandReturnObject &cmd_retobj, Status &error,
       const lldb_private::ExecutionContext &exe_ctx) override;
 
-  
   Status GenerateFunction(const char *signature, const StringList &input,
                           bool is_callback) override;
 
@@ -219,7 +218,7 @@ public:
 
   bool GetLongHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp,
                                    std::string &dest) override;
-                                   
+
   StructuredData::ObjectSP
   GetOptionsForCommandObject(StructuredData::GenericSP cmd_obj_sp) override;
 
@@ -228,7 +227,7 @@ public:
 
   bool SetOptionValueForCommandObject(StructuredData::GenericSP cmd_obj_sp,
                                       ExecutionContext *exe_ctx,
-                                      llvm::StringRef long_option, 
+                                      llvm::StringRef long_option,
                                       llvm::StringRef value) override;
 
   void OptionParsingStartedForCommandObject(
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
index 5f0cc4c23db7..57d37395b5ec 100644
--- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -219,7 +219,7 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject(
 }
 
 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject(
-    PyObject *implementor, lldb::DebuggerSP debugger, 
+    PyObject *implementor, lldb::DebuggerSP debugger,
     StructuredDataImpl &args_impl,
     lldb_private::CommandReturnObject &cmd_retobj,
     lldb::ExecutionContextRefSP exe_ctx_ref_sp) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/70734


More information about the lldb-commits mailing list