}
static void printArchiveChild(StringRef Filename, const Archive::Child &C,
- bool verbose, bool print_offset,
+ size_t ChildIndex, bool verbose,
+ bool print_offset,
StringRef ArchitectureName = StringRef()) {
if (print_offset)
outs() << C.getChildOffset() << "\t";
sys::fs::perms Mode =
- unwrapOrError(C.getAccessMode(), Filename, C, ArchitectureName);
+ unwrapOrError(C.getAccessMode(), Filename,
+ getFileNameForError(C, ChildIndex),
+ ArchitectureName);
if (verbose) {
// FIXME: this first dash, "-", is for (Mode & S_IFMT) == S_IFREG.
// But there is nothing in sys::fs::perms for S_IFMT or S_IFREG.
outs() << format(
"%3d/%-3d %5" PRId64 " ",
- unwrapOrError(C.getUID(), Filename, C, ArchitectureName),
- unwrapOrError(C.getGID(), Filename, C, ArchitectureName),
- unwrapOrError(C.getRawSize(), Filename, C, ArchitectureName));
+ unwrapOrError(C.getUID(), Filename, getFileNameForError(C, ChildIndex),
+ ArchitectureName),
+ unwrapOrError(C.getGID(), Filename, getFileNameForError(C, ChildIndex),
+ ArchitectureName),
+ unwrapOrError(C.getRawSize(), Filename,
+ getFileNameForError(C, ChildIndex), ArchitectureName));
StringRef RawLastModified = C.getRawLastModified();
if (verbose) {
Expected<StringRef> NameOrErr = C.getName();
if (!NameOrErr) {
consumeError(NameOrErr.takeError());
- outs() << unwrapOrError(C.getRawName(), Filename, C, ArchitectureName)
+ outs() << unwrapOrError(C.getRawName(), Filename,
+ getFileNameForError(C, ChildIndex),
+ ArchitectureName)
<< "\n";
} else {
StringRef Name = NameOrErr.get();
outs() << Name << "\n";
}
} else {
- outs() << unwrapOrError(C.getRawName(), Filename, C, ArchitectureName)
+ outs() << unwrapOrError(C.getRawName(), Filename,
+ getFileNameForError(C, ChildIndex),
+ ArchitectureName)
<< "\n";
}
}
bool print_offset,
StringRef ArchitectureName = StringRef()) {
Error Err = Error::success();
+ size_t I = 0;
for (const auto &C : A->children(Err, false))
- printArchiveChild(Filename, C, verbose, print_offset, ArchitectureName);
+ printArchiveChild(Filename, C, I++, verbose, print_offset,
+ ArchitectureName);
if (Err)
report_error(std::move(Err), StringRef(), Filename, ArchitectureName);
printArchiveHeaders(Filename, A, !NonVerbose, ArchiveMemberOffsets);
Error Err = Error::success();
+ unsigned I = -1;
for (auto &C : A->children(Err)) {
+ ++I;
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {
if (Error E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
- report_error(std::move(E), Filename, C);
+ report_error(std::move(E), Filename, getFileNameForError(C, I));
continue;
}
if (MachOObjectFile *O = dyn_cast<MachOObjectFile>(&*ChildOrErr.get())) {
printArchiveHeaders(Filename, A.get(), !NonVerbose,
ArchiveMemberOffsets, ArchitectureName);
Error Err = Error::success();
+ unsigned I = -1;
for (auto &C : A->children(Err)) {
+ ++I;
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {
- if (Error E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
- report_error(std::move(E), Filename, C, ArchitectureName);
+ if (Error E =
+ isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
+ report_error(std::move(E), Filename, getFileNameForError(C, I),
+ ArchitectureName);
continue;
}
if (MachOObjectFile *O =
printArchiveHeaders(Filename, A.get(), !NonVerbose,
ArchiveMemberOffsets);
Error Err = Error::success();
+ unsigned I = -1;
for (auto &C : A->children(Err)) {
+ ++I;
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {
if (Error E =
isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
- report_error(std::move(E), Filename, C);
+ report_error(std::move(E), Filename, getFileNameForError(C, I));
continue;
}
if (MachOObjectFile *O =
printArchiveHeaders(Filename, A.get(), !NonVerbose,
ArchiveMemberOffsets, ArchitectureName);
Error Err = Error::success();
+ unsigned I = -1;
for (auto &C : A->children(Err)) {
+ ++I;
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {
if (Error E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
- report_error(std::move(E), Filename, C, ArchitectureName);
+ report_error(std::move(E), Filename, getFileNameForError(C, I),
+ ArchitectureName);
continue;
}
if (MachOObjectFile *O =
return SectionFilter([](object::SectionRef S) { return shouldKeep(S); }, O);
}
+std::string getFileNameForError(const object::Archive::Child &C,
+ unsigned Index) {
+ Expected<StringRef> NameOrErr = C.getName();
+ if (NameOrErr)
+ return NameOrErr.get();
+ // If we have an error getting the name then we print the index of the archive
+ // member. Since we are already in an error state, we just ignore this error.
+ consumeError(NameOrErr.takeError());
+ return "<file index: " + std::to_string(Index) + ">";
+}
+
void error(std::error_code EC) {
if (!EC)
return;
exit(1);
}
-LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef ArchiveName,
- const object::Archive::Child &C,
- StringRef ArchitectureName) {
- Expected<StringRef> NameOrErr = C.getName();
- // TODO: if we have a error getting the name then it would be nice to print
- // the index of which archive member this is and or its offset in the
- // archive instead of "???" as the name.
- if (!NameOrErr) {
- consumeError(NameOrErr.takeError());
- report_error(std::move(E), ArchiveName, "???", ArchitectureName);
- } else
- report_error(std::move(E), ArchiveName, NameOrErr.get(), ArchitectureName);
-}
-
static void warnOnNoMatchForSections() {
SetVector<StringRef> MissingSections;
for (StringRef S : FilterSections) {
/// Dump each object file in \a a;
static void dumpArchive(const Archive *A) {
Error Err = Error::success();
+ unsigned I = -1;
for (auto &C : A->children(Err)) {
+ ++I;
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
- report_error(std::move(E), A->getFileName(), C);
+ report_error(std::move(E), A->getFileName(), getFileNameForError(C, I));
continue;
}
if (ObjectFile *O = dyn_cast<ObjectFile>(&*ChildOrErr.get()))