The crash was caused when dereferencing nullptr in DumpObject and printArchiveChild.
In DumpObject, we have
2311 StringRef ArchiveName = a != nullptr ? a->getFileName() : ""; ... 2323 printArchiveChild(a->getFileName(), *c);
2368 StringRef ArchiveName = A ? A->getFileName() : ""; ... 2378 printArchiveChild(A->getFileName(), *C);
Look, this will cause segment fault when we use -a option on Non-archive files.
Besides, in printArchiveChild
2236 static void printArchiveChild(StringRef Filename, const Archive::Child &C) { 2237 Expected<sys::fs::perms> ModeOrErr = C.getAccessMode(); ...
This can also cause segment fault when calling C.getAccessMode() (&C can be nullptr).
I update the printArchiveChild argument by taking a pointer of Archive::Child and check whether it's a nullptr.
This is a draft, I will add some tests later.
Any suggestions are welcoming, thanks
I don't think you need to worry about testing both switches in this test, as this is testing a specific aspect of the switch, rather than the generic behaviour. That will then allow you to write the llvm-objdump and FileCheck on the same line:
# RUN: llvm-objdump --archive-headers %t | FileCheck %s