diff options
author | Pete Lawrence <plawrence@apple.com> | 2023-10-30 10:21:00 -1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-30 13:21:00 -0700 |
commit | 92d8a28cc665d73d9d679b8c014dd04f95d1df18 (patch) | |
tree | 19b3a218ad57e05a911da01c0f4f80ca3c0a4bd4 /lldb/source/Commands/CommandObjectBreakpoint.cpp | |
parent | 2446439f51cf0d2dfb11c823436a930de7a4b8a2 (diff) | |
download | llvm-92d8a28cc665d73d9d679b8c014dd04f95d1df18.zip llvm-92d8a28cc665d73d9d679b8c014dd04f95d1df18.tar.gz llvm-92d8a28cc665d73d9d679b8c014dd04f95d1df18.tar.bz2 |
[lldb] Part 2 of 2 - Refactor `CommandObject::DoExecute(...)` return `void` (not `bool`) (#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
Diffstat (limited to 'lldb/source/Commands/CommandObjectBreakpoint.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectBreakpoint.cpp | 105 |
1 files changed, 42 insertions, 63 deletions
diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp index 18cbb95..e1d1c5e 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -528,7 +528,7 @@ public: }; 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 @@ protected: 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 @@ protected: } else { result.AppendError("Only one shared library can be specified for " "address breakpoints."); - return false; + return; } break; } @@ -647,7 +647,7 @@ protected: result.AppendWarning( "Function name regex does not accept glob patterns."); } - return false; + return; } bp_sp = target.CreateFuncRegexBreakpoint( @@ -664,7 +664,7 @@ protected: 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 @@ protected: 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 @@ protected: "Error setting extra exception arguments: %s", precond_error.AsCString()); target.RemoveBreakpointByID(bp_sp->GetID()); - return false; + return; } } break; case eSetTypeScripted: { @@ -707,7 +707,7 @@ protected: result.AppendErrorWithFormat( "Error setting extra exception arguments: %s", error.AsCString()); target.RemoveBreakpointByID(bp_sp->GetID()); - return false; + return; } } break; default: @@ -726,7 +726,7 @@ protected: result.AppendErrorWithFormat("Invalid breakpoint name: %s", name.c_str()); target.RemoveBreakpointByID(bp_sp->GetID()); - return false; + return; } } } @@ -753,8 +753,6 @@ protected: } else if (!bp_sp) { result.AppendError("Breakpoint creation failed: No breakpoint created."); } - - return result.Succeeded(); } private: @@ -835,7 +833,7 @@ public: 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 @@ protected: } } } - - return result.Succeeded(); } private: @@ -906,7 +902,7 @@ public: } 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 @@ protected: if (num_breakpoints == 0) { result.AppendError("No breakpoints exist to be enabled."); - return false; + return; } if (command.empty()) { @@ -963,8 +959,6 @@ protected: 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 @@ protected: if (num_breakpoints == 0) { result.AppendError("No breakpoints exist to be disabled."); - return false; + return; } if (command.empty()) { @@ -1076,8 +1070,6 @@ protected: result.SetStatus(eReturnStatusSuccessFinishNoResult); } } - - return result.Succeeded(); } }; @@ -1168,7 +1160,7 @@ public: }; 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 @@ protected: 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 @@ protected: result.AppendError("Invalid breakpoint ID."); } } - - return result.Succeeded(); } private: @@ -1289,7 +1279,7 @@ public: }; 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 @@ protected: // 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 @@ protected: } else { result.AppendError("Breakpoint clear: No breakpoint cleared."); } - - return result.Succeeded(); } private: @@ -1445,7 +1433,7 @@ public: }; 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 @@ protected: 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 @@ protected: (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 @@ protected: 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 @@ protected: } 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 @@ protected: "%d breakpoints deleted; %d breakpoint locations disabled.\n", delete_count, disable_count); result.SetStatus(eReturnStatusSuccessFinishNoResult); - return result.Succeeded(); } private: @@ -1709,12 +1696,12 @@ public: 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 @@ protected: 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 @@ protected: if (!bp_sp) { result.AppendErrorWithFormatv("Could not find specified breakpoint {0}", bp_id); - return false; + return; } } @@ -1765,7 +1752,6 @@ protected: m_bp_opts.GetBreakpointOptions(), m_access_options.GetPermissions()); } - return true; } private: @@ -1806,10 +1792,10 @@ public: 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 @@ protected: 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 @@ protected: 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 @@ protected: target.AddNameToBreakpoint(bp_sp, bp_name, error); } } - - return true; } private: @@ -1889,10 +1873,10 @@ public: 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 @@ protected: 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 @@ protected: 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 @@ protected: target.RemoveNameFromBreakpoint(bp_sp, bp_name); } } - - return true; } private: @@ -1955,7 +1937,7 @@ public: Options *GetOptions() override { return &m_option_group; } protected: - bool DoExecute(Args &command, CommandReturnObject &result) override { + void DoExecute(Args &command, CommandReturnObject &result) override { Target &target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); @@ -2005,7 +1987,6 @@ protected: } } } - return true; } private: @@ -2267,7 +2248,7 @@ public: }; 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; @@ -2281,7 +2262,7 @@ protected: if (!error.Success()) { result.AppendError(error.AsCString()); - return false; + return; } Stream &output_stream = result.GetOutputStream(); @@ -2302,7 +2283,6 @@ protected: false); } } - return result.Succeeded(); } private: @@ -2383,7 +2363,7 @@ public: }; 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; @@ -2397,7 +2377,7 @@ protected: if (!result.Succeeded()) { result.SetStatus(eReturnStatusFailed); - return false; + return; } } FileSpec file_spec(m_options.m_filename); @@ -2408,7 +2388,6 @@ protected: result.AppendErrorWithFormat("error serializing breakpoints: %s.", error.AsCString()); } - return result.Succeeded(); } private: |