Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symbolic breakpoint for when dispatch_async is called with a specific queue

I'm debugging an issue in my project involving grand central dispatch. In debugging this, it would be really helpful to have a way of being notified when work is dispatched to a specific queue.

Is there some way of setting a symbolic breakpoint on dispatch_async with a condition that could check whether the dispatch queue argument is the same as some other queue that I have access to?

like image 214
Antonio Avatar asked Jan 24 '26 21:01

Antonio


1 Answers

Here's how to set a conditional breakpoint. (I haven't done conditions on queues, I'm making the assumption here that pointer equality will Just Work™.)

First get the address of the queue you want, let's say it's 0x12345678. Then create a breakpoint:

breakpoint set -n dispatch_async -c '$register == 0x12345678'

Replace $register with an expression specific to the architecture.

Updated to show $arg1 from Jim Ingham's comment

Simulator

  • x86: *(id*)($esp+4)
  • x86-64: $arg1 (aka $rdi)

Device

  • armv7: $arg1 (aka $r0)
  • arm64: $arg1 (aka $x0)
like image 191
Dave Lee Avatar answered Jan 26 '26 12:01

Dave Lee