From c779b36d254d32d46f9fab6ec1ef16c5c58620ec Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 6 Jul 2018 21:01:42 +0000 Subject: [PDB] One more fix for hasing GSI records. The reference implementation uses a case-insensitive string comparison for strings of equal length. This will cause the string "tEo" to compare less than "VUo". However we were using a case sensitive comparison, which would generate the opposite outcome. Switch to a case insensitive comparison. Also, when one of the strings contains non-ascii characters, fallback to a straight memcmp. The only way to really test this is with a DIA test. Before this patch, the test will fail (but succeed if link.exe is used instead of lld-link). After the patch, it succeeds even with lld-link. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336464 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp | 2 +- tools/llvm-pdbutil/llvm-pdbutil.cpp | 88 +++++++++++++++++++++++ tools/llvm-pdbutil/llvm-pdbutil.h | 2 + 3 files changed, 91 insertions(+), 1 deletion(-) (limited to 'tools/llvm-pdbutil') diff --git a/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp b/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp index 739a95e6342..1270223b1c7 100644 --- a/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp +++ b/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp @@ -35,7 +35,7 @@ void ExternalSymbolDumper::dump(const PDBSymbolPublicSymbol &Symbol) { Printer.NewLine(); uint64_t Addr = Symbol.getVirtualAddress(); - Printer << "["; + Printer << "public ["; WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Addr, 10); Printer << "] "; WithColor(Printer, PDB_ColorItem::Identifier).get() << LinkageName; diff --git a/tools/llvm-pdbutil/llvm-pdbutil.cpp b/tools/llvm-pdbutil/llvm-pdbutil.cpp index 0088d30babd..5b0d21f83db 100644 --- a/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ b/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -20,10 +20,13 @@ #include "InputFile.h" #include "LinePrinter.h" #include "OutputStyle.h" +#include "PrettyClassDefinitionDumper.h" #include "PrettyCompilandDumper.h" +#include "PrettyEnumDumper.h" #include "PrettyExternalSymbolDumper.h" #include "PrettyFunctionDumper.h" #include "PrettyTypeDumper.h" +#include "PrettyTypedefDumper.h" #include "PrettyVariableDumper.h" #include "YAMLOutputStyle.h" @@ -65,7 +68,11 @@ #include "llvm/DebugInfo/PDB/PDBSymbolData.h" #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" +#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" #include "llvm/Support/BinaryByteStream.h" #include "llvm/Support/COM.h" #include "llvm/Support/CommandLine.h" @@ -161,6 +168,11 @@ cl::opt ShowInjectedSourceContent( cl::desc("When displaying an injected source, display the file content"), cl::cat(OtherOptions), cl::sub(PrettySubcommand)); +cl::list WithName( + "with-name", + cl::desc("Display any symbol or type with the specified exact name"), + cl::cat(TypeCategory), cl::ZeroOrMore, cl::sub(PrettySubcommand)); + cl::opt Compilands("compilands", cl::desc("Display compilands"), cl::cat(TypeCategory), cl::sub(PrettySubcommand)); cl::opt Symbols("module-syms", @@ -963,6 +975,82 @@ static void dumpPretty(StringRef Path) { outs() << "HasPrivateSymbols "; Printer.Unindent(); + if (!opts::pretty::WithName.empty()) { + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::SectionHeader).get() + << "---SYMBOLS & TYPES BY NAME---"; + + for (StringRef Name : opts::pretty::WithName) { + auto Symbols = GlobalScope->findChildren( + PDB_SymType::None, Name, PDB_NameSearchFlags::NS_CaseSensitive); + if (!Symbols || Symbols->getChildCount() == 0) { + Printer.formatLine("[not found] - {0}", Name); + continue; + } + Printer.formatLine("[{0} occurrences] - {1}", Symbols->getChildCount(), + Name); + + AutoIndent Indent(Printer); + Printer.NewLine(); + + while (auto Symbol = Symbols->getNext()) { + switch (Symbol->getSymTag()) { + case PDB_SymType::Typedef: { + TypedefDumper TD(Printer); + std::unique_ptr T = + llvm::unique_dyn_cast(std::move(Symbol)); + TD.start(*T); + break; + } + case PDB_SymType::Enum: { + EnumDumper ED(Printer); + std::unique_ptr E = + llvm::unique_dyn_cast(std::move(Symbol)); + ED.start(*E); + break; + } + case PDB_SymType::UDT: { + ClassDefinitionDumper CD(Printer); + std::unique_ptr C = + llvm::unique_dyn_cast(std::move(Symbol)); + CD.start(*C); + break; + } + case PDB_SymType::BaseClass: + case PDB_SymType::Friend: { + TypeDumper TD(Printer); + Symbol->dump(TD); + break; + } + case PDB_SymType::Function: { + FunctionDumper FD(Printer); + std::unique_ptr F = + llvm::unique_dyn_cast(std::move(Symbol)); + FD.start(*F, FunctionDumper::PointerType::None); + break; + } + case PDB_SymType::Data: { + VariableDumper VD(Printer); + std::unique_ptr D = + llvm::unique_dyn_cast(std::move(Symbol)); + VD.start(*D); + break; + } + case PDB_SymType::PublicSymbol: { + ExternalSymbolDumper ED(Printer); + std::unique_ptr PS = + llvm::unique_dyn_cast(std::move(Symbol)); + ED.dump(*PS); + break; + } + default: + llvm_unreachable("Unexpected symbol tag!"); + } + } + } + llvm::outs().flush(); + } + if (opts::pretty::Compilands) { Printer.NewLine(); WithColor(Printer, PDB_ColorItem::SectionHeader).get() diff --git a/tools/llvm-pdbutil/llvm-pdbutil.h b/tools/llvm-pdbutil/llvm-pdbutil.h index 8dad5e87ef2..7496adaeb62 100644 --- a/tools/llvm-pdbutil/llvm-pdbutil.h +++ b/tools/llvm-pdbutil/llvm-pdbutil.h @@ -75,6 +75,8 @@ bool compareFunctionSymbols( bool compareDataSymbols(const std::unique_ptr &F1, const std::unique_ptr &F2); +extern llvm::cl::list WithName; + extern llvm::cl::opt Compilands; extern llvm::cl::opt Symbols; extern llvm::cl::opt Globals; -- cgit v1.2.3