Skip to content

Commit 0e8fa5a

Browse files
committed
[DWIMPrint] Move the setting of the result status into dump_val_object (llvm#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. (cherry picked from commit 9473e16)
1 parent b82e193 commit 0e8fa5a

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
@@ -150,10 +150,14 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
150150
maybe_add_hint(output);
151151
result.GetOutputStream() << output;
152152
} else {
153-
if (llvm::Error error =
154-
valobj.Dump(result.GetOutputStream(), dump_options))
153+
llvm::Error error =
154+
valobj.Dump(result.GetOutputStream(), dump_options);
155+
if (error) {
155156
result.AppendError(toString(std::move(error)));
157+
return;
158+
}
156159
}
160+
result.SetStatus(eReturnStatusSuccessFinishResult);
157161
};
158162

159163
// First, try `expr` as the name of a frame variable.
@@ -174,7 +178,6 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
174178
}
175179

176180
dump_val_object(*valobj_sp);
177-
result.SetStatus(eReturnStatusSuccessFinishResult);
178181
return;
179182
}
180183
}
@@ -222,7 +225,6 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
222225
if (auto var_sp = state->GetVariable(expr))
223226
if (auto valobj_sp = var_sp->GetValueObject()) {
224227
dump_val_object(*valobj_sp);
225-
result.SetStatus(eReturnStatusSuccessFinishResult);
226228
return;
227229
}
228230

@@ -243,34 +245,36 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
243245
error_stream << " " << fixed_expression << "\n";
244246
}
245247

246-
if (expr_result == eExpressionCompleted) {
247-
if (verbosity != eDWIMPrintVerbosityNone) {
248-
StringRef flags;
249-
if (args.HasArgs())
250-
flags = args.GetArgStringWithDelimiter();
251-
result.AppendMessageWithFormatv("note: ran `expression {0}{1}`", flags,
252-
expr);
253-
}
254-
255-
if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
256-
dump_val_object(*valobj_sp);
257-
258-
if (suppress_result)
259-
if (auto result_var_sp =
260-
target.GetPersistentVariable(valobj_sp->GetName())) {
261-
auto language = valobj_sp->GetPreferredDisplayLanguage();
262-
if (auto *persistent_state =
263-
target.GetPersistentExpressionStateForLanguage(language))
264-
persistent_state->RemovePersistentVariable(result_var_sp);
265-
}
266-
267-
result.SetStatus(eReturnStatusSuccessFinishResult);
268-
} else {
248+
// If the expression failed, return an error.
249+
if (expr_result != eExpressionCompleted) {
269250
if (valobj_sp)
270251
result.SetError(valobj_sp->GetError());
271252
else
272253
result.AppendErrorWithFormatv(
273254
"unknown error evaluating expression `{0}`", expr);
255+
return;
256+
}
257+
258+
if (verbosity != eDWIMPrintVerbosityNone) {
259+
StringRef flags;
260+
if (args.HasArgs())
261+
flags = args.GetArgStringWithDelimiter();
262+
result.AppendMessageWithFormatv("note: ran `expression {0}{1}`", flags,
263+
expr);
274264
}
265+
266+
if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
267+
dump_val_object(*valobj_sp);
268+
else
269+
result.SetStatus(eReturnStatusSuccessFinishResult);
270+
271+
if (suppress_result)
272+
if (auto result_var_sp =
273+
target.GetPersistentVariable(valobj_sp->GetName())) {
274+
auto language = valobj_sp->GetPreferredDisplayLanguage();
275+
if (auto *persistent_state =
276+
target.GetPersistentExpressionStateForLanguage(language))
277+
persistent_state->RemovePersistentVariable(result_var_sp);
278+
}
275279
}
276280
}

0 commit comments

Comments
 (0)