Click here to Skip to main content
14,644,614 members
Rate this:
Please Sign up or sign in to vote.
Hi,

I am having a project build using vs2010 compiler for c++. The problem is, when i debug the application created, i need to see the values dynamically, so i put few break points and started debugging., but the values are not getting shown up when i move the mouse over the variables. When i print values using cout, the values gets printed without problem., and when i tried to add watch for the variable, the watch windows shows the variable as undefined or some thing..,

Kindly if some one knows what setting needs to be changed or if i am doing some thing wrong. Let me know your thoughts!

Thanks,
Sajith
Posted
Comments
nv3 9-Sep-13 9:38am
   
Had your program arrived at one of the break points when you tried this? If not, this is the problem. The debugger won't show any values while the program is running.
gssajith87 9-Sep-13 10:01am
   
Yes, it comes to every break point.
nv3 9-Sep-13 10:03am
   
And have you compiled in DEBUG configuration. If you compile in RELEASE configuration there will be only minimal debug support.
gssajith87 9-Sep-13 10:25am
   
Yes i have configured in DEBUG only. I am able to see all other values in other files., only one file is having this problem, i tried cleaning up the proj and rebuild, i tired deleting the obj file corresponding to the cpp file and compiled again. Still problem exist.
nv3 9-Sep-13 10:42am
   
I have sometimes seen that kind of behavior when stopping at a breakpoint in a member function and the this-pointer has an illegal address. Could you go to the "Locals" tab in the debugger and see that "this" points to. Also: As long as you have not stepped inside a function, but are just at the opening brace, the this-pointer is not yet set and you can't see any of the member variables.
Philippe Mori 9-Sep-13 15:42pm
   
Just to be sure, are you debugging native C++ code from a native application? I know that in C++/CLI, the debugger is not always able to figure out some symbols when the assembly is used by a managed C# application. I haven't yet figured out in what case it happens.

Are you able to see some symbols when displaying local variable windows.
Rate this:
Please Sign up or sign in to vote.

Solution 2

A few things that could go wrong:

1. Are you sure the file that you look at is the one you compiled? Maybe you are looking at a copy that you accidentally opened instead of the current source file. You can view the location of the file by hovering the mouse over the tab title.

2. Have you used conditional compilation by excluding parts of your code through #ifdef commands? Maybe the symbols you try to view are excluded from compilation.

3. are the variables you want to view within the active scope, i. e. within the same scope as the current position of the program counter? Maybe the breakpoint hits only after the variable has run out of scope. In that case the variable is considered an undefined symbol, just like you said the watch window states.

If it's none of these, maybe you should post the section of your code showing the position of the breakpoint and the variable you want to view.

P.S.: I just recalled a tricky variant to option 3: if you define a variable within the header of a for loop, then it will go out of scope at the end of the loop! So, if you try this:
for int i = 0; i < 10; ++i)
   if (myvec[i] < 0)
      break;

* // break somewhere here

You can not view the value of i after this loop, because it no longer exists! It's tricky because earlier versions of VS did retain such variables even affter the loop (against the rules of the C++ standard)
   
v3
Comments
Philippe Mori 10-Sep-13 8:49am
   
In fact, the standard rule has changed somewhere in the 199x and it just take some time for VC to catch up...
nv3 10-Sep-13 10:15am
   
All very good points, Stefan.
gssajith87 26-Sep-13 8:07am
   
Will post the code snippet in my next post! Had to move on with other activities, though i am facing similar errors now and then i will post it when i get it next time (shortly).

Reg the questions posted by @Stefan_Lang,
1) The Files are for sure compiled.
2) No Conditional Compilation.
3) I am quite sure , the variable is with in the scope., as the matter of evidence i am able to cout.

In the code example you have posted., if i do a cout of integer "i", i would have ended up with a compilation error.

Thanks for all your times., will get back shortly with the possible code snippet.
Stefan_Lang 9-Oct-13 4:19am
   
Regarding the first point, I was _not_ asking whether you compiled the file! Instead my point was that you may have more than one copy of this file on your hard disk. I know I often have a copy or two of the entire project I am working on for various reasons, and I sometimes run into the problem that I open a source file in the wrong folder - as a result, setting a breakpoint in that file has no effect at all! Unfortunately the Visual Studio IDE does not properly warn you about such mistakes.
gssajith87 13-Nov-13 14:17pm
   
