当我想要停止变量时,如何在xCode中设置BreakPoint?

时间:2021-02-26 22:58:48

I want set a breakPoint when a variable changes. For example:

我想在变量更改时设置breakPoint。例如:

......
if(downloader){
        [downloader addDelegate:sImageAutoSaver];
}
......

I want to break the app when downloader changes. For I want to know who changes the variable.

我希望在下载程序更改时中断应用程序。因为我想知道谁更改了变量。

1 个解决方案

#1


10  

If downloader is an ivar and you're using Xcode 4.4 you can use debugger console. Place normal breakpoint inside init method of this class or in viewDidLoad (if it's a ViewController) or in general, before downloader is assigned. When execution stops on created breakpoint, type watch set variable -w write self->downloader in debugger console. You'll see Watchpoint created: Watchpoint 1: addr = 0x092359b4 ... message. Next, press continue button and your program will stop whenever variable will be assigned.

如果下载器是ivar并且您正在使用Xcode 4.4,则可以使用调试器控制台。将普通断点放在此类的init方法内或viewDidLoad中(如果它是ViewController)或一般情况下,在分配下载器之前。当执行在创建的断点上停止时,在调试器控制台中键入watch set variable -w write self-> downloader。您将看到Watchpoint已创建:Watchpoint 1:addr = 0x092359b4 ... message。接下来,按继续按钮,只要分配了变量,程序就会停止。

After variable breakpoint hits and you'll see only assembly, try to look through execution stack on left navigation panel for methods of your application.

在变量断点命中后,您将只看到汇编,尝试查看左侧导航面板上的执行堆栈,了解您的应用程序的方法。

#1


10  

If downloader is an ivar and you're using Xcode 4.4 you can use debugger console. Place normal breakpoint inside init method of this class or in viewDidLoad (if it's a ViewController) or in general, before downloader is assigned. When execution stops on created breakpoint, type watch set variable -w write self->downloader in debugger console. You'll see Watchpoint created: Watchpoint 1: addr = 0x092359b4 ... message. Next, press continue button and your program will stop whenever variable will be assigned.

如果下载器是ivar并且您正在使用Xcode 4.4,则可以使用调试器控制台。将普通断点放在此类的init方法内或viewDidLoad中(如果它是ViewController)或一般情况下,在分配下载器之前。当执行在创建的断点上停止时,在调试器控制台中键入watch set variable -w write self-> downloader。您将看到Watchpoint已创建:Watchpoint 1:addr = 0x092359b4 ... message。接下来,按继续按钮,只要分配了变量,程序就会停止。

After variable breakpoint hits and you'll see only assembly, try to look through execution stack on left navigation panel for methods of your application.

在变量断点命中后,您将只看到汇编,尝试查看左侧导航面板上的执行堆栈,了解您的应用程序的方法。