views:

164

answers:

2

Suppose I have this function:

std::string Func1 (std::string myString)
{
   //do some string processing 
   std::string newString == Func2(myString)
   return newString;  
}

how do I set a conditional break when newString has a specific value ? (without changing the source)

setting a condition newString == "my value"

didn't work the breakpoints got disabled with an error "overloaded operator not found"

A: 

Set a standard breakpoint, then right-click on it (the bullet on the margin) and select "Condition" in the context menu. A window will appear in which you can edit the condition that must be true so that the debugger will stop in that breakpoint.

Konamiman
tried it, but I got a message about overloaded operator not found
Eli
+2  A: 

Some searching has failed to turn up any way to do this. Suggested alternatives are to put the test in your code and add a standard breakpoint:

if (myStr == "xyz")
{
    // Set breakpoint here
}

Or to build up your test from individual character comparisons. Even looking at individual characters in the string is a bit dicey; in Visual Studio 2005 I had to dig down into the member variables like

myStr._Bx._Buf[0] == 'x' && myStr._Bx._Buf[1] == 'y' && myStr._Bx._Buf[2] == 'z'

Neither of these approaches is very satisfactory. We should have better access to a ubiquitous feature of the Standard Library.

Brad Payne
+1. I was just writing a similar answer. The only way I know of to do this is to peek inside the implementation. Note that for std::string, this can get pretty complicated because of the short string optimization.
Adrian McCarthy