[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #112079)

Robert O'Callahan via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 11 01:56:36 PST 2024


rocallahan wrote:

The approach I implemented fails when evaluating a breakpoint condition requires running a function in the target process, e.g. evaluating a breakpoint condition that's a function call, or calling `mmap()` to allocate memory for JITted code. That pushes a `ThreadPlanCallFunction` onto the plan stack and resumes the target in the forward direction. With my code as-is, switching directions discards all thread plans before resuming, so we discard the `ThreadPlanCallFunction` and everything breaks.

In this case we need the `ThreadPlanCallFunction` to complete normally and then when the breakpoint condition has finished evaluating to false, resume execution in the reverse direction. So it seems like we should use the thread plan stack --- associate a direction with each thread plan, so `ThreadPlanCallFunction` executes forward and completes, but after it has been popped, the thread plan below it will tell us to execute in reverse.

So I tried adding a virtual function `ThreadPlan::GetDirection()` and [introducing `ThreadPlanReverseContinue`](https://github.com/rocallahan/llvm-project/tree/reverse-continue-thread-plan) which executes in reverse. `SBProcess::ReverseContinue()` pushes a `ThreadPlanReverseContinue` onto the plan stack and resumes. There is big question about when/how this plan should be removed. In principle we should remove it when a stop is reported to the user. I tried making `ThreadPlanReverseContinue::MischiefManaged()` always return true. That doesn't work because it makes us pop the `ThreadPlanReverseContinue` before the breakpoint condition is even evaluated. So what would be a good way to pop `ThreadPlanReverseContinue`?

An alternative approach would be to store a "current direction" in `ThreadPlanBase` and have `SBProcess::Continue/ReverseContinue` both set it. But that is kind of scary because any execution command that doesn't go through `SBProcess::Continue/ReverseContinue` will resume in the last-used direction. But let me know if that sounds better.

@jimingham this all sounds like your territory.

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


More information about the lldb-commits mailing list