1.下载编译https://github.com/0cch/luadbg

2.编写脚本1.txt

.load luadbg_v15
*.sympath+ srv*c:\MyServerSymbols*https://msdl.microsoft.com/download/symbols
x *!*CrtDumpMemoryLeaks*
bm *!*CrtDumpMemoryLeaks* ".logopen temp.txt;gu;.logclose;!lua analyse_leak.lua"
bl
gc

3.编写脚本analyse_leak.lua

function Sleep(n)
if n > then os.execute("ping -n " .. tonumber(n + ) .. " localhost > NUL") end
end print('---1\n')
local open = io.open local function read_file(path)
local file = open(path, "rb") -- r read mode and b binary mode
if not file then return nil end
local content = file:read "*a" -- *a or *all reads the whole file
file:close()
return content
end local function exec_from_io(cmd)
local path='temp.txt'
exec(string.format('.logopen %s', path))
exec(cmd)
Sleep()
exec('.logclose') local file = open(path, "rb") -- r read mode and b binary mode
if not file then return nil end
local content = file:read "*a" -- *a or *all reads the whole file
file:close()
return content
end print('---2\n')
local leak_str = read_file('temp.txt')
--print('---leak_str:', leak_str, '\n') --g:\temp\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(74) : {286} normal block at 0x000CD920, 4 bytes long.
print('---3\n') pe=
i=
while (true)
do
print('-----------------',i,'\n')
i = i+ p2b, p2e, addr= string.find(leak_str, 'normal block at ([^,]*),', pe)
print('---p2b, p2e, addr',p2b, p2e, addr, '\n')
if p2b==nil then break end cmd=string.format('!heap -p -a %s', addr)
print('---cmd:',cmd,'\n')
stacks=exec_tostring(cmd)
print('---stacks\n', stacks) pe = p2e
end

4. attach程序,执行 $<1.txt

5.程序运行,执行令他泄露,然后退出

6.程序会break到windbg里面,显示出泄露信息,比如在我这边的输出

0:000> !lua analyse_leak.lua
---1

---2

---3

----------------- 1

---p2b, p2e, addr 148 174 0x088C4FF8

---cmd: !heap -p -a 0x088C4FF8

---stacks
address 088c4ff8 found in
_DPH_HEAP_ROOT @ 57c1000
in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize)
8852c64: 88c4fd8 28 - 88c4000 2000
5360a65c verifier!AVrfDebugPageHeapAllocate+0x0000023c
778768c5 ntdll!RtlDebugAllocateHeap+0x0000003c
777d553c ntdll!RtlpAllocateHeap+0x000017dc
777d2f8a ntdll!RtlpAllocateHeapInternal+0x0000017a
777d2dfe ntdll!RtlAllocateHeap+0x0000003e
06225028 ucrtbased!heap_alloc_dbg_internal+0x00000198
06224e36 ucrtbased!heap_alloc_dbg+0x00000036
0622760a ucrtbased!_malloc_dbg+0x0000001a
0fb91257 mfc140ud!operator new+0x00000037
0fb912e6 mfc140ud!operator new+0x00000016
00d785aa MFCApplication2+0x000185aa
0fe5f48d mfc140ud!AfxDlgProc+0x0000005d
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a3ac48 USER32!UserCallDlgProcCheckWow+0x000002a8
74a3a307 USER32!DefDlgProcWorker+0x000000c7
74a3a224 USER32!DefDlgProcW+0x00000054
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a55913 USER32!UserCallWinProcCheckWow+0x000002d3
74a4b387 USER32!CallWindowProcW+0x00000097
0ff7fb7a mfc140ud!CWnd::DefWindowProcW+0x0000004a
0ff7fc6f mfc140ud!CWnd::Default+0x0000005f
0fe609b7 mfc140ud!CDialog::HandleInitDialog+0x00000137
0ff86d1d mfc140ud!CWnd::OnWndMsg+0x00000e2d
0ff8abb6 mfc140ud!CWnd::WindowProc+0x00000056
0ff7c1b8 mfc140ud!AfxCallWndProc+0x00000128
0ff7d1b5 mfc140ud!AfxWndProc+0x000000b5
0fcca0ad mfc140ud!AfxWndProcBase+0x0000006d
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a55913 USER32!UserCallWinProcCheckWow+0x000002d3
74a413da USER32!SendMessageWorker+0x0000028a
74a3ebef USER32!InternalCreateDialog+0x000011df
74a4f075 USER32!CreateDialogIndirectParamAorW+0x00000035

