From: Andreas Arnez Date: Tue, 13 Jun 2017 13:20:26 +0000 (+0200) Subject: gdb/testsuite: Add "get_endianness" convenience proc X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=805acca042afed8e8431c92ab031167b03475676;p=binutils-gdb.git gdb/testsuite: Add "get_endianness" convenience proc The test suite contains multiple instances of determining the target's endianness with GDB's "show endian" command. This patch replaces these by an invocation of a new convenience proc 'get_endianness'. gdb/testsuite/ChangeLog: * lib/gdb.exp (get_endianness): New proc. * gdb.arch/aarch64-fp.exp: Use it. * gdb.arch/altivec-regs.exp: Likewise. * gdb.arch/e500-regs.exp: Likewise. * gdb.arch/vsx-regs.exp: Likewise. * gdb.base/dump.exp: Likewise. * gdb.base/funcargs.exp: Likewise. * gdb.base/gnu_vector.exp: Likewise. * gdb.dwarf2/formdata16.exp: Likewise. * gdb.dwarf2/implptrpiece.exp: Likewise. * gdb.dwarf2/nonvar-access.exp: Likewise. * gdb.python/py-inferior.exp: Likewise. * gdb.trace/unavailable-dwarf-piece.exp: Likewise. --- diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 882ec3ae73c..878d08de607 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,19 @@ +2017-06-13 Andreas Arnez + + * lib/gdb.exp (get_endianness): New proc. + * gdb.arch/aarch64-fp.exp: Use it. + * gdb.arch/altivec-regs.exp: Likewise. + * gdb.arch/e500-regs.exp: Likewise. + * gdb.arch/vsx-regs.exp: Likewise. + * gdb.base/dump.exp: Likewise. + * gdb.base/funcargs.exp: Likewise. + * gdb.base/gnu_vector.exp: Likewise. + * gdb.dwarf2/formdata16.exp: Likewise. + * gdb.dwarf2/implptrpiece.exp: Likewise. + * gdb.dwarf2/nonvar-access.exp: Likewise. + * gdb.python/py-inferior.exp: Likewise. + * gdb.trace/unavailable-dwarf-piece.exp: Likewise. + 2017-06-13 Andreas Arnez PR gdb/21226 diff --git a/gdb/testsuite/gdb.arch/aarch64-fp.exp b/gdb/testsuite/gdb.arch/aarch64-fp.exp index 2faf121a33d..483c8f1816f 100644 --- a/gdb/testsuite/gdb.arch/aarch64-fp.exp +++ b/gdb/testsuite/gdb.arch/aarch64-fp.exp @@ -34,14 +34,7 @@ if ![runto_main] { return -1 } -set endianness "little" -set test "show endian" -gdb_test_multiple $test $test { - -re "(.* )(big|little)( endian.*)$gdb_prompt $" { - set endianness $expect_out(2,string) - pass "endianness" - } -} +set endianness [get_endianness] gdb_test "break ${srcfile}:[gdb_get_line_number "return"]" \ "Breakpoint $decimal at 0x\[0-9a-fA-F\]+: file .*${srcfile}.*\\\." \ diff --git a/gdb/testsuite/gdb.arch/altivec-regs.exp b/gdb/testsuite/gdb.arch/altivec-regs.exp index b3b5aed5db5..165f61a194a 100644 --- a/gdb/testsuite/gdb.arch/altivec-regs.exp +++ b/gdb/testsuite/gdb.arch/altivec-regs.exp @@ -77,17 +77,7 @@ gdb_test "set \$vrsave = 1" "" "" gdb_test "next" "" "" -set endianness "" -set msg "detect endianness" -gdb_test_multiple "show endian" "$msg" { - -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" { - pass "$msg" - set endianness $expect_out(2,string) - } - -re ".*$gdb_prompt $" { - fail "$msg" - } -} +set endianness [get_endianness] # And then read the AltiVec registers back, to see that # a) the register write above worked, and diff --git a/gdb/testsuite/gdb.arch/e500-regs.exp b/gdb/testsuite/gdb.arch/e500-regs.exp index 8bf405a9afe..bab6e7ddbd2 100644 --- a/gdb/testsuite/gdb.arch/e500-regs.exp +++ b/gdb/testsuite/gdb.arch/e500-regs.exp @@ -59,17 +59,7 @@ for {set i 0} {$i < 32} {incr i 1} { #gdb_test "next" "" "" -send_gdb "show endian\n" -gdb_expect { - -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" { - pass "endianness" - set endianness $expect_out(2,string) - } - -re ".*$gdb_prompt $" { - fail "couldn't get endianness" - } - timeout { fail "(timeout) endianness" } -} +set endianness [get_endianness] # And then read the E500 registers back, to see that # a) the register write above worked, and diff --git a/gdb/testsuite/gdb.arch/vsx-regs.exp b/gdb/testsuite/gdb.arch/vsx-regs.exp index 15e7196367a..e6b8d726366 100644 --- a/gdb/testsuite/gdb.arch/vsx-regs.exp +++ b/gdb/testsuite/gdb.arch/vsx-regs.exp @@ -56,17 +56,7 @@ if ![runto_main] then { gdb_suppress_tests } -set endianness "" -set msg "detect endianness" -gdb_test_multiple "show endian" "$msg" { - -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" { - pass "$msg" - set endianness $expect_out(2,string) - } - -re ".*$gdb_prompt $" { - fail "$msg" - } -} +set endianness [get_endianness] # Data sets used throughout the test diff --git a/gdb/testsuite/gdb.base/dump.exp b/gdb/testsuite/gdb.base/dump.exp index e67e1aa91e3..a9625d754b4 100644 --- a/gdb/testsuite/gdb.base/dump.exp +++ b/gdb/testsuite/gdb.base/dump.exp @@ -101,12 +101,7 @@ if { ! [ runto checkpoint1 ] } then { # Get the endianness for the later use with endianless formats. -gdb_test_multiple "show endian" "show endian" { - -re ".* (big|little) endian.*$gdb_prompt $" { - set endian $expect_out(1,string) - pass "endianness: $endian" - } -} +set endian [get_endianness] # Now generate some dump files. diff --git a/gdb/testsuite/gdb.base/funcargs.exp b/gdb/testsuite/gdb.base/funcargs.exp index 5852f12b936..c48b88203e9 100644 --- a/gdb/testsuite/gdb.base/funcargs.exp +++ b/gdb/testsuite/gdb.base/funcargs.exp @@ -1139,15 +1139,9 @@ gdb_test_multiple "print sizeof (int)" "getting sizeof int" { } } -gdb_test_multiple "show endian" "getting target endian" { - -re ".*little endian.*$gdb_prompt $" { - set target_bigendian_p 0 - # pass silently - } - -re ".*big endian.*$gdb_prompt $" { - set target_bigendian_p 1 - # pass silently - } +switch [get_endianness] { + little { set target_bigendian_p 0 } + big { set target_bigendian_p 1 } } # Perform tests diff --git a/gdb/testsuite/gdb.base/gnu_vector.exp b/gdb/testsuite/gdb.base/gnu_vector.exp index 1e0e46c2df2..44b1405107a 100644 --- a/gdb/testsuite/gdb.base/gnu_vector.exp +++ b/gdb/testsuite/gdb.base/gnu_vector.exp @@ -48,12 +48,7 @@ if { ![runto main] } { } # Get endianess for the scalar->vector casts -gdb_test_multiple "show endian" "show endian" { - -re ".* (big|little) endian.*$gdb_prompt $" { - set endian $expect_out(1,string) - pass "endianness: $endian" - } -} +set endian [get_endianness] # Test printing of character vector types gdb_test "print c4" "\\\$$decimal = \\{1, 2, 3, 4\\}" diff --git a/gdb/testsuite/gdb.dwarf2/formdata16.exp b/gdb/testsuite/gdb.dwarf2/formdata16.exp index a3ccbd39b50..752ccb4a7d5 100644 --- a/gdb/testsuite/gdb.dwarf2/formdata16.exp +++ b/gdb/testsuite/gdb.dwarf2/formdata16.exp @@ -28,14 +28,7 @@ if [prepare_for_testing "failed to prepare for endianness test" ${testfile} ${sr return -1 } -set endianness "little" -set test "show endian" -gdb_test_multiple $test $test { - -re "(.* )(big|little)( endian.*)\r\n$gdb_prompt $" { - set endianness $expect_out(2,string) - pass "endianness" - } -} +set endianness [get_endianness] set high "0x123456789abcdef0" set low "0x0fedcba987654321" diff --git a/gdb/testsuite/gdb.dwarf2/implptrpiece.exp b/gdb/testsuite/gdb.dwarf2/implptrpiece.exp index ef483c0f980..ac3ee784659 100644 --- a/gdb/testsuite/gdb.dwarf2/implptrpiece.exp +++ b/gdb/testsuite/gdb.dwarf2/implptrpiece.exp @@ -119,14 +119,8 @@ if ![runto_main] { return -1 } -# Determine endianness. -set endian "little" -gdb_test_multiple "show endian" "determine endianness" { - -re ".* (big|little) endian.*$gdb_prompt $" { - set endian $expect_out(1,string) - pass "endianness: $endian" - } -} +# Determine byte order. +set endian [get_endianness] # Access the second byte of s through an implicit pointer to the third # byte of s, using a negative offset. Compare that to the second byte of diff --git a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp index 54060291b39..b7d952a5f28 100644 --- a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp +++ b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp @@ -205,14 +205,8 @@ if ![runto_main] { return -1 } -# Determine endianness. -set endian "little" -gdb_test_multiple "show endian" "determine endianness" { - -re ".* (big|little) endian.*$gdb_prompt $" { - set endian $expect_out(1,string) - pass "endianness: $endian" - } -} +# Determine byte order. +set endian [get_endianness] # Byte-aligned objects with simple location descriptions. switch $endian { big {set val 0x345678} little {set val 0x785634} } diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index adb5df35032..c2ea2c2a4bc 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -30,15 +30,9 @@ clean_restart ${testfile} # Skip all tests if Python scripting is not enabled. if { [skip_python_tests] } { continue } -gdb_test_multiple "show endian" "getting target endian" { - -re ".*little endian.*$gdb_prompt $" { - set python_pack_char "<" - # pass silently - } - -re ".*big endian.*$gdb_prompt $" { - set python_pack_char ">" - # pass silently - } +switch [get_endianness] { + little { set python_pack_char "<" } + big { set python_pack_char ">" } } # The following tests require execution. diff --git a/gdb/testsuite/gdb.trace/unavailable-dwarf-piece.exp b/gdb/testsuite/gdb.trace/unavailable-dwarf-piece.exp index 3b14bea0703..d8a75d4809b 100644 --- a/gdb/testsuite/gdb.trace/unavailable-dwarf-piece.exp +++ b/gdb/testsuite/gdb.trace/unavailable-dwarf-piece.exp @@ -325,13 +325,7 @@ with_test_prefix "tracing bar" { gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" gdb_test_no_output "tstop" - set endian "" - gdb_test_multiple "show endian" "show endian" { - -re ".* (big|little) endian.*$gdb_prompt $" { - set endian $expect_out(1,string) - pass "endianness: $endian" - } - } + set endian [get_endianness] gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" if { $endian == "little" } { diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 6633d242965..a74f97465ec 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -5671,6 +5671,19 @@ proc set_remotetimeout { timeout } { } } +# Get the target's current endianness and return it. +proc get_endianness { } { + global gdb_prompt + + gdb_test_multiple "show endian" "determine endianness" { + -re ".* (little|big) endian.*\r\n$gdb_prompt $" { + # Pass silently. + return $expect_out(1,string) + } + } + return "little" +} + # ROOT and FULL are file names. Returns the relative path from ROOT # to FULL. Note that FULL must be in a subdirectory of ROOT. # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this