[PATCH v6 5/5] objdump: Add test on option --map-global-vars display global variable information
Guillaume VACHERIAS
guillaume.vacherias@foss.st.com
Fri Nov 21 12:51:32 GMT 2025
More information about the Binutils mailing list
Fri Nov 21 12:51:32 GMT 2025
- Previous message (by thread): [PATCH v6 4/5] objdump: Link and display all variables information
- Next message (by thread): [PATCH v6 0/5] Objdump: New feature display of global variable info based on DWARF info section
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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-all/objdump-map-global-vars.c | 48 +++++++++++ binutils/testsuite/binutils-all/objdump.exp | 74 ++++++++++++++++ .../binutils-all/objdump.map-global-vars | 86 +++++++++++++++++++ 3 files changed, 208 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/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..c6f06f53246 100644 --- a/binutils/testsuite/binutils-all/objdump.exp +++ b/binutils/testsuite/binutils-all/objdump.exp @@ -959,6 +959,80 @@ 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}] + set patternfile [remote_download host tmpdir/objdump.map-global-vars] + } else { + set testfile tmpdir/objdump-map-global-vars${exe} + set patternfile $srcdir/$subdir/objdump.map-global-vars + } + + 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" "" "/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" + } + + # Read and split patterns by double newline using regsub and split + set pattern_file [open $patternfile r] + set pattern_data [read $pattern_file] + close $pattern_file + + set marked_pattern_blocks [regsub -all {\n\n} $pattern_data ";"] + set pattern_blocks [split $marked_pattern_blocks ";"] + + # Read and split output into blocks by double newline using regsub and split + set output_file [open "tmpdir/objdump.out" r] + set output_data [read $output_file] + close $output_file + + set marked_output_blocks [regsub -all {\n\n} $output_data ";"] + set output_blocks [split $marked_output_blocks ";"] + + # Match each output block against all patterns, order independent + foreach oblock $output_blocks { + if {$oblock eq ""} { continue } + set matched 0 + foreach pblock $pattern_blocks { + if {[regexp $pblock $oblock]} { + set matched 1 + } + } + if {!$matched} { + fail "objdump --map-global-vars $oblock did not found any match" + return + } + } + 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..d8f900c5141 --- /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: 0 + 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: 0 + type: char, size: 0x1 + member: u2, offset: 0 + 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: 0 + 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: 0 + 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 \ No newline at end of file -- 2.43.0
- Previous message (by thread): [PATCH v6 4/5] objdump: Link and display all variables information
- Next message (by thread): [PATCH v6 0/5] Objdump: New feature display of global variable info based on DWARF info section
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list