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技巧的更多相关文章

  1. gdb调试的艺术——Debug技巧

    调试的艺术——Debug技巧总结 (本文从写好的wiki里粘出来的,格式稍乱不影响阅读) 用Q+编号代表问题,A+编号代表答案.用这种方式组织.如无特别说明,这些技巧都是针对Visual Studio ...

  2. 玩转Windows服务系列——Windows服务小技巧

    伴随着研究Windows服务,逐渐掌握了一些小技巧,现在与大家分享一下. 将Windows服务转变为控制台程序 由于默认的Windows服务程序,编译后为Win32的窗口程序.我们在程序启动或运行过程 ...

  3. 玩转Windows服务系列——Windows服务小技巧

    原文:玩转Windows服务系列——Windows服务小技巧 伴随着研究Windows服务,逐渐掌握了一些小技巧,现在与大家分享一下. 将Windows服务转变为控制台程序 由于默认的Windows服 ...

  4. Windows服务小技巧

    Windows服务小技巧 阅读目录 开始 将Windows服务转变为控制台程序 注册服务为自动启动服务 注册服务时设置服务的依赖关系 添加自定义命令行参数 自定义命令行参数演示 系列链接 伴随着研究W ...

  5. 全面介绍Windows内存管理机制及C++内存分配实例(四):内存映射文件

    本文背景: 在编程中,很多Windows或C++的内存函数不知道有什么区别,更别谈有效使用:根本的原因是,没有清楚的理解操作系统的内存管理机制,本文企图通过简单的总结描述,结合实例来阐明这个机制. 本 ...

  6. 全面介绍Windows内存管理机制及C++内存分配实例

    转自:http://blog.csdn.net/yeming81/article/details/2046193 本文基本上是windows via c/c++上的内容,笔记做得不错.. 本文背景: ...

  7. 第13章 Windows内存体系结构

    13.1 Windows的虚拟地址空间安排 13.1.1虚拟地址空间的分区(即虚拟地址空间布局) 进程的地址空间划分 分区 x86 32位 Windows 3GB用户模式下的x86 32位Window ...

  8. Windows内存管理和linux内存管理

    windows内存管理 windows 内存管理方式主要分为:页式管理,段式管理,段页式管理. 页式管理的基本原理是将各进程的虚拟空间划分为若干个长度相等的页:页式管理把内存空间按照页的大小划分成片或 ...

  9. windows内存映射学习及帮助类实现

    本文通过创建文件内存映射类,学习windows内存映射相关知识:创建内存映射文件后,可以按照内存操作方式操作文件:支持32位程序处理超过4G大小的文件. 感谢http://blog.csdn.net/ ...

随机推荐

  1. docker 容器目录挂载 | 进出容器

    docker run --name wnginx -d -p 9001:80 -v /home/www:/usr/share/nginx/html nginx --name   别名 -d      ...

  2. OpenCV在未知相机内参数情况下的立体图像矫正方法及注意事项

    http://blog.sina.com.cn/s/blog_4298002e01013yb8.html 很多时候我们不知道摄像机的内参数矩阵,并且我们也不太关注内参数到底是多少,因为我们仅仅关心如何 ...

  3. 前端学习笔记之CSS浮动浅析

    很早以前就接触过CSS,但对于浮动始终非常迷惑,可能是自身理解能力差,也可能是没能遇到一篇通俗的教程. 前些天小菜终于搞懂了浮动的基本原理,迫不及待的分享给大家. 写在前面的话: 由于CSS内容比较多 ...

  4. 20145328 《网络对抗技术》逆向及Bof基础实践

    20145328 <网络对抗技术>逆向及Bof基础实践 实践内容 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回 ...

  5. [数据库] - org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection

    MySQL的驱动改名了,如果使用原来的com.mysql.jdbc.Driver 那么会提醒驱动不正常了,那么新的MySQL驱动名为:com.mysql.cj.jdbc.Driver 之后还报错,如题 ...

  6. Spring Cloud 开发的一些推荐规划

    1.提供一个统一的 父 pom 依赖    作用:统一版本与引入必要依赖 2.提供一个模板模型. 作用: 开发人员不必关系具体基础启动项 3.提供一个统一基础配置模型 作用: 开发人员不比太过关注与必 ...

  7. install ros-indigo-pcl-ros

    CMake Warning at /opt/ros/indigo/share/catkin/cmake/catkinConfig.cmake: (find_package): Could not fi ...

  8. SQL Server2012创建约束图解

            SQLServer中有五种约束:Primary Key约束.Foreign Key约束.Unique约束.Default约束和Check约束  1 . Primary Key 约束 在 ...

  9. EK算法复杂度分析

    引理: EK算法每次增广使所有顶点$v\in V-\{s,t\}$到$s$的最短距离$d[v]$增大. 采用反证法, 假设存在一个点$v\in V-\{s,t\}$, 使得$d'[v]< d[v ...

  10. 2-7-搭建DNS服务器实现域名解析

    学习服务的方法: 了解服务的作用:名称,功能,特点 安装服务 配置文件的位置,端口 服务开启和关闭的脚本 修改配置文件(实战举例) 排错(从上到下,从内到外) -------------------- ...