【Visual Leak Detector】配置項 ReportTo

来源:https://www.cnblogs.com/young520/archive/2023/03/29/17263205.html
-Advertisement-
Play Games

使用 VLD 記憶體泄漏檢測工具輔助開發時整理的學習筆記。本篇介紹 VLD 配置文件中配置項 ReportTo 的使用方法。 ...


說明

使用 VLD 記憶體泄漏檢測工具輔助開發時整理的學習筆記。本篇介紹 VLD 配置文件中配置項 ReportTo 的使用方法。同系列文章目錄可見 《記憶體泄漏檢測工具》目錄

目錄


1. 配置文件使用說明

在程式中通過 #include "vld.h" 的方式檢測記憶體泄漏時,VLD 首先會嘗試在程式的生成目錄下讀取 vld.ini 文件,若未讀取成功,則會嘗試在 VLD 的安裝目錄下讀取 vld.ini 文件,若仍未讀取成功,則會使用內置的預設配置,內置的預設配置如果不動源碼是無法更改的,因此通過修改相應目錄下的 vld.ini 文件來定製 VLD 功能是最好的選擇。當配置參數等號右邊為空,或者給配置了不合法值時,在使用過程中會被程式重置到預設值。

2. 設置報告輸出的位置

參數名ReportTo

有效賦值debuggerfileboth

預設值debugger

功能說明:設置泄漏檢測報告的輸出位置,輸出到調試控制台(debugger)、輸出到文件(file)、控制台和文件都輸出(both),當報告可以輸出到文件時,文件路徑會使用 ReportFile 指定的值(預設值為 .\memory_leak_report.txt)。

2.1 測試代碼

#include <QCoreApplication>
#include "vld.h"

void testFun(int i)
{
    int *ptr = new int(i);
    printf("ptr = %08x, *ptr = %08x.\n", ptr, *ptr);
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    testFun(1);

    return a.exec();
}

測試環境:QT 5.9.2MSVC 2015 32bitDebug 模式,VLD 版本為 2.5.1,VLD 配置文件只對該參數做修改,測試工程所在路徑為:E:\Cworkspace\Qt 5.9\QtDemo\testVLD

2.2 ReportTo = debugger 時的輸出

標準輸出窗顯示:

ptr = 00f57a30, *ptr = 00000001.

VLD 輸出報告(控制台):

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x00F57A30: 4 bytes ----------
  Leak Hash: 0x78A7E46A, Count: 1, Total 4 bytes
  Call Stack (TID 23728):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x7 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (14): testVLD.exe!main() + 0x7 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    01 00 00 00                                                  ........ ........


Visual Leak Detector detected 1 memory leak (40 bytes).
Largest number used: 40 bytes.
Total allocations: 40 bytes.
Visual Leak Detector is now exiting.

2.3 ReportTo = file 時的輸出

標準輸出窗顯示:

ptr = 01059490, *ptr = 00000001.

VLD 輸出報告(控制台):

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini

VLD 輸出報告(文件 memory_leak_report.txt):

Visual Leak Detector Version 2.5.1 installed.
    Outputting the report to E:\Cworkspace\Qt 5.9\QtDemo\build-testVLD-Desktop_Qt_5_9_2_MSVC2015_32bit-Debug\memory_leak_report.txt
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x01059490: 4 bytes ----------
  Leak Hash: 0x78A7E46A, Count: 1, Total 4 bytes
  Call Stack (TID 15680):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x7 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (14): testVLD.exe!main() + 0x7 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    01 00 00 00                                                  ........ ........


Visual Leak Detector detected 1 memory leak (40 bytes).
Largest number used: 40 bytes.
Total allocations: 40 bytes.
Visual Leak Detector is now exiting.

2.4 ReportTo = both 時的輸出

標準輸出窗顯示:

ptr = 00ebb038, *ptr = 00000001.

