Skip to content

Commit fc52ee3

Browse files
authored
[lldb][ClangUserExpression][NFCI] Pass the most specific ExecutionContextScope possible into ClangExpressionParser (#87657)
The `ClangExpressionParser` takes an `ExecutionContextScope` which it uses to query the `Process`/`Target`/`StackFrame` to set various compiler options in preparation for parsing an expression. However, `TryParse` constructs the parser with a `Process` or `Target`, never a `StackFrame`. So when the parser tries to retrieve the current `StackFrame` from the `exe_scope`, it doesn't succeed. In future patches we want to query the `StackFrame` from within the `ClangExpressionParser` constructor. This patch simplifies `TryParse`, by removing the redundant `exe_scope` parameter, and instead uses the `exe_ctx` to derive the most fitting `exe_scope` to pass into `ClangExpressionParser`. Not entirely sure how to test this. This patch is a prerequisite to get subsequent patches that set `LangOpts` based on the current `StackFrame` to work.
1 parent b2ea38f commit fc52ee3

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ bool ClangUserExpression::PrepareForParsing(
553553
}
554554

555555
bool ClangUserExpression::TryParse(
556-
DiagnosticManager &diagnostic_manager, ExecutionContextScope *exe_scope,
557-
ExecutionContext &exe_ctx, lldb_private::ExecutionPolicy execution_policy,
558-
bool keep_result_in_memory, bool generate_debug_info) {
556+
DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
557+
lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory,
558+
bool generate_debug_info) {
559559
m_materializer_up = std::make_unique<Materializer>();
560560

561561
ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
@@ -574,7 +574,8 @@ bool ClangUserExpression::TryParse(
574574
}
575575

576576
m_parser = std::make_unique<ClangExpressionParser>(
577-
exe_scope, *this, generate_debug_info, m_include_directories, m_filename);
577+
exe_ctx.GetBestExecutionContextScope(), *this, generate_debug_info,
578+
m_include_directories, m_filename);
578579

579580
unsigned num_errors = m_parser->Parse(diagnostic_manager);
580581

@@ -669,15 +670,8 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
669670
// Parse the expression
670671
//
671672

672-
Process *process = exe_ctx.GetProcessPtr();
673-
ExecutionContextScope *exe_scope = process;
674-
675-
if (!exe_scope)
676-
exe_scope = exe_ctx.GetTargetPtr();
677-
678-
bool parse_success = TryParse(diagnostic_manager, exe_scope, exe_ctx,
679-
execution_policy, keep_result_in_memory,
680-
generate_debug_info);
673+
bool parse_success = TryParse(diagnostic_manager, exe_ctx, execution_policy,
674+
keep_result_in_memory, generate_debug_info);
681675
// If the expression failed to parse, check if retrying parsing with a loaded
682676
// C++ module is possible.
683677
if (!parse_success && shouldRetryWithCppModule(*target, execution_policy)) {
@@ -695,9 +689,8 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
695689
// so recreate those.
696690
CreateSourceCode(retry_manager, exe_ctx, m_imported_cpp_modules,
697691
/*for_completion*/ false);
698-
parse_success = TryParse(retry_manager, exe_scope, exe_ctx,
699-
execution_policy, keep_result_in_memory,
700-
generate_debug_info);
692+
parse_success = TryParse(retry_manager, exe_ctx, execution_policy,
693+
keep_result_in_memory, generate_debug_info);
701694
// Return the parse diagnostics if we were successful.
702695
if (parse_success)
703696
diagnostic_manager = std::move(retry_manager);
@@ -759,6 +752,7 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
759752
}
760753
}
761754

755+
Process *process = exe_ctx.GetProcessPtr();
762756
if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
763757
m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
764758
return true;
@@ -840,13 +834,8 @@ bool ClangUserExpression::Complete(ExecutionContext &exe_ctx,
840834
DeclMap()->SetLookupsEnabled(true);
841835
}
842836

843-
Process *process = exe_ctx.GetProcessPtr();
844-
ExecutionContextScope *exe_scope = process;
845-
846-
if (!exe_scope)
847-
exe_scope = exe_ctx.GetTargetPtr();
848-
849-
ClangExpressionParser parser(exe_scope, *this, false);
837+
ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this,
838+
false);
850839

851840
// We have to find the source code location where the user text is inside
852841
// the transformed expression code. When creating the transformed text, we

lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ class ClangUserExpression : public LLVMUserExpression {
185185
/// The parameter have the same meaning as in ClangUserExpression::Parse.
186186
/// \see ClangUserExpression::Parse
187187
bool TryParse(DiagnosticManager &diagnostic_manager,
188-
ExecutionContextScope *exe_scope, ExecutionContext &exe_ctx,
189-
lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory,
190-
bool generate_debug_info);
188+
ExecutionContext &exe_ctx,
189+
lldb_private::ExecutionPolicy execution_policy,
190+
bool keep_result_in_memory, bool generate_debug_info);
191191

192192
void SetupCppModuleImports(ExecutionContext &exe_ctx);
193193

0 commit comments

Comments
 (0)