Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Debugging Objective-C

Debugging Objective-C
Thread Tools
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Mar 22, 2003, 06:25 PM
 
I staretd out programming in Java, so when something would crash in butn there, I would get a nice back trace that was very helpful. In objective-c, I find it takes my 2-3 times as long to find out where a bug in my software is at. Right now, somehow NSCFType is being send a width message, but not in my code explicitely. What I'd like to know is - is there a better way than guess and check to hunt these problems down? I suppose I could add a category to NSCFType with the width method added, but I'd assume there's a better way.

Thanks,
Matt Fahrenbacher
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Mar 22, 2003, 07:41 PM
 
In general, a good debugging trick for ObjC is to set a breakpoint on -[NSException raise]. Then the debugger will stop and give you a stack trace when something goes wrong.

Your specific issue sounds like a case where somebody is sending messages to an object that has been deallocated -- the same pointer got reused for another object later, which isn't the object you're looking for. Make sure you're calling -retain when appropriate.
Rick Roe
icons.cx | weblog
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Mar 22, 2003, 08:04 PM
 
Originally posted by Rickster:
In general, a good debugging trick for ObjC is to set a breakpoint on -[NSException raise]. Then the debugger will stop and give you a stack trace when something goes wrong.

Your specific issue sounds like a case where somebody is sending messages to an object that has been deallocated -- the same pointer got reused for another object later, which isn't the object you're looking for. Make sure you're calling -retain when appropriate.
I think you're right on the cause - it switched from NSCFDictionary to NSCFSet (or was it NSSet?), which always tells me I'm doing that. The odd thing is it has something to do with my outlineview delegate methods... although I'm finding it impossible to find which method. Does NSLog() always get flushed?

I'll keep looking, but how would I use [NSException raise]? Wouldn't that require me to know where in my code the problem is at?

Matt Fahrenbacher
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Mar 23, 2003, 12:00 PM
 
Not call -[NSException raise], set a breakpoint on it in GDB. So that it breaks whenever an exception is raised and you can see what's going on.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Mar 23, 2003, 04:13 PM
 
If you do your debugging inside PB (instead of with gdb on the command line), switch to the Breakpoints tab, hit New, and type "-[NSException raise]".
Rick Roe
icons.cx | weblog
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Mar 23, 2003, 07:24 PM
 
You can use NSDebug.h to help debug these sorts of problems. Cmd-D and type "NSDebug.h" from Project Builder.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:55 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2