@@ -144,9 +144,13 @@ lldb::ExpressionResults
144144UserExpression::Evaluate (ExecutionContext &exe_ctx,
145145 const EvaluateExpressionOptions &options,
146146 llvm::StringRef expr, llvm::StringRef prefix,
147- lldb::ValueObjectSP &result_valobj_sp, Status &error,
147+ lldb::ValueObjectSP &result_valobj_sp,
148148 std::string *fixed_expression, ValueObject *ctx_obj) {
149149 Log *log (GetLog (LLDBLog::Expressions | LLDBLog::Step));
150+ auto set_error = [&](Status error) {
151+ result_valobj_sp = ValueObjectConstResult::Create (
152+ exe_ctx.GetBestExecutionContextScope (), std::move (error));
153+ };
150154
151155 if (ctx_obj) {
152156 static unsigned const ctx_type_mask = lldb::TypeFlags::eTypeIsClass |
@@ -155,8 +159,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
155159 if (!(ctx_obj->GetTypeInfo () & ctx_type_mask)) {
156160 LLDB_LOG (log, " == [UserExpression::Evaluate] Passed a context object of "
157161 " an invalid type, can't run expressions." );
158- error =
159- Status::FromErrorString (" a context object of an invalid type passed" );
162+ set_error (Status (" a context object of an invalid type passed" ));
160163 return lldb::eExpressionSetupError;
161164 }
162165 }
@@ -168,8 +171,8 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
168171 LLDB_LOG (log, " == [UserExpression::Evaluate] Passed a context object of "
169172 " a reference type that can't be dereferenced, can't run "
170173 " expressions." );
171- error = Status::FromErrorString (
172- " passed context object of an reference type cannot be deferenced" );
174+ set_error ( Status (
175+ " passed context object of an reference type cannot be deferenced" )) ;
173176 return lldb::eExpressionSetupError;
174177 }
175178
@@ -187,30 +190,29 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
187190 if (!target) {
188191 LLDB_LOG (log, " == [UserExpression::Evaluate] Passed a NULL target, can't "
189192 " run expressions." );
190- error = Status::FromErrorString (" expression passed a null target" );
193+ set_error ( Status (" expression passed a null target" ) );
191194 return lldb::eExpressionSetupError;
192195 }
193196
194197 Process *process = exe_ctx.GetProcessPtr ();
195198
196- if (process == nullptr && execution_policy == eExecutionPolicyAlways) {
199+ if (process && execution_policy == eExecutionPolicyAlways) {
197200 LLDB_LOG (log, " == [UserExpression::Evaluate] No process, but the policy is "
198201 " eExecutionPolicyAlways" );
199202
200- error = Status::FromErrorString (
201- " expression needed to run but couldn't: no process" );
203+ set_error (Status (" expression needed to run but couldn't: no process" ));
202204
203205 return execution_results;
204206 }
205207
206208 // Since we might need to allocate memory, we need to be stopped to run
207209 // an expression.
208- if (process != nullptr && process->GetState () != lldb::eStateStopped) {
209- error = Status::FromErrorStringWithFormatv (
210+ if (process && process->GetState () != lldb::eStateStopped) {
211+ set_error ( Status::FromErrorStringWithFormatv (
210212 " unable to evaluate expression while the process is {0}: the process "
211213 " must be stopped because the expression might require allocating "
212214 " memory." ,
213- StateAsCString (process->GetState ()));
215+ StateAsCString (process->GetState ()))) ;
214216 return execution_results;
215217 }
216218
@@ -251,13 +253,14 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
251253 language = frame->GetLanguage ();
252254 }
253255
256+ Status error;
254257 lldb::UserExpressionSP user_expression_sp (
255- target->GetUserExpressionForLanguage (expr, full_prefix, language,
256- desired_type, options, ctx_obj,
257- error));
258+ target->GetUserExpressionForLanguage (
259+ expr, full_prefix, language, desired_type, options, ctx_obj, error));
258260 if (error.Fail () || !user_expression_sp) {
259261 LLDB_LOG (log, " == [UserExpression::Evaluate] Getting expression: {0} ==" ,
260262 error.AsCString ());
263+ set_error (std::move (error));
261264 return lldb::eExpressionSetupError;
262265 }
263266
@@ -268,10 +271,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
268271 const bool generate_debug_info = options.GetGenerateDebugInfo ();
269272
270273 if (options.InvokeCancelCallback (lldb::eExpressionEvaluationParse)) {
271- Status error = Status::FromErrorString (
272- " expression interrupted by callback before parse" );
273- result_valobj_sp = ValueObjectConstResult::Create (
274- exe_ctx.GetBestExecutionContextScope (), std::move (error));
274+ set_error (Status (" expression interrupted by callback before parse" ));
275275 return lldb::eExpressionInterrupted;
276276 }
277277
@@ -358,15 +358,13 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
358358 lldb::eExpressionSetupError,
359359 " expression needed to run but couldn't" ));
360360 } else if (execution_policy == eExecutionPolicyTopLevel) {
361- error = Status (UserExpression::kNoResult , lldb::eErrorTypeGeneric);
361+ set_error ( Status (UserExpression::kNoResult , lldb::eErrorTypeGeneric) );
362362 return lldb::eExpressionCompleted;
363363 } else {
364364 if (options.InvokeCancelCallback (lldb::eExpressionEvaluationExecution)) {
365- error = Status::FromError (llvm::make_error<ExpressionError>(
365+ set_error ( Status::FromError (llvm::make_error<ExpressionError>(
366366 lldb::eExpressionInterrupted,
367- " expression interrupted by callback before execution" ));
368- result_valobj_sp = ValueObjectConstResult::Create (
369- exe_ctx.GetBestExecutionContextScope (), std::move (error));
367+ " expression interrupted by callback before execution" )));
370368 return lldb::eExpressionInterrupted;
371369 }
372370
@@ -410,17 +408,14 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
410408 }
411409
412410 if (options.InvokeCancelCallback (lldb::eExpressionEvaluationComplete)) {
413- error = Status::FromError (llvm::make_error<ExpressionError>(
411+ set_error ( Status::FromError (llvm::make_error<ExpressionError>(
414412 lldb::eExpressionInterrupted,
415- " expression interrupted by callback after complete" ));
413+ " expression interrupted by callback after complete" ))) ;
416414 return lldb::eExpressionInterrupted;
417415 }
418416
419- if (result_valobj_sp.get () == nullptr ) {
420- result_valobj_sp = ValueObjectConstResult::Create (
421- exe_ctx.GetBestExecutionContextScope (), std::move (error));
422- }
423-
417+ if (error.Fail ())
418+ set_error (std::move (error));
424419 return execution_results;
425420}
426421
0 commit comments