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> OutputFileOpt("o", desc("Specify the output file."
34 " default: <input file>.dwarf"),
35 value_desc("filename"));
36
37 static opt<std::string> OsoPrependPath("oso-prepend-path",
38 desc("Specify a directory to prepend "
39 "to the paths of object files."),
40 value_desc("path"));
41
42 static opt<bool> Verbose("v", desc("Verbosity level"), init(false));
43
44 static opt<bool> NoOutput("no-output", desc("Do the link in memory, but do "
45 "not emit the result file."),
46 init(false));
47
48 static opt<bool>
49 ParseOnly("parse-only",
50 desc("Only parse the debug map, do not actaully link "
51 "the DWARF."),
52 init(false));
53 }
54
main(int argc,char ** argv)55 int main(int argc, char **argv) {
56 llvm::sys::PrintStackTraceOnErrorSignal();
57 llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
58 llvm::llvm_shutdown_obj Shutdown;
59 LinkOptions Options;
60
61 llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n");
62 auto DebugMapPtrOrErr = parseDebugMap(InputFile, OsoPrependPath, Verbose);
63
64 Options.Verbose = Verbose;
65 Options.NoOutput = NoOutput;
66
67 llvm::InitializeAllTargetInfos();
68 llvm::InitializeAllTargetMCs();
69 llvm::InitializeAllTargets();
70 llvm::InitializeAllAsmPrinters();
71
72 if (auto EC = DebugMapPtrOrErr.getError()) {
73 llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
74 << "\": " << EC.message() << '\n';
75 return 1;
76 }
77
78 if (Verbose)
79 (*DebugMapPtrOrErr)->print(llvm::outs());
80
81 if (ParseOnly)
82 return 0;
83
84 std::string OutputFile;
85 if (OutputFileOpt.empty()) {
86 if (InputFile == "-")
87 OutputFile = "a.out.dwarf";
88 else
89 OutputFile = InputFile + ".dwarf";
90 } else {
91 OutputFile = OutputFileOpt;
92 }
93
94 return !linkDwarf(OutputFile, **DebugMapPtrOrErr, Options);
95 }
96