您的位置:首页 > 产品设计 > UI/UE

Magic Debug Values(神奇的调试值)

2007-01-10 11:34 316 查看
摘自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".
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: