How to rewrite this conditional breakpoint by comparing a char* variable??

Hi expert,

I want to find out a better way to setup a conditional breakpoint when comparing a char* variable.

char* mystr is pointing to a block of memory

I want to break when the following occur
mystr has a substring of "KING"

currently, I have to write the condition as "sdrName[0]=='K' && sdrName[1]=='I' && sdrName[2]=='N' && sdrName[3]=='G'"

I know this will only breaks when mystr == KINGXXX
Tried to use strcmp or strsub function, but the breakpoints will never break. SO I assume you cannot use the string.h function?

Can anyone help me out?

Who is Participating?

Improve company productivity with a Business Account.Sign Up

DanRollinsConnect With a Mentor Commented:
This reference
     Chapter 5: Advanced Debugger Usage with Visual Studio .NET (John Robbins)
     >> For native code, you can't call functions from your conditional expressions,
    >>  but you do have access to the pseudo registers/values.

indicates that you cant, for instance, call strstr()... but you can access any variable by name and otherwise use statements that would appear in a "if" statment in the program.

This spells it out quite clearly (from the VS manual):
      Restrictions on C/C++ Expressions [in debugging]

As to the other thing:
Even if you have 1 MILLION DLLs and 1 BILLION lines of code, making a change as we have suggested changes only ONE SOURCE MODULE.   A Build operation will see that just that one module has changed and will know not to compile the other modules (which have not changed).  As I said, it should take a few seconds to do that and then link the one (or perhaps several) executable module(s) that are affected by the change.  If it is taking longer than that to make a one-line program change to your Debug Build version, then there is something severely wrong with your Build settings.

-- Dan
I don't think that there is another way. Debugger cannot call strcmp function to evaluate breakpoint, it's abilities are restricted.
But you can write temporary code with condition and break when it is true, like this:

if ( ... )       // any condition
    // put breakpoint here

Not so smart, but always work for me, and I never use conditional breakpoints.
I agree with AlexFM... the debugger is limited is what "condition" you can specify.
You can also use ASSERT; for instance:

     ASSERT( strstr(sdrName,"KING") != NULL )  // if its a null-terminated c-style string
     ASSERT( sdrName.Find("KING") != -1 )   // if it's a CString

The debugger will stop the program and you can start single stepping.  One advantage is that this will have an effect only in the Debug build.  The disadvantage is the same as for AlexFM's suggestion:  By adding lines of code to the program, you end up with the "observation dilemma" -- you change the thing you are trying to observe, risking the chance that the change itself masks or worsens the problem you are trying to debug...

-- Dan
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

4eyesgirlAuthor Commented:
But I would have to recompile the code which is something I am avoding to do.  It takes almost half hour to recompile and build the application I am working on.  So this would not be an option to me
wow... you need a faster computer or you need to check your settings to use, for instance, precomiled headers and incremental linking.  That kind of change affects just one module... no headers, etc.  It should recompile in a few seconds.  

Even doing a full clean and rebuild, VC++ routinely compiles my 100,000-line program including five separate DLLs in about 3 minutes... just long enough to run down the hall and grab a cuppacoffee.
4eyesgirlAuthor Commented:
Unfortunately, the product I am working on is a much larger system than 100,000 line of codes.

and it contains at least 50 dll in this product.

So, is there no way to break under condition?  Can someone give me a list of what kind of syntex of .net accept to set the conditional breakpoint?  If you can give me this list, I will reward you the point.


I only wish I had been able to find a a more specific source of information that would tell you exactly what restrictions there are in the expressions that you can use in the debugger.  Sorry.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.