Skip to content

[lldb] Part 2 of 2 - Refactor CommandObject::DoExecute(...) return void (not bool) #69991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

PortalPete
Copy link
Contributor

[lldb] Part 2 of 2 - Refactor CommandObject::DoExecute(...) to return void instead of bool

Justifications:

  • The code doesn't ultimately apply the true/false return values.
  • The methods already pass around a CommandReturnObject, typically with a result parameter.
  • Each command return object already contains:
    • A more precise status
    • The error code(s) that apply to that status

Part 1 refactors the CommandObject::Execute(...) method.

rdar://117378957

@llvmbot
Copy link
Member

llvmbot commented Oct 24, 2023

@llvm/pr-subscribers-lldb

Author: Pete Lawrence (PortalPete)

Changes

[lldb] Part 2 of 2 - Refactor CommandObject::DoExecute(...) to return void instead of bool

Justifications:

  • The code doesn't ultimately apply the true/false return values.
  • The methods already pass around a CommandReturnObject, typically with a result parameter.
  • Each command return object already contains:
    • A more precise status
    • The error code(s) that apply to that status

Part 1 refactors the CommandObject::Execute(...) method.

rdar://117378957


Patch is 301.30 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/69991.diff

62 Files Affected:

  • (modified) lldb/include/lldb/Interpreter/CommandAlias.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/CommandObject.h (+5-5)
  • (modified) lldb/include/lldb/Interpreter/CommandObjectMultiword.h (+2-2)
  • (modified) lldb/source/API/SBCommandInterpreter.cpp (+2-4)
  • (modified) lldb/source/Commands/CommandObjectApropos.cpp (+1-3)
  • (modified) lldb/source/Commands/CommandObjectApropos.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectBreakpoint.cpp (+42-63)
  • (modified) lldb/source/Commands/CommandObjectBreakpointCommand.cpp (+10-15)
  • (modified) lldb/source/Commands/CommandObjectCommands.cpp (+65-86)
  • (modified) lldb/source/Commands/CommandObjectDWIMPrint.cpp (+4-6)
  • (modified) lldb/source/Commands/CommandObjectDWIMPrint.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectDiagnostics.cpp (+4-4)
  • (modified) lldb/source/Commands/CommandObjectDisassemble.cpp (+5-7)
  • (modified) lldb/source/Commands/CommandObjectDisassemble.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectExpression.cpp (+7-8)
  • (modified) lldb/source/Commands/CommandObjectExpression.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectFrame.cpp (+32-44)
  • (modified) lldb/source/Commands/CommandObjectGUI.cpp (+1-3)
  • (modified) lldb/source/Commands/CommandObjectGUI.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectHelp.cpp (+3-5)
  • (modified) lldb/source/Commands/CommandObjectHelp.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectLanguage.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectLog.cpp (+16-26)
  • (modified) lldb/source/Commands/CommandObjectMemory.cpp (+71-76)
  • (modified) lldb/source/Commands/CommandObjectMemoryTag.cpp (+14-16)
  • (modified) lldb/source/Commands/CommandObjectMultiword.cpp (+10-10)
  • (modified) lldb/source/Commands/CommandObjectPlatform.cpp (+40-62)
  • (modified) lldb/source/Commands/CommandObjectPlugin.cpp (+2-4)
  • (modified) lldb/source/Commands/CommandObjectProcess.cpp (+35-58)
  • (modified) lldb/source/Commands/CommandObjectQuit.cpp (+5-7)
  • (modified) lldb/source/Commands/CommandObjectQuit.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectRegexCommand.cpp (+5-5)
  • (modified) lldb/source/Commands/CommandObjectRegexCommand.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectRegister.cpp (+5-9)
  • (modified) lldb/source/Commands/CommandObjectScript.cpp (+5-7)
  • (modified) lldb/source/Commands/CommandObjectScript.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectSession.cpp (+2-4)
  • (modified) lldb/source/Commands/CommandObjectSettings.cpp (+32-59)
  • (modified) lldb/source/Commands/CommandObjectSource.cpp (+14-19)
  • (modified) lldb/source/Commands/CommandObjectStats.cpp (+5-8)
  • (modified) lldb/source/Commands/CommandObjectTarget.cpp (+89-126)
  • (modified) lldb/source/Commands/CommandObjectThread.cpp (+63-77)
  • (modified) lldb/source/Commands/CommandObjectThreadUtil.cpp (+14-14)
  • (modified) lldb/source/Commands/CommandObjectThreadUtil.h (+2-2)
  • (modified) lldb/source/Commands/CommandObjectTrace.cpp (+8-13)
  • (modified) lldb/source/Commands/CommandObjectType.cpp (+46-62)
  • (modified) lldb/source/Commands/CommandObjectVersion.cpp (+1-2)
  • (modified) lldb/source/Commands/CommandObjectVersion.h (+1-1)
  • (modified) lldb/source/Commands/CommandObjectWatchpoint.cpp (+34-50)
  • (modified) lldb/source/Commands/CommandObjectWatchpointCommand.cpp (+12-17)
  • (modified) lldb/source/Interpreter/CommandAlias.cpp (+1-1)
  • (modified) lldb/source/Interpreter/CommandObject.cpp (+7-8)
  • (modified) lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp (+1-2)
  • (modified) lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (+10-12)
  • (modified) lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (+5-6)
  • (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (+11-16)
  • (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp (+3-5)
  • (modified) lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp (+5-7)
  • (modified) lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.h (+1-1)
  • (modified) lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.cpp (+1-5)
  • (modified) lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.h (+1-1)
  • (modified) lldb/unittests/Interpreter/TestCommandPaths.cpp (+1-2)
diff --git a/lldb/include/lldb/Interpreter/CommandAlias.h b/lldb/include/lldb/Interpreter/CommandAlias.h
index 26826db62705d67..7b59ea0a74bb9e5 100644
--- a/lldb/include/lldb/Interpreter/CommandAlias.h
+++ b/lldb/include/lldb/Interpreter/CommandAlias.h
@@ -56,7 +56,7 @@ class CommandAlias : public CommandObject {
 
   void SetHelpLong(llvm::StringRef str) override;
 
-  bool Execute(const char *args_string, CommandReturnObject &result) override;
+  void Execute(const char *args_string, CommandReturnObject &result) override;
 
   lldb::CommandObjectSP GetUnderlyingCommand() {
     return m_underlying_command_sp;
diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h
index d8358435a483bab..7b427de0264f756 100644
--- a/lldb/include/lldb/Interpreter/CommandObject.h
+++ b/lldb/include/lldb/Interpreter/CommandObject.h
@@ -312,7 +312,7 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
       return false;
   }
 
-  virtual bool Execute(const char *args_string,
+  virtual void Execute(const char *args_string,
                        CommandReturnObject &result) = 0;
 
 protected:
@@ -398,10 +398,10 @@ class CommandObjectParsed : public CommandObject {
 
   ~CommandObjectParsed() override = default;
 
-  bool Execute(const char *args_string, CommandReturnObject &result) override;
+  void Execute(const char *args_string, CommandReturnObject &result) override;
 
 protected:
-  virtual bool DoExecute(Args &command, CommandReturnObject &result) = 0;
+  virtual void DoExecute(Args &command, CommandReturnObject &result) = 0;
 
   bool WantsRawCommandString() override { return false; }
 };
@@ -415,10 +415,10 @@ class CommandObjectRaw : public CommandObject {
 
   ~CommandObjectRaw() override = default;
 
-  bool Execute(const char *args_string, CommandReturnObject &result) override;
+  void Execute(const char *args_string, CommandReturnObject &result) override;
 
 protected:
-  virtual bool DoExecute(llvm::StringRef command,
+  virtual void DoExecute(llvm::StringRef command,
                          CommandReturnObject &result) = 0;
 
   bool WantsRawCommandString() override { return true; }
diff --git a/lldb/include/lldb/Interpreter/CommandObjectMultiword.h b/lldb/include/lldb/Interpreter/CommandObjectMultiword.h
index 1c14b492c8097fe..bceb7f0e51edb6c 100644
--- a/lldb/include/lldb/Interpreter/CommandObjectMultiword.h
+++ b/lldb/include/lldb/Interpreter/CommandObjectMultiword.h
@@ -59,7 +59,7 @@ class CommandObjectMultiword : public CommandObject {
   std::optional<std::string> GetRepeatCommand(Args &current_command_args,
                                               uint32_t index) override;
 
-  bool Execute(const char *args_string, CommandReturnObject &result) override;
+  void Execute(const char *args_string, CommandReturnObject &result) override;
 
   bool IsRemovable() const override { return m_can_be_removed; }
 
@@ -129,7 +129,7 @@ class CommandObjectProxy : public CommandObject {
   ///     Execute is called) and \a GetProxyCommandObject returned null.
   virtual llvm::StringRef GetUnsupportedError();
 
-  bool Execute(const char *args_string, CommandReturnObject &result) override;
+  void Execute(const char *args_string, CommandReturnObject &result) override;
 
 protected:
   // These two want to iterate over the subcommand dictionary.
diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp
index d275da933919e53..c3cbb00145ed3eb 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -70,13 +70,11 @@ class CommandPluginInterfaceImplementation : public CommandObjectParsed {
   }
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     SBCommandReturnObject sb_return(result);
     SBCommandInterpreter sb_interpreter(&m_interpreter);
     SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this());
-    bool ret = m_backend->DoExecute(debugger_sb, command.GetArgumentVector(),
-                                    sb_return);
-    return ret;
+    m_backend->DoExecute(debugger_sb, command.GetArgumentVector(), sb_return);
   }
   std::shared_ptr<lldb::SBCommandPluginInterface> m_backend;
   std::optional<std::string> m_auto_repeat_command;
diff --git a/lldb/source/Commands/CommandObjectApropos.cpp b/lldb/source/Commands/CommandObjectApropos.cpp
index c6680f8b140d16b..88c214d4fc56ab6 100644
--- a/lldb/source/Commands/CommandObjectApropos.cpp
+++ b/lldb/source/Commands/CommandObjectApropos.cpp
@@ -38,7 +38,7 @@ CommandObjectApropos::CommandObjectApropos(CommandInterpreter &interpreter)
 
 CommandObjectApropos::~CommandObjectApropos() = default;
 
-bool CommandObjectApropos::DoExecute(Args &args, CommandReturnObject &result) {
+void CommandObjectApropos::DoExecute(Args &args, CommandReturnObject &result) {
   const size_t argc = args.GetArgumentCount();
 
   if (argc == 1) {
@@ -90,6 +90,4 @@ bool CommandObjectApropos::DoExecute(Args &args, CommandReturnObject &result) {
   } else {
     result.AppendError("'apropos' must be called with exactly one argument.\n");
   }
-
-  return result.Succeeded();
 }
diff --git a/lldb/source/Commands/CommandObjectApropos.h b/lldb/source/Commands/CommandObjectApropos.h
index 042753f240328bd..f43420c1815d90d 100644
--- a/lldb/source/Commands/CommandObjectApropos.h
+++ b/lldb/source/Commands/CommandObjectApropos.h
@@ -23,7 +23,7 @@ class CommandObjectApropos : public CommandObjectParsed {
   ~CommandObjectApropos() override;
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override;
+  void DoExecute(Args &command, CommandReturnObject &result) override;
 };
 
 } // namespace lldb_private
diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index 18cbb9528b717a5..e1d1c5e42c32a03 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -528,7 +528,7 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
   };
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy);
 
     // The following are the various types of breakpoints that could be set:
@@ -577,12 +577,12 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
       if (num_files == 0) {
         if (!GetDefaultFile(target, file, result)) {
           result.AppendError("No file supplied and no default file available.");
-          return false;
+          return;
         }
       } else if (num_files > 1) {
         result.AppendError("Only one file at a time is allowed for file and "
                            "line breakpoints.");
-        return false;
+        return;
       } else
         file = m_options.m_filenames.GetFileSpecAtIndex(0);
 
@@ -613,7 +613,7 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
       } else {
         result.AppendError("Only one shared library can be specified for "
                            "address breakpoints.");
-        return false;
+        return;
       }
       break;
     }
@@ -647,7 +647,7 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
             result.AppendWarning(
                 "Function name regex does not accept glob patterns.");
         }
-        return false;
+        return;
       }
 
       bp_sp = target.CreateFuncRegexBreakpoint(
@@ -664,7 +664,7 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
         if (!GetDefaultFile(target, file, result)) {
           result.AppendError(
               "No files provided and could not find default file.");
-          return false;
+          return;
         } else {
           m_options.m_filenames.Append(file);
         }
@@ -675,7 +675,7 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
         result.AppendErrorWithFormat(
             "Source text regular expression could not be compiled: \"%s\"",
             llvm::toString(std::move(err)).c_str());
-        return false;
+        return;
       }
       bp_sp = target.CreateSourceRegexBreakpoint(
           &(m_options.m_modules), &(m_options.m_filenames),
@@ -693,7 +693,7 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
             "Error setting extra exception arguments: %s",
             precond_error.AsCString());
         target.RemoveBreakpointByID(bp_sp->GetID());
-        return false;
+        return;
       }
     } break;
     case eSetTypeScripted: {
@@ -707,7 +707,7 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
         result.AppendErrorWithFormat(
             "Error setting extra exception arguments: %s", error.AsCString());
         target.RemoveBreakpointByID(bp_sp->GetID());
-        return false;
+        return;
       }
     } break;
     default:
