问题
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?
回答1:
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
)
回答2:
If you set the label on your queue you can just set a conditional breakpoint on a string match within the block being executed. Sometime's I'll just log it like this though.
if (!strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(myDispatchQueue)){
printf("Booyah!\n");
}
来源:https://stackoverflow.com/questions/30470217/symbolic-breakpoint-for-when-dispatch-async-is-called-with-a-specific-queue