【Visual Leak Detector】配置项 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

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:【Visual Leak Detector】配置项 ReportTo - Python技术站

(0)
上一篇 2023年4月18日
下一篇 2023年4月18日

相关文章

  • C++/Qt网络通讯模块设计与实现(总结)

    至此,C++/Qt网络通讯模块设计与实现已分析完毕,代码已应用于实际产品中。 C++/Qt网络通讯模块设计与实现(一) 该章节从模块的功能需求以及非功能需求进行分析,即网络通讯模块负责网络数据包的发送、接收以及对外提供功能调用以及接口回调,其不进行产品业务的实现,达到平台化复用的目的,给出了类图,如下所示::   符合先设计再开发的思想,各类的功能也有详细描…

    C++ 2023年4月18日
    00
  • LeetCode 力扣 205. 同构字符串

    给定两个字符串 s 和 t ,判断它们是否是同构的。 如果 s 中的字符可以按某种映射关系替换得到 t ,那么这两个字符串是同构的。 每个出现的字符都应当映射到另一个字符,同时不改变字符的顺序。不同字符不能映射到同一个字符上,相同字符只能映射到同一个字符上,字符可以映射到自己本身。 示例 1: 输入:s = “egg”, t = “add”输出:true示例…

    C++ 2023年4月18日
    00
  • 前缀和

    前缀和 一、介绍 前缀,顾名思义就是一个东西前面的点缀…(bushi 其实打比方来说就是:假如有一字符串ABCD,那么他的前缀就是A、AB、ABC、ABCD这四个从新从第一个字母一次往后开始拼接的字符串。当然这是字符串。但前缀和一般应用于数组,对于给定的数组a=[1,2,3,4],他的前 i 项和sum[i]就表示数组中a[0]~a[i]的和,具体为:s…

    C++ 2023年5月3日
    00
  • 【Visual Leak Detector】源码调试 VLD 库

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍 VLD 源码的调试。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. VLD 库源码调试步骤 1.1 设置为启动项目 1.2 设置调试程序 1.3 设置输出目录 1.4 拷贝 vld 依赖文件 1.5 加断点调试 2. 注意事项 1. VLD 库源码调试步骤 以 vld2.…

    C++ 2023年5月7日
    00
  • <五>move移动语义和forward类型转发

    move : 移动语义,得到右值类型forward:类型转发,能够识别左值和右值类型 只有两种形式的引用,左值引用和右值引用,万能引用不是一种引用类型,它存在于模板的引用折叠情况,但是能够接受左值和右值区分左值和右值得一个简单方式就是能不能取地址一个右值一旦有名字那么就变成了左值 #include <iostream> using namespa…

    C++ 2023年5月4日
    00
  • C++ 并发编程实战 第二章 线程管控

    第二章 线程管控 std::thread 简介 构造和析构函数 /// 默认构造 /// 创建一个线程,什么也不做 thread() noexcept; /// 带参构造 /// 创建一个线程,以 A 为参数执行 F 函数 template <class Fn, class… Args> explicit thread(Fn&&amp…

    C++ 2023年4月17日
    00
  • 从0开始学习c++

    常量指针与指针常量 #include<iostream> using namespace std; int main() { int a = 10; int b = 20; // 常量指针与指针常量 // 1.常量指针 const修饰指针 指针的指向是可以修改的(指针变量中存的地址值可以修改) 指针指向的值不能改(不能通过解引用的形式修改地址中存…

    C++ 2023年4月24日
    00
  • 最短路径问题

    平面上有n个点(n<=100),每个点的坐标均在-10000~10000之间,其中的一些点之间有连线。 若有连线,则表示可从一个点到达另一个点,即两点间有通路,同路的距离为两点间的直线距离。现在的任务是找出从一点到另一点之间的最短路径。 小提示: 两点的距离:如果点\(A\)坐标为\((x_A,y_A)\),点\(B\)的坐标为\((x_B,y_B)\),\…

    C++ 2023年4月24日
    00
合作推广
合作推广
分享本页
返回顶部