Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - scribble, guard edges and guard malloc

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.

like image 912
Duck Avatar asked Mar 06 '12 19:03

Duck


People also ask

What is malloc scribble?

MallocScribble. If set, free sets each byte of every released block to the value 0x55 . MallocPreScribble. If set, malloc sets each byte of a newly allocated block to the value 0xAA . This increases the likelihood that a program making assumptions about freshly allocated memory fails.

How do I enable guard for malloc?

To enable debugging using Guard Malloc, choose the Run > Enable Guard Malloc option in Xcode before running your project. Building and running your application with this option enabled runs your application using the Guard Malloc library automatically.


1 Answers

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.

like image 190
Joachim Isaksson Avatar answered Sep 23 '22 14:09

Joachim Isaksson