[dsymutil] Add a LinkOptions struct to pass to the DwarfLinker. NFC.

The only option we have to pass down currently is verbosity, but there
are more to come.

llvm-svn: 230823
This commit is contained in:
Frederic Riss 2015-02-28 00:29:07 +00:00
parent 9ac9a2831c
commit b981832951
3 changed files with 26 additions and 14 deletions

View File

@ -71,8 +71,9 @@ private:
/// first step when we start processing a DebugMapObject. /// first step when we start processing a DebugMapObject.
class DwarfLinker { class DwarfLinker {
public: public:
DwarfLinker(StringRef OutputFilename, bool Verbose) DwarfLinker(StringRef OutputFilename, const LinkOptions &Options)
: OutputFilename(OutputFilename), Verbose(Verbose), BinHolder(Verbose) {} : OutputFilename(OutputFilename), Options(Options),
BinHolder(Options.Verbose) {}
/// \brief Link the contents of the DebugMap. /// \brief Link the contents of the DebugMap.
bool link(const DebugMap &); bool link(const DebugMap &);
@ -181,7 +182,7 @@ private:
private: private:
std::string OutputFilename; std::string OutputFilename;
bool Verbose; LinkOptions Options;
BinaryHolder BinHolder; BinaryHolder BinHolder;
/// The units of the current debug map object. /// The units of the current debug map object.
@ -229,7 +230,7 @@ void DwarfLinker::reportWarning(const Twine &Warning, const DWARFUnit *Unit,
Context = CurrentDebugObject->getObjectFilename(); Context = CurrentDebugObject->getObjectFilename();
warn(Warning, Context); warn(Warning, Context);
if (!Verbose || !DIE) if (!Options.Verbose || !DIE)
return; return;
errs() << " in DIE:\n"; errs() << " in DIE:\n";
@ -383,7 +384,7 @@ bool DwarfLinker::hasValidRelocation(uint32_t StartOffset, uint32_t EndOffset,
return false; return false;
const auto &ValidReloc = ValidRelocs[NextValidReloc++]; const auto &ValidReloc = ValidRelocs[NextValidReloc++];
if (Verbose) if (Options.Verbose)
outs() << "Found valid debug map entry: " << ValidReloc.Mapping->getKey() outs() << "Found valid debug map entry: " << ValidReloc.Mapping->getKey()
<< " " << format("\t%016" PRIx64 " => %016" PRIx64, << " " << format("\t%016" PRIx64 " => %016" PRIx64,
ValidReloc.Mapping->getValue().ObjectAddress, ValidReloc.Mapping->getValue().ObjectAddress,
@ -447,7 +448,7 @@ unsigned DwarfLinker::shouldKeepVariableDIE(
(Flags & TF_InFunctionScope)) (Flags & TF_InFunctionScope))
return Flags; return Flags;
if (Verbose) if (Options.Verbose)
DIE.dump(outs(), const_cast<DWARFUnit *>(&OrigUnit), 0, 8 /* Indent */); DIE.dump(outs(), const_cast<DWARFUnit *>(&OrigUnit), 0, 8 /* Indent */);
return Flags | TF_Keep; return Flags | TF_Keep;
@ -479,7 +480,7 @@ unsigned DwarfLinker::shouldKeepSubprogramDIE(
!hasValidRelocation(LowPcOffset, LowPcEndOffset, MyInfo)) !hasValidRelocation(LowPcOffset, LowPcEndOffset, MyInfo))
return Flags; return Flags;
if (Verbose) if (Options.Verbose)
DIE.dump(outs(), const_cast<DWARFUnit *>(&OrigUnit), 0, 8 /* Indent */); DIE.dump(outs(), const_cast<DWARFUnit *>(&OrigUnit), 0, 8 /* Indent */);
return Flags | TF_Keep; return Flags | TF_Keep;
@ -616,7 +617,7 @@ bool DwarfLinker::link(const DebugMap &Map) {
for (const auto &Obj : Map.objects()) { for (const auto &Obj : Map.objects()) {
CurrentDebugObject = Obj.get(); CurrentDebugObject = Obj.get();
if (Verbose) if (Options.Verbose)
outs() << "DEBUG MAP OBJECT: " << Obj->getObjectFilename() << "\n"; outs() << "DEBUG MAP OBJECT: " << Obj->getObjectFilename() << "\n";
auto ErrOrObj = BinHolder.GetObjectFile(Obj->getObjectFilename()); auto ErrOrObj = BinHolder.GetObjectFile(Obj->getObjectFilename());
if (std::error_code EC = ErrOrObj.getError()) { if (std::error_code EC = ErrOrObj.getError()) {
@ -626,7 +627,7 @@ bool DwarfLinker::link(const DebugMap &Map) {
// Look for relocations that correspond to debug map entries. // Look for relocations that correspond to debug map entries.
if (!findValidRelocsInDebugInfo(*ErrOrObj, *Obj)) { if (!findValidRelocsInDebugInfo(*ErrOrObj, *Obj)) {
if (Verbose) if (Options.Verbose)
outs() << "No valid relocations found. Skipping.\n"; outs() << "No valid relocations found. Skipping.\n";
continue; continue;
} }
@ -639,7 +640,7 @@ bool DwarfLinker::link(const DebugMap &Map) {
// parent links that we will use during the next phase. // parent links that we will use during the next phase.
for (const auto &CU : DwarfContext.compile_units()) { for (const auto &CU : DwarfContext.compile_units()) {
auto *CUDie = CU->getCompileUnitDIE(false); auto *CUDie = CU->getCompileUnitDIE(false);
if (Verbose) { if (Options.Verbose) {
outs() << "Input compilation unit:"; outs() << "Input compilation unit:";
CUDie->dump(outs(), CU.get(), 0); CUDie->dump(outs(), CU.get(), 0);
} }
@ -664,8 +665,9 @@ bool DwarfLinker::link(const DebugMap &Map) {
} }
} }
bool linkDwarf(StringRef OutputFilename, const DebugMap &DM, bool Verbose) { bool linkDwarf(StringRef OutputFilename, const DebugMap &DM,
DwarfLinker Linker(OutputFilename, Verbose); const LinkOptions &Options) {
DwarfLinker Linker(OutputFilename, Options);
return Linker.link(DM); return Linker.link(DM);
} }
} }

View File

@ -51,10 +51,13 @@ int main(int argc, char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal(); llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram StackPrinter(argc, argv); llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
llvm::llvm_shutdown_obj Shutdown; llvm::llvm_shutdown_obj Shutdown;
LinkOptions Options;
llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n"); llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n");
auto DebugMapPtrOrErr = parseDebugMap(InputFile, OsoPrependPath, Verbose); auto DebugMapPtrOrErr = parseDebugMap(InputFile, OsoPrependPath, Verbose);
Options.Verbose = Verbose;
if (auto EC = DebugMapPtrOrErr.getError()) { if (auto EC = DebugMapPtrOrErr.getError()) {
llvm::errs() << "error: cannot parse the debug map for \"" << InputFile llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
<< "\": " << EC.message() << '\n'; << "\": " << EC.message() << '\n';
@ -77,5 +80,5 @@ int main(int argc, char **argv) {
OutputFile = OutputFileOpt; OutputFile = OutputFileOpt;
} }
return !linkDwarf(OutputFile, **DebugMapPtrOrErr, Verbose); return !linkDwarf(OutputFile, **DebugMapPtrOrErr, Options);
} }

View File

@ -23,6 +23,13 @@
namespace llvm { namespace llvm {
namespace dsymutil { namespace dsymutil {
struct LinkOptions {
bool Verbose;
LinkOptions() : Verbose(false) {}
};
/// \brief Extract the DebugMap from the given file. /// \brief Extract the DebugMap from the given file.
/// The file has to be a MachO object file. /// The file has to be a MachO object file.
llvm::ErrorOr<std::unique_ptr<DebugMap>> llvm::ErrorOr<std::unique_ptr<DebugMap>>
@ -33,7 +40,7 @@ parseDebugMap(StringRef InputFile, StringRef PrependPath = "",
/// \p DM into a DwarfFile named \p OutputFilename. /// \p DM into a DwarfFile named \p OutputFilename.
/// \returns false if the link failed. /// \returns false if the link failed.
bool linkDwarf(StringRef OutputFilename, const DebugMap &DM, bool linkDwarf(StringRef OutputFilename, const DebugMap &DM,
bool Verbose = false); const LinkOptions &Options);
} }
} }
#endif // LLVM_TOOLS_DSYMUTIL_DSYMUTIL_H #endif // LLVM_TOOLS_DSYMUTIL_DSYMUTIL_H