Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set conditional breakpoint based on string comparison in Visual Studio? [duplicate]

Tags:

This is something I have tried from time to time over the years and never quite succeeded. I just want to set a conditional break point for Visual C++ 2012 based on string equality. The variable I want to test is

string test; 

I tried

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. 
like image 707
Kit Fisto Avatar asked Feb 21 '14 13:02

Kit Fisto


People also ask

How do I set a conditional breakpoint in Visual Studio?

Right-click the breakpoint symbol and select Conditions (or press Alt + F9, C). Or hover over the breakpoint symbol, select the Settings icon, and then select Conditions in the Breakpoint Settings window.

How do you set a breakpoint in Visual Studio code?

An inline breakpoint can be set using Shift+F9 or through the context menu during a debug session. Inline breakpoints are shown inline in the editor. Inline breakpoints can also have conditions. Editing multiple breakpoints on a line is possible through the context menu in the editor's left margin.

Is a conditional breakpoint that is not associated with any particular line but with a variable?

A more sophisticated approach uses dynamic (or "conditional") breakpoints. These are not bound to a particular line, but rather to a particular situation. When you run it, the PowerShell debugger will automatically stop the script whenever a new value is assigned to the variable $a.

What is a conditional breakpoint?

Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.


1 Answers

For use in Visual Studio, this has been answered here. In particular, the string provided in OBWANDO's answer can be used to set the break point condition. Note, however, that it is a bit klugy. You will receive a warning message when the breakpoint is hit even though the debugger has stopped. It doesn't appear to cause any harm.

like image 88
rrirower Avatar answered Sep 21 '22 09:09

rrirower