Files
binutils-gdb/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp
Joel Brobecker b26daff97c fix printing of DWARF fixed-point type objects with format modifier
Consider a fixed-point type such the scaling factor is 1/16,
as the following Ada code snippet would create:

      type FP1_Type is delta 0.1 range -1.0 .. +1.0;
      FP1_Var : FP1_Type := 0.25;

Printing the value of this variable with a format modifier yields
the wrong value. E.g.:

    (gdb) p /x fp1_var
    $6 = 0x4

Since the real value is 0.25, we therefore expected...

    (gdb) p /x fp1_var
    $6 = 0x0

What happens, in this case, is that the value being printed is
actually the "raw" value of our object, before the scaling factor
gets applied.

This commit fixes the issue by using approach as for float values,
where we convert the value into an integer value, prior to printing,
knowing that the conversion takes the scaling factor into account.

gdb/ChangeLog:

        * printcmd.c (print_scalar_formatted): Add fixed-point type
        handling when options->format is set.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/dw2-fixed-point.exp: Add "print /x" tests.
2020-11-15 03:14:24 -05:00

145 lines
4.5 KiB
Plaintext

# Copyright 2016-2020 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
if {![dwarf2_support]} {
return 0
}
standard_testfile dw2-fixed-point.c dw2-fixed-point-dw.S
# Make some DWARF for the test.
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
cu {} {
DW_TAG_compile_unit {
{DW_AT_language @DW_LANG_Ada95}
{DW_AT_name pck.ads}
{DW_AT_comp_dir /tmp}
} {
declare_labels fp1_base_type fp2_base_type fp3_small \
fp3_base_type fp1_range_type
fp1_base_type: DW_TAG_base_type {
{DW_AT_byte_size 1 DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_signed_fixed}
{DW_AT_name pck__fp1_type}
{DW_AT_binary_scale -4 DW_FORM_sdata}
}
DW_TAG_variable {
{DW_AT_name pck__fp1_var}
{DW_AT_type :$fp1_base_type}
{DW_AT_location {
DW_OP_addr [gdb_target_symbol pck__fp1_var]
} SPECIAL_expr}
{external 1 flag}
}
fp2_base_type: DW_TAG_base_type {
{DW_AT_byte_size 1 DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_signed_fixed}
{DW_AT_name pck__fp2_type}
{DW_AT_decimal_scale -2 DW_FORM_sdata}
}
DW_TAG_variable {
{DW_AT_name pck__fp2_var}
{DW_AT_type :$fp2_base_type}
{DW_AT_location {
DW_OP_addr [gdb_target_symbol pck__fp2_var]
} SPECIAL_expr}
{external 1 flag}
}
fp3_small: DW_TAG_constant {
{DW_AT_GNU_numerator 1 DW_FORM_data1}
{DW_AT_GNU_denominator 30 DW_FORM_sdata}
}
fp3_base_type: DW_TAG_base_type {
{DW_AT_byte_size 1 DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_signed_fixed}
{DW_AT_name pck__fp3_type}
{DW_AT_small :$fp3_small}
}
DW_TAG_variable {
{DW_AT_name pck__fp3_var}
{DW_AT_type :$fp3_base_type}
{DW_AT_location {
DW_OP_addr [gdb_target_symbol pck__fp3_var]
} SPECIAL_expr}
{external 1 flag}
}
fp1_range_type: DW_TAG_subrange_type {
{DW_AT_lower_bound 0xf0 DW_FORM_data1}
{DW_AT_upper_bound 0x10 DW_FORM_data1}
{DW_AT_name foo__fp1_range_type}
{DW_AT_type :$fp1_base_type}
}
DW_TAG_variable {
{DW_AT_name pck__fp1_range_var}
{DW_AT_type :$fp1_range_type}
{DW_AT_location {
DW_OP_addr [gdb_target_symbol pck__fp1_range_var]
} SPECIAL_expr}
{external 1 flag}
}
}
}
}
if { [prepare_for_testing ${testfile}.exp ${testfile} \
[list $srcfile $asm_file] {nodebug}] } {
return -1
}
if ![runto_main] {
return -1
}
# Do the testing in Ada mode, since this is the language for which
# this feature has been implemented, and where we know the language
# has the concept of fixed-point types.
gdb_test_no_output "set lang ada"
gdb_test "print pck.fp1_var" \
" = 0.25"
gdb_test "print /x pck.fp1_var" \
" = 0x0"
gdb_test "print pck.fp2_var" \
" = -0.01"
gdb_test "print /x pck.fp2_var" \
" = 0x0"
gdb_test "print pck.fp3_var" \
" = 0.1"
gdb_test "print /x pck.fp3_var" \
" = 0x0"
gdb_test "print pck.fp1_range_var" \
" = 1"
gdb_test "print /x pck.fp1_range_var" \
" = 0x1"