windows内存debug技巧
A) c++ memory/heap corrupt debug 技巧
1. catch first exception
2. data breakpoint
VC tell us some address is corrupt when free some pointer
Check which pointer it is
Set break point when malloc the pointer
Set data breakpoint at the corrupt address after the pointer is malloc
VC will break at the place which corrupts memory
3. application verifier heap check 功能
4.
B) c++ memory leakage
注:需要管理员权限(gflags需要),能上网(会自动下载symbols)
主要有几个需求
一是dump leakage,可以用1,3实现
二是显示leakage的call stack,可以用1,2实现
而2的用法是比较两次快照,1可以在程序退出时做
1. windbg
set _NT_SYMBOL_PATH=SRV*C:\MyLocalSymbols*http://msdl.microsoft.com/download/symbols
run gflags to enable the stack trace of the program
start the program
start windbg and attach to the program
bm wineagle!_CrtDumpMemoryLeaks
make the program leak memory
exit program
the program will break into windbg
step out by gu command
!heap -p -a <ADDR> where ADDR is the dumped leakage address
2. umdh
set _NT_SYMBOL_PATH=SRV*C:\MyLocalSymbols*http://msdl.microsoft.com/download/symbols
Gflags to enable OS log stack trace
restart the debugee program
-1- umdh.exe -pn:application_name.exe -f:FirstDump.txt
-2- ... exercise the application
-3- umdh.exe -pn:application_name.exe -f:SecondDump.txt
-4- umdh.exe FirstDump.txt SecondDump.txt -f:Result.txt
Compares allocations from the two dumps.
3. vc crt lib dump leakage
C) crt内存结构
Crt: _CrtSetDbgFlag, _CrtCheckMemory
D)关于gflags的heap类型
Gflags:
Full-page heap: placing a non-accessible page at the end of the allocation
Normal page heap: It checks fill patterns when a heap block is freed
Advantage: reduces memory consumption
Disadvantage
E) windbg extension
http://www.codeproject.com/Articles/6522/Debug-Tutorial-Part-4-Writing-WINDBG-Extensions
http://www.haogongju.net/art/1428822
??Debugging Tools for Windows, ?%programfiles%\ Debugging Tools for Windows (x86)\sdk????.
??:
Sdk\inc: ?????
??Dump???Callstack,??windbg???????
Sdk\lib:?????,dbghelp.lib,dbgeng.lib,engextcpp.lib,??????????
??Dump???Callstack,??windbg???????
Sdk\samples: samples(???????)
??Dump???Callstack,??windbg???????
Sdk\help:????
F)
Windows Performance Analyzer
http://msdn.microsoft.com/en-us/library/windows/desktop/ff190971%28v=vs.85%29.aspx
Write a debugger
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/90770a1c-7f83-4f81-864f-e64f3e17d02b
You can use mdbg as a model for a debugger implementation, it comes with source code and you will find a lot of references about it . Depending on the type of debugging you want to do there are two APIs you can use: - for native applications you should use the native debugging API :爃ttp://msdn.microsoft.com/en-us/library/ms679304(VS.85).aspx
- for managed applications the managed debugging API :爃ttp://msdn.microsoft.com/en-us/library/ms404520.aspx
Both come with samples, for example this (http://msdn.microsoft.com/en-us/library/ms679288(VS.85).aspx) is an example of building a basic debugger using the native API. I also recommend Mike Stall's debugging blog爃ttp://blogs.msdn.com/jmstall/default.aspx.
Creating a Basic Debugger
http://msdn.microsoft.com/en-us/library/ms679288%28VS.85%29.aspx
Sample code for PDB 2 XML tool
http://blogs.msdn.com/b/jmstall/archive/2005/08/25/sample-pdb2xml.aspx
Tool to get snapshot of managed callstacks
http://blogs.msdn.com/b/jmstall/archive/2005/11/28/snapshot.aspx
windows内存debug技巧的更多相关文章
- gdb调试的艺术——Debug技巧
调试的艺术——Debug技巧总结 (本文从写好的wiki里粘出来的,格式稍乱不影响阅读) 用Q+编号代表问题,A+编号代表答案.用这种方式组织.如无特别说明,这些技巧都是针对Visual Studio ...
- 玩转Windows服务系列——Windows服务小技巧
伴随着研究Windows服务,逐渐掌握了一些小技巧,现在与大家分享一下. 将Windows服务转变为控制台程序 由于默认的Windows服务程序,编译后为Win32的窗口程序.我们在程序启动或运行过程 ...
- 玩转Windows服务系列——Windows服务小技巧
原文:玩转Windows服务系列——Windows服务小技巧 伴随着研究Windows服务,逐渐掌握了一些小技巧,现在与大家分享一下. 将Windows服务转变为控制台程序 由于默认的Windows服 ...
- Windows服务小技巧
Windows服务小技巧 阅读目录 开始 将Windows服务转变为控制台程序 注册服务为自动启动服务 注册服务时设置服务的依赖关系 添加自定义命令行参数 自定义命令行参数演示 系列链接 伴随着研究W ...
- 全面介绍Windows内存管理机制及C++内存分配实例(四):内存映射文件
本文背景: 在编程中,很多Windows或C++的内存函数不知道有什么区别,更别谈有效使用:根本的原因是,没有清楚的理解操作系统的内存管理机制,本文企图通过简单的总结描述,结合实例来阐明这个机制. 本 ...
- 全面介绍Windows内存管理机制及C++内存分配实例
转自:http://blog.csdn.net/yeming81/article/details/2046193 本文基本上是windows via c/c++上的内容,笔记做得不错.. 本文背景: ...
- 第13章 Windows内存体系结构
13.1 Windows的虚拟地址空间安排 13.1.1虚拟地址空间的分区(即虚拟地址空间布局) 进程的地址空间划分 分区 x86 32位 Windows 3GB用户模式下的x86 32位Window ...
- Windows内存管理和linux内存管理
windows内存管理 windows 内存管理方式主要分为:页式管理,段式管理,段页式管理. 页式管理的基本原理是将各进程的虚拟空间划分为若干个长度相等的页:页式管理把内存空间按照页的大小划分成片或 ...
- windows内存映射学习及帮助类实现
本文通过创建文件内存映射类,学习windows内存映射相关知识:创建内存映射文件后,可以按照内存操作方式操作文件:支持32位程序处理超过4G大小的文件. 感谢http://blog.csdn.net/ ...
随机推荐
- Sublime Text 3图标更改
Sublime Text 3图标更改 步骤: 1.下载ico图标 2.然后更改图标 注意:重点讲解下,如何将png文件转换为ico图标: 网络上单独找sublime text 3的ico图标比较不好找 ...
- 20145314郑凯杰《网络对抗技术》实验1 逆向及Bof基础实践
20145314郑凯杰<网络对抗技术>实验1 逆向及Bof基础实践 1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数 ...
- godaddy之ssl申请
第一步 执行下面命令生成csr和key文件 openssl req -new -newkey rsa: -nodes -keyout trips.com.key -out trips.com.csr ...
- 使用javascript模拟常见数据结构(一)
数据结构和算法可算是每个程序员的必备技能,而随着前端工作的深入,对于数据结构的知识真的是越来越需要掌握了.好了,于是乎最近看了<javascript数据结构和算法>,算是对于后面的使用C语 ...
- SQL——DDL简单语句
基于MySQL的: status 命令查看MySQL当前信息 show databases; 命令列出所有数据库模式 use test; use命令切换到指定数据库模式 show tables; 列出 ...
- PHP 手机号中间4位加密
/** * 中间加密 字符串截取法 */ public static function encryptTel($tel) { $new_tel = substr($tel, 0, 3).'****'. ...
- 过了所有技术面,却倒在 HR 一个问题上
面试问离职原因,这是我们广大程序员朋友面试时逃不开的问题,如果答得不好,可能就影响了你整个的面试结果. 最近在群里,我也看到大家在讨论这个问题,其中有个朋友的回复很有感触,我分享给大家看一下. 如图, ...
- ng-grid
请查看官网:http://angular-ui.github.io/ui-grid/ 简单的使用: 总的来说我们 1.需要引入ng-grid-1.3.2.js 2.在html页面需要加入 class ...
- vue双向绑定原理及实现
vue双向绑定原理及实现 一.总结 一句话总结:vue中的双向绑定主要是通过发布者-订阅者模式来实现的 发布 订阅 1.单向绑定和双向绑定的区别是什么? model view 更新 单向绑定:mode ...
- baseCss/resetCss(转)
原文链接:https://github.com/hangyangws/baseCss#basecss baseCss 意义 统一各个浏览器差异.统一团队开发起始标准.弥补浏览器的“缺点”.提供频繁使用 ...