Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4: Can't use Enable Guard Malloc due to dylib error for iPad simulator

In Xcode 4.x I've edited my Run scheme to 'Enable Guard Malloc' since I have a nondescript malloc error I need to track down. I'm aware I need to run in the simulator to use this feature. However, when I do so the app immediately freezes and Xcode shows me a stack trace that looks like this:

Stack trace in Xcode 4.x

I've googled around to find a solution, but thus far no joy. It was reported elsewhere that I should be setting an environment variable in my scheme:

DYLD_INSERT_LIBRARIES  ->  /usr/lib/libgmalloc.dylib

However this doesn't solve the problem. I have also tried 'lsystem' as the value, but that didn't work either.

Can anyone suggest a solution to this dylib issue, or perhaps recommend an alternative to 'Enable Guard Malloc' to identify where a malloc'd heap area is being exceeded?

UPDATE

To clarify, this is the type of error I'm dealing with:

malloc: *** error for object 0x2b4b54: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug

I've tried setting a symbol breakpoint of malloc_error_break, however it still breaks 'randomly' upon memory issues rather than at the point of exceeding an allocated region.

like image 726
KomodoDave Avatar asked Oct 14 '11 07:10

KomodoDave


1 Answers

To help with the debugging you can set MallocStackLogging, then when your App crashes, type this in the gdb console:

(gdb) info malloc-history 0x543216

Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.

See this article for more detailed instructions.

like image 70
chown Avatar answered Oct 21 '22 06:10

chown