如何在Visual C ++中添加一个条件断点 [英] How to add a conditional breakpoint in Visual C++

查看:347
本文介绍了如何在Visual C ++中添加一个条件断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在VC ++ Express 2005中为我的代码添加一个断点条件,以便断点只有在局部变量符合指定条件时才会触发。例如

I want to add a breakpoint condition to my code in VC++ Express 2005, so that the breakpoint only triggers if a local variable meets a specified criteria. e.g.

bool my_test(UIDList test_list) {
    foo(test_list);
    bar(test_list); // I have a breakpoint here, but only want it to trigger if test_list.Length() > 0
    print(test_list);
}

右键单击我的断点并选择Condition ...发现一个对话框,看起来做我想要的,但是我尝试输入到文本字段的任何东西导致以下错误:

Having right-clicked on my breakpoint and selected "Condition..." I have found a dialog that appears to do what I want, however anything I try typing into the text field results in the following error:


评估断点
条件:CX0052:错误:成员
函数不存在

Unable to evaluate the breakpoint condition: CX0052: Error: member function not present

,但我找不到我的答案。我希望在VC ++有经验的人可能能指出我的方向正确...

I tried the help documentation, but I couldn't find my answer. I'm hoping someone experienced in VC++ might be able to point me in the right direction...

我以前尝试升级到更新版本的VC ++ Express,但项目没有干净地进口。由于项目的复杂性和我当前的时间尺度,我现在不能考虑升级为解决方案。

I have previously tried upgrading to a more recent version of VC++ Express, but the project did not import cleanly. Due to the complexity of the project and my current time scales I can't consider upgrading as a solution at this point.

推荐答案

使用DebugBreak();函数:

use the DebugBreak(); function:

bool my_test(UIDList test_list) {
    foo(test_list);
    if (bar(test_list) /* or whatever check :) */) // I have a breakpoint here, but only want it to trigger if test_list.Length() > 0
        DebugBreak();
    }
    print(test_list);
}

或者你总是可以使用assert(expression)

Or you can always use assert(expression)

bool my_test(UIDList test_list) {
    foo(test_list);
    bar(test_list);
    assert(test_list.Length() > 0); // will break here
    print(test_list);
}

这篇关于如何在Visual C ++中添加一个条件断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