@@ -726,7 +726,7 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
             result.AppendErrorWithFormat("Invalid breakpoint name: %s",
                                          name.c_str());
             target.RemoveBreakpointByID(bp_sp->GetID());
-            return false;
+            return;
           }
         }
       }
@@ -753,8 +753,6 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
     } else if (!bp_sp) {
       result.AppendError("Breakpoint creation failed: No breakpoint created.");
     }
-
-    return result.Succeeded();
   }
 
 private:
@@ -835,7 +833,7 @@ class CommandObjectBreakpointModify : public CommandObjectParsed {
   Options *GetOptions() override { return &m_options; }
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy);
 
     std::unique_lock<std::recursive_mutex> lock;
@@ -868,8 +866,6 @@ class CommandObjectBreakpointModify : public CommandObjectParsed {
         }
       }
     }
-
-    return result.Succeeded();
   }
 
 private:
@@ -906,7 +902,7 @@ class CommandObjectBreakpointEnable : public CommandObjectParsed {
   }
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetSelectedOrDummyTarget();
 
     std::unique_lock<std::recursive_mutex> lock;
@@ -918,7 +914,7 @@ class CommandObjectBreakpointEnable : public CommandObjectParsed {
 
     if (num_breakpoints == 0) {
       result.AppendError("No breakpoints exist to be enabled.");
-      return false;
+      return;
     }
 
     if (command.empty()) {
@@ -963,8 +959,6 @@ class CommandObjectBreakpointEnable : public CommandObjectParsed {
         result.SetStatus(eReturnStatusSuccessFinishNoResult);
       }
     }
-
-    return result.Succeeded();
   }
 };
 
