2014-12-12 17:31:24 +00:00
|
|
|
//===-- dsymutil.cpp - Debug info dumping utility for llvm ----------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This program is a utility that aims to be a dropin replacement for
|
|
|
|
// Darwin's dsymutil.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DebugMap.h"
|
|
|
|
#include "dsymutil.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
#include "llvm/Support/Options.h"
|
2015-01-14 11:23:27 +00:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2014-12-12 17:31:24 +00:00
|
|
|
#include "llvm/Support/Signals.h"
|
2015-01-14 11:23:27 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2015-02-28 00:29:11 +00:00
|
|
|
#include "llvm/Support/TargetSelect.h"
|
2014-12-12 17:31:24 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace llvm::dsymutil;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
using namespace llvm::cl;
|
|
|
|
|
|
|
|
static opt<std::string> InputFile(Positional, desc("<input file>"),
|
|
|
|
init("a.out"));
|
|
|
|
|
2015-02-28 00:29:03 +00:00
|
|
|
static opt<std::string> OutputFileOpt("o", desc("Specify the output file."
|
|
|
|
" default: <input file>.dwarf"),
|
|
|
|
value_desc("filename"));
|
|
|
|
|
2014-12-12 17:31:24 +00:00
|
|
|
static opt<std::string> OsoPrependPath("oso-prepend-path",
|
|
|
|
desc("Specify a directory to prepend "
|
|
|
|
"to the paths of object files."),
|
|
|
|
value_desc("path"));
|
|
|
|
|
|
|
|
static opt<bool> Verbose("v", desc("Verbosity level"), init(false));
|
|
|
|
|
2015-02-28 00:29:11 +00:00
|
|
|
static opt<bool> NoOutput("no-output", desc("Do the link in memory, but do "
|
|
|
|
"not emit the result file."),
|
|
|
|
init(false));
|
|
|
|
|
2014-12-12 17:31:24 +00:00
|
|
|
static opt<bool>
|
|
|
|
ParseOnly("parse-only",
|
|
|
|
desc("Only parse the debug map, do not actaully link "
|
|
|
|
"the DWARF."),
|
|
|
|
init(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
|
|
|
llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
|
|
|
|
llvm::llvm_shutdown_obj Shutdown;
|
2015-02-28 00:29:07 +00:00
|
|
|
LinkOptions Options;
|
2014-12-12 17:31:24 +00:00
|
|
|
|
|
|
|
llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n");
|
2014-12-16 20:22:11 +00:00
|
|
|
auto DebugMapPtrOrErr = parseDebugMap(InputFile, OsoPrependPath, Verbose);
|
2014-12-12 17:31:24 +00:00
|
|
|
|
2015-02-28 00:29:07 +00:00
|
|
|
Options.Verbose = Verbose;
|
2015-02-28 00:29:11 +00:00
|
|
|
Options.NoOutput = NoOutput;
|
|
|
|
|
|
|
|
llvm::InitializeAllTargetInfos();
|
|
|
|
llvm::InitializeAllTargetMCs();
|
|
|
|
llvm::InitializeAllTargets();
|
|
|
|
llvm::InitializeAllAsmPrinters();
|
2015-02-28 00:29:07 +00:00
|
|
|
|
2014-12-12 17:31:24 +00:00
|
|
|
if (auto EC = DebugMapPtrOrErr.getError()) {
|
|
|
|
llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
|
|
|
|
<< "\": " << EC.message() << '\n';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Verbose)
|
|
|
|
(*DebugMapPtrOrErr)->print(llvm::outs());
|
|
|
|
|
|
|
|
if (ParseOnly)
|
|
|
|
return 0;
|
|
|
|
|
2015-02-28 00:29:03 +00:00
|
|
|
std::string OutputFile;
|
|
|
|
if (OutputFileOpt.empty()) {
|
|
|
|
if (InputFile == "-")
|
|
|
|
OutputFile = "a.out.dwarf";
|
|
|
|
else
|
|
|
|
OutputFile = InputFile + ".dwarf";
|
|
|
|
} else {
|
|
|
|
OutputFile = OutputFileOpt;
|
|
|
|
}
|
2014-12-12 17:31:24 +00:00
|
|
|
|
2015-02-28 00:29:07 +00:00
|
|
|
return !linkDwarf(OutputFile, **DebugMapPtrOrErr, Options);
|
2014-12-12 17:31:24 +00:00
|
|
|
}
|