Skip to content

Commit 9473e16

Browse files
[DWIMPrint] Move the setting of the result status into dump_val_object (#96232)
Previously the result would get overwritten by a success on all code paths. This is another NFC change for TypeSystemClang, because an object description cannot actually fail there. It will have different behavior in the Swift plugin.
1 parent eea150c commit 9473e16

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,14 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
141141
maybe_add_hint(output);
142142
result.GetOutputStream() << output;
143143
} else {
144-
if (llvm::Error error =
145-
valobj.Dump(result.GetOutputStream(), dump_options))
144+
llvm::Error error =
145+
valobj.Dump(result.GetOutputStream(), dump_options);
146+
if (error) {
146147
result.AppendError(toString(std::move(error)));
148+
return;
149+
}
147150
}
151+
result.SetStatus(eReturnStatusSuccessFinishResult);
148152
};
149153

150154
// First, try `expr` as the name of a frame variable.
@@ -165,7 +169,6 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
165169
}
166170

167171
dump_val_object(*valobj_sp);
168-
result.SetStatus(eReturnStatusSuccessFinishResult);
169172
return;
170173
}
171174
}
@@ -176,7 +179,6 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
176179
if (auto var_sp = state->GetVariable(expr))
177180
if (auto valobj_sp = var_sp->GetValueObject()) {
178181
dump_val_object(*valobj_sp);
179-
result.SetStatus(eReturnStatusSuccessFinishResult);
180182
return;
181183
}
182184

@@ -197,34 +199,36 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
197199
error_stream << " " << fixed_expression << "\n";
198200
}
199201

200-
if (expr_result == eExpressionCompleted) {
201-
if (verbosity != eDWIMPrintVerbosityNone) {
202-
StringRef flags;
203-
if (args.HasArgs())
204-
flags = args.GetArgStringWithDelimiter();
205-
result.AppendMessageWithFormatv("note: ran `expression {0}{1}`", flags,
206-
expr);
207-
}
208-
209-
if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
210-
dump_val_object(*valobj_sp);
211-
212-
if (suppress_result)
213-
if (auto result_var_sp =
214-
target.GetPersistentVariable(valobj_sp->GetName())) {
215-
auto language = valobj_sp->GetPreferredDisplayLanguage();
216-
if (auto *persistent_state =
217-
target.GetPersistentExpressionStateForLanguage(language))
218-
persistent_state->RemovePersistentVariable(result_var_sp);
219-
}
220-
221-
result.SetStatus(eReturnStatusSuccessFinishResult);
222-
} else {
202+
// If the expression failed, return an error.
203+
if (expr_result != eExpressionCompleted) {
223204
if (valobj_sp)
224205
result.SetError(valobj_sp->GetError());
225206
else
226207
result.AppendErrorWithFormatv(
227208
"unknown error evaluating expression `{0}`", expr);
209+
return;
210+
}
211+
212+
if (verbosity != eDWIMPrintVerbosityNone) {
213+
StringRef flags;
214+
if (args.HasArgs())
215+
flags = args.GetArgStringWithDelimiter();
216+
result.AppendMessageWithFormatv("note: ran `expression {0}{1}`", flags,
217+
expr);
228218
}
219+
220+
if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
221+
dump_val_object(*valobj_sp);
222+
else
223+
result.SetStatus(eReturnStatusSuccessFinishResult);
224+
225+
if (suppress_result)
226+
if (auto result_var_sp =
227+
target.GetPersistentVariable(valobj_sp->GetName())) {
228+
auto language = valobj_sp->GetPreferredDisplayLanguage();
229+
if (auto *persistent_state =
230+
target.GetPersistentExpressionStateForLanguage(language))
231+
persistent_state->RemovePersistentVariable(result_var_sp);
232+
}
229233
}
230234
}

0 commit comments

Comments
 (0)