搜集整理一些VC调试技巧
2008-06-11 18:33
357 查看
1. 常用VC调试用伪寄存器表
[Table from "Debugging Applications" by John Robbins]
2. 显示最近错误说明: @err,hr
hr代表错误号的说明
wm代表windows消息
3. 列表数组.
默认情况下,一个指针仅显示其地址的第一个值,如果这个指针代表数组可以实用如下格式来显示指定数量的数组元素:
指针,数量
如"ptr,10",用于显示指针ptr指向地址的10个元素值,"(ptr+1000),10"查看第1000个开始的10个元素
4. 内存状态值的意义
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程序调试>>
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 |
2. 显示最近错误说明: @err,hr
hr代表错误号的说明
wm代表windows消息
3. 列表数组.
默认情况下,一个指针仅显示其地址的第一个值,如果这个指针代表数组可以实用如下格式来显示指定数量的数组元素:
指针,数量
如"ptr,10",用于显示指针ptr指向地址的10个元素值,"(ptr+1000),10"查看第1000个开始的10个元素
4. 内存状态值的意义
Value | Usage |
---|---|
0xCDCDCDCD | Allocated in heap, but not initialized |
0xDDDDDDDD | Released 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. |
0xCCCCCCCC | Allocated on stack, but not initialized |
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程序调试>>
相关文章推荐
- 一些VC的快捷键以及调试技巧
- 一些VC的快捷键以及调试方法技巧
- 一些VC的快捷键以及调试方法技巧
- 一些VC的快捷键以及调试方法技巧
- 一些VC的快捷键以及调试方法技巧【转】
- 一些VC的快捷键以及调试方法技巧
- 一些VC的快捷键以及调试方法技巧
- VC中的一些调试技巧
- vc 6.0开发工具与调试技巧整理
- 一些VC的快捷键以及调试方法技巧
- VC调试技巧收集整理
- 一些VC的快捷键以及调试技巧
- vc++ 调试技巧整理
- VC中的一些调试技巧
- VC中的一些调试技巧
- 一些VC的快捷键以及调试方法技巧
- 一些VC的快捷键以及调试方法技巧
- VC++开发工具与调试技巧整理
- 一些VC的快捷键以及调试技巧
- 一些VC的快捷键以及调试方法技巧