簡體   English   中英

XCode:以編程方式啟用符號斷點?

[英]XCode: Programmatically enable a symbolic breakpoint?

有沒有辦法以編程方式啟用斷點? 通常我會使用斷點條件,但我需要使用符號斷點。

具體來說,在調用scrollToIndexPath和調用reloadData之間,某些東西正在改變我的UIScrollView的contentOffset 我想在調用scrollToIndexPath之后才啟用符號斷點。

Jim Ingham的回答適用於x86系統。 對於iOS設備,我能夠使用此答案中描述的方法以編程方式創建斷點。 插入行

asm("svc 0");

使調試器停止在XCode中的以下指令。

在此輸入圖像描述

有趣的是,如果你沒有連接到XCode,程序將繼續正常執行。

你可以使用__builtin_trap()來做到這一點。 在x86系統上,您必須在按下陷阱后手動調整電腦。 但這很容易做到,如果你的代碼受到很多打擊並且你只需要在一些復雜的情況下陷阱,那么它有時很有用。 就像是:

 > lldb trapit
(lldb) target create "trapit"
Current executable set to 'trapit' (x86_64).
(lldb) run
Process 63363 launched: '/private/tmp/trapit' (x86_64)
About to trap.
Process 63363 stopped
* thread #1: tid = 0x2054b7, function: main , stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000100000f4d trapit`main at trapit.c:6
   3    int main()
   4    {
   5      printf ("About to trap.\n");
-> 6      __builtin_trap();
   7      printf("Trapped.\n");
   8    }
(lldb) dis -f
trapit`main:
    0x100000f30 <+0>:  pushq  %rbp
    0x100000f31 <+1>:  movq   %rsp, %rbp
    0x100000f34 <+4>:  subq   $0x10, %rsp
    0x100000f38 <+8>:  leaq   0x47(%rip), %rdi          ; "About to trap.\n"
    0x100000f3f <+15>: movb   $0x0, %al
    0x100000f41 <+17>: callq  0x100000f66               ; symbol stub for: printf
    0x100000f46 <+22>: leaq   0x49(%rip), %rdi          ; "Trapped.\n"
->  0x100000f4d <+29>: ud2    
    0x100000f4f <+31>: movl   %eax, -0x4(%rbp)
    0x100000f52 <+34>: movb   $0x0, %al
    0x100000f54 <+36>: callq  0x100000f66               ; symbol stub for: printf
    0x100000f59 <+41>: xorl   %ecx, %ecx
    0x100000f5b <+43>: movl   %eax, -0x8(%rbp)
    0x100000f5e <+46>: movl   %ecx, %eax
    0x100000f60 <+48>: addq   $0x10, %rsp
    0x100000f64 <+52>: popq   %rbp
    0x100000f65 <+53>: retq   
(lldb) reg write pc 0x100000f4f
(lldb) c
Process 63363 resuming
Trapped.
Process 63363 exited with status = 0 (0x00000000) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM