Xcode 4 / gdb / 如何简单地监视对象属性?
我对 Xcode 4 非常迷失。观看一个简单的变量是一场噩梦。我不知道如何“观察变量值”。在 Xcode 3 中更容易...
我有以下代码:
if (labelEast.center.x > (east_oldPosition.x + 50) )
NSLog(@"Time to switch to previous exercise !");
else if (labelEast.center.x < (east_oldPosition.x - 50) )
NSLog(@"Time to switch to next exercise !");
设置断点后,我只是想观看 labelEast.center.x
(labelEast
是UILabel
对象)。由于我在 Xcode 4 菜单中找不到监视项,因此我尝试使用 gdb。我习惯用 po (打印对象)打印变量/对象值。但现在,我无法显示 labelEast
center
属性,因为它是从母类继承的。
(gdb) po labelEast.center
没有名为 center 的成员。
我不明白为什么 gdb 会这么说,而代码却可以正常工作并看到该属性。
因此我有两个问题:
- 如何在没有 gdb 的情况下以图形方式观察这样的属性(就像在 Visual Studio 中一样简单)?
- 如何用 gdb 做同样的事情?
非常感谢, 弗兰茨
不幸的是,我尝试了但得到了这个:
po [标签南中心]
程序收到信号EXC_BAD_ACCESS,无法访问内存。 原因:KERN_INVALID_ADDRESS位于地址:0x1a000356 0x343c7d06中 objc_msgSend_stret () 正在调试的程序在 从 GDB 调用的函数。 GDB 保留在信号所在的帧中 已收到。要更改此行为,请使用“set unwindonsignal on” 包含函数 (objc_msgSend) 的表达式的求值 将会被抛弃。
当我尝试时:
(gdb) 打印 labelSouth.center
没有名为 center 的成员。
我真的怀疑无法访问 UILabel
中的中心属性。但我怎样才能运行代码???
I am very lost in Xcode 4. Watching a simple variable is a nightmare. I do not figure out how to just "watch a variable value". It was easier in Xcode 3...
I have the following piece of code:
if (labelEast.center.x > (east_oldPosition.x + 50) )
NSLog(@"Time to switch to previous exercise !");
else if (labelEast.center.x < (east_oldPosition.x - 50) )
NSLog(@"Time to switch to next exercise !");
After setting a breakpoint, I am just trying to watch labelEast.center.x
(labelEast
is a UILabel
object). Since I could not find a watch item in a Xcode 4 menu, I am trying to use gdb. I am used to print variable/object values with po
(print object). But now, I cannot display labelEast
center
property because it is inherited from a mother class.
(gdb) po labelEast.center
There is no member named center.
I do not understand why gdb says this whereas the code works fine and sees the property.
Thus I have 2 questions:
- How to watch such a property without gdb in a graphical way (as simply as in Visual Studio) ?
- How to do the same with gdb ?
Many thanks,
Franz
Unfortunately, I tried it but got this:
po [labelSouth center]
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x1a000356 0x343c7d06 in
objc_msgSend_stret () The program being debugged was signaled while in
a function called from GDB. GDB remains in the frame where the signal
was received. To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (objc_msgSend)
will be abandoned.
And when I try:
(gdb) print labelSouth.center
There is no member named center.
I really suspect there is no access to center property in UILabel
. But how can me code run ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己也遇到过几次这个问题,只是为了记住“哦,没错,gdb 不支持点表示法,所以我必须使用 getter”。然后就去做吧:
世界就会再次变得美好。另外重读您的问题,我发现您正在请求打印一个非对象,因此您必须向 gdb 提示您想要打印的属性类型:
等等。
I've hit this thing a few times myself just to remember "oh, that's right, gdb doesn't support dot notation so I have to use getter". Then just do:
and all is well with the world again. Also rereading your question I see that you're requesting a non object to be printed, hence you have to give gdb a hint of what type of property you want to print:
and so on.