首页 > 其他分享 >Qt Visual Leak Detector 输出解析(四)

Qt Visual Leak Detector 输出解析(四)

时间:2024-03-04 18:44:54浏览次数:19  
标签:exe Qt Leak bytes Visual Detector testVLD

1. 使用方式

  在 QT 中使用 VLD 的方法可以查看另外几篇博客:

  • QT 使用 Visual Leak Detector(方式一)
  • QT 使用 Visual Leak Detector(方式二)
  • QT 使用 Visual Leak Detector(方式三)

  本次测试使用的环境为:QT 5.9.2,Debug 模式,VLD 版本为 2.5.1,VLD 配置文件不做任何更改使用默认配置,测试工程所在路径为:E:\Cworkspace\Qt 5.9\QtDemo\testVLD。

2. 测试代码

  写一个有一处内存泄漏的程序,如下:

 1 #include <QCoreApplication>
 2 #include "vld.h"
 3 
 4 void testFun()
 5 {
 6     int *ptr = new int(0x55345678);
 7     printf("ptr = %08x, *ptr = %08x", ptr, *ptr);
 8 }
 9 
10 int main(int argc, char *argv[])
11 {
12     QCoreApplication a(argc, argv);
13 
14     testFun();
15 
16     return a.exec();
17 }

3. 使用 32 bit 编译器时的输出

  使用 MSVC 2015 32bit 编译器,程序运行时,在标准输出窗会输出以下结果:

ptr = 0070a3d0, *ptr = 55345678

  程序运行结束后,检测到了内存泄漏,VLD 会输出以下报告(本例中出现一处内存泄漏),第 1~3 行显示 VLD 运行状态,第 4~21 行显示泄漏内存的详细信息,第 22~24 行总结此次泄漏情况,第 25 行显示 VLD 退出状态。

 1 Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
 2 Visual Leak Detector Version 2.5.1 installed.
 3 WARNING: Visual Leak Detector detected memory leaks!
 4 ---------- Block 1 at 0x0070A3D0: 4 bytes ----------
 5   Leak Hash: 0xA7ED883D, Count: 1, Total 4 bytes
 6   Call Stack (TID 20672):
 7     ucrtbased.dll!malloc()
 8     f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes
 9     e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x7 bytes
10     e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (16): testVLD.exe!main()
11     f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
12     f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
13     f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
14     f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
15     KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
16     ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
17     ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
18   Data:
19     78 56 34 55                                                  xV4U.... ........
20 
21 
22 Visual Leak Detector detected 1 memory leak (40 bytes).
23 Largest number used: 40 bytes.
24 Total allocations: 40 bytes.
25 Visual Leak Detector is now exiting.

4. 使用 64 bit 编译器时的输出

  使用 MSVC 2015 64bit 编译器,程序运行时,在标准输出窗会输出以下结果:

ptr = 25a42da0, *ptr = 55345678

  程序运行结束后,检测到了内存泄漏,VLD 会输出以下报告(本例中出现一处内存泄漏),第 1~3 行显示 VLD 运行状态,第 4~21 行显示泄漏内存的详细信息,第 22~24 行总结此次泄漏情况,第 25 行显示 VLD 退出状态。

 1 Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
 2 Visual Leak Detector Version 2.5.1 installed.
 3 WARNING: Visual Leak Detector detected memory leaks!
 4 ---------- Block 1 at 0x0000000025A42DA0: 4 bytes ----------
 5   Leak Hash: 0x92ED96C9, Count: 1, Total 4 bytes
 6   Call Stack (TID 16444):
 7     ucrtbased.dll!malloc()
 8     f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0xA bytes
 9     e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0xA bytes
10     e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (16): testVLD.exe!main()
11     f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (75): testVLD.exe!invoke_main()
12     f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
13     f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
14     f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
15     KERNEL32.DLL!BaseThreadInitThunk() + 0x14 bytes
16     ntdll.dll!RtlUserThreadStart() + 0x21 bytes
17   Data:
18     78 56 34 55                                                  xV4U.... ........
19 
20 
21 Visual Leak Detector detected 1 memory leak (56 bytes).
22 Largest number used: 56 bytes.
23 Total allocations: 56 bytes.
24 Visual Leak Detector is now exiting.

5. 输出报告对比结果

使用不同位数的编译器时,输出报告的差异主要体现在以下几点:

  • 地址的表示位数不同,32 bit 编译器使用 8 位十六进制数表示,64 bit 编译器使用 16 位十六进制数表示。体现在输出的第 4 行,分别为 0x0070A3D0 和 0x0000000025A42DA0。
  • 程序启动时所调用的 Windows 操作系统函数不完全相同,32 bit 编译器调用了两次 RtlGetAppContainerNamedObjectPath() 函数和一次 BaseThreadInitThunk() 函数,64 bit 编译器只调用了一次 RtlUserThreadStart() 函数和一次 BaseThreadInitThunk() 函数,且它们调用 BaseThreadInitThunk() 函数时泄漏指令的内存偏移量不同,32 bit 编译器是 0x19 bytes,而 64 bit 编译器是 0x14 bytes。
  • 内存管理头的宽度不同,32 bit 编译器时是 36 bytes,64 bit 编译器时是 52 bytes。体现在输出的倒数第二行,分别为 Total allocations: 40 bytes 和 Total allocations: 56 bytes,将代码请求的内存大小 4 bytes 加上各自管理头的内存大小,可以得到与输出一致的结果: 4 + 36 = 40 b y t e s 4 + 36 = 40bytes4+36=40bytes 及 4 + 52 = 56 b y t e s 4 + 52 = 56bytes4+52=56bytes。

