windbg 使用指南《一》

來源:互聯網
上載者:User

安裝完WinDbug之後,在WinDbug路徑下會有一個UMDH.exe的檔案,通過這個檔案可以通過“棧回溯資料庫”的方式定位應用程式記憶體泄露的地方。

The User-Mode Dump Heap (UMDH) tool, Umdh.exe, analyzes the Microsoft Windows heap memory allocations for a given process. UMDH has the following modes.

  • Analyze a running process ("Mode 1"). UMDH captures and analyzes the heap memory allocations for a process. For each allocation, UMDH displays the size of the allocation, the size of the overhead, the pointer
    to the allocation and the allocation stack. If a process has more than one active memory heap, UMDH captures all heaps.
  • Analyze UMDH log files ("Mode 2"). UMDH analyzes the logs to help detect memory leaks. When comparing two UMDH output logs from subsequent runs of a UMDF driver, UMDH displays the calls in which the allocation
    size increased the most between the runs. 


umdh只能針對分配了記憶體,但是沒有進行釋放的程式起到檢測作用。除了umdh.exe 通過!heap 也可找到增長的那個堆,並找到對應的棧資訊,從而定位到函數源碼。

A:UMDH方式

建立應用程式WinDbugTest.exe

1.cmd視窗轉到gflags.exe目錄(WinDbug路徑),運行:gflags.exe -i F:\Test|WinDbugTest\\Debug\WinDbugTest.exe +ust  來啟用目標程式的ust功能

2.開啟應用程式WinDbugTest.exe不執行任何操作;

3.cmd視窗轉到umdh.exe目錄(WinDbug路徑),運行:umdh.exe -pn:WinDbugTest.exe -f:u1.log               記錄當前棧引用資料庫相關資訊

4.對程式進行相關操作,執行一些建立記憶體以及釋放記憶體的操作。

5.cmd視窗轉到umdh.exe目錄(WinDbug路徑),運行:umdh.exe -pn:WinDbugTest.exe -f:u2.log               記錄當前棧引用資料庫相關資訊

6.cmd視窗轉到umdh.exe目錄(WinDbug路徑),運行:umdh.exe u1.log  u2.log  -f:u3.log                              將之前擷取的棧引用資料庫資訊進行對比來找到出現異常的地址

 

B:!Heap方式

   1.!heap -s

   2.!heap -stat -h XXXXX

   3.!heap -flt s  XX

   4.!heap -p -a VVV

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.