dsymutil.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include "DebugMap.h"
  15. #include "dsymutil.h"
  16. #include "llvm/Support/ManagedStatic.h"
  17. #include "llvm/Support/Options.h"
  18. #include "llvm/Support/PrettyStackTrace.h"
  19. #include "llvm/Support/Signals.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. #include "llvm/Support/TargetSelect.h"
  22. #include <string>
  23. using namespace llvm::dsymutil;
  24. namespace {
  25. using namespace llvm::cl;
  26. static opt<std::string> InputFile(Positional, desc("<input file>"),
  27. init("a.out"));
  28. static opt<std::string>
  29. OutputFileOpt("o",
  30. desc("Specify the output file. default: <input file>.dwarf"),
  31. value_desc("filename"));
  32. static opt<std::string> OsoPrependPath(
  33. "oso-prepend-path",
  34. desc("Specify a directory to prepend to the paths of object files."),
  35. value_desc("path"));
  36. static opt<bool> Verbose("v", desc("Verbosity level"), init(false));
  37. static opt<bool>
  38. NoOutput("no-output",
  39. desc("Do the link in memory, but do not emit the result file."),
  40. init(false));
  41. static opt<bool> DumpDebugMap(
  42. "dump-debug-map",
  43. desc("Parse and dump the debug map to standard output. Not DWARF link "
  44. "will take place."),
  45. init(false));
  46. static opt<bool> InputIsYAMLDebugMap(
  47. "y", desc("Treat the input file is a YAML debug map rather than a binary."),
  48. init(false));
  49. }
  50. int main(int argc, char **argv) {
  51. llvm::sys::PrintStackTraceOnErrorSignal();
  52. llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
  53. llvm::llvm_shutdown_obj Shutdown;
  54. LinkOptions Options;
  55. llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n");
  56. auto DebugMapPtrOrErr =
  57. parseDebugMap(InputFile, OsoPrependPath, Verbose, InputIsYAMLDebugMap);
  58. Options.Verbose = Verbose;
  59. Options.NoOutput = NoOutput;
  60. llvm::InitializeAllTargetInfos();
  61. llvm::InitializeAllTargetMCs();
  62. llvm::InitializeAllTargets();
  63. llvm::InitializeAllAsmPrinters();
  64. if (auto EC = DebugMapPtrOrErr.getError()) {
  65. llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
  66. << "\": " << EC.message() << '\n';
  67. return 1;
  68. }
  69. if (Verbose || DumpDebugMap)
  70. (*DebugMapPtrOrErr)->print(llvm::outs());
  71. if (DumpDebugMap)
  72. return 0;
  73. std::string OutputFile;
  74. if (OutputFileOpt.empty()) {
  75. if (InputFile == "-")
  76. OutputFile = "a.out.dwarf";
  77. else
  78. OutputFile = InputFile + ".dwarf";
  79. } else {
  80. OutputFile = OutputFileOpt;
  81. }
  82. return !linkDwarf(OutputFile, **DebugMapPtrOrErr, Options);
  83. }