Blog Archives

Printing a C array in the debugger Console

I’m by no means a GDB expert.  I know the basics, but I just learned this gem today.  Say you have a C array with five items created with something like this:

int *array = malloc(5 * sizeof(int));

And you want to print it out in the debugger quickly.  You can’t just print the pointer because GDB doesn’t know to print it as an array, but this will:

p *array@5


$1 = {0, 0, 0, 0, 0, 1}

To use this the left hand side, before the ‘@’ should be an array, and the right hand side needs to be the length of the array.  Very handy.

Xcode, We need to talk.

Dear Xcode:

I want to like you.  I really do.  But lately I feel as though all I’m doing is putting up with you.  O Xcode, how do I hate thee!  Let me count the ways:

  1. Least intuitive code-completion . . . ever.  Let’s say I’m typing the following:
    NSString *aString = [NSStr

    Why, oh why would you think I want an NSStream?  There’s not a single reference to an NSStream in the project.  I’m not sure I’ve EVER used NSStream.  I can’t imagine there’s anyone in the world who uses more NSStreams than NSStrings.  Aside from being earlier in an alphabetical sort, there’s no reason NSStream should ever appear.  You’re smart Xcode, I expect more.

  2. Please don’t make interface builder any slower.  My sanity can’t take it anymore.  Every time I accidentally click on a .xib I might as well go make some coffee, because that’s how long it will take to come up.
  3. And while we’re on the topic.  Why can I drag outlets to class file but I can reference the owner class as itself for things like delegates?  And why do you never know what object I’ve clicked on?  And why can’t I modify the dimensions of a default view?  Xcode, I think interface builder is a bad influence on you.
  4. GDB Disaster.  Code completion in GDB: Good idea.  Buggy code completion in GDB.  Awful idea.  I swear this works about 5% of the time that I actually get the object I want in the place I want.  The menu shows when it wants to, but usually it will just drop text in there as it feels like.  Why don’t we start by automatically inserting the opening square brace before we try to get clever about code completion here.
  5. Where’s my #@$%ing stack trace.  I could deal with you Xcode, and all your annoyances until you decided not to give me a stack trace on an unhandled exception.  At least I felt like you were on my side.  Now you’re just trying to make my life harder.  I guess you’re only willing to work with devs who memorize the addresses of their call stacks.

    WTF, Xcode?