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

Posted on 2006-06-21
Medium Priority
Last Modified: 2012-06-27
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?

Question by:4eyesgirl
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 48

Expert Comment

ID: 16953167
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.
LVL 49

Expert Comment

ID: 16955301
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

Author Comment

ID: 16956748
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
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

LVL 49

Expert Comment

ID: 16958685
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.

Author Comment

ID: 16963962
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.


LVL 49

Accepted Solution

DanRollins earned 1500 total points
ID: 16964907
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
LVL 49

Expert Comment

ID: 16971532
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.

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question