----------------- 2

---p2b, p2e, addr 296 322 0x088C4FF9

---cmd: !heap -p -a 0x088C4FF9

---stacks
address 088c4ff9 found in
_DPH_HEAP_ROOT @ 57c1000
in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize)
8852c64: 88c4fd8 28 - 88c4000 2000
5360a65c verifier!AVrfDebugPageHeapAllocate+0x0000023c
778768c5 ntdll!RtlDebugAllocateHeap+0x0000003c
777d553c ntdll!RtlpAllocateHeap+0x000017dc
777d2f8a ntdll!RtlpAllocateHeapInternal+0x0000017a
777d2dfe ntdll!RtlAllocateHeap+0x0000003e
06225028 ucrtbased!heap_alloc_dbg_internal+0x00000198
06224e36 ucrtbased!heap_alloc_dbg+0x00000036
0622760a ucrtbased!_malloc_dbg+0x0000001a
0fb91257 mfc140ud!operator new+0x00000037
0fb912e6 mfc140ud!operator new+0x00000016
00d785aa MFCApplication2+0x000185aa
0fe5f48d mfc140ud!AfxDlgProc+0x0000005d
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a3ac48 USER32!UserCallDlgProcCheckWow+0x000002a8
74a3a307 USER32!DefDlgProcWorker+0x000000c7
74a3a224 USER32!DefDlgProcW+0x00000054
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a55913 USER32!UserCallWinProcCheckWow+0x000002d3
74a4b387 USER32!CallWindowProcW+0x00000097
0ff7fb7a mfc140ud!CWnd::DefWindowProcW+0x0000004a
0ff7fc6f mfc140ud!CWnd::Default+0x0000005f
0fe609b7 mfc140ud!CDialog::HandleInitDialog+0x00000137
0ff86d1d mfc140ud!CWnd::OnWndMsg+0x00000e2d
0ff8abb6 mfc140ud!CWnd::WindowProc+0x00000056
0ff7c1b8 mfc140ud!AfxCallWndProc+0x00000128
0ff7d1b5 mfc140ud!AfxWndProc+0x000000b5
0fcca0ad mfc140ud!AfxWndProcBase+0x0000006d
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a55913 USER32!UserCallWinProcCheckWow+0x000002d3
74a413da USER32!SendMessageWorker+0x0000028a
74a3ebef USER32!InternalCreateDialog+0x000011df
74a4f075 USER32!CreateDialogIndirectParamAorW+0x00000035

----------------- 3

---p2b, p2e, addr <out of memory> <out of memory> <out of memory>

