llvm.org GIT mirror llvm / 54a2768
llvm-objdump: Replace the -macho -raw option with a generic -raw-clang-ast option that works with all object container formats. Now that clang modules/PCH are object containers this option is useful to to construct pipes like llvm-objdump -raw-clang-ast foo.pcm | llvm-bcanalyzer - to inspect the AST contents in a PCH container. Will be tested via clang. Belatedly addresses review feedback for r233390. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241659 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 5 years ago
4 changed file(s) with 53 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
0 # RUN: llvm-objdump -macho -section=__data %p/Inputs/bind2.macho-x86_64 | FileCheck %s
1 # RUN: llvm-objdump -macho -section=__data -raw %p/Inputs/bind2.macho-x86_64 | FileCheck --check-prefix=RAW %s
21
32 # CHECK: bind2.macho-x86_64:
4 # RAW-NOT: bind2.macho-x86_64:
100100 llvm::DumpSections("section",
101101 cl::desc("Prints the specified segment,section for "
102102 "Mach-O objects (requires -macho)"));
103
104 cl::opt llvm::Raw("raw",
105 cl::desc("Have -section dump the raw binary contents"));
106103
107104 cl::opt
108105 llvm::InfoPlist("info-plist",
10451042 uint32_t sect_size = BytesStr.size();
10461043 uint64_t sect_addr = Section.getAddress();
10471044
1048 if (Raw) {
1049 outs().write(BytesStr.data(), BytesStr.size());
1050 continue;
1051 }
1052
10531045 outs() << "Contents of (" << SegName << "," << SectName
10541046 << ") section\n";
10551047
11781170 // UniversalHeaders or ArchiveHeaders.
11791171 if (Disassemble || PrivateHeaders || ExportsTrie || Rebase || Bind ||
11801172 LazyBind || WeakBind || IndirectSymbols || DataInCode || LinkOptHints ||
1181 DylibsUsed || DylibId || ObjcMetaData ||
1182 (DumpSections.size() != 0 && !Raw)) {
1173 DylibsUsed || DylibId || ObjcMetaData || (DumpSections.size() != 0)) {
11831174 outs() << Filename;
11841175 if (!ArchiveMemberName.empty())
11851176 outs() << '(' << ArchiveMemberName << ')';
9595 cl::opt
9696 llvm::WeakBind("weak-bind", cl::desc("Display mach-o weak binding info"));
9797
98 cl::opt
99 llvm::RawClangAST("raw-clang-ast",
100 cl::desc("Dump the raw binary contents of the clang AST section"));
101
98102 static cl::opt
99103 MachOOpt("macho", cl::desc("Use MachO specific object file parser"));
100104 static cl::alias
12961300 }
12971301 }
12981302
1303 /// Dump the raw contents of the __clangast section so the output can be piped
1304 /// into llvm-bcanalyzer.
1305 void llvm::printRawClangAST(const ObjectFile *Obj) {
1306 if (outs().is_displayed()) {
1307 errs() << "The -raw-clang-ast option will dump the raw binary contents of "
1308 "the clang ast section.\n"
1309 "Please redirect the output to a file or another program such as "
1310 "llvm-bcanalyzer.\n";
1311 return;
1312 }
1313
1314 StringRef ClangASTSectionName("__clangast");
1315 if (isa(Obj)) {
1316 ClangASTSectionName = "clangast";
1317 }
1318
1319 Optional ClangASTSection;
1320 for (auto Sec : Obj->sections()) {
1321 StringRef Name;
1322 Sec.getName(Name);
1323 if (Name == ClangASTSectionName) {
1324 ClangASTSection = Sec;
1325 break;
1326 }
1327 }
1328 if (!ClangASTSection)
1329 return;
1330
1331 StringRef ClangASTContents;
1332 if (error(ClangASTSection.getValue().getContents(ClangASTContents))) {
1333 errs() << "Could not read the " << ClangASTSectionName << " section!\n";
1334 return;
1335 }
1336
1337 outs().write(ClangASTContents.data(), ClangASTContents.size());
1338 }
1339
12991340 static void printFaultMaps(const ObjectFile *Obj) {
13001341 const char *FaultMapSectionName = nullptr;
13011342
13501391 }
13511392
13521393 static void DumpObject(const ObjectFile *o) {
1353 outs() << '\n';
1354 outs() << o->getFileName()
1355 << ":\tfile format " << o->getFileFormatName() << "\n\n";
1394 // Avoid other output when using a raw option.
1395 if (!RawClangAST) {
1396 outs() << '\n';
1397 outs() << o->getFileName()
1398 << ":\tfile format " << o->getFileFormatName() << "\n\n";
1399 }
13561400
13571401 if (Disassemble)
13581402 DisassembleObject(o, Relocations);
13781422 printLazyBindTable(o);
13791423 if (WeakBind)
13801424 printWeakBindTable(o);
1425 if (RawClangAST)
1426 printRawClangAST(o);
13811427 if (PrintFaultMaps)
13821428 printFaultMaps(o);
13831429 }
14681514 && !Bind
14691515 && !LazyBind
14701516 && !WeakBind
1517 && !RawClangAST
14711518 && !(UniversalHeaders && MachOOpt)
14721519 && !(ArchiveHeaders && MachOOpt)
14731520 && !(IndirectSymbols && MachOOpt)
2525 extern cl::opt MCPU;
2626 extern cl::list MAttrs;
2727 extern cl::list DumpSections;
28 extern cl::opt Raw;
2928 extern cl::opt Disassemble;
3029 extern cl::opt NoShowRawInsn;
3130 extern cl::opt PrivateHeaders;
3433 extern cl::opt Bind;
3534 extern cl::opt LazyBind;
3635 extern cl::opt WeakBind;
36 extern cl::opt RawClangAST;
3737 extern cl::opt UniversalHeaders;
3838 extern cl::opt ArchiveHeaders;
3939 extern cl::opt IndirectSymbols;
7171 void printBindTable(const object::ObjectFile *o);
7272 void printLazyBindTable(const object::ObjectFile *o);
7373 void printWeakBindTable(const object::ObjectFile *o);
74 void printRawClangAST(const object::ObjectFile *o);
7475 void PrintRelocations(const object::ObjectFile *o);
7576 void PrintSectionHeaders(const object::ObjectFile *o);
7677 void PrintSectionContents(const object::ObjectFile *o);