[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Conditional Breakpoints in MSVC++

Posted on 2006-04-05
10
Medium Priority
?
831 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?
0
Comment
Question by:jribble
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 20

Expert Comment

by:ikework
ID: 16381790
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
 
LVL 20

Expert Comment

by:ikework
ID: 16381800
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
 
LVL 86

Expert Comment

by:jkr
ID: 16381969
>>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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jribble
ID: 16382052
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
 
LVL 20

Expert Comment

by:ikework
ID: 16382056
oops ... correction

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

ike
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16382081
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
 
LVL 48

Accepted Solution

by:
AlexFM earned 1000 total points
ID: 16382125
0
 

Author Comment

by:jribble
ID: 16383381
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
 
LVL 2

Expert Comment

by:rahul_r_jadhav
ID: 16384026
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 16384356
In this case you need to do this in code as described in previous posts.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

872 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