Skip to content

Commit 4d0cd52

Browse files
committed
Fix formatting
1 parent f477350 commit 4d0cd52

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

clang/docs/DebuggingCoroutines.rst

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ generator and its internal state.
180180
To do so, we can simply look into the ``gen.hdl`` variable. LLDB comes with a
181181
pretty printer for ``std::coroutine_handle`` which will show us the internal
182182
state of the coroutine. For GDB, you will have to use the ``show-coro-frame``
183-
command provided by the :ref:`GDB Debugger Script`.
183+
command provided by the :ref:`gdb-script`.
184184

185185
.. image:: ./coro-generator-suspended.png
186186

@@ -360,7 +360,7 @@ type of a task is a template argument. For simplicity's sake, we hard-coded the
360360
``int`` type in this example.
361361

362362
Stack traces of in-flight coroutines
363-
-----------------------------------
363+
------------------------------------
364364

365365
Let's assume you have the following program and set a breakpoint inside the
366366
``write_output`` function. There are multiple call paths through which this
@@ -407,7 +407,7 @@ When using LLDB's CLI, the command ``p --ptr-depth 4 __promise`` might also be
407407
useful to automatically dereference all the pointers up to the given depth.
408408

409409
To get a flat representation of that call stack, we can use a debugger script,
410-
such as the one shown in the :ref:`LLDB Debugger Script` section. With that
410+
such as the one shown in the :ref:`lldb-script` section. With that
411411
script, we can run ``coro bt`` to get the following stack trace:
412412

413413
.. code-block::
@@ -466,13 +466,13 @@ One such solution is to store the list of in-flight coroutines in a collection:
466466
};
467467
468468
With this in place, it is possible to inspect ``inflight_coroutines`` from the
469-
debugger, and rely on LLDB's pretty-printer for ``std::coroutine_handle``s to
469+
debugger, and rely on LLDB's ``std::coroutine_handle`` pretty-printer to
470470
inspect the coroutines.
471471

472472
This technique will track *all* coroutines, also the ones which are currently
473473
awaiting another coroutine, though. To identify just the "roots" of our
474474
in-flight coroutines, we can use the ``coro in-flight inflight_coroutines``
475-
command provided by the :ref:`LLDB Debugger Script`.
475+
command provided by the :ref:`lldb-script`.
476476

477477
Please note that the above is expensive from a runtime performance perspective,
478478
and requires locking to prevent data races. As such, it is not recommended to
@@ -542,7 +542,7 @@ hence might have to set breakpoints in the ramp function and its ``.noalloc``
542542
variant.
543543

544544
Artificial ``__promise`` and ``__coro_frame`` variables
545-
---------------------------------------------------
545+
-------------------------------------------------------
546546

547547
Inside all coroutine functions, clang / LLVM synthesize a ``__promise`` and
548548
``__coro_frame`` variable. These variables are used to store the coroutine's
@@ -586,7 +586,8 @@ The promise is guaranteed to be at a 16 byte offset from the coroutine frame.
586586
If we have a coroutine handle at address 0x416eb0, we can hence reinterpret-cast
587587
the promise as follows:
588588

589-
.. code-block::
589+
.. code-block:: text
590+
590591
print (task::promise_type)*(0x416eb0+16)
591592
592593
Devirtualization of coroutine handles
@@ -621,7 +622,7 @@ assuming we have a ``std::coroutine_handle`` is at address 0x418eb0:
621622
$2 = {__resume_fn = 0x4019e0 <coro_task(int)>, __destroy_fn = 0x402000 <coro_task(int)>, __promise = {...}, ...}
622623

623624
In practice, one would use the ``show-coro-frame`` command provided by the
624-
:ref:`GDB Debugger Script`.
625+
:ref:`gdb-script`.
625626

626627
LLDB comes with devirtualization support out of the box, as part of the
627628
pretty-printer for ``std::coroutine_handle``. Internally, this pretty-printer
@@ -632,7 +633,7 @@ the resume function, devirtualization would hence fail for all coroutines that
632633
have reached their final suspension point.
633634

634635
Interpreting the coroutine frame in optimized builds
635-
---------------------------------------------------
636+
----------------------------------------------------
636637

637638
The ``__coro_frame`` variable usually refers to the coroutine frame of an
638639
*in-flight* coroutine. This means, the coroutine is currently executing.
@@ -705,6 +706,8 @@ source.
705706
Resources
706707
=========
707708

709+
.. _lldb-script:
710+
708711
LLDB Debugger Script
709712
--------------------
710713

@@ -956,11 +959,13 @@ Note that this script requires LLDB 21.0 or newer.
956959
if __name__ == '__main__':
957960
print("This script should be loaded from LLDB using `command script import <filename>`")
958961
962+
.. _gdb-script:
959963

960964
GDB Debugger Script
961965
-------------------
962966

963967
For GDB, the following script provides a couple of useful commands:
968+
964969
* ``async-bt`` to print the stack trace of a coroutine
965970
* ``show-coro-frame`` to print the coroutine frame, similar to
966971
LLDB's builtin pretty-printer for coroutine frames

0 commit comments

Comments
 (0)