Skip to content

Commit a4197e4

Browse files
authored
Add docs describing how the thread plan stack affects stepping (#110167)
This is a convenient little feature of lldb, but if you didn't know it was there you'd likely never discover it.
1 parent 6fd870b commit a4197e4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

lldb/docs/use/tutorial.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,43 @@ This command will run the thread in the current frame until it reaches line 100
536536
in this frame or stops if it leaves the current frame. This is a pretty close
537537
equivalent to GDB's ``until`` command.
538538

539+
One other useful thing to note about the lldb stepping commands is that they
540+
are implemented as a stack of interruptible operations. Until the operation -
541+
e.g. step to the next line - is completed, it will remain on the
542+
stack. If the step over is interrupted and control returned to you,
543+
any new stepping commands you issue won't replace the step-over, but instead
544+
their operations will be pushed onto the stack after the original step over.
545+
Then each of them will be retired as they are completed, finally returning to the
546+
original step over operation.
547+
548+
Suppose, for instance, you ``step-over`` a source line with a function call.
549+
If there is a breakpoint in that function, hitting the breakpoint will interrupt
550+
the step over. At that point, you will likely want to examine the state at
551+
the breakpoint, maybe stepping around in that frame, or stepping into other
552+
functions, running some expressions, etc.
553+
554+
Because the original step-over has remained on the stack, when you've finished
555+
your examinations, a simple ``continue`` will resume the original ``step-over``
556+
operation, and you will arrive at the end of your starting source line in the
557+
original frame.
558+
559+
This saves you from having to keep track of your original intention, and manually
560+
issuing the requisite number of ``step-out`` commands to get back to the frame
561+
you were stepping over. The stack maintains that information for you.
562+
563+
Hand-called functions using the ``expr`` command are also implemented by
564+
operations on this same stack. So if you are calling some code with the ``expr`` command,
565+
and hit a breakpoint during the evaluation of that code, you can examine
566+
the state where you stopped, and when you're satisfied, issue a
567+
``continue`` to finish the expression evaluation operation and print the function
568+
result.
569+
570+
You can examine the state of the operations stack using the ``thread plan list``
571+
command, and if, for instance, you decide you don't actually want that outermost
572+
next to continue running, you can remove it with the ``thread plan discard``
573+
command. If you are interested in following this process in more detail, the
574+
``lldb step`` logging channel is useful source of information.
575+
539576
A process, by default, will share the LLDB terminal with the inferior process.
540577
When in this mode, much like when debugging with GDB, when the process is
541578
running anything you type will go to the ``STDIN`` of the inferior process. To

0 commit comments

Comments
 (0)