@@ -1020,7 +1014,7 @@ the second re-enables the first location.");
   }
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetSelectedOrDummyTarget();
     std::unique_lock<std::recursive_mutex> lock;
     target.GetBreakpointList().GetListMutex(lock);
@@ -1030,7 +1024,7 @@ the second re-enables the first location.");
 
     if (num_breakpoints == 0) {
       result.AppendError("No breakpoints exist to be disabled.");
-      return false;
+      return;
     }
 
     if (command.empty()) {
@@ -1076,8 +1070,6 @@ the second re-enables the first location.");
         result.SetStatus(eReturnStatusSuccessFinishNoResult);
       }
     }
-
-    return result.Succeeded();
   }
 };
 
@@ -1168,7 +1160,7 @@ class CommandObjectBreakpointList : public CommandObjectParsed {
   };
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
 
     const BreakpointList &breakpoints =
@@ -1181,7 +1173,7 @@ class CommandObjectBreakpointList : public CommandObjectParsed {
     if (num_breakpoints == 0) {
       result.AppendMessage("No breakpoints currently set.");
       result.SetStatus(eReturnStatusSuccessFinishNoResult);
-      return true;
+      return;
     }
 
     Stream &output_stream = result.GetOutputStream();
@@ -1216,8 +1208,6 @@ class CommandObjectBreakpointList : public CommandObjectParsed {
         result.AppendError("Invalid breakpoint ID.");
       }
     }
