Solved

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

Posted on 2006-06-21
7
644 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now