Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4 / gdb / How simply watch object properties?

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:

  1. How to watch such a property without gdb in a graphical way (as simply as in Visual Studio) ?
  2. 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 ???

like image 637
user255607 Avatar asked Dec 17 '22 09:12

user255607


1 Answers

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:

(gdb) po [myObject someProperty]

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:

(gdb) p (CGRect)[myView frame]
(gdb) p (CGPoint)[myView center]

and so on.

like image 107
Eimantas Avatar answered Dec 28 '22 08:12

Eimantas