用windbg 检查内存泄漏的更多相关文章

  1. 用mtrace检查内存泄漏

    http://blog.csdn.net/ixidof/article/details/6638066内存泄漏检查方法(for Linux) 如果你更想读原始文档, 请参考glibc info的&qu ...

  2. c++检查内存泄漏

    使用_CrtDumpMemoryLeaks()函数检查内存泄漏 #include <cstdio> #include <cstdlib> #include <crtdbg ...

  3. mtrace检查内存泄漏

    内存泄漏检查方法(for Linux) 如果你更想读原始文档, 请参考glibc info的"Allocation Debugging" 一章 (执行info libc);glib ...

  4. iOS开发 如何检查内存泄漏

    本文转载至 http://mobile.51cto.com/iphone-423391.htm 在开发的时候内存泄漏是不可避免的,但是也是我们需要尽量减少的,因为内存泄漏可能会很大程度的影响程序的稳定 ...

  5. ios--->instrument的leaks来检查内存泄漏

    instrument来检查内存泄漏 1.第一步打开 或者: 然后选择leaks 2.若此时编译出现如下问题,可能是非debug版本造成的,切换成debug版本即可 打开工程的Edit Scheme选项 ...

  6. UWP开发入门(十三)——用Diagnostic Tool检查内存泄漏

    因为.NET的垃圾回收机制相当完善,通常情况下我们是不需要关心内存泄漏的.问题人一但傻起来,连自己都会害怕,几个页面跳啊跳的,内存蹭蹭的往上涨,拉都拉不住.这种时候我们就需要冷静下来,泡一杯热巧克力. ...

  7. 基于WinDbg的内存泄漏分析

    在前面C++中基于Crt的内存泄漏检测一文中提到的方法已经可以解决我们的大部分内存泄露问题了,但是该方法是有前提的,那就是一定要有源代码,而且还只能是Debug版本调试模式下.实际上很多时候我们的程序 ...

  8. 记一次使用windbg排查内存泄漏的过程

    一.背景 近期有一个项目在运行当中出现一些问题,程序顺利启动,但是观察一阵子后发现内存使用总量在很缓慢地升高, 虽然偶尔还会往下降一些,但是总体还是不断上升:内存运行6个小时候从33M上升到80M: ...

  9. Android内存管理(14)*使用开源库LeakCanary检查内存泄漏

    1.简介 它是一个非常简单好用的内存泄漏检测工具库.可以轻松检测Activity,Fragment的内存泄漏.如果有内存泄漏,它会产生一个通知. 2.资料 官网: https://github.com ...

随机推荐

  1. Mybatis级联,使用JOIN和Associa,以及一些ID覆盖和自动变换。

    先说下坑,比如数据库的字段是 DW_ID  ,用generator讲mybatis自动转换的时候,会省略下表_变成dwId,所以我们之后自己手动设计的时候也尽量换成dwId: generate的myb ...

  2. <Dr.Elephant><How to tune ur application>

    Why Dr.Elephant? Most of Hadoop optimization tools out there, but they are focused on simplifying th ...

  3. Python 的基本运算及分析

    1题   输出1 2 3 4 5 6  8 9 10 . 方法一: count = 0while count < 10 : count += 1 if count == 7 : continue ...

  4. mysql储存引擎

    Mysql数据库常用存储引擎 数据库存储引擎:是数据库底层软件组织,数据库管理系统(DBMS)使用数据引擎进行创建.查询.更新和删除数据.不同的存储引擎提供不同的存储机制.索引技巧.锁定水平等功能,使 ...

  5. django面试大全

    1.Django请求的生命周期 a. wsgi, 创建socket服务端,用于接收用户请求并对请求进行初次封装. b. 中间件,对所有请求到来之前,响应之前定制一些操作. c. 路由匹配,在url和视 ...

  6. python day 16作业

    day18天作业及默写1,完成下列功能: 1.1创建一个人类Person,再类中创建3个静态变量(静态字段) animal = '高级动物' soup = '有灵魂' language = '语言' ...

  7. L2-001. 紧急救援(最短路的变形)*

    L2-001. 紧急救援 #include <cstdio> #include <algorithm> using namespace std; ; int const INF ...

  8. 关于Q-LEARNING的优化

    Q-LEARNING 最后得到的一个图寻路最佳路径:---直接转化为图关于多顶点深度遍历热度传递 V(level+1) = 0.8 * Max(Vi(level))   这个方法可以在O时间收敛 原方 ...

  9. Fizz Buzz 问题

    要求: 给你一个整数n. 从 1 到 n 按照下面的规则打印每个数: 如果这个数被3整除,打印fizz. 如果这个数被5整除,打印buzz. 如果这个数能同时被3和5整除,打印fizz buzz. 示 ...

  10. 【c++基础】字符数组和string相互转换

    字符数组转化成string类型char ch [] = "ABCDEFG";string str(ch);//也可string str = ch;或者char ch [] = &q ...