Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing namespaced global variables in Visual Studio debugger?

When debugging a non-managed C++ project in Visual Studio 2008, I occasionally want to see the value of a global variable. We don't have a lot of these but those that are there all declared within a namespace called 'global'. e.g.

namespace global
{
  int foo;
  bool bar;

  ...
}

The problem is that when the code is stopped at a breakpoint, the default debugging tooltip (from pointing at the variable name) and quickwatch (shift-f9 on the variable name) don't take the namespace into consideration and hence won't work.

So for example I can point at 'foo' and nothing comes up. If I shift-f9 on foo, it will bring up the quickwatch, which then says 'CXX0017: Error: symbol "foo" not found'. I can get around that by manually editing the variable name in the quickwatch window to prefix it with "global::" (which is cumbersome considering you have to do it each time you want to quickwatch), but there is no fix for the tooltip that I can work out. Setting the 'default namespace' of the project properties doesn't help.

How can I tell the VS debugger to use the namespace that it already knows the variable is declared in (since it has the declaration right there), or, alternatively, tell it a default namespace to look for variables in if it doesn't find them?

My google-fu has failed to find an answer. This report lists the same problem, with MS saying it's "by design", but even so I am hoping there is some way to work around it (perhaps with clever use of autoexp.dat?)

like image 979
Chris Avatar asked Jun 06 '10 06:06

Chris


People also ask

How do I show global variables in Visual Studio debugger?

You can go to the quick-watch window - Ctrl + Alt + Q , enter the variable name there, and press Add Watch . The variable will be added to the Watch window. Save this answer.

How do I see variable values in Visual Studio debugging?

Hover over a variable to see its value. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.

How do I see variables in Visual Studio?

With my key bindings it is bound to Ctrl - F . The Quick Find dialog box is shown in the upper right corner of the editor window. You can change where to search from the drop down. Normally you search in Current Document but you can change it to Entire Solution.


2 Answers

Using the full name including the namespace in the source solved it for me.

e.g.: write

global::bar = (global::foo==0)

instead of

bar = (foo==0)
like image 65
R Risack Avatar answered Oct 16 '22 22:10

R Risack


If the symbol is located in a different DLL, you can use the following syntax in the Watch window:

{,,<dllname>}<fully qualified symbol name>

e. g.

{,,foobar64d.dll}global::foo

See https://docs.microsoft.com/en-us/visualstudio/debugger/context-operator-cpp?view=vs-2017 or search for "visual studio context operator".

like image 27
Andreas Haferburg Avatar answered Oct 16 '22 23:10

Andreas Haferburg