Magic Debug Values(神奇的调试值)

摘自Azure's Blog

http://www.azure.com.cn/article.asp?id=233

Magic debug values are specific values written to memory during allocation or deallocation, so that it will later be possible to tell whether or not they have become corrupted and to make it obvious when values taken from uninitialized memory are being used.

Memory is usually viewed in hexadecimal, so common values used are often repeated digits or hexspeak.

Famous and common examples include:

0xBAADF00D
0xBAADFEED
0xBADBADBADBAD

Burroughs B6700 "uninitialized" memory (48-bit words)
0xC0EDBABE
0xC001D00D
0xCCCCCCCC

Used by Microsoft's C++ compiler to mark uninitialised stack areas in debug mode.
0xCDCDCDCD
Used by Microsoft's C++ debugging heap to mark uninitialised heap areas.
0xDDDDDDDD
Used by MicroQuill's SmartHeap and Microsoft's C++ debugging heap to mark memory returned to the heap.
0xDEADBEEF
Famously used on IBM systems such as the RS/6000, also in OPENSTEP Enterprise and the Commodore Amiga.
0xEBEBEBEB
From MicroQuill's SmartHeap.
OxFACADE
Used by a number of real-time OS's
0xFD
Used by Microsoft's C++ debugging heap to mark guard bytes in the heap.
0xFEEEFEEE
Used by Microsoft's C++ compiler to mark the storage area of a deleted class in debug mode.
Note that most of these are each 8 nybbles (32 bits) long, as most modern computers are designed to manipulate 32 bits at a time.

The prevalence of these values in Microsoft technology is no coincidence; they are discussed in detail in Steve McGuire's well-known book Writing Solid Code from Microsoft Press. He gives a variety of criteria for these values, such as:

They should not be useful; that is, most algorithms that operate on them should be expected to do something unusual. Numbers like zero don't fit this criterion.
They should be easily recognized by the programmer as invalid values in the debugger.
On machines that don't have byte alignment, they should be odd, so that dereferencing them as addresses causes an exception.
They should cause an exception, or perhaps even a debugger break, if executed as code.
Since they were often used to mark areas of memory that were essentially empty, some of these terms came to be used in phrases meaning "gone, aborted, flushed from memory"; e.g. "Your program is DEADBEEF".  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值