@@ -144,9 +144,13 @@ lldb::ExpressionResults
144
144
UserExpression::Evaluate (ExecutionContext &exe_ctx,
145
145
const EvaluateExpressionOptions &options,
146
146
llvm::StringRef expr, llvm::StringRef prefix,
147
- lldb::ValueObjectSP &result_valobj_sp, Status &error,
147
+ lldb::ValueObjectSP &result_valobj_sp,
148
148
std::string *fixed_expression, ValueObject *ctx_obj) {
149
149
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
+ };
150
154
151
155
if (ctx_obj) {
152
156
static unsigned const ctx_type_mask = lldb::TypeFlags::eTypeIsClass |
@@ -155,8 +159,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
155
159
if (!(ctx_obj->GetTypeInfo () & ctx_type_mask)) {
156
160
LLDB_LOG (log, " == [UserExpression::Evaluate] Passed a context object of "
157
161
" 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" ));
160
163
return lldb::eExpressionSetupError;
161
164
}
162
165
}
@@ -168,8 +171,8 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
168
171
LLDB_LOG (log, " == [UserExpression::Evaluate] Passed a context object of "
169
172
" a reference type that can't be dereferenced, can't run "
170
173
" 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" )) ;
173
176
return lldb::eExpressionSetupError;
174
177
}
175
178
@@ -181,37 +184,34 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
181
184
const ResultType desired_type = options.DoesCoerceToId ()
182
185
? UserExpression::eResultTypeId
183
186
: UserExpression::eResultTypeAny;
184
- lldb::ExpressionResults execution_results = lldb::eExpressionSetupError;
185
-
186
187
Target *target = exe_ctx.GetTargetPtr ();
187
188
if (!target) {
188
189
LLDB_LOG (log, " == [UserExpression::Evaluate] Passed a NULL target, can't "
189
190
" run expressions." );
190
- error = Status::FromErrorString (" expression passed a null target" );
191
+ set_error ( Status (" expression passed a null target" ) );
191
192
return lldb::eExpressionSetupError;
192
193
}
193
194
194
195
Process *process = exe_ctx.GetProcessPtr ();
195
196
196
- if (process == nullptr && execution_policy == eExecutionPolicyAlways) {
197
+ if (! process && execution_policy == eExecutionPolicyAlways) {
197
198
LLDB_LOG (log, " == [UserExpression::Evaluate] No process, but the policy is "
198
199
" eExecutionPolicyAlways" );
199
200
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" ));
202
202
203
- return execution_results ;
203
+ return lldb::eExpressionSetupError ;
204
204
}
205
205
206
206
// Since we might need to allocate memory, we need to be stopped to run
207
207
// 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 (
210
210
" unable to evaluate expression while the process is {0}: the process "
211
211
" must be stopped because the expression might require allocating "
212
212
" memory." ,
213
- StateAsCString (process->GetState ()));
214
- return execution_results ;
213
+ StateAsCString (process->GetState ()))) ;
214
+ return lldb::eExpressionSetupError ;
215
215
}
216
216
217
217
// Explicitly force the IR interpreter to evaluate the expression when the
@@ -251,13 +251,14 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
251
251
language = frame->GetLanguage ();
252
252
}
253
253
254
+ Status error;
254
255
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));
258
258
if (error.Fail () || !user_expression_sp) {
259
259
LLDB_LOG (log, " == [UserExpression::Evaluate] Getting expression: {0} ==" ,
260
260
error.AsCString ());
261
+ set_error (std::move (error));
261
262
return lldb::eExpressionSetupError;
262
263
}
263
264
@@ -268,10 +269,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
268
269
const bool generate_debug_info = options.GetGenerateDebugInfo ();
269
270
270
271
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" ));
275
273
return lldb::eExpressionInterrupted;
276
274
}
277
275
@@ -287,6 +285,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
287
285
fixed_expression = &tmp_fixed_expression;
288
286
289
287
*fixed_expression = user_expression_sp->GetFixedText ().str ();
288
+ lldb::ExpressionResults execution_results = lldb::eExpressionSetupError;
290
289
291
290
// Swift Playgrounds disable fixits, but SwiftASTContext may get
292
291
// poisoned (see SwiftASTContextForExpressions::ModulesDidLoad())
@@ -365,15 +364,13 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
365
364
lldb::eExpressionSetupError,
366
365
" expression needed to run but couldn't" ));
367
366
} else if (execution_policy == eExecutionPolicyTopLevel) {
368
- error = Status (UserExpression::kNoResult , lldb::eErrorTypeGeneric);
367
+ set_error ( Status (UserExpression::kNoResult , lldb::eErrorTypeGeneric) );
369
368
return lldb::eExpressionCompleted;
370
369
} else {
371
370
if (options.InvokeCancelCallback (lldb::eExpressionEvaluationExecution)) {
372
- error = Status::FromError (llvm::make_error<ExpressionError>(
371
+ set_error ( Status::FromError (llvm::make_error<ExpressionError>(
373
372
lldb::eExpressionInterrupted,
374
- " expression interrupted by callback before execution" ));
375
- result_valobj_sp = ValueObjectConstResult::Create (
376
- exe_ctx.GetBestExecutionContextScope (), std::move (error));
373
+ " expression interrupted by callback before execution" )));
377
374
return lldb::eExpressionInterrupted;
378
375
}
379
376
@@ -417,17 +414,14 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
417
414
}
418
415
419
416
if (options.InvokeCancelCallback (lldb::eExpressionEvaluationComplete)) {
420
- error = Status::FromError (llvm::make_error<ExpressionError>(
417
+ set_error ( Status::FromError (llvm::make_error<ExpressionError>(
421
418
lldb::eExpressionInterrupted,
422
- " expression interrupted by callback after complete" ));
419
+ " expression interrupted by callback after complete" ))) ;
423
420
return lldb::eExpressionInterrupted;
424
421
}
425
422
426
- if (result_valobj_sp.get () == nullptr ) {
427
- result_valobj_sp = ValueObjectConstResult::Create (
428
- exe_ctx.GetBestExecutionContextScope (), std::move (error));
429
- }
430
-
423
+ if (error.Fail ())
424
+ set_error (std::move (error));
431
425
return execution_results;
432
426
}
433
427
0 commit comments