2

does anyone knows if its possible to set a multiple condition breakpoint on a specific line in Visual Studio 2013 (C++) ?

I was trying using the '&&' but it didn't worked. I also couldn't find an answer on MSDN.

the breakpoint that i wanna set is inside the WindowProc, the condition that i wanna set is - message = WM_MOUSEMOVE, WPARAM = MK_LBUTTON

thanks in advace, Igor.

Igor Bezverhi
  • 483
  • 1
  • 5
  • 11
  • *"It didn't work"* is not an error description. Please update your question, and explicitly state the expected result and the observed behavior. Also note that *wParam* for [WM_MOUSEMOVE](https://msdn.microsoft.com/en-us/library/windows/desktop/ms645616.aspx) stores a combination of flags. Comparing for equality with a particular value is usually not what you want. – IInspectable May 27 '15 at 08:23

2 Answers2

2

Using && is allowed and should work. What's more, a lot of common C++ expressions are allowed. This page lists what is and what isn't allowed.

Note that using this kind of breakpoint will considerably slow down your application. To the point where debugging is no longer feasible. This might be what has led you to believe && isn't allowed. To overcome this particular problem you might want to use a construct like this:

//untested code
#ifdef _DEBUG
if(condition a && condition b)
{
    //either output something (option A)
    std::cout << "condition a and b are true"
    //or create a nop statement (option B)
    __nop(); //and set a breakpoint
    //or create a 'nop statement' with compiler warning (option C)
    int breakpoint = 0;
}
#endif

This will yield much better performance.

Since this code is only compiled in when you are compiling in debug, you can leave this bit of code in (and option B would therefore be the best). If you however want to be reminded to remove the debugging clause, option C is probably the way you wanna go. As this will generate a variable breakpoint is declared but never used warning. As kindly suggested by borisbn.

If you are using this statement a lot it's probably most useful to wrap it into a precompiler macro.

laurisvr
  • 2,724
  • 6
  • 25
  • 44
  • what do you mean by nop statement ? a nop instruction? (0x90) – Igor Bezverhi May 27 '15 at 08:15
  • 1
    A statement that is executed but doesn't actually alter the state of the program. Since C++ is lacking an explicit nop statement. The `(void)0;` is a common way to implement this. See [also](http://stackoverflow.com/questions/300208/how-does-one-execute-a-no-op-in-c-c) – laurisvr May 27 '15 at 08:17
  • Another common way is `int breakpoint = 0;` This is useful because compiler will generate a warning like `variable breakpoint is declared but never used` that will indicate to you all places with problems. And yes, conditional breakpoints extremely slows down the execution – borisbn May 27 '15 at 08:48
  • @borisbn Actually that is better:) I will change my answer accordingly – laurisvr May 27 '15 at 08:51
  • *"almost all C++ expressions are allowed"*... I'm pretty sure this is not even remotely correct. Procedure calls are not allowed at all. – user541686 May 27 '15 at 08:59
  • I'm also pretty sure `(void)0` doesn't really generate a nop. If you want a nop in Visual C++, use `__nop()`; it'll work in release mode too. – user541686 May 27 '15 at 09:00
  • To be honest I don't understand your answer -- it's not "subjective", but rather much *everything* you said in your answer is outright wrong. Your nop doesn't nop, your "almost all" wasn't even close to almost all, and in fact you **explicitly CANNOT** have expressions with side effects; if you try those, you will get the error *"This expression has side effects and will not be evaluated."* I'm -1'ing this answer because I can't even imagine how you you came to your conclusions, but they're blatantly wrong. – user541686 May 27 '15 at 09:04
  • Not sure, but I'm not going to bother looking at it... the answer left me in a very bad mood. I really dislike how confidently you made blatantly wrong claims, so I'm leaving my -1 even if you fix everything, because it forced me to waste my own time double checking that you're actually wrong. – user541686 May 27 '15 at 09:13
  • to implement __nop() I need to add a particular header? – Igor Bezverhi May 27 '15 at 09:16
  • I already told you what your blatantly wrong claim was in **bold** in my previous comment, and like I said I'm too annoyed by it to change my vote even if you've tried to fix it. – user541686 May 27 '15 at 09:17
  • @IgorBezverhi: Hmm, apparently it's not auto-declared even though it's an intrinsic. Try `#include `? – user541686 May 27 '15 at 09:19
2

WM_MOUSEMOVE is a macrodefinition and gets replaced in the source code by the compiler during compilation. It is unknown to the debugger, so you can't use it in a breakpoint condition expression; use explicit number constant instead.

BTW, are you aware you used operator '=', which is not the same as '=='...?

CiaPan
  • 9,381
  • 2
  • 21
  • 35
  • yeah, I wrote a 'pseudo-code' in the question, I just thought it wont be clear if I would write "0x200" instead "WM_MOUSEMOVE" – Igor Bezverhi May 27 '15 at 09:09
  • I use compound conditions all the time in VS2010 and in 2008 previously, can't imagine it wouldn't work in 2013. – CiaPan May 27 '15 at 09:31