How to list suspended tasks in XCode debugger?

The Xcode debug navigator has the excellent "View Process by Thread" and "View Process by Queue" options, but since swift 5.5 it is sorely missing a "View Process by Task" option. I do hope this is under development and will be overjoyed to see it announced at WWDC this year...

Even without a nice UI though, presumably all the information is already available somewhere accessible through lldb

Question: Is it possible in lldb in Xcode to get a list of suspended tasks in a paused process and on which file/ line they are awaiting ?

Side Notes:
I saw swift-inspect, but that only works for local processes, I am debugging an app on an iPhone.

I have tried Instruments but it is huge and clunky and slows to a crawl with many tasks. I have a Task.sleep running every 15 seconds and that creates a new Task Clock.sleep row for every call, filling up the trace with unnecessary information.

I struggled at first to view tasks from a running app on an iOS device, but found a workaround that allowed me to view tasks in an app already launched from XCode.

  1. In Xcode debug navigator sidebar, click on CPU, then on the "Profile in Instruments" button on top right. This opens a CPU trace in Xcode.

  2. In Instruments, select New in the File menu, select Swift Concurreny, then "Choose"

  3. This opens a Task trace window, your iPhone process should be selected at the top, but with a red crossed circle indicating another tool is attached to the app.

  4. Back in the cpu trace tool, hit stop and close the window

  5. It should then be possible to press record in the Swift Concurrency trace window. Click on the reveal triangle under swift tasks.

Hey presto, you can now see the state of running tasks !

Frustratingly, Instruments is unable to find any code in my project when I click on the stack trace I just get "Error. Can't find source code for selected symbol", even though I can see the code sitting in Xcode window right next to it.

@Apple Please Please Please make this easier, by adding a Tasks category to the Debug Navigator in Xcode and a Profile in Instruments button which opens the Swift Concurrency tool directly, rather than having to jump through the hoops described above. And please also fix the source code lookup in instruments.

Apologies if I have missed a simpler way to connect instruments to running tasks ...

2 Likes

Thanks for providing this feedback!