@@ -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
@@ -181,37 +184,34 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
181184 const ResultType desired_type = options.DoesCoerceToId ()
182185 ? UserExpression::eResultTypeId
183186 : UserExpression::eResultTypeAny;
184- lldb::ExpressionResults execution_results = lldb::eExpressionSetupError;
185-
186187 Target *target = exe_ctx.GetTargetPtr ();
187188 if (!target) {
188189 LLDB_LOG (log, " == [UserExpression::Evaluate] Passed a NULL target, can't "
189190 " run expressions." );
190- error = Status::FromErrorString (" expression passed a null target" );
191+ set_error ( Status (" expression passed a null target" ) );
191192 return lldb::eExpressionSetupError;
192193 }
193194
194195 Process *process = exe_ctx.GetProcessPtr ();
195196
196- if (process == nullptr && execution_policy == eExecutionPolicyAlways) {
197+ if (! process && execution_policy == eExecutionPolicyAlways) {
197198 LLDB_LOG (log, " == [UserExpression::Evaluate] No process, but the policy is "
198199 " eExecutionPolicyAlways" );
199200
200- error = Status::FromErrorString (
201- " expression needed to run but couldn't: no process" );
201+ set_error (Status (" expression needed to run but couldn't: no process" ));
202202
203- return execution_results ;
203+ return lldb::eExpressionSetupError ;
204204 }
205205
206206 // Since we might need to allocate memory, we need to be stopped to run
207207 // an expression.
208- if (process != nullptr && process->GetState () != lldb::eStateStopped) {
209- error = Status::FromErrorStringWithFormatv (
208+ if (process && process->GetState () != lldb::eStateStopped) {
209+ set_error ( Status::FromErrorStringWithFormatv (
210210 " unable to evaluate expression while the process is {0}: the process "
211211 " must be stopped because the expression might require allocating "
212212 " memory." ,
213- StateAsCString (process->GetState ()));
214- return execution_results ;
213+ StateAsCString (process->GetState ()))) ;
214+ return lldb::eExpressionSetupError ;
215215 }
216216
217217 // Explicitly force the IR interpreter to evaluate the expression when the
@@ -251,13 +251,14 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
251251 language = frame->GetLanguage ();
252252 }
253253
254+ Status error;
254255 lldb::UserExpressionSP user_expression_sp (
255- target->GetUserExpressionForLanguage (expr, full_prefix, language,
256- desired_type, options, ctx_obj,
257- error));
256+ target->GetUserExpressionForLanguage (
257+ expr, full_prefix, language, desired_type, options, ctx_obj, error));
258258 if (error.Fail () || !user_expression_sp) {
259259 LLDB_LOG (log, " == [UserExpression::Evaluate] Getting expression: {0} ==" ,
260260 error.AsCString ());
261+ set_error (std::move (error));
261262 return lldb::eExpressionSetupError;
262263 }
263264
@@ -268,10 +269,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
268269 const bool generate_debug_info = options.GetGenerateDebugInfo ();
269270
270271 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));
272+ set_error (Status (" expression interrupted by callback before parse" ));
275273 return lldb::eExpressionInterrupted;
276274 }
277275
@@ -287,6 +285,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
287285 fixed_expression = &tmp_fixed_expression;
288286
289287 *fixed_expression = user_expression_sp->GetFixedText ().str ();
288+ lldb::ExpressionResults execution_results = lldb::eExpressionSetupError;
290289
291290 // If there is a fixed expression, try to parse it:
292291 if (!parse_success) {
@@ -358,15 +357,13 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
358357 lldb::eExpressionSetupError,
359358 " expression needed to run but couldn't" ));
360359 } else if (execution_policy == eExecutionPolicyTopLevel) {
361- error = Status (UserExpression::kNoResult , lldb::eErrorTypeGeneric);
360+ set_error ( Status (UserExpression::kNoResult , lldb::eErrorTypeGeneric) );
362361 return lldb::eExpressionCompleted;
363362 } else {
364363 if (options.InvokeCancelCallback (lldb::eExpressionEvaluationExecution)) {
365- error = Status::FromError (llvm::make_error<ExpressionError>(
364+ set_error ( Status::FromError (llvm::make_error<ExpressionError>(
366365 lldb::eExpressionInterrupted,
367- " expression interrupted by callback before execution" ));
368- result_valobj_sp = ValueObjectConstResult::Create (
369- exe_ctx.GetBestExecutionContextScope (), std::move (error));
366+ " expression interrupted by callback before execution" )));
370367 return lldb::eExpressionInterrupted;
371368 }
372369
@@ -410,17 +407,14 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
410407 }
411408
412409 if (options.InvokeCancelCallback (lldb::eExpressionEvaluationComplete)) {
413- error = Status::FromError (llvm::make_error<ExpressionError>(
410+ set_error ( Status::FromError (llvm::make_error<ExpressionError>(
414411 lldb::eExpressionInterrupted,
415- " expression interrupted by callback after complete" ));
412+ " expression interrupted by callback after complete" ))) ;
416413 return lldb::eExpressionInterrupted;
417414 }
418415
419- if (result_valobj_sp.get () == nullptr ) {
420- result_valobj_sp = ValueObjectConstResult::Create (
421- exe_ctx.GetBestExecutionContextScope (), std::move (error));
422- }
423-
416+ if (error.Fail ())
417+ set_error (std::move (error));
424418 return execution_results;
425419}
426420
0 commit comments