Utils: Use MDTuple::get() directly, NFC
[oota-llvm.git] / tools / dsymutil / dsymutil.cpp
1 //===-- dsymutil.cpp - Debug info dumping utility for llvm ----------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This program is a utility that aims to be a dropin replacement for
11 // Darwin's dsymutil.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "DebugMap.h"
16 #include "dsymutil.h"
17
18 #include "llvm/Support/ManagedStatic.h"
19 #include "llvm/Support/PrettyStackTrace.h"
20 #include "llvm/Support/Options.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "llvm/Support/Signals.h"
23
24 #include <string>
25
26 using namespace llvm::dsymutil;
27
28 namespace {
29 using namespace llvm::cl;
30
31 static opt<std::string> InputFile(Positional, desc("<input file>"),
32                                   init("a.out"));
33
34 static opt<std::string> OsoPrependPath("oso-prepend-path",
35                                        desc("Specify a directory to prepend "
36                                             "to the paths of object files."),
37                                        value_desc("path"));
38
39 static opt<bool> Verbose("v", desc("Verbosity level"), init(false));
40
41 static opt<bool>
42     ParseOnly("parse-only",
43               desc("Only parse the debug map, do not actaully link "
44                    "the DWARF."),
45               init(false));
46 }
47
48 int main(int argc, char **argv) {
49   llvm::sys::PrintStackTraceOnErrorSignal();
50   llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
51   llvm::llvm_shutdown_obj Shutdown;
52
53   llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n");
54   auto DebugMapPtrOrErr = parseDebugMap(InputFile, OsoPrependPath, Verbose);
55
56   if (auto EC = DebugMapPtrOrErr.getError()) {
57     llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
58                  << "\": " << EC.message() << '\n';
59     return 1;
60   }
61
62   if (Verbose)
63     (*DebugMapPtrOrErr)->print(llvm::outs());
64
65   if (ParseOnly)
66     return 0;
67
68   std::string OutputBasename(InputFile);
69   if (OutputBasename == "-")
70     OutputBasename = "a.out";
71
72   return !linkDwarf(OutputBasename + ".dwarf", **DebugMapPtrOrErr, Verbose);
73 }