@@ -180,7 +180,7 @@ generator and its internal state.
180
180
To do so, we can simply look into the ``gen.hdl `` variable. LLDB comes with a
181
181
pretty printer for ``std::coroutine_handle `` which will show us the internal
182
182
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 `.
184
184
185
185
.. image :: ./coro-generator-suspended.png
186
186
@@ -360,7 +360,7 @@ type of a task is a template argument. For simplicity's sake, we hard-coded the
360
360
``int `` type in this example.
361
361
362
362
Stack traces of in-flight coroutines
363
- -----------------------------------
363
+ ------------------------------------
364
364
365
365
Let's assume you have the following program and set a breakpoint inside the
366
366
``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
407
407
useful to automatically dereference all the pointers up to the given depth.
408
408
409
409
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
411
411
script, we can run ``coro bt `` to get the following stack trace:
412
412
413
413
.. code-block ::
@@ -466,13 +466,13 @@ One such solution is to store the list of in-flight coroutines in a collection:
466
466
};
467
467
468
468
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
470
470
inspect the coroutines.
471
471
472
472
This technique will track *all * coroutines, also the ones which are currently
473
473
awaiting another coroutine, though. To identify just the "roots" of our
474
474
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 `.
476
476
477
477
Please note that the above is expensive from a runtime performance perspective,
478
478
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``
542
542
variant.
543
543
544
544
Artificial ``__promise `` and ``__coro_frame `` variables
545
- ---------------------------------------------------
545
+ -------------------------------------------------------
546
546
547
547
Inside all coroutine functions, clang / LLVM synthesize a ``__promise `` and
548
548
``__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.
586
586
If we have a coroutine handle at address 0x416eb0, we can hence reinterpret-cast
587
587
the promise as follows:
588
588
589
- .. code-block ::
589
+ .. code-block :: text
590
+
590
591
print (task::promise_type)*(0x416eb0+16)
591
592
592
593
Devirtualization of coroutine handles
@@ -621,7 +622,7 @@ assuming we have a ``std::coroutine_handle`` is at address 0x418eb0:
621
622
$2 = {__resume_fn = 0x4019e0 <coro_task(int)>, __destroy_fn = 0x402000 <coro_task(int)>, __promise = {...}, ...}
622
623
623
624
In practice, one would use the ``show-coro-frame `` command provided by the
624
- :ref: `GDB Debugger Script `.
625
+ :ref: `gdb-script `.
625
626
626
627
LLDB comes with devirtualization support out of the box, as part of the
627
628
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
632
633
have reached their final suspension point.
633
634
634
635
Interpreting the coroutine frame in optimized builds
635
- ---------------------------------------------------
636
+ ----------------------------------------------------
636
637
637
638
The ``__coro_frame `` variable usually refers to the coroutine frame of an
638
639
*in-flight * coroutine. This means, the coroutine is currently executing.
@@ -705,6 +706,8 @@ source.
705
706
Resources
706
707
=========
707
708
709
+ .. _lldb-script :
710
+
708
711
LLDB Debugger Script
709
712
--------------------
710
713
@@ -956,11 +959,13 @@ Note that this script requires LLDB 21.0 or newer.
956
959
if __name__ == ' __main__' :
957
960
print (" This script should be loaded from LLDB using `command script import <filename>`" )
958
961
962
+ .. _gdb-script :
959
963
960
964
GDB Debugger Script
961
965
-------------------
962
966
963
967
For GDB, the following script provides a couple of useful commands:
968
+
964
969
* ``async-bt `` to print the stack trace of a coroutine
965
970
* ``show-coro-frame `` to print the coroutine frame, similar to
966
971
LLDB's builtin pretty-printer for coroutine frames
0 commit comments