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;
|
|
|
|
|
2015-07-29 22:29:46 +00:00
|
|
|
OptionCategory DsymCategory("Specific Options");
|
|
|
|
static opt<bool> Help("h", desc("Alias for -help"), Hidden);
|
2015-07-29 22:29:50 +00:00
|
|
|
static opt<bool> Version("v", desc("Alias for -version"), Hidden);
|
2015-07-29 22:29:46 +00:00
|
|
|
|
2015-07-31 20:22:20 +00:00
|
|
|
static list<std::string> InputFiles(Positional, OneOrMore,
|
|
|
|
desc("<input files>"), cat(DsymCategory));
|
2014-12-12 17:31:24 +00:00
|
|
|
|
2015-06-03 16:57:07 +00:00
|
|
|
static opt<std::string>
|
|
|
|
OutputFileOpt("o",
|
|
|
|
desc("Specify the output file. default: <input file>.dwarf"),
|
2015-07-29 22:29:46 +00:00
|
|
|
value_desc("filename"), cat(DsymCategory));
|
2015-02-28 00:29:03 +00:00
|
|
|
|
2015-06-03 16:57:07 +00:00
|
|
|
static opt<std::string> OsoPrependPath(
|
|
|
|
"oso-prepend-path",
|
|
|
|
desc("Specify a directory to prepend to the paths of object files."),
|
2015-07-29 22:29:46 +00:00
|
|
|
value_desc("path"), cat(DsymCategory));
|
2014-12-12 17:31:24 +00:00
|
|
|
|
2015-07-29 22:29:46 +00:00
|
|
|
static opt<bool> Verbose("verbose", desc("Verbosity level"), init(false),
|
|
|
|
cat(DsymCategory));
|
2014-12-12 17:31:24 +00:00
|
|
|
|
2015-06-03 16:57:07 +00:00
|
|
|
static opt<bool>
|
|
|
|
NoOutput("no-output",
|
|
|
|
desc("Do the link in memory, but do not emit the result file."),
|
2015-07-29 22:29:46 +00:00
|
|
|
init(false), cat(DsymCategory));
|
2015-02-28 00:29:11 +00:00
|
|
|
|
2015-07-21 22:41:43 +00:00
|
|
|
static opt<bool>
|
|
|
|
NoODR("no-odr",
|
|
|
|
desc("Do not use ODR (One Definition Rule) for type uniquing."),
|
2015-07-29 22:29:46 +00:00
|
|
|
init(false), cat(DsymCategory));
|
2015-07-21 22:41:43 +00:00
|
|
|
|
2015-06-03 16:57:12 +00:00
|
|
|
static opt<bool> DumpDebugMap(
|
|
|
|
"dump-debug-map",
|
|
|
|
desc("Parse and dump the debug map to standard output. Not DWARF link "
|
|
|
|
"will take place."),
|
2015-07-29 22:29:46 +00:00
|
|
|
init(false), cat(DsymCategory));
|
2015-06-03 20:29:24 +00:00
|
|
|
|
|
|
|
static opt<bool> InputIsYAMLDebugMap(
|
|
|
|
"y", desc("Treat the input file is a YAML debug map rather than a binary."),
|
2015-07-29 22:29:46 +00:00
|
|
|
init(false), cat(DsymCategory));
|
2014-12-12 17:31:24 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 18:27:34 +00:00
|
|
|
static std::string getOutputFileName(llvm::StringRef InputFile) {
|
|
|
|
if (OutputFileOpt.empty()) {
|
|
|
|
if (InputFile == "-")
|
|
|
|
return "a.out.dwarf";
|
|
|
|
return (InputFile + ".dwarf").str();
|
|
|
|
}
|
|
|
|
return OutputFileOpt;
|
|
|
|
}
|
|
|
|
|
2015-08-05 18:27:38 +00:00
|
|
|
void llvm::dsymutil::exitDsymutil(int ExitStatus) {
|
|
|
|
exit(ExitStatus);
|
|
|
|
}
|
|
|
|
|
2014-12-12 17:31:24 +00:00
|
|
|
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
|
|
|
|
2015-07-29 22:29:46 +00:00
|
|
|
HideUnrelatedOptions(DsymCategory);
|
|
|
|
llvm::cl::ParseCommandLineOptions(
|
|
|
|
argc, argv,
|
|
|
|
"manipulate archived DWARF debug symbol files.\n\n"
|
|
|
|
"dsymutil links the DWARF debug information found in the object files\n"
|
|
|
|
"for the executable <input file> by using debug symbols information\n"
|
|
|
|
"contained in its symbol table.\n");
|
|
|
|
|
|
|
|
if (Help)
|
|
|
|
PrintHelpMessage();
|
2015-06-03 20:29:24 +00:00
|
|
|
|
2015-07-29 22:29:50 +00:00
|
|
|
if (Version) {
|
|
|
|
llvm::cl::PrintVersionMessage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-28 00:29:07 +00:00
|
|
|
Options.Verbose = Verbose;
|
2015-02-28 00:29:11 +00:00
|
|
|
Options.NoOutput = NoOutput;
|
2015-07-21 22:41:43 +00:00
|
|
|
Options.NoODR = NoODR;
|
2015-02-28 00:29:11 +00:00
|
|
|
|
|
|
|
llvm::InitializeAllTargetInfos();
|
|
|
|
llvm::InitializeAllTargetMCs();
|
|
|
|
llvm::InitializeAllTargets();
|
|
|
|
llvm::InitializeAllAsmPrinters();
|
2015-02-28 00:29:07 +00:00
|
|
|
|
2015-07-31 20:22:20 +00:00
|
|
|
if (InputFiles.size() > 1 && !OutputFileOpt.empty()) {
|
|
|
|
llvm::errs() << "error: cannot use -o with multiple inputs\n";
|
2014-12-12 17:31:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-07-31 20:22:20 +00:00
|
|
|
for (auto &InputFile : InputFiles) {
|
|
|
|
auto DebugMapPtrOrErr =
|
|
|
|
parseDebugMap(InputFile, OsoPrependPath, Verbose, InputIsYAMLDebugMap);
|
|
|
|
|
|
|
|
if (auto EC = DebugMapPtrOrErr.getError()) {
|
|
|
|
llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
|
|
|
|
<< "\": " << EC.message() << '\n';
|
2015-08-05 18:27:38 +00:00
|
|
|
exitDsymutil(1);
|
2015-07-31 20:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Verbose || DumpDebugMap)
|
|
|
|
(*DebugMapPtrOrErr)->print(llvm::outs());
|
|
|
|
|
|
|
|
if (DumpDebugMap)
|
|
|
|
continue;
|
|
|
|
|
2015-08-05 18:27:34 +00:00
|
|
|
std::string OutputFile = getOutputFileName(InputFile);
|
2015-07-31 20:22:20 +00:00
|
|
|
if (!linkDwarf(OutputFile, **DebugMapPtrOrErr, Options))
|
2015-08-05 18:27:38 +00:00
|
|
|
exitDsymuti(1);
|
2015-02-28 00:29:03 +00:00
|
|
|
}
|
2014-12-12 17:31:24 +00:00
|
|
|
|
2015-08-05 18:27:38 +00:00
|
|
|
exitDsymutil(0);
|
2014-12-12 17:31:24 +00:00
|
|
|
}
|