|
8 | 8 | * [Dispatchers and threads](#dispatchers-and-threads)
|
9 | 9 | * [Unconfined vs confined dispatcher](#unconfined-vs-confined-dispatcher)
|
10 | 10 | * [Debugging coroutines and threads](#debugging-coroutines-and-threads)
|
| 11 | + * [Debugging with IDEA](#debugging-with-idea) |
| 12 | + * [Debugging using logging](#debugging-using-logging) |
11 | 13 | * [Jumping between threads](#jumping-between-threads)
|
12 | 14 | * [Job in the context](#job-in-the-context)
|
13 | 15 | * [Children of a coroutine](#children-of-a-coroutine)
|
@@ -155,8 +157,35 @@ The unconfined dispatcher should not be used in general code.
|
155 | 157 |
|
156 | 158 | Coroutines can suspend on one thread and resume on another thread.
|
157 | 159 | Even with a single-threaded dispatcher it might be hard to
|
158 |
| -figure out what the coroutine was doing, where, and when. The common approach to debugging applications with |
159 |
| -threads is to print the thread name in the log file on each log statement. This feature is universally supported |
| 160 | +figure out what the coroutine was doing, where, and when if you don't have special tooling. |
| 161 | + |
| 162 | +#### Debugging with IDEA |
| 163 | + |
| 164 | +The Coroutine Debugger of the Kotlin plugin simplifies debugging coroutines in IntelliJ IDEA. |
| 165 | + |
| 166 | +> Debugging works for versions 1.3.8 or later of `kotlinx-coroutines-core`. |
| 167 | +
|
| 168 | +The **Debug Tool Window** contains a **Coroutines** tab. In this tab, you can find information about both currently |
| 169 | +running and suspended coroutines. The coroutines are grouped by the dispatcher they are running on. |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | +You can: |
| 174 | +* Easily check the state of each coroutine. |
| 175 | +* See the values of local and captured variables for both running and suspended coroutines. |
| 176 | +* See a full coroutine creation stack, as well as a call stack inside the coroutine. The stack includes all frames with |
| 177 | +variable values, even those that would be lost during standard debugging. |
| 178 | + |
| 179 | +If you need a full report containing the state of each coroutine and its stack, right-click inside the **Coroutines** tab, and then |
| 180 | +click **Get Coroutines Dump**. |
| 181 | + |
| 182 | +Learn more about debugging coroutines in [this blog post](https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-rc-debugging-coroutines/) |
| 183 | +and [IntelliJ IDEA documentation](https://www.jetbrains.com/help/idea/debug-kotlin-coroutines.html). |
| 184 | + |
| 185 | +#### Debugging using logging |
| 186 | + |
| 187 | +Another approach to debugging applications with |
| 188 | +threads without Coroutine Debugger is to print the thread name in the log file on each log statement. This feature is universally supported |
160 | 189 | by logging frameworks. When using coroutines, the thread name alone does not give much of a context, so
|
161 | 190 | `kotlinx.coroutines` includes debugging facilities to make it easier.
|
162 | 191 |
|
|
0 commit comments