We help IT Professionals succeed at work.

Conditional Breakpoints in MSVC++

jribble
jribble asked
on
Medium Priority
863 Views
Last Modified: 2010-05-18
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?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT

Commented:
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
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>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();

Author

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?).
CERTIFIED EXPERT

Commented:
oops ... correction

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

ike

Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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;
            
      }
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.

Commented:
In this case you need to do this in code as described in previous posts.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.