-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Refactor UserExpression::Evaluate to only have one error channel. #117186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,9 +144,13 @@ lldb::ExpressionResults | |
UserExpression::Evaluate(ExecutionContext &exe_ctx, | ||
const EvaluateExpressionOptions &options, | ||
llvm::StringRef expr, llvm::StringRef prefix, | ||
lldb::ValueObjectSP &result_valobj_sp, Status &error, | ||
lldb::ValueObjectSP &result_valobj_sp, | ||
std::string *fixed_expression, ValueObject *ctx_obj) { | ||
Log *log(GetLog(LLDBLog::Expressions | LLDBLog::Step)); | ||
auto set_error = [&](Status error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the interest of getting rid of Status, should this take an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ValueObject is the prime remaining user of long-lived Status objects, so it would be a purely cosmetic change. |
||
result_valobj_sp = ValueObjectConstResult::Create( | ||
exe_ctx.GetBestExecutionContextScope(), std::move(error)); | ||
}; | ||
|
||
if (ctx_obj) { | ||
static unsigned const ctx_type_mask = lldb::TypeFlags::eTypeIsClass | | ||
|
@@ -155,8 +159,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, | |
if (!(ctx_obj->GetTypeInfo() & ctx_type_mask)) { | ||
LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a context object of " | ||
"an invalid type, can't run expressions."); | ||
error = | ||
Status::FromErrorString("a context object of an invalid type passed"); | ||
set_error(Status("a context object of an invalid type passed")); | ||
return lldb::eExpressionSetupError; | ||
} | ||
} | ||
|
@@ -168,8 +171,8 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, | |
LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a context object of " | ||
"a reference type that can't be dereferenced, can't run " | ||
"expressions."); | ||
error = Status::FromErrorString( | ||
"passed context object of an reference type cannot be deferenced"); | ||
set_error(Status( | ||
"passed context object of an reference type cannot be deferenced")); | ||
return lldb::eExpressionSetupError; | ||
} | ||
|
||
|
@@ -181,37 +184,34 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, | |
const ResultType desired_type = options.DoesCoerceToId() | ||
? UserExpression::eResultTypeId | ||
: UserExpression::eResultTypeAny; | ||
lldb::ExpressionResults execution_results = lldb::eExpressionSetupError; | ||
|
||
Target *target = exe_ctx.GetTargetPtr(); | ||
if (!target) { | ||
LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a NULL target, can't " | ||
"run expressions."); | ||
error = Status::FromErrorString("expression passed a null target"); | ||
set_error(Status("expression passed a null target")); | ||
return lldb::eExpressionSetupError; | ||
} | ||
|
||
Process *process = exe_ctx.GetProcessPtr(); | ||
|
||
if (process == nullptr && execution_policy == eExecutionPolicyAlways) { | ||
if (!process && execution_policy == eExecutionPolicyAlways) { | ||
LLDB_LOG(log, "== [UserExpression::Evaluate] No process, but the policy is " | ||
"eExecutionPolicyAlways"); | ||
|
||
error = Status::FromErrorString( | ||
"expression needed to run but couldn't: no process"); | ||
set_error(Status("expression needed to run but couldn't: no process")); | ||
|
||
return execution_results; | ||
return lldb::eExpressionSetupError; | ||
} | ||
|
||
// Since we might need to allocate memory, we need to be stopped to run | ||
// an expression. | ||
if (process != nullptr && process->GetState() != lldb::eStateStopped) { | ||
error = Status::FromErrorStringWithFormatv( | ||
if (process && process->GetState() != lldb::eStateStopped) { | ||
set_error(Status::FromErrorStringWithFormatv( | ||
"unable to evaluate expression while the process is {0}: the process " | ||
"must be stopped because the expression might require allocating " | ||
"memory.", | ||
StateAsCString(process->GetState())); | ||
return execution_results; | ||
StateAsCString(process->GetState()))); | ||
return lldb::eExpressionSetupError; | ||
} | ||
|
||
// Explicitly force the IR interpreter to evaluate the expression when the | ||
|
@@ -251,13 +251,14 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, | |
language = frame->GetLanguage(); | ||
} | ||
|
||
Status error; | ||
lldb::UserExpressionSP user_expression_sp( | ||
target->GetUserExpressionForLanguage(expr, full_prefix, language, | ||
desired_type, options, ctx_obj, | ||
error)); | ||
target->GetUserExpressionForLanguage( | ||
expr, full_prefix, language, desired_type, options, ctx_obj, error)); | ||
if (error.Fail() || !user_expression_sp) { | ||
LLDB_LOG(log, "== [UserExpression::Evaluate] Getting expression: {0} ==", | ||
error.AsCString()); | ||
set_error(std::move(error)); | ||
return lldb::eExpressionSetupError; | ||
} | ||
|
||
|
@@ -268,10 +269,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, | |
const bool generate_debug_info = options.GetGenerateDebugInfo(); | ||
|
||
if (options.InvokeCancelCallback(lldb::eExpressionEvaluationParse)) { | ||
Status error = Status::FromErrorString( | ||
"expression interrupted by callback before parse"); | ||
result_valobj_sp = ValueObjectConstResult::Create( | ||
exe_ctx.GetBestExecutionContextScope(), std::move(error)); | ||
set_error(Status("expression interrupted by callback before parse")); | ||
return lldb::eExpressionInterrupted; | ||
} | ||
|
||
|
@@ -287,6 +285,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, | |
fixed_expression = &tmp_fixed_expression; | ||
|
||
*fixed_expression = user_expression_sp->GetFixedText().str(); | ||
lldb::ExpressionResults execution_results = lldb::eExpressionSetupError; | ||
|
||
// If there is a fixed expression, try to parse it: | ||
if (!parse_success) { | ||
|
@@ -358,15 +357,13 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, | |
lldb::eExpressionSetupError, | ||
"expression needed to run but couldn't")); | ||
} else if (execution_policy == eExecutionPolicyTopLevel) { | ||
error = Status(UserExpression::kNoResult, lldb::eErrorTypeGeneric); | ||
set_error(Status(UserExpression::kNoResult, lldb::eErrorTypeGeneric)); | ||
return lldb::eExpressionCompleted; | ||
} else { | ||
if (options.InvokeCancelCallback(lldb::eExpressionEvaluationExecution)) { | ||
error = Status::FromError(llvm::make_error<ExpressionError>( | ||
set_error(Status::FromError(llvm::make_error<ExpressionError>( | ||
lldb::eExpressionInterrupted, | ||
"expression interrupted by callback before execution")); | ||
result_valobj_sp = ValueObjectConstResult::Create( | ||
exe_ctx.GetBestExecutionContextScope(), std::move(error)); | ||
"expression interrupted by callback before execution"))); | ||
return lldb::eExpressionInterrupted; | ||
} | ||
|
||
|
@@ -410,17 +407,14 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, | |
} | ||
|
||
if (options.InvokeCancelCallback(lldb::eExpressionEvaluationComplete)) { | ||
error = Status::FromError(llvm::make_error<ExpressionError>( | ||
set_error(Status::FromError(llvm::make_error<ExpressionError>( | ||
lldb::eExpressionInterrupted, | ||
"expression interrupted by callback after complete")); | ||
"expression interrupted by callback after complete"))); | ||
return lldb::eExpressionInterrupted; | ||
} | ||
|
||
if (result_valobj_sp.get() == nullptr) { | ||
result_valobj_sp = ValueObjectConstResult::Create( | ||
exe_ctx.GetBestExecutionContextScope(), std::move(error)); | ||
} | ||
|
||
if (error.Fail()) | ||
set_error(std::move(error)); | ||
return execution_results; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.