How to find all global variables in C++ source code, DLL or any file created by the VC++ compiler? How to find all global variables in C++ source code, DLL or any file created by the VC++ compiler? multithreading multithreading

How to find all global variables in C++ source code, DLL or any file created by the VC++ compiler?


This could help:

  1. Open the project in visual studio.
  2. Open 'Class View' of the project
  3. Under the project title, you will find 'Global Functions and Variable'.

I have checked this with Visual Studio 2010 and above.

Edit: As suggested by Ajay in comments, you could also categorize items in groups. For grouping items:

  1. In class view, right click on project title
  2. Select `Group By Object/Member Type'
  3. Select the required tree like variables or structures or enums etc.


One option might be letting the linker generate a map file (/MAP in Visual Studio).

You will get a .map file for each binary with two sections:

A table of segments

 Start         Length     Name                   Class 0001:00000000 00010000H .textbss                DATA 0002:00000000 000034b4H .text                   CODE 0003:00000000 00000104H .CRT$XCA                DATA 0003:00000104 00000104H .CRT$XCAA               DATA 0003:00000208 00000104H .CRT$XCZ                DATA 0003:0000030c 00000104H .CRT$XIA                DATA ...

A list of symbols (functions and data)

  Address         Publics by Value              Rva+Base       Lib:Object 0000:00000000       ___safe_se_handler_count   00000000     <absolute> 0000:00000000       ___safe_se_handler_table   00000000     <absolute> 0000:00000000       ___ImageBase               00400000     <linker-defined> 0001:00000000       __enc$textbss$begin        00401000     <linker-defined> 0001:00010000       __enc$textbss$end          00411000     <linker-defined> 0002:000003a0       _wmain                     004113a0 f   console4.obj ...

You can tell apart the functions from variables by the "CODE" / "DATA" designaiton in the segment list.

Advantage: You will get all symbols, even those in libraries, that were not removed by the Linker.

Disadvanatge: You will get all symbols, even those in libraries, that were not removed by the Linker. I don't know of any tool that does the code/data separation automatically.


I know the http://code.google.com/p/data-race-test/wiki/ThreadSanitizer program (product of google) which can work in Windows and on compiled code. It is dynamic instrumentation program (like valgrind or bit like qemu/virtualbox), which add some checks to memory accesses. It will try to find some threading problems. You can just run your program under control of threadsanitizer. There will be slowdown from dynamic translation and from instrumentation code (up to 20x-50x times slower). But Some problems will be detected automatically.

It also allows you to annotate some custom synchronization functions in source code.

Wiki of program has links to other thread-race detectors: http://code.google.com/p/data-race-test/wiki/RaceDetectionLinks