gdb on iPhone

gdb on iPhone,第1张

概述General Break on szone_error not working [permalink] Sometimes when you have memory corruption issues, the malloc library happily informs you: Borkdoku(11062,0xcec0600) malloc: *** error for object 0x @H_419_6@General Break on szone_error not working [permalink]
Sometimes when you have memory corruption 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 gotten szone_error to actually do anything. Try breaking on malloc_printf instead.

 

Breaking on exceptions [permalink]
It can be annoying tracking down the cause of thrown exceptions in Cocoa. you get a notice like 2007-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 tell gdb 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'll get set no matter how you invoke gdb (no need to add these to every single project,for instance).

I've been told VoiceOver uses exceptions 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 = '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 and so on.
(gdb) print (char*) $r4 = 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 use wchar_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 on libgmalloc 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"]

 

@H_419_6@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") = (struct objc_object *) 0xa0a051d8gdb) call (ID)[ bundleWithPath:@"/blah/blah/PoseAsClassBundle.bundle"] = (struct objc_object *) 0x51467e0(gdb) call (BOol)[ load]Reading symbols for shared librarIEs . done
一个挺好的网站:http://www.borkware.com/quickies/
总结

以上是内存溢出为你收集整理的gdb on iPhone全部内容,希望文章能够帮你解决gdb on iPhone所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1069894.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存