Xcode - scribble, guard edges and guard malloc

IphoneIosXcodeMacos

Iphone Problem Overview


Can someone explain what do these options in Xcode do?

  • Enable Scribble
  • Enable Guard Edges
  • Enable Guard Malloc

what they are and what they do and how useful can they be for debugging/testing?

thanks.

Iphone Solutions


Solution 1 - Iphone

From the http://developer.apple.com/library/ios/documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/055-Build_and_Run_Your_App/build_app.html">documentation</a>;.

  • Enable Scribble. Fill allocated memory with 0xAA and deallocated memory with 0x55.
  • Enable Guard Edges. Add guard pages before and after large allocations.
  • Enable Guard Malloc. Use libgmalloc to catch common memory problems such as buffer overruns and use-after-free.

Scribble will make it rather obvious that you're using a memory block after it's free'd by overwriting any data that used to be in the memory block upon free.
Guard edges and Guard Malloc will help you find memory overruns and (to some extent) use-after-free by read and write protecting memory blocks to make your program crash more obviously if misusing memory.

Solution 2 - Iphone

The "documentation" link above is to Xcode in general, but more specifically RN-MallocOptions covers these (and other) options in detail.

Jim Kubicek shows a nice example in Debugging Smashed Memory in Obj-C, including the important "How do I enable these in Xcode?" question:

> Open the ‘Edit Scheme’ window and navigate to the Diagnostics tab. You’ll want to turn on “Enable Scribble” and “Malloc Stack”. ... in short, “Enabled Scribble” will cause the allocator to write 0xAA to newly allocated memory and write 0x55 to deallocated memory. “Malloc Stack” will log the allocation and free history of your memory.

If you've read this far, you'll probably be interested in Apple's Technical Notes:

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDuckView Question on Stackoverflow
Solution 1 - IphoneJoachim IsakssonView Answer on Stackoverflow
Solution 2 - IphoneNuthatchView Answer on Stackoverflow