[dsymutil] Rename -v option to -verbose
[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 #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"
23 #include <string>
24
25 using namespace llvm::dsymutil;
26
27 namespace {
28 using namespace llvm::cl;
29
30 static opt<std::string> InputFile(Positional, desc("<input file>"),
31                                   init("a.out"));
32
33 static opt<std::string>
34     OutputFileOpt("o",
35                   desc("Specify the output file. default: <input file>.dwarf"),
36                   value_desc("filename"));
37
38 static opt<std::string> OsoPrependPath(
39     "oso-prepend-path",
40     desc("Specify a directory to prepend to the paths of object files."),
41     value_desc("path"));
42
43 static opt<bool> Verbose("verbose", desc("Verbosity level"), init(false));
44
45 static opt<bool>
46     NoOutput("no-output",
47              desc("Do the link in memory, but do not emit the result file."),
48              init(false));
49
50 static opt<bool>
51     NoODR("no-odr",
52           desc("Do not use ODR (One Definition Rule) for type uniquing."),
53           init(false));
54
55 static opt<bool> DumpDebugMap(
56     "dump-debug-map",
57     desc("Parse and dump the debug map to standard output. Not DWARF link "
58          "will take place."),
59     init(false));
60
61 static opt<bool> InputIsYAMLDebugMap(
62     "y", desc("Treat the input file is a YAML debug map rather than a binary."),
63     init(false));
64 }
65
66 int main(int argc, char **argv) {
67   llvm::sys::PrintStackTraceOnErrorSignal();
68   llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
69   llvm::llvm_shutdown_obj Shutdown;
70   LinkOptions Options;
71
72   llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n");
73
74   auto DebugMapPtrOrErr =
75       parseDebugMap(InputFile, OsoPrependPath, Verbose, InputIsYAMLDebugMap);
76
77   Options.Verbose = Verbose;
78   Options.NoOutput = NoOutput;
79   Options.NoODR = NoODR;
80
81   llvm::InitializeAllTargetInfos();
82   llvm::InitializeAllTargetMCs();
83   llvm::InitializeAllTargets();
84   llvm::InitializeAllAsmPrinters();
85
86   if (auto EC = DebugMapPtrOrErr.getError()) {
87     llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
88                  << "\": " << EC.message() << '\n';
89     return 1;
90   }
91
92   if (Verbose || DumpDebugMap)
93     (*DebugMapPtrOrErr)->print(llvm::outs());
94
95   if (DumpDebugMap)
96     return 0;
97
98   std::string OutputFile;
99   if (OutputFileOpt.empty()) {
100     if (InputFile == "-")
101       OutputFile = "a.out.dwarf";
102     else
103       OutputFile = InputFile + ".dwarf";
104   } else {
105     OutputFile = OutputFileOpt;
106   }
107
108   return !linkDwarf(OutputFile, **DebugMapPtrOrErr, Options);
109 }