-
-    return result.Succeeded();
   }
 
 private:
@@ -1289,7 +1279,7 @@ class CommandObjectBreakpointClear : public CommandObjectParsed {
   };
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetSelectedOrDummyTarget();
 
     // The following are the various types of breakpoints that could be
@@ -1310,7 +1300,7 @@ class CommandObjectBreakpointClear : public CommandObjectParsed {
     // Early return if there's no breakpoint at all.
     if (num_breakpoints == 0) {
       result.AppendError("Breakpoint clear: No breakpoint cleared.");
-      return result.Succeeded();
+      return;
     }
 
     // Find matching breakpoints and delete them.
@@ -1357,8 +1347,6 @@ class CommandObjectBreakpointClear : public CommandObjectParsed {
     } else {
       result.AppendError("Breakpoint clear: No breakpoint cleared.");
     }
-
-    return result.Succeeded();
   }
 
 private:
@@ -1445,7 +1433,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
   };
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
     result.Clear();
     
@@ -1458,7 +1446,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
 
     if (num_breakpoints == 0) {
       result.AppendError("No breakpoints exist to be deleted.");
-      return false;
+      return;
     }
 
     // Handle the delete all breakpoints case:
@@ -1475,7 +1463,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
             (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
       }
       result.SetStatus(eReturnStatusSuccessFinishNoResult);
