Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How best to debug a crash within objc_msgSend?

I have a crash taking place when an NSAutoreleasePool drains. Presumably the pool is trying to deallocate an object that has been prematurely released by another piece of code. The crash I have is in the midst of objc_msgSend as it is trying to send a message to an object that doesn't exist anymore.

Given the stack state, what tips/tricks/processes/gdb commands do I have at my disposal to get information about the object in question and/or the point at which the illegitimate deallocation took place?

like image 1000
fbrereto Avatar asked Aug 24 '09 21:08

fbrereto


3 Answers

I came across what appeared to be a crash in objc_msgSend. What was even stranger was application:didFinishLaunchingWithOptions: was not even getting reached before the so called crash occured!

In my case the crash turned out to be a breakpoint that I had inadvertantly set on a memory address that was getting called before any of my code was even reached.

enter image description here

After the hour or so of trying to figure this out, I unchecked the breakpoint, ran the code, face palmed and then continued my day pretending it had never happened…

like image 176
Justyn Avatar answered Oct 19 '22 23:10

Justyn


If you have a hunch that it is a premature deletion, enable zombies to confirm your hypothesis and then debug what is going on. When you enable zombies, objects are not really destroyed, but set to a zombie state, which helps you to detect when they are accessed after they dealloc is called. Read more from NSZombieEnabled

like image 29
Teemu Kurppa Avatar answered Oct 19 '22 22:10

Teemu Kurppa


The definitive article on this kind of crash: http://www.sealiesoftware.com/blog/archive/2008/09/22/objc_explain_So_you_crashed_in_objc_msgSend.html

like image 40
Pierre Houston Avatar answered Oct 20 '22 00:10

Pierre Houston