您的位置:首页 > 其它

搜集整理一些VC调试技巧

2008-06-11 18:33 357 查看
1. 常用VC调试用伪寄存器表

Complete list of pseudoregisters

Pseudoregister

Description

@ERR

Last error value; the same value returned by the
GetLastError()
API function

@TIB

Thread information block for the current thread; necessary because the debugger doesn't handle the "FS:0" format

@CLK

Undocumented clock register; usable only in the Watch window

@EAX, @EBX, @ECX, @EDX, @ESI, @EDI, @EIP, @ESP, @EBP, @EFL

Intel CPU registers

@CS, @DS, @ES, @SS, @FS, @GS

Intel CPU segment registers

@ST0, @ST1, @ST2, @ST3, @ST4, @ST5, @ST6, @ST7

Intel CPU floating-point registers

[Table from "Debugging Applications" by John Robbins]

2. 显示最近错误说明: @err,hr

hr代表错误号的说明

wm代表windows消息

3. 列表数组.

默认情况下,一个指针仅显示其地址的第一个值,如果这个指针代表数组可以实用如下格式来显示指定数量的数组元素:

指针,数量

如"ptr,10",用于显示指针ptr指向地址的10个元素值,"(ptr+1000),10"查看第1000个开始的10个元素

4. 内存状态值的意义

ValueUsage
0xCDCDCDCDAllocated in heap, but not initialized
0xDDDDDDDDReleased heap memory.
0xFDFDFDFD"NoMansLand" fences automatically placed at boundary of heap memory. Should never be overwritten. If you do overwrite one, you're probably walking off the end of an array.
0xCCCCCCCCAllocated on stack, but not initialized
5. 设置参数断点

Set breakpoint

Determine stack offset to argument (see disassembly window)

Set condition e.g. dw esp+0x8 == 0xFFFFFFFF

6. 检查堆内存破坏

Enable heap checking (slow)
{,,msvcrtd.dll}_crtDbgFlag = 5

7. 检查内存泄露

Include order is important
Some things redefine malloc and free, etc.
Step 1, include in global header file
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
Step 2, enable checks in WinMain:
// Enables tracking and reporting on shutdown.
_CrtSetDbgFlag (
_CRTDBG_ALLOC_MEM_DF |
_CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode ( _CRT_ERROR,
_CRTDBG_MODE_DEBUG);
8. 模块中对象类型cast

variable defined in current DLL, type defined in another
DLL:
{,,foo.dll}(CMyClass *){*}pObject
pObject is local, CMyClass defined in foo.dll

9. 编译debug正常,Release不正常

Uninitialized variables

Often 0 used in debug builds

Unless /GZ switch is enabled

Under/Overruns of memory

use debug heap (running in debugger on NT)

Wrong calling convention (esp. GetProcAddress)

Use /GZ in compiler

Optimizer unforgiving

Overwriting locals more likely

Locals packed on stack

Locals reused

10 调试时不正常,不调试正常

使用附加到进程方式进行调试(直接调试时使用的是调试堆)

查看项目属性中关于调试参数的设置,修改调试目录

4. 建议书籍<<Windows程序调试>>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: