[lldb-dev] Problem unwinding from inside of a CRT function

Zachary Turner zturner at google.com
Fri Jan 16 13:12:45 PST 2015

On Fri Jan 16 2015 at 12:45:00 PM <jingham at apple.com> wrote:

> > On Jan 16, 2015, at 12:14 PM, Zachary Turner <zturner at google.com> wrote:
> >
> > I'm still trying to wrap my head around the way LLDB does things.
> >
> > If I understand correctly, when you run thread step-over, it enters
> single step mode (by setting the trap flag on the CPU).  Every time the CPU
> traps, LLDB picks this up and asks the ThreadPlan "should i stop now?"
> "should i stop now?" until the ThreadPlan returns true.  And part of this
> "should i stop now" involves generating an unwind.
> >
> That's close, but not quite correct.
> 1) In the original implementation, (and this is how gdb does it, BTW) lldb
> single-stepped till "something interesting happened."  As an optimization,
> when you are doing any kind of step through source range, I changed lldb so
> it runs from "instruction that could branch" to "instruction that could
> branch" using breakpoints.  Then when it hits an instruction that could
> branch it single steps that instruction, and then figures out from where
> that went what to do next.
> BTW, if it were helpful to figure out what to do next, we could store some
> info (the old stack frame or whatever) when we hit a branch instruction,
> and then use it when the single-step completed.  I haven't needed to do
> that yet, however; Jason's always been able to get the unwinder work
> reliably enough not to require this.
Let's say you're stopped at the first line of foo() here.

1.     void foo()
2.     {
3. ->     printf(
4.              "Line 1\n");
5.         printf("Line 2\n");
6.         printf("Line 3\n");
7.     }

When you step-over, why can't it just say: Ok, current source line is 3.
Debug info tells me that the next instruction begins on line 5.  Line 5
corresponds to address 0x12345678.  Put a breakpoint on 0x12345678.  To
account for the fact that foo() may be recursive, also save off a copy of
the stack pointer.  When the breakpoint is hit, stop if the stack pointer
is the same or less than the saved value (depending on the definition of
"less" for your architecture), otherwise don't stop.

(Still trying to process the rest of the points in your email)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20150116/6b0dc2b0/attachment.html>

More information about the lldb-dev mailing list