Conditional Breakpoints in MSVC++

I want to set a conditional breakpoint in MSVC++ (i.e., when a CString value matches a specific value, then break at that time).  Is there a way to do this (without having to change my code to put in an if statment and hitting the break with that block?
jribbleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ikeworkCommented:
you can use assert, instead of real breakpoints:

#include <cassert>

..

CString strTest = "khkh";
// the code will stop here, if strTemp is "huhu"
assert( strTest == "huhu" );


good luck :)
ike
0
ikeworkCommented:
this is only vompiled into the debug-version, so dont worry to have unused code in the release-version .. its only in the debug-version


ike
0
jkrCommented:
>>I want to set a conditional breakpoint in MSVC++

'DebugBreak()' (http://msdn.microsoft.com/library/en-us/debug/base/debugbreak.asp) serves this purpose, e.g.

CString str = "test";

If ( str == "test") DebugBreak();
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

jribbleAuthor Commented:
Is there any way to do this from within the tool itself (i.e., specifying a breakpoint and then associating a conditional against it?).
0
ikeworkCommented:
oops ... correction

// the code will stop here, if strTemp is NOT "huhu"
assert( strTest == "huhu" );

ike
0
AlexFMCommented:
VC++ 6.0 has BreakPoints dialog, which allows to set breakpoint condition. Search this dialog in the main menu (in Edit or Debug menu). This is called conditional breakpoint.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jribbleAuthor Commented:
AlexFM,

I am able to set a conditional breakpoint, but I can't seem to set the breakpoint I want.  For example, I can set a conditional below to break when i == 5 for example, but if I try to break where msg = "ABCDEFG", then it disables the breakpoint before running the debugger.  Actually, what I would like to do is something like payment->Get("REF") == "xyz".

Any thoughts?

      // For each payment...
      for (int i = 0; i < getPaymentData()->GetCount(); i++) {
            
            CTableData *payment = (CTableData *)getPaymentData()->ElementAt(i);
            CTableData *terms = (CTableData *)getTerms()->Get(payment->Get("TERMS"));

            CString msg;
            msg.Format("%s %s-%s\n", payment->Get("PLANT_CODE"), payment->Get("MANIFOLD_PO_NUMBER"), payment->Get("MANIFOLD_RELEASE"));
            TRACE(msg);

            CMesTime *dueDate = calculateDueDate(terms, payment);

            calculateApprovalCutoff(payment, dueDate);
      
            delete dueDate;
            
      }
0
rahul_r_jadhavCommented:
string comparison can not be done in the debugger.
if you were having char array[] instead of CString then  array[0] == 'x' && array[1] == 'y' ...
could have been possible.
0
AlexFMCommented:
In this case you need to do this in code as described in previous posts.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

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.