PDA

View Full Version : How do you debug in XCode?




jamdr
Apr 30, 2006, 12:08 AM
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?



szymczyk
Apr 30, 2006, 01:09 AM
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.

jamdr
Apr 30, 2006, 12:39 PM
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?:(

szymczyk
Apr 30, 2006, 01:40 PM
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.

HiRez
Apr 30, 2006, 02:24 PM
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.

savar
Apr 30, 2006, 03:36 PM
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.

whooleytoo
May 2, 2006, 06:25 PM
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.

nareck
Dec 23, 2010, 04:29 AM
Thanks to the repliers!
Even after 4 and a half year it helps the newbies ;)

gnasher729
Dec 23, 2010, 11:32 AM
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.