[lit] Remove LitTestCase
[llvm-complete.git] / tools / llvm-dwarfdump / llvm-dwarfdump.cpp
blobde2221b1392421aa4119cb8ac678a2cd677d7432
1 //===-- llvm-dwarfdump.cpp - Debug info dumping utility for llvm ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This program is a utility that works like "dwarfdump".
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ADT/STLExtras.h"
14 #include "llvm/ADT/StringSet.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/DebugInfo/DIContext.h"
17 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
18 #include "llvm/Object/Archive.h"
19 #include "llvm/Object/MachOUniversal.h"
20 #include "llvm/Object/ObjectFile.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/Debug.h"
23 #include "llvm/Support/Format.h"
24 #include "llvm/Support/InitLLVM.h"
25 #include "llvm/Support/MemoryBuffer.h"
26 #include "llvm/Support/Path.h"
27 #include "llvm/Support/Regex.h"
28 #include "llvm/Support/TargetSelect.h"
29 #include "llvm/Support/ToolOutputFile.h"
30 #include "llvm/Support/WithColor.h"
31 #include "llvm/Support/raw_ostream.h"
33 using namespace llvm;
34 using namespace object;
36 /// Parser for options that take an optional offest argument.
37 /// @{
38 struct OffsetOption {
39 uint64_t Val = 0;
40 bool HasValue = false;
41 bool IsRequested = false;
44 namespace llvm {
45 namespace cl {
46 template <>
47 class parser<OffsetOption> final : public basic_parser<OffsetOption> {
48 public:
49 parser(Option &O) : basic_parser(O) {}
51 /// Return true on error.
52 bool parse(Option &O, StringRef ArgName, StringRef Arg, OffsetOption &Val) {
53 if (Arg == "") {
54 Val.Val = 0;
55 Val.HasValue = false;
56 Val.IsRequested = true;
57 return false;
59 if (Arg.getAsInteger(0, Val.Val))
60 return O.error("'" + Arg + "' value invalid for integer argument!");
61 Val.HasValue = true;
62 Val.IsRequested = true;
63 return false;
66 enum ValueExpected getValueExpectedFlagDefault() const {
67 return ValueOptional;
70 void printOptionInfo(const Option &O, size_t GlobalWidth) const {
71 outs() << " -" << O.ArgStr;
72 Option::printHelpStr(O.HelpStr, GlobalWidth, getOptionWidth(O));
75 void printOptionDiff(const Option &O, OffsetOption V, OptVal Default,
76 size_t GlobalWidth) const {
77 printOptionName(O, GlobalWidth);
78 outs() << "[=offset]";
81 // An out-of-line virtual method to provide a 'home' for this class.
82 void anchor() override {};
84 } // cl
85 } // llvm
87 /// @}
88 /// Command line options.
89 /// @{
91 namespace {
92 using namespace cl;
94 OptionCategory DwarfDumpCategory("Specific Options");
95 static opt<bool> Help("h", desc("Alias for -help"), Hidden,
96 cat(DwarfDumpCategory));
97 static list<std::string>
98 InputFilenames(Positional, desc("<input object files or .dSYM bundles>"),
99 ZeroOrMore, cat(DwarfDumpCategory));
101 cl::OptionCategory SectionCategory("Section-specific Dump Options",
102 "These control which sections are dumped. "
103 "Where applicable these parameters take an "
104 "optional =<offset> argument to dump only "
105 "the entry at the specified offset.");
107 static opt<bool> DumpAll("all", desc("Dump all debug info sections"),
108 cat(SectionCategory));
109 static alias DumpAllAlias("a", desc("Alias for -all"), aliasopt(DumpAll));
111 // Options for dumping specific sections.
112 static unsigned DumpType = DIDT_Null;
113 static std::array<llvm::Optional<uint64_t>, (unsigned)DIDT_ID_Count>
114 DumpOffsets;
115 #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
116 static opt<OffsetOption> Dump##ENUM_NAME( \
117 CMDLINE_NAME, desc("Dump the " ELF_NAME " section"), \
118 cat(SectionCategory));
119 #include "llvm/BinaryFormat/Dwarf.def"
120 #undef HANDLE_DWARF_SECTION
122 static alias DumpDebugFrameAlias("eh-frame", desc("Alias for -debug-frame"),
123 NotHidden, cat(SectionCategory),
124 aliasopt(DumpDebugFrame));
125 static list<std::string>
126 ArchFilters("arch",
127 desc("Dump debug information for the specified CPU "
128 "architecture only. Architectures may be specified by "
129 "name or by number. This option can be specified "
130 "multiple times, once for each desired architecture."),
131 cat(DwarfDumpCategory));
132 static opt<bool>
133 Diff("diff",
134 desc("Emit diff-friendly output by omitting offsets and addresses."),
135 cat(DwarfDumpCategory));
136 static list<std::string>
137 Find("find",
138 desc("Search for the exact match for <name> in the accelerator tables "
139 "and print the matching debug information entries. When no "
140 "accelerator tables are available, the slower but more complete "
141 "-name option can be used instead."),
142 value_desc("name"), cat(DwarfDumpCategory));
143 static alias FindAlias("f", desc("Alias for -find."), aliasopt(Find));
144 static opt<bool>
145 IgnoreCase("ignore-case",
146 desc("Ignore case distinctions in when searching by name."),
147 value_desc("i"), cat(DwarfDumpCategory));
148 static alias IgnoreCaseAlias("i", desc("Alias for -ignore-case."),
149 aliasopt(IgnoreCase));
150 static list<std::string> Name(
151 "name",
152 desc("Find and print all debug info entries whose name (DW_AT_name "
153 "attribute) matches the exact text in <pattern>. When used with the "
154 "the -regex option <pattern> is interpreted as a regular expression."),
155 value_desc("pattern"), cat(DwarfDumpCategory));
156 static alias NameAlias("n", desc("Alias for -name"), aliasopt(Name));
157 static opt<unsigned long long> Lookup("lookup",
158 desc("Lookup <address> in the debug information and print out any "
159 "available file, function, block and line table details."),
160 value_desc("address"), cat(DwarfDumpCategory));
161 static opt<std::string>
162 OutputFilename("out-file", cl::init(""),
163 cl::desc("Redirect output to the specified file."),
164 cl::value_desc("filename"));
165 static alias OutputFilenameAlias("o", desc("Alias for -out-file."),
166 aliasopt(OutputFilename),
167 cat(DwarfDumpCategory));
168 static opt<bool>
169 UseRegex("regex",
170 desc("Treat any <pattern> strings as regular expressions when "
171 "searching instead of just as an exact string match."),
172 cat(DwarfDumpCategory));
173 static alias RegexAlias("x", desc("Alias for -regex"), aliasopt(UseRegex));
174 static opt<bool>
175 ShowChildren("show-children",
176 desc("Show a debug info entry's children when selectively "
177 "printing with the =<offset> option."),
178 cat(DwarfDumpCategory));
179 static alias ShowChildrenAlias("c", desc("Alias for -show-children."),
180 aliasopt(ShowChildren));
181 static opt<bool>
182 ShowParents("show-parents",
183 desc("Show a debug info entry's parents when selectively "
184 "printing with the =<offset> option."),
185 cat(DwarfDumpCategory));
186 static alias ShowParentsAlias("p", desc("Alias for -show-parents."),
187 aliasopt(ShowParents));
188 static opt<bool>
189 ShowForm("show-form",
190 desc("Show DWARF form types after the DWARF attribute types."),
191 cat(DwarfDumpCategory));
192 static alias ShowFormAlias("F", desc("Alias for -show-form."),
193 aliasopt(ShowForm), cat(DwarfDumpCategory));
194 static opt<unsigned> RecurseDepth(
195 "recurse-depth",
196 desc("Only recurse to a depth of N when displaying debug info entries."),
197 cat(DwarfDumpCategory), init(-1U), value_desc("N"));
198 static alias RecurseDepthAlias("r", desc("Alias for -recurse-depth."),
199 aliasopt(RecurseDepth));
201 static opt<bool>
202 SummarizeTypes("summarize-types",
203 desc("Abbreviate the description of type unit entries."),
204 cat(DwarfDumpCategory));
205 static cl::opt<bool>
206 Statistics("statistics",
207 cl::desc("Emit JSON-formatted debug info quality metrics."),
208 cat(DwarfDumpCategory));
209 static opt<bool> Verify("verify", desc("Verify the DWARF debug info."),
210 cat(DwarfDumpCategory));
211 static opt<bool> Quiet("quiet", desc("Use with -verify to not emit to STDOUT."),
212 cat(DwarfDumpCategory));
213 static opt<bool> DumpUUID("uuid", desc("Show the UUID for each architecture."),
214 cat(DwarfDumpCategory));
215 static alias DumpUUIDAlias("u", desc("Alias for -uuid."), aliasopt(DumpUUID));
216 static opt<bool> Verbose("verbose",
217 desc("Print more low-level encoding details."),
218 cat(DwarfDumpCategory));
219 static alias VerboseAlias("v", desc("Alias for -verbose."), aliasopt(Verbose),
220 cat(DwarfDumpCategory));
221 } // namespace
222 /// @}
223 //===----------------------------------------------------------------------===//
225 static void error(StringRef Prefix, std::error_code EC) {
226 if (!EC)
227 return;
228 WithColor::error() << Prefix << ": " << EC.message() << "\n";
229 exit(1);
232 static DIDumpOptions getDumpOpts() {
233 DIDumpOptions DumpOpts;
234 DumpOpts.DumpType = DumpType;
235 DumpOpts.RecurseDepth = RecurseDepth;
236 DumpOpts.ShowAddresses = !Diff;
237 DumpOpts.ShowChildren = ShowChildren;
238 DumpOpts.ShowParents = ShowParents;
239 DumpOpts.ShowForm = ShowForm;
240 DumpOpts.SummarizeTypes = SummarizeTypes;
241 DumpOpts.Verbose = Verbose;
242 // In -verify mode, print DIEs without children in error messages.
243 if (Verify)
244 return DumpOpts.noImplicitRecursion();
245 return DumpOpts;
248 static uint32_t getCPUType(MachOObjectFile &MachO) {
249 if (MachO.is64Bit())
250 return MachO.getHeader64().cputype;
251 else
252 return MachO.getHeader().cputype;
255 /// Return true if the object file has not been filtered by an --arch option.
256 static bool filterArch(ObjectFile &Obj) {
257 if (ArchFilters.empty())
258 return true;
260 if (auto *MachO = dyn_cast<MachOObjectFile>(&Obj)) {
261 std::string ObjArch =
262 Triple::getArchTypeName(MachO->getArchTriple().getArch());
264 for (auto Arch : ArchFilters) {
265 // Match name.
266 if (Arch == ObjArch)
267 return true;
269 // Match architecture number.
270 unsigned Value;
271 if (!StringRef(Arch).getAsInteger(0, Value))
272 if (Value == getCPUType(*MachO))
273 return true;
276 return false;
279 using HandlerFn = std::function<bool(ObjectFile &, DWARFContext &DICtx, Twine,
280 raw_ostream &)>;
282 /// Print only DIEs that have a certain name.
283 static bool filterByName(const StringSet<> &Names, DWARFDie Die,
284 StringRef NameRef, raw_ostream &OS) {
285 std::string Name =
286 (IgnoreCase && !UseRegex) ? NameRef.lower() : NameRef.str();
287 if (UseRegex) {
288 // Match regular expression.
289 for (auto Pattern : Names.keys()) {
290 Regex RE(Pattern, IgnoreCase ? Regex::IgnoreCase : Regex::NoFlags);
291 std::string Error;
292 if (!RE.isValid(Error)) {
293 errs() << "error in regular expression: " << Error << "\n";
294 exit(1);
296 if (RE.match(Name)) {
297 Die.dump(OS, 0, getDumpOpts());
298 return true;
301 } else if (Names.count(Name)) {
302 // Match full text.
303 Die.dump(OS, 0, getDumpOpts());
304 return true;
306 return false;
309 /// Print only DIEs that have a certain name.
310 static void filterByName(const StringSet<> &Names,
311 DWARFContext::unit_iterator_range CUs,
312 raw_ostream &OS) {
313 for (const auto &CU : CUs)
314 for (const auto &Entry : CU->dies()) {
315 DWARFDie Die = {CU.get(), &Entry};
316 if (const char *Name = Die.getName(DINameKind::ShortName))
317 if (filterByName(Names, Die, Name, OS))
318 continue;
319 if (const char *Name = Die.getName(DINameKind::LinkageName))
320 filterByName(Names, Die, Name, OS);
324 static void getDies(DWARFContext &DICtx, const AppleAcceleratorTable &Accel,
325 StringRef Name, SmallVectorImpl<DWARFDie> &Dies) {
326 for (const auto &Entry : Accel.equal_range(Name)) {
327 if (llvm::Optional<uint64_t> Off = Entry.getDIESectionOffset()) {
328 if (DWARFDie Die = DICtx.getDIEForOffset(*Off))
329 Dies.push_back(Die);
334 static DWARFDie toDie(const DWARFDebugNames::Entry &Entry,
335 DWARFContext &DICtx) {
336 llvm::Optional<uint64_t> CUOff = Entry.getCUOffset();
337 llvm::Optional<uint64_t> Off = Entry.getDIEUnitOffset();
338 if (!CUOff || !Off)
339 return DWARFDie();
341 DWARFCompileUnit *CU = DICtx.getCompileUnitForOffset(*CUOff);
342 if (!CU)
343 return DWARFDie();
345 if (llvm::Optional<uint64_t> DWOId = CU->getDWOId()) {
346 // This is a skeleton unit. Look up the DIE in the DWO unit.
347 CU = DICtx.getDWOCompileUnitForHash(*DWOId);
348 if (!CU)
349 return DWARFDie();
352 return CU->getDIEForOffset(CU->getOffset() + *Off);
355 static void getDies(DWARFContext &DICtx, const DWARFDebugNames &Accel,
356 StringRef Name, SmallVectorImpl<DWARFDie> &Dies) {
357 for (const auto &Entry : Accel.equal_range(Name)) {
358 if (DWARFDie Die = toDie(Entry, DICtx))
359 Dies.push_back(Die);
363 /// Print only DIEs that have a certain name.
364 static void filterByAccelName(ArrayRef<std::string> Names, DWARFContext &DICtx,
365 raw_ostream &OS) {
366 SmallVector<DWARFDie, 4> Dies;
367 for (const auto &Name : Names) {
368 getDies(DICtx, DICtx.getAppleNames(), Name, Dies);
369 getDies(DICtx, DICtx.getAppleTypes(), Name, Dies);
370 getDies(DICtx, DICtx.getAppleNamespaces(), Name, Dies);
371 getDies(DICtx, DICtx.getDebugNames(), Name, Dies);
373 llvm::sort(Dies);
374 Dies.erase(std::unique(Dies.begin(), Dies.end()), Dies.end());
376 for (DWARFDie Die : Dies)
377 Die.dump(OS, 0, getDumpOpts());
380 /// Handle the --lookup option and dump the DIEs and line info for the given
381 /// address.
382 static bool lookup(DWARFContext &DICtx, uint64_t Address, raw_ostream &OS) {
383 auto DIEsForAddr = DICtx.getDIEsForAddress(Lookup);
385 if (!DIEsForAddr)
386 return false;
388 DIDumpOptions DumpOpts = getDumpOpts();
389 DumpOpts.RecurseDepth = 0;
390 DIEsForAddr.CompileUnit->dump(OS, DumpOpts);
391 if (DIEsForAddr.FunctionDIE) {
392 DIEsForAddr.FunctionDIE.dump(OS, 2, DumpOpts);
393 if (DIEsForAddr.BlockDIE)
394 DIEsForAddr.BlockDIE.dump(OS, 4, DumpOpts);
397 if (DILineInfo LineInfo = DICtx.getLineInfoForAddress(Lookup))
398 LineInfo.dump(OS);
400 return true;
403 bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
404 Twine Filename, raw_ostream &OS);
406 static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
407 raw_ostream &OS) {
408 logAllUnhandledErrors(DICtx.loadRegisterInfo(Obj), errs(),
409 Filename.str() + ": ");
410 // The UUID dump already contains all the same information.
411 if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
412 OS << Filename << ":\tfile format " << Obj.getFileFormatName() << '\n';
414 // Handle the --lookup option.
415 if (Lookup)
416 return lookup(DICtx, Lookup, OS);
418 // Handle the --name option.
419 if (!Name.empty()) {
420 StringSet<> Names;
421 for (auto name : Name)
422 Names.insert((IgnoreCase && !UseRegex) ? StringRef(name).lower() : name);
424 filterByName(Names, DICtx.normal_units(), OS);
425 filterByName(Names, DICtx.dwo_units(), OS);
426 return true;
429 // Handle the --find option and lower it to --debug-info=<offset>.
430 if (!Find.empty()) {
431 filterByAccelName(Find, DICtx, OS);
432 return true;
435 // Dump the complete DWARF structure.
436 DICtx.dump(OS, getDumpOpts(), DumpOffsets);
437 return true;
440 static bool verifyObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
441 Twine Filename, raw_ostream &OS) {
442 // Verify the DWARF and exit with non-zero exit status if verification
443 // fails.
444 raw_ostream &stream = Quiet ? nulls() : OS;
445 stream << "Verifying " << Filename.str() << ":\tfile format "
446 << Obj.getFileFormatName() << "\n";
447 bool Result = DICtx.verify(stream, getDumpOpts());
448 if (Result)
449 stream << "No errors.\n";
450 else
451 stream << "Errors detected.\n";
452 return Result;
455 static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
456 HandlerFn HandleObj, raw_ostream &OS);
458 static bool handleArchive(StringRef Filename, Archive &Arch,
459 HandlerFn HandleObj, raw_ostream &OS) {
460 bool Result = true;
461 Error Err = Error::success();
462 for (auto Child : Arch.children(Err)) {
463 auto BuffOrErr = Child.getMemoryBufferRef();
464 error(Filename, errorToErrorCode(BuffOrErr.takeError()));
465 auto NameOrErr = Child.getName();
466 error(Filename, errorToErrorCode(NameOrErr.takeError()));
467 std::string Name = (Filename + "(" + NameOrErr.get() + ")").str();
468 Result &= handleBuffer(Name, BuffOrErr.get(), HandleObj, OS);
470 error(Filename, errorToErrorCode(std::move(Err)));
472 return Result;
475 static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
476 HandlerFn HandleObj, raw_ostream &OS) {
477 Expected<std::unique_ptr<Binary>> BinOrErr = object::createBinary(Buffer);
478 error(Filename, errorToErrorCode(BinOrErr.takeError()));
480 bool Result = true;
481 if (auto *Obj = dyn_cast<ObjectFile>(BinOrErr->get())) {
482 if (filterArch(*Obj)) {
483 std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*Obj);
484 Result = HandleObj(*Obj, *DICtx, Filename, OS);
487 else if (auto *Fat = dyn_cast<MachOUniversalBinary>(BinOrErr->get()))
488 for (auto &ObjForArch : Fat->objects()) {
489 std::string ObjName =
490 (Filename + "(" + ObjForArch.getArchFlagName() + ")").str();
491 if (auto MachOOrErr = ObjForArch.getAsObjectFile()) {
492 auto &Obj = **MachOOrErr;
493 if (filterArch(Obj)) {
494 std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(Obj);
495 Result &= HandleObj(Obj, *DICtx, ObjName, OS);
497 continue;
498 } else
499 consumeError(MachOOrErr.takeError());
500 if (auto ArchiveOrErr = ObjForArch.getAsArchive()) {
501 error(ObjName, errorToErrorCode(ArchiveOrErr.takeError()));
502 Result &= handleArchive(ObjName, *ArchiveOrErr.get(), HandleObj, OS);
503 continue;
504 } else
505 consumeError(ArchiveOrErr.takeError());
507 else if (auto *Arch = dyn_cast<Archive>(BinOrErr->get()))
508 Result = handleArchive(Filename, *Arch, HandleObj, OS);
509 return Result;
512 static bool handleFile(StringRef Filename, HandlerFn HandleObj,
513 raw_ostream &OS) {
514 ErrorOr<std::unique_ptr<MemoryBuffer>> BuffOrErr =
515 MemoryBuffer::getFileOrSTDIN(Filename);
516 error(Filename, BuffOrErr.getError());
517 std::unique_ptr<MemoryBuffer> Buffer = std::move(BuffOrErr.get());
518 return handleBuffer(Filename, *Buffer, HandleObj, OS);
521 /// If the input path is a .dSYM bundle (as created by the dsymutil tool),
522 /// replace it with individual entries for each of the object files inside the
523 /// bundle otherwise return the input path.
524 static std::vector<std::string> expandBundle(const std::string &InputPath) {
525 std::vector<std::string> BundlePaths;
526 SmallString<256> BundlePath(InputPath);
527 // Normalize input path. This is necessary to accept `bundle.dSYM/`.
528 sys::path::remove_dots(BundlePath);
529 // Manually open up the bundle to avoid introducing additional dependencies.
530 if (sys::fs::is_directory(BundlePath) &&
531 sys::path::extension(BundlePath) == ".dSYM") {
532 std::error_code EC;
533 sys::path::append(BundlePath, "Contents", "Resources", "DWARF");
534 for (sys::fs::directory_iterator Dir(BundlePath, EC), DirEnd;
535 Dir != DirEnd && !EC; Dir.increment(EC)) {
536 const std::string &Path = Dir->path();
537 sys::fs::file_status Status;
538 EC = sys::fs::status(Path, Status);
539 error(Path, EC);
540 switch (Status.type()) {
541 case sys::fs::file_type::regular_file:
542 case sys::fs::file_type::symlink_file:
543 case sys::fs::file_type::type_unknown:
544 BundlePaths.push_back(Path);
545 break;
546 default: /*ignore*/;
549 error(BundlePath, EC);
551 if (!BundlePaths.size())
552 BundlePaths.push_back(InputPath);
553 return BundlePaths;
556 int main(int argc, char **argv) {
557 InitLLVM X(argc, argv);
559 llvm::InitializeAllTargetInfos();
560 llvm::InitializeAllTargetMCs();
562 HideUnrelatedOptions({&DwarfDumpCategory, &SectionCategory, &ColorCategory});
563 cl::ParseCommandLineOptions(
564 argc, argv,
565 "pretty-print DWARF debug information in object files"
566 " and debug info archives.\n");
568 if (Help) {
569 PrintHelpMessage(/*Hidden =*/false, /*Categorized =*/true);
570 return 0;
573 // FIXME: Audit interactions between these two options and make them
574 // compatible.
575 if (Diff && Verbose) {
576 WithColor::error() << "incompatible arguments: specifying both -diff and "
577 "-verbose is currently not supported";
578 return 0;
581 std::unique_ptr<ToolOutputFile> OutputFile;
582 if (!OutputFilename.empty()) {
583 std::error_code EC;
584 OutputFile = llvm::make_unique<ToolOutputFile>(OutputFilename, EC,
585 sys::fs::F_None);
586 error("Unable to open output file" + OutputFilename, EC);
587 // Don't remove output file if we exit with an error.
588 OutputFile->keep();
591 raw_ostream &OS = OutputFile ? OutputFile->os() : outs();
592 bool OffsetRequested = false;
594 // Defaults to dumping all sections, unless brief mode is specified in which
595 // case only the .debug_info section in dumped.
596 #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
597 if (Dump##ENUM_NAME.IsRequested) { \
598 DumpType |= DIDT_##ENUM_NAME; \
599 if (Dump##ENUM_NAME.HasValue) { \
600 DumpOffsets[DIDT_ID_##ENUM_NAME] = Dump##ENUM_NAME.Val; \
601 OffsetRequested = true; \
604 #include "llvm/BinaryFormat/Dwarf.def"
605 #undef HANDLE_DWARF_SECTION
606 if (DumpUUID)
607 DumpType |= DIDT_UUID;
608 if (DumpAll)
609 DumpType = DIDT_All;
610 if (DumpType == DIDT_Null) {
611 if (Verbose)
612 DumpType = DIDT_All;
613 else
614 DumpType = DIDT_DebugInfo;
617 // Unless dumping a specific DIE, default to --show-children.
618 if (!ShowChildren && !Verify && !OffsetRequested && Name.empty() && Find.empty())
619 ShowChildren = true;
621 // Defaults to a.out if no filenames specified.
622 if (InputFilenames.empty())
623 InputFilenames.push_back("a.out");
625 // Expand any .dSYM bundles to the individual object files contained therein.
626 std::vector<std::string> Objects;
627 for (const auto &F : InputFilenames) {
628 auto Objs = expandBundle(F);
629 Objects.insert(Objects.end(), Objs.begin(), Objs.end());
632 if (Verify) {
633 // If we encountered errors during verify, exit with a non-zero exit status.
634 if (!all_of(Objects, [&](std::string Object) {
635 return handleFile(Object, verifyObjectFile, OS);
637 exit(1);
638 } else if (Statistics)
639 for (auto Object : Objects)
640 handleFile(Object, collectStatsForObjectFile, OS);
641 else
642 for (auto Object : Objects)
643 handleFile(Object, dumpObjectFile, OS);
645 return EXIT_SUCCESS;