[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
This commit is contained in:
Colin LeMahieu committed 2015-07-29 19:08:10 +00:00
1 parent 7e90f694b6
commit 154b3f0725
4 files changed
+22 -27

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
// This test checks that --section works correctly // This test checks that --section works correctly
// RUN: llvm-objdump -h %p/Inputs/section-filter.obj -j=.text \ // RUN: llvm-objdump -h %p/Inputs/section-filter.obj -j=.text \
// RUN: -j=.bss | FileCheck %s // RUN: --section=.bss | FileCheck %s
# CHECK: .text # CHECK: .text
# CHECK-NOT: .data # CHECK-NOT: .data
+5 -10
View File
@@ -97,11 +97,6 @@ cl::opt<bool>
cl::desc("Print the linker optimization hints for " cl::desc("Print the linker optimization hints for "
"Mach-O objects (requires -macho)")); "Mach-O objects (requires -macho)"));
cl::list<std::string>
llvm::DumpSections("section",
cl::desc("Prints the specified segment,section for "
"Mach-O objects (requires -macho)"));
cl::opt<bool> cl::opt<bool>
llvm::InfoPlist("info-plist", llvm::InfoPlist("info-plist",
cl::desc("Print the info plist section as strings for " cl::desc("Print the info plist section as strings for "
@@ -1006,8 +1001,8 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O,
if (verbose) if (verbose)
CreateSymbolAddressMap(O, &AddrMap); CreateSymbolAddressMap(O, &AddrMap);
for (unsigned i = 0; i < DumpSections.size(); ++i) { for (unsigned i = 0; i < FilterSections.size(); ++i) {
StringRef DumpSection = DumpSections[i]; StringRef DumpSection = FilterSections[i];
std::pair<StringRef, StringRef> DumpSegSectName; std::pair<StringRef, StringRef> DumpSegSectName;
DumpSegSectName = DumpSection.split(','); DumpSegSectName = DumpSection.split(',');
StringRef DumpSegName, DumpSectName; StringRef DumpSegName, DumpSectName;
@@ -1171,7 +1166,7 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF,
// UniversalHeaders or ArchiveHeaders. // UniversalHeaders or ArchiveHeaders.
if (Disassemble || PrivateHeaders || ExportsTrie || Rebase || Bind || if (Disassemble || PrivateHeaders || ExportsTrie || Rebase || Bind ||
LazyBind || WeakBind || IndirectSymbols || DataInCode || LinkOptHints || LazyBind || WeakBind || IndirectSymbols || DataInCode || LinkOptHints ||
DylibsUsed || DylibId || ObjcMetaData || (DumpSections.size() != 0)) { DylibsUsed || DylibId || ObjcMetaData || (FilterSections.size() != 0)) {
outs() << Filename; outs() << Filename;
if (!ArchiveMemberName.empty()) if (!ArchiveMemberName.empty())
outs() << '(' << ArchiveMemberName << ')'; outs() << '(' << ArchiveMemberName << ')';
@@ -1194,7 +1189,7 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF,
PrintSectionHeaders(MachOOF); PrintSectionHeaders(MachOOF);
if (SectionContents) if (SectionContents)
PrintSectionContents(MachOOF); PrintSectionContents(MachOOF);
if (DumpSections.size() != 0) if (FilterSections.size() != 0)
DumpSectionContents(Filename, MachOOF, !NonVerbose); DumpSectionContents(Filename, MachOOF, !NonVerbose);
if (InfoPlist) if (InfoPlist)
DumpInfoPlistSectionContents(Filename, MachOOF); DumpInfoPlistSectionContents(Filename, MachOOF);
@@ -6065,7 +6060,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
diContext.reset(new DWARFContextInMemory(*DbgObj)); diContext.reset(new DWARFContextInMemory(*DbgObj));
} }
if (DumpSections.size() == 0) if (FilterSections.size() == 0)
outs() << "(" << DisSegName << "," << DisSectName << ") section\n"; outs() << "(" << DisSegName << "," << DisSectName << ") section\n";
for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) { for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
+15 -14
View File
@@ -135,8 +135,13 @@ SectionHeadersShort("headers", cl::desc("Alias for --section-headers"),
static cl::alias static cl::alias
SectionHeadersShorter("h", cl::desc("Alias for --section-headers"), SectionHeadersShorter("h", cl::desc("Alias for --section-headers"),
cl::aliasopt(SectionHeaders)); cl::aliasopt(SectionHeaders));
cl::list<std::string> cl::list<std::string>
llvm::Sections("j", cl::desc("Operate on the specified sections only")); llvm::FilterSections("section", cl::desc("Operate on the specified sections only. "
"With -macho dump segment,section"));
cl::alias
static FilterSectionsj("j", cl::desc("Alias for --section"),
cl::aliasopt(llvm::FilterSections));
cl::list<std::string> cl::list<std::string>
llvm::MAttrs("mattr", llvm::MAttrs("mattr",
@@ -175,7 +180,7 @@ static StringRef ToolName;
static int ReturnValue = EXIT_SUCCESS; static int ReturnValue = EXIT_SUCCESS;
namespace { namespace {
typedef std::function<int(llvm::object::SectionRef const &)> FilterPredicate; typedef std::function<bool(llvm::object::SectionRef const &)> FilterPredicate;
class SectionFilterIterator { class SectionFilterIterator {
public: public:
@@ -224,20 +229,16 @@ private:
llvm::object::ObjectFile const &Object; llvm::object::ObjectFile const &Object;
}; };
SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O) { SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O) {
if (Sections.empty()) {
return SectionFilter([](llvm::object::SectionRef const &) { return 0; }, O);
}
return SectionFilter([](llvm::object::SectionRef const &S) { return SectionFilter([](llvm::object::SectionRef const &S) {
if(FilterSections.empty())
return false;
llvm::StringRef String; llvm::StringRef String;
std::error_code error = S.getName(String); std::error_code error = S.getName(String);
if (error) { if (error)
return error.value(); return true;
} return std::find(FilterSections.begin(),
if (std::find(Sections.begin(), Sections.end(), FilterSections.end(),
String) != Sections.end()) { String) == FilterSections.end();
return 0;
}
return 1;
}, },
O); O);
} }
@@ -1616,7 +1617,7 @@ int main(int argc, char **argv) {
&& !(DylibsUsed && MachOOpt) && !(DylibsUsed && MachOOpt)
&& !(DylibId && MachOOpt) && !(DylibId && MachOOpt)
&& !(ObjcMetaData && MachOOpt) && !(ObjcMetaData && MachOOpt)
&& !(DumpSections.size() != 0 && MachOOpt) && !(FilterSections.size() != 0 && MachOOpt)
&& !PrintFaultMaps) { && !PrintFaultMaps) {
cl::PrintHelpMessage(); cl::PrintHelpMessage();
return 2; return 2;
+1 -2
View File
@@ -25,8 +25,7 @@ extern cl::opt<std::string> TripleName;
extern cl::opt<std::string> ArchName; extern cl::opt<std::string> ArchName;
extern cl::opt<std::string> MCPU; extern cl::opt<std::string> MCPU;
extern cl::list<std::string> MAttrs; extern cl::list<std::string> MAttrs;
extern cl::list<std::string> Sections; extern cl::list<std::string> FilterSections;
extern cl::list<std::string> DumpSections;
extern cl::opt<bool> Disassemble; extern cl::opt<bool> Disassemble;
extern cl::opt<bool> DisassembleAll; extern cl::opt<bool> DisassembleAll;
extern cl::opt<bool> NoShowRawInsn; extern cl::opt<bool> NoShowRawInsn;