Document directory
General
- Break on szone_error not working[Permalink]
Sometimes when you have memory upload uption issues, the malloc library happily informs you:Borkdoku(11062,0xcec0600) malloc: *** error for object 0xd109010: incorrect checksum for freed object - object was probably modified after being freed, break at szone_error to debug
Which is fine and dandy, but it lies. I 've never gottenszone_error
To actually do anything. Try breaking onmalloc_printf
Instead.
- Breaking on exceptions[Permalink]
It can be annoying tracking down the cause of thrown exceptions in cocoa. You get a notice like2007-05-05 17:18:00.702 QueenStitcher[2804:117] *** Assertion failure in -[NSColorWell setColor:], NSColorWell.m:497, u suk l0s3r
, And then the runloop happily runs again, giving you no clue where the problem is. I tellgdb
To always break on cocoa exceptions:fb -[NSException raise]fb objc_exception_throw()
For maximal enjoyment, add these two lines to your~/.gdbinit
File, so they all get set no matter how you invokegdb
(No need to add these to every single project, for instance ).
I 've been told voiceover uses limits tions heavily, so if you're doing voiceover development, these breaks may cause you pain.
- Displaying four-character ints[Permalink]
Old-school Mac programming (and QuickTime, and other places) use four-character ints, things like'bork'
. You can have GDB print them out if you need to look at one or two of them:(gdb) print/T 1936746868$4 = 'spit'
(Thanks to Daniel jalkut for the print/t trick)
- Finding 'self 'on intel[Permalink]
(gdb) po *(int*)($ebp+8)
- Ignoring Signals[Permalink]
(gdb) handle SIGTRAP nostop
The signal still goes to your program. Another handy option is 'ignore' to prevent it coming to the program. Also there is 'print' to print a message go on.
- Printing method arguments[Permalink]
If you 've hit a breakpoint on a method that doesn' t have debug symbols, you can sometimes get useful information by looking in the processor registers. Arguments start in$r3
And go up from there. For Objective-C method sends,$r3
Has 'self ', and$r4
Has the name of The method. Subsequent arguments are in$5
And so on.(gdb) print (char*) $r4$5 = 0x90874160 "drawRect:"(gdb) po $r5<BWStitchView: 0x1a6670>
- Printing object retain count in GDB[Permalink]
In the GDB Console:
(gdb) print (int)[theObject retainCount]
If you're expecting to have an excessively high number of retains, you can use(unsigned int)
In the cast. I find(int)
A skootch faster to type.
- Printing wide character strings[Permalink]
GDB won't by default let you print wide character strings. here is a little bit of GDB code that'll let you print them. in case that page moves, here is the relevant stuff. paste this into your.gdbinit
And then you can usewchar_print
:define wchar_print echo " set $i = 0 while (1 == 1) set $c = (char)(($arg0)[$i++]) if ($c == '/0') loop_break end printf "%c", $c end echo "enddocument wchar_printwchar_print <wstr>Print ASCII part of <wstr>, which is a wide character string of type wchar_t*.end
- Seeing functions and selectors[Permalink]
info selectors
Will show you all of the selectors in the application's symbol table.info functions
Will show you all of the functions. You can supply regular expressions to limit the output.
- Using libgmalloc in GDB[Permalink]
libgmalloc
Puts guard pages at the end of malloc 'd blocks of memory, letting you catch buffer overruns. (This will hugely inflate your program's working set, and may lead to swapping) to turn onlibgmalloc
In GDB, do this:(gdb) set env DYLD_INSERT_LIBRARIES /usr/lib/libgmalloc.dylib
- Calling objective-C methods in GDB[Permalink]
To call an objective-C method in the GDB Console, You have to cast the return type (since GDB doesn't really know what the return value is ):(gdb) call (void)[textField setStringValue: @"Bork"]
Hacks
A good site: http://www.borkware.com/quickies/