views:

369

answers:

1

working on a mac os project (meaning not iPhone) requiring 10.6 and is 64bit, allows me to use properties to generate both accessor methods and instance variables in the header file. but, during debug, i'm not seeing how to look at the object's properties values after they have been populated. is there some build setting that needs to be turned on?

if i am declaring an object's instance variables (between {} in the header), then i can see those values (when they are used) during debug either in the debug window itself, or by using the cursor-hover over the highlighted line trick in the editor during a break, or by doing cli in gdb like 'p *object' for instance.

old way:

@class Suit;
@interface Card : NSObject 
{
    NSNumber *playOrder;
    Suit *suit;
    NSNumber *displayNumber;
    NSNumber *orderIndex;
}
@property(nonatomic, retain) Suit *suit;
@property(nonatomic, retain) NSNumber *displayNumber;
@property(nonatomic, retain) NSNumber *orderIndex;

new way:

@class Suit;
@interface Card : NSObject 

@property(nonatomic, retain) Suit *suit;
@property(nonatomic, retain) NSNumber *displayNumber;
@property(nonatomic, retain) NSNumber *orderIndex;
@property(nonatomic, retain) NSNumber *playOrder;

in this new-fangled 10.6 required 64bit idea (which seems simpler to me) none of these debug methods display the object's values. i figure that i must have something turned off, because this newer idea, doesn't seem better.

gdb results for old way:

(gdb) po newCard
New Card : 0 of Suit : Hearts (NSCalibratedRGBColorSpace 1 0 0 1). with orderIndex of: 1
(gdb) p *newCard
$1 = {
  <NSObject> = {
    isa = 0x100002188
  }, 
  members of Card: 
  playOrder = 0x0, 
  suit = 0x200053a20, 
  displayNumber = 0x20001bac0, 
  orderIndex = 0x200012de0
}
(gdb)

gdb results for new way:

(gdb) po newCard
New Card : 0 of Suit : Hearts (NSCalibratedRGBColorSpace 1 0 0 1). with orderIndex of: 1
(gdb) p *newCard
$3 = {
  <NSObject> = {
    isa = 0x100002188
  }, <No data fields>}
(gdb) 

so looking at the docs for objective-c 2.0:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW3

describes what i am referring to (synthesizing instance variables in 'modern' runtime), but what isn't said anywhere, is that if you do this, the values will not be available during debugging.

i've found an SO page with pertinent information, but not focused on this effect: http://stackoverflow.com/questions/1007607/using-instance-variables-with-modern-runtime

what did i miss?

+1  A: 

I assume that you are @synthesizing those variables?

You may also need { } in the interface, so the compiler knows where to put it.

@interface Card : NSObject
{

}

I would avoid this kind of syntax... especially if you define the properties yourself.

Also, look up <objc/runtime.h> and see if you can print a list of ivars for the class. I use the following all the time for debugging methods or classes from APIs that have no documentation.

    unsigned int total_method_count = 0;
    Method * method_list = class_copyMethodList(object_getClass([obj class]), &total_method_count);
    @try
    {
        int method_counter = 0;
        for (method_counter = 0; method_counter < total_method_count; method_counter++)
        {
            Method method = method_list[method_counter];
            // check if method the KVC getter you are interested in
            NSLog(@"Method: %s", sel_getName(method_getName(method)));
        }
    } @catch (NSException *e) {
        //Do Nothing
    }
Stephen Furlani
yes, the .m file has @synthesize for the properties in both examples.as to using '{}' in the second example, i am using the idea that if a project is set to be 64-bit, and requiring 10.6 to run, then instance variables can be synthesized, and the '{}' is not necessary. thus my extreme surprise finding no data to use in debug, so sure i have something wrong.i'll try your code and report back. thanks, stephen.
lulu
i can see where the above idea can be helpful, as well as using the runtime header functions in debugging as a strategy, and will probably help other folks too.what i am asking about is that it seems that if i use synthesized ivars in creating projects that are 64-bit, 10.6 runtime, then i'm not seeing debugging data references, and to me, this seems so odd, (to not be able to use gdb or xcode debug) that i'm sure i've got something missing in my setup. so that's the basis of my question: 'what did i miss?'.
lulu
All I was referencing was the fact that the compiler may not be generating the ivars at all. Hence why you should use the runtime to make sure they're generated and not just rely on (gdb) or the XCode debugger. Also, since the compiler is not doing anything intelligent, you may want to add the `{ }` to make sure the compiler knows where to put that code. Unfortunately that's as far as I can help you. If you can't see your ivars with the runtime.h then the "new" way is just a bunch of horse-malarky and you should never use "invisible" syntax like that anyway.
Stephen Furlani
sorry it took a while to get back to you.thank you for the advice. i have changed my 'real' project adding back {}. i was using this book:'Cocoa and Objective:Up and Running', and the author uses this idea througout his examples, however the book doesn't cover gdb.
lulu