【问题标题】:How to set conditional breakpoint based on string comparison in Visual Studio? [duplicate]如何在 Visual Studio 中根据字符串比较设置条件断点? [复制]
【发布时间】:2018-06-18 16:07:26
【问题描述】:

这是我多年来不时尝试的事情,但从未完全成功。我只想根据字符串相等性为 Visual C++ 2012 设置条件断点。我要测试的变量是

string test;

我试过了

test == "foo"
=> The breakpoint cannot be set. no operator "==" matches these operands

test == string("foo")
=> The breakpoint cannot be set. no operator "==" matches these operands

test.compare("foo") == 0
=> The breakpoint cannot be set. This expression has side effects and will not be evaluated.

strcmp(test.c_str(), "foo") == 0
=> The breakpoint cannot be set. This expression has side effects and will not be evaluated.

【问题讨论】:

    标签: c++ visual-studio-2012 breakpoints string-comparison conditional-breakpoint


    【解决方案1】:

    对于在 Visual Studio 中使用,已回答 here。特别是,OBWANDO 的答案中提供的字符串可用于设置断点条件。但是请注意,它有点笨拙。即使调试器已停止,当断点被命中时,您也会收到一条警告消息。它似乎不会造成任何伤害。

    【讨论】:

    • 是的,该帖子回答了我的问题,并且 OBWANDO 的解决方案也非常适合我。感谢您指出这一点。
    【解决方案2】:

    您可以使用以下便携且简单的方式:

    if (!test.compare("foo")) {
        int dummy = 0; // any statement, put breakpoint here
    }
    

    【讨论】:

    • 谢谢,但我正在寻找一种无需修改源代码即可设置断点条件的方法。
    • 你可以随时尝试 test[0] == ''
    猜你喜欢
    • 1970-01-01
    • 2010-11-02
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    • 2013-01-24
    • 2020-11-22
    • 1970-01-01
    • 2011-01-16
    相关资源
    最近更新 更多