[Lldb-commits] [lldb] 5f18584 - [lldb] Fix CommandObjects that don't set a return status (#196588)
via lldb-commits
lldb-commits at lists.llvm.org
Fri May 8 19:53:55 PDT 2026
Author: Jonas Devlieghere
Date: 2026-05-08T21:53:49-05:00
New Revision: 5f1858428127267ff63c78c49ca6241674c4d72d
URL: https://github.com/llvm/llvm-project/commit/5f1858428127267ff63c78c49ca6241674c4d72d
DIFF: https://github.com/llvm/llvm-project/commit/5f1858428127267ff63c78c49ca6241674c4d72d.diff
LOG: [lldb] Fix CommandObjects that don't set a return status (#196588)
Several CommandObject subclasses had DoExecute paths that returned
without ever calling SetStatus on the CommandReturnObject. The status
was silently left at its initial eReturnStatusStarted value, which made
Succeeded() report false for what were really successful commands and
left CommandReturnObject in an undefined state.
Added:
Modified:
lldb/source/API/SBCommandInterpreter.cpp
lldb/source/Commands/CommandObjectBreakpoint.cpp
lldb/source/Commands/CommandObjectCommands.cpp
lldb/source/Commands/CommandObjectExpression.cpp
lldb/source/Commands/CommandObjectFrame.cpp
lldb/source/Commands/CommandObjectHelp.cpp
lldb/source/Commands/CommandObjectLog.cpp
lldb/source/Commands/CommandObjectMemory.cpp
lldb/source/Commands/CommandObjectPlatform.cpp
lldb/source/Commands/CommandObjectRegister.cpp
lldb/source/Commands/CommandObjectScripting.cpp
lldb/source/Commands/CommandObjectSession.cpp
lldb/source/Commands/CommandObjectSettings.cpp
lldb/source/Commands/CommandObjectSource.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Commands/CommandObjectThread.cpp
lldb/source/Commands/CommandObjectType.cpp
Removed:
################################################################################
diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp
index 4c1cddc21b972..a1593d67ffd6e 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -75,7 +75,13 @@ class CommandPluginInterfaceImplementation : public CommandObjectParsed {
SBCommandReturnObject sb_return(result);
SBCommandInterpreter sb_interpreter(&m_interpreter);
SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this());
- m_backend->DoExecute(debugger_sb, command.GetArgumentVector(), sb_return);
+ bool success = m_backend->DoExecute(debugger_sb,
+ command.GetArgumentVector(), sb_return);
+ // If the plugin command did not set its own status, infer it from the
+ // boolean return value so that callers always see a defined status.
+ if (result.GetStatus() == eReturnStatusInvalid)
+ result.SetStatus(success ? eReturnStatusSuccessFinishResult
+ : eReturnStatusFailed);
}
lldb::SBCommandPluginInterface *m_backend;
std::optional<std::string> m_auto_repeat_command;
diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index bb71055ebb3cb..c462a4875b127 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -2959,6 +2959,7 @@ class CommandObjectBreakpointNameConfigure : public CommandObjectParsed {
m_bp_opts.GetBreakpointOptions(),
m_access_options.GetPermissions());
}
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
private:
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index 1f4783c26be8e..84e661ec01f53 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -868,6 +868,7 @@ a number follows 'f':"
if (error.Success()) {
AddRegexCommandToInterpreter();
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
}
if (error.Fail()) {
@@ -2498,6 +2499,8 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
if (m_options.m_class_name.empty() && m_options.m_funct_name.empty()) {
m_interpreter.GetPythonCommandsFromIOHandler(" ", // Prompt
*this); // IOHandlerDelegate
+ // Still gathering input; the IOHandler will set the final status.
+ result.SetStatus(eReturnStatusStarted);
return;
}
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index 0b86c329572ee..76cb60c7e4804 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -593,6 +593,8 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command,
if (command.empty()) {
GetMultilineExpression();
+ // Still gathering input; the IOHandler will set the final status.
+ result.SetStatus(eReturnStatusStarted);
return;
}
@@ -660,6 +662,8 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command,
// No expression following options
else if (expr.empty()) {
GetMultilineExpression();
+ // Still gathering input; the IOHandler will set the final status.
+ result.SetStatus(eReturnStatusStarted);
return;
}
}
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index b1cc6c42a04fc..f039eb6be6eaa 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -176,6 +176,8 @@ class CommandObjectFrameDiagnose : public CommandObjectParsed {
ValueObjectPrinter printer(*valobj_sp, &result.GetOutputStream(), options);
if (llvm::Error error = printer.PrintValueObject())
result.AppendError(toString(std::move(error)));
+ else
+ result.SetStatus(eReturnStatusSuccessFinishResult);
}
CommandOptions m_options;
diff --git a/lldb/source/Commands/CommandObjectHelp.cpp b/lldb/source/Commands/CommandObjectHelp.cpp
index f1dbd03fe97cb..a29ded846b100 100644
--- a/lldb/source/Commands/CommandObjectHelp.cpp
+++ b/lldb/source/Commands/CommandObjectHelp.cpp
@@ -168,6 +168,7 @@ void CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) {
for (size_t i = 0; i < match_count; i++) {
output_strm.Printf("\t%s\n", matches.GetStringAtIndex(i));
}
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
// Maybe the user is asking for help about a command argument rather than
// a command.
diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp
index b61627f4d4d55..e51a85e9f0308 100644
--- a/lldb/source/Commands/CommandObjectLog.cpp
+++ b/lldb/source/Commands/CommandObjectLog.cpp
@@ -273,7 +273,8 @@ class CommandObjectLogDisable : public CommandObjectParsed {
if (Log::DisableLogChannel(channel, args.GetArgumentArrayRef(),
error_stream))
result.SetStatus(eReturnStatusSuccessFinishNoResult);
- result.GetErrorStream() << error;
+ else
+ result.AppendError(error);
}
}
};
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index ac91b63e378a8..9164e209b6bc2 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -769,6 +769,7 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
result.GetOutputStream().Printf(
"%zi bytes %s to '%s'\n", bytes_written,
append ? "appended" : "written", path.c_str());
+ result.SetStatus(eReturnStatusSuccessFinishResult);
return;
} else {
result.AppendErrorWithFormat("Failed to write %" PRIu64
@@ -820,6 +821,7 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
return;
}
}
+ result.SetStatus(eReturnStatusSuccessFinishResult);
return;
}
@@ -1510,6 +1512,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
return;
}
}
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
OptionGroupOptions m_option_group;
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 37ae2899f79b3..52b571acd13ee 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1300,6 +1300,7 @@ class CommandObjectPlatformProcessList : public CommandObjectParsed {
ostrm, platform_sp->GetUserIDResolver(), m_options.show_args,
m_options.verbose);
}
+ result.SetStatus(eReturnStatusSuccessFinishResult);
}
}
} else {
diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp
index 29d1cd6dc13e4..c86fd11d4d9e3 100644
--- a/lldb/source/Commands/CommandObjectRegister.cpp
+++ b/lldb/source/Commands/CommandObjectRegister.cpp
@@ -220,6 +220,8 @@ class CommandObjectRegisterRead : public CommandObjectParsed {
}
}
}
+ if (result.GetStatus() != eReturnStatusFailed)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
}
class CommandOptions : public OptionGroup {
diff --git a/lldb/source/Commands/CommandObjectScripting.cpp b/lldb/source/Commands/CommandObjectScripting.cpp
index 1f8ee0a9554ec..21400a62d697f 100644
--- a/lldb/source/Commands/CommandObjectScripting.cpp
+++ b/lldb/source/Commands/CommandObjectScripting.cpp
@@ -229,6 +229,8 @@ class CommandObjectScriptingExtensionList : public CommandObjectParsed {
if (!num_listed_interface)
s << " None\n";
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
}
private:
diff --git a/lldb/source/Commands/CommandObjectSession.cpp b/lldb/source/Commands/CommandObjectSession.cpp
index ac7eec5e04f0a..586e0f405920f 100644
--- a/lldb/source/Commands/CommandObjectSession.cpp
+++ b/lldb/source/Commands/CommandObjectSession.cpp
@@ -179,6 +179,7 @@ class CommandObjectSessionHistory : public CommandObjectParsed {
}
history.Dump(result.GetOutputStream(), start_idx.second,
stop_idx.second);
+ result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
}
}
}
diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp
index 34a59d506da7f..b09c65982a277 100644
--- a/lldb/source/Commands/CommandObjectSettings.cpp
+++ b/lldb/source/Commands/CommandObjectSettings.cpp
@@ -409,6 +409,7 @@ class CommandObjectSettingsWrite : public CommandObjectParsed {
if (args.empty()) {
GetDebugger().DumpAllPropertyValues(&clean_ctx, out_file,
OptionValue::eDumpGroupExport);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
return;
}
@@ -419,6 +420,8 @@ class CommandObjectSettingsWrite : public CommandObjectParsed {
result.AppendError(error.AsCString());
}
}
+ if (result.GetStatus() != eReturnStatusFailed)
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
private:
diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp
index b2896e02264f7..0d131bcd626aa 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -1199,6 +1199,8 @@ class CommandObjectSourceList : public CommandObjectParsed {
}
}
}
+ if (result.GetStatus() != eReturnStatusFailed)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
}
const SymbolContextList *GetBreakpointLocations() {
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index eb71e77447281..40da1418e8d7b 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -305,6 +305,8 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
if (!label.empty()) {
if (auto E = target_sp->SetLabel(label))
result.SetError(std::move(E));
+ else
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
return;
}
@@ -989,6 +991,8 @@ class CommandObjectTargetVariable : public CommandObjectParsed {
m_interpreter.PrintWarningsIfNecessary(result.GetOutputStream(),
m_cmd_name);
+ if (result.GetStatus() != eReturnStatusFailed)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
}
OptionGroupOptions m_option_group;
@@ -3104,6 +3108,8 @@ class CommandObjectTargetModulesLoad
result.AppendError("either the \"--file <module>\" or the \"--uuid "
"<uuid>\" option must be specified.\n");
}
+ if (result.GetStatus() != eReturnStatusFailed)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
}
OptionGroupOptions m_option_group;
@@ -3772,6 +3778,7 @@ class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed {
result.GetOutputStream().Printf("\n");
}
+ result.SetStatus(eReturnStatusSuccessFinishResult);
}
CommandOptions m_options;
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index c51cc837dc47b..89b2e14e09c5b 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -782,6 +782,7 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
if (!error.Success()) {
result.AppendMessage(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
return;
}
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index a1a593ddfac63..9b3d4428272cd 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -1559,10 +1559,12 @@ void CommandObjectTypeSummaryAdd::DoExecute(Args &command,
#else
result.AppendError("python is disabled");
#endif
- return;
+ } else {
+ Execute_StringSummary(command, result);
}
- Execute_StringSummary(command, result);
+ if (result.GetStatus() != eReturnStatusFailed)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
}
static bool FixArrayTypeNameWithRegex(ConstString &type_name) {
More information about the lldb-commits
mailing list