-      return result.Succeeded();
+      return;
     }
  
     // Either we have some kind of breakpoint specification(s),
@@ -1491,7 +1479,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
             command, &target, result, &excluded_bp_ids,
             BreakpointName::Permissions::PermissionKinds::deletePerm);
         if (!result.Succeeded())
-          return false;
+          return;
       }
 
       for (auto breakpoint_sp : breakpoints.Breakpoints()) {
@@ -1504,14 +1492,14 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
       }
       if (valid_bp_ids.GetSize() == 0) {
         result.AppendError("No disabled breakpoints.");
-        return false;
+        return;
       }
     } else {
       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
           command, &target, result, &valid_bp_ids,
           BreakpointName::Permissions::PermissionKinds::deletePerm);
       if (!result.Succeeded())
-        return false;
+        return;
     }
     
     int delete_count = 0;
@@ -1542,7 +1530,6 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
         "%d breakpoints deleted; %d breakpoint locations disabled.\n",
         delete_count, disable_count);
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
-    return result.Succeeded();
   }
 
 private:
@@ -1709,12 +1696,12 @@ class CommandObjectBreakpointNameConfigure : public CommandObjectParsed {
   Options *GetOptions() override { return &m_option_group; }
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
 
     const size_t argc = command.GetArgumentCount();
     if (argc == 0) {
       result.AppendError("No names provided.");
-      return false;
+      return;
     }
 
     Target &target = GetSelectedOrDummyTarget(false);
@@ -1728,7 +1715,7 @@ class CommandObjectBreakpointNameConfigure : public CommandObjectParsed {
       if (!BreakpointID::StringIsBreakpointName(entry.ref(), error)) {
         result.AppendErrorWithFormat("Invalid breakpoint name: %s - %s",
                                      entry.c_str(), error.AsCString());
-        return false;
+        return;
       }
     }
     // Now configure them, we already pre-checked the names so we don't need to
@@ -1741,7 +1728,7 @@ class CommandObjectBreakpointNameConfigure : public CommandObjectParsed {
       if (!bp_sp) {
         result.AppendErrorWithFormatv("Could not find specified breakpoint {0}",
                                       bp_id);
-        return false;
+        return;
       }
     }
 
@@ -1765,7 +1752,6 @@ class CommandObjectBreakpointNameConfigure : public CommandObjectParsed {
                                        m_bp_opts.GetBreakpointOptions(),
                                        m_access_options.GetPermissions());
     }
