Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 30, 2006, 01:08 AM   #1
jamdr
macrumors 6502a
 
jamdr's Avatar
 
Join Date: Jul 2003
Location: Bay Area
How do you debug in XCode?

I'm new to Obj-C and when I tried to run my application I got this error in the run log:

2006-04-30 01:01:18.940 MyProject[404] NSScanner: nil string argument

I don't really understand what that means because I don't know where in my code the error occurred. Is one of those numbers a line number? XCode's debugger seems really unintuitive. I'm used to eclipse, where if an error occurs you can jump right to the part of your code where the problem is. How can I do this in XCode?

Last edited by jamdr; Apr 30, 2006 at 01:16 AM.
jamdr is offline   0 Reply With Quote
Old Apr 30, 2006, 02:09 AM   #2
szymczyk
macrumors regular
 
Join Date: Mar 2006
You're not running your code in the debugger so Xcode can't tell you the line of code where the error occurred. Choose Debug > Debug Executable to run your program in the debugger, which will make debugging your program much easier.

Regarding the error message, your program is trying to use a nil string pointer. When you declare pointer variables in your program, you must allocate memory for them before you use them.
__________________
Mark Szymczyk
Author, Xcode Tools Sensei
http://www.meandmark.com
szymczyk is offline   0 Reply With Quote
Old Apr 30, 2006, 01:39 PM   #3
jamdr
Thread Starter
macrumors 6502a
 
jamdr's Avatar
 
Join Date: Jul 2003
Location: Bay Area
Thanks for the reply. I see the debug mode, but I still don't get it. If I run my code in the debugger and an error occurs, I just see a window pop up full of assembly code. So the error occurred at 0xfffeff20 <+0032> lwz r11,0(r2). Is there a way to get a little more high level than that? Also is there a way to see what the current values of local variables are? I see a memory window, but again it's just registers and hex values. Is there no higher-level debug mode?
jamdr is offline   0 Reply With Quote
Old Apr 30, 2006, 02:40 PM   #4
szymczyk
macrumors regular
 
Join Date: Mar 2006
To the left of the variable list is the call stack. You should be able to see the function that generated the assembly language. Click on that function to go the function in the editor. Xcode does not automatically take you to the line of code that caused an error.

If you don't see any meaningful function names in the call stack, you may not have Xcode set up for debugging. Xcode has two different build configurations for each target: debug and release. Choose Project > Set Active Build Configuration > Debug. If you have an older version of Xcode, Xcode calls the build configurations development and deployment instead of debug and release. In this case you want the development build configuration. Using the debug build configuration gives you higher-level debugging.
__________________
Mark Szymczyk
Author, Xcode Tools Sensei
http://www.meandmark.com
szymczyk is offline   0 Reply With Quote
Old Apr 30, 2006, 03:24 PM   #5
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Quote:
Originally Posted by szymczyk
Xcode does not automatically take you to the line of code that caused an error.
Sometimes it does, actually (sometimes it will even highlight the line, sometimes not). I have yet to figure out what causes it to do this seemingly at random. Also, you will not be able to see any of your related methods shown in the call stack if the error was generated in a method in another process or thread. For example, your application might be playing a movie or a song. If the error occurs in a separate QuickTime or CoreAudio render thread (even one initiated by your application), you won't see any of your own code.

You can also set breakpoints by clicking on a line number on the left of your code pane. When running the debugger, the application will pause at the breakpoint where you can examine the state of your application (all the objects and variables) at that point, and also step over code line by line to watch what changes in detail.
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Apr 30, 2006, 04:36 PM   #6
savar
macrumors 68000
 
savar's Avatar
 
Join Date: Jun 2003
Location: District of Columbia
Send a message via AIM to savar
Quote:
Originally Posted by jamdr
Thanks for the reply. I see the debug mode, but I still don't get it. If I run my code in the debugger and an error occurs, I just see a window pop up full of assembly code. So the error occurred at 0xfffeff20 <+0032> lwz r11,0(r2). Is there a way to get a little more high level than that? Also is there a way to see what the current values of local variables are? I see a memory window, but again it's just registers and hex values. Is there no higher-level debug mode?
Either the error occurred in some piece of code outside of your project, or you're not looking at the right window pane. There should be options to show local variables and single-step through source code.
__________________
Mehce
savar is offline   0 Reply With Quote
Old May 2, 2006, 07:25 PM   #7
whooleytoo
macrumors 603
 
whooleytoo's Avatar
 
Join Date: Aug 2002
Location: Cork, Ireland.
Send a message via AIM to whooleytoo
Quote:
Originally Posted by jamdr
Thanks for the reply. I see the debug mode, but I still don't get it. If I run my code in the debugger and an error occurs, I just see a window pop up full of assembly code. So the error occurred at 0xfffeff20 <+0032> lwz r11,0(r2). Is there a way to get a little more high level than that? Also is there a way to see what the current values of local variables are? I see a memory window, but again it's just registers and hex values. Is there no higher-level debug mode?
Do you use an NSScanner object in your code? If so, put a breakpoint on this line (or a line previous to it) and debug. Then step over the line where you allocate/use the NSScanner, and see what happens.
__________________
Mac <- Macintosh <- McIntosh apples <- John McIntosh <- McIntosh surname <- "Mac an toshach" <- "Son of the Chief"
whooleytoo is offline   0 Reply With Quote
Old Dec 23, 2010, 05:29 AM   #8
nareck
macrumors newbie
 
Join Date: Dec 2010
Thanks to the repliers!
Even after 4 and a half year it helps the newbies
nareck is offline   0 Reply With Quote
Old Dec 23, 2010, 12:32 PM   #9
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by jamdr View Post
I'm new to Obj-C and when I tried to run my application I got this error in the run log:

2006-04-30 01:01:18.940 MyProject[404] NSScanner: nil string argument

I don't really understand what that means because I don't know where in my code the error occurred. Is one of those numbers a line number? XCode's debugger seems really unintuitive. I'm used to eclipse, where if an error occurs you can jump right to the part of your code where the problem is. How can I do this in XCode?
By the way, anything that is in the run log will be there because the developer put an "NSLog" statement into their code which was executed, and that NSLog statement will put whatever the developer wanted into the code. It is not an error. If you have an error where the program would crash, and you run under the debugger, then XCode will go to the place of the crash.
gnasher729 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
xcode debug issue ip.kban Mac Programming 2 Dec 7, 2013 07:01 AM
Moving from xcode 3.2 to xcode 4.5.2 compilation error for 'abs' macro in stdlib.h hrishidev Mac Programming 7 Jun 2, 2013 11:36 AM
View NSArrays while Debug'n larswik iPhone/iPad Programming 2 Feb 17, 2013 02:33 AM
XCode asking for password to Build & Debug BadWolf13 Mac Programming 5 Nov 14, 2012 07:45 PM
Debug iOS from Terminal Garbag3man117 iPhone/iPad Programming 0 Jun 10, 2012 05:26 PM

Forum Jump

All times are GMT -5. The time now is 06:22 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC