[all-commits] [llvm/llvm-project] 554f4d: [lldb][Target] RunThreadPlan to save/restore the E...

Michael Buch via All-commits all-commits at lists.llvm.org
Thu Apr 3 03:10:37 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 554f4d1a5769357ee8438c23f572d595c720ff3c
      https://github.com/llvm/llvm-project/commit/554f4d1a5769357ee8438c23f572d595c720ff3c
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2025-04-03 (Thu, 03 Apr 2025)

  Changed paths:
    M lldb/source/Target/Process.cpp
    A lldb/test/API/commands/expression/expr-from-non-zero-frame/Makefile
    A lldb/test/API/commands/expression/expr-from-non-zero-frame/TestExprFromNonZeroFrame.py
    A lldb/test/API/commands/expression/expr-from-non-zero-frame/main.c

  Log Message:
  -----------
  [lldb][Target] RunThreadPlan to save/restore the ExecutionContext's frame if one exists (#134097)

When using `SBFrame::EvaluateExpression` on a frame that's not the
currently selected frame, we would sometimes run into errors such as:
```
error: error: The context has changed before we could JIT the expression!
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
```

During expression parsing, we call `RunStaticInitializers`. On our
internal fork this happens quite frequently because any usage of, e.g.,
function pointers, will inject ptrauth fixup code into the expression.
The static initializers are run using `RunThreadPlan`. The
`ExecutionContext::m_frame_sp` going into the `RunThreadPlan` is the
`SBFrame` that we called `EvaluateExpression` on. LLDB then tries to
save this frame to restore it after the thread-plan ran (the restore
occurs by unconditionally overwriting whatever is in
`ExecutionContext::m_frame_sp`). However, if the `selected_frame_sp` is
not the same as the `SBFrame`, then `RunThreadPlan` would set the
`ExecutionContext`'s frame to a different frame than what we started
with. When we `PrepareToExecuteJITExpression`, LLDB checks whether the
`ExecutionContext` frame changed from when we initially
`EvaluateExpression`, and if did, bails out with the error above.

One such test-case is attached. This currently passes regardless of the
fix because our ptrauth static initializers code isn't upstream yet. But
the plan is to upstream it soon.

This patch addresses the issue by saving/restoring the frame of the
incoming `ExecutionContext`, if such frame exists. Otherwise, fall back
to using the selected frame.

rdar://147456589



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list