仅当在 Visual C 中遇到另一个中断时才中断的任何方法; 2008年?
我多次发现自己处于这种情况,我需要闯入一个仅在达到特定断点后才被调用数百次的函数。
假设有一个函数可以更新对象的状态。这被称为多次 框架。我正在测试一个编辑对象的函数。一旦该函数被调用,我就可以进入 UpdateStatus
函数。显然,如果我在 UpdateStatus 中放置断点,它总是会中断,并且我将永远无法与程序交互。如果我可以在断点上设置一个条件,仅在其他函数中的断点命中时才中断,那就太好了。请注意,这只是一个示例。
我使用的是 Visual C++ 2008。
I have found myself in this situation many times where I need to break into a function that is called hundreds of times only after a particular break-point has been hit.
So let's say there is a function that updates the status of objects. This is called multiple times per
frame. I am testing a function that edits an object. As soon as that function is hit, I can then break into the UpdateStatus
function. Obviously, if I put a breakpoint in UpdateStatus
it will always break and I will never be able to interact with the program. What would be great if I could set a condition on the breakpoint to only break if the breakpoint in the other function hit. Note that this is just an example.
I am using Visual C++ 2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我记得我自己也遇到过这样的情况。我相信您可以将 Visual Studio 跟踪点与 Visual Studio 宏结合起来,非常轻松地完成此操作。本页介绍如何编写打开断点的宏:http://weseetips.com/tag/enable -breakpoint/ 由于您只想启用单个断点,因此您需要在宏中使用文件和行号的某种组合来仅启用您想要的断点 - 您可以在此处找到断点对象成员:<一href="http://msdn.microsoft.com/en-us/library/envdte.breakpoint.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/envdte.breakpoint .aspx(File 和 FileLine 看起来特别有用)
此页面描述如何使用“跟踪点”来运行宏:http://msdn.microsoft.com/en-us/library/232dxah7.aspx (此页面有一些设置跟踪点的漂亮屏幕截图:http://weblogs.asp .net/scottgu/archive/2010/08/18/debugging-tips-with-visual-studio-2010.aspx 中VS2010)
因此您可以创建一个启用断点的宏,并创建一个执行宏的跟踪点。 (您甚至可以添加第二个跟踪点来禁用断点,以便您可以轻松地重复该过程。)
I remember running into a situation like this myself. I believe you can combine Visual Studio tracepoints with Visual Studio macros to do this pretty easily. This page describes how to write a macro that turns on breakpoints: http://weseetips.com/tag/enable-breakpoint/ Since you want to enable only a single breakpoint, you'll want to use some combination of file and line number in your macro to enable only the breakpoint you want--you can find the breakpoint object members here: http://msdn.microsoft.com/en-us/library/envdte.breakpoint.aspx (File and FileLine look particularly useful)
This page describes how to use a 'tracepoint' to run a macro: http://msdn.microsoft.com/en-us/library/232dxah7.aspx (This page has some nice screenshots of setting up tracepoints: http://weblogs.asp.net/scottgu/archive/2010/08/18/debugging-tips-with-visual-studio-2010.aspx in VS2010)
So you could create a macro that will enable your breakpoint, and create a tracepoint that executes your macro. (You can even add a second tracepoint that disables the breakpoint afterward, so that you can easily repeat the process.)
您可以在
UpdateStatus 中放置条件断点本身。
或者,在
UpdateStatus
的调用站点放置一个条件断点,然后手动执行单步执行。您是否能够执行其中一项(或任何一项)取决于断点条件的复杂程度以及该条件的输入是否可以从特定堆栈帧“访问”。
You might be able to place a conditional breakpoint within the
UpdateStatus
itself.Alternatively, place a conditional breakpoint at the call-site of
UpdateStatus
then perform the step-in manually.Whether you'll be able to do one or the other (or any at all) depends on how complex the breakpoint condition is and whether input for that condition is "reachable" from the particular stack frame.
您可以让第一个断点在命中时设置一个标志,然后让第二个断点检查该标志作为条件。
您可以通过指定命中时打印的“消息”来设置标志,如下所示:
当然,
flag
需要存在于范围内。(如果可以声明一个仅在调试期间存在的变量,那就太好了,但我不知道如何做到这一点。)
You could have the first breakpoint set a flag when hit, then let the second breakpoint check that flag as a condition.
You can set the flag by specifying a "message" to be printed when hit, like so:
flag
needs to exist in the scope, of course.(It would be nice if it was possible to declare a variable that only exists during the debug, but I'm unaware of how to do this.)