1

So, having a hard time dereferencing some data I've loaded into arrays and dictionaries:

Inside a controller:

- (void)setupVendorsArray {
    self.vendorsArray = [NSArray arrayWithObjects:@"Toyota", @"Honda",nil];
}

- (void)setupProductFamiliesHash {

    NSArray *lowcost = [NSArray arrayWithObjects:@"Corolla", @"Fit",nil];
    NSArray *midrange = [NSArray arrayWithObjects:@"Camry", @"Accord",nil];
    NSArray *highend = [NSArray arrayWithObjects:@"Lexus", @"Acura",nil];
    NSArray *trucks = [NSArray arrayWithObjects:@"Tacoma", @"Ridgeline",nil];

    NSDictionary *lc = [NSDictionary dictionaryWithObjects:lowcost forKeys:self.vendorsArray]; 
    NSDictionary *mr = [NSDictionary dictionaryWithObjects:midrange forKeys:self.vendorsArray]; 
    NSDictionary *he = [NSDictionary dictionaryWithObjects:highend forKeys:self.vendorsArray]; 
    NSDictionary *tk = [NSDictionary dictionaryWithObjects:trucks forKeys:self.vendorsArray]; 

    self.productFamiliesHash = [NSArray arrayWithObjects:lc,mr,he,tk,nil];
}

In gdb print-object results in this for productFamiliesHash:

(gdb) print-object self.productFamiliesHash
<__NSArrayI 0x6b2c760>(
{
    Toyota = "Corolla";
    Honda = "Fit";
},
{
    Toyota = "Camry";
    Honda = "Accord";
},
{
    Toyota = "Lexus";
    Honda = "Acura";
},
{
    Toyota = "Tacoma";
    Honda = "Ridgeline";
}
)

But, for the life of me I can't seem to access, for example, Toyota Corolla, which I would expect I could do like this in gdb:

(gdb) p [[productFamiliesHash objectAtIndex:0] objectForKey:@"Toyota"]

However, gdb gives:

Unable to call function "objc_msgSend" at 0x156408c: no return type information available.

How do I dereference the dictionary within the array?

2
  • 1
    You have it right. Try po in the gdb console instead of p. po prints out ObjC objects. Commented Jan 25, 2012 at 4:57
  • You probably should avoid using the name productFamiliesHash when the object is really an array. Commented Jan 25, 2012 at 5:47

2 Answers 2

4

Try using po instead of p. For Objective-C methods, p requires that you cast the result:

(gdb) p (id) [[productFamiliesHash objectAtIndex:0] objectForKey:@"Toyota"]

Even then, you won't get the description of the object, only the pointer value.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome. Thanks @iccir. Works like a charm! (using the po)
1

Use po (print object) instead. The other important thing is that gdb needs to know the exact type of object before it can send it a message directly, so you just have to cast it properly:

po [(NSDictionary *)[productFamiliesHash objectAtIndex:0] objectForKey:@"Toyota"]

5 Comments

Actually, in this case you don't need to cast it. iccir's way works fine.
for that matter, it might generate a warning in code if you didn't cast and sent a message to an (id)?
Thanks for the quick response @Costique. I gave this one to iccir, just because he was first...
@ThomasW Hm, doesn't "no return type information available" say that gdb can't guess the return type of [productFamiliesHash objectAtIndex:0] because it is declared as id?
@Costique I just tried and gdb doesn't give that message in this case, even if productFamiliesHash is of type id. I think the case where it does give the "no return type information available" message is when the return type is not known to be an objective-C object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.