VLD 輸出報告(控制台):

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
    Outputting the report to the debugger and to E:\Cworkspace\Qt 5.9\QtDemo\build-testVLD-Desktop_Qt_5_9_2_MSVC2015_32bit-Debug\memory_leak_report.txt
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x00EBB038: 4 bytes ----------
  Leak Hash: 0x78A7E46A, Count: 1, Total 4 bytes
  Call Stack (TID 13352):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x7 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (14): testVLD.exe!main() + 0x7 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    01 00 00 00                                                  ........ ........


Visual Leak Detector detected 1 memory leak (40 bytes).
Largest number used: 40 bytes.
Total allocations: 40 bytes.
Visual Leak Detector is now exiting.

VLD 輸出報告(文件 memory_leak_report.txt):

Visual Leak Detector Version 2.5.1 installed.
    Outputting the report to the debugger and to E:\Cworkspace\Qt 5.9\QtDemo\build-testVLD-Desktop_Qt_5_9_2_MSVC2015_32bit-Debug\memory_leak_report.txt
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x00EBB038: 4 bytes ----------
  Leak Hash: 0x78A7E46A, Count: 1, Total 4 bytes
  Call Stack (TID 13352):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x7 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (14): testVLD.exe!main() + 0x7 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    01 00 00 00                                                  ........ ........


Visual Leak Detector detected 1 memory leak (40 bytes).
Largest number used: 40 bytes.
Total allocations: 40 bytes.
Visual Leak Detector is now exiting.

2.5 輸出結果對比

  • ReportTo = debugger 時,泄漏報告只會輸出到調試控制臺中。
  • ReportTo = file 時,泄漏報告只會輸出到指定文件中,控制台只列印配置文件讀取情況。
  • ReportTo = both 時,泄漏報告同時輸出到調試控制台與指定文件中,文件中除了第一行沒有輸出配置文件讀取情況外,其他地方與調試控制台的輸出保持一致。

本文作者:木三百川

本文鏈接:https://www.cnblogs.com/young520/p/17263205.html

版權聲明:本文系博主原創文章,著作權歸作者所有。商業轉載請聯繫作者獲得授權,非商業轉載請附上出處鏈接。遵循 署名-非商業性使用-相同方式共用 4.0 國際版 (CC BY-NC-SA 4.0) 版權協議。


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 作為 C 端前端研發,除了攻剋業務難點以外,也要有更深層的自我目標,那就是性能優化。這事兒說大不大,說小也不小,但難度絕對不一般,所涉及的範圍優化點深入工程每個細胞。做好前端性能優化絕非簡單之事!文章主要內容介紹前端性能考核指標及優化方案。 ...
  • Vue Router 是 Vue.js 的官方路由管理器,它可以幫助我們實現單頁應用(Single Page Application,SPA)的前端路由。 Vue Router 基於 Vue.js 的組件化思想,將路由視為組件,並提供了多種方式來定義路由和渲染組件。Vue Router 可以通過 U ...
  • 解釋器模式(Interpreter Pattern):是一種行為型設計模式,它可以用來解決一些特定問題,例如編譯器、計算器等等。這種模式定義了一個語言的語法,並用一個解釋器來解釋語言中的表達式。 解釋器模式可以用來處理例如數據格式化、表單驗證等業務場景。在這些場景中,我們需要定義一些語法規則,然後使 ...
  • Axios是一個基於Promise的HTTP客戶端,用於在瀏覽器和Node.js中發送HTTP請求。它可以使用在Vue中發送請求以及與後端API進行交互。 在Vue中使用Axios可以通過以下步驟: 安裝Axios 可以通過npm或yarn來安裝Axios:npm install axios yar ...
  • 3D 全景技術可以實現日常生活中的很多功能需求,比如地圖的街景全景模式、數字展廳、線上看房、社交媒體的全景圖預覽、短視頻直播平臺的全景直播等。Three.js 實現全景功能也是十分方便的,本文將介紹如何一步步優雅實現在多個3D全景中穿梭漫游,達到如在真實世界中前進後退的視覺效果。全景漫游系列文章將分... ...
  • XSS攻擊是什麼? XSS攻擊是指攻擊者利用網站中的漏洞,向頁面中註入惡意腳本,從而獲取用戶的信息或者控制用戶的電腦。 舉一個通俗的例子,早期使用JSP頁面渲染頁面的項目,如果將用戶名改成nick<alert>1</alert>,則當用戶打開頁面時,就會彈出一個警告框,而這個警告框可以被惡意腳本所 ...
  • 一站式的消息管理器 在網路應用中,消息處理是必不可少的,該文章主要簡單介紹一款簡單的消息管理器的實現,其具備以下功能: 提供多種消息序列化和反序列化方式,目前支持JDK、ProtoStuff以及JSON,提供其他自定義的序列化/反序列化器插口。 提供多種消息加密/解密,目前支持對稱加密:AES、不對 ...
  • 使用 VLD 記憶體泄漏檢測工具輔助開發時整理的學習筆記。本篇介紹 VLD 配置文件中配置項 SelfTest 的使用方法。 ...
