【Visual Leak Detector】配置项 StackWalkMethod

说明

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

1. 配置文件使用说明

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

2. 设置调用堆栈的跟踪方法

参数名StackWalkMethod

有效赋值fastsafe

默认值fast

功能说明:设置调用堆栈的跟踪方法。fast 方法速度快但跟踪的调用堆栈可能不完整,会漏掉一些;safe 方法能更可靠地获得完整的调用堆栈,但速度会慢很多,有可能导致被检测的程序性能出现显著下降,这时为了减少检测时间,可以将配置项 MaxTraceFrames 设置得小一些。

2.1 测试代码

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

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

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

    QTime timedebuge;

    timedebuge.start();
    testFun(30);
    qDebug() << "Elapsed Time: " << timedebuge.elapsed() << "ms";

    return a.exec();
}

测试环境:QT 5.9.2MSVC 2015 32bitDebug 模式,VLD 版本为 2.5.1,VLD 配置文件只对该参数做修改,测试工程所在路径为:E:\Cworkspace\Qt 5.9\QtDemo\testVLD

2.2 StackWalkMethod = fast 时的输出

标准输出窗显示:

ptr = 006e90c0, *ptr = 00000001.
Elapsed Time:  1 ms

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 0x006E90C0: 4 bytes ----------
  Leak Hash: 0x03496A17, Count: 1, Total 4 bytes
  Call Stack (TID 11760):
    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 (13): testVLD.exe!testFun() + 0x7 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (25): 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 StackWalkMethod = safe 时的输出

标准输出窗显示:

ptr = 012aa388, *ptr = 00000001.
Elapsed Time:  18 ms

VLD 输出报告:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
    Using the "safe" (but slow) stack walking method.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x012AA388: 4 bytes ----------
  Leak Hash: 0x9281F97B, Count: 1, Total 4 bytes
  Call Stack (TID 30696):
    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 (13): testVLD.exe!testFun() + 0x7 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0xC bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (25): 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 输出结果对比

  • StackWalkMethod = fast 时,耗时 1 ms,此次检测输出了全部的调用堆栈。
  • StackWalkMethod = safe 时,耗时 18 ms,也检测输出了全部的调用堆栈。

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

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

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

相关文章

  • 2023团队天梯模拟赛 L2-3 智能护理中心统计 and L3-1 塔防游戏(23分)

    L2-3 智能护理中心统计 智能护理中心系统将辖下的护理点分属若干个大区,例如华东区、华北区等;每个大区又分若干个省来进行管理;省又分市,等等。我们将所有这些有管理或护理功能的单位称为“管理结点”。现在已知每位老人由唯一的一个管理结点负责,每个管理结点属于唯一的上级管理结点管辖。你需要实现一个功能,来统计任何一个管理结点所负责照看的老人的数量。 注意这是一个…

    C++ 2023年4月19日
    00
  • XMake学习笔记(1):Windows(MSYS2)下MinGW-w64环境搭建和XMake安装

    以前写的C++基本都是C with STL,大多是面向过程的算法题,或者比较小的项目,然后经常报各种编译错误(对编译原理不熟),经常把人搞到崩溃,搞不懂构建、链接之类的东西。 现在开始记录一下XMake的学习笔记,记录一些学习过程中踩的坑,在这篇文章,你将学习到Windows下利用MSYS2进行Mingw-w64环境搭建和XMake安装,并用Xmake构建一…

    C++ 2023年4月30日
    00
  • 【Visual Leak Detector】源码文件概览

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇对 VLD 源码包中的各文件用途做个概述。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 整体概览 2. 文件夹 .teamcity 3 文件夹 lib 3.1 文件夹 cppformat(生成 libformat) 3.2 文件夹 dbghelp 3.3 文件夹 gtest(…

    C++ 2023年4月24日
    00
  • 【Visual Leak Detector】核心源码剖析(VLD 2.5.1)

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇对 VLD 2.5.1 源码做内存泄漏检测的思路进行剖析。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 源码获取 2. 源码文件概览 3. 源码剖析 3.1 通过 inline hook 修补 LdrpCallInitRoutine 3.2 通过 IAT hook 替换内存操…

    C++ 2023年5月11日
    00
  • 【Visual Leak Detector】配置项 ReportFile

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍 VLD 配置文件中配置项 ReportFile 的使用方法。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 配置文件使用说明 2. 设置输出文件的路径 2.1 测试代码 2.2 ReportFile 为空时的输出 2.3 ReportFile 指定中文文件名时的输出 2.…

    C++ 2023年4月18日
    00
  • C++基础1: 命名空间

    0. 前言 C++是在C语言基础之上的一门语言, 所以学习C++的第一步是思考C++是如何优化C语言设计中的一些不足, 如作用域, IO , 函数, 指针, 宏等 这些内容同时也是为之后学习C++类和对象打基础, 下面说一下C++是如何优化C语言中的作用域 1. 命名空间 在说明命名空间的概念和如何优化C作用域之前, 首先来看一个例子 如图, 编译器报ran…

    C++ 2023年4月19日
    00
  • 高效c语言1快速入门

    本章将开发你的第一个C语言程序:传统的 “Hello, world!”程序。然后讨论一些编辑器和编译器的选项,并阐述移植性问题。 Hello, world! #include <stdio.h> #include <stdlib.h> int main(void) { puts(“Hello, world!”); return EXI…

    C++ 2023年5月10日
    00
  • 【Visual Leak Detector】配置项 ReportTo

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

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