是否有可能在对象的实例中停止断点?(Is it possible to stop on a breakpoint in an instance of an object?)

编程入门 行业动态 更新时间:2024-10-25 07:33:48
是否有可能在对象的实例中停止断点?(Is it possible to stop on a breakpoint in an instance of an object?)

我试过在类定义中创建一个断点,停止发送给对象实例的消息,希望它跳转到类代码,并允许我逐行浏览并查看本地变量的值。

但是,我要冒险出来说“不,这不应该是可能的” ,因为在内存中可能有多个类的实例。 如果有人能够给出更好的解释,那将是隆重的。

(作为一个方面说明,我的选择是运行时数据过多的NSLogging。)

I've tried creating a breakpoint within a class definition, stopping on the message sent to an object instance, hoping it would then jump to the class code and allow me to walk through line by line and see the values of the local variables.

However, I'm going to venture out and say "no, this should not be possible", as there could be multiple instances of the class in memory. If someone could give a better explanation, that would be grand.

(As a side note, my alternative is excessive NSLogging of the runtime data.)

最满意答案

对的,这是可能的! 您可以将条件添加到断点:

http://d.pr/yZVB+ http://d.pr/pWOB+

条件满足时,程序只会在此断点处暂停。 你可以选择一个条件,比如self == _myGlobalInstanceOfInterest 。

如果不想将实例存储在变量中,例如,可以在没有条件的情况下启动断点 - 然后当程序正在运行时找出想要的实例时,请使用p myObject获取地址,然后设置条件以使用该地址(例如self == 0x8badf00d )。

Yes, it is possible! You can add a condition to a breakpoint:

http://d.pr/yZVB+ http://d.pr/pWOB+

The program will only pause at this breakpoint when the condition is satisfied. You could choose a condition such as self == _myGlobalInstanceOfInterest.

If you don't want to store the instance in a variable, you might, for example, start the breakpoint without a condition — and then when you figure out which instance you want as the program is running, use p myObject to get the address, and then just set the condition to use the that address (such as self == 0x8badf00d).

更多推荐

本文发布于:2023-07-30 01:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321408.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有可能   断点   实例   对象   object

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!