一周排行
    -Advertisement-
    Play Games
  • .Net8.0 Blazor Hybird 桌面端 (WPF/Winform) 實測可以完整運行在 win7sp1/win10/win11. 如果用其他工具打包,還可以運行在mac/linux下, 傳送門BlazorHybrid 發佈為無依賴包方式 安裝 WebView2Runtime 1.57 M ...
  • 目錄前言PostgreSql安裝測試額外Nuget安裝Person.cs模擬運行Navicate連postgresql解決方案Garnet為什麼要選擇Garnet而不是RedisRedis不再開源Windows版的Redis是由微軟維護的Windows Redis版本老舊,後續可能不再更新Garne ...
  • C#TMS系統代碼-聯表報表學習 領導被裁了之後很快就有人上任了,幾乎是無縫銜接,很難讓我不想到這早就決定好了。我的職責沒有任何變化。感受下來這個系統封裝程度很高,我只要會調用方法就行。這個系統交付之後不會有太多問題,更多應該是做小需求,有大的開發任務應該也是第二期的事,嗯?怎麼感覺我變成運維了?而 ...
  • 我在隨筆《EAV模型(實體-屬性-值)的設計和低代碼的處理方案(1)》中介紹了一些基本的EAV模型設計知識和基於Winform場景下低代碼(或者說無代碼)的一些實現思路,在本篇隨筆中,我們來分析一下這種針對通用業務,且只需定義就能構建業務模塊存儲和界面的解決方案,其中的數據查詢處理的操作。 ...
  • 對某個遠程伺服器啟用和設置NTP服務(Windows系統) 打開註冊表 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer 將 Enabled 的值設置為 1,這將啟用NTP伺服器功 ...
  • title: Django信號與擴展:深入理解與實踐 date: 2024/5/15 22:40:52 updated: 2024/5/15 22:40:52 categories: 後端開發 tags: Django 信號 松耦合 觀察者 擴展 安全 性能 第一部分:Django信號基礎 Djan ...
  • 使用xadmin2遇到的問題&解決 環境配置: 使用的模塊版本: 關聯的包 Django 3.2.15 mysqlclient 2.2.4 xadmin 2.0.1 django-crispy-forms >= 1.6.0 django-import-export >= 0.5.1 django-r ...
  • 今天我打算整點兒不一樣的內容,通過之前學習的TransformerMap和LazyMap鏈,想搞點不一樣的,所以我關註了另外一條鏈DefaultedMap鏈,主要調用鏈為: 調用鏈詳細描述: ObjectInputStream.readObject() DefaultedMap.readObject ...
  • 後端應用級開發者該如何擁抱 AI GC?就是在這樣的一個大的浪潮下,我們的傳統的應用級開發者。我們該如何選擇職業或者是如何去快速轉型,跟上這樣的一個行業的一個浪潮? 0 AI金字塔模型 越往上它的整個難度就是職業機會也好,或者說是整個的這個運作也好,它的難度會越大,然後越往下機會就會越多,所以這是一 ...
  • @Autowired是Spring框架提供的註解,@Resource是Java EE 5規範提供的註解。 @Autowired預設按照類型自動裝配,而@Resource預設按照名稱自動裝配。 @Autowired支持@Qualifier註解來指定裝配哪一個具有相同類型的bean,而@Resourc... ...