Xcode - 涂鸦、保护边缘和保护 malloc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9590350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:32:45  来源:igfitidea点击:

Xcode - scribble, guard edges and guard malloc

iphoneiosxcodemacos

提问by DuckDucking

Can someone explain what do these options in Xcode do?

有人能解释一下 Xcode 中的这些选项有什么作用吗?

  • Enable Scribble
  • Enable Guard Edges
  • Enable Guard Malloc
  • 启用涂鸦
  • 启用防护边缘
  • 启用 Guard Malloc

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

它们是什么,它们做什么以及它们对调试/测试有多大用处?

thanks.

谢谢。

采纳答案by Joachim Isaksson

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.
  • 启用涂鸦。用 0xAA 填充分配的内存,用 0x55 填充释放的内存。
  • 启用防护边缘。在大量分配之前和之后添加保护页。
  • 启用 Guard Malloc。使用 libgmalloc 来捕获常见的内存问题,例如缓冲区溢出和释放后使用。

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.

Scribble 将使您在释放内存块后使用内存块变得相当明显,因为它会在释放时覆盖曾经在内存块中的任何数据。
Guard edge 和 Guard Malloc 将通过读写保护内存块来帮助您找到内存溢出和(在某种程度上)释放后使用,使您的程序在滥用内存时更明显地崩溃。

回答by Nuthatch

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

上面的“文档”链接通常指向 Xcode,但更具体地说,RN-MallocOptions 详细介绍了这些(和其他)选项。

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

Jim Kubicek 在Debugging Smashed Memory in Obj-C 中展示了一个很好的例子,包括重要的“我如何在 Xcode 中启用这些?” 题:

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.

打开“编辑方案”窗口并导航到“诊断”选项卡。您需要打开“Enable Scribble”和“Malloc Stack”。...简而言之,“启用涂鸦”将导致分配器将 0xAA 写入新分配的内存并将 0x55 写入释放的内存。“Malloc Stack”会记录你内存的分配和释放历史。

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

如果你读到这里,你可能会对 Apple 的技术说明感兴趣: