Symbolic breakpoint for when dispatch_async is called with a specific queue

有些话、适合烂在心里 提交于 2019-12-04 12:25:55
Dave Lee

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)

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");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!