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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With