views:

86

answers:

2

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!

A: 

Only if the external library has debugging symbols. Maybe not even then.

Duracell
+1  A: 

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.

Patrick
this trick did well!
zeroboo