GDB on iPhone

Source: Internet
Author: User
Document directory
  • General
  • Hacks
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_errorTo actually do anything. Try breaking onmalloc_printfInstead.

     

  • 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 tellgdbTo always break on cocoa exceptions:
    fb -[NSException raise]fb objc_exception_throw()

    For maximal enjoyment, add these two lines to your~/.gdbinitFile, 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$r3And go up from there. For Objective-C method sends,$r3Has 'self ', and$r4Has the name of The method. Subsequent arguments are in$5And 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.gdbinitAnd 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 selectorsWill show you all of the selectors in the application's symbol table.info functionsWill show you all of the functions. You can supply regular expressions to limit the output.

     

  • Using libgmalloc in GDB[Permalink]
    libgmallocPuts 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 onlibgmallocIn 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
  • Loading a bundle into a running program[Permalink]
    Sometimes it's handy to load a bundle into a running app to do some poseasclass: For doing some debugging or reverse engineering. make a cocoa bundle which has the code you want to load, then do:

    (gdb) call (id) objc_getClass("NSBundle")$1 = (struct objc_object *) 0xa0a051d8gdb) call (id)[$1 bundleWithPath:@"/blah/blah/PoseAsClassBundle.bundle"]$2 = (struct objc_object *) 0x51467e0(gdb) call (BOOL)[$2 load]Reading symbols for shared libraries . done
A good site: http://www.borkware.com/quickies/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.