fbrereto
fbrereto

Reputation: 35935

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?

Upvotes: 12

Views: 17146

Answers (4)

Teemu Kurppa
Teemu Kurppa

Reputation: 4849

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

Upvotes: 17

Justyn
Justyn

Reputation: 1500

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…

Upvotes: 4

Wevah
Wevah

Reputation: 28242

If you use NSZombieEnabled you can at least figure out what class the object is.

Upvotes: 4

Related Questions