Solved

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

Posted on 2006-06-21
7
669 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

12 Experts available now in Live!

Get 1:1 Help Now