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 <string>
23
24 using namespace llvm::dsymutil;
25
26 namespace {
27 using namespace llvm::cl;
28
29 static opt<std::string> InputFile(Positional, desc("<input file>"),
30 init("a.out"));
31
32 static opt<std::string> OsoPrependPath("oso-prepend-path",
33 desc("Specify a directory to prepend "
34 "to the paths of object files."),
35 value_desc("path"));
36
37 static opt<bool> Verbose("v", desc("Verbosity level"), init(false));
38
39 static opt<bool>
40 ParseOnly("parse-only",
41 desc("Only parse the debug map, do not actaully link "
42 "the DWARF."),
43 init(false));
44 }
45
main(int argc,char ** argv)46 int main(int argc, char **argv) {
47 llvm::sys::PrintStackTraceOnErrorSignal();
48 llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
49 llvm::llvm_shutdown_obj Shutdown;
50
51 llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n");
52 auto DebugMapPtrOrErr = parseDebugMap(InputFile, OsoPrependPath, Verbose);
53
54 if (auto EC = DebugMapPtrOrErr.getError()) {
55 llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
56 << "\": " << EC.message() << '\n';
57 return 1;
58 }
59
60 if (Verbose)
61 (*DebugMapPtrOrErr)->print(llvm::outs());
62
63 if (ParseOnly)
64 return 0;
65
66 std::string OutputBasename(InputFile);
67 if (OutputBasename == "-")
68 OutputBasename = "a.out";
69
70 return !linkDwarf(OutputBasename + ".dwarf", **DebugMapPtrOrErr, Verbose);
71 }
72