-    return true;
   }
 
 private:
@@ -1806,10 +1792,10 @@ class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
   Options *GetOptions() override { return &m_option_group; }
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     if (!m_name_options.m_name.OptionWasSet()) {
       result.AppendError("No name option provided.");
-      return false;
+      return;
     }
 
     Target &target =
@@ -1823,7 +1809,7 @@ class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
     size_t num_breakpoints = breakpoints.GetSize();
     if (num_breakpoints == 0) {
       result.AppendError("No breakpoints, cannot add names.");
-      return false;
+      return;
     }
 
     // Particular breakpoint selected; disable that breakpoint.
@@ -1835,7 +1821,7 @@ class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
     if (result.Succeeded()) {
       if (valid_bp_ids.GetSize() == 0) {
         result.AppendError("No breakpoints specified, cannot add names.");
-        return false;
+        return;
       }
       size_t num_valid_ids = valid_bp_ids.GetSize();
       const char *bp_name = m_name_options.m_name.GetCurrentValue();
@@ -1848,8 +1834,6 @@ class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
         target.AddNameToBreakpoint(bp_sp, bp_name, error);
       }
     }
-
-    return true;
   }
 
 private:
@@ -1889,10 +1873,10 @@ class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
   Options *GetOptions() override { return &m_option_group; }
 
 protected:
