llvm.org GIT mirror llvm / 154b3f0
[llvm-objdump] Merging MachO DumpSections in to FilterSections. Simplifying some predicate logic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243556 91177308-0d34-0410-b5e6-96231b3b80d8 Colin LeMahieu 5 years ago
4 changed file(s) with 22 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
0 // This test checks that --section works correctly
11 // RUN: llvm-objdump -h %p/Inputs/section-filter.obj -j=.text \
2 // RUN: -j=.bss | FileCheck %s
2 // RUN: --section=.bss | FileCheck %s
33
44 # CHECK: .text
55 # CHECK-NOT: .data
9494 cl::opt
9595 llvm::LinkOptHints("link-opt-hints",
9696 cl::desc("Print the linker optimization hints for "
97 "Mach-O objects (requires -macho)"));
98
99 cl::list
100 llvm::DumpSections("section",
101 cl::desc("Prints the specified segment,section for "
10297 "Mach-O objects (requires -macho)"));
10398
10499 cl::opt
10051000 if (verbose)
10061001 CreateSymbolAddressMap(O, &AddrMap);
10071002
1008 for (unsigned i = 0; i < DumpSections.size(); ++i) {
1009 StringRef DumpSection = DumpSections[i];
1003 for (unsigned i = 0; i < FilterSections.size(); ++i) {
1004 StringRef DumpSection = FilterSections[i];
10101005 std::pair DumpSegSectName;
10111006 DumpSegSectName = DumpSection.split(',');
10121007 StringRef DumpSegName, DumpSectName;
11701165 // UniversalHeaders or ArchiveHeaders.
11711166 if (Disassemble || PrivateHeaders || ExportsTrie || Rebase || Bind ||
11721167 LazyBind || WeakBind || IndirectSymbols || DataInCode || LinkOptHints ||
1173 DylibsUsed || DylibId || ObjcMetaData || (DumpSections.size() != 0)) {
1168 DylibsUsed || DylibId || ObjcMetaData || (FilterSections.size() != 0)) {
11741169 outs() << Filename;
11751170 if (!ArchiveMemberName.empty())
11761171 outs() << '(' << ArchiveMemberName << ')';
11931188 PrintSectionHeaders(MachOOF);
11941189 if (SectionContents)
11951190 PrintSectionContents(MachOOF);
1196 if (DumpSections.size() != 0)
1191 if (FilterSections.size() != 0)
11971192 DumpSectionContents(Filename, MachOOF, !NonVerbose);
11981193 if (InfoPlist)
11991194 DumpInfoPlistSectionContents(Filename, MachOOF);
60646059 diContext.reset(new DWARFContextInMemory(*DbgObj));
60656060 }
60666061
6067 if (DumpSections.size() == 0)
6062 if (FilterSections.size() == 0)
60686063 outs() << "(" << DisSegName << "," << DisSectName << ") section\n";
60696064
60706065 for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
134134 static cl::alias
135135 SectionHeadersShorter("h", cl::desc("Alias for --section-headers"),
136136 cl::aliasopt(SectionHeaders));
137
137138 cl::list
138 llvm::Sections("j", cl::desc("Operate on the specified sections only"));
139 llvm::FilterSections("section", cl::desc("Operate on the specified sections only. "
140 "With -macho dump segment,section"));
141 cl::alias
142 static FilterSectionsj("j", cl::desc("Alias for --section"),
143 cl::aliasopt(llvm::FilterSections));
139144
140145 cl::list
141146 llvm::MAttrs("mattr",
174179 static int ReturnValue = EXIT_SUCCESS;
175180
176181 namespace {
177 typedef std::function<int(llvm::object::SectionRef const &)> FilterPredicate;
182 typedef std::function<bool(llvm::object::SectionRef const &)> FilterPredicate;
178183
179184 class SectionFilterIterator {
180185 public:
223228 llvm::object::ObjectFile const &Object;
224229 };
225230 SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O) {
226 if (Sections.empty()) {
227 return SectionFilter([](llvm::object::SectionRef const &) { return 0; }, O);
228 }
229231 return SectionFilter([](llvm::object::SectionRef const &S) {
232 if(FilterSections.empty())
233 return false;
230234 llvm::StringRef String;
231235 std::error_code error = S.getName(String);
232 if (error) {
233 return error.value();
234 }
235 if (std::find(Sections.begin(), Sections.end(),
236 String) != Sections.end()) {
237 return 0;
238 }
239 return 1;
236 if (error)
237 return true;
238 return std::find(FilterSections.begin(),
239 FilterSections.end(),
240 String) == FilterSections.end();
240241 },
241242 O);
242243 }
16151616 && !(DylibsUsed && MachOOpt)
16161617 && !(DylibId && MachOOpt)
16171618 && !(ObjcMetaData && MachOOpt)
1618 && !(DumpSections.size() != 0 && MachOOpt)
1619 && !(FilterSections.size() != 0 && MachOOpt)
16191620 && !PrintFaultMaps) {
16201621 cl::PrintHelpMessage();
16211622 return 2;
2424 extern cl::opt ArchName;
2525 extern cl::opt MCPU;
2626 extern cl::list MAttrs;
27 extern cl::list Sections;
28 extern cl::list DumpSections;
27 extern cl::list FilterSections;
2928 extern cl::opt Disassemble;
3029 extern cl::opt DisassembleAll;
3130 extern cl::opt NoShowRawInsn;