Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-06-21
7
Medium Priority
?
692 Views
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?


THX
0
Comment
Question by:4eyesgirl
  • 4
  • 2
7 Comments
 
LVL 48

Expert Comment

by:AlexFM
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.
0
 
LVL 49

Expert Comment

by:DanRollins
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
or
     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
0
 

Author Comment

by:4eyesgirl
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
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 49

Expert Comment

by:DanRollins
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.
0
 

Author Comment

by:4eyesgirl
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.

Thanks.

0
 
LVL 49

Accepted Solution

by:
DanRollins earned 1500 total points
ID: 16964907
This reference
     Chapter 5: Advanced Debugger Usage with Visual Studio .NET (John Robbins)
     http://www.microsoft.com/mspress/books/sampchap/5822.asp
     >> 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]
      http://msdn.microsoft.com/library/en-us/vsdebug/html/vchowdifferences.asp

=-=-=-=-=-=-=-=-
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
0
 
LVL 49

Expert Comment

by:DanRollins
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.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

783 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