[llvm] r357270 - [llvm-readelf] Allow prefix flags for -p and -x

Jordan Rupprecht via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 29 09:43:13 PDT 2019


Author: rupprecht
Date: Fri Mar 29 09:43:13 2019
New Revision: 357270

URL: http://llvm.org/viewvc/llvm-project?rev=357270&view=rev
Log:
[llvm-readelf] Allow prefix flags for -p and -x

Summary: This allows syntax like `llvm-readelf -p.data1 -x.data2`.

Reviewers: jhenderson

Reviewed By: jhenderson

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59965

Modified:
    llvm/trunk/test/tools/llvm-readobj/hexdump.test
    llvm/trunk/test/tools/llvm-readobj/string-dump.test
    llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp

Modified: llvm/trunk/test/tools/llvm-readobj/hexdump.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/hexdump.test?rev=357270&r1=357269&r2=357270&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/hexdump.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/hexdump.test Fri Mar 29 09:43:13 2019
@@ -3,3 +3,30 @@ RUN: llvm-readobj -x .text %p/../../Obje
 
 CHECK: Hex dump of section '.text':
 CHECK-NEXT: {{^}}0x00400460
+
+// Test that the -x alias can be used flexibly. Create a baseline and ensure
+// all other combinations are identical.
+RUN: llvm-readelf --file-header --hex-dump=.text \
+RUN:   %p/../../Object/Inputs/hello-world.elf-x86-64 > %t.hexdump.out
+RUN: llvm-readelf -h --hex-dump .text \
+RUN:   %p/../../Object/Inputs/hello-world.elf-x86-64 > %t.hexdump.1
+RUN: llvm-readelf -h -x .text \
+RUN:   %p/../../Object/Inputs/hello-world.elf-x86-64 > %t.hexdump.2
+RUN: llvm-readelf -h -x=.text \
+RUN:   %p/../../Object/Inputs/hello-world.elf-x86-64 > %t.hexdump.3
+RUN: llvm-readelf -h -x.text \
+RUN:   %p/../../Object/Inputs/hello-world.elf-x86-64 > %t.hexdump.4
+RUN: llvm-readelf -hx .text \
+RUN:   %p/../../Object/Inputs/hello-world.elf-x86-64 > %t.hexdump.5
+RUN: llvm-readelf -hx=.text \
+RUN:   %p/../../Object/Inputs/hello-world.elf-x86-64 > %t.hexdump.6
+RUN: llvm-readelf -hx.text \
+RUN:   %p/../../Object/Inputs/hello-world.elf-x86-64 > %t.hexdump.7
+
+RUN: cmp %t.hexdump.out %t.hexdump.1
+RUN: cmp %t.hexdump.out %t.hexdump.2
+RUN: cmp %t.hexdump.out %t.hexdump.3
+RUN: cmp %t.hexdump.out %t.hexdump.4
+RUN: cmp %t.hexdump.out %t.hexdump.5
+RUN: cmp %t.hexdump.out %t.hexdump.6
+RUN: cmp %t.hexdump.out %t.hexdump.7

Modified: llvm/trunk/test/tools/llvm-readobj/string-dump.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/string-dump.test?rev=357270&r1=357269&r2=357270&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/string-dump.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/string-dump.test Fri Mar 29 09:43:13 2019
@@ -1,13 +1,44 @@
 # Check the dumping of a section as strings.
 # RUN: yaml2obj %s > %t
 
-# RUN: llvm-readobj --string-dump=.strings --string-dump=.not_null_terminated %t | FileCheck %s
-# RUN: llvm-readobj -p=.strings -p=.not_null_terminated %t | FileCheck %s
-# RUN: llvm-readobj --string-dump=1 --string-dump=2 %t | FileCheck %s
-
-# RUN: llvm-readelf --string-dump=.strings --string-dump=.not_null_terminated %t | FileCheck %s
-# RUN: llvm-readelf -p=.strings -p=.not_null_terminated %t | FileCheck %s
-# RUN: llvm-readelf --string-dump=1 --string-dump=2 %t | FileCheck %s
+# RUN: llvm-readobj --string-dump=.strings \
+# RUN:   --string-dump=.not_null_terminated %t > %t.readobj.out
+# RUN: FileCheck %s --input-file=%t.readobj.out
+
+# Also test the different ways --string-dump can be specified, i.e. as a short
+# flag (-p), with different prefix modes (-p .foo, -p=.foo, -p.foo), and with
+# the value being a index section number instead of a section name.
+# RUN: llvm-readobj -p=.strings -p=.not_null_terminated %t > %t.readobj.1
+# RUN: llvm-readobj -p.strings -p.not_null_terminated %t > %t.readobj.2
+# RUN: llvm-readobj --string-dump=1 --string-dump=2 %t > %t.readobj.3
+# RUN: llvm-readobj -p1 -p2 %t > %t.readobj.4
+# RUN: llvm-readobj -p=1 -p=2 %t > %t.readobj.5
+
+# RUN: cmp %t.readobj.out %t.readobj.1
+# RUN: cmp %t.readobj.out %t.readobj.2
+# RUN: cmp %t.readobj.out %t.readobj.3
+# RUN: cmp %t.readobj.out %t.readobj.4
+# RUN: cmp %t.readobj.out %t.readobj.5
+
+# Run readelf flag tests with an additional flag, --file-header, so we can test
+# -p grouped with something.
+# RUN: llvm-readelf --file-header --string-dump=.strings \
+# RUN:   --string-dump=.not_null_terminated %t > %t.readelf.out
+# RUN: FileCheck %s --input-file=%t.readelf.out
+
+# RUN: llvm-readelf -h -p=.strings -p=.not_null_terminated %t > %t.readelf.1
+# RUN: llvm-readelf -p.strings -hp.not_null_terminated %t > %t.readelf.2
+# RUN: llvm-readelf -h --string-dump=1 --string-dump=2 %t > %t.readelf.3
+# RUN: llvm-readelf -hp1 -p2 %t > %t.readelf.4
+# RUN: llvm-readelf -hp 1 -p.not_null_terminated %t > %t.readelf.5
+# RUN: llvm-readelf -p=1 -hp=2 %t > %t.readelf.6
+
+# RUN: cmp %t.readelf.out %t.readelf.1
+# RUN: cmp %t.readelf.out %t.readelf.2
+# RUN: cmp %t.readelf.out %t.readelf.3
+# RUN: cmp %t.readelf.out %t.readelf.4
+# RUN: cmp %t.readelf.out %t.readelf.5
+# RUN: cmp %t.readelf.out %t.readelf.6
 
 # CHECK:      String dump of section '.strings':
 # CHECK-NEXT: [ 0] here

Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=357270&r1=357269&r2=357270&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Fri Mar 29 09:43:13 2019
@@ -180,13 +180,13 @@ namespace opts {
   cl::list<std::string> StringDump("string-dump", cl::desc("<number|name>"),
                                    cl::ZeroOrMore);
   cl::alias StringDumpShort("p", cl::desc("Alias for --string-dump"),
-                            cl::aliasopt(StringDump));
+                            cl::aliasopt(StringDump), cl::Prefix);
 
   // -hex-dump, -x
   cl::list<std::string> HexDump("hex-dump", cl::desc("<number|name>"),
                                 cl::ZeroOrMore);
   cl::alias HexDumpShort("x", cl::desc("Alias for --hex-dump"),
-                         cl::aliasopt(HexDump));
+                         cl::aliasopt(HexDump), cl::Prefix);
 
   // -demangle, -C
   cl::opt<bool> Demangle("demangle",




More information about the llvm-commits mailing list