1 //===-- dsymutil.cpp - Debug info dumping utility for llvm ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This program is a utility that aims to be a dropin replacement for
13 //===----------------------------------------------------------------------===//
17 #include "llvm/Support/ManagedStatic.h"
18 #include "llvm/Support/Options.h"
19 #include "llvm/Support/PrettyStackTrace.h"
20 #include "llvm/Support/Signals.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "llvm/Support/TargetSelect.h"
25 using namespace llvm::dsymutil;
28 using namespace llvm::cl;
30 OptionCategory DsymCategory("Specific Options");
31 static opt<bool> Help("h", desc("Alias for -help"), Hidden);
32 static opt<bool> Version("v", desc("Alias for -version"), Hidden);
34 static list<std::string> InputFiles(Positional, OneOrMore,
35 desc("<input files>"), cat(DsymCategory));
37 static opt<std::string>
39 desc("Specify the output file. default: <input file>.dwarf"),
40 value_desc("filename"), cat(DsymCategory));
42 static opt<std::string> OsoPrependPath(
44 desc("Specify a directory to prepend to the paths of object files."),
45 value_desc("path"), cat(DsymCategory));
47 static opt<bool> Verbose("verbose", desc("Verbosity level"), init(false),
52 desc("Do the link in memory, but do not emit the result file."),
53 init(false), cat(DsymCategory));
57 desc("Do not use ODR (One Definition Rule) for type uniquing."),
58 init(false), cat(DsymCategory));
60 static opt<bool> DumpDebugMap(
62 desc("Parse and dump the debug map to standard output. Not DWARF link "
64 init(false), cat(DsymCategory));
66 static opt<bool> InputIsYAMLDebugMap(
67 "y", desc("Treat the input file is a YAML debug map rather than a binary."),
68 init(false), cat(DsymCategory));
71 static std::string getOutputFileName(llvm::StringRef InputFile) {
72 if (OutputFileOpt.empty()) {
75 return (InputFile + ".dwarf").str();
80 int main(int argc, char **argv) {
81 llvm::sys::PrintStackTraceOnErrorSignal();
82 llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
83 llvm::llvm_shutdown_obj Shutdown;
86 HideUnrelatedOptions(DsymCategory);
87 llvm::cl::ParseCommandLineOptions(
89 "manipulate archived DWARF debug symbol files.\n\n"
90 "dsymutil links the DWARF debug information found in the object files\n"
91 "for the executable <input file> by using debug symbols information\n"
92 "contained in its symbol table.\n");
98 llvm::cl::PrintVersionMessage();
102 Options.Verbose = Verbose;
103 Options.NoOutput = NoOutput;
104 Options.NoODR = NoODR;
106 llvm::InitializeAllTargetInfos();
107 llvm::InitializeAllTargetMCs();
108 llvm::InitializeAllTargets();
109 llvm::InitializeAllAsmPrinters();
111 if (InputFiles.size() > 1 && !OutputFileOpt.empty()) {
112 llvm::errs() << "error: cannot use -o with multiple inputs\n";
116 for (auto &InputFile : InputFiles) {
117 auto DebugMapPtrOrErr =
118 parseDebugMap(InputFile, OsoPrependPath, Verbose, InputIsYAMLDebugMap);
120 if (auto EC = DebugMapPtrOrErr.getError()) {
121 llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
122 << "\": " << EC.message() << '\n';
126 if (Verbose || DumpDebugMap)
127 (*DebugMapPtrOrErr)->print(llvm::outs());
132 std::string OutputFile = getOutputFileName(InputFile);
133 if (!linkDwarf(OutputFile, **DebugMapPtrOrErr, Options))