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 static opt<std::string> InputFile(Positional, desc("<input file>"),
33 static opt<std::string>
35 desc("Specify the output file. default: <input file>.dwarf"),
36 value_desc("filename"));
38 static opt<std::string> OsoPrependPath(
40 desc("Specify a directory to prepend to the paths of object files."),
43 static opt<bool> Verbose("v", desc("Verbosity level"), init(false));
47 desc("Do the link in memory, but do not emit the result file."),
50 static opt<bool> DumpDebugMap(
52 desc("Parse and dump the debug map to standard output. Not DWARF link "
56 static opt<bool> InputIsYAMLDebugMap(
57 "y", desc("Treat the input file is a YAML debug map rather than a binary."),
61 int main(int argc, char **argv) {
62 llvm::sys::PrintStackTraceOnErrorSignal();
63 llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
64 llvm::llvm_shutdown_obj Shutdown;
67 llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n");
69 auto DebugMapPtrOrErr =
70 parseDebugMap(InputFile, OsoPrependPath, Verbose, InputIsYAMLDebugMap);
72 Options.Verbose = Verbose;
73 Options.NoOutput = NoOutput;
75 llvm::InitializeAllTargetInfos();
76 llvm::InitializeAllTargetMCs();
77 llvm::InitializeAllTargets();
78 llvm::InitializeAllAsmPrinters();
80 if (auto EC = DebugMapPtrOrErr.getError()) {
81 llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
82 << "\": " << EC.message() << '\n';
86 if (Verbose || DumpDebugMap)
87 (*DebugMapPtrOrErr)->print(llvm::outs());
92 std::string OutputFile;
93 if (OutputFileOpt.empty()) {
95 OutputFile = "a.out.dwarf";
97 OutputFile = InputFile + ".dwarf";
99 OutputFile = OutputFileOpt;
102 return !linkDwarf(OutputFile, **DebugMapPtrOrErr, Options);