-  bool DoExecute(Args &command, CommandReturnObject &result) override {
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     if (!m_name_options.m_name.OptionWasSet()) {
       result.AppendError("No name option provided.");
-      return false;
+      return;
     }
 
     Target &target =
@@ -1906,7 +1890,7 @@ class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
     size_t num_breakpoints = breakpoints.GetSize();
     if (num_breakpoints == 0) {
       result.AppendError("No breakpoints, cannot delete names.");
-      return false;
+      return;
     }
 
     // Particular breakpoint selected; disable that breakpoint.
@@ -1918,7 +1902,7 @@ class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
     if (result.Succeeded()) {
       if (valid_bp_ids.GetSize() == 0) {
         result.AppendError("No breakpoints specified, cannot delete names.");
-        return false;
+        return;
       }
       ConstString bp_name(m_name_options.m_name.GetCurrentValue());
       size_t num_valid_ids = valid_bp_ids.GetSize();
@@ -1929,8 +1913,6 @@ class CommandObjectBreakpointNameDelete : public CommandObjectPa...
[truncated]

Copy link
Collaborator

@jasonmolenda jasonmolenda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, modulo the three little things I noted in the patch.

@PortalPete PortalPete force-pushed the refactor/CommandObject-DoExecute branch from a01da49 to 6a41a7a Compare October 24, 2023 12:50
Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I looked at every changed line, looks good to me overall. Found one place with a small style issue but it's not a blocker. Thanks!

@PortalPete PortalPete force-pushed the refactor/CommandObject-DoExecute branch from 6a41a7a to 00b0e33 Compare October 24, 2023 20:06
@PortalPete
Copy link
Contributor Author

I think I looked at every changed line, looks good to me overall. Found one place with a small style issue but it's not a blocker. Thanks!

Thanks @bulbazord!
Do you know why the code_formatter check/bot didn't flag that or the other one-line if statements?

@medismailben
Copy link
Member

I think I looked at every changed line, looks good to me overall. Found one place with a small style issue but it's not a blocker. Thanks!

Thanks @bulbazord! Do you know why the code_formatter check/bot didn't flag that or the other one-line if statements?

This could be because it's part of the LLVM style guide but not enforced in the .clang-format.

Also looked at most of the lines, LGTM. I wonder however why did you decide to make 2 separate PRs for this ? Is there any reason for this ? It could have been 2 commits in the same PR.

@bulbazord
Copy link
Member

I think I looked at every changed line, looks good to me overall. Found one place with a small style issue but it's not a blocker. Thanks!

Thanks @bulbazord! Do you know why the code_formatter check/bot didn't flag that or the other one-line if statements?

This could be because it's part of the LLVM style guide but not enforced in the .clang-format.

Also looked at most of the lines, LGTM. I wonder however why did you decide to make 2 separate PRs for this ? Is there any reason for this ? It could have been 2 commits in the same PR.

Yeah, I think it's probably not enforced. Maybe it should be? 🤔

adrian-prantl referenced this pull request Oct 25, 2023
…oid` (not `bool`) (#69989)

[lldb] Part 1 of 2 - Refactor `CommandObject::Execute(...)` to return
`void` instead of ~~`bool`~~

Justifications:
- The code doesn't ultimately apply the `true`/`false` return values.
- The methods already pass around a `CommandReturnObject`, typically
with a `result` parameter.
- Each command return object already contains:
	- A more precise status
	- The error code(s) that apply to that status

Part 2 refactors the `CommandObject::DoExecute(...)` method.
- See
[https://github.com/llvm/llvm-project/pull/69991](https://github.com/llvm/llvm-project/pull/69991)

rdar://117378957
…rn `void` instead of ~~`bool`~~

Justifications:
- The code doesn't ultimately apply the `true`/`false` return values.
- The methods already pass around a `CommandReturnObject`, typically with a `result` parameter.
- Each command return object already contains:
	- A more precise status
	- The error code(s) that apply to that status

Part 1 refactors the `CommandObject::Execute(...)` method.

rdar://117378957
@PortalPete PortalPete force-pushed the refactor/CommandObject-DoExecute branch from 00b0e33 to 9e9771d Compare October 26, 2023 02:16
zahiraam referenced this pull request in zahiraam/llvm-project Oct 26, 2023
…oid` (not `bool`) (llvm#69989)

[lldb] Part 1 of 2 - Refactor `CommandObject::Execute(...)` to return
`void` instead of ~~`bool`~~

Justifications:
- The code doesn't ultimately apply the `true`/`false` return values.
- The methods already pass around a `CommandReturnObject`, typically
with a `result` parameter.
- Each command return object already contains:
	- A more precise status
	- The error code(s) that apply to that status

Part 2 refactors the `CommandObject::DoExecute(...)` method.
- See
[https://github.com/llvm/llvm-project/pull/69991](https://github.com/llvm/llvm-project/pull/69991)

rdar://117378957
@adrian-prantl adrian-prantl merged commit 92d8a28 into llvm:main Oct 30, 2023
PortalPete referenced this pull request in PortalPete/llvm-project Feb 7, 2024
…oid` (not `bool`) (llvm#69989)

[lldb] Part 1 of 2 - Refactor `CommandObject::Execute(...)` to return
`void` instead of ~~`bool`~~

Justifications:
- The code doesn't ultimately apply the `true`/`false` return values.
- The methods already pass around a `CommandReturnObject`, typically
with a `result` parameter.
- Each command return object already contains:
	- A more precise status
	- The error code(s) that apply to that status

Part 2 refactors the `CommandObject::DoExecute(...)` method.
- See
[https://github.com/llvm/llvm-project/pull/69991](https://github.com/llvm/llvm-project/pull/69991)

rdar://117378957
PortalPete added a commit to PortalPete/llvm-project that referenced this pull request Feb 7, 2024
…`void` (not `bool`) (llvm#69991)

[lldb] Part 2 of 2 - Refactor `CommandObject::DoExecute(...)` to return
`void` instead of ~~`bool`~~

Justifications:
- The code doesn't ultimately apply the `true`/`false` return values.
- The methods already pass around a `CommandReturnObject`, typically
with a `result` parameter.
- Each command return object already contains:
	- A more precise status
	- The error code(s) that apply to that status

Part 1 refactors the `CommandObject::Execute(...)` method.
- See
[https://github.com/llvm/llvm-project/pull/69989](https://github.com/llvm/llvm-project/pull/69989)

rdar://117378957
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants