コード例 #1
0
ファイル: llvm-dwarfdump.cpp プロジェクト: crabtw/llvm
static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
                           raw_ostream &OS) {
  logAllUnhandledErrors(DICtx.loadRegisterInfo(Obj), errs(),
                        Filename.str() + ": ");
  // The UUID dump already contains all the same information.
  if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
    OS << Filename << ":\tfile format " << Obj.getFileFormatName() << '\n';

  // Handle the --lookup option.
  if (Lookup)
    return lookup(DICtx, Lookup, OS);

  // Handle the --name option.
  if (!Name.empty()) {
    StringSet<> Names;
    for (auto name : Name)
      Names.insert((IgnoreCase && !UseRegex) ? StringRef(name).lower() : name);

    filterByName(Names, DICtx.compile_units(), OS);
    filterByName(Names, DICtx.dwo_compile_units(), OS);
    return true;
  }

  // Handle the --find option and lower it to --debug-info=<offset>.
  if (!Find.empty()) {
    filterByAccelName(Find, DICtx, OS);
    return true;
  }

  // Dump the complete DWARF structure.
  DICtx.dump(OS, getDumpOpts(), DumpOffsets);
  return true;
}
コード例 #2
0
static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
                           raw_ostream &OS) {
  logAllUnhandledErrors(DICtx.loadRegisterInfo(Obj), errs(),
                        Filename.str() + ": ");
  // The UUID dump already contains all the same information.
  if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
    OS << Filename << ":\tfile format " << Obj.getFileFormatName() << '\n';

  // Handle the --lookup option.
  if (Lookup)
    return lookup(DICtx, Lookup, OS);

  // Handle the --name option.
  if (!Name.empty()) {
    StringSet<> Names;
    for (auto name : Name)
      Names.insert((IgnoreCase && !UseRegex) ? StringRef(name).lower() : name);

    filterByName(Names, DICtx.compile_units(), OS);
    filterByName(Names, DICtx.dwo_compile_units(), OS);
    return true;
  }

  // Handle the --find option and lower it to --debug-info=<offset>.
  if (!Find.empty()) {
    DumpOffsets[DIDT_ID_DebugInfo] = [&]() -> llvm::Optional<uint64_t> {
      for (auto Name : Find) {
        auto find = [&](const DWARFAcceleratorTable &Accel)
            -> llvm::Optional<uint64_t> {
          for (auto Entry : Accel.equal_range(Name))
            for (auto Atom : Entry)
              if (auto Offset = Atom.getAsSectionOffset())
                return Offset;
          return None;
        };
        if (auto Offset = find(DICtx.getAppleNames()))
          return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
        if (auto Offset = find(DICtx.getAppleTypes()))
          return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
        if (auto Offset = find(DICtx.getAppleNamespaces()))
          return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
      }
      return None;
    }();
    // Early exit if --find was specified but the current file doesn't have it.
    if (!DumpOffsets[DIDT_ID_DebugInfo])
      return true;
  }

  // Dump the complete DWARF structure.
  DICtx.dump(OS, getDumpOpts(), DumpOffsets);
  return true;
}