标签:exe,Qt,Leak,bytes,Visual,Detector,testVLD
From: https://www.cnblogs.com/ybqjymy/p/18052408

相关文章

  • Qt Visual Leak Detector 输出解析(一)
    1.使用方式在QT中使用VLD的方法可以查看另外几篇博客: QT使用VisualLeakDetector(方式一)QT使用 VisualLeakDetector(方式二)QT使用 VisualLeakDetector(方式三) 本次测试使用的环境为:QT5.9.2,MSVC201532bit,Debug模式,VLD版本为2.5.1,VLD配置文......
  • QT Visual Leak Detector 输出解析(二)
    1.使用方式在QT中使用VLD的方法可以查看另外几篇博客:QT使用VisualLeakDetector(方式一)QT使用VisualLeakDetector(方式二)QT使用VisualLeakDetector(方式三)本次测试使用的环境为:QT5.9.2,MSVC201532bit,Debug模式,VLD版本为2.5.1,VLD配置文件不做任何......
  • Qt 使用 Visual Leak Detector(方式二)
    1.使用前的准备参考本人另一篇博客安装VisualLeakDetector下载vld-2.5.1-setup.exe并按步骤安装VLD。这一种使用方式的特点是,在一台电脑上安装完成后,需在项目pro文件中指明库及头文件的路径,然后在mian.cpp文件中#include"vld.h"。当把项目拷贝到别的电脑上编译......
  • Qt 使用Visual Leak Detector(方式三)
    1.使用前的准备参考本人另一篇博客安装VisualLeakDetector下载vld-2.5.1-setup.exe并按步骤安装VLD。这一种使用方式的特点是,在一台电脑上安装完成后,将VLD安装目录下的lib库及include文件拷贝到项目目录中,在项目pro文件中指明库及头文件的路径,并将vld.ini......
  • Qt 使用 Visual Leak Detector(方式一)
    1.使用前的准备参考本人另一篇博客安装VisualLeakDetector下载vld-2.5.1-setup.exe并按步骤安装VLD。这一种使用方式的缺点是,当把项目拷贝到别的电脑上编译运行时,需要按以下流程重新配置VLD环境。但优点是在一台电脑上配置完成后,用的时候十分方便,包含头文件就可以......
  • Qt MSVC使用内存泄露检测工具 VLD(Visual Leak Detector)
    一、简介VLD=VisualLeakDetector,是一款用于VisualC++的免费的内存泄露检测工具,官网 kinddragon.github.io, GitHub 。先说优点:为每个泄漏的块提供完整的堆栈跟踪,包括源文件和行号信息(如果可用)。检测大多数(如果不是全部)类型的进程内内存泄漏,包括基于COM的泄漏......
  • Visual Leak Detector 安装 VLD
    一.工具下载VisualLeakDetector官网下载地址:https://kinddragon.github.io/vld/,点击DownloadInstaller绿色按钮可下载工具的安装程序vld-2.5.1-setup.exe。也可去Git仓库releases界面下载安装程序vld-2.5.1-setup.exe。二.工具安装2.1Next2.2Iacceptt......
  • Visual Studio 性能探查器排查内存泄漏
    1、自用方法介绍【1】VS使用debug模式执行程序(注意:Release模式无法看到堆栈细节!)【2】截取内存快照2、别人方法介绍【1】首先用vsattach到进程,再点调试–窗口–显示诊断工具。注意:如果用调试–性能探测器去附加进程,则内存使用率这一项是灰的,无法勾选,但是......
  • Visual Studio 打开Qt项目
    一、下载QTVSTOOL插件1.1下载地址官方下载地址:Indexof/development_releases/vsaddin找到对应的VS版本下载1.2 安装先关闭VS,然后安装,在打开VS,就看到顶部有QTVSTOOLS 了1.3 添加路径QtOptions->Add->apth,找到你Qt安装的目录对应的如下文件夹Q......
  • Visual Leak Detector 简介
    1.工具简介VisualLeakDetector简称VLD,是Windows平台下用于C/C++代码内存泄漏检测的开源工具,使用起来比较简单,配置好环境后包含头文件,就可以在运行时自动检测是否存在内存泄漏,并在指定位置(控制台或者文本文件)输出检测报告。该工具最初由DanMoulding开发,但是后面2.......