蒐集整理一些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. 內存狀態值的意義

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

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程序調試>>

 

 

發佈了21 篇原創文章 · 獲贊 4 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章