开发者

How come my execution result is correct, but watch list result is wrong?

I wrote a c++ program, and when I'm using debug mode, I put a pointer type variable (say m_pdummy) into the watch list, but it shows "bad ptr";

If I expand this pointer(by clicking the "+" left to the name) and wants to see other variables under this pointer, all variables show "expression cannot be evaluated";

However, in my code, I wrote some output stuff, like:

CString str;

DWORD d1;

d1 = m_pdummy->m_wgear;

str.Format("%d");

MessageBox(str);

and then message box shows correct value;

But if I drag m_pdummy, d1, str into watch l开发者_开发百科ist, all of them says either "expression cannot be evaluated" or "symbol not found"; But this is impossible because message box could show values;

So what's the problem here?!

Best regards to whom read this, Thanks!

Marson


It may be that you're in the wrong stack frame. Those variables you list only exist according to their storage duration. If you're outside that duration (for example, before entering their function or after leaving it), the variable do not exist.

Example, say you have the function (line numbers on left):

20
21    int dbl (int x) {
22        int y = x + x + x;
23        y -= x;
24        return y;
25    }
26

The duration of x is only on lines 21 thru 25 (and y is 22 thru 25). Any attempt to watch the variables outside of that duration will probably result in the message you're seeing.

This is true for objects as well, you won't be able to see member variables unless an object has been instantiated.

The other possibility is that, even if an object has been instantiated, you may need the full name, something like myObject->m_pDummy.

They're guesses based on limited available information, but that's the first things I'd be looking into.


Maybe the code you are debugging with is not exactly the one running, or the VS Compiler optimize your code so some of the code doesn't exist anymore.
In the case of the former, the breakpoint and debug value cannot be watched, you should check out the code match the debugging one. I come up with this when I register COM server a 'wrong' dll.
In the case of the latter, you should close the optimization option. Hope this will help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