binutils-gdb/gdb/testsuite/gdb.base/dfp-test.exp

389 lines
17 KiB
Plaintext
Raw Normal View History

# Copyright (C) 2007-2017 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/>.
# This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
# This file is part of the gdb testsuite. It is intended to test that
# gdb could correctly handle decimal floating point introduced in IEEE 754R.
standard_testfile .c
# Try to compile the test case. If we can't, assume the
# toolchain does not yet provide DFP support and bail out.
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {quiet debug}] != "" } {
verbose "Skipping DFP tests."
return -1
}
clean_restart ${binfile}
if ![runto_main] then {
perror "couldn't run to breakpoint"
continue
}
set sizeof_long [get_sizeof "long" 4]
proc d32_set_tests {} {
gdb_test "p d32=123.45df" " = 123.45"
gdb_test "p d32=12345.df" " = 12345"
gdb_test "p d32=12345.67df" " = 12345.67"
gdb_test "p d32=1234567.df" " = 1234567"
gdb_test "p d32=1.234567E0df" " = 1.234567"
gdb_test "p d32=1.234567E10df" " = 1.234567E\\+10"
gdb_test "p d32=1.234567E+96df" " = 1.234567E\\+96"
# Test that gdb could handle the max, normalized min and subnormalized min.
gdb_test "p d32=9.999999E96df" " = 9.999999E\\+96"
gdb_test "p d32=1.0E-95df" " = 1.0E\\-95"
gdb_test "p d32=1.E-101df" " = 1E\\-101"
gdb_test "p d32=0.000001E-95df" " = 1E\\-101"
# Test that gdb could detect coefficient/exponent out of range.
# The coefficient out of range will be rounded to its nearest value.
# And the exponent out of range will be handled as infinity.
gdb_test "p d32=1.2345678df" " = 1.234568" "1.2345678 is rounded to 1.234568"
gdb_test "p d32=1.0E-101df" " = 1E-101" "1.0E-101 is rounded to 1E-101"
gdb_test "p d32=1.234567E+97df" " = Infinity" "1.234567E+97 is Infinity"
# Test that gdb could detect the errors in the string representation of _Decimal32
gdb_test "p d32=12345.df" " = 12345" "12345. is a valid number"
gdb_test "p d32=12345df" ".*Invalid number.*" "12345 is an invalid number"
gdb_test "p d32=1.23Edf" ".*Conversion syntax.*" "1.23E is an invalid number"
gdb_test "p d32=1.23E45Adf" ".*Conversion syntax.*" "1.23E45A is an invalid number"
}
proc d64_set_tests {} {
gdb_test "p d64=123.45dd" " = 123.45"
gdb_test "p d64=12345.dd" " = 12345"
gdb_test "p d64=12345.67dd" " = 12345.67"
gdb_test "p d64=1.234567890123456dd" " = 1.234567890123456"
gdb_test "p d64=1.234567890123456E10dd" " = 12345678901.23456"
gdb_test "p d64=1.234567890123456E100dd" " = 1.234567890123456E\\+100"
gdb_test "p d64=1.234567890123456E384dd" " = 1.234567890123456E\\+384"
# Test that gdb could handle the max, normalized min and subnormalized min.
gdb_test "p d64=9.999999999999999E384dd" " = 9.999999999999999E\\+384"
gdb_test "p d64=1.E-383dd" " = 1E\\-383"
gdb_test "p d64=1.E-398dd" " = 1E\\-398"
gdb_test "p d64=0.000000000000001E-383dd" " = 1E\\-398"
# Test that gdb could detect coefficient/exponent out of range.
# The coefficient out of range will be rounded to its nearest value.
# And the exponent out of range will be handled as infinity.
gdb_test "p d64=1.2345678901234567dd" " = 1.234567890123457" "1.2345678901234567 is rounded to 1.234567890123457"
gdb_test "p d64=9.9999999999999999E384dd" " = Infinity" "d64=9.9999999999999999E384 is Infinity"
gdb_test "p d64=1.234567890123456E385dd" " = Infinity" "d64=1.234567890123456E385 is Infinity"
# Test that gdb could detect the errors in the string representation of _Decimal64
gdb_test "p d64=12345dd" ".*Invalid number.*" "12345dd is an invalid number"
gdb_test "p d64=1.23Edd" ".*Conversion syntax.*" "1.23E is an invalid number"
gdb_test "p d64=1.23E45Add" ".*Conversion syntax.*" "1.23E45A is an invalid number"
}
proc d128_set_tests {} {
gdb_test "p d128=123.45dl" " = 123.45"
gdb_test "p d128=12345.dl" " = 12345"
gdb_test "p d128=12345.67dl" " = 12345.67"
gdb_test "p d128=1.234567890123456789012345678901234dl" " = 1.234567890123456789012345678901234"
gdb_test "p d128=1.234567890123456E10dl" " = 12345678901.23456"
gdb_test "p d128=1.234567890123456E100dl" " = 1.234567890123456E\\+100"
gdb_test "p d128=1.234567890123456E1000dl" " = 1.234567890123456E\\+1000"
# Test that gdb could handle the max, normalized min and subnormalized min.
gdb_test "p d128=9.999999999999999999999999999999999E6144dl" " = 9.999999999999999999999999999999999E\\+6144"
gdb_test "p d128=1.E-6143dl" " = 1E\\-6143"
gdb_test "p d128=1.E-6176dl" " = 1E\\-6176"
gdb_test "p d128=0.000000000000000000000000000000001E-6143dl" " = 1E\\-6176"
# Test that gdb could detect coefficient/exponent out of range.
# The coefficient out of range will be rounded to its nearest value.
# And the exponent out of range will be handled as infinity.
gdb_test "p d128=1.2345678901234567890123456789012345dl" "1.234567890123456789012345678901234" "1.2345678901234567890123456789012345 is rounded to 1.234567890123456789012345678901234"
gdb_test "p d128=1.234567890123456E6145dl" "Infinity" "d128=1.234567890123456E6145 is Infinity"
# Test that gdb could detect the errors in the string representation of _Decimal128
gdb_test "p d128=12345dl" ".*Invalid number.*" "12345dl is an invalid number"
gdb_test "p d128=1.23Edl" ".*Conversion syntax.*" "1.23E is an invalid number"
gdb_test "p d128=1.23E45Adl" ".*Conversion syntax.*" "1.23E45A is an invalid number"
}
# Different tests on 32-bits decimal floating point, including the printing
# of finite numbers, infinite and NaN, and also the setting of different
# decimal value.
if [gdb_test "next" \
".*Positive infd32.*" \
"next after initializing d32"] then { gdb_suppress_tests }
gdb_test "print d32" "1.2345" "d32 is initialized to 1.2345"
if [gdb_test "next" \
".*Negative infd32.*" \
"next after assigning builtin infinity to d32"] then { gdb_suppress_tests }
gdb_test "print d32" "Infinity" "d32 is positive Infinity"
if [gdb_test "next" \
".*__builtin_nand32.*" \
"next after assigning negative builtin infinity to d32"] then { gdb_suppress_tests }
gdb_test "print d32" "-Infinity" "d32 is negative Infinity"
if [gdb_test "next" \
".*d64 = 1.2345.*" \
"next after assigning builtin NaN to d32"] then { gdb_suppress_tests }
gdb_test "print d32" "NaN" "d32 is NaN"
d32_set_tests
# Different tests on 64-bits decimal floating point, including the display
# of finite number, infinite and NaN, and also the setting of different
# decimal value.
if [gdb_test "next" \
".*Positive infd64.*" \
"next after initializing d64"] then { gdb_suppress_tests }
gdb_test "print d64" "1.2345" "d64 is initialized to 1.2345"
if [gdb_test "next" \
".*Negative infd64.*" \
"next after assigning builtin infinity to d64"] then { gdb_suppress_tests }
gdb_test "print d64" "Infinity" "d64 is positive Infinity"
if [gdb_test "next" \
".*__builtin_nand64.*" \
"next after assigning negative builtin infinity to d64"] then { gdb_suppress_tests }
gdb_test "print d64" "-Infinity" "d64 is negative Infinity"
if [gdb_test "next" \
".*d128 = 1.2345.*" \
"next after assigning builtin NaN to d64"] then { gdb_suppress_tests }
gdb_test "print d64" "NaN" "d64 is NaN"
d64_set_tests
# Different tests on 128-bits decimal floating point, including the display
# of finite number, infinite and NaN, and also the setting of different
# decimal value.
if [gdb_test "next" \
".*Positive infd128.*" \
"next after initializing d128"] then { gdb_suppress_tests }
gdb_test "print d128" "1.2345" "d128 is initialized to 1.2345"
d128_set_tests
if [gdb_test "next" \
".*Negative infd128.*" \
"next after assigning builtin infinity to d128"] then { gdb_suppress_tests }
gdb_test "print d128" "Infinity" "d128 is positive Infinity"
if [gdb_test "next" \
".*__builtin_nand128.*" \
"next after assigning negative builtin infinity to d128"] then { gdb_suppress_tests }
gdb_test "print d128" "-Infinity" "d128 is negative Infinity"
if [gdb_test "next" \
".*arg0_32.*" \
"next after assigning builtin NaN to d128"] then { gdb_suppress_tests }
gdb_test "print d128" "NaN" "d128 is NaN"
# The following tests are intended to verify that gdb can correctly handle
# DFP types in function arguments.
gdb_breakpoint arg0_32
gdb_continue_to_breakpoint "entry to arg0_32"
gdb_test "backtrace" ".*arg0_32 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_32"
gdb_breakpoint arg0_64
gdb_continue_to_breakpoint "entry to arg0_64"
gdb_test "backtrace" ".*arg0_64 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_64"
gdb_breakpoint arg0_128
gdb_continue_to_breakpoint "entry to arg0_128"
gdb_test "backtrace" ".*arg0_128 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_128"
# Test calling inferior function with DFP arguments or return value.
Fix test names starting with uppercase using gdb_test on a single line. Changes in v3: Fixed incorrect substitutions. This fixes offender testcases that have test names starting with uppercase when using gdb_test in a single line construct. gdb/testsuite/ChangeLog 2016-12-01 Luis Machado <lgustavo@codesourcery.com> Fix test names starting with uppercase throughout the files. * gdb.arch/i386-mpx-simple_segv.exp * gdb.arch/i386-mpx.exp * gdb.arch/i386-permbkpt.exp * gdb.arch/pa-nullify.exp * gdb.arch/powerpc-d128-regs.exp * gdb.arch/vsx-regs.exp * gdb.base/bfp-test.exp * gdb.base/break.exp * gdb.base/breakpoint-shadow.exp * gdb.base/callfuncs.exp * gdb.base/charset.exp * gdb.base/commands.exp * gdb.base/completion.exp * gdb.base/dfp-test.exp * gdb.base/echo.exp * gdb.base/ending-run.exp * gdb.base/eval.exp * gdb.base/expand-psymtabs.exp * gdb.base/float128.exp * gdb.base/floatn.exp * gdb.base/foll-exec-mode.exp * gdb.base/gdb1056.exp * gdb.base/gdb11531.exp * gdb.base/kill-after-signal.exp * gdb.base/multi-forks.exp * gdb.base/overlays.exp * gdb.base/pending.exp * gdb.base/sepdebug.exp * gdb.base/testenv.exp * gdb.base/valgrind-db-attach.exp * gdb.base/watch_thread_num.exp * gdb.base/watchpoint-cond-gone.exp * gdb.base/watchpoint.exp * gdb.base/watchpoints.exp * gdb.cp/arg-reference.exp * gdb.cp/baseenum.exp * gdb.cp/operator.exp * gdb.cp/shadow.exp * gdb.dwarf2/dw2-op-out-param.exp * gdb.dwarf2/dw2-reg-undefined.exp * gdb.go/chan.exp * gdb.go/hello.exp * gdb.go/integers.exp * gdb.go/methods.exp * gdb.go/package.exp * gdb.guile/scm-parameter.exp * gdb.guile/scm-progspace.exp * gdb.guile/scm-value.exp * gdb.mi/mi-pending.exp * gdb.mi/user-selected-context-sync.exp * gdb.multi/multi-attach.exp * gdb.multi/tids.exp * gdb.opt/clobbered-registers-O2.exp * gdb.pascal/floats.exp * gdb.pascal/integers.exp * gdb.python/py-block.exp * gdb.python/py-events.exp * gdb.python/py-parameter.exp * gdb.python/py-symbol.exp * gdb.python/py-symtab.exp * gdb.python/py-type.exp * gdb.python/py-value.exp * gdb.python/py-xmethods.exp * gdb.python/python.exp * gdb.reverse/break-precsave.exp * gdb.reverse/consecutive-precsave.exp * gdb.reverse/finish-precsave.exp * gdb.reverse/i386-precsave.exp * gdb.reverse/machinestate-precsave.exp * gdb.reverse/sigall-precsave.exp * gdb.reverse/solib-precsave.exp * gdb.reverse/step-precsave.exp * gdb.reverse/until-precsave.exp * gdb.reverse/watch-precsave.exp * gdb.server/ext-attach.exp * gdb.server/ext-restart.exp * gdb.server/ext-run.exp * gdb.server/ext-wrapper.exp * gdb.stabs/gdb11479.exp * gdb.stabs/weird.exp * gdb.threads/attach-many-short-lived-threads.exp * gdb.threads/kill.exp * gdb.threads/watchpoint-fork.exp
2016-12-01 21:41:23 +01:00
gdb_test "call arg0_32 (1.2df, 2.2df, 3.2df, 4.2df, 5.2df, 6.2df)" "Breakpoint.*arg0_32.*" "call function with correct _Decimal32 arguments."
gdb_test "backtrace 1" "\n#\[0-9\]+ arg0_32 \\(arg0=1.2, arg1=2.2, arg2=3.2, arg3=4.2, arg4=5.2, arg5=6.2\\).*" "backtrace function with correct _Decimal32 arguments."
gdb_test "finish" " = 1.2" "correct _Decimal32 return value from called function."
Fix test names starting with uppercase using gdb_test on a single line. Changes in v3: Fixed incorrect substitutions. This fixes offender testcases that have test names starting with uppercase when using gdb_test in a single line construct. gdb/testsuite/ChangeLog 2016-12-01 Luis Machado <lgustavo@codesourcery.com> Fix test names starting with uppercase throughout the files. * gdb.arch/i386-mpx-simple_segv.exp * gdb.arch/i386-mpx.exp * gdb.arch/i386-permbkpt.exp * gdb.arch/pa-nullify.exp * gdb.arch/powerpc-d128-regs.exp * gdb.arch/vsx-regs.exp * gdb.base/bfp-test.exp * gdb.base/break.exp * gdb.base/breakpoint-shadow.exp * gdb.base/callfuncs.exp * gdb.base/charset.exp * gdb.base/commands.exp * gdb.base/completion.exp * gdb.base/dfp-test.exp * gdb.base/echo.exp * gdb.base/ending-run.exp * gdb.base/eval.exp * gdb.base/expand-psymtabs.exp * gdb.base/float128.exp * gdb.base/floatn.exp * gdb.base/foll-exec-mode.exp * gdb.base/gdb1056.exp * gdb.base/gdb11531.exp * gdb.base/kill-after-signal.exp * gdb.base/multi-forks.exp * gdb.base/overlays.exp * gdb.base/pending.exp * gdb.base/sepdebug.exp * gdb.base/testenv.exp * gdb.base/valgrind-db-attach.exp * gdb.base/watch_thread_num.exp * gdb.base/watchpoint-cond-gone.exp * gdb.base/watchpoint.exp * gdb.base/watchpoints.exp * gdb.cp/arg-reference.exp * gdb.cp/baseenum.exp * gdb.cp/operator.exp * gdb.cp/shadow.exp * gdb.dwarf2/dw2-op-out-param.exp * gdb.dwarf2/dw2-reg-undefined.exp * gdb.go/chan.exp * gdb.go/hello.exp * gdb.go/integers.exp * gdb.go/methods.exp * gdb.go/package.exp * gdb.guile/scm-parameter.exp * gdb.guile/scm-progspace.exp * gdb.guile/scm-value.exp * gdb.mi/mi-pending.exp * gdb.mi/user-selected-context-sync.exp * gdb.multi/multi-attach.exp * gdb.multi/tids.exp * gdb.opt/clobbered-registers-O2.exp * gdb.pascal/floats.exp * gdb.pascal/integers.exp * gdb.python/py-block.exp * gdb.python/py-events.exp * gdb.python/py-parameter.exp * gdb.python/py-symbol.exp * gdb.python/py-symtab.exp * gdb.python/py-type.exp * gdb.python/py-value.exp * gdb.python/py-xmethods.exp * gdb.python/python.exp * gdb.reverse/break-precsave.exp * gdb.reverse/consecutive-precsave.exp * gdb.reverse/finish-precsave.exp * gdb.reverse/i386-precsave.exp * gdb.reverse/machinestate-precsave.exp * gdb.reverse/sigall-precsave.exp * gdb.reverse/solib-precsave.exp * gdb.reverse/step-precsave.exp * gdb.reverse/until-precsave.exp * gdb.reverse/watch-precsave.exp * gdb.server/ext-attach.exp * gdb.server/ext-restart.exp * gdb.server/ext-run.exp * gdb.server/ext-wrapper.exp * gdb.stabs/gdb11479.exp * gdb.stabs/weird.exp * gdb.threads/attach-many-short-lived-threads.exp * gdb.threads/kill.exp * gdb.threads/watchpoint-fork.exp
2016-12-01 21:41:23 +01:00
gdb_test "call arg0_64 (1.2dd, 2.2dd, 3.2dd, 4.2dd, 5.2dd, 6.2dd)" "Breakpoint.*arg0_64.*" "call function with correct _Decimal64 arguments."
gdb_test "backtrace 1" "\n#\[0-9\]+ arg0_64 \\(arg0=1.2, arg1=2.2, arg2=3.2, arg3=4.2, arg4=5.2, arg5=6.2\\).*" "backtrace function with correct _Decimal64 arguments."
gdb_test "finish" " = 1.2" "correct _Decimal64 return value from called function."
Fix test names starting with uppercase using gdb_test on a single line. Changes in v3: Fixed incorrect substitutions. This fixes offender testcases that have test names starting with uppercase when using gdb_test in a single line construct. gdb/testsuite/ChangeLog 2016-12-01 Luis Machado <lgustavo@codesourcery.com> Fix test names starting with uppercase throughout the files. * gdb.arch/i386-mpx-simple_segv.exp * gdb.arch/i386-mpx.exp * gdb.arch/i386-permbkpt.exp * gdb.arch/pa-nullify.exp * gdb.arch/powerpc-d128-regs.exp * gdb.arch/vsx-regs.exp * gdb.base/bfp-test.exp * gdb.base/break.exp * gdb.base/breakpoint-shadow.exp * gdb.base/callfuncs.exp * gdb.base/charset.exp * gdb.base/commands.exp * gdb.base/completion.exp * gdb.base/dfp-test.exp * gdb.base/echo.exp * gdb.base/ending-run.exp * gdb.base/eval.exp * gdb.base/expand-psymtabs.exp * gdb.base/float128.exp * gdb.base/floatn.exp * gdb.base/foll-exec-mode.exp * gdb.base/gdb1056.exp * gdb.base/gdb11531.exp * gdb.base/kill-after-signal.exp * gdb.base/multi-forks.exp * gdb.base/overlays.exp * gdb.base/pending.exp * gdb.base/sepdebug.exp * gdb.base/testenv.exp * gdb.base/valgrind-db-attach.exp * gdb.base/watch_thread_num.exp * gdb.base/watchpoint-cond-gone.exp * gdb.base/watchpoint.exp * gdb.base/watchpoints.exp * gdb.cp/arg-reference.exp * gdb.cp/baseenum.exp * gdb.cp/operator.exp * gdb.cp/shadow.exp * gdb.dwarf2/dw2-op-out-param.exp * gdb.dwarf2/dw2-reg-undefined.exp * gdb.go/chan.exp * gdb.go/hello.exp * gdb.go/integers.exp * gdb.go/methods.exp * gdb.go/package.exp * gdb.guile/scm-parameter.exp * gdb.guile/scm-progspace.exp * gdb.guile/scm-value.exp * gdb.mi/mi-pending.exp * gdb.mi/user-selected-context-sync.exp * gdb.multi/multi-attach.exp * gdb.multi/tids.exp * gdb.opt/clobbered-registers-O2.exp * gdb.pascal/floats.exp * gdb.pascal/integers.exp * gdb.python/py-block.exp * gdb.python/py-events.exp * gdb.python/py-parameter.exp * gdb.python/py-symbol.exp * gdb.python/py-symtab.exp * gdb.python/py-type.exp * gdb.python/py-value.exp * gdb.python/py-xmethods.exp * gdb.python/python.exp * gdb.reverse/break-precsave.exp * gdb.reverse/consecutive-precsave.exp * gdb.reverse/finish-precsave.exp * gdb.reverse/i386-precsave.exp * gdb.reverse/machinestate-precsave.exp * gdb.reverse/sigall-precsave.exp * gdb.reverse/solib-precsave.exp * gdb.reverse/step-precsave.exp * gdb.reverse/until-precsave.exp * gdb.reverse/watch-precsave.exp * gdb.server/ext-attach.exp * gdb.server/ext-restart.exp * gdb.server/ext-run.exp * gdb.server/ext-wrapper.exp * gdb.stabs/gdb11479.exp * gdb.stabs/weird.exp * gdb.threads/attach-many-short-lived-threads.exp * gdb.threads/kill.exp * gdb.threads/watchpoint-fork.exp
2016-12-01 21:41:23 +01:00
gdb_test "call arg0_128 (1.2dl, 2.2dl, 3.2dl, 4.2dl, 5.2dl, 6.2dl)" "Breakpoint.*arg0_128.*" "call function with correct _Decimal128 arguments."
gdb_test "backtrace 1" "\n#\[0-9\]+ arg0_128 \\(arg0=1.2, arg1=2.2, arg2=3.2, arg3=4.2, arg4=5.2, arg5=6.2\\).*" "backtrace function with correct _Decimal128 arguments."
gdb_test "finish" " = 1.2" "correct _Decimal128 return value from called function."
gdb_test "call decimal_dec128_align (double_val1, dec128_val2, double_val3, double_val4, double_val5, double_val6, double_val7, double_val8, double_val9, double_val10, double_val11, double_val12, double_val13, double_val14)" " = 1" \
"Call function with mixed decimal float arguments TEST."
gdb_test "call decimal_mixed (dec32_val1, dec64_val1, dec128_val1)" " = 1" \
"Call function with mixed decimal float arguments."
gdb_test "call decimal_many_args_dec32 (dec32_val1, dec32_val2, dec32_val3, dec32_val4, dec32_val5, dec32_val6, dec32_val7, dec32_val8, dec32_val9, dec32_val10, dec32_val11, dec32_val12, dec32_val13, dec32_val14, dec32_val15, dec32_val16)" " = 1" \
"Call function with many _Decimal32 arguments."
gdb_test "call decimal_many_args_dec64 (dec64_val1, dec64_val2, dec64_val3, dec64_val4, dec64_val5, dec64_val6, dec64_val7, dec64_val8, dec64_val9, dec64_val10, dec64_val11, dec64_val12, dec64_val13, dec64_val14, dec64_val15, dec64_val16)" " = 1" \
"Call function with many _Decimal64 arguments."
gdb_test "call decimal_many_args_dec128 (dec128_val1, dec128_val2, dec128_val3, dec128_val4, dec128_val5, dec128_val6, dec128_val7, dec128_val8, dec128_val9, dec128_val10, dec128_val11, dec128_val12, dec128_val13, dec128_val14, dec128_val15, dec128_val16)" " = 1" \
"Call function with many _Decimal128 arguments."
gdb_test "call decimal_many_args_mixed (dec32_val1, dec32_val2, dec32_val3, dec64_val4, dec64_val5, dec64_val6, dec64_val7, dec128_val8, dec128_val9, dec128_val10, dec32_val11, dec64_val12, dec32_val13, dec64_val14, dec128_val15)" " = 1" \
"Call function with many mixed decimal float arguments."
# The following tests are intended to verify that gdb can handle DFP types
# correctly in struct.
gdb_breakpoint [gdb_get_line_number "Exit point"]
gdb_continue_to_breakpoint "Setting a decimal struct"
gdb_test "print ds.dec32" " = 1.2345"
gdb_test "print ds.dec64" " = 1.2345"
gdb_test "print ds.dec128" " = 1.2345"
# Test expressions with DFP variables.
gdb_test "print d32 + ds.dec32" " = 1.3345"
gdb_test "print d64 + ds.dec64" " = 1.3345"
gdb_test "print d128 + ds.dec128" " = 1.3345"
# Test conversion between different _Decimal sizes.
gdb_test "ptype d64 + ds.dec32" " = volatile _Decimal64"
gdb_test "ptype d128 + ds.dec32" " = volatile _Decimal128"
gdb_test "ptype d128 + ds.dec64" " = volatile _Decimal128"
Fix type casts losing typedefs and reimplement "whatis" typedef stripping (Ref: https://sourceware.org/ml/gdb/2017-06/msg00020.html) Assuming int_t is a typedef to int: typedef int int_t; gdb currently loses this expression's typedef: (gdb) p (int_t) 0 $1 = 0 (gdb) whatis $1 type = int or: (gdb) whatis (int_t) 0 type = int or, to get "whatis" out of the way: (gdb) maint print type (int_t) 0 ... name 'int' code 0x8 (TYPE_CODE_INT) ... This prevents a type printer for "int_t" kicking in, with e.g.: (gdb) p (int_t) 0 From the manual, we can see that that "whatis (int_t) 0" command invocation should have printed "type = int_t": If @var{arg} is a variable or an expression, @code{whatis} prints its literal type as it is used in the source code. If the type was defined using a @code{typedef}, @code{whatis} will @emph{not} print the data type underlying the @code{typedef}. (...) If @var{arg} is a type name that was defined using @code{typedef}, @code{whatis} @dfn{unrolls} only one level of that @code{typedef}. That one-level stripping is currently done here, in gdb/eval.c:evaluate_subexp_standard, handling OP_TYPE: ... else if (noside == EVAL_AVOID_SIDE_EFFECTS) { struct type *type = exp->elts[pc + 1].type; /* If this is a typedef, then find its immediate target. We use check_typedef to resolve stubs, but we ignore its result because we do not want to dig past all typedefs. */ check_typedef (type); if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) type = TYPE_TARGET_TYPE (type); return allocate_value (type); } However, this stripping is reachable in both: #1 - (gdb) whatis (int_t)0 # ARG is an expression with a cast to # typedef type. #2 - (gdb) whatis int_t # ARG is a type name. while only case #2 should strip the typedef. Removing that code from evaluate_subexp_standard is part of the fix. Instead, we make the "whatis" command implementation itself strip one level of typedefs when the command argument is a type name. We then run into another problem, also fixed by this commit: value_cast always drops any typedefs of the destination type. With all that fixed, "whatis (int_t) 0" now works as expected: (gdb) whatis int_t type = int (gdb) whatis (int_t)0 type = int_t value_cast has many different exit/convertion paths, for handling many different kinds of casts/conversions, and most of them had to be tweaked to construct the value of the right "to" type. The new tests try to exercise most of it, by trying castin of many different combinations of types. With: $ make check TESTS="*/whatis-ptype*.exp */gnu_vector.exp */dfp-test.exp" ... due to combinatorial explosion, the testsuite results for the tests above alone grow like: - # of expected passes 246 + # of expected passes 3811 You'll note that the tests exposed one GCC buglet, filed here: Missing DW_AT_type in DW_TAG_typedef of "typedef of typedef of void" https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81267 gdb/ChangeLog: 2017-08-21 Pedro Alves <palves@redhat.com> * eval.c (evaluate_subexp_standard) <OP_TYPE>: Don't dig past typedefs. * typeprint.c (whatis_exp): If handling "whatis", and expression is OP_TYPE, strip one typedef level. Otherwise don't strip typedefs here. * valops.c (value_cast): Save "to" type before resolving stubs/typedefs. Use that type as resulting value's type. gdb/testsuite/ChangeLog: 2017-08-21 Pedro Alves <palves@redhat.com> * gdb.base/dfp-test.c (d32_t, d64_t, d128_t, d32_t2, d64_t2, d128_t2, v_d32_t, v_d64_t) (v_d128_t, v_d32_t2, v_d64_t2, v_d128_t2): New. * gdb.base/dfp-test.exp: Add whatis/ptype/cast tests. * gdb.base/gnu_vector.exp: Add whatis/ptype/cast tests. * gdb.base/whatis-ptype-typedefs.c: New. * gdb.base/whatis-ptype-typedefs.exp: New. * gdb.python/py-prettyprint.c (int_type, int_type2): New typedefs. (an_int, an_int_type, an_int_type2): New globals. * gdb.python/py-prettyprint.exp (run_lang_tests): Add tests involving typedefs and cast expressions. * gdb.python/py-prettyprint.py (class pp_int_typedef): New. (lookup_typedefs_function): New. (typedefs_pretty_printers_dict): New. (top level): Register lookup_typedefs_function in gdb.pretty_printers.
2017-08-21 12:34:32 +02:00
gdb_test "whatis d64 + ds.dec32" " = volatile _Decimal64"
gdb_test "whatis d128 + ds.dec32" " = volatile _Decimal128"
gdb_test "whatis d128 + ds.dec64" " = volatile _Decimal128"
# Mixture of Decimal and integral operands
gdb_test "p d32 + 1" " = 1.1"
gdb_test "p 2 + d64" " = 2.1"
gdb_test "p ds.int4 + d128" " = 1.1"
Clean up some DFP interfaces This cleans up a number of interfaces in dfp.c / dfp.h. Specifically: - The decimal_from_string / decimal_to_string routines are C++-ified to operate on std::string instead of character buffers. In the decimal_from_string, the boolean return value now actually is bool instead of an int. - The decimal_from_integral and decimal_from_doublest routines take an struct value as input. This is not really appropriate at the low level the DFP routines sit, so this replaced them with new routines decimal_from_longest / decimal_from_ulongest / decimal_from_doublest that operate on contents instead. - To mirror the decimal_from_[u]longest, a new decimal_to_longest routine is added as well, which can be used in unpack_long to avoid an unnecessary conversion via DOUBLEST. Note that the decimal_from_longest / decimal_from_ulongest routines are actually more powerful than decimal_from_integral: the old routine would only accept integer *types* of at most four bytes size, while the new routines accept all integer *values* that fit in an [u]int32_t, no matter which type they came from. The DFP tests are updated to allow for this larger range of integers that can be converted. gdb/ChangeLog: 2017-10-05 Ulrich Weigand <uweigand@de.ibm.com> * dfp.h (MAX_DECIMAL_STRING): Move to dfp.c. (decimal_to_string): Return std::string object. (decimal_from_string): Accept std::string object. Return bool. (decimal_from_integral, decimal_from_doublest): Remove. (decimal_from_longest): Add prototype. (decimal_from_ulongest): Likewise. (decimal_to_longest): Likewise. (decimal_from_doublest): Likewise. * dfp.c: Do not include "gdbtypes.h" or "value.h". (MAX_DECIMAL_STRING): Move here. (decimal_to_string): Return std::string object. (decimal_from_string): Accept std::string object. Return bool. (decimal_from_integral): Remove, replace by ... (decimal_from_longest, decimal_from_ulongest): ... these new functions. (decimal_to_longest): New function. (decimal_from_floating): Remove, replace by ... (decimal_from_doublest): ... this new function. (decimal_to_doublest): Update to new decimal_to_string interface. * value.c (unpack_long): Use decimal_to_longest. * valops.c (value_cast): Use decimal_from_doublest instead of decimal_from_floating. Use decimal_from_[u]longest isntead of decimal_from_integral. * valarith.c (value_args_as_decimal): Likewise. * valprint.c (print_decimal_floating): Update to new decimal_to_string interface. * printcmd.c (printf_decfloat): Likewise. * c-exp.y (parse_number): Update to new decimal_from_string interface. gdb/testsuite/ChangeLog: 2017-10-05 Ulrich Weigand <uweigand@de.ibm.com> * gdb.base/dfp-exprs.exp: Update tests to larger range of supported integer-to-dfp conversion. * gdb.base/dfp-test.exp: Likewise.
2017-10-05 19:14:08 +02:00
gdb_test "p d32 + ds.long8" " = 2.1"
gdb_test "ptype d32 + 1" " = volatile _Decimal32"
gdb_test "ptype ds.int4 + d128" " = volatile _Decimal128"
# Test other operations with DFP operands
gdb_test "p !d32" " = 0"
gdb_test "p !d64" " = 0"
gdb_test "p !d128" " = 0"
gdb_test "p +d32" " = 0.1"
gdb_test "p +d64" " = 0.1"
gdb_test "p +d128" " = 0.1"
gdb_test "p d64 == d128" " = 1"
gdb_test "p d128 == ds.dec32" " = 0"
gdb_test "p d128 == d32" " = 1"
gdb_test "p ds.dec32 == ds.dec64" " = 1"
gdb_test "p d32 < ds.dec32" " = 1"
gdb_test "p d64 < ds.dec64" " = 1"
gdb_test "p d128 < ds.dec128" " = 1"
gdb_test "p ds.dec32 < d32" " = 0"
gdb_test "p d64 > ds.dec64" " = 0"
gdb_test "p ds.dec128 > d128 " " = 1"
gdb_test "p d32 < ds.int4" " = 1"
gdb_test "p ds.int4 > d32" " = 1"
gdb_test "p ds.dec32 < ds.int4" " = 0"
gdb_test "p ds.int4 > ds.dec64" " = 0"
gdb_test "p ds.dec128 > ds.int4" " = 1"
# Reject operation with DFP and Binary FP
gdb_test "p d64 + ds.float4" "Mixing decimal floating types with other floating types is not allowed."
gdb_test "p ds.double8 + d128" "Mixing decimal floating types with other floating types is not allowed."
# The following tests are intended to verify that gdb can handle "d1=d2"
# and "d1=-d2" correctly.
gdb_test "print ds.dec32=d32" " = 0.1"
gdb_test "print ds.dec64=d64" " = 0.1"
gdb_test "print ds.dec128=d128" " = 0.1"
gdb_test "print ds.dec32 = -d32" " = -0.1"
gdb_test "print ds.dec64 = -d64" " = -0.1"
gdb_test "print ds.dec128 = -d128" " = -0.1"
# Test cast to and from DFP values
gdb_test "print ds.double8 = ds.dec64" " = -0.(0999.*|1000.*)"
gdb_test "print ds.dec64 = ds.float4" " = 3.(0999.*|1000.*)"
gdb_test "print ds.dec128 = -ds.double8" " = 0.(0999.*|1000.*)"
gdb_test "print ds.dec128 = ds.dec32" " = -0.1"
gdb_test "print ds.dec32 = ds.int4" " = 1"
gdb_test "print ds.int4 = 7.3dl" " = 7"
Fix type casts losing typedefs and reimplement "whatis" typedef stripping (Ref: https://sourceware.org/ml/gdb/2017-06/msg00020.html) Assuming int_t is a typedef to int: typedef int int_t; gdb currently loses this expression's typedef: (gdb) p (int_t) 0 $1 = 0 (gdb) whatis $1 type = int or: (gdb) whatis (int_t) 0 type = int or, to get "whatis" out of the way: (gdb) maint print type (int_t) 0 ... name 'int' code 0x8 (TYPE_CODE_INT) ... This prevents a type printer for "int_t" kicking in, with e.g.: (gdb) p (int_t) 0 From the manual, we can see that that "whatis (int_t) 0" command invocation should have printed "type = int_t": If @var{arg} is a variable or an expression, @code{whatis} prints its literal type as it is used in the source code. If the type was defined using a @code{typedef}, @code{whatis} will @emph{not} print the data type underlying the @code{typedef}. (...) If @var{arg} is a type name that was defined using @code{typedef}, @code{whatis} @dfn{unrolls} only one level of that @code{typedef}. That one-level stripping is currently done here, in gdb/eval.c:evaluate_subexp_standard, handling OP_TYPE: ... else if (noside == EVAL_AVOID_SIDE_EFFECTS) { struct type *type = exp->elts[pc + 1].type; /* If this is a typedef, then find its immediate target. We use check_typedef to resolve stubs, but we ignore its result because we do not want to dig past all typedefs. */ check_typedef (type); if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) type = TYPE_TARGET_TYPE (type); return allocate_value (type); } However, this stripping is reachable in both: #1 - (gdb) whatis (int_t)0 # ARG is an expression with a cast to # typedef type. #2 - (gdb) whatis int_t # ARG is a type name. while only case #2 should strip the typedef. Removing that code from evaluate_subexp_standard is part of the fix. Instead, we make the "whatis" command implementation itself strip one level of typedefs when the command argument is a type name. We then run into another problem, also fixed by this commit: value_cast always drops any typedefs of the destination type. With all that fixed, "whatis (int_t) 0" now works as expected: (gdb) whatis int_t type = int (gdb) whatis (int_t)0 type = int_t value_cast has many different exit/convertion paths, for handling many different kinds of casts/conversions, and most of them had to be tweaked to construct the value of the right "to" type. The new tests try to exercise most of it, by trying castin of many different combinations of types. With: $ make check TESTS="*/whatis-ptype*.exp */gnu_vector.exp */dfp-test.exp" ... due to combinatorial explosion, the testsuite results for the tests above alone grow like: - # of expected passes 246 + # of expected passes 3811 You'll note that the tests exposed one GCC buglet, filed here: Missing DW_AT_type in DW_TAG_typedef of "typedef of typedef of void" https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81267 gdb/ChangeLog: 2017-08-21 Pedro Alves <palves@redhat.com> * eval.c (evaluate_subexp_standard) <OP_TYPE>: Don't dig past typedefs. * typeprint.c (whatis_exp): If handling "whatis", and expression is OP_TYPE, strip one typedef level. Otherwise don't strip typedefs here. * valops.c (value_cast): Save "to" type before resolving stubs/typedefs. Use that type as resulting value's type. gdb/testsuite/ChangeLog: 2017-08-21 Pedro Alves <palves@redhat.com> * gdb.base/dfp-test.c (d32_t, d64_t, d128_t, d32_t2, d64_t2, d128_t2, v_d32_t, v_d64_t) (v_d128_t, v_d32_t2, v_d64_t2, v_d128_t2): New. * gdb.base/dfp-test.exp: Add whatis/ptype/cast tests. * gdb.base/gnu_vector.exp: Add whatis/ptype/cast tests. * gdb.base/whatis-ptype-typedefs.c: New. * gdb.base/whatis-ptype-typedefs.exp: New. * gdb.python/py-prettyprint.c (int_type, int_type2): New typedefs. (an_int, an_int_type, an_int_type2): New globals. * gdb.python/py-prettyprint.exp (run_lang_tests): Add tests involving typedefs and cast expressions. * gdb.python/py-prettyprint.py (class pp_int_typedef): New. (lookup_typedefs_function): New. (typedefs_pretty_printers_dict): New. (top level): Register lookup_typedefs_function in gdb.pretty_printers.
2017-08-21 12:34:32 +02:00
# Test "whatis"/"ptype" of expressions involving casts to/from dfp
# typedefs.
# This list is composed by sub-lists, and their elements are (in
# order):
#
# - Type to cast to. This is also what "whatis" should print.
# - What "ptype" should print.
# Columns in the sublists represent:
# to/whatis # ptype
foreach elem {
{"_Decimal32" "_Decimal32"}
{"_Decimal64" "_Decimal64"}
{"_Decimal128" "_Decimal128"}
{"d32_t" "_Decimal32"}
{"d64_t" "_Decimal64"}
{"d128_t" "_Decimal128"}
{"d32_t2" "_Decimal32"}
{"d64_t2" "_Decimal64"}
{"d128_t2" "_Decimal128"}
} {
set type [lindex $elem 0]
set ptype [lindex $elem 1]
gdb_test "whatis ($type) 0" " = $type"
gdb_test "ptype ($type) 0" " = $ptype"
}
# Test:
# - whatis/ptype of variables of typedef type.
# - whatis/ptype of typedef type names.
# - whatis/ptype of typedef-of-typedef type names.
# Columns in the sublists represent:
# Type name # whatis # ptype
foreach elem {
{"v_d32_t" "d32_t" "_Decimal32"}
{"v_d64_t" "d64_t" "_Decimal64"}
{"v_d128_t" "d128_t" "_Decimal128"}
{"d32_t" "_Decimal32" "_Decimal32"}
{"d64_t" "_Decimal64" "_Decimal64"}
{"d128_t" "_Decimal128" "_Decimal128"}
{"d32_t2" "d32_t" "_Decimal32"}
{"d64_t2" "d64_t" "_Decimal64"}
{"d128_t2" "d128_t" "_Decimal128"}
} {
set type [lindex $elem 0]
set whatis [lindex $elem 1]
set ptype [lindex $elem 2]
gdb_test "whatis $type" " = $whatis"
gdb_test "ptype $type" " = $ptype"
}