aboutsummaryrefslogtreecommitdiff
path: root/gdb/target-float.c
AgeCommit message (Collapse)AuthorFilesLines
2020-05-14gdb: remove TYPE_CODE macroSimon Marchi1-12/+12
Remove TYPE_CODE, changing all the call sites to use type::code directly. This is quite a big diff, but this was mostly done using sed and coccinelle. A few call sites were done by hand. gdb/ChangeLog: * gdbtypes.h (TYPE_CODE): Remove. Change all call sites to use type::code instead.
2020-01-01Update copyright year range in all GDB files.Joel Brobecker1-1/+1
gdb/ChangeLog: Update copyright year range in all GDB files.
2019-12-13Silence ARI warning about floatformat_to_doubleTom Tromey1-2/+2
This silences ARI at the one spot that is permitted to call floatformat_to_double, and also removes the corresponding "fix" call from gdb_ari.sh -- it was incorrect, and now is not needed. gdb/ChangeLog 2019-12-13 Tom Tromey <tromey@adacore.com> * contrib/ari/gdb_ari.sh: Remove "fix" call for floatformat_to_double. * target-float.c (host_float_ops<T>::from_target): Add ARI comment. Change-Id: I778a17a04da417c113194004dd7de3b1df381266
2019-11-21Adjust byte order variable display/change if DW_AT_endianity is present.Peeter Joot1-3/+3
- Rationale: It is possible for compilers to indicate the desired byte order interpretation of scalar variables using the DWARF attribute: DW_AT_endianity A type flagged with this variable would typically use one of: DW_END_big DW_END_little which instructs the debugger what the desired byte order interpretation of the variable should be. The GCC compiler (as of V6) has a mechanism for setting the desired byte ordering of the fields within a structure or union. For, example, on a little endian target, a structure declared as: struct big { int v; short a[4]; } __attribute__( ( scalar_storage_order( "big-endian" ) ) ); could be used to ensure all the structure members have a big-endian interpretation (the compiler would automatically insert byte swap instructions before and after respective store and load instructions). - To reproduce GCC V8 is required to correctly emit DW_AT_endianity DWARF attributes in all situations when the scalar_storage_order attribute is used. A fix for (dwarf endianity instrumentation) for GCC V6-V7 can be found in the URL field of the following PR: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82509 - Test-case: A new test case (testsuite/gdb.base/endianity.*) is included with this patch. Manual testing for mixed endianity code has also been done with GCC V8. See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82509#c4 - Observed vs. expected: Without this change, using scalar_storage_order that doesn't match the target, such as struct otherendian { int v; } __attribute__( ( scalar_storage_order( "big-endian" ) ) ); would behave like the following on a little endian target: Breakpoint 1 at 0x401135: file endianity.c, line 41. (gdb) run Starting program: /home/pjoot/freeware/t/a.out Missing separate debuginfos, use: debuginfo-install glibc-2.17-292.el7.x86_64 Breakpoint 1, main () at endianity.c:41 41 struct otherendian o = {3}; (gdb) n 43 do_nothing (&o); /* START */ (gdb) p o $1 = {v = 50331648} (gdb) p /x $2 = {v = 0x3000000} whereas with this gdb enhancement we can access the variable with the user specified endianity: Breakpoint 1, main () at endianity.c:41 41 struct otherendian o = {3}; (gdb) p o $1 = {v = 0} (gdb) n 43 do_nothing (&o); /* START */ (gdb) p o $2 = {v = 3} (gdb) p o.v = 4 $3 = 4 (gdb) p o.v $4 = 4 (gdb) x/4xb &o.v 0x7fffffffd90c: 0x00 0x00 0x00 0x04 (observe that the 4 byte int variable has a big endian representation in the hex dump.) gdb/ChangeLog 2019-11-21 Peeter Joot <peeter.joot@lzlabs.com> Byte reverse display of variables with DW_END_big, DW_END_little (DW_AT_endianity) dwarf attributes if different than the native byte order. * ada-lang.c (ada_value_binop): Use type_byte_order instead of gdbarch_byte_order. * ada-valprint.c (printstr): (ada_val_print_string): * ada-lang.c (value_pointer): (ada_value_binop): Use type_byte_order instead of gdbarch_byte_order. * c-lang.c (c_get_string): Use type_byte_order instead of gdbarch_byte_order. * c-valprint.c (c_val_print_array): Use type_byte_order instead of gdbarch_byte_order. * cp-valprint.c (cp_print_class_member): Use type_byte_order instead of gdbarch_byte_order. * dwarf2loc.c (rw_pieced_value): Use type_byte_order instead of gdbarch_byte_order. * dwarf2read.c (read_base_type): Handle DW_END_big, DW_END_little * f-lang.c (f_get_encoding): Use type_byte_order instead of gdbarch_byte_order. * findvar.c (default_read_var_value): Use type_byte_order instead of gdbarch_byte_order. * gdbtypes.c (check_types_equal): Require matching TYPE_ENDIANITY_NOT_DEFAULT if set. (recursive_dump_type): Print TYPE_ENDIANITY_BIG, and TYPE_ENDIANITY_LITTLE if set. (type_byte_order): new function. * gdbtypes.h (TYPE_ENDIANITY_NOT_DEFAULT): New macro. (struct main_type) <flag_endianity_not_default>: New field. (type_byte_order): New function. * infcmd.c (default_print_one_register_info): Use type_byte_order instead of gdbarch_byte_order. * p-lang.c (pascal_printstr): Use type_byte_order instead of gdbarch_byte_order. * p-valprint.c (pascal_val_print): Use type_byte_order instead of gdbarch_byte_order. * printcmd.c (print_scalar_formatted): Use type_byte_order instead of gdbarch_byte_order. * solib-darwin.c (darwin_current_sos): Use type_byte_order instead of gdbarch_byte_order. * solib-svr4.c (solib_svr4_r_ldsomap): Use type_byte_order instead of gdbarch_byte_order. * stap-probe.c (stap_modify_semaphore): Use type_byte_order instead of gdbarch_byte_order. * target-float.c (target_float_same_format_p): Use type_byte_order instead of gdbarch_byte_order. * valarith.c (scalar_binop): (value_bit_index): Use type_byte_order instead of gdbarch_byte_order. * valops.c (value_cast): Use type_byte_order instead of gdbarch_byte_order. * valprint.c (generic_emit_char): (generic_printstr): (val_print_string): Use type_byte_order instead of gdbarch_byte_order. * value.c (unpack_long): (unpack_bits_as_long): (unpack_value_bitfield): (modify_field): (pack_long): (pack_unsigned_long): Use type_byte_order instead of gdbarch_byte_order. * findvar.c (unsigned_pointer_to_address): (signed_pointer_to_address): (unsigned_address_to_pointer): (address_to_signed_pointer): (default_read_var_value): (default_value_from_register): Use type_byte_order instead of gdbarch_byte_order. * gnu-v3-abi.c (gnuv3_make_method_ptr): Use type_byte_order instead of gdbarch_byte_order. * riscv-tdep.c (riscv_print_one_register_info): Use type_byte_order instead of gdbarch_byte_order. gdb/testsuite/ChangeLog 2019-11-21 Peeter Joot <peeter.joot@lzlabs.com> * gdb.base/endianity.c: New test. * gdb.base/endianity.exp: New file. Change-Id: I4bd98c1b4508c2d7c5a5dbb15d7b7b1cb4e667e2
2019-10-18[gdb] Fix more typos in commentsTom de Vries1-1/+1
Fix typos in comments. NFC. Tested on x86_64-linux. gdb/ChangeLog: 2019-10-18 Tom de Vries <tdevries@suse.de> * aarch64-tdep.c: Fix typos in comments. * ada-lang.c: Same. * ada-tasks.c: Same. * alpha-tdep.c: Same. * alpha-tdep.h: Same. * amd64-nat.c: Same. * amd64-windows-tdep.c: Same. * arc-tdep.c: Same. * arc-tdep.h: Same. * arch-utils.c: Same. * arm-nbsd-tdep.c: Same. * arm-tdep.c: Same. * ax-gdb.c: Same. * blockframe.c: Same. * btrace.c: Same. * c-varobj.c: Same. * coff-pe-read.c: Same. * coffread.c: Same. * cris-tdep.c: Same. * darwin-nat.c: Same. * dbxread.c: Same. * dcache.c: Same. * disasm.c: Same. * dtrace-probe.c: Same. * dwarf-index-write.c: Same. * dwarf2-frame-tailcall.c: Same. * dwarf2-frame.c: Same. * dwarf2read.c: Same. * eval.c: Same. * exceptions.c: Same. * fbsd-tdep.c: Same. * findvar.c: Same. * frame.c: Same. * frv-tdep.c: Same. * gnu-v3-abi.c: Same. * go32-nat.c: Same. * h8300-tdep.c: Same. * hppa-tdep.c: Same. * i386-linux-tdep.c: Same. * i386-tdep.c: Same. * ia64-libunwind-tdep.c: Same. * ia64-tdep.c: Same. * infcmd.c: Same. * infrun.c: Same. * linespec.c: Same. * linux-nat.c: Same. * linux-thread-db.c: Same. * machoread.c: Same. * mdebugread.c: Same. * mep-tdep.c: Same. * mn10300-tdep.c: Same. * namespace.c: Same. * objfiles.c: Same. * opencl-lang.c: Same. * or1k-tdep.c: Same. * osabi.c: Same. * ppc-linux-nat.c: Same. * ppc-linux-tdep.c: Same. * ppc-sysv-tdep.c: Same. * printcmd.c: Same. * procfs.c: Same. * record-btrace.c: Same. * record-full.c: Same. * remote-fileio.c: Same. * remote.c: Same. * rs6000-tdep.c: Same. * s12z-tdep.c: Same. * score-tdep.c: Same. * ser-base.c: Same. * ser-go32.c: Same. * skip.c: Same. * sol-thread.c: Same. * solib-svr4.c: Same. * solib.c: Same. * source.c: Same. * sparc-nat.c: Same. * sparc-sol2-tdep.c: Same. * sparc-tdep.c: Same. * sparc64-tdep.c: Same. * stabsread.c: Same. * stack.c: Same. * symfile.c: Same. * symtab.c: Same. * target-descriptions.c: Same. * target-float.c: Same. * thread.c: Same. * utils.c: Same. * valops.c: Same. * valprint.c: Same. * value.c: Same. * varobj.c: Same. * windows-nat.c: Same. * xcoffread.c: Same. * xstormy16-tdep.c: Same. * xtensa-tdep.c: Same. Change-Id: I5175f1b107bfa4e1cdd4a3361ccb4739e53c75c4
2019-09-11Fix float to LONGEST conversion.Ali Tamur1-6/+11
The code used to have undefined behaviour when template parameter is float and host_float is NaN, because it attempted to convert NaN value to LONGEST at the last statement. This frequently caused crashes on tests that checked "info all-registers" (at least when the code is compiled with clang; I didn't test with gdb). gdb/ChangeLog: *target-float.c (host_float_ops<T>::to_longest): Update implementation.
2019-07-10Don't include gdbarch.h from defs.hTom Tromey1-1/+1
I touched symtab.h and was surprised to see how many files were rebuilt. I looked into it a bit, and found that defs.h includes gdbarch.h, which in turn includes many things. gdbarch.h is only needed by a minority ofthe files in gdb, so this patch removes the include from defs.h and updates the fallout. I did "wc -l" on the files in build/gdb/.deps; this patch reduces the line count from 139935 to 137030; so there are definitely future build-time savings here. Note that while I configured with --enable-targets=all, it's possible that some *-nat.c file needs an update. I could not test all of these. The buildbot caught a few problems along these lines. gdb/ChangeLog 2019-07-10 Tom Tromey <tom@tromey.com> * defs.h: Don't include gdbarch.h. * aarch64-ravenscar-thread.c, aarch64-tdep.c, alpha-bsd-tdep.h, alpha-linux-tdep.c, alpha-mdebug-tdep.c, arch-utils.h, arm-tdep.h, ax-general.c, btrace.c, buildsym-legacy.c, buildsym.h, c-lang.c, cli/cli-decode.h, cli/cli-dump.c, cli/cli-script.h, cli/cli-style.h, coff-pe-read.h, compile/compile-c-support.c, compile/compile-cplus.h, compile/compile-loc2c.c, corefile.c, cp-valprint.c, cris-linux-tdep.c, ctf.c, d-lang.c, d-namespace.c, dcache.c, dicos-tdep.c, dictionary.c, disasm-selftests.c, dummy-frame.c, dummy-frame.h, dwarf2-frame-tailcall.c, dwarf2expr.c, expression.h, f-lang.c, frame-base.c, frame-unwind.c, frv-linux-tdep.c, gdbarch-selftests.c, gdbtypes.h, go-lang.c, hppa-nbsd-tdep.c, hppa-obsd-tdep.c, i386-dicos-tdep.c, i386-tdep.h, ia64-vms-tdep.c, interps.h, language.c, linux-record.c, location.h, m2-lang.c, m32r-linux-tdep.c, mem-break.c, memattr.c, mn10300-linux-tdep.c, nios2-linux-tdep.c, objfiles.h, opencl-lang.c, or1k-linux-tdep.c, p-lang.c, parser-defs.h, ppc-tdep.h, probe.h, python/py-record-btrace.c, record-btrace.c, record.h, regcache-dump.c, regcache.h, riscv-fbsd-tdep.c, riscv-linux-tdep.c, rust-exp.y, sh-linux-tdep.c, sh-nbsd-tdep.c, source-cache.c, sparc-nbsd-tdep.c, sparc-obsd-tdep.c, sparc-ravenscar-thread.c, sparc64-fbsd-tdep.c, std-regs.c, target-descriptions.h, target-float.c, tic6x-linux-tdep.c, tilegx-linux-tdep.c, top.c, tracefile.c, trad-frame.c, type-stack.h, ui-style.c, utils.c, utils.h, valarith.c, valprint.c, varobj.c, x86-tdep.c, xml-support.h, xtensa-linux-tdep.c, cli/cli-cmds.h: Update. * s390-linux-nat.c, procfs.c, inf-ptrace.c: Likewise.
2019-01-01Update copyright year range in all GDB files.Joel Brobecker1-1/+1
This commit applies all changes made after running the gdb/copyright.py script. Note that one file was flagged by the script, due to an invalid copyright header (gdb/unittests/basic_string_view/element_access/char/empty.cc). As the file was copied from GCC's libstdc++-v3 testsuite, this commit leaves this file untouched for the time being; a patch to fix the header was sent to gcc-patches first. gdb/ChangeLog: Update copyright year range in all GDB files.
2018-10-04Simple -Wshadow=local fixesTom Tromey1-2/+1
This fixes all the straightforward -Wshadow=local warnings in gdb. A few standard approaches are used here: * Renaming an inner (or outer, but more commonly inner) variable; * Lowering a declaration to avoid a clash; * Moving a declaration into a more inner scope to avoid a clash, including the special case of moving a declaration into a loop header. I did not consider any of the changes in this patch to be particularly noteworthy, though of course they should all still be examined. gdb/ChangeLog 2018-10-04 Tom Tromey <tom@tromey.com> * ctf.c (SET_ARRAY_FIELD): Rename "u32". * p-valprint.c (pascal_val_print): Split inner "i" variable. * xtensa-tdep.c (xtensa_push_dummy_call): Declare "i" in loop header. * xstormy16-tdep.c (xstormy16_push_dummy_call): Declare "val" in more inner scope. * xcoffread.c (read_xcoff_symtab): Rename inner "symbol". * varobj.c (varobj_update): Rename inner "newobj", "type_changed". * valprint.c (generic_emit_char): Rename inner "buf". * valops.c (find_overload_match): Rename inner "temp". (value_struct_elt_for_reference): Declare "v" in more inner scope. * v850-tdep.c (v850_push_dummy_call): Rename "len". * unittests/array-view-selftests.c (run_tests): Rename inner "vec". * tui/tui-stack.c (tui_show_frame_info): Declare "i" in loop header. * tracepoint.c (merge_uploaded_trace_state_variables): Declare "tsv" in more inner scope. (print_one_static_tracepoint_marker): Rename inner "tuple_emitter". * tic6x-tdep.c (tic6x_analyze_prologue): Declare "inst" lower. (tic6x_push_dummy_call): Don't redeclare "addr". * target-float.c: Declare "dto" lower. * symtab.c (lookup_local_symbol): Rename inner "sym". (find_pc_sect_line): Rename inner "pc". * stack.c (print_frame): Don't redeclare "gdbarch". (return_command): Rename inner "gdbarch". * s390-tdep.c (s390_prologue_frame_unwind_cache): Renam inner "sp". * rust-lang.c (rust_internal_print_type): Declare "i" in loop header. * rs6000-tdep.c (ppc_process_record): Rename inner "addr". * riscv-tdep.c (riscv_push_dummy_call): Declare "info" in inner scope. * remote.c (remote_target::update_thread_list): Don't redeclare "tp". (remote_target::process_initial_stop_replies): Rename inner "thread". (remote_target::remote_parse_stop_reply): Don't redeclare "p". (remote_target::wait_as): Don't redeclare "stop_reply". (remote_target::get_thread_local_address): Rename inner "result". (remote_target::get_tib_address): Likewise.
2018-09-05Make -Wformat-nonliteral work with gccTom Tromey1-0/+7
After looking into why the build failed for Simon but not for me, we found that the underlying cause was due to how gcc treats -Wformat-nonliteral. gcc requires -Wformat to be given first; but warning.m4 was not doing this, so -Wformat-nonliteral was not being used. This patch changes warning.m4 to account gcc's requirement. This then showed that the target-float.c build change in the earlier Makefile patch was also incorrect. Simon didn't see this in his build, but gcc now points it out. So, this patch fixes this problem as well. 2018-09-05 Tom Tromey <tom@tromey.com> * warning.m4 (AM_GDB_WARNINGS): Add -Wformat when testing -Wformat-nonliteral. * target-float.c (host_float_ops<T>::to_string) (host_float_ops<T>::from_string): Use DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL. * configure: Rebuild. gdb/gdbserver/ChangeLog 2018-09-05 Tom Tromey <tom@tromey.com> * configure: Rebuild.
2018-01-02Update copyright year range in all GDB filesJoel Brobecker1-1/+1
gdb/ChangeLog: Update copyright year range in all GDB files
2017-12-11[MPFR] Fix regression on 32-bit host systemsUlrich Weigand1-1/+1
When converting parts of the mantissa to MPFR, we need to make sure to do an *unsigned* conversion. Since we convert at most 32 bits at a time, stored in an unsigned long, this doesn't matter on systems where "long" is larger than 32 bits. But on systems where it is 32 bits, we can get conversion errors. gdb/ChangeLog 2017-12-11 Ulrich Weigand <uweigand@de.ibm.com> * target-float.c (mpfr_float_ops::from_target): Use mpfr_set_ui instead of mpfr_set_si to convert mantissa bits.
2017-11-29Define MPFR_USE_INTMAX_T so that mpfr.h assumes intmax_t is available.John Baldwin1-0/+2
mpfr.h uses a non-portable test to guess if intmax_t is available and if API functions using intmax_t should be exposed. Define MPFR_USE_INTMAX_T to override the non-portable test and always expose these functions. This fixes the build on platforms where the test guesses incorrectly. gdb/ChangeLog: * target-float.c [HAVE_LIBMPFR]: Define MPFR_USE_INTMAX_T.
2017-11-22Target FP: Make use of MPFR if availableUlrich Weigand1-0/+569
This second patch introduces mfpr_float_ops, an new implementation of target_float_ops. This implements precise emulation of target floating-point formats using the MPFR library. This is then used to perform operations on types that do not match any host type. Note that use of MPFR is still not required. The patch adds a configure option --with-mpfr similar to --with-expat. If use of MPFR is disabled via the option or MPFR is not available, code will fall back to current behavior. This means that operations on types that do not match any host type will be implemented on the host long double type instead. A new test case verifies that we can correctly print the largest __float128 value now. gdb/ChangeLog: 2017-11-22 Ulrich Weigand <uweigand@de.ibm.com> * NEWS: Document use of GNU MPFR. * README: Likewise. * Makefile.in (LIBMPFR): Add define. (CLIBS): Add $(LIBMPFR). * configure.ac: Add --with-mpfr configure option. * configure: Regenerate. * config.in: Regenerate. * target-float.c [HAVE_LIBMPFR]: Include <mpfr.h>. (class mpfr_float_ops): New type. (mpfr_float_ops::from_target): Two new overloaded functions. (mpfr_float_ops::to_target): Likewise. (mpfr_float_ops::to_string): New function. (mpfr_float_ops::from_string): Likewise. (mpfr_float_ops::to_longest): Likewise. (mpfr_float_ops::from_longest): Likewise. (mpfr_float_ops::from_ulongest): Likewise. (mpfr_float_ops::to_host_double): Likewise. (mpfr_float_ops::from_host_double): Likewise. (mpfr_float_ops::convert): Likewise. (mpfr_float_ops::binop): Likewise. (mpfr_float_ops::compare): Likewise. (get_target_float_ops): Use mpfr_float_ops if available. gdb/doc/ChangeLog: 2017-11-22 Ulrich Weigand <uweigand@de.ibm.com> * gdb.texinfo (Requirements): Document use of GNU MPFR. gdb/testsuite/ChangeLog: 2017-11-22 Ulrich Weigand <uweigand@de.ibm.com> * gdb.base/float128.c (large128): New variable. * gdb.base/float128.exp: Add test to print largest __float128 value.
2017-11-22Target FP: Refactor use of host floating-point arithmeticUlrich Weigand1-422/+630
Prepare for using MPFR to implement floating-point arithmetic by refactoring the way host floating-point arithmetic is currently used. In particular, fix the following two problems that cause different (and incorrect) results due to using host arithmetic: - Current processing always uses host "long double", and then converts back to the actual target format. This may introduce rounding errors. - Conversion of FP values to LONGEST simply does a host C++ type cast. However the result of such a cast is undefined if the source value is outside the representable range. MPFR always has defined behavior here (returns the minimum or maximum representable value). To fix the first issue, I've now created not just one set of routines using host FP arithmetic (on long double), but instead three different sets of routines, one each for host float, double, and long double. Operations can then be performed in the desired type directly, avoiding the extra rounding step. Using C++ templates, the three sets can all share the same source code without duplication. To fix the second issue, I'm simply enforcing the same conversion rule (which makes sense anyway) when converting out-of-range values from FP to LONGEST. To contain the code complexity with the variety of options now possible, I've created a new class "target_float_ops". There are a total of five separate implementations of this: host_float_ops<float> Implemented via host FP in given type host_float_ops<double> host_float_ops<long double> mpfr_float_ops Implemented via MPFR if available decimal_float_ops Implemented via libdecnumber Note instead of using the DOUBLEST define, this always just uses the "long double" data type. But since we now require C++11 anyway, this type must in any case be avaialble unconditionally. Most target floating-point operations simply dispatch to a (virtual) member routine of this class. Which implementation to choose is determined from the target types involved, and whether they match some host type or not. E.g. any operation on a single type that matches a host type is performed in that type. Operations involving two types that both match host types are performed in the larger one (according to C/C++ implicit conversion rules). Operations that involve any type that does not match a host type are performed using MPFR. (And of course operations involving decimal FP are performed using libdecnumber.) This first patch implements the refactoring of target-float.c as described above, introduing the host_float_ops and decimal_float_ops classes, and using them. Use of MPFR is introduced in the second patch. A bit of special-case handling code is moved around to as to avoid code duplication between host_float_ops and mpfr_float_ops. Note that due to the changes mentioned above, I've had to update (fix) the floating-point register values tested in the gdb.arch/vsx-regs.exp test case. (The new values now work both with host arithmetic and MPFR.) gdb/ChangeLog: 2017-11-22 Ulrich Weigand <uweigand@de.ibm.com> * target-float.c: Do not include <math.h>. Include <cmath> and <limits>. (DOUBLEST): Do not define. (class target_float_ops): New type. (class host_float_ops): New templated type. (class decimal_float_ops): New type. (floatformat_to_doublest): Rename to ... (host_float_ops<T>::from_target): ... this. Use template type T instead of DOUBLEST. Use C++ math routines. Update recursive calls. (host_float_ops<T>::from_target): New overload using a type argument. (floatformat_from_doublest): Rename to ... (host_float_ops<T>::to_target): ... this. Use template type T instead of DOUBLEST. Use C++ math routines. Update recursive calls. (host_float_ops<T>::to_target): New overload using a type argument. (floatformat_printf_format): New function. (struct printf_length_modifier): New templated type. (floatformat_to_string): Rename to ... (host_float_ops<T>::to_string): ... this. Use type instead of floatformat argument. Use floatformat_printf_format and printf_length_modifier. Remove special handling of invalid numbers, infinities and NaN (moved to target_float_to_string). (struct scanf_length_modifier): New templated type. (floatformat_from_string): Rename to ... (host_float_ops<T>::from_string): ... this. Use type instead of floatformat argument. Use scanf_length_modifier. (floatformat_to_longest): Rename to ... (host_float_ops<T>::to_longest): ... this. Use type instead of floatformat argument. Handle out-of-range values deterministically. (floatformat_from_longest): Rename to ... (host_float_ops<T>::from_longest): ... this. Use type instead of floatformat argument. (floatformat_from_ulongest): Rename to ... (host_float_ops<T>::from_ulongest): ... this. Use type instead of floatformat argument. (floatformat_to_host_double): Rename to ... (host_float_ops<T>::to_host_double): ... this. Use type instead of floatformat argument. (floatformat_from_host_double): Rename to ... (host_float_ops<T>::from_host_double): ... this. Use type instead of floatformat argument. (floatformat_convert): Rename to ... (host_float_ops<T>::convert): ... this. Use type instead of floatformat arguments. Remove handling of no-op conversions. (floatformat_binop): Rename to ... (host_float_ops<T>::binop): ... this. Use type instead of floatformat arguments. (floatformat_compare): Rename to ... (host_float_ops<T>::compare): ... this. Use type instead of floatformat arguments. (match_endianness): Use type instead of length/byte_order arguments. (set_decnumber_context): Likewise. (decimal_from_number): Likewise. Update calls. (decimal_to_number): Likewise. (decimal_is_zero): Likewise. Update calls. Move to earlier in file. (decimal_float_ops::to_host_double): New dummy function. (decimal_float_ops::from_host_double): Likewise. (decimal_to_string): Rename to ... (decimal_float_ops::to_string): ... this. Use type instead of length/byte_order arguments. Update calls. (decimal_from_string): Rename to ... (decimal_float_ops::from_string): ... this. Use type instead of length/byte_order arguments. Update calls. (decimal_from_longest): Rename to ... (decimal_float_ops::from_longest): ... this. Use type instead of length/byte_order arguments. Update calls. (decimal_from_ulongest): Rename to ... (decimal_float_ops::from_ulongest): ... this. Use type instead of length/byte_order arguments. Update calls. (decimal_to_longest): Rename to ... (decimal_float_ops::to_longest): ... this. Use type instead of length/byte_order arguments. Update calls. (decimal_binop): Rename to ... (decimal_float_ops::binop): ... this. Use type instead of length/byte_order arguments. Update calls. (decimal_compare): Rename to ... (decimal_float_ops::compare): ... this. Use type instead of length/byte_order arguments. Update calls. (decimal_convert): Rename to ... (decimal_float_ops::convert): ... this. Use type instead of length/byte_order arguments. Update calls. (target_float_same_category_p): New function. (target_float_same_format_p): Likewise. (target_float_format_length): Likewise. (enum target_float_ops_kind): New type. (get_target_float_ops_kind): New function. (get_target_float_ops): Three new overloaded functions. (target_float_is_zero): Update call. (target_float_to_string): Add special handling of invalid numbers, infinities and NaN (moved from floatformat_to_string). Use target_float_ops callback. (target_float_from_string): Use target_float_ops callback. (target_float_to_longest): Likewise. (target_float_from_longest): Likewise. (target_float_from_ulongest): Likewise. (target_float_to_host_double): Likewise. (target_float_from_host_double): Likewise. (target_float_convert): Add special case for no-op conversions. Use target_float_ops callback. (target_float_binop): Use target_float_ops callback. (target_float_compare): Likewise. gdb/testsuite/ChangeLog: 2017-11-22 Ulrich Weigand <uweigand@de.ibm.com> * gdb.arch/vsx-regs.exp: Update register content checks.
2017-11-16Refactor endian handling in DFP routinesUlrich Weigand1-39/+31
This patch moves endian conversion into the decimal_from_number and decimal_to_number routines, and removes it from all their callers, making the code simpler overall. No functional change. gdb/ChangeLog: 2017-11-16 Ulrich Weigand <uweigand@de.ibm.com> * target-float.c (decimal_from_number): Add byte_order argument and call match_endianness. Error if unknown floating-point type. (decimal_to_number): Add byte_order argument and call match_endianness. (decimal_from_longest): Update call. Do not call match_endianness. (decimal_from_ulongest): Likewise. (decimal_binop): Likewise. (decimal_is_zero): Likewise. (decimal_compare): Likewise. (decimal_convert): Likewise.
2017-11-06Target FP: Merge doublest.c and dfp.c into target-float.cUlrich Weigand1-2/+1246
Now that all target FP operations are performed via target-float.c, this file remains the sole caller of functions in doublest.c and dfp.c. Therefore, this patch merges the latter files into the former and makes all their function static there. gdb/ChangeLog: 2017-11-06 Ulrich Weigand <uweigand@de.ibm.com> * Makefile.in (SFILES): Remove doublest.c and dfp.c. (HFILES_NO_SRCDIR): Remove doublest.h and dfp.h. (COMMON_OBS): Remove doublest.o and dfp.o. Do not build target-float.c (instead of doublest.c) with -Wformat-nonliteral. * doublest.c: Remove file. * doublest.h: Remove file. * dfp.c: Remove file. * dfp.h: Remove file. * target-float.c: Do not include "doublest.h" and "dfp.h". (DOUBLEST): Move here from doublest.h. (enum float_kind): Likewise. (FLOATFORMAT_CHAR_BIT): Likewise. (FLOATFORMAT_LARGEST_BYTES): Likewise. (floatformat_totalsize_bytes): Move here from doublest.c. Make static. (floatformat_precision): Likewise. (floatformat_normalize_byteorder, get_field, put_field): Likewise. (floatformat_is_negative, floatformat_classify, floatformat_mantissa): Likewise. (host_float_format, host_double_format, host_long_double_format): Likewise. (floatformat_to_string, floatformat_from_string): Likewise. (floatformat_to_doublest): Likewise. Also, inline the original convert_floatformat_to_doublest. (floatformat_from_doublest): Likewise. Also, inline the original convert_floatformat_from_doublest. Include "dpd/decimal128.h", "dpd/decimal64.h", and "dpd/decimal32.h". (MAX_DECIMAL_STRING): Move here from dfp.c. (match_endianness): Likewise. (set_decnumber_context, decimal_check_errors): Likewise. (decimal_from_number, decimal_to_number): Likewise. (decimal_to_string, decimal_from_string): Likewise. Make static. (decimal_from_longest, decimal_from_ulongest): Likewise. (decimal_to_longest): Likewise. (decimal_binop, decimal_is_zero, decimal_compare): Likewise. (decimal_convert): Likewise.
2017-11-06Target FP: Handle interfaces to scripting languagesUlrich Weigand1-0/+57
The last remaing use for DOUBLEST is in the code that interfaces to the scripting languages (Python and Guile). The problem here is that we expose interfaces to convert a GDB value to and from native values of floating-point type in those languages, and those by definition use the host floating-point format. While we cannot completely eliminate conversions to/from the host floating-point format here, we still need to get rid of the uses of value_as_double / value_from_double, since those will go away. This patch implements two new target-float.c routine: - target_float_to_host_double - target_float_from_host_double which convert to/from a host "double". Those should only ever be used where a host "double" is mandated by an external interface. gdb/ChangeLog: 2017-11-06 Ulrich Weigand <uweigand@de.ibm.com> * target-float.c (floatformat_to_host_double): New function. (floatformat_from_host_double): Likewise. (target_float_to_host_double): Likewise. (target_float_from_host_double): Likewise. * target-float.h (target_float_to_host_double): Add prototype. (target_float_from_host_double): Likewise. * guile/scm-value.c: Include "target-float.h". (gdbscm_value_to_real): Use target_float_to_host_double. Handle integer source values via value_as_long. * guile/scm-math.c: Include "target-float.h". Do not include "doublest.h", "dfp.h", and "expression.h". (vlscm_convert_typed_number): Use target_float_from_host_double. (vlscm_convert_number): Likewise. * python/py-value.c (valpy_float): Use target_float_to_host_double. (convert_value_from_python): Use target_float_from_host_double.
2017-11-06Target FP: Add binop and compare routines to target-float.{c,h}Ulrich Weigand1-0/+152
This patch adds the following target floating-point routines: - target_float_binop - target_float_compare which call the equivalent decimal_ routines to handle decimal FP, and call helper routines that currently still go via DOUBLEST to handle binary FP (derived from current valarith.c code). These routines are used to handle both binary and decimal FP types in scalar_binop, value_equal, and value_less, mostly following the method currently used for decimal FP. The existing value_args_as_decimal helper is renamed to value_args_as_target_float and extended to handle both binary and decimal types. The unary operations value_pos and value_neg are also simplified, the former by using a simple copy for all scalar types, the latter by using value_binop (... BINOP_SUB) to implement negation as subtraction from zero. ChangeLog: 2017-11-06 Ulrich Weigand <uweigand@de.ibm.com> * target-float.c: Include <math.h>. (floatformat_binop): New function. (floatformat_compare): Likewise. (target_float_binop): Likewise. (target_float_compare): Likewise. * target-float.h: Include "expression.h". (target_float_binop): Add prototype. (target_float_compare): Likewise. * valarith.c: Do not include "doublest.h" and "dfp.h". Include "common/byte-vector.h". (value_args_as_decimal): Remove, replace by ... (value_args_as_target_float): ... this function. Handle both binary and decimal target floating-point formats. (scalar_binop): Handle both binary and decimal FP using value_args_as_target_float and target_float_binop. (value_equal): Handle both binary and decimal FP using value_args_as_target_float and target_float_compare. (value_less): Likewise. (value_pos): Handle all scalar types as simple copy. (value_neg): Handle all scalar types via BINOP_SUB from 0. * dfp.c (decimal_binop): Throw error instead of internal_error when called with an unsupported operation code.
2017-11-06Target FP: Add conversion routines to target-float.{c,h}Ulrich Weigand1-0/+169
This patch adds the following conversion routines: - target_float_to_longest - target_float_from_longest - target_float_from_ulongest - target_float_convert which call the equivalent decimal_ routines to handle decimal FP, and call helper routines that currently still go via DOUBLEST to handle binary FP. The target_float_convert routine not only handles BFP<->BFP and DFP<->DFP conversions, but also BFP<->DFP, which are implemented by converting to a string and back. These helpers are used in particular to implement conversion from and to FP in value_cast, without going through DOUBLEST there. In order to implement this for the FP<-integer case, the pack_long / pack_unsigned_long routines are extended to support floating-point values as output (thereby allowing use of value_from_[u]longest with a floating-point target type). This latter change also allows simplification of value_one. gdb/ChangeLog: 2017-11-06 Ulrich Weigand <uweigand@de.ibm.com> * target-float.c (floatformat_to_longest): New function. (floatformat_from_longest, floatformat_from_ulongest): Likewise. (floatformat_convert): Likewise. (target_float_to_longest): Likewise. (target_float_from_longest, target_float_from_ulongest): Likewise. (target_float_convert): Likewise. * target-float.h (target_float_to_longest): Add prototype. (target_float_from_longest, target_float_from_ulongest): Likewise. (target_float_convert): Likewise. * value.c (unpack_long): Use target_float_to_longest. (pack_long): Allow FP types. Use target_float_from_longest. (pack_unsigned_long): Likewise using target_float_from_ulongest. * valops.c: Include "target-float.h". Do not include "dfp.h". (value_cast): Handle conversions to FP using target_float_convert, value_from_ulongest, and value_from_longest. (value_one): Use value_from_longest for FP types as well.
2017-11-06Target FP: Add string routines to target-float.{c,h}Ulrich Weigand1-0/+37
This adds target_float_to_string and target_float_from_string, which dispatch to the corresponding floatformat_ or decimal_ routines. Existing users of those routines are changed to use the new target-float routines instead (most of those places already handle both binary and decimal FP). In addition, two other places are changes to use target_float_from_string: - define_symbol in stabsread.c, when parsing a floating-point literal from stabs debug info - gdbarch-selftest.c when initializing a target format values (to eliminate use of DOUBLEST there). gdb/ChangeLog: 2017-11-06 Ulrich Weigand <uweigand@de.ibm.com> * target-float.c (target_float_to_string): New function. (target_float_from_string): New function. * target-float.h (target_float_to_string): Add prototype. (target_float_from_string): Add prototype. * valprint.c: Include "target-float.h". Do not include "doublest.h" and "dfp.h". (print_floating): Use target_float_to_string. * printcmd.c: Include "target-float.h". Do not include "dfp.h". (printf_floating): Use target_float_to_string. * i387-tdep.c: Include "target-float.h". Do not include "doublest.h". (print_i387_value): Use target_float_to_string. * mips-tdep.c: Include "target-float.h". (mips_print_fp_register): Use target_float_to_string. * sh64-tdep.c: Include "target-float.h". (sh64_do_fp_register): Use target_float_to_string. * parse.c: Include "target-float.h". Do not include "doublest.h" and "dfp.h". (parse_float): Use target_float_from_string. * stabsread.c: Include "target-float.h". Do not include "doublest.h". (define_symbol): Use target_float_from_string. * gdbarch-selftests.c: Include "target-float.h". (register_to_value_test): Use target_float_from_string.
2017-11-06Target FP: Introduce target-float.{c,h}Ulrich Weigand1-0/+62
This patch introduces the new set of target floating-point handling routines in target-float.{c,h}. In the end, the intention is that this file will contain support for all operations in target FP format, fully replacing both the current doublest.{c,h} and dfp.{c,h}. To begin with, this patch only adds a target_float_is_zero routine, which handles the equivalent of decimal_is_zero for both binary and decimal FP. For the binary case, to avoid conversion to DOUBLEST, this is implemented using the floatformat_classify routine. However, it turns out that floatformat_classify actually has a bug (it was not used to check for zero before), so this is fixed as well. The new routine is used in both value_logical_not and valpy_nonzero. There is one extra twist: the code previously used value_as_double to convert to DOUBLEST and then compare against zero. That routine performs an extra task: it detects invalid floating-point values and raises an error. In any place where value_as_double is removed in favor of some target-float.c routine, we need to replace that check. To keep this check centralized in one place, I've added a new routine is_floating_value, which returns a boolean determining whether a value's type is floating point (binary or decimal), and if so, also performs the validity check. Since we need to check whether a value is FP before calling any of the target-float routines anyway, this seems a good place to add the check without much code size overhead. In some places where we only want to check for floating-point types and not perform a validity check (e.g. for the *output* of an operation), we can use the new is_floating_type routine (in gdbarch) instead. The validity check itself is done by a new target_float_is_valid routine in target-float, encapsulating floatformat_is_valid. ChangeLog: 2017-11-06 Ulrich Weigand <uweigand@de.ibm.com> * Makefile.c (SFILES): Add target-float.c. (HFILES_NO_SRCDIR): Add target-float.h. (COMMON_OBS): Add target-float.o. * target-float.h: New file. * target-float.c: New file. * doublest.c (floatformat_classify): Fix detection of float_zero. * gdbtypes.c (is_floating_type): New function. * gdbtypes.h (is_floating_type): Add prototype. * value.c: Do not include "floatformat.h". (unpack_double): Use target_float_is_valid. (is_floating_value): New function. * value.h (is_floating_value): Add prototype- * valarith.c: Include "target-float.h". (value_logical_not): Use target_float_is_zero. * python/py-value.c: Include "target-float.h". (valpy_nonzero): Use target_float_is_zero.