diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-06-10 13:44:06 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-06-10 13:44:06 +0000 |
commit | 7ab83427af0f77b59941ceba41d509d7d097b065 (patch) | |
tree | cc41c05b1db454e3d802f34df75e636ee922ad87 /tools | |
parent | d288ef4c1788d3a951a7558c68312c2d320612b1 (diff) | |
download | src-7ab83427af0f77b59941ceba41d509d7d097b065.tar.gz src-7ab83427af0f77b59941ceba41d509d7d097b065.zip |
Vendor import of llvm trunk r305145:vendor/llvm/llvm-trunk-r305145
Notes
Notes:
svn path=/vendor/llvm/dist/; revision=319780
svn path=/vendor/llvm/llvm-trunk-r305145/; revision=319781; tag=vendor/llvm/llvm-trunk-r305145
Diffstat (limited to 'tools')
-rw-r--r-- | tools/LLVMBuild.txt | 2 | ||||
-rw-r--r-- | tools/bugpoint/OptimizerDriver.cpp | 5 | ||||
-rw-r--r-- | tools/dsymutil/DwarfLinker.cpp | 9 | ||||
-rw-r--r-- | tools/llc/llc.cpp | 97 | ||||
-rw-r--r-- | tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 3 | ||||
-rw-r--r-- | tools/llvm-cvtres/LLVMBuild.txt | 2 | ||||
-rw-r--r-- | tools/llvm-cvtres/llvm-cvtres.cpp | 73 | ||||
-rw-r--r-- | tools/llvm-cvtres/llvm-cvtres.h | 2 | ||||
-rw-r--r-- | tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 4 | ||||
-rw-r--r-- | tools/llvm-lto2/llvm-lto2.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 22 | ||||
-rw-r--r-- | tools/llvm-nm/llvm-nm.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-objdump/MachODump.cpp | 7 | ||||
-rw-r--r-- | tools/llvm-pdbdump/C13DebugFragmentVisitor.cpp | 87 | ||||
-rw-r--r-- | tools/llvm-pdbdump/C13DebugFragmentVisitor.h | 60 | ||||
-rw-r--r-- | tools/llvm-pdbutil/Analyze.cpp (renamed from tools/llvm-pdbdump/Analyze.cpp) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/Analyze.h (renamed from tools/llvm-pdbdump/Analyze.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/CMakeLists.txt (renamed from tools/llvm-pdbdump/CMakeLists.txt) | 5 | ||||
-rw-r--r-- | tools/llvm-pdbutil/CompactTypeDumpVisitor.cpp (renamed from tools/llvm-pdbdump/CompactTypeDumpVisitor.cpp) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/CompactTypeDumpVisitor.h (renamed from tools/llvm-pdbdump/CompactTypeDumpVisitor.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/Diff.cpp (renamed from tools/llvm-pdbdump/Diff.cpp) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/Diff.h (renamed from tools/llvm-pdbdump/Diff.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/LLVMBuild.txt (renamed from tools/llvm-pdbdump/LLVMBuild.txt) | 4 | ||||
-rw-r--r-- | tools/llvm-pdbutil/LLVMOutputStyle.cpp (renamed from tools/llvm-pdbdump/LLVMOutputStyle.cpp) | 308 | ||||
-rw-r--r-- | tools/llvm-pdbutil/LLVMOutputStyle.h (renamed from tools/llvm-pdbdump/LLVMOutputStyle.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/LinePrinter.cpp (renamed from tools/llvm-pdbdump/LinePrinter.cpp) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/LinePrinter.h (renamed from tools/llvm-pdbdump/LinePrinter.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/OutputStyle.h (renamed from tools/llvm-pdbdump/OutputStyle.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PdbYaml.cpp (renamed from tools/llvm-pdbdump/PdbYaml.cpp) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PdbYaml.h (renamed from tools/llvm-pdbdump/PdbYaml.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyBuiltinDumper.cpp (renamed from tools/llvm-pdbdump/PrettyBuiltinDumper.cpp) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyBuiltinDumper.h (renamed from tools/llvm-pdbdump/PrettyBuiltinDumper.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp (renamed from tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyClassDefinitionDumper.h (renamed from tools/llvm-pdbdump/PrettyClassDefinitionDumper.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp (renamed from tools/llvm-pdbdump/PrettyClassLayoutGraphicalDumper.cpp) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.h (renamed from tools/llvm-pdbdump/PrettyClassLayoutGraphicalDumper.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyCompilandDumper.cpp (renamed from tools/llvm-pdbdump/PrettyCompilandDumper.cpp) | 4 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyCompilandDumper.h (renamed from tools/llvm-pdbdump/PrettyCompilandDumper.h) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyEnumDumper.cpp (renamed from tools/llvm-pdbdump/PrettyEnumDumper.cpp) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyEnumDumper.h (renamed from tools/llvm-pdbdump/PrettyEnumDumper.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp (renamed from tools/llvm-pdbdump/PrettyExternalSymbolDumper.cpp) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyExternalSymbolDumper.h (renamed from tools/llvm-pdbdump/PrettyExternalSymbolDumper.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyFunctionDumper.cpp (renamed from tools/llvm-pdbdump/PrettyFunctionDumper.cpp) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyFunctionDumper.h (renamed from tools/llvm-pdbdump/PrettyFunctionDumper.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyTypeDumper.cpp (renamed from tools/llvm-pdbdump/PrettyTypeDumper.cpp) | 134 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyTypeDumper.h (renamed from tools/llvm-pdbdump/PrettyTypeDumper.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyTypedefDumper.cpp (renamed from tools/llvm-pdbdump/PrettyTypedefDumper.cpp) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyTypedefDumper.h (renamed from tools/llvm-pdbdump/PrettyTypedefDumper.h) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyVariableDumper.cpp (renamed from tools/llvm-pdbdump/PrettyVariableDumper.cpp) | 2 | ||||
-rw-r--r-- | tools/llvm-pdbutil/PrettyVariableDumper.h (renamed from tools/llvm-pdbdump/PrettyVariableDumper.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/StreamUtil.cpp (renamed from tools/llvm-pdbdump/StreamUtil.cpp) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/StreamUtil.h (renamed from tools/llvm-pdbdump/StreamUtil.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/YAMLOutputStyle.cpp (renamed from tools/llvm-pdbdump/YAMLOutputStyle.cpp) | 75 | ||||
-rw-r--r-- | tools/llvm-pdbutil/YAMLOutputStyle.h (renamed from tools/llvm-pdbdump/YAMLOutputStyle.h) | 0 | ||||
-rw-r--r-- | tools/llvm-pdbutil/fuzzer/CMakeLists.txt (renamed from tools/llvm-pdbdump/fuzzer/CMakeLists.txt) | 6 | ||||
-rw-r--r-- | tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp (renamed from tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp) | 4 | ||||
-rw-r--r-- | tools/llvm-pdbutil/llvm-pdbutil.cpp (renamed from tools/llvm-pdbdump/llvm-pdbdump.cpp) | 140 | ||||
-rw-r--r-- | tools/llvm-pdbutil/llvm-pdbutil.h (renamed from tools/llvm-pdbdump/llvm-pdbdump.h) | 41 | ||||
-rw-r--r-- | tools/llvm-readobj/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/llvm-readobj/COFFDumper.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-readobj/COFFImportDumper.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-readobj/ELFDumper.cpp | 202 | ||||
-rw-r--r-- | tools/llvm-readobj/LLVMBuild.txt | 2 | ||||
-rw-r--r-- | tools/llvm-stress/llvm-stress.cpp | 3 | ||||
-rw-r--r-- | tools/llvm-xray/xray-extract.cc | 2 | ||||
-rw-r--r-- | tools/obj2yaml/dwarf2yaml.cpp | 1 | ||||
-rw-r--r-- | tools/obj2yaml/macho2yaml.cpp | 2 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2elf.cpp | 2 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2macho.cpp | 6 |
69 files changed, 733 insertions, 612 deletions
diff --git a/tools/LLVMBuild.txt b/tools/LLVMBuild.txt index e3041a6d40d4..bcf58842eac3 100644 --- a/tools/LLVMBuild.txt +++ b/tools/LLVMBuild.txt @@ -40,7 +40,7 @@ subdirectories = llvm-modextract llvm-nm llvm-objdump - llvm-pdbdump + llvm-pdbutil llvm-profdata llvm-rtdyld llvm-size diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index ae3a31adaea3..489e50b88101 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -202,10 +202,11 @@ bool BugDriver::runPasses(Module *Program, } else Args.push_back(tool.c_str()); - Args.push_back("-o"); - Args.push_back(OutputFilename.c_str()); for (unsigned i = 0, e = OptArgs.size(); i != e; ++i) Args.push_back(OptArgs[i].c_str()); + Args.push_back("-disable-symbolication"); + Args.push_back("-o"); + Args.push_back(OutputFilename.c_str()); std::vector<std::string> pass_args; for (unsigned i = 0, e = PluginLoader::getNumPlugins(); i != e; ++i) { pass_args.push_back(std::string("-load")); diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index f74d721e6149..88de2706544e 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -6,15 +6,15 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include "DebugMap.h" #include "BinaryHolder.h" #include "DebugMap.h" -#include "dsymutil.h" #include "MachOUtils.h" #include "NonRelocatableStringpool.h" +#include "dsymutil.h" #include "llvm/ADT/IntervalMap.h" -#include "llvm/ADT/StringMap.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/DIE.h" #include "llvm/Config/config.h" @@ -23,8 +23,8 @@ #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCContext.h" #include "llvm/MC/MCCodeEmitter.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCObjectFileInfo.h" @@ -33,7 +33,6 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetOptionsCommandFlags.h" #include "llvm/Object/MachO.h" -#include "llvm/Support/Dwarf.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Target/TargetMachine.h" diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index e10d112dcf90..e71c3c5bb705 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -62,6 +62,9 @@ static cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); static cl::opt<std::string> +InputLanguage("x", cl::desc("Input language ('ir' or 'mir')")); + +static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename")); static cl::opt<unsigned> @@ -335,6 +338,12 @@ int main(int argc, char **argv) { llvm::make_unique<yaml::Output>(YamlFile->os())); } + if (InputLanguage != "" && InputLanguage != "ir" && + InputLanguage != "mir") { + errs() << argv[0] << "Input language must be '', 'IR' or 'MIR'\n"; + return 1; + } + // Compile the module TimeCompilations times to give better compile time // metrics. for (unsigned I = TimeCompilations; I; --I) @@ -398,10 +407,11 @@ static int compileModule(char **argv, LLVMContext &Context) { // If user just wants to list available options, skip module loading if (!SkipModule) { - if (StringRef(InputFilename).endswith_lower(".mir")) { + if (InputLanguage == "mir" || + (InputLanguage == "" && StringRef(InputFilename).endswith(".mir"))) { MIR = createMIRParserFromFile(InputFilename, Err, Context); if (MIR) - M = MIR->parseLLVMModule(); + M = MIR->parseIRModule(); } else M = parseIRFile(InputFilename, Err, Context); if (!M) { @@ -518,54 +528,67 @@ static int compileModule(char **argv, LLVMContext &Context) { OS = BOS.get(); } - if (!RunPassNames->empty()) { - if (!StartAfter.empty() || !StopAfter.empty() || !StartBefore.empty() || - !StopBefore.empty()) { - errs() << argv[0] << ": start-after and/or stop-after passes are " - "redundant when run-pass is specified.\n"; - return 1; - } - if (!MIR) { - errs() << argv[0] << ": run-pass needs a .mir input.\n"; - return 1; - } + const char *argv0 = argv[0]; + AnalysisID StartBeforeID = getPassID(argv0, "start-before", StartBefore); + AnalysisID StartAfterID = getPassID(argv0, "start-after", StartAfter); + AnalysisID StopAfterID = getPassID(argv0, "stop-after", StopAfter); + AnalysisID StopBeforeID = getPassID(argv0, "stop-before", StopBefore); + if (StartBeforeID && StartAfterID) { + errs() << argv0 << ": -start-before and -start-after specified!\n"; + return 1; + } + if (StopBeforeID && StopAfterID) { + errs() << argv0 << ": -stop-before and -stop-after specified!\n"; + return 1; + } + + if (MIR) { + // Construct a custom pass pipeline that starts after instruction + // selection. LLVMTargetMachine &LLVMTM = static_cast<LLVMTargetMachine&>(*Target); TargetPassConfig &TPC = *LLVMTM.createPassConfig(PM); + TPC.setDisableVerify(NoVerify); PM.add(&TPC); MachineModuleInfo *MMI = new MachineModuleInfo(&LLVMTM); - MMI->setMachineFunctionInitializer(MIR.get()); + if (MIR->parseMachineFunctions(*M, *MMI)) + return 1; PM.add(MMI); TPC.printAndVerify(""); - for (const std::string &RunPassName : *RunPassNames) { - if (addPass(PM, argv[0], RunPassName, TPC)) + if (!RunPassNames->empty()) { + if (!StartAfter.empty() || !StopAfter.empty() || !StartBefore.empty() || + !StopBefore.empty()) { + errs() << argv0 << ": start-after and/or stop-after passes are " + "redundant when run-pass is specified.\n"; return 1; + } + + for (const std::string &RunPassName : *RunPassNames) { + if (addPass(PM, argv0, RunPassName, TPC)) + return 1; + } + } else { + TPC.setStartStopPasses(StartBeforeID, StartAfterID, StopBeforeID, + StopAfterID); + TPC.addISelPasses(); + TPC.addMachinePasses(); } - PM.add(createPrintMIRPass(*OS)); - } else { - const char *argv0 = argv[0]; - AnalysisID StartBeforeID = getPassID(argv0, "start-before", StartBefore); - AnalysisID StartAfterID = getPassID(argv0, "start-after", StartAfter); - AnalysisID StopAfterID = getPassID(argv0, "stop-after", StopAfter); - AnalysisID StopBeforeID = getPassID(argv0, "stop-before", StopBefore); - - if (StartBeforeID && StartAfterID) { - errs() << argv[0] << ": -start-before and -start-after specified!\n"; - return 1; - } - if (StopBeforeID && StopAfterID) { - errs() << argv[0] << ": -stop-before and -stop-after specified!\n"; - return 1; - } + TPC.setInitialized(); - // Ask the target to add backend passes as necessary. - if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify, - StartBeforeID, StartAfterID, StopBeforeID, - StopAfterID, MIR.get())) { - errs() << argv[0] << ": target does not support generation of this" + if (!StopBefore.empty() || !StopAfter.empty() || !RunPassNames->empty()) { + PM.add(createPrintMIRPass(*OS)); + } else if (LLVMTM.addAsmPrinter(PM, *OS, FileType, MMI->getContext())) { + errs() << argv0 << ": target does not support generation of this" << " file type!\n"; return 1; } + PM.add(createFreeMachineFunctionPass()); + } else if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify, + StartBeforeID, StartAfterID, + StopBeforeID, StopAfterID)) { + errs() << argv0 << ": target does not support generation of this" + << " file type!\n"; + return 1; } // Before executing passes, print the final values of the LLVM options. diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 676134ca2368..c8fa56d724bf 100644 --- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -121,6 +121,8 @@ static const char *GetBlockName(unsigned BlockID, case bitc::USELIST_BLOCK_ID: return "USELIST_BLOCK_ID"; case bitc::GLOBALVAL_SUMMARY_BLOCK_ID: return "GLOBALVAL_SUMMARY_BLOCK"; + case bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID: + return "FULL_LTO_GLOBALVAL_SUMMARY_BLOCK"; case bitc::MODULE_STRTAB_BLOCK_ID: return "MODULE_STRTAB_BLOCK"; case bitc::STRTAB_BLOCK_ID: return "STRTAB_BLOCK"; } @@ -298,6 +300,7 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID, STRINGIFY_CODE(MST_CODE, HASH) } case bitc::GLOBALVAL_SUMMARY_BLOCK_ID: + case bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID: switch (CodeID) { default: return nullptr; diff --git a/tools/llvm-cvtres/LLVMBuild.txt b/tools/llvm-cvtres/LLVMBuild.txt index 73693bccb0ea..78c598b75e31 100644 --- a/tools/llvm-cvtres/LLVMBuild.txt +++ b/tools/llvm-cvtres/LLVMBuild.txt @@ -19,4 +19,4 @@ type = Tool name = llvm-cvtres parent = Tools -required_libraries = Option Support +required_libraries = Object Option Support diff --git a/tools/llvm-cvtres/llvm-cvtres.cpp b/tools/llvm-cvtres/llvm-cvtres.cpp index 95a6623b44eb..eaba02c16f39 100644 --- a/tools/llvm-cvtres/llvm-cvtres.cpp +++ b/tools/llvm-cvtres/llvm-cvtres.cpp @@ -112,20 +112,23 @@ int main(int argc_, const char *argv_[]) { return 0; } - machine Machine; + bool Verbose = InputArgs.hasArg(OPT_VERBOSE); + + Machine MachineType; if (InputArgs.hasArg(OPT_MACHINE)) { std::string MachineString = InputArgs.getLastArgValue(OPT_MACHINE).upper(); - Machine = StringSwitch<machine>(MachineString) - .Case("ARM", machine::ARM) - .Case("X64", machine::X64) - .Case("X86", machine::X86) - .Default(machine::UNKNOWN); - if (Machine == machine::UNKNOWN) + MachineType = StringSwitch<Machine>(MachineString) + .Case("ARM", Machine::ARM) + .Case("X64", Machine::X64) + .Case("X86", Machine::X86) + .Default(Machine::UNKNOWN); + if (MachineType == Machine::UNKNOWN) reportError("Unsupported machine architecture"); } else { - outs() << "Machine architecture not specified; assumed X64.\n"; - Machine = machine::X64; + if (Verbose) + outs() << "Machine architecture not specified; assumed X64.\n"; + MachineType = Machine::X64; } std::vector<std::string> InputFiles = InputArgs.getAllArgValues(OPT_INPUT); @@ -139,20 +142,22 @@ int main(int argc_, const char *argv_[]) { if (InputArgs.hasArg(OPT_OUT)) { OutputFile = InputArgs.getLastArgValue(OPT_OUT); } else { - OutputFile = StringRef(InputFiles[0]); + OutputFile = llvm::sys::path::filename(StringRef(InputFiles[0])); llvm::sys::path::replace_extension(OutputFile, ".obj"); } - outs() << "Machine: "; - switch (Machine) { - case machine::ARM: - outs() << "ARM\n"; - break; - case machine::X86: - outs() << "X86\n"; - break; - default: - outs() << "X64\n"; + if (Verbose) { + outs() << "Machine: "; + switch (MachineType) { + case Machine::ARM: + outs() << "ARM\n"; + break; + case Machine::X86: + outs() << "X86\n"; + break; + default: + outs() << "X64\n"; + } } WindowsResourceParser Parser; @@ -169,22 +174,28 @@ int main(int argc_, const char *argv_[]) { if (!RF) reportError(File + ": unrecognized file format.\n"); - int EntryNumber = 0; - Expected<ResourceEntryRef> EntryOrErr = RF->getHeadEntry(); - if (!EntryOrErr) - error(EntryOrErr.takeError()); - ResourceEntryRef Entry = EntryOrErr.get(); - bool End = false; - while (!End) { - error(Entry.moveNext(End)); - EntryNumber++; + if (Verbose) { + int EntryNumber = 0; + Expected<ResourceEntryRef> EntryOrErr = RF->getHeadEntry(); + if (!EntryOrErr) + error(EntryOrErr.takeError()); + ResourceEntryRef Entry = EntryOrErr.get(); + bool End = false; + while (!End) { + error(Entry.moveNext(End)); + EntryNumber++; + } + outs() << "Number of resources: " << EntryNumber << "\n"; } - outs() << "Number of resources: " << EntryNumber << "\n"; error(Parser.parse(RF)); } - Parser.printTree(); + if (Verbose) + Parser.printTree(); + + error( + llvm::object::writeWindowsResourceCOFF(OutputFile, MachineType, Parser)); return 0; } diff --git a/tools/llvm-cvtres/llvm-cvtres.h b/tools/llvm-cvtres/llvm-cvtres.h index 2e45b66461f0..f7b14faeebe3 100644 --- a/tools/llvm-cvtres/llvm-cvtres.h +++ b/tools/llvm-cvtres/llvm-cvtres.h @@ -14,6 +14,4 @@ void error(std::error_code EC); -enum class machine { UNKNOWN = 0, ARM, X64, X86 }; - #endif diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 2b5babe79824..1da157c4e4d5 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -67,6 +67,7 @@ static cl::opt<DIDumpType> DumpType( clEnumValN(DIDT_GnuPubnames, "gnu_pubnames", ".debug_gnu_pubnames"), clEnumValN(DIDT_GnuPubtypes, "gnu_pubtypes", ".debug_gnu_pubtypes"), clEnumValN(DIDT_Str, "str", ".debug_str"), + clEnumValN(DIDT_StrOffsets, "str_offsets", ".debug_str_offsets"), clEnumValN(DIDT_StrDwo, "str.dwo", ".debug_str.dwo"), clEnumValN(DIDT_StrOffsetsDwo, "str_offsets.dwo", ".debug_str_offsets.dwo"), @@ -83,6 +84,8 @@ static cl::opt<bool> Verify("verify", cl::desc("Verify the DWARF debug info")); static cl::opt<bool> Quiet("quiet", cl::desc("Use with -verify to not emit to STDOUT.")); +static cl::opt<bool> Brief("brief", cl::desc("Print fewer low-level details")); + static void error(StringRef Filename, std::error_code EC) { if (!EC) return; @@ -100,6 +103,7 @@ static void DumpObjectFile(ObjectFile &Obj, Twine Filename) { DIDumpOptions DumpOpts; DumpOpts.DumpType = DumpType; DumpOpts.SummarizeTypes = SummarizeTypes; + DumpOpts.Brief = Brief; DICtx->dump(outs(), DumpOpts); } diff --git a/tools/llvm-lto2/llvm-lto2.cpp b/tools/llvm-lto2/llvm-lto2.cpp index 89f85157e1df..bbfece517c80 100644 --- a/tools/llvm-lto2/llvm-lto2.cpp +++ b/tools/llvm-lto2/llvm-lto2.cpp @@ -162,6 +162,8 @@ static int run(int argc, char **argv) { Res.FinalDefinitionInLinkageUnit = true; else if (C == 'x') Res.VisibleToRegularObj = true; + else if (C == 'r') + Res.LinkerRedefined = true; else { llvm::errs() << "invalid character " << C << " in resolution: " << R << '\n'; diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 87efac2d33cf..8782588dfdd8 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -56,17 +56,15 @@ static cl::opt<bool> RelaxELFRel( "relax-relocations", cl::init(true), cl::desc("Emit R_X86_64_GOTPCRELX instead of R_X86_64_GOTPCREL")); -static cl::opt<DebugCompressionType> -CompressDebugSections("compress-debug-sections", cl::ValueOptional, - cl::init(DebugCompressionType::DCT_None), - cl::desc("Choose DWARF debug sections compression:"), - cl::values( - clEnumValN(DebugCompressionType::DCT_None, "none", - "No compression"), - clEnumValN(DebugCompressionType::DCT_Zlib, "zlib", - "Use zlib compression"), - clEnumValN(DebugCompressionType::DCT_ZlibGnu, "zlib-gnu", - "Use zlib-gnu compression (deprecated)"))); +static cl::opt<DebugCompressionType> CompressDebugSections( + "compress-debug-sections", cl::ValueOptional, + cl::init(DebugCompressionType::None), + cl::desc("Choose DWARF debug sections compression:"), + cl::values(clEnumValN(DebugCompressionType::None, "none", "No compression"), + clEnumValN(DebugCompressionType::Z, "zlib", + "Use zlib compression"), + clEnumValN(DebugCompressionType::GNU, "zlib-gnu", + "Use zlib-gnu compression (deprecated)"))); static cl::opt<bool> ShowInst("show-inst", cl::desc("Show internal instruction representation")); @@ -494,7 +492,7 @@ int main(int argc, char **argv) { MAI->setRelaxELFRelocations(RelaxELFRel); - if (CompressDebugSections != DebugCompressionType::DCT_None) { + if (CompressDebugSections != DebugCompressionType::None) { if (!zlib::isAvailable()) { errs() << ProgName << ": build tools with zlib to enable -compress-debug-sections"; diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index b022c300756d..722cb9e7e449 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -17,6 +17,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/StringSwitch.h" +#include "llvm/BinaryFormat/COFF.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalVariable.h" @@ -31,7 +32,6 @@ #include "llvm/Object/MachOUniversal.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Object/Wasm.h" -#include "llvm/Support/COFF.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index a260d6ff42c5..8927f57cc97f 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -11,12 +11,12 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Object/MachO.h" #include "llvm-objdump.h" #include "llvm-c/Disassembler.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Triple.h" +#include "llvm/BinaryFormat/MachO.h" #include "llvm/Config/config.h" #include "llvm/DebugInfo/DIContext.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" @@ -30,6 +30,7 @@ #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" +#include "llvm/Object/MachO.h" #include "llvm/Object/MachOUniversal.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" @@ -39,7 +40,6 @@ #include "llvm/Support/FormattedStream.h" #include "llvm/Support/GraphWriter.h" #include "llvm/Support/LEB128.h" -#include "llvm/Support/MachO.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" @@ -2594,7 +2594,8 @@ static const char *get_symbol_32(uint32_t sect_offset, SectionRef S, // These are structs in the Objective-C meta data and read to produce the // comments for disassembly. While these are part of the ABI they are no -// public defintions. So the are here not in include/llvm/Support/MachO.h . +// public defintions. So the are here not in include/llvm/BinaryFormat/MachO.h +// . // The cfstring object in a 64-bit Mach-O file. struct cfstring64_t { diff --git a/tools/llvm-pdbdump/C13DebugFragmentVisitor.cpp b/tools/llvm-pdbdump/C13DebugFragmentVisitor.cpp deleted file mode 100644 index 78971eb5879a..000000000000 --- a/tools/llvm-pdbdump/C13DebugFragmentVisitor.cpp +++ /dev/null @@ -1,87 +0,0 @@ -//===- C13DebugFragmentVisitor.cpp -------------------------------*- C++-*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "C13DebugFragmentVisitor.h" - -#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" -#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" -#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" -#include "llvm/DebugInfo/PDB/Native/PDBFile.h" -#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h" -#include "llvm/DebugInfo/PDB/Native/RawError.h" - -using namespace llvm; -using namespace llvm::codeview; -using namespace llvm::pdb; - -C13DebugFragmentVisitor::C13DebugFragmentVisitor(PDBFile &F) : F(F) {} - -C13DebugFragmentVisitor::~C13DebugFragmentVisitor() {} - -Error C13DebugFragmentVisitor::visitUnknown( - codeview::DebugUnknownSubsectionRef &Fragment) { - return Error::success(); -} - -Error C13DebugFragmentVisitor::visitFileChecksums( - codeview::DebugChecksumsSubsectionRef &Checksums) { - assert(!this->Checksums.hasValue()); - this->Checksums = Checksums; - return Error::success(); -} - -Error C13DebugFragmentVisitor::visitLines( - codeview::DebugLinesSubsectionRef &Lines) { - this->Lines.push_back(Lines); - return Error::success(); -} - -Error C13DebugFragmentVisitor::visitInlineeLines( - codeview::DebugInlineeLinesSubsectionRef &Lines) { - this->InlineeLines.push_back(Lines); - return Error::success(); -} - -Error C13DebugFragmentVisitor::finished() { - if (!Checksums.hasValue()) { - assert(Lines.empty()); - return Error::success(); - } - if (auto EC = handleFileChecksums()) - return EC; - - if (auto EC = handleLines()) - return EC; - - if (auto EC = handleInlineeLines()) - return EC; - - return Error::success(); -} - -Expected<StringRef> -C13DebugFragmentVisitor::getNameFromStringTable(uint32_t Offset) { - auto ST = F.getStringTable(); - if (!ST) - return ST.takeError(); - - return ST->getStringForID(Offset); -} - -Expected<StringRef> -C13DebugFragmentVisitor::getNameFromChecksumsBuffer(uint32_t Offset) { - assert(Checksums.hasValue()); - - auto Array = Checksums->getArray(); - auto ChecksumIter = Array.at(Offset); - if (ChecksumIter == Array.end()) - return make_error<RawError>(raw_error_code::invalid_format); - const auto &Entry = *ChecksumIter; - return getNameFromStringTable(Entry.FileNameOffset); -} diff --git a/tools/llvm-pdbdump/C13DebugFragmentVisitor.h b/tools/llvm-pdbdump/C13DebugFragmentVisitor.h deleted file mode 100644 index a12f282c4c5c..000000000000 --- a/tools/llvm-pdbdump/C13DebugFragmentVisitor.h +++ /dev/null @@ -1,60 +0,0 @@ -//===- C13DebugFragmentVisitor.h - Visitor for CodeView Info ----*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TOOLS_LLVMPDBDUMP_C13DEBUGFRAGMENTVISITOR_H -#define LLVM_TOOLS_LLVMPDBDUMP_C13DEBUGFRAGMENTVISITOR_H - -#include "llvm/ADT/Optional.h" -#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" -#include "llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h" -#include "llvm/Support/Error.h" - -#include <vector> - -namespace llvm { - -namespace pdb { - -class PDBFile; - -class C13DebugFragmentVisitor : public codeview::DebugSubsectionVisitor { -public: - C13DebugFragmentVisitor(PDBFile &F); - ~C13DebugFragmentVisitor(); - - Error visitUnknown(codeview::DebugUnknownSubsectionRef &Fragment) final; - - Error - visitFileChecksums(codeview::DebugChecksumsSubsectionRef &Checksums) final; - - Error visitLines(codeview::DebugLinesSubsectionRef &Lines) final; - - Error - visitInlineeLines(codeview::DebugInlineeLinesSubsectionRef &Lines) final; - - Error finished() final; - -protected: - virtual Error handleFileChecksums() { return Error::success(); } - virtual Error handleLines() { return Error::success(); } - virtual Error handleInlineeLines() { return Error::success(); } - - Expected<StringRef> getNameFromStringTable(uint32_t Offset); - Expected<StringRef> getNameFromChecksumsBuffer(uint32_t Offset); - - Optional<codeview::DebugChecksumsSubsectionRef> Checksums; - std::vector<codeview::DebugInlineeLinesSubsectionRef> InlineeLines; - std::vector<codeview::DebugLinesSubsectionRef> Lines; - - PDBFile &F; -}; -} -} - -#endif diff --git a/tools/llvm-pdbdump/Analyze.cpp b/tools/llvm-pdbutil/Analyze.cpp index b503cdcbf1ea..b503cdcbf1ea 100644 --- a/tools/llvm-pdbdump/Analyze.cpp +++ b/tools/llvm-pdbutil/Analyze.cpp diff --git a/tools/llvm-pdbdump/Analyze.h b/tools/llvm-pdbutil/Analyze.h index 7230ae45b0c8..7230ae45b0c8 100644 --- a/tools/llvm-pdbdump/Analyze.h +++ b/tools/llvm-pdbutil/Analyze.h diff --git a/tools/llvm-pdbdump/CMakeLists.txt b/tools/llvm-pdbutil/CMakeLists.txt index a1f54a3bff6a..9875dfb5a257 100644 --- a/tools/llvm-pdbdump/CMakeLists.txt +++ b/tools/llvm-pdbutil/CMakeLists.txt @@ -7,12 +7,11 @@ set(LLVM_LINK_COMPONENTS Support ) -add_llvm_tool(llvm-pdbdump +add_llvm_tool(llvm-pdbutil Analyze.cpp - C13DebugFragmentVisitor.cpp CompactTypeDumpVisitor.cpp Diff.cpp - llvm-pdbdump.cpp + llvm-pdbutil.cpp LinePrinter.cpp LLVMOutputStyle.cpp PdbYaml.cpp diff --git a/tools/llvm-pdbdump/CompactTypeDumpVisitor.cpp b/tools/llvm-pdbutil/CompactTypeDumpVisitor.cpp index 6dd54e0dbec1..6dd54e0dbec1 100644 --- a/tools/llvm-pdbdump/CompactTypeDumpVisitor.cpp +++ b/tools/llvm-pdbutil/CompactTypeDumpVisitor.cpp diff --git a/tools/llvm-pdbdump/CompactTypeDumpVisitor.h b/tools/llvm-pdbutil/CompactTypeDumpVisitor.h index 41ccea0c2e90..41ccea0c2e90 100644 --- a/tools/llvm-pdbdump/CompactTypeDumpVisitor.h +++ b/tools/llvm-pdbutil/CompactTypeDumpVisitor.h diff --git a/tools/llvm-pdbdump/Diff.cpp b/tools/llvm-pdbutil/Diff.cpp index 418c2361ac32..3fe6c511d35f 100644 --- a/tools/llvm-pdbdump/Diff.cpp +++ b/tools/llvm-pdbutil/Diff.cpp @@ -10,7 +10,7 @@ #include "Diff.h" #include "StreamUtil.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/PDB/Native/Formatters.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" diff --git a/tools/llvm-pdbdump/Diff.h b/tools/llvm-pdbutil/Diff.h index 6037576e21bb..6037576e21bb 100644 --- a/tools/llvm-pdbdump/Diff.h +++ b/tools/llvm-pdbutil/Diff.h diff --git a/tools/llvm-pdbdump/LLVMBuild.txt b/tools/llvm-pdbutil/LLVMBuild.txt index 4043e13ceaec..adbe4993e3fa 100644 --- a/tools/llvm-pdbdump/LLVMBuild.txt +++ b/tools/llvm-pdbutil/LLVMBuild.txt @@ -1,4 +1,4 @@ -;===- ./tools/llvm-pdbdump/LLVMBuild.txt -----------------------*- Conf -*--===; +;===- ./tools/llvm-pdbutil/LLVMBuild.txt -----------------------*- Conf -*--===; ; ; The LLVM Compiler Infrastructure ; @@ -17,7 +17,7 @@ [component_0] type = Tool -name = llvm-pdbdump +name = llvm-pdbutil parent = Tools required_libraries = DebugInfoMSF DebugInfoPDB diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/tools/llvm-pdbutil/LLVMOutputStyle.cpp index 31c342cd0f5a..824f88f8efd0 100644 --- a/tools/llvm-pdbdump/LLVMOutputStyle.cpp +++ b/tools/llvm-pdbutil/LLVMOutputStyle.cpp @@ -9,16 +9,21 @@ #include "LLVMOutputStyle.h" -#include "C13DebugFragmentVisitor.h" #include "CompactTypeDumpVisitor.h" #include "StreamUtil.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugCrossImpSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h" #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" #include "llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h" +#include "llvm/DebugInfo/CodeView/DebugSymbolRVASubsection.h" +#include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h" #include "llvm/DebugInfo/CodeView/DebugUnknownSubsection.h" #include "llvm/DebugInfo/CodeView/EnumTables.h" #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" @@ -81,62 +86,74 @@ struct PageStats { BitVector UseAfterFreePages; }; -class C13RawVisitor : public C13DebugFragmentVisitor { +class C13RawVisitor : public DebugSubsectionVisitor { public: - C13RawVisitor(ScopedPrinter &P, PDBFile &F, LazyRandomTypeCollection &IPI) - : C13DebugFragmentVisitor(F), P(P), IPI(IPI) {} + C13RawVisitor(ScopedPrinter &P, LazyRandomTypeCollection &TPI, + LazyRandomTypeCollection &IPI) + : P(P), TPI(TPI), IPI(IPI) {} - Error handleLines() override { - if (Lines.empty()) + Error visitUnknown(DebugUnknownSubsectionRef &Unknown) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::Unknown)) + return Error::success(); + DictScope DD(P, "Unknown"); + P.printHex("Kind", static_cast<uint32_t>(Unknown.kind())); + ArrayRef<uint8_t> Data; + BinaryStreamReader Reader(Unknown.getData()); + consumeError(Reader.readBytes(Data, Reader.bytesRemaining())); + P.printBinaryBlock("Data", Data); + return Error::success(); + } + + Error visitLines(DebugLinesSubsectionRef &Lines, + const DebugSubsectionState &State) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::Lines)) return Error::success(); DictScope DD(P, "Lines"); - for (const auto &Fragment : Lines) { - DictScope DDD(P, "Block"); - P.printNumber("RelocSegment", Fragment.header()->RelocSegment); - P.printNumber("RelocOffset", Fragment.header()->RelocOffset); - P.printNumber("CodeSize", Fragment.header()->CodeSize); - P.printBoolean("HasColumns", Fragment.hasColumnInfo()); + P.printNumber("RelocSegment", Lines.header()->RelocSegment); + P.printNumber("RelocOffset", Lines.header()->RelocOffset); + P.printNumber("CodeSize", Lines.header()->CodeSize); + P.printBoolean("HasColumns", Lines.hasColumnInfo()); - for (const auto &L : Fragment) { - DictScope DDDD(P, "Lines"); + for (const auto &L : Lines) { + DictScope DDDD(P, "FileEntry"); - if (auto EC = printFileName("FileName", L.NameIndex)) - return EC; + if (auto EC = printFileName("FileName", L.NameIndex, State)) + return EC; - for (const auto &N : L.LineNumbers) { - DictScope DDD(P, "Line"); - LineInfo LI(N.Flags); - P.printNumber("Offset", N.Offset); - if (LI.isAlwaysStepInto()) - P.printString("StepInto", StringRef("Always")); - else if (LI.isNeverStepInto()) - P.printString("StepInto", StringRef("Never")); - else - P.printNumber("LineNumberStart", LI.getStartLine()); - P.printNumber("EndDelta", LI.getLineDelta()); - P.printBoolean("IsStatement", LI.isStatement()); - } - for (const auto &C : L.Columns) { - DictScope DDD(P, "Column"); - P.printNumber("Start", C.StartColumn); - P.printNumber("End", C.EndColumn); - } + for (const auto &N : L.LineNumbers) { + DictScope DDD(P, "Line"); + LineInfo LI(N.Flags); + P.printNumber("Offset", N.Offset); + if (LI.isAlwaysStepInto()) + P.printString("StepInto", StringRef("Always")); + else if (LI.isNeverStepInto()) + P.printString("StepInto", StringRef("Never")); + else + P.printNumber("LineNumberStart", LI.getStartLine()); + P.printNumber("EndDelta", LI.getLineDelta()); + P.printBoolean("IsStatement", LI.isStatement()); + } + for (const auto &C : L.Columns) { + DictScope DDD(P, "Column"); + P.printNumber("Start", C.StartColumn); + P.printNumber("End", C.EndColumn); } } return Error::success(); } - Error handleFileChecksums() override { - if (!Checksums.hasValue()) + Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums, + const DebugSubsectionState &State) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::FileChecksums)) return Error::success(); DictScope DD(P, "FileChecksums"); - for (const auto &CS : *Checksums) { + for (const auto &CS : Checksums) { DictScope DDD(P, "Checksum"); - if (auto Result = getNameFromStringTable(CS.FileNameOffset)) + if (auto Result = getNameFromStringTable(CS.FileNameOffset, State)) P.printString("FileName", *Result); else return Result.takeError(); @@ -146,34 +163,140 @@ public: return Error::success(); } - Error handleInlineeLines() override { - if (InlineeLines.empty()) + Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees, + const DebugSubsectionState &State) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::InlineeLines)) return Error::success(); DictScope D(P, "InlineeLines"); - for (const auto &IL : InlineeLines) { - P.printBoolean("HasExtraFiles", IL.hasExtraFiles()); - ListScope LS(P, "Lines"); - for (const auto &L : IL) { - DictScope DDD(P, "Inlinee"); - if (auto EC = printFileName("FileName", L.Header->FileID)) - return EC; + P.printBoolean("HasExtraFiles", Inlinees.hasExtraFiles()); + ListScope LS(P, "Lines"); + for (const auto &L : Inlinees) { + DictScope DDD(P, "Inlinee"); + if (auto EC = printFileName("FileName", L.Header->FileID, State)) + return EC; - if (auto EC = dumpTypeRecord("Function", L.Header->Inlinee)) - return EC; - P.printNumber("SourceLine", L.Header->SourceLineNum); - if (IL.hasExtraFiles()) { - ListScope DDDD(P, "ExtraFiles"); - for (const auto &EF : L.ExtraFiles) { - if (auto EC = printFileName("File", EF)) - return EC; - } + if (auto EC = dumpTypeRecord("Function", L.Header->Inlinee)) + return EC; + P.printNumber("SourceLine", L.Header->SourceLineNum); + if (Inlinees.hasExtraFiles()) { + ListScope DDDD(P, "ExtraFiles"); + for (const auto &EF : L.ExtraFiles) { + if (auto EC = printFileName("File", EF, State)) + return EC; } } } return Error::success(); } + Error visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &CSE, + const DebugSubsectionState &State) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::CrossScopeExports)) + return Error::success(); + + ListScope D(P, "CrossModuleExports"); + for (const auto &M : CSE) { + DictScope D(P, "Export"); + P.printHex("Local", M.Local); + P.printHex("Global", M.Global); + } + return Error::success(); + } + + Error visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &CSI, + const DebugSubsectionState &State) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::CrossScopeImports)) + return Error::success(); + + ListScope L(P, "CrossModuleImports"); + for (const auto &M : CSI) { + DictScope D(P, "ModuleImport"); + auto Name = getNameFromStringTable(M.Header->ModuleNameOffset, State); + if (!Name) + return Name.takeError(); + P.printString("Module", *Name); + P.printHexList("Imports", M.Imports); + } + return Error::success(); + } + + Error visitFrameData(DebugFrameDataSubsectionRef &FD, + const DebugSubsectionState &State) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::FrameData)) + return Error::success(); + + ListScope L(P, "FrameData"); + for (const auto &Frame : FD) { + DictScope D(P, "Frame"); + auto Name = getNameFromStringTable(Frame.FrameFunc, State); + if (!Name) + return joinErrors(make_error<RawError>(raw_error_code::invalid_format, + "Invalid Frame.FrameFunc index"), + Name.takeError()); + P.printNumber("Rva", Frame.RvaStart); + P.printNumber("CodeSize", Frame.CodeSize); + P.printNumber("LocalSize", Frame.LocalSize); + P.printNumber("ParamsSize", Frame.ParamsSize); + P.printNumber("MaxStackSize", Frame.MaxStackSize); + P.printString("FrameFunc", *Name); + P.printNumber("PrologSize", Frame.PrologSize); + P.printNumber("SavedRegsSize", Frame.SavedRegsSize); + P.printNumber("Flags", Frame.Flags); + } + return Error::success(); + } + + Error visitSymbols(DebugSymbolsSubsectionRef &Symbols, + const DebugSubsectionState &State) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::Symbols)) + return Error::success(); + ListScope L(P, "Symbols"); + + // This section should not actually appear in a PDB file, it really only + // appears in object files. But we support it here for testing. So we + // specify the Object File container type. + codeview::CVSymbolDumper SD(P, TPI, CodeViewContainer::ObjectFile, nullptr, + false); + for (auto S : Symbols) { + DictScope LL(P, ""); + if (auto EC = SD.dump(S)) { + return make_error<RawError>( + raw_error_code::corrupt_file, + "DEBUG_S_SYMBOLS subsection contained corrupt symbol record"); + } + } + return Error::success(); + } + + Error visitStringTable(DebugStringTableSubsectionRef &Strings, + const DebugSubsectionState &State) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::StringTable)) + return Error::success(); + + ListScope D(P, "String Table"); + BinaryStreamReader Reader(Strings.getBuffer()); + StringRef S; + consumeError(Reader.readCString(S)); + while (Reader.bytesRemaining() > 0) { + consumeError(Reader.readCString(S)); + if (S.empty() && Reader.bytesRemaining() < 4) + break; + P.printString(S); + } + return Error::success(); + } + + Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &RVAs, + const DebugSubsectionState &State) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::CoffSymbolRVAs)) + return Error::success(); + + ListScope D(P, "COFF Symbol RVAs"); + P.printHexList("RVAs", RVAs); + return Error::success(); + } + private: Error dumpTypeRecord(StringRef Label, TypeIndex Index) { CompactTypeDumpVisitor CTDV(IPI, Index, &P); @@ -189,15 +312,33 @@ private: } return Error::success(); } - Error printFileName(StringRef Label, uint32_t Offset) { - if (auto Result = getNameFromChecksumsBuffer(Offset)) { + Error printFileName(StringRef Label, uint32_t Offset, + const DebugSubsectionState &State) { + if (auto Result = getNameFromChecksumsBuffer(Offset, State)) { P.printString(Label, *Result); return Error::success(); } else return Result.takeError(); } + Expected<StringRef> + getNameFromStringTable(uint32_t Offset, const DebugSubsectionState &State) { + return State.strings().getString(Offset); + } + + Expected<StringRef> + getNameFromChecksumsBuffer(uint32_t Offset, + const DebugSubsectionState &State) { + auto Array = State.checksums().getArray(); + auto ChecksumIter = Array.at(Offset); + if (ChecksumIter == Array.end()) + return make_error<RawError>(raw_error_code::invalid_format); + const auto &Entry = *ChecksumIter; + return getNameFromStringTable(Entry.FileNameOffset, State); + } + ScopedPrinter &P; + LazyRandomTypeCollection &TPI; LazyRandomTypeCollection &IPI; }; } @@ -727,8 +868,10 @@ LLVMOutputStyle::initializeTypeDatabase(uint32_t SN) { } Error LLVMOutputStyle::dumpDbiStream() { - bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms || - opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo; + bool DumpModules = opts::shared::DumpModules || + opts::shared::DumpModuleSyms || + opts::shared::DumpModuleFiles || + !opts::shared::DumpModuleSubsections.empty(); if (!opts::raw::DumpHeaders && !DumpModules) return Error::success(); if (!File.hasPDBDbiStream()) { @@ -778,7 +921,7 @@ Error LLVMOutputStyle::dumpDbiStream() { P.printNumber("Symbol Byte Size", Modi.getSymbolDebugInfoByteSize()); P.printNumber("Type Server Index", Modi.getTypeServerIndex()); P.printBoolean("Has EC Info", Modi.hasECInfo()); - if (opts::raw::DumpModuleFiles) { + if (opts::shared::DumpModuleFiles) { std::string FileListName = to_string(Modules.getSourceFileCount(I)) + " Contributing Source Files"; ListScope LL(P, FileListName); @@ -787,8 +930,9 @@ Error LLVMOutputStyle::dumpDbiStream() { } bool HasModuleDI = (Modi.getModuleStreamIndex() < File.getNumStreams()); bool ShouldDumpSymbols = - (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes); - if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) { + (opts::shared::DumpModuleSyms || opts::raw::DumpSymRecordBytes); + if (HasModuleDI && + (ShouldDumpSymbols || !opts::shared::DumpModuleSubsections.empty())) { auto ModStreamData = MappedBlockStream::createIndexedStream( File.getMsfLayout(), File.getMsfBuffer(), Modi.getModuleStreamIndex(), File.getAllocator()); @@ -797,19 +941,19 @@ Error LLVMOutputStyle::dumpDbiStream() { if (auto EC = ModS.reload()) return EC; + auto ExpectedTpi = initializeTypeDatabase(StreamTPI); + if (!ExpectedTpi) + return ExpectedTpi.takeError(); + auto &Tpi = *ExpectedTpi; if (ShouldDumpSymbols) { - auto ExpectedTypes = initializeTypeDatabase(StreamTPI); - if (!ExpectedTypes) - return ExpectedTypes.takeError(); - auto &Types = *ExpectedTypes; ListScope SS(P, "Symbols"); - codeview::CVSymbolDumper SD(P, Types, CodeViewContainer::Pdb, nullptr, + codeview::CVSymbolDumper SD(P, Tpi, CodeViewContainer::Pdb, nullptr, false); bool HadError = false; for (auto S : ModS.symbols(&HadError)) { DictScope LL(P, ""); - if (opts::raw::DumpModuleSyms) { + if (opts::shared::DumpModuleSyms) { if (auto EC = SD.dump(S)) { llvm::consumeError(std::move(EC)); HadError = true; @@ -824,14 +968,22 @@ Error LLVMOutputStyle::dumpDbiStream() { raw_error_code::corrupt_file, "DBI stream contained corrupt symbol record"); } - if (opts::raw::DumpLineInfo) { - ListScope SS(P, "LineInfo"); - auto ExpectedTypes = initializeTypeDatabase(StreamIPI); - if (!ExpectedTypes) - return ExpectedTypes.takeError(); - auto &IpiItems = *ExpectedTypes; - C13RawVisitor V(P, File, IpiItems); - if (auto EC = codeview::visitDebugSubsections(ModS.subsections(), V)) + if (!opts::shared::DumpModuleSubsections.empty()) { + ListScope SS(P, "Subsections"); + auto ExpectedIpi = initializeTypeDatabase(StreamIPI); + if (!ExpectedIpi) + return ExpectedIpi.takeError(); + auto &Ipi = *ExpectedIpi; + auto ExpectedStrings = File.getStringTable(); + if (!ExpectedStrings) + return joinErrors( + make_error<RawError>(raw_error_code::no_stream, + "Could not get string table!"), + ExpectedStrings.takeError()); + + C13RawVisitor V(P, Tpi, Ipi); + if (auto EC = codeview::visitDebugSubsections( + ModS.subsections(), V, ExpectedStrings->getStringTable())) return EC; } } diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.h b/tools/llvm-pdbutil/LLVMOutputStyle.h index 184dc4e1f44d..184dc4e1f44d 100644 --- a/tools/llvm-pdbdump/LLVMOutputStyle.h +++ b/tools/llvm-pdbutil/LLVMOutputStyle.h diff --git a/tools/llvm-pdbdump/LinePrinter.cpp b/tools/llvm-pdbutil/LinePrinter.cpp index 7fa524400aef..ef56b5fe8e6a 100644 --- a/tools/llvm-pdbdump/LinePrinter.cpp +++ b/tools/llvm-pdbutil/LinePrinter.cpp @@ -9,7 +9,7 @@ #include "LinePrinter.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/PDB/UDTLayout.h" diff --git a/tools/llvm-pdbdump/LinePrinter.h b/tools/llvm-pdbutil/LinePrinter.h index 1a922feb1e62..1a922feb1e62 100644 --- a/tools/llvm-pdbdump/LinePrinter.h +++ b/tools/llvm-pdbutil/LinePrinter.h diff --git a/tools/llvm-pdbdump/OutputStyle.h b/tools/llvm-pdbutil/OutputStyle.h index dfefc25a215e..dfefc25a215e 100644 --- a/tools/llvm-pdbdump/OutputStyle.h +++ b/tools/llvm-pdbutil/OutputStyle.h diff --git a/tools/llvm-pdbdump/PdbYaml.cpp b/tools/llvm-pdbutil/PdbYaml.cpp index b4a41fbfdb8f..b4a41fbfdb8f 100644 --- a/tools/llvm-pdbdump/PdbYaml.cpp +++ b/tools/llvm-pdbutil/PdbYaml.cpp diff --git a/tools/llvm-pdbdump/PdbYaml.h b/tools/llvm-pdbutil/PdbYaml.h index 62ed608916fc..62ed608916fc 100644 --- a/tools/llvm-pdbdump/PdbYaml.h +++ b/tools/llvm-pdbutil/PdbYaml.h diff --git a/tools/llvm-pdbdump/PrettyBuiltinDumper.cpp b/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp index 591d5e70cfd6..fcda312e65e9 100644 --- a/tools/llvm-pdbdump/PrettyBuiltinDumper.cpp +++ b/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp @@ -9,7 +9,7 @@ #include "PrettyBuiltinDumper.h" #include "LinePrinter.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" diff --git a/tools/llvm-pdbdump/PrettyBuiltinDumper.h b/tools/llvm-pdbutil/PrettyBuiltinDumper.h index fb6b0b172e6e..fb6b0b172e6e 100644 --- a/tools/llvm-pdbdump/PrettyBuiltinDumper.h +++ b/tools/llvm-pdbutil/PrettyBuiltinDumper.h diff --git a/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp b/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp index 90f7772001d7..651cb8b7649e 100644 --- a/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp +++ b/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp @@ -11,7 +11,7 @@ #include "LinePrinter.h" #include "PrettyClassLayoutGraphicalDumper.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/SmallString.h" diff --git a/tools/llvm-pdbdump/PrettyClassDefinitionDumper.h b/tools/llvm-pdbutil/PrettyClassDefinitionDumper.h index 6569a1d304f6..6569a1d304f6 100644 --- a/tools/llvm-pdbdump/PrettyClassDefinitionDumper.h +++ b/tools/llvm-pdbutil/PrettyClassDefinitionDumper.h diff --git a/tools/llvm-pdbdump/PrettyClassLayoutGraphicalDumper.cpp b/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp index d11472679626..54e33683f552 100644 --- a/tools/llvm-pdbdump/PrettyClassLayoutGraphicalDumper.cpp +++ b/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp @@ -16,7 +16,7 @@ #include "PrettyTypedefDumper.h" #include "PrettyVariableDumper.h" #include "PrettyVariableDumper.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/PDB/PDBSymbolData.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h" diff --git a/tools/llvm-pdbdump/PrettyClassLayoutGraphicalDumper.h b/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.h index f83f1a6c1b34..f83f1a6c1b34 100644 --- a/tools/llvm-pdbdump/PrettyClassLayoutGraphicalDumper.h +++ b/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.h diff --git a/tools/llvm-pdbdump/PrettyCompilandDumper.cpp b/tools/llvm-pdbutil/PrettyCompilandDumper.cpp index 9cf7bf82a164..65e8badbc99a 100644 --- a/tools/llvm-pdbdump/PrettyCompilandDumper.cpp +++ b/tools/llvm-pdbutil/PrettyCompilandDumper.cpp @@ -1,4 +1,4 @@ -//===- PrettyCompilandDumper.cpp - llvm-pdbdump compiland dumper -*- C++ *-===// +//===- PrettyCompilandDumper.cpp - llvm-pdbutil compiland dumper -*- C++ *-===// // // The LLVM Compiler Infrastructure // @@ -11,7 +11,7 @@ #include "LinePrinter.h" #include "PrettyFunctionDumper.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" diff --git a/tools/llvm-pdbdump/PrettyCompilandDumper.h b/tools/llvm-pdbutil/PrettyCompilandDumper.h index 2127e7d1f529..cae196e9d134 100644 --- a/tools/llvm-pdbdump/PrettyCompilandDumper.h +++ b/tools/llvm-pdbutil/PrettyCompilandDumper.h @@ -1,4 +1,4 @@ -//===- PrettyCompilandDumper.h - llvm-pdbdump compiland dumper -*- C++ --*-===// +//===- PrettyCompilandDumper.h - llvm-pdbutil compiland dumper -*- C++ --*-===// // // The LLVM Compiler Infrastructure // diff --git a/tools/llvm-pdbdump/PrettyEnumDumper.cpp b/tools/llvm-pdbutil/PrettyEnumDumper.cpp index 965ca1b9f989..7aff5b93d986 100644 --- a/tools/llvm-pdbdump/PrettyEnumDumper.cpp +++ b/tools/llvm-pdbutil/PrettyEnumDumper.cpp @@ -11,7 +11,7 @@ #include "LinePrinter.h" #include "PrettyBuiltinDumper.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/PDB/PDBSymbolData.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" diff --git a/tools/llvm-pdbdump/PrettyEnumDumper.h b/tools/llvm-pdbutil/PrettyEnumDumper.h index c6e65a6d1772..c6e65a6d1772 100644 --- a/tools/llvm-pdbdump/PrettyEnumDumper.h +++ b/tools/llvm-pdbutil/PrettyEnumDumper.h diff --git a/tools/llvm-pdbdump/PrettyExternalSymbolDumper.cpp b/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp index fc40d90cee96..fc40d90cee96 100644 --- a/tools/llvm-pdbdump/PrettyExternalSymbolDumper.cpp +++ b/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp diff --git a/tools/llvm-pdbdump/PrettyExternalSymbolDumper.h b/tools/llvm-pdbutil/PrettyExternalSymbolDumper.h index 6a009862ddd4..6a009862ddd4 100644 --- a/tools/llvm-pdbdump/PrettyExternalSymbolDumper.h +++ b/tools/llvm-pdbutil/PrettyExternalSymbolDumper.h diff --git a/tools/llvm-pdbdump/PrettyFunctionDumper.cpp b/tools/llvm-pdbutil/PrettyFunctionDumper.cpp index 8b2043989b81..06d72410359f 100644 --- a/tools/llvm-pdbdump/PrettyFunctionDumper.cpp +++ b/tools/llvm-pdbutil/PrettyFunctionDumper.cpp @@ -10,7 +10,7 @@ #include "PrettyFunctionDumper.h" #include "LinePrinter.h" #include "PrettyBuiltinDumper.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBExtras.h" diff --git a/tools/llvm-pdbdump/PrettyFunctionDumper.h b/tools/llvm-pdbutil/PrettyFunctionDumper.h index 1a6f5430ec5a..1a6f5430ec5a 100644 --- a/tools/llvm-pdbdump/PrettyFunctionDumper.h +++ b/tools/llvm-pdbutil/PrettyFunctionDumper.h diff --git a/tools/llvm-pdbdump/PrettyTypeDumper.cpp b/tools/llvm-pdbutil/PrettyTypeDumper.cpp index cd156f051573..0f6086395ad1 100644 --- a/tools/llvm-pdbdump/PrettyTypeDumper.cpp +++ b/tools/llvm-pdbutil/PrettyTypeDumper.cpp @@ -14,7 +14,7 @@ #include "PrettyClassDefinitionDumper.h" #include "PrettyEnumDumper.h" #include "PrettyTypedefDumper.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" @@ -135,80 +135,84 @@ filterAndSortClassDefs(LinePrinter &Printer, Enumerator &E, TypeDumper::TypeDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {} void TypeDumper::start(const PDBSymbolExe &Exe) { + auto Children = Exe.findAllChildren(); if (opts::pretty::Enums) { - auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>(); - Printer.NewLine(); - WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums"; - Printer << ": (" << Enums->getChildCount() << " items)"; - Printer.Indent(); - while (auto Enum = Enums->getNext()) - Enum->dump(*this); - Printer.Unindent(); + if (auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>()) { + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums"; + Printer << ": (" << Enums->getChildCount() << " items)"; + Printer.Indent(); + while (auto Enum = Enums->getNext()) + Enum->dump(*this); + Printer.Unindent(); + } } if (opts::pretty::Typedefs) { - auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>(); - Printer.NewLine(); - WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs"; - Printer << ": (" << Typedefs->getChildCount() << " items)"; - Printer.Indent(); - while (auto Typedef = Typedefs->getNext()) - Typedef->dump(*this); - Printer.Unindent(); + if (auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>()) { + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs"; + Printer << ": (" << Typedefs->getChildCount() << " items)"; + Printer.Indent(); + while (auto Typedef = Typedefs->getNext()) + Typedef->dump(*this); + Printer.Unindent(); + } } if (opts::pretty::Classes) { - auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>(); - uint32_t All = Classes->getChildCount(); - - Printer.NewLine(); - WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes"; - - bool Precompute = false; - Precompute = - (opts::pretty::ClassOrder != opts::pretty::ClassSortMode::None); - - // If we're using no sort mode, then we can start getting immediate output - // from the tool by just filtering as we go, rather than processing - // everything up front so that we can sort it. This makes the tool more - // responsive. So only precompute the filtered/sorted set of classes if - // necessary due to the specified options. - std::vector<LayoutPtr> Filtered; - uint32_t Shown = All; - if (Precompute) { - Filtered = filterAndSortClassDefs(Printer, *Classes, All); - - Shown = Filtered.size(); - } + if (auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>()) { + uint32_t All = Classes->getChildCount(); + + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes"; + + bool Precompute = false; + Precompute = + (opts::pretty::ClassOrder != opts::pretty::ClassSortMode::None); + + // If we're using no sort mode, then we can start getting immediate output + // from the tool by just filtering as we go, rather than processing + // everything up front so that we can sort it. This makes the tool more + // responsive. So only precompute the filtered/sorted set of classes if + // necessary due to the specified options. + std::vector<LayoutPtr> Filtered; + uint32_t Shown = All; + if (Precompute) { + Filtered = filterAndSortClassDefs(Printer, *Classes, All); + + Shown = Filtered.size(); + } - Printer << ": (Showing " << Shown << " items"; - if (Shown < All) - Printer << ", " << (All - Shown) << " filtered"; - Printer << ")"; - Printer.Indent(); - - // If we pre-computed, iterate the filtered/sorted list, otherwise iterate - // the DIA enumerator and filter on the fly. - if (Precompute) { - for (auto &Class : Filtered) - dumpClassLayout(*Class); - } else { - while (auto Class = Classes->getNext()) { - if (Class->getUnmodifiedTypeId() != 0) - continue; - - if (Printer.IsTypeExcluded(Class->getName(), Class->getLength())) - continue; - - auto Layout = llvm::make_unique<ClassLayout>(std::move(Class)); - if (Layout->deepPaddingSize() < opts::pretty::PaddingThreshold) - continue; - - dumpClassLayout(*Layout); + Printer << ": (Showing " << Shown << " items"; + if (Shown < All) + Printer << ", " << (All - Shown) << " filtered"; + Printer << ")"; + Printer.Indent(); + + // If we pre-computed, iterate the filtered/sorted list, otherwise iterate + // the DIA enumerator and filter on the fly. + if (Precompute) { + for (auto &Class : Filtered) + dumpClassLayout(*Class); + } else { + while (auto Class = Classes->getNext()) { + if (Class->getUnmodifiedTypeId() != 0) + continue; + + if (Printer.IsTypeExcluded(Class->getName(), Class->getLength())) + continue; + + auto Layout = llvm::make_unique<ClassLayout>(std::move(Class)); + if (Layout->deepPaddingSize() < opts::pretty::PaddingThreshold) + continue; + + dumpClassLayout(*Layout); + } } - } - Printer.Unindent(); + Printer.Unindent(); + } } } diff --git a/tools/llvm-pdbdump/PrettyTypeDumper.h b/tools/llvm-pdbutil/PrettyTypeDumper.h index 68a2f0246eba..68a2f0246eba 100644 --- a/tools/llvm-pdbdump/PrettyTypeDumper.h +++ b/tools/llvm-pdbutil/PrettyTypeDumper.h diff --git a/tools/llvm-pdbdump/PrettyTypedefDumper.cpp b/tools/llvm-pdbutil/PrettyTypedefDumper.cpp index 2d8e915d7604..2266e6ea2bef 100644 --- a/tools/llvm-pdbdump/PrettyTypedefDumper.cpp +++ b/tools/llvm-pdbutil/PrettyTypedefDumper.cpp @@ -12,7 +12,7 @@ #include "LinePrinter.h" #include "PrettyBuiltinDumper.h" #include "PrettyFunctionDumper.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBExtras.h" diff --git a/tools/llvm-pdbdump/PrettyTypedefDumper.h b/tools/llvm-pdbutil/PrettyTypedefDumper.h index 34c139601301..133bbfb7db0e 100644 --- a/tools/llvm-pdbdump/PrettyTypedefDumper.h +++ b/tools/llvm-pdbutil/PrettyTypedefDumper.h @@ -1,4 +1,4 @@ -//===- PrettyTypedefDumper.h - llvm-pdbdump typedef dumper ---*- C++ ----*-===// +//===- PrettyTypedefDumper.h - llvm-pdbutil typedef dumper ---*- C++ ----*-===// // // The LLVM Compiler Infrastructure // diff --git a/tools/llvm-pdbdump/PrettyVariableDumper.cpp b/tools/llvm-pdbutil/PrettyVariableDumper.cpp index 70925f4b03d0..4884fc8ee5a4 100644 --- a/tools/llvm-pdbdump/PrettyVariableDumper.cpp +++ b/tools/llvm-pdbutil/PrettyVariableDumper.cpp @@ -12,7 +12,7 @@ #include "LinePrinter.h" #include "PrettyBuiltinDumper.h" #include "PrettyFunctionDumper.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbolData.h" diff --git a/tools/llvm-pdbdump/PrettyVariableDumper.h b/tools/llvm-pdbutil/PrettyVariableDumper.h index cacf1ce9577b..cacf1ce9577b 100644 --- a/tools/llvm-pdbdump/PrettyVariableDumper.h +++ b/tools/llvm-pdbutil/PrettyVariableDumper.h diff --git a/tools/llvm-pdbdump/StreamUtil.cpp b/tools/llvm-pdbutil/StreamUtil.cpp index 81aa256b5002..81aa256b5002 100644 --- a/tools/llvm-pdbdump/StreamUtil.cpp +++ b/tools/llvm-pdbutil/StreamUtil.cpp diff --git a/tools/llvm-pdbdump/StreamUtil.h b/tools/llvm-pdbutil/StreamUtil.h index b5c0beba44fe..b5c0beba44fe 100644 --- a/tools/llvm-pdbdump/StreamUtil.h +++ b/tools/llvm-pdbutil/StreamUtil.h diff --git a/tools/llvm-pdbdump/YAMLOutputStyle.cpp b/tools/llvm-pdbutil/YAMLOutputStyle.cpp index ee72b90b12d1..58c538d968c8 100644 --- a/tools/llvm-pdbdump/YAMLOutputStyle.cpp +++ b/tools/llvm-pdbutil/YAMLOutputStyle.cpp @@ -9,15 +9,13 @@ #include "YAMLOutputStyle.h" -#include "C13DebugFragmentVisitor.h" #include "PdbYaml.h" -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" #include "llvm/DebugInfo/CodeView/DebugSubsection.h" -#include "llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h" #include "llvm/DebugInfo/CodeView/DebugUnknownSubsection.h" #include "llvm/DebugInfo/CodeView/Line.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" @@ -39,39 +37,8 @@ YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) } Error YAMLOutputStyle::dump() { - if (opts::pdb2yaml::All) { - opts::pdb2yaml::StreamMetadata = true; - opts::pdb2yaml::StreamDirectory = true; - opts::pdb2yaml::PdbStream = true; - opts::pdb2yaml::StringTable = true; - opts::pdb2yaml::DbiStream = true; - opts::pdb2yaml::DbiModuleInfo = true; - opts::pdb2yaml::DbiModuleSyms = true; - opts::pdb2yaml::DbiModuleSourceFileInfo = true; - opts::pdb2yaml::DbiModuleSourceLineInfo = true; - opts::pdb2yaml::TpiStream = true; - opts::pdb2yaml::IpiStream = true; - } - if (opts::pdb2yaml::StreamDirectory) opts::pdb2yaml::StreamMetadata = true; - if (opts::pdb2yaml::DbiModuleSyms) - opts::pdb2yaml::DbiModuleInfo = true; - - if (opts::pdb2yaml::DbiModuleSourceLineInfo) - opts::pdb2yaml::DbiModuleSourceFileInfo = true; - - if (opts::pdb2yaml::DbiModuleSourceFileInfo) - opts::pdb2yaml::DbiModuleInfo = true; - - if (opts::pdb2yaml::DbiModuleInfo) - opts::pdb2yaml::DbiStream = true; - - // Some names from the module source file info get pulled from the string - // table, so if we're writing module source info, we have to write the string - // table as well. - if (opts::pdb2yaml::DbiModuleSourceLineInfo) - opts::pdb2yaml::StringTable = true; if (auto EC = dumpFileHeaders()) return EC; @@ -125,8 +92,8 @@ Error YAMLOutputStyle::dumpFileHeaders() { } Error YAMLOutputStyle::dumpStringTable() { - bool RequiresStringTable = opts::pdb2yaml::DbiModuleSourceFileInfo || - opts::pdb2yaml::DbiModuleSourceLineInfo; + bool RequiresStringTable = opts::shared::DumpModuleFiles || + !opts::shared::DumpModuleSubsections.empty(); bool RequestedStringTable = opts::pdb2yaml::StringTable; if (!RequiresStringTable && !RequestedStringTable) return Error::success(); @@ -192,6 +159,30 @@ Error YAMLOutputStyle::dumpPDBStream() { return Error::success(); } +static opts::ModuleSubsection convertSubsectionKind(DebugSubsectionKind K) { + switch (K) { + case DebugSubsectionKind::CrossScopeExports: + return opts::ModuleSubsection::CrossScopeExports; + case DebugSubsectionKind::CrossScopeImports: + return opts::ModuleSubsection::CrossScopeImports; + case DebugSubsectionKind::FileChecksums: + return opts::ModuleSubsection::FileChecksums; + case DebugSubsectionKind::InlineeLines: + return opts::ModuleSubsection::InlineeLines; + case DebugSubsectionKind::Lines: + return opts::ModuleSubsection::Lines; + case DebugSubsectionKind::Symbols: + return opts::ModuleSubsection::Symbols; + case DebugSubsectionKind::StringTable: + return opts::ModuleSubsection::StringTable; + case DebugSubsectionKind::FrameData: + return opts::ModuleSubsection::FrameData; + default: + return opts::ModuleSubsection::Unknown; + } + llvm_unreachable("Unreachable!"); +} + Error YAMLOutputStyle::dumpDbiStream() { if (!opts::pdb2yaml::DbiStream) return Error::success(); @@ -209,7 +200,7 @@ Error YAMLOutputStyle::dumpDbiStream() { Obj.DbiStream->PdbDllRbld = DS.getPdbDllRbld(); Obj.DbiStream->PdbDllVersion = DS.getPdbDllVersion(); Obj.DbiStream->VerHeader = DS.getDbiVersion(); - if (opts::pdb2yaml::DbiModuleInfo) { + if (opts::shared::DumpModules) { const auto &Modules = DS.modules(); for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) { DbiModuleDescriptor MI = Modules.getModuleDescriptor(I); @@ -219,7 +210,7 @@ Error YAMLOutputStyle::dumpDbiStream() { DMI.Mod = MI.getModuleName(); DMI.Obj = MI.getObjFileName(); - if (opts::pdb2yaml::DbiModuleSourceFileInfo) { + if (opts::shared::DumpModuleFiles) { auto Files = Modules.source_files(I); DMI.SourceFiles.assign(Files.begin(), Files.end()); } @@ -239,13 +230,17 @@ Error YAMLOutputStyle::dumpDbiStream() { auto ExpectedST = File.getStringTable(); if (!ExpectedST) return ExpectedST.takeError(); - if (opts::pdb2yaml::DbiModuleSourceLineInfo && + if (!opts::shared::DumpModuleSubsections.empty() && ModS.hasDebugSubsections()) { auto ExpectedChecksums = ModS.findChecksumsSubsection(); if (!ExpectedChecksums) return ExpectedChecksums.takeError(); for (const auto &SS : ModS.subsections()) { + opts::ModuleSubsection OptionKind = convertSubsectionKind(SS.kind()); + if (!opts::checkModuleSubsection(OptionKind)) + continue; + auto Converted = CodeViewYAML::YAMLDebugSubsection::fromCodeViewSubection( ExpectedST->getStringTable(), *ExpectedChecksums, SS); @@ -255,7 +250,7 @@ Error YAMLOutputStyle::dumpDbiStream() { } } - if (opts::pdb2yaml::DbiModuleSyms) { + if (opts::shared::DumpModuleSyms) { DMI.Modi.emplace(); DMI.Modi->Signature = ModS.signature(); diff --git a/tools/llvm-pdbdump/YAMLOutputStyle.h b/tools/llvm-pdbutil/YAMLOutputStyle.h index 3690e3529d4a..3690e3529d4a 100644 --- a/tools/llvm-pdbdump/YAMLOutputStyle.h +++ b/tools/llvm-pdbutil/YAMLOutputStyle.h diff --git a/tools/llvm-pdbdump/fuzzer/CMakeLists.txt b/tools/llvm-pdbutil/fuzzer/CMakeLists.txt index cf5a0f70aab3..6af00476577f 100644 --- a/tools/llvm-pdbdump/fuzzer/CMakeLists.txt +++ b/tools/llvm-pdbutil/fuzzer/CMakeLists.txt @@ -5,11 +5,11 @@ set(LLVM_LINK_COMPONENTS Support ) -add_llvm_executable(llvm-pdbdump-fuzzer +add_llvm_executable(llvm-pdbutil-fuzzer EXCLUDE_FROM_ALL - llvm-pdbdump-fuzzer.cpp + llvm-pdbutil-fuzzer.cpp ) -target_link_libraries(llvm-pdbdump-fuzzer +target_link_libraries(llvm-pdbutil-fuzzer LLVMFuzzer ) diff --git a/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp b/tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp index 5f09416a9ff6..4edb53e261ff 100644 --- a/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp +++ b/tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp @@ -1,4 +1,4 @@ -//===-- llvm-pdbdump-fuzzer.cpp - Fuzz the llvm-pdbdump tool --------------===// +//===-- llvm-pdbutil-fuzzer.cpp - Fuzz the llvm-pdbutil tool --------------===// // // The LLVM Compiler Infrastructure // @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// /// /// \file -/// \brief This file implements a function that runs llvm-pdbdump +/// \brief This file implements a function that runs llvm-pdbutil /// on a single input. This function is then linked into the Fuzzer library. /// //===----------------------------------------------------------------------===// diff --git a/tools/llvm-pdbdump/llvm-pdbdump.cpp b/tools/llvm-pdbutil/llvm-pdbutil.cpp index 4626de9c4440..f6b6a156a767 100644 --- a/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -1,4 +1,4 @@ -//===- llvm-pdbdump.cpp - Dump debug info from a PDB file -------*- C++ -*-===// +//===- llvm-pdbutil.cpp - Dump debug info from a PDB file -------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm-pdbdump.h" +#include "llvm-pdbutil.h" #include "Analyze.h" #include "Diff.h" @@ -269,7 +269,6 @@ namespace raw { cl::OptionCategory MsfOptions("MSF Container Options"); cl::OptionCategory TypeOptions("Type Record Options"); -cl::OptionCategory FileOptions("Module & File Options"); cl::OptionCategory SymbolOptions("Symbol Options"); cl::OptionCategory MiscOptions("Miscellaneous Options"); @@ -323,20 +322,9 @@ cl::opt<bool> DumpIpiRecordBytes( cl::desc("dump CodeView type record raw bytes from IPI stream"), cl::cat(TypeOptions), cl::sub(RawSubcommand)); -// MODULE & FILE OPTIONS -cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"), - cl::cat(FileOptions), cl::sub(RawSubcommand)); -cl::opt<bool> DumpModuleFiles("module-files", cl::desc("dump file information"), - cl::cat(FileOptions), cl::sub(RawSubcommand)); -cl::opt<bool> DumpLineInfo("line-info", - cl::desc("dump file and line information"), - cl::cat(FileOptions), cl::sub(RawSubcommand)); - // SYMBOL OPTIONS cl::opt<bool> DumpGlobals("globals", cl::desc("dump globals stream data"), cl::cat(SymbolOptions), cl::sub(RawSubcommand)); -cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"), - cl::cat(SymbolOptions), cl::sub(RawSubcommand)); cl::opt<bool> DumpPublics("publics", cl::desc("dump Publics stream data"), cl::cat(SymbolOptions), cl::sub(RawSubcommand)); cl::opt<bool> @@ -381,11 +369,9 @@ namespace pdb2yaml { cl::opt<bool> All("all", cl::desc("Dump everything we know how to dump."), cl::sub(PdbToYamlSubcommand), cl::init(false)); -cl::opt<bool> - NoFileHeaders("no-file-headers", - cl::desc("Do not dump MSF file headers (you will not be able " - "to generate a fresh PDB from the resulting YAML)"), - cl::sub(PdbToYamlSubcommand), cl::init(false)); +cl::opt<bool> NoFileHeaders("no-file-headers", + cl::desc("Do not dump MSF file headers"), + cl::sub(PdbToYamlSubcommand), cl::init(false)); cl::opt<bool> Minimal("minimal", cl::desc("Don't write fields with default values"), cl::sub(PdbToYamlSubcommand), cl::init(false)); @@ -406,29 +392,8 @@ cl::opt<bool> StringTable("string-table", cl::desc("Dump the PDB String Table"), cl::sub(PdbToYamlSubcommand), cl::init(false)); cl::opt<bool> DbiStream("dbi-stream", - cl::desc("Dump the DBI Stream (Stream 2)"), + cl::desc("Dump the DBI Stream Headers (Stream 2)"), cl::sub(PdbToYamlSubcommand), cl::init(false)); -cl::opt<bool> - DbiModuleInfo("dbi-module-info", - cl::desc("Dump DBI Module Information (implies -dbi-stream)"), - cl::sub(PdbToYamlSubcommand), cl::init(false)); - -cl::opt<bool> DbiModuleSyms( - "dbi-module-syms", - cl::desc("Dump DBI Module Information (implies -dbi-module-info)"), - cl::sub(PdbToYamlSubcommand), cl::init(false)); - -cl::opt<bool> DbiModuleSourceFileInfo( - "dbi-module-source-info", - cl::desc( - "Dump DBI Module Source File Information (implies -dbi-module-info)"), - cl::sub(PdbToYamlSubcommand), cl::init(false)); - -cl::opt<bool> - DbiModuleSourceLineInfo("dbi-module-lines", - cl::desc("Dump DBI Module Source Line Information " - "(implies -dbi-module-source-info)"), - cl::sub(PdbToYamlSubcommand), cl::init(false)); cl::opt<bool> TpiStream("tpi-stream", cl::desc("Dump the TPI Stream (Stream 3)"), @@ -443,6 +408,51 @@ cl::list<std::string> InputFilename(cl::Positional, cl::sub(PdbToYamlSubcommand)); } +namespace shared { +cl::OptionCategory FileOptions("Module & File Options"); + +// MODULE & FILE OPTIONS +cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"), + cl::cat(FileOptions), cl::sub(RawSubcommand), + cl::sub(PdbToYamlSubcommand)); +cl::opt<bool> DumpModuleFiles("module-files", cl::desc("dump file information"), + cl::cat(FileOptions), cl::sub(RawSubcommand), + cl::sub(PdbToYamlSubcommand)); +cl::list<ModuleSubsection> DumpModuleSubsections( + "subsections", cl::ZeroOrMore, cl::CommaSeparated, + cl::desc("dump subsections from each module's debug stream"), + cl::values( + clEnumValN( + ModuleSubsection::CrossScopeExports, "cme", + "Cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"), + clEnumValN( + ModuleSubsection::CrossScopeImports, "cmi", + "Cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"), + clEnumValN(ModuleSubsection::FileChecksums, "fc", + "File checksums (DEBUG_S_CHECKSUMS subsection)"), + clEnumValN(ModuleSubsection::InlineeLines, "ilines", + "Inlinee lines (DEBUG_S_INLINEELINES subsection)"), + clEnumValN(ModuleSubsection::Lines, "lines", + "Lines (DEBUG_S_LINES subsection)"), + clEnumValN(ModuleSubsection::StringTable, "strings", + "String Table (DEBUG_S_STRINGTABLE subsection) (not " + "typically present in PDB file)"), + clEnumValN(ModuleSubsection::FrameData, "frames", + "Frame Data (DEBUG_S_FRAMEDATA subsection)"), + clEnumValN(ModuleSubsection::Symbols, "symbols", + "Symbols (DEBUG_S_SYMBOLS subsection) (not typically " + "present in PDB file)"), + clEnumValN(ModuleSubsection::CoffSymbolRVAs, "rvas", + "COFF Symbol RVAs (DEBUG_S_COFF_SYMBOL_RVA subsection)"), + clEnumValN(ModuleSubsection::Unknown, "unknown", + "Any subsection not covered by another option"), + clEnumValN(ModuleSubsection::All, "all", "All known subsections")), + cl::cat(FileOptions), cl::sub(RawSubcommand), cl::sub(PdbToYamlSubcommand)); +cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"), + cl::cat(FileOptions), cl::sub(RawSubcommand), + cl::sub(PdbToYamlSubcommand)); +} // namespace shared + namespace analyze { cl::opt<bool> StringTable("hash-collisions", cl::desc("Find hash collisions"), cl::sub(AnalyzeSubcommand), cl::init(false)); @@ -463,6 +473,13 @@ cl::opt<std::string> static ExitOnError ExitOnErr; +bool opts::checkModuleSubsection(opts::ModuleSubsection MS) { + return any_of(opts::shared::DumpModuleSubsections, + [=](opts::ModuleSubsection M) { + return M == MS || M == opts::ModuleSubsection::All; + }); +} + static void yamlToPdb(StringRef Path) { BumpPtrAllocator Allocator; ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer = @@ -540,8 +557,8 @@ static void yamlToPdb(StringRef Path) { } } - auto CodeViewSubsections = - ExitOnErr(CodeViewYAML::convertSubsectionList(MI.Subsections, Strings)); + auto CodeViewSubsections = ExitOnErr(CodeViewYAML::toCodeViewSubsectionList( + Allocator, MI.Subsections, Strings)); for (auto &SS : CodeViewSubsections) { ModiBuilder.addDebugSubsection(std::move(SS)); } @@ -852,7 +869,7 @@ int main(int argc_, const char *argv_[]) { sys::PrintStackTraceOnErrorSignal(argv_[0]); PrettyStackTraceProgram X(argc_, argv_); - ExitOnErr.setBanner("llvm-pdbdump: "); + ExitOnErr.setBanner("llvm-pdbutil: "); SmallVector<const char *, 256> argv; SpecificBumpPtrAllocator<char> ArgAllocator; @@ -879,12 +896,29 @@ int main(int argc_, const char *argv_[]) { } } + if ((opts::RawSubcommand && opts::raw::RawAll) || + (opts::PdbToYamlSubcommand && opts::pdb2yaml::All)) { + opts::shared::DumpModules = true; + opts::shared::DumpModuleFiles = true; + opts::shared::DumpModuleSyms = true; + opts::shared::DumpModuleSubsections.push_back(opts::ModuleSubsection::All); + if (llvm::is_contained(opts::shared::DumpModuleSubsections, + opts::ModuleSubsection::All)) { + opts::shared::DumpModuleSubsections.reset(); + opts::shared::DumpModuleSubsections.push_back( + opts::ModuleSubsection::All); + } + } + + if (opts::shared::DumpModuleSyms || opts::shared::DumpModuleFiles) + opts::shared::DumpModules = true; + + if (opts::shared::DumpModules) + opts::pdb2yaml::DbiStream = true; + if (opts::RawSubcommand) { if (opts::raw::RawAll) { opts::raw::DumpHeaders = true; - opts::raw::DumpModules = true; - opts::raw::DumpModuleFiles = true; - opts::raw::DumpModuleSyms = true; opts::raw::DumpGlobals = true; opts::raw::DumpPublics = true; opts::raw::DumpSectionHeaders = true; @@ -896,7 +930,6 @@ int main(int argc_, const char *argv_[]) { opts::raw::DumpIpiRecords = true; opts::raw::DumpSectionMap = true; opts::raw::DumpSectionContribs = true; - opts::raw::DumpLineInfo = true; opts::raw::DumpFpo = true; opts::raw::DumpStringTable = true; } @@ -908,6 +941,17 @@ int main(int argc_, const char *argv_[]) { exit(1); } } + if (opts::PdbToYamlSubcommand) { + if (opts::pdb2yaml::All) { + opts::pdb2yaml::StreamMetadata = true; + opts::pdb2yaml::StreamDirectory = true; + opts::pdb2yaml::PdbStream = true; + opts::pdb2yaml::StringTable = true; + opts::pdb2yaml::DbiStream = true; + opts::pdb2yaml::TpiStream = true; + opts::pdb2yaml::IpiStream = true; + } + } llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded); diff --git a/tools/llvm-pdbdump/llvm-pdbdump.h b/tools/llvm-pdbutil/llvm-pdbutil.h index b344129d217a..f1699d0bb557 100644 --- a/tools/llvm-pdbdump/llvm-pdbdump.h +++ b/tools/llvm-pdbutil/llvm-pdbutil.h @@ -1,4 +1,4 @@ -//===- llvm-pdbdump.h ----------------------------------------- *- C++ --*-===// +//===- llvm-pdbutil.h ----------------------------------------- *- C++ --*-===// // // The LLVM Compiler Infrastructure // @@ -27,6 +27,29 @@ uint32_t getTypeLength(const PDBSymbolData &Symbol); namespace opts { +enum class ModuleSubsection { + Unknown, + Lines, + FileChecksums, + InlineeLines, + CrossScopeImports, + CrossScopeExports, + StringTable, + Symbols, + FrameData, + CoffSymbolRVAs, + All +}; + +bool checkModuleSubsection(ModuleSubsection Kind); + +template <typename... Ts> +bool checkModuleSubsection(ModuleSubsection K1, ModuleSubsection K2, + Ts &&... Rest) { + return checkModuleSubsection(K1) || + checkModuleSubsection(K2, std::forward<Ts>(Rest)...); +} + namespace pretty { enum class ClassDefinitionFormat { None, Layout, All }; @@ -96,13 +119,8 @@ extern llvm::cl::opt<bool> DumpTpiRecordBytes; extern llvm::cl::opt<bool> DumpTpiRecords; extern llvm::cl::opt<bool> DumpIpiRecords; extern llvm::cl::opt<bool> DumpIpiRecordBytes; -extern llvm::cl::opt<bool> DumpModules; -extern llvm::cl::opt<bool> DumpModuleFiles; -extern llvm::cl::opt<bool> DumpModuleLines; -extern llvm::cl::opt<bool> DumpModuleSyms; extern llvm::cl::opt<bool> DumpPublics; extern llvm::cl::opt<bool> DumpSectionContribs; -extern llvm::cl::opt<bool> DumpLineInfo; extern llvm::cl::opt<bool> DumpSectionMap; extern llvm::cl::opt<bool> DumpSymRecordBytes; extern llvm::cl::opt<bool> DumpSectionHeaders; @@ -123,14 +141,17 @@ extern llvm::cl::opt<bool> StreamDirectory; extern llvm::cl::opt<bool> StringTable; extern llvm::cl::opt<bool> PdbStream; extern llvm::cl::opt<bool> DbiStream; -extern llvm::cl::opt<bool> DbiModuleInfo; -extern llvm::cl::opt<bool> DbiModuleSyms; -extern llvm::cl::opt<bool> DbiModuleSourceFileInfo; -extern llvm::cl::opt<bool> DbiModuleSourceLineInfo; extern llvm::cl::opt<bool> TpiStream; extern llvm::cl::opt<bool> IpiStream; extern llvm::cl::list<std::string> InputFilename; } + +namespace shared { +extern llvm::cl::opt<bool> DumpModules; +extern llvm::cl::opt<bool> DumpModuleFiles; +extern llvm::cl::list<ModuleSubsection> DumpModuleSubsections; +extern llvm::cl::opt<bool> DumpModuleSyms; +} // namespace shared } #endif diff --git a/tools/llvm-readobj/CMakeLists.txt b/tools/llvm-readobj/CMakeLists.txt index 0ad149538f63..bde486a5f0db 100644 --- a/tools/llvm-readobj/CMakeLists.txt +++ b/tools/llvm-readobj/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_LINK_COMPONENTS DebugInfoCodeView Object + BinaryFormat Support DebugInfoCodeView DebugInfoMSF diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index bc07bd296ad2..6223c09a4ded 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -21,6 +21,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/BinaryFormat/COFF.h" #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" @@ -45,7 +46,6 @@ #include "llvm/Object/COFF.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/BinaryStreamReader.h" -#include "llvm/Support/COFF.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ConvertUTF.h" diff --git a/tools/llvm-readobj/COFFImportDumper.cpp b/tools/llvm-readobj/COFFImportDumper.cpp index 83715e60f057..c5b8bf758462 100644 --- a/tools/llvm-readobj/COFFImportDumper.cpp +++ b/tools/llvm-readobj/COFFImportDumper.cpp @@ -15,9 +15,9 @@ #include "Error.h" #include "ObjDumper.h" #include "llvm-readobj.h" +#include "llvm/BinaryFormat/COFF.h" #include "llvm/Object/COFF.h" #include "llvm/Object/COFFImportFile.h" -#include "llvm/Support/COFF.h" using namespace llvm::object; diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 427920569042..116f02f7f154 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -1,4 +1,4 @@ -//===-- ELFDumper.cpp - ELF-specific dumper ---------------------*- C++ -*-===// +//===- ELFDumper.cpp - ELF-specific dumper --------------------------------===// // // The LLVM Compiler Infrastructure // @@ -17,19 +17,44 @@ #include "ObjDumper.h" #include "StackMapPrinter.h" #include "llvm-readobj.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/ELF.h" +#include "llvm/Object/ELF.h" #include "llvm/Object/ELFObjectFile.h" +#include "llvm/Object/ELFTypes.h" +#include "llvm/Object/Error.h" +#include "llvm/Object/ObjectFile.h" +#include "llvm/Object/StackMapParser.h" #include "llvm/Support/ARMAttributeParser.h" #include "llvm/Support/ARMBuildAttributes.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/MipsABIFlags.h" #include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/raw_ostream.h" +#include <algorithm> +#include <cinttypes> +#include <cstddef> +#include <cstdint> +#include <cstdlib> +#include <iterator> +#include <memory> +#include <string> +#include <system_error> +#include <vector> using namespace llvm; using namespace llvm::object; @@ -49,28 +74,28 @@ using namespace ELF; return std::string(#enum).substr(3); #define TYPEDEF_ELF_TYPES(ELFT) \ - typedef ELFFile<ELFT> ELFO; \ - typedef typename ELFO::Elf_Shdr Elf_Shdr; \ - typedef typename ELFO::Elf_Sym Elf_Sym; \ - typedef typename ELFO::Elf_Dyn Elf_Dyn; \ - typedef typename ELFO::Elf_Dyn_Range Elf_Dyn_Range; \ - typedef typename ELFO::Elf_Rel Elf_Rel; \ - typedef typename ELFO::Elf_Rela Elf_Rela; \ - typedef typename ELFO::Elf_Rel_Range Elf_Rel_Range; \ - typedef typename ELFO::Elf_Rela_Range Elf_Rela_Range; \ - typedef typename ELFO::Elf_Phdr Elf_Phdr; \ - typedef typename ELFO::Elf_Half Elf_Half; \ - typedef typename ELFO::Elf_Ehdr Elf_Ehdr; \ - typedef typename ELFO::Elf_Word Elf_Word; \ - typedef typename ELFO::Elf_Hash Elf_Hash; \ - typedef typename ELFO::Elf_GnuHash Elf_GnuHash; \ - typedef typename ELFO::Elf_Sym_Range Elf_Sym_Range; \ - typedef typename ELFO::Elf_Versym Elf_Versym; \ - typedef typename ELFO::Elf_Verneed Elf_Verneed; \ - typedef typename ELFO::Elf_Vernaux Elf_Vernaux; \ - typedef typename ELFO::Elf_Verdef Elf_Verdef; \ - typedef typename ELFO::Elf_Verdaux Elf_Verdaux; \ - typedef typename ELFO::uintX_t uintX_t; + using ELFO = ELFFile<ELFT>; \ + using Elf_Shdr = typename ELFO::Elf_Shdr; \ + using Elf_Sym = typename ELFO::Elf_Sym; \ + using Elf_Dyn = typename ELFO::Elf_Dyn; \ + using Elf_Dyn_Range = typename ELFO::Elf_Dyn_Range; \ + using Elf_Rel = typename ELFO::Elf_Rel; \ + using Elf_Rela = typename ELFO::Elf_Rela; \ + using Elf_Rel_Range = typename ELFO::Elf_Rel_Range; \ + using Elf_Rela_Range = typename ELFO::Elf_Rela_Range; \ + using Elf_Phdr = typename ELFO::Elf_Phdr; \ + using Elf_Half = typename ELFO::Elf_Half; \ + using Elf_Ehdr = typename ELFO::Elf_Ehdr; \ + using Elf_Word = typename ELFO::Elf_Word; \ + using Elf_Hash = typename ELFO::Elf_Hash; \ + using Elf_GnuHash = typename ELFO::Elf_GnuHash; \ + using Elf_Sym_Range = typename ELFO::Elf_Sym_Range; \ + using Elf_Versym = typename ELFO::Elf_Versym; \ + using Elf_Verneed = typename ELFO::Elf_Verneed; \ + using Elf_Vernaux = typename ELFO::Elf_Vernaux; \ + using Elf_Verdef = typename ELFO::Elf_Verdef; \ + using Elf_Verdaux = typename ELFO::Elf_Verdaux; \ + using uintX_t = typename ELFO::uintX_t; namespace { @@ -81,15 +106,16 @@ template <class ELFT> class DumpStyle; /// the size, entity size and virtual address are different entries in arbitrary /// order (DT_REL, DT_RELSZ, DT_RELENT for example). struct DynRegionInfo { - DynRegionInfo() : Addr(nullptr), Size(0), EntSize(0) {} + DynRegionInfo() = default; DynRegionInfo(const void *A, uint64_t S, uint64_t ES) : Addr(A), Size(S), EntSize(ES) {} + /// \brief Address in current address space. - const void *Addr; + const void *Addr = nullptr; /// \brief Size in bytes of the region. - uint64_t Size; + uint64_t Size = 0; /// \brief Size of each entity in the region. - uint64_t EntSize; + uint64_t EntSize = 0; template <typename Type> ArrayRef<Type> getAsArrayRef() const { const Type *Start = reinterpret_cast<const Type *>(Addr); @@ -139,6 +165,7 @@ public: private: std::unique_ptr<DumpStyle<ELFT>> ELFDumperStyle; + TYPEDEF_ELF_TYPES(ELFT) DynRegionInfo checkDRI(DynRegionInfo DRI) { @@ -196,6 +223,7 @@ private: : PointerIntPair<const void *, 1>(verdef, 0) {} VersionMapEntry(const Elf_Vernaux *vernaux) : PointerIntPair<const void *, 1>(vernaux, 1) {} + bool isNull() const { return getPointer() == nullptr; } bool isVerdef() const { return !isNull() && getInt() == 0; } bool isVernaux() const { return !isNull() && getInt() == 1; } @@ -262,10 +290,11 @@ void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const { template <typename ELFT> class DumpStyle { public: using Elf_Shdr = typename ELFFile<ELFT>::Elf_Shdr; - using Elf_Sym = typename ELFFile<ELFT>::Elf_Sym; + using Elf_Sym = typename ELFFile<ELFT>::Elf_Sym; DumpStyle(ELFDumper<ELFT> *Dumper) : Dumper(Dumper) {} - virtual ~DumpStyle() {} + virtual ~DumpStyle() = default; + virtual void printFileHeaders(const ELFFile<ELFT> *Obj) = 0; virtual void printGroupSections(const ELFFile<ELFT> *Obj) = 0; virtual void printRelocations(const ELFFile<ELFT> *Obj) = 0; @@ -274,9 +303,7 @@ public: virtual void printDynamicSymbols(const ELFFile<ELFT> *Obj) = 0; virtual void printDynamicRelocations(const ELFFile<ELFT> *Obj) = 0; virtual void printSymtabMessage(const ELFFile<ELFT> *obj, StringRef Name, - size_t Offset) { - return; - } + size_t Offset) {} virtual void printSymbol(const ELFFile<ELFT> *Obj, const Elf_Sym *Symbol, const Elf_Sym *FirstSym, StringRef StrTable, bool IsDynamic) = 0; @@ -284,16 +311,20 @@ public: virtual void printHashHistogram(const ELFFile<ELFT> *Obj) = 0; virtual void printNotes(const ELFFile<ELFT> *Obj) = 0; const ELFDumper<ELFT> *dumper() const { return Dumper; } + private: const ELFDumper<ELFT> *Dumper; }; template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> { formatted_raw_ostream OS; + public: TYPEDEF_ELF_TYPES(ELFT) + GNUStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper) : DumpStyle<ELFT>(Dumper), OS(W.getOStream()) {} + void printFileHeaders(const ELFO *Obj) override; void printGroupSections(const ELFFile<ELFT> *Obj) override; void printRelocations(const ELFO *Obj) override; @@ -301,8 +332,8 @@ public: void printSymbols(const ELFO *Obj) override; void printDynamicSymbols(const ELFO *Obj) override; void printDynamicRelocations(const ELFO *Obj) override; - virtual void printSymtabMessage(const ELFO *Obj, StringRef Name, - size_t Offset) override; + void printSymtabMessage(const ELFO *Obj, StringRef Name, + size_t Offset) override; void printProgramHeaders(const ELFO *Obj) override; void printHashHistogram(const ELFFile<ELFT> *Obj) override; void printNotes(const ELFFile<ELFT> *Obj) override; @@ -311,6 +342,7 @@ private: struct Field { StringRef Str; unsigned Column; + Field(StringRef S, unsigned Col) : Str(S), Column(Col) {} Field(unsigned Col) : Str(""), Column(Col) {} }; @@ -348,6 +380,7 @@ private: template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> { public: TYPEDEF_ELF_TYPES(ELFT) + LLVMStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper) : DumpStyle<ELFT>(Dumper), W(W) {} @@ -368,10 +401,11 @@ private: void printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel); void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, StringRef StrTable, bool IsDynamic) override; + ScopedPrinter &W; }; -} // namespace +} // end anonymous namespace namespace llvm { @@ -405,7 +439,7 @@ std::error_code createELFDumper(const object::ObjectFile *Obj, return readobj_error::unsupported_obj_file_format; } -} // namespace llvm +} // end namespace llvm // Iterate through the versions needed section, and place each Elf_Vernaux // in the VersionMap according to its index. @@ -525,8 +559,8 @@ static void printVersionDefinitionSection(ELFDumper<ELFT> *Dumper, const ELFO *Obj, const typename ELFO::Elf_Shdr *Sec, ScopedPrinter &W) { - typedef typename ELFO::Elf_Verdef VerDef; - typedef typename ELFO::Elf_Verdaux VerdAux; + using VerDef = typename ELFO::Elf_Verdef; + using VerdAux = typename ELFO::Elf_Verdaux; DictScope SD(W, "SHT_GNU_verdef"); if (!Sec) @@ -581,8 +615,8 @@ static void printVersionDependencySection(ELFDumper<ELFT> *Dumper, const ELFO *Obj, const typename ELFO::Elf_Shdr *Sec, ScopedPrinter &W) { - typedef typename ELFO::Elf_Verneed VerNeed; - typedef typename ELFO::Elf_Vernaux VernAux; + using VerNeed = typename ELFO::Elf_Verneed; + using VernAux = typename ELFO::Elf_Vernaux; DictScope SD(W, "SHT_GNU_verneed"); if (!Sec) @@ -978,9 +1012,7 @@ static const EnumEntry<unsigned> ElfSymbolTypes[] = { {"GNU_IFunc", "IFUNC", ELF::STT_GNU_IFUNC}}; static const EnumEntry<unsigned> AMDGPUSymbolTypes[] = { - { "AMDGPU_HSA_KERNEL", ELF::STT_AMDGPU_HSA_KERNEL }, - { "AMDGPU_HSA_INDIRECT_FUNCTION", ELF::STT_AMDGPU_HSA_INDIRECT_FUNCTION }, - { "AMDGPU_HSA_METADATA", ELF::STT_AMDGPU_HSA_METADATA } + { "AMDGPU_HSA_KERNEL", ELF::STT_AMDGPU_HSA_KERNEL } }; static const char *getGroupType(uint32_t Flag) { @@ -1012,13 +1044,6 @@ static const EnumEntry<unsigned> ElfXCoreSectionFlags[] = { LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_DP_SECTION) }; -static const EnumEntry<unsigned> ElfAMDGPUSectionFlags[] = { - LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_GLOBAL), - LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_READONLY), - LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_CODE), - LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_AGENT) -}; - static const EnumEntry<unsigned> ElfARMSectionFlags[] = { LLVM_READOBJ_ENUM_ENT(ELF, SHF_ARM_PURECODE) }; @@ -1077,13 +1102,6 @@ static const char *getElfSegmentType(unsigned Arch, unsigned Type) { // Check potentially overlapped processor-specific // program header type. switch (Arch) { - case ELF::EM_AMDGPU: - switch (Type) { - LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_GLOBAL_PROGRAM); - LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_GLOBAL_AGENT); - LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_READONLY_AGENT); - LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_CODE_AGENT); - } case ELF::EM_ARM: switch (Type) { LLVM_READOBJ_ENUM_CASE(ELF, PT_ARM_EXIDX); @@ -1139,14 +1157,6 @@ static std::string getElfPtType(unsigned Arch, unsigned Type) { default: // All machine specific PT_* types switch (Arch) { - case ELF::EM_AMDGPU: - switch (Type) { - LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_GLOBAL_PROGRAM); - LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_GLOBAL_AGENT); - LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_READONLY_AGENT); - LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_CODE_AGENT); - } - return ""; case ELF::EM_ARM: if (Type == ELF::PT_ARM_EXIDX) return "EXIDX"; @@ -1262,7 +1272,6 @@ static const char *getElfMipsOptionsOdkType(unsigned Odk) { template <typename ELFT> ELFDumper<ELFT>::ELFDumper(const ELFFile<ELFT> *Obj, ScopedPrinter &Writer) : ObjDumper(Writer), Obj(Obj) { - SmallVector<const Elf_Phdr *, 4> LoadSegments; for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) { if (Phdr.p_type == ELF::PT_DYNAMIC) { @@ -1591,8 +1600,8 @@ static const EnumEntry<unsigned> ElfDynamicDTMipsFlags[] = { template <typename T, typename TFlag> void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) { - typedef EnumEntry<TFlag> FlagEntry; - typedef SmallVector<FlagEntry, 10> FlagVector; + using FlagEntry = EnumEntry<TFlag>; + using FlagVector = SmallVector<FlagEntry, 10>; FlagVector SetFlags; for (const auto &Flag : Flags) { @@ -1711,6 +1720,7 @@ void ELFDumper<ELFT>::printUnwindInfo() { } namespace { + template <> void ELFDumper<ELFType<support::little, false>>::printUnwindInfo() { const unsigned Machine = Obj->getHeader()->e_machine; if (Machine == EM_ARM) { @@ -1720,7 +1730,8 @@ template <> void ELFDumper<ELFType<support::little, false>>::printUnwindInfo() { } W.startLine() << "UnwindInfo not implemented.\n"; } -} + +} // end anonymous namespace template<class ELFT> void ELFDumper<ELFT>::printDynamicTable() { @@ -1766,7 +1777,7 @@ template<class ELFT> void ELFDumper<ELFT>::printNeededLibraries() { ListScope D(W, "NeededLibraries"); - typedef std::vector<StringRef> LibsTy; + using LibsTy = std::vector<StringRef>; LibsTy Libs; for (const auto &Entry : dynamic_table()) @@ -1820,6 +1831,7 @@ void ELFDumper<ELFT>::printAttributes() { } namespace { + template <> void ELFDumper<ELFType<support::little, false>>::printAttributes() { if (Obj->getHeader()->e_machine != EM_ARM) { W.startLine() << "Attributes not implemented.\n"; @@ -1845,13 +1857,12 @@ template <> void ELFDumper<ELFType<support::little, false>>::printAttributes() { ARMAttributeParser(&W).Parse(Contents, true); } } -} -namespace { template <class ELFT> class MipsGOTParser { public: TYPEDEF_ELF_TYPES(ELFT) - typedef typename ELFO::Elf_Addr GOTEntry; + using GOTEntry = typename ELFO::Elf_Addr; + MipsGOTParser(ELFDumper<ELFT> *Dumper, const ELFO *Obj, Elf_Dyn_Range DynTable, ScopedPrinter &W); @@ -1862,11 +1873,11 @@ private: ELFDumper<ELFT> *Dumper; const ELFO *Obj; ScopedPrinter &W; - llvm::Optional<uint64_t> DtPltGot; - llvm::Optional<uint64_t> DtLocalGotNum; - llvm::Optional<uint64_t> DtGotSym; - llvm::Optional<uint64_t> DtMipsPltGot; - llvm::Optional<uint64_t> DtJmpRel; + Optional<uint64_t> DtPltGot; + Optional<uint64_t> DtLocalGotNum; + Optional<uint64_t> DtGotSym; + Optional<uint64_t> DtMipsPltGot; + Optional<uint64_t> DtJmpRel; std::size_t getGOTTotal(ArrayRef<uint8_t> GOT) const; const GOTEntry *makeGOTIter(ArrayRef<uint8_t> GOT, std::size_t EntryNum); @@ -1882,7 +1893,8 @@ private: const GOTEntry *It, StringRef StrTable, const Elf_Sym *Sym); }; -} + +} // end anonymous namespace template <class ELFT> MipsGOTParser<ELFT>::MipsGOTParser(ELFDumper<ELFT> *Dumper, const ELFO *Obj, @@ -2353,8 +2365,8 @@ template <class ELFT> void ELFDumper<ELFT>::printStackMap() const { ArrayRef<uint8_t> StackMapContentsArray = unwrapOrError(Obj->getSectionContents(StackMapSection)); - prettyPrintStackMap(llvm::outs(), StackMapV2Parser<ELFT::TargetEndianness>( - StackMapContentsArray)); + prettyPrintStackMap(outs(), StackMapV2Parser<ELFT::TargetEndianness>( + StackMapContentsArray)); } template <class ELFT> void ELFDumper<ELFT>::printGroupSections() { @@ -2455,7 +2467,7 @@ template <class ELFT> void GNUStyle<ELFT>::printGroupSections(const ELFO *Obj) { template <class ELFT> void GNUStyle<ELFT>::printRelocation(const ELFO *Obj, const Elf_Shdr *SymTab, const Elf_Rela &R, bool IsRela) { - std::string Offset, Info, Addend = "", Value; + std::string Offset, Info, Addend, Value; SmallString<32> RelocName; StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*SymTab)); StringRef TargetName; @@ -2549,6 +2561,7 @@ template <class ELFT> void GNUStyle<ELFT>::printRelocations(const ELFO *Obj) { std::string getSectionTypeString(unsigned Arch, unsigned Type) { using namespace ELF; + switch (Arch) { case EM_ARM: switch (Type) { @@ -2715,7 +2728,7 @@ template <class ELFT> void GNUStyle<ELFT>::printSections(const ELFO *Obj) { template <class ELFT> void GNUStyle<ELFT>::printSymtabMessage(const ELFO *Obj, StringRef Name, size_t Entries) { - if (Name.size()) + if (!Name.empty()) OS << "\nSymbol table '" << Name << "' contains " << Entries << " entries:\n"; else @@ -2870,7 +2883,7 @@ template <class ELFT> void GNUStyle<ELFT>::printSymbols(const ELFO *Obj) { template <class ELFT> void GNUStyle<ELFT>::printDynamicSymbols(const ELFO *Obj) { - if (this->dumper()->getDynamicStringTable().size() == 0) + if (this->dumper()->getDynamicStringTable().empty()) return; auto StringTable = this->dumper()->getDynamicStringTable(); auto DynSyms = this->dumper()->dynamic_symbols(); @@ -3084,19 +3097,19 @@ void GNUStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela R, Obj->getRelocationTypeName(R.getType(Obj->isMips64EL()), RelocName); SymbolName = unwrapOrError(Sym->getName(this->dumper()->getDynamicStringTable())); - std::string Addend = "", Info, Offset, Value; + std::string Addend, Info, Offset, Value; Offset = to_string(format_hex_no_prefix(R.r_offset, Width)); Info = to_string(format_hex_no_prefix(R.r_info, Width)); Value = to_string(format_hex_no_prefix(Sym->getValue(), Width)); int64_t RelAddend = R.r_addend; - if (SymbolName.size() && IsRela) { + if (!SymbolName.empty() && IsRela) { if (R.r_addend < 0) Addend = " - "; else Addend = " + "; } - if (!SymbolName.size() && Sym->getValue() == 0) + if (SymbolName.empty() && Sym->getValue() == 0) Value = ""; if (IsRela) @@ -3231,7 +3244,7 @@ void GNUStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) { size_t MaxChain = 1; size_t CumulativeNonZero = 0; - if (Chains.size() == 0 || NBucket == 0) + if (Chains.empty() || NBucket == 0) return; std::vector<size_t> ChainLen(NBucket, 0); @@ -3562,13 +3575,13 @@ void LLVMStyle<ELFT>::printRelocation(const ELFO *Obj, Elf_Rela Rel, DictScope Group(W, "Relocation"); W.printHex("Offset", Rel.r_offset); W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL())); - W.printNumber("Symbol", TargetName.size() > 0 ? TargetName : "-", + W.printNumber("Symbol", !TargetName.empty() ? TargetName : "-", Rel.getSymbol(Obj->isMips64EL())); W.printHex("Addend", Rel.r_addend); } else { raw_ostream &OS = W.startLine(); OS << W.hex(Rel.r_offset) << " " << RelocName << " " - << (TargetName.size() > 0 ? TargetName : "-") << " " + << (!TargetName.empty() ? TargetName : "-") << " " << W.hex(Rel.r_addend) << "\n"; } } @@ -3592,10 +3605,6 @@ template <class ELFT> void LLVMStyle<ELFT>::printSections(const ELFO *Obj) { std::vector<EnumEntry<unsigned>> SectionFlags(std::begin(ElfSectionFlags), std::end(ElfSectionFlags)); switch (Obj->getHeader()->e_machine) { - case EM_AMDGPU: - SectionFlags.insert(SectionFlags.end(), std::begin(ElfAMDGPUSectionFlags), - std::end(ElfAMDGPUSectionFlags)); - break; case EM_ARM: SectionFlags.insert(SectionFlags.end(), std::begin(ElfARMSectionFlags), std::end(ElfARMSectionFlags)); @@ -3763,12 +3772,12 @@ void LLVMStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel) { DictScope Group(W, "Relocation"); W.printHex("Offset", Rel.r_offset); W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL())); - W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-"); + W.printString("Symbol", !SymbolName.empty() ? SymbolName : "-"); W.printHex("Addend", Rel.r_addend); } else { raw_ostream &OS = W.startLine(); OS << W.hex(Rel.r_offset) << " " << RelocName << " " - << (SymbolName.size() > 0 ? SymbolName : "-") << " " + << (!SymbolName.empty() ? SymbolName : "-") << " " << W.hex(Rel.r_addend) << "\n"; } } @@ -3801,4 +3810,3 @@ template <class ELFT> void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) { W.startLine() << "printNotes not implemented!\n"; } - diff --git a/tools/llvm-readobj/LLVMBuild.txt b/tools/llvm-readobj/LLVMBuild.txt index c0ed38e18d0c..87ede1008cb3 100644 --- a/tools/llvm-readobj/LLVMBuild.txt +++ b/tools/llvm-readobj/LLVMBuild.txt @@ -19,4 +19,4 @@ type = Tool name = llvm-readobj parent = Tools -required_libraries = all-targets BitReader Object DebugInfoCodeView DebugInfoPDB DebugInfoMSF +required_libraries = all-targets BitReader Object BinaryFormat DebugInfoCodeView DebugInfoPDB DebugInfoMSF diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp index 74b7735f8cd1..f1cdc5fa1056 100644 --- a/tools/llvm-stress/llvm-stress.cpp +++ b/tools/llvm-stress/llvm-stress.cpp @@ -382,6 +382,7 @@ struct ConstModifier: public Modifier { switch (Ran->Rand() % 2) { case 0: if (Ty->getScalarType()->isIntegerTy()) return PT->push_back(ConstantVector::getAllOnesValue(Ty)); + llvm_unreachable("Unexpected state"); case 1: if (Ty->getScalarType()->isIntegerTy()) return PT->push_back(ConstantVector::getNullValue(Ty)); } @@ -407,9 +408,11 @@ struct ConstModifier: public Modifier { case 0: if (Ty->isIntegerTy()) return PT->push_back(ConstantInt::get(Ty, APInt::getAllOnesValue(Ty->getPrimitiveSizeInBits()))); + llvm_unreachable("Unexpected state"); case 1: if (Ty->isIntegerTy()) return PT->push_back(ConstantInt::get(Ty, APInt::getNullValue(Ty->getPrimitiveSizeInBits()))); + llvm_unreachable("Unexpected state"); case 2: case 3: case 4: case 5: case 6: if (Ty->isIntegerTy()) PT->push_back(ConstantInt::get(Ty, Ran->Rand())); diff --git a/tools/llvm-xray/xray-extract.cc b/tools/llvm-xray/xray-extract.cc index d7015a05b0f2..6b72b81ab814 100644 --- a/tools/llvm-xray/xray-extract.cc +++ b/tools/llvm-xray/xray-extract.cc @@ -18,11 +18,11 @@ #include "func-id-helper.h" #include "xray-registry.h" +#include "llvm/BinaryFormat/ELF.h" #include "llvm/Object/ELF.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/DataExtractor.h" -#include "llvm/Support/ELF.h" #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" diff --git a/tools/obj2yaml/dwarf2yaml.cpp b/tools/obj2yaml/dwarf2yaml.cpp index d41b44c06810..d97eda30c039 100644 --- a/tools/obj2yaml/dwarf2yaml.cpp +++ b/tools/obj2yaml/dwarf2yaml.cpp @@ -203,6 +203,7 @@ void dumpDebugInfo(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) { case dwarf::DW_FORM_line_strp: case dwarf::DW_FORM_strp_sup: case dwarf::DW_FORM_GNU_str_index: + case dwarf::DW_FORM_strx: if (auto Val = FormValue.getValue().getAsCStringOffset()) NewValue.Value = Val.getValue(); break; diff --git a/tools/obj2yaml/macho2yaml.cpp b/tools/obj2yaml/macho2yaml.cpp index f7b6c4748d5e..a1d107dc5afb 100644 --- a/tools/obj2yaml/macho2yaml.cpp +++ b/tools/obj2yaml/macho2yaml.cpp @@ -216,7 +216,7 @@ void MachODumper::dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y) { MachO::swapStruct(LC.Data.load_command_data); EndPtr = processLoadCommandData<MachO::load_command>(LC, LoadCmd); break; -#include "llvm/Support/MachO.def" +#include "llvm/BinaryFormat/MachO.def" } auto RemainingBytes = LoadCmd.C.cmdsize - (EndPtr - LoadCmd.Ptr); if (!std::all_of(EndPtr, &EndPtr[RemainingBytes], diff --git a/tools/yaml2obj/yaml2elf.cpp b/tools/yaml2obj/yaml2elf.cpp index 8fd2bfd16726..c89f768ed6ff 100644 --- a/tools/yaml2obj/yaml2elf.cpp +++ b/tools/yaml2obj/yaml2elf.cpp @@ -14,10 +14,10 @@ #include "yaml2obj.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/BinaryFormat/ELF.h" #include "llvm/MC/StringTableBuilder.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/ObjectYAML/ELFYAML.h" -#include "llvm/Support/ELF.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" diff --git a/tools/yaml2obj/yaml2macho.cpp b/tools/yaml2obj/yaml2macho.cpp index 92b736e5298e..34b6ac2029fc 100644 --- a/tools/yaml2obj/yaml2macho.cpp +++ b/tools/yaml2obj/yaml2macho.cpp @@ -13,11 +13,11 @@ //===----------------------------------------------------------------------===// #include "yaml2obj.h" -#include "llvm/ObjectYAML/ObjectYAML.h" +#include "llvm/BinaryFormat/MachO.h" #include "llvm/ObjectYAML/DWARFEmitter.h" +#include "llvm/ObjectYAML/ObjectYAML.h" #include "llvm/Support/Error.h" #include "llvm/Support/LEB128.h" -#include "llvm/Support/MachO.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" @@ -239,7 +239,7 @@ Error MachOWriter::writeLoadCommands(raw_ostream &OS) { BytesWritten += writeLoadCommandData<MachO::load_command>(LC, OS, Obj.IsLittleEndian); break; -#include "llvm/Support/MachO.def" +#include "llvm/BinaryFormat/MachO.def" } if (LC.PayloadBytes.size() > 0) { |