Lines Matching defs:coroutine
35 coroutine type
38 A `coroutine function` is any function that contains any of the Coroutine
39 Keywords `co_await`, `co_yield`, or `co_return`. A `coroutine type` is a
40 possible return type of one of these `coroutine functions`. `Task` and
41 `Generator` are commonly referred to coroutine types.
43 coroutine
46 By technical definition, a `coroutine` is a suspendable function. However,
47 programmers typically use `coroutine` to refer to an individual instance.
52 std::vector<Task> Coros; // Task is a coroutine type.
54 Coros.push_back(CoroTask()); // CoroTask is a coroutine function, which
55 // would return a coroutine type 'Task'.
59 say "`Coros` contains 3 coroutine instances" or "Coros contains 3 coroutine
62 In this document, we follow the common practice of using `coroutine` to refer
63 to an individual `coroutine instance`, since the terms `coroutine instance` and
64 `coroutine object` aren't sufficiently defined in this case.
66 coroutine frame
69 The C++ Standard uses `coroutine state` to describe the allocated storage. In
70 the compiler, we use `coroutine frame` to describe the generated data structure
73 The structure of coroutine frames
76 The structure of coroutine frames is defined as:
89 coroutine function. So the name of the coroutine is obtainable once the
90 address of the coroutine is known.
95 Every coroutine has a `promise_type`, which defines the behavior
96 for the corresponding coroutine. In other words, if two coroutines have the
99 coroutine, printing the `promise_type` can be done by:
105 It is also possible to print the `promise_type` of a coroutine from the address
106 of the coroutine frame. For example, if the address of a coroutine frame is
115 16 bit offset from the coroutine frame.
126 Print coroutine frames
129 LLVM generates the debug information for the coroutine frame in the LLVM middle
130 end, which permits printing of the coroutine frame in the debugger. Much like
131 the `promise_type`, when stopped at a breakpoint inside a coroutine we can
132 print the coroutine frame by:
139 Just as printing the `promise_type` is possible from the coroutine address,
140 printing the details of the coroutine frame from an address is also possible:
144 (gdb) # Get the address of coroutine frame
147 (gdb) # Get the linkage name for the coroutine
152 (gdb) # The coroutine frame type is 'linkage_name.coro_frame_ty'
158 (1) The name of the debug type of the coroutine frame is the `linkage_name`,
159 plus the `.coro_frame_ty` suffix because each coroutine function shares the
160 same coroutine type.
162 (2) The coroutine function name is accessible from the address of the coroutine
167 Examples to print coroutine frames
174 #include <coroutine>
244 of the current suspension point of the coroutine is emitted as `__coro_index`.
245 In the above example, the `__coro_index` value of `1` means the coroutine
308 coroutine frame should not be thought of as directly representing the
315 points, which are where the coroutine is currently suspended and awaiting.
318 variable in the coroutine frame works well.
321 cases, it is necessary to use the coroutine libraries to insert the
348 await inside the `promise_type`. Since we can locate the coroutine function
349 from the address of the coroutine, we can identify suspended points this way
358 Another important requirement to debug a coroutine is to print the asynchronous
359 stack to identify the asynchronous caller of the coroutine. As many
360 implementations of coroutine types store `std::coroutine_handle<> continuation`
362 `continuation` is typically the awaiting coroutine for the current coroutine.
365 Since the `promise_type` is obtainable from the address of a coroutine and
366 contains the corresponding continuation (which itself is a coroutine with a
379 #include <coroutine>
465 In the example, the ``task`` coroutine holds a ``continuation`` field,
503 # If we want to generalize the scripts to other coroutine types, we need to be sure
517 raise Exception('Not stackless coroutine.')
572 "Please use `async-bt` in stackless coroutine context.")
596 print("usage: show-coro-frame <address of coroutine frame>")
667 We can make it by passing the address of the corresponding coroutine frame to ``async-bt`` command.
669 By the debugging scripts, we can print any coroutine frame too as long as we know the address.
670 For example, we can print the coroutine frame for ``detail::chain_fn<18>()`` in the above example.
671 From the log record, we know the address of the coroutine frame is ``0x4412c0`` in the run. Then we can:
735 In the above code snippet, we save the address of every lived coroutine in the
737 coroutine we can derive the function, `promise_type`, and other members of the