﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Error-随笔分类-调试技术</title><link>http://www.cppblog.com/Error/category/21013.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 01 Dec 2014 02:09:51 GMT</lastBuildDate><pubDate>Mon, 01 Dec 2014 02:09:51 GMT</pubDate><ttl>60</ttl><item><title>转）WinDBG 技巧：设断点命令详解(bp, bu, bm, ba 以及bl, bc, bd, be)</title><link>http://www.cppblog.com/Error/archive/2014/12/01/208994.html</link><dc:creator>Enic</dc:creator><author>Enic</author><pubDate>Mon, 01 Dec 2014 01:40:00 GMT</pubDate><guid>http://www.cppblog.com/Error/archive/2014/12/01/208994.html</guid><wfw:comment>http://www.cppblog.com/Error/comments/208994.html</wfw:comment><comments>http://www.cppblog.com/Error/archive/2014/12/01/208994.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Error/comments/commentRss/208994.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Error/services/trackbacks/208994.html</trackback:ping><description><![CDATA[<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">WinDBG 提供了多种设断点的命令：bp, bu, bm, ba</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">bp 命令是在某个地址下断点， 可以 bp 0x7783FEB 也可以 bp MyApp!SomeFunction 。 对于后者，WinDBG 会自动找到MyApp!SomeFunction 对应的地址并设置断点。 但是使用bp的问题在于：1）当代码修改之后，函数地址改变，该断点仍然保持在相同位置，不一定继续有效； 2）WinDBG 不会把bp断点保存工作空间中 。&nbsp; 所以，我比较喜欢用bu 命令。</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">bu 命令是针对某个符号下断点。 比如 bu MyApp!SomeFunction 。 在代码被修改之后， 该断点可以随着函数地址改变而自动更新到最新位置。&nbsp; 而且bu 断点会保存在WinDbg工作空间中， 下次启动 Windbg 的时候该断点会自动设置上去。</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">另外，在模块没有被加载的时候，bp 断点会失败（因为函数地址不存在），而bu 断点则可以成功。 新版的WinDBG中 bp失败后会自动被转成bu 。</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">bm 命令也是针对符号下断点。 但是它支持匹配表达式。 很多时候你下好几个断点。 比如，把MyClass 所有的成员函数都下断点： bu MyApp!MyClass::* ， 或者把所有以CreateWindow开头的函数都下断点： bu user32!CreateWindow* 。</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">以上三个命令是对代码下断点， 我们还可以对数据下断点。</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">ba 命令就是针对数据下断点的命令， 该断点在指定内存被访问时触发。 命令格式为</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">ba Access Size [地址]</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">Access 是访问的方式， 比如 e (执行)， r (读/写)， w (写)</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">Size 是监控访问的位置的大小，以字节为单位。 值为 1、2或4，还可以是 8（64位机）。</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">比如要对内存0x0483DFE进行写操作的时候下断点，可以用命令 ba w4 0x0483DFE</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">这里顺便提以下其他断点命令：</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">bl&nbsp; 列出所有断点</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">bc&nbsp; 清除断点</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">bd 禁用断点</div><div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">be 启动被bd 命令经用的断点</div><img src ="http://www.cppblog.com/Error/aggbug/208994.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Error/" target="_blank">Enic</a> 2014-12-01 09:40 <a href="http://www.cppblog.com/Error/archive/2014/12/01/208994.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>