[PATCH v3 5/5] objdump: Add test on option --map-global-vars display global variable information

Guillaume VACHERIAS guillaume.vacherias@foss.st.com
Mon Sep 1 17:50:44 GMT 2025


Add test for the display 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/ChangeLog                            |  4 +
 .../binutils-all/objdump-map-global-vars.c    | 48 +++++++++++
 binutils/testsuite/binutils-all/objdump.exp   | 39 +++++++++
 .../binutils-all/objdump.map-global-vars      | 86 +++++++++++++++++++
 4 files changed, 177 insertions(+)
 create mode 100644 binutils/testsuite/binutils-all/objdump-map-global-vars.c
 create mode 100644 binutils/testsuite/binutils-all/objdump.map-global-vars

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 97513d3135c..2eaaa9f87e4 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -68,6 +68,10 @@
 
 	* doc/binutils.texi: Add documentation for new option --map-global-vars.
 
+	* testsuite/binutils-all/objdump-map-global-vars.c: New file.
+	* testsuite/binutils-all/objdump.map-global-vars: New file.
+	* testsuite/binutils-all/objdump.exp: Add new test.
+
 2025-07-13  Nick Clifton  <nickc@redhat.com>
 
 	* 2.45 Branch point.
diff --git a/binutils/testsuite/binutils-all/objdump-map-global-vars.c b/binutils/testsuite/binutils-all/objdump-map-global-vars.c
new file mode 100644
index 00000000000..4ae0d3b007c
--- /dev/null
+++ b/binutils/testsuite/binutils-all/objdump-map-global-vars.c
@@ -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;
+}
diff --git a/binutils/testsuite/binutils-all/objdump.exp b/binutils/testsuite/binutils-all/objdump.exp
index f3142b10442..80c5af681ca 100644
--- a/binutils/testsuite/binutils-all/objdump.exp
+++ b/binutils/testsuite/binutils-all/objdump.exp
@@ -959,6 +959,45 @@ 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 --map-global-vars $testfile" "" "/dev/null" "tmpdir/objdump.out"]
+
+    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+       fail "objdump --map-global-vars (reason: unexpected output)"
+       send_log $got
+       send_log "\n"
+    }
+
+    if { [regexp_diff tmpdir/objdump.out $srcdir/$subdir/objdump.map-global-vars] } then {
+      fail "objdump --map-global-vars"
+    } else {
+      pass "objdump --map-global-vars"
+    }
+}
+
+test_objdump_map_global_vars
+
 # Test objdump --private
 proc test_objdump_P {} {
     global srcdir
diff --git a/binutils/testsuite/binutils-all/objdump.map-global-vars b/binutils/testsuite/binutils-all/objdump.map-global-vars
new file mode 100644
index 00000000000..d6fed23edda
--- /dev/null
+++ b/binutils/testsuite/binutils-all/objdump.map-global-vars
@@ -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
-- 
2.25.1



More information about the Binutils mailing list