Friday, March 13, 2009

Debugging

I've been wanting do to a post on using the Debugger in Xcode, since that's a topic that had to be cut from the book. Knowing how to debug gets to be rather important as you start writing your own programs, especially as those programs get to be bigger and more complex. Unfortunately, I'm heads down right now trying to get caught up on a couple of different things, and just haven't had the time to do full blog post on the topic.

I did, however, take a break last night to record a short screencast on Debugging in Xcode. There's very little editing in this, so it's not as polished as some screencasts, but if you're new to Xcode or to programming in general, I think you'll benefit from watching it. It shows the basics of using the debugger, including breakpoints, conditional breakpoints, and using breakpoint actions. Click the image to play the movie.





16 comments:

John Keyes said...

This was great -- thanks Jeff!

karstenbriksoft said...

nice screencast, but the mouse-click sound is really distracting. You already enabled the mouse click highlighting so the sound is really a bit too much.

Karsten

Jeff LaMarche said...

I'll see if I can't turn it off... it's a new program for me, not very familiar with its features yet.

Cyril said...

As usual, great post, and great screencast.

Two or three personal comments :
- I use the all in one view, and get the debug + log window all in one.
- print description to console int he context menu seems to be the same as po.
- you should add obc_exception_throw in your global breakpoints.

Looking forward to the Instruments screencast!

Jeff LaMarche said...

D'oh! Cyril, now I feel stupid. I didn't even talk about symbolic breakpoints!

I'll have to do an addendum posting to show how to set a symbolic breakpoint using objc_exception_throw as an example.

jozero said...

That was super informative, thanks. I've been looking for the one step beyond 'caveman debugging' explanation. One item I'm having difficulty with is since items can run asynchronously (say a gui updated, nsurl call, nsthread, etc) if an app crashes its hard to find exactly what is causing the crash - here caveman debugging is of no value. I tried to use 'info symbol' to print out the lowest value of a stack crash but more often than not get 'line is junk' message. How do you narrow down a crash ? Am I missing something obvious - is there a way to get an explicit 'the app crashed in this object in this method on this line' information ?

thanks. I've enjoyed reading your book.

Jeff LaMarche said...

Jozero:

If it's a overreleasing error, it's going to be hard to set a breakpoint for it, because the error's often going to happen when the autorelease pool is drained, regardless of where the actual problem is in your code.

Cyril's suggestion above, is a good one, though - set a symbolic breakpoint for objc_exception_throw, which will stop execution at the line of code where the exception happened. Very helpful, and I'm going to do a follow up showing how to do symbolic breakpoints in a day or two if I can find the time, but it's pretty easy to do, if you Google it, there are a few blogs that show how to do it.

Jeff

nicedexter said...

Great, thanks

In a Breakpoint Log, how would you print out the description, says of an NSURL *url, like it would do with "po url" ?

Manu

Frederik W said...

I just posted a (positive) review on Amazon for your book, pointing out that I felt some information on debugging was missing. I felt pretty lost when I had done a typo and all I got was a blank simulator. So I was really psyched to find this post. Thanks!, and also thanks for an excellent book.

Joe said...

Excellent, very informative, love your book as well. The conditional breakpoint info was worth the watch alone for me! Thanks for your efforts. :-)

Sebastian said...

How would you realize something like
NSLog(@"x %f",myView.center.x);
with this breakpoint logging ?

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

JeansPilot said...

JeansPilot offers the chance to buy a large variety of men’s and women’s jeans clothing from the world famous Italian Brands.
Online jeans clothing store looks for original fashion clothing sales and clearances of worldwide known designers. We participate in fashion auctions to get the lowest possible price for Top quality Clothes, Shoes and Accessories.
Buy Jeans

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels

John Hsu said...

Best thing I've ever seen on getting started with Xcode debugging - you solved several mysteries for me in a few short minutes.

Many thanks!

bamhm182 said...

I've been doing "Caveman debugging" since I started with XCode in 2009. Never felt the need to actually learn how to properly debug, but your video left me going ":O... WHAT have I been DOING all these years!?!" haha. Great video, Part 2 is amazing as well.