1

I am building a tool that process my VC++ source codes. For this, I need to obtain a list of symbols including local variable names and their types used by my codes. I know Visual C++ 2010 already provides a .bsc file that allows the object browser to locate symbols quickly. But this is an interactive tool. I need to obtain a list of the symbols in a file. Is there any tools allowing us to programmatically obtain the list of symbols used in our own VC++ source codes?

I tried the Debug Interface Access SDK provided by Microsoft. It allows us to read the .pdb file for the names of the local variables used. But I also want to obtain the exact type names used in my source codes. e.g.

MYTYPE dwordVar;

DIA SDK allows us to obtain the string "dwordVar" which is the name of a local variable. But it cannot tell its type name is "MYTYPE". It can only tell us what MYTYPE really represents (like unsigned long). But not the symbol "MYTYPE".

If Visual C++ isnt offering this feature, is there any third party tools supporting this feature?

Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
JavaMan
  • 4,954
  • 4
  • 41
  • 69

1 Answers1

1

Experimenting with this program:

typedef unsigned long MYTYPE;

int wmain(int argc, wchar_t *argv[])
{
    MYTYPE test = 99LU;
}

both DIA SDK and DbgHelp return 16 (SymTagBaseType) for the symtype of the type symbol for test. It would be nice if the type symbol were a Typedef symbol (17/SymTagTypedef), but it might be that the PDB itself does not record whether the source file used a typedef or type name in declaring the type of the local variable.

One possible work-around is to enumerate the SymTagTypedef children of the global scope symbol, building a std::multimap from type IDs of the types to the typedef names. Then, for each local variable, if the multimap contains entries for the Data symbol's type ID (obtained via IDiaSymbol::get_typeId), use the IDiaSession::findLines method to figure out the line(s) on which the Data symbol is declared and search those lines for any of the typedef name strings, possibly performing preprocessing before searching.

Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
  • Thanks. Is it possible to locate, using IDiaSession::findLines or the like, which lines in the source code are containing variable declaration? I've done some tests and it seems that a local variable declaration line will not even be counted as a source code line in the ::findLines call. – JavaMan Aug 29 '11 at 07:16
  • @JavaMan: Sorry for the delay. I tried both DIA SDK and DbgHelp and neither returns line information for a local variable declaration, or even a global variable declaration. The best that I could get were the line number(s) of the [lexical parent symbol](http://msdn.microsoft.com/en-us/library/202d5966.aspx), which for the case of a local variable declaration is the Function symbol. Pretty frustrating... – Daniel Trebbien Sep 05 '11 at 16:53