搜集整理一些VC调试技巧

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. 设置参数断点

  1. Set breakpoint
  2. Determine stack offset to argument (see disassembly window)
  3. 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程序调试>>

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值