[Lldb-commits] [lldb] [lldb][ClangUserExpression][NFCI] Pass the most specific ExecutionContextScope possible into ClangExpressionParser (PR #87657)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 4 14:39:01 PDT 2024


================
@@ -553,9 +553,9 @@ bool ClangUserExpression::PrepareForParsing(
 }
 
 bool ClangUserExpression::TryParse(
-    DiagnosticManager &diagnostic_manager, ExecutionContextScope *exe_scope,
-    ExecutionContext &exe_ctx, lldb_private::ExecutionPolicy execution_policy,
-    bool keep_result_in_memory, bool generate_debug_info) {
+    DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
+    lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory,
+    bool generate_debug_info) {
----------------
clayborg wrote:

Jim made comments below. `ExecutionContextScope *` is just as good as an ExecutionContext, but it is actually more specific as a `Target`, `Process`, `Thread` and `StackFrame` are all `ExecutionContextScope *` objects. They just know how to re-create any items needed. So a `StackFrame` can use `ExecutionContextScope` APIs (which is virtually overrides) to get the thread, process and target. The `Thread` can get the process and target. The `Process` can get the target. So it is no better or worse, it just specifies one thing would be the same as having an `ExecutionContext` filled out as much as needed. We do need to be careful to pass in the right thing as Jim said, where if we only want the `Target` to be used, we shouldn't pass in a `StackFrame` as the `ExecutionContextScope *`, but this will be exactly the same as passing a `ExecutionContext` that has the stack frame filled out when we only want to consult the target. So no real difference, and using `ExecutionContextScope *` is better since we can control what we pass as the root of where to start looking whereas if we pass in a fully filled out ExecutionContext, we will always consult the deepest item (Stack, then frame, then thread, then process/target) if it is filled out. 

So if the ExecutionContext is always filled out correctly to the right depth, then calling the `exe_ctx.GetBestExecutionContextScope()` suggestion will work. If not, then we need to pass in the right level, or modify the ExecutionContext and remove items from it.

https://github.com/llvm/llvm-project/pull/87657


More information about the lldb-commits mailing list