Xcode - scribble, guard edges and guard malloc

后端 未结 2 722
感动是毒
感动是毒 2020-12-13 12:18

Can someone explain what do these options in Xcode do?

  • Enable Scribble
  • Enable Guard Edges
  • Enable Guard Malloc

what they are an

相关标签:
2条回答
  • 2020-12-13 12:57

    From the documentation.

    • 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.

    0 讨论(0)
  • 2020-12-13 12:58

    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:

    • Technical Note TN2239 - iOS Debugging Magic
    • Technical Note TN2124 - Mac OS X Debugging Magic
    0 讨论(0)
提交回复
热议问题