【Visual Leak Detector】配置项 ReportFile

说明

使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍 VLD 配置文件中配置项 ReportFile 的使用方法。同系列文章目录可见 《内存泄漏检测工具》目录

1. 配置文件使用说明

在程序中通过 #include "vld.h" 的方式检测内存泄漏时,VLD 首先会尝试在程序的生成目录下读取 vld.ini 文件,若未读取成功,则会尝试在 VLD 的安装目录下读取 vld.ini 文件,若仍未读取成功,则会使用内置的默认配置,内置的默认配置如果不动源码是无法更改的,因此通过修改相应目录下的 vld.ini 文件来定制 VLD 功能是最好的选择。当配置参数等号右边为空,或者给配置了不合法值时,在使用过程中会被程序重置到默认值。

2. 设置输出文件的路径

参数名ReportFile

有效赋值:合法且包含文件名的文件路径。

默认值.\memory_leak_report.txt

功能说明:当 ReportFile = fileReportFile = both 时,这个配置项才能起到作用,设置报告输出的文件路径及文件名,这个路径可以是绝对路径,也可以是相对路径,默认路径是生成目录,默认文件名是 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 配置文件除了对该参数做修改外,还将 ReportFile 设置为 file,测试工程所在路径为:E:\Cworkspace\Qt 5.9\QtDemo\testVLD

2.2 ReportFile 为空时的输出

标准输出窗显示:

ptr = 01027298, *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 0x01027298: 4 bytes ----------
  Leak Hash: 0x78A7E46A, Count: 1, Total 4 bytes
  Call Stack (TID 27760):
    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 ReportFile 指定中文文件名时的输出

设置如下:

ReportFile = E:\Cworkspace\Qt 5.9\QtDemo\中文文件.txt

标准输出窗显示:

ptr = 00dea598, *ptr = 00000001.

VLD 输出报告(控制台):

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

在路径 E:\Cworkspace\Qt 5.9\QtDemo 下生成了以下文件,中文文件名乱码了。

Oh Shit!-图片走丢了-打个广告-欢迎来博客园关注“木三百川”

VLD 输出报告(文件中),文件内容没有乱码:

Visual Leak Detector Version 2.5.1 installed.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x00DEA598: 4 bytes ----------
  Leak Hash: 0x78A7E46A, Count: 1, Total 4 bytes
  Call Stack (TID 21832):
    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 ReportFile 指定中文路径时的输出

设置如下:

ReportFile = E:\Cworkspace\Qt 5.9\QtDemo\中文路径\test.txt

标准输出窗显示:

ptr = 00cfb310, *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 0x00CFB310: 4 bytes ----------
  Leak Hash: 0x78A7E46A, Count: 1, Total 4 bytes
  Call Stack (TID 10592):
    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 里面是不合法的,输出被重置到了控制台中。

Oh Shit!-图片走丢了-打个广告-欢迎来博客园关注“木三百川”

2.5 输出结果对比

  • ReportFile 为空时,将在生成目录下输出到文件 memory_leak_report.txt 中。
  • ReportFile 指定中文文件名时,报告能正常输出到指定文件,但文件名会乱码。
  • ReportFile 指定中文路径时,报告会被重置输出到控制台,不能输出到指定文件。

原文链接:https://www.cnblogs.com/young520/p/17263196.html

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

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

相关文章

  • 【Visual Leak Detector】在 VS 高版本中使用 VLD

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。 本篇介绍如何在 VS 高版本中使用 vld2.5.1。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 使用前的准备 2. 在 VS 2015 及更早版本中使用 VLD 3. 在 VS 高版本中使用 VLD 3.1 参考资料:在 VS 2017 中使用 VLD 3.2 参考资料:在…

    C++ 2023年5月6日
    00
  • 07、【算例】openfoam带孔盘体应力分析

    官网:https://doc.cfd.direct/openfoam/user-guide-v9/platehole$FOAM_TUTORIALS/stressAnalysis/solidDisplacementFoam下的案例 1、网格划分 /*——————————–*- C++ -*—————…

    C++ 2023年4月18日
    00
  • 【Visual Leak Detector】配置项 SelfTest

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍 VLD 配置文件中配置项 SelfTest 的使用方法。 同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 配置文件使用说明 2. 设置是否开启泄漏自检 2.1 测试代码 2.2 SelfTest = off 时的输出 2.3 SelfTest = on 时的输出 2.4 …

    C++ 2023年4月18日
    00
  • 二分查找算法讲解及其C++代码实现

    二分查找算法是一种常用的查找算法,也被称为折半查找。它可以在有序的数组或列表中快速查找需要的元素。 算法描述: 首先确定数组的中间位置mid=(left+right)/2; 然后将要查找的值key与中间位置的值进行比较; 如果key等于中间位置的值,则查找成功,返回mid; 如果key小于中间位置的值,则在左半部分继续查找; 如果key大于中间位置的值,则在…

    C++ 2023年4月30日
    00
  • 【Qt6】QWindow类可以做什么

    原来的水文标题是“用 VS Code 搞 Qt6”,想想还是直接改为“Qt6”,反正这个用不用 VS Code 也能搞。虽然我知道大伙伴们都很讨厌 CMake,但毕竟这厮几乎成了 C++ 的玩家规范了。Qt 也算识大体,支持用 CMake 来构建程序。所以,只要你用的是能写 C++ 的工具,理论上都能搞 Qt。 创建应用程序界面的时候,我们一般会选用 QWi…

    C++ 2023年4月24日
    00
  • 第四部分:Spdlog日志库的核心组件分析-logger

    Spdlog是一个快速且可扩展的C++日志库,它支持多线程和异步日志记录。在本文中,我们将分析Spdlog日志库的核心代码,探究其实现原理和代码结构。 Spdlog的基本架构 上一篇文章介绍了spdlog的五个主要组件,其中最重要是Logger、Sink和Formatter其中,Logger负责日志的记录和管理,Sink负责将日志输出到不同的目标(比如控制台…

    C++ 2023年4月18日
    00
  • 【Visual Leak Detector】配置项 SkipHeapFreeLeaks

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍 VLD 配置文件中配置项 SkipHeapFreeLeaks 的使用方法。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 配置文件使用说明 2. 设置是否跳过堆内存泄漏检测 2.1 测试代码 2.2 SkipHeapFreeLeaks = no 时的输出 2.3 Skip…

    C++ 2023年4月18日
    00
  • 聊一聊 Valgrind 监视非托管内存泄露和崩溃

    一:背景 1. 讲故事 只要是程序总会出现各种莫名其妙的问题,比如:非托管内存泄露,程序崩溃,在 Windows 平台上一般用微软自家的官方工具 App Verifier 就可以洞察,那问题出在 Linux 上怎么办呢?由于 Linux 崇尚自由,需要在各种牛鬼蛇神写的非官方开源软件中寻找一个比较靠谱的,比如本篇所说的 Valgrind。 个人感觉 Valg…

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