@Stefan_Lang, that was not my case. In my case, the problem was, the file was not compiling properly when i compile the solution making changes multiple times. But unsure, why this happens !
Rate this:
Please Sign up or sign in to vote.

Solution 3

Thanks for your time guys., Recently i noticed the same issue occurred again for me! that is, when i keep my mouse over the variable, i was not able to see the value of the variable while debugging. i compiled my solution mutiple times to get rid of this problem, but it did not help. I went on to delete the exe file and again compiled my solution., it just did a linkage and created the exe but the problem still existed. So i wanted to make sure that , the file in which the variable exist was properly compiled., so i removed a ";" to check if it throws any compilation error when compiling the solution. But on compiling the solution, i noticed that the compilation was successful and it did not find the error that i put in . So now i decided to compile the file alone in which the variable exist , this time the compiler found the error that is it compiled the file, now again i compiled the solution., this time when i debug i was able to see the variable value while debugging...


Conclusion : In my case, the problem was, the file was not compiling properly when i compile the solution making changes multiple times.
   
Comments
Stefan_Lang 22-Nov-13 4:31am
   
This shouldn't happen: at the very least, if you directly change that file, it should compile when you build the solution! The only reason why this may not be so is if the file is not part of your solution! Have you forgotten to add it?

P.S.: another possible reason for the compiler to ignore a change is if the affected code is part of a template: if the compiler doesn't recognize that the template is needed elsewhere, then it may see no reason to compile anything. But then, template code must reside in headers: if you put template code into a *.cpp file, that may be the problem!
gssajith87 22-Nov-13 4:43am
   
I am sure the file is part of the solution and the cpp file does not include any template.
Rate this:
Please Sign up or sign in to vote.

Solution 4

Hello,

I've discovered the way to break into native code and have access to STL containers' content when debugging using CLI :

Tools\Options...\Debugging\General : uncheck 'Use Managed Compatibility Mode' (YES! UNCHECK IT!)

In the native code, instead to add breakpoints, just add this :

assert(false);

When breaking against the shores, just click either 'Retry' to debug or 'Ignore' to continue.

Happy debugging with Visual Studio 2015 :)

Kochise
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

Nothing is supposed to happen just on a mouse event. Instead use "Watch" windows (under debug menu, available while you are in debugging), or "QuickWatch" context menu item. Also, better make sure the debug information is available, which is the case when you use the default "Debug" configuration.

—SA
   
Comments
[no name] 9-Sep-13 20:48pm
   
I don't agree. When debugging a C++ program in VS2010 and a breakpoint is reached then moving the mouse to a variable (in scope) brings up a tooltip showing the state of the variable.
   
Okay, but if OP does not see it, it's better to use something more certain, which cannot be ruined by a slip of a hand... :-)
—SA
gssajith87 9-Sep-13 22:11pm
   
I tried out watch window, but it throws that's the variable is undefined
   
Are you sure you configure to have debug information?
—SA
[no name] 10-Sep-13 0:57am
   
I agree with SA. In addition the mere fact you can cout the value at some point does not mean it is in scope when the breakpoint is hit. A code snippet showing where your breakpoint is located may be helpful.
   
Right, this is a good point.
—SA
gssajith87 7-Nov-13 6:09am
   
Thanks for your time guys., Recently i noticed the same issue occured again for me! that is, when i keep my mouse over the variable, i was not able to see the value of the variable while debugging. i compiled my solution mutiple times to get rid of this problem, but it did not help. I went on to delete the exe file and again compiled my solution., it just did a linkage and created the exe but the problem still existed. So i wanted to make sure that , the file in which the variable exist was properly compiled., so i removed a ";" to check if it throws any compilation error when compiling the solution. But on compiling the solution, i noticed that the compilation was successful and it did not find the error that i put in . So now i decided to compile the file alone in which the variable exist , this time the compiler found the error that is it compiled the file, now again i compiled the solution., this time when i debug i was able to see the variable value while debugging...


Conclusion : In my case, the problem was, the file was not compiling properly when i compile the solution making changes multiple times.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100