From: Zachary Turner Date: Wed, 28 Jan 2015 01:22:33 +0000 (+0000) Subject: [llvm-pdbdump] Add basic symbol dumping. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e0f25c29621cb6ce6725097086f811d0d87adcdb;p=oota-llvm.git [llvm-pdbdump] Add basic symbol dumping. This adds two command line options: --symbols dumps a list of all symbols found in the PDB. --symbol-details dumps the same list, but with detailed information for every symbol such as type, attributes, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227286 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/llvm-pdbdump/llvm-pdbdump.cpp b/tools/llvm-pdbdump/llvm-pdbdump.cpp index 89f885b574e..2c5109888bc 100644 --- a/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -38,12 +38,12 @@ cl::list InputFilenames(cl::Positional, cl::OneOrMore); cl::opt Streams("streams", cl::desc("Display data stream information")); -cl::alias StreamsShort("s", cl::desc("Alias for --streams"), +cl::alias StreamsShort("x", cl::desc("Alias for --streams"), cl::aliasopt(Streams)); cl::opt StreamData("stream-data", cl::desc("Dumps stream record data as bytes")); -cl::alias StreamDataShort("S", cl::desc("Alias for --stream-data"), +cl::alias StreamDataShort("X", cl::desc("Alias for --stream-data"), cl::aliasopt(StreamData)); cl::opt Tables("tables", @@ -63,10 +63,19 @@ cl::opt Compilands("compilands", "files) and their source file composition")); cl::alias CompilandsShort("c", cl::desc("Alias for --compilands"), cl::aliasopt(Compilands)); + +cl::opt Symbols("symbols", cl::desc("Display symbols")); +cl::alias SymbolsShort("s", cl::desc("Alias for --symbols"), + cl::aliasopt(Symbols)); + +cl::opt SymbolDetails("symbol-details", + cl::desc("Display symbol details")); +cl::alias SymbolDetailsShort("S", cl::desc("Alias for --symbol-details"), + cl::aliasopt(SymbolDetails)); } template -static HRESULT GetDiaTable(IDiaSession *Session, TableType **Table) { +static HRESULT getDIATable(IDiaSession *Session, TableType **Table) { CComPtr EnumTables = nullptr; HRESULT Error = S_OK; if (FAILED(Error = Session->getEnumTables(&EnumTables))) @@ -194,7 +203,7 @@ static void dumpDebugTables(IDiaSession *Session) { static void dumpSourceFiles(IDiaSession *Session) { CComPtr EnumSourceFileList; - if (FAILED(GetDiaTable(Session, &EnumSourceFileList))) + if (FAILED(getDIATable(Session, &EnumSourceFileList))) return; LONG SourceFileCount = 0; @@ -216,7 +225,7 @@ static void dumpSourceFiles(IDiaSession *Session) { static void dumpCompilands(IDiaSession *Session) { CComPtr EnumSourceFileList; - if (FAILED(GetDiaTable(Session, &EnumSourceFileList))) + if (FAILED(getDIATable(Session, &EnumSourceFileList))) return; LONG SourceFileCount = 0; @@ -280,6 +289,32 @@ static void dumpCompilands(IDiaSession *Session) { outs().flush(); } +static void dumpSymbols(IDiaSession *Session) { + CComPtr EnumSymbols; + if (FAILED(getDIATable(Session, &EnumSymbols))) + return; + + LONG SymbolCount = 0; + EnumSymbols->get_Count(&SymbolCount); + + outs() << "Dumping symbols [" << SymbolCount << " symbols]\n"; + int UnnamedSymbolCount = 0; + for (auto Symbol : make_com_enumerator(EnumSymbols)) { + DIASymbol SymbolSymbol(Symbol); + DIAResult SymbolName = SymbolSymbol.getName(); + if (!SymbolName.hasValue() || SymbolName.value().empty()) { + ++UnnamedSymbolCount; + outs() << " (Unnamed symbol)\n"; + } else { + outs() << " " << SymbolSymbol.getName().value() << "\n"; + } + if (opts::SymbolDetails) + SymbolSymbol.fullDump(4); + } + outs() << "(Found " << UnnamedSymbolCount << " unnamed symbols)\n"; + outs().flush(); +} + static void dumpInput(StringRef Path) { SmallVector Path16String; llvm::convertUTF8ToUTF16String(Path, Path16String); @@ -312,6 +347,10 @@ static void dumpInput(StringRef Path) { if (opts::Compilands) { dumpCompilands(Session); } + + if (opts::Symbols || opts::SymbolDetails) { + dumpSymbols(Session); + } } int main(int argc_, const char *argv_[]) {