[v4,5/5] objdump: Add test on option --map-global-vars display global variable information
Commit Message
Add test for the display of global variable information.
Single generic test that takes into account the data model
conventions (ILP32, LP64, ILP64, ILP64 and LLP64).
binutils/testsuite/binutils-all
* objdump-map-global-vars.c: New test.
* objdump.map-global-vars: New test.
* objdump.exp: Add new test.
Signed-off-by: Guillaume VACHERIAS <guillaume.vacherias@foss.st.com>
---
.../binutils-all/objdump-map-global-vars.c | 48 +++++++++++
binutils/testsuite/binutils-all/objdump.exp | 63 ++++++++++++++
.../binutils-all/objdump.map-global-vars | 86 +++++++++++++++++++
3 files changed, 197 insertions(+)
create mode 100644 binutils/testsuite/binutils-all/objdump-map-global-vars.c
create mode 100644 binutils/testsuite/binutils-all/objdump.map-global-vars
Comments
On 09.09.2025 14:43, Guillaume VACHERIAS wrote:
> Add test for the display of global variable information.
> Single generic test that takes into account the data model
> conventions (ILP32, LP64, ILP64, ILP64 and LLP64).
>
> binutils/testsuite/binutils-all
>
> * objdump-map-global-vars.c: New test.
> * objdump.map-global-vars: New test.
> * objdump.exp: Add new test.
>
> Signed-off-by: Guillaume VACHERIAS <guillaume.vacherias@foss.st.com>
My v3 remarks weren't addressed verbally, and from eyeballing I also can't
spot any change.
Jan
On 23.09.2025 01:25, Jan Beulich wrote:
> On 09.09.2025 14:43, Guillaume VACHERIAS wrote:
>> Add test for the display of global variable information.
>> Single generic test that takes into account the data model
>> conventions (ILP32, LP64, ILP64, ILP64 and LLP64).
>>
>> binutils/testsuite/binutils-all
>>
>> * objdump-map-global-vars.c: New test.
>> * objdump.map-global-vars: New test.
>> * objdump.exp: Add new test.
>>
>> Signed-off-by: Guillaume VACHERIAS <guillaume.vacherias@foss.st.com>
>
> My v3 remarks weren't addressed verbally, and from eyeballing I also can't
> spot any change.
Hmm, I then recalled that the revision log is in patch 1 (rather than the
patch itself). From that it looks like you made some adjustments. Yet
especially for the ordering independence one I'm not quite convinced this
is suitable. You now wouldn't, afaict, fail if any unexpected output
appeared.
Jan
new file mode 100644
@@ -0,0 +1,48 @@
+char a;
+int b;
+long c;
+void *d;
+
+volatile int e;
+const int f;
+
+enum _enum {
+ E1,
+ E2,
+ E3
+};
+
+enum _enum g;
+
+struct _struct {
+ char m1;
+ enum _enum m2;
+};
+
+struct _struct h;
+
+union _union {
+ char u1;
+ const char *u2;
+};
+
+union _union i;
+
+struct _node {
+ int value;
+ struct _node *next;
+};
+
+typedef struct _node node;
+
+node j;
+
+node k[4][2];
+
+char *l[2];
+
+int
+main (void)
+{
+ return 0;
+}
@@ -959,6 +959,69 @@ proc test_objdump_S { } {
test_objdump_S
+# Test objdump --map-global-vars on file containing dwarf-2 encoding information.
+
+proc test_objdump_map_global_vars { } {
+ global srcdir
+ global subdir
+ global OBJDUMP
+ global OBJDUMPFLAGS
+ global exe
+
+ set test "objdump --map-global-vars"
+
+ if { [target_compile $srcdir/$subdir/objdump-map-global-vars.c tmpdir/objdump-map-global-vars${exe} executable debug] != "" } {
+ unsupported "$test (build)"
+ return
+ }
+
+ if [is_remote host] {
+ set testfile [remote_download host tmpdir/objdump-map-global-vars${exe}]
+ } else {
+ set testfile tmpdir/objdump-map-global-vars${exe}
+ }
+
+ set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS --dwarf=info $testfile"]
+ if { [regexp -line {^ *Version: *([0-9]+)} $got -> dwarf_version] } then {
+ if {$dwarf_version < 2} then {
+ unsupported "$test (DWARF2 at least is required)"
+ return
+ }
+ }
+
+ set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS --map-global-vars $testfile"]
+
+ if [is_remote host] {
+ set pattern_file [remote_download host $srcdir/$subdir/objdump.map-global-vars]
+ } else {
+ set pattern_file $srcdir/$subdir/objdump.map-global-vars
+ }
+
+ set pattern_file [open $pattern_file r]
+ set patterns [read $pattern_file]
+ close $pattern_file
+
+ set got_block [split $got "\n\n"]
+ set pattern_list [split $patterns "\n\n"]
+
+ foreach block $got_block {
+ set matched 0
+ foreach pattern $pattern_list {
+ if {[regexp $pattern $block match]} {
+ set matched 1
+ break
+ }
+ }
+ if (!$matched) {
+ fail "objdump --map-global-vars"
+ }
+ }
+
+ pass "objdump --map-global-vars"
+}
+
+test_objdump_map_global_vars
+
# Test objdump --private
proc test_objdump_P {} {
global srcdir
new file mode 100644
@@ -0,0 +1,86 @@
+.*objdump-map-global-vars: file format .*
+
+a @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: char, size: 0x1
+
+b @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: int, size: 0x(2|4|8)
+
+c @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: long .*, size: 0x(4|8)
+
+d @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: ptr, size: 0x(4|8)
+
+e @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: volatile
+ type: int, size: 0x(2|4|8)
+
+f @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: const
+ type: int, size: 0x(2|4|8)
+
+g @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: enum _enum, size: 0x(2|4)
+ {
+ value: E1 = 0
+ value: E2 = 1
+ value: E3 = 2
+ }
+
+h @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: struct _struct, size: 0x(4|8)
+ {
+ member: m1, offset: 0x0
+ type: char, size: 0x1
+ member: m2, offset: 0x(4|8)
+ type: enum _enum, size: 0x(2|4)
+ {
+ value: E1 = 0
+ value: E2 = 1
+ value: E3 = 2
+ }
+ }
+
+i @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: union _union, size: 0x(2|4|8)
+ {
+ member: u1, offset: 0x0
+ type: char, size: 0x1
+ member: u2, offset: 0x0
+ type: ptr, size: 0x(2|4|8)
+ type: const
+ type: char, size: 0x1
+ }
+
+j @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: typedef node
+ {
+ type: struct _node, size: 0x(4|8|10)
+ {
+ member: value, offset: 0x0
+ type: int, size: 0x(2|4|8)
+ member: next, offset: 0x(4|8)
+ type: ptr, size: 0x(2|4|8)
+ nested: struct _node
+ }
+ }
+
+k @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: array\[4\]\[2\]
+ type: typedef node
+ {
+ type: struct _node, size: 0x(4|8|10)
+ {
+ member: value, offset: 0x0
+ type: int, size: 0x(2|4|8)
+ member: next, offset: 0x8
+ type: ptr, size: 0x(2|4|8)
+ nested: struct _node
+ }
+ }
+
+l @ 0x([0-9a-fA-F]{8}) 0x([0-9a-fA-F]{8})
+ type: array\[2\]
+ type: ptr, size: 0x(2|4|8)
+ type: char, size: 0x1