Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i list and watch all global variables on watch windows of visual studio (for c++)?

When stopped at a breakpoint on main(), i can manually add name of a global variables to watch windows, but what i want is how to show a list of all global variables, because i'm using an external library, which contains many static things. Is it possible? Thanks in advance!

like image 798
tiboo Avatar asked Jun 10 '10 04:06

tiboo


People also ask

How do I view global variables in Visual Studio?

You can go to the quick-watch window - Ctrl + Alt + Q , enter the variable name there, and press Add Watch .

How do I see all variables in Visual Studio?

Go to menu Debug->Windows->Autos to make it appear. Locals While debugging you can enable 'Locals' which will show you all variables in the current stack frame. Go to menu Debug->Windows->Locals to make it appear.

How do I open the watch list in Visual Studio?

To Show the Panel Use the View > Debug > Watch List shortcut. The default shortcut depends on the keyboard mapping scheme chosen in the Customize Keyboard dialog. For the Visual Studio Emulation scheme, it is Alt+3 . For the Borland Classic and Default schemes, it is Ctrl+Alt+W .


1 Answers

Is the problem that you don't know the global variable names? Or is the problem that you want to look at many global variables and don't want to type them over and over again in the watch window? For the moment I assume the second. I also assume that your external library is a .LIB library and not a .DLL.

You could write a class that contains one member for every global variable you want to watch, make it a reference, and construct an instance of the class at startup, assigning the global variables to the reference members, like this:

class MyGlobalVariableClass
   {
   public:
      MyGlobalVariableClass()
      : m_var1(globalVariable1OfExternalLibrary)
      , m_var2(globalVariable2OfExternalLibrary)
      {}
   private:
      long   &m_var1;
      double &m_var2;
   };
MyGlobalVariableClass myGlobalVariableInstance;

Now you can just enter myGlobalVariableInstance in the watch window, expand it, and you will see all its members, and thus all the global variables.

This trick assumes that you know all the names of the global variables. If you don't, you could try to use DUMPBIN to investigate the contents of the LIB of the external library, and try to deduct the variable names from the output of DUMPBIN.

like image 80
Patrick Avatar answered Oct 23 '22 23:10

Patrick