Skip to content

Commit

Permalink
gdb/riscv/testsuite: fix failures in gdb.arch/riscv-reg-aliases.exp
Browse files Browse the repository at this point in the history
When running on a native RISC-V Linux target I currently see failures
in the gdb.arch/riscv-reg-aliases.exp test like this:

  set $ft0.float = 501
  (gdb) PASS: gdb.arch/riscv-reg-aliases.exp: write non-zero value to ft0
  p/d $ft0.float
  $263 = 1140490240
  (gdb) FAIL: gdb.arch/riscv-reg-aliases.exp: read ft0 after non-zero write to ft0

This test started failing after this commit:

  commit 56262a9
  Date:   Thu Feb 17 13:43:59 2022 -0700

      Change how "print/x" displays floating-point value

The problem is that when 501 is written to $ft0.float the value is
converted to floating point format and stored in the register.  Prior
to the above commit printing with /x and /d would first extract the
value as a float, and then convert the value to an integer for
display.  After the above commit GDB now uses the raw register value
when displaying /x and /d, and so we see this behaviour:

  (gdb) info registers $ft0
  ft0            {float = 501, double = 5.6347704700123827e-315}	(raw 0x0000000043fa8000)
  (gdb) p/f $ft0.float
  $1 = 501
  (gdb) p/d $ft0.float
  $2 = 1140490240
  (gdb) p/x $ft0.float
  $3 = 0x43fa8000

To fix this test I now print the float registers using the /f format
rather than /d.  With this change the test now passes.
  • Loading branch information
T-J-Teru committed Aug 9, 2022
1 parent 410a346 commit c1abad9
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions gdb/testsuite/gdb.arch/riscv-reg-aliases.exp
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,22 @@ proc check_zero_register_value {testname} {
# and we need to read/write using a ".float" extension. This is passed in
# REG_EXTENSION. If no extension is needed then REG_EXTENSION is the empty
# string.
proc check_setting_registers_to_zero { reg_set reg_extension } {
#
# PRINT_FMT is used when inspecting the registers, and should be a
# character that can be used in a GDB print command as an output
# format, e.g. 'd' (decimal), or 'f' (float).
proc check_setting_registers_to_zero { reg_set reg_extension print_fmt } {
foreach reg_desc ${reg_set} {
set primary_name [lindex ${reg_desc} 0]
set alias_names [lindex ${reg_desc} 1]

gdb_test_no_output "set \$${primary_name}${reg_extension} = 0" \
"set register ${primary_name} to an initial value of zero"
gdb_test "p/d \$${primary_name}${reg_extension}" " = 0" \
gdb_test "p/${print_fmt} \$${primary_name}${reg_extension}" " = 0" \
"check the initial value of ${primary_name} is now zero"

foreach reg_alias ${alias_names} {
gdb_test "p/d \$${reg_alias}${reg_extension}" " = 0" \
gdb_test "p/${print_fmt} \$${reg_alias}${reg_extension}" " = 0" \
"check the initial value of ${reg_alias} is now zero"
}
}
Expand All @@ -94,7 +98,11 @@ proc check_setting_registers_to_zero { reg_set reg_extension } {
# of the aliases.
#
# The REG_EXTENSION field is used as in CHECK_SETTING_REGISTERS_TO_ZERO.
proc check_setting_registers_to_value { reg_set reg_extension reg_value } {
#
# PRINT_FMT is used when inspecting the registers, and should be a
# character that can be used in a GDB print command as an output
# format, e.g. 'd' (decimal), or 'f' (float).
proc check_setting_registers_to_value { reg_set reg_extension reg_value print_fmt } {
foreach reg_desc ${reg_set} {
set primary_name [lindex ${reg_desc} 0]
set alias_names [lindex ${reg_desc} 1]
Expand All @@ -104,10 +112,10 @@ proc check_setting_registers_to_value { reg_set reg_extension reg_value } {
set reg_value [incr reg_value]
gdb_test_no_output "set \$${primary_name}${reg_extension} = $reg_value" \
"write non-zero value to ${primary_name}"
gdb_test "p/d \$${primary_name}${reg_extension}" " = $reg_value" \
gdb_test "p/${print_fmt} \$${primary_name}${reg_extension}" " = $reg_value" \
"read ${primary_name} after non-zero write to ${primary_name}"
foreach reg_alias ${alias_names} {
gdb_test "p/d \$${reg_alias}${reg_extension}" " = $reg_value" \
gdb_test "p/${print_fmt} \$${reg_alias}${reg_extension}" " = $reg_value" \
"read ${reg_alias} after non-zero write to ${primary_name}"
}

Expand All @@ -119,11 +127,11 @@ proc check_setting_registers_to_value { reg_set reg_extension reg_value } {
gdb_test_no_output "set \$${reg_alias}${reg_extension} = $reg_value" \
"write non-zero value to ${reg_alias}"

gdb_test "p/d \$${primary_name}${reg_extension}" " = $reg_value" \
gdb_test "p/${print_fmt} \$${primary_name}${reg_extension}" " = $reg_value" \
"read ${primary_name} after non-zero write to ${reg_alias}"

foreach other_reg_alias ${alias_names} {
gdb_test "p/d \$${other_reg_alias}${reg_extension}" " = $reg_value" \
gdb_test "p/${print_fmt} \$${other_reg_alias}${reg_extension}" " = $reg_value" \
"read ${other_reg_alias} after non-zero write to ${reg_alias}"
}
}
Expand Down Expand Up @@ -173,19 +181,19 @@ gdb_assert ![string eq "${freg_extension}" "INVALID"] \

# Now check that we can write zero, and read zero back to all of the integer
# and floating point registers.
check_setting_registers_to_zero ${xreg_names} ""
check_setting_registers_to_zero ${xreg_names} "" "d"

if { ! $skip_freg_tests } {
check_setting_registers_to_zero ${freg_names} ${freg_extension}
check_setting_registers_to_zero ${freg_names} ${freg_extension} "f"
}

# Set each register in turn to a new value, and confirm that the new value can
# be read back from the primary name, and from all of the alias names. The
# value passed in to each test invocation here is arbitrary, they are
# significantly different so that the float tests don't reuse value from the
# integer tests.
check_setting_registers_to_value ${xreg_names} "" 100
check_setting_registers_to_value ${xreg_names} "" 100 "d"

if { ! $skip_freg_tests } {
check_setting_registers_to_value ${freg_names} ${freg_extension} 500
check_setting_registers_to_value ${freg_names} ${freg_extension} 500 "f"
}

0 comments on commit c1abad9

Please sign in to comment.