This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[rfc/rfa(DavidT?)] Move DOUBLEST to doublest.{h,c}
- To: gdb-patches at sources dot redhat dot com
- Subject: [rfc/rfa(DavidT?)] Move DOUBLEST to doublest.{h,c}
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Mon, 16 Jul 2001 11:18:13 -0400
Hello,
(As they say, always have a plan B. Plan A, reclaim floatformat, failed
:-).
The attached patch moves all the floating point conversion routines to a
single place - doublest.[hc]. It doesn't modify the actual code. It
updates all the missing include dependencies that I could find. All the
buildable targets listed in the MAINTAINERS file still build.
Look OK? I note this carves a chunk out of both utils.c and findvar.c
What's next?
I've a follow on patch to introduce two new functions
extract_floatformat() and store_floatformat(). All th magic currently
found in extract_floating() and store_floating() would be moved to these
new functions. All current calls to floatformat_from_doublest() and
floatformat_to_doublest() would be replaced by those functions. The net
effect would be that all floating point conversions would go through a
single path and always use the most exact mechanism available.
I've also a second patch to tweek the actual conversion code so that it
isn't as lossy (use ULONGEST instead of unsigned long).
If anyone ever gets inspired they could then extend doublest.[hc] to
implement portable floating point (using either gcc/real.c or
sim/common/sim-fpu.[hc].
Andrew
2001-07-15 Andrew Cagney <ac131313@redhat.com>
* defs.h (HOST_FLOAT_FORMAT, HOST_DOUBLE_FORMAT)
(HOST_FLOAT_FORMAT, HOST_DOUBLE_FORMAT)
(HOST_LONG_DOUBLE_FORMAT, DOUBLEST)
(floatformat_to_doublest, floatformat_from_doublest)
(floatformat_is_negative, floatformat_is_nan)
(floatformat_mantissa, store_floating)
(extract_floating): Move declaration from here.
* doublest.h: To here. New file.
* utils.c (get_field, floatformat_to_doublest, put_field)
(ldfrexp, floatformat_from_doublest, floatformat_is_negative)
(floatformat_is_nan, floatformat_mantissa)
(FLOATFORMAT_CHAR_BIT): Move from here.
* doublest.c: To here. New file.
* findvar.c (store_floating, extract_floating): Move from here.
* doublest.c: To here.
* Makefile.in (SFILES): Add doublest.c.
(COMMON_OBS): Add doublest.o.
(doublest.o): Specify dependencies.
(doublest_h): Define.
* config/m88k/tm-m88k.h: Include "doublest.h".
* config/m68k/tm-m68k.h, config/i960/tm-i960.h: Ditto.
* config/i386/xm-nbsd.h, config/i386/xm-linux.h: Ditto.
* config/i386/xm-i386gnu.h, config/i386/xm-go32.h: Ditto.
* config/i386/xm-fbsd.h, config/i386/tm-symmetry.h: Ditto.
* rs6000-tdep.c, valarith.c: Ditto.
* valprint.c, stabsread.c, sh-tdep.c: Ditto.
* ia64-tdep.c, i387-tdep.c, i386-tdep.c: Ditto.
* values.c, arm-tdep.c, arm-linux-tdep.c: Ditto.
* alpha-tdep.c, ax.h, expression.h: Ditto.
* Makefile.in (arm-tdep.o): Add $(doublest_h).
(i386-tdep.o, i387-tdep.o, ia64-tdep.o): Ditto.
(rs6000-tdep.o, stabsread.o, valarith.o): Ditto.
(values.o, valprint.o, arm-linux-tdep.o): Ditto.
(alpha-tdep.o, ax_h): Ditto.
(expression_h): Add $(doublest_h) and $(symtab_h).
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.98
diff -p -r1.98 Makefile.in
*** Makefile.in 2001/07/15 18:57:06 1.98
--- Makefile.in 2001/07/16 15:00:10
*************** SFILES = ax-general.c ax-gdb.c bcache.c
*** 540,546 ****
tui/tuiStack.c tui/tuiStack.h tui/tuiWin.c tui/tuiWin.h \
tui/tui-file.h tui/tui-file.c \
ui-file.h ui-file.c \
! frame.c \
gnu-v2-abi.c gnu-v3-abi.c hpacc-abi.c cp-abi.c
LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
--- 540,546 ----
tui/tuiStack.c tui/tuiStack.h tui/tuiWin.c tui/tuiWin.h \
tui/tui-file.h tui/tui-file.c \
ui-file.h ui-file.c \
! frame.c doublest.c \
gnu-v2-abi.c gnu-v3-abi.c hpacc-abi.c cp-abi.c
LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
*************** frame_h = frame.h
*** 582,588 ****
symtab_h = symtab.h bcache.h
symfile_h = symfile.h
gdbtypes_h = gdbtypes.h
! expression_h = expression.h
value_h = value.h $(symtab_h) $(gdbtypes_h) $(expression_h)
breakpoint_h = breakpoint.h $(frame_h) $(value_h)
--- 582,588 ----
symtab_h = symtab.h bcache.h
symfile_h = symfile.h
gdbtypes_h = gdbtypes.h
! expression_h = expression.h $(doublest_h) $(symtab_h)
value_h = value.h $(symtab_h) $(gdbtypes_h) $(expression_h)
breakpoint_h = breakpoint.h $(frame_h) $(value_h)
*************** tm_h = @tm_h@
*** 597,608 ****
nm_h = @nm_h@
defs_h = defs.h $(xm_h) $(tm_h) $(nm_h) config.status config.h gdbarch.h ui-file.h
top_h = top.h
inferior_h = inferior.h $(breakpoint_h)
target_h = target.h $(bfd_h) $(symtab_h) $(dcache_h) $(memattr_h)
memattr_h = memattr.h
tracepoint_h = tracepoint.h
! ax_h = ax.h
event_loop_h = event-loop.h
event_top_h = event-top.h
inf_loop_h = inf-loop.h
--- 597,610 ----
nm_h = @nm_h@
defs_h = defs.h $(xm_h) $(tm_h) $(nm_h) config.status config.h gdbarch.h ui-file.h
+ doublest_h = doublest.h $(floatformat_h)
+
top_h = top.h
inferior_h = inferior.h $(breakpoint_h)
target_h = target.h $(bfd_h) $(symtab_h) $(dcache_h) $(memattr_h)
memattr_h = memattr.h
tracepoint_h = tracepoint.h
! ax_h = ax.h $(doublest_h)
event_loop_h = event-loop.h
event_top_h = event-top.h
inf_loop_h = inf-loop.h
*************** COMMON_OBS = version.o blockframe.o brea
*** 695,701 ****
c-valprint.o cp-valprint.o ch-valprint.o f-valprint.o m2-valprint.o \
nlmread.o serial.o mdebugread.o os9kread.o top.o utils.o \
ui-file.o tui-file.o \
! frame.o \
gnu-v2-abi.o gnu-v3-abi.o hpacc-abi.o cp-abi.o
OBS = $(COMMON_OBS) $(ANNOTATE_OBS)
--- 697,703 ----
c-valprint.o cp-valprint.o ch-valprint.o f-valprint.o m2-valprint.o \
nlmread.o serial.o mdebugread.o os9kread.o top.o utils.o \
ui-file.o tui-file.o \
! frame.o doublest.o \
gnu-v2-abi.o gnu-v3-abi.o hpacc-abi.o cp-abi.o
OBS = $(COMMON_OBS) $(ANNOTATE_OBS)
*************** alpha-nat.o: alpha-nat.c $(defs_h) $(gdb
*** 1204,1210 ****
alpha-tdep.o: alpha-tdep.c $(defs_h) $(gdbcmd_h) $(gdbcore_h) \
$(inferior_h) $(symtab_h) $(dis-asm.h) $(gdb_string_h) linespec.h \
! $(regcache_h)
annotate.o: annotate.c $(defs_h) annotate.h $(value_h) target.h $(gdbtypes_h)
--- 1206,1212 ----
alpha-tdep.o: alpha-tdep.c $(defs_h) $(gdbcmd_h) $(gdbcore_h) \
$(inferior_h) $(symtab_h) $(dis-asm.h) $(gdb_string_h) linespec.h \
! $(regcache_h) $(doublest_h)
annotate.o: annotate.c $(defs_h) annotate.h $(value_h) target.h $(gdbtypes_h)
*************** arm-linux-nat.o: arm-linux-nat.c $(defs_
*** 1212,1221 ****
$(gdb_string_h) $(regcache_h)
arm-linux-tdep.o: arm-linux-tdep.c $(defs_h) target.h $(value_h) \
! $(gdbtypes_h) $(floatformat_h) $(regcache_h)
arm-tdep.o: arm-tdep.c $(gdbcmd_h) $(gdbcore_h) $(inferior_h) $(defs_h) \
! $(gdbcore_h) $(regcache_h)
bcache.o: bcache.c bcache.h $(defs_h)
--- 1214,1223 ----
$(gdb_string_h) $(regcache_h)
arm-linux-tdep.o: arm-linux-tdep.c $(defs_h) target.h $(value_h) \
! $(gdbtypes_h) $(floatformat_h) $(regcache_h) $(doublest_h)
arm-tdep.o: arm-tdep.c $(gdbcmd_h) $(gdbcore_h) $(inferior_h) $(defs_h) \
! $(gdbcore_h) $(regcache_h) $(doublest_h)
bcache.o: bcache.c bcache.h $(defs_h)
*************** c-typeprint.o: c-typeprint.c c-lang.h $(
*** 1239,1244 ****
--- 1241,1249 ----
c-valprint.o: c-valprint.c $(defs_h) $(expression_h) $(gdbtypes_h) \
language.h $(symtab_h) valprint.h $(value_h) $(cp_abi_h)
+ doublest.o: doublest.c $(defs_h) $(doublest_h) $(floatformat_h) \
+ gdb_assert.h gdb_string.h
+
f-lang.o: f-lang.c f-lang.h $(defs_h) $(expression_h) $(gdbtypes_h) \
language.h parser-defs.h $(symtab_h) $(gdb_string_h)
*************** i386gnu-nat.o: gnu-nat.h
*** 1523,1529 ****
i386-tdep.o: i386-tdep.c $(defs_h) $(gdb_string_h) $(frame_h) \
$(inferior_h) $(gdbcore_h) target.h $(floatformat_h) \
! $(symtab_h) $(gdbcmd_h) $(command_h) $(arch_utils_h) $(regcache_h)
i386-nat.o: i386-nat.c $(defs_h) $(breakpoint_h) $(command_h) $(gdbcmd_h)
--- 1528,1535 ----
i386-tdep.o: i386-tdep.c $(defs_h) $(gdb_string_h) $(frame_h) \
$(inferior_h) $(gdbcore_h) target.h $(floatformat_h) \
! $(symtab_h) $(gdbcmd_h) $(command_h) $(arch_utils_h) $(regcache_h) \
! $(doublest_h)
i386-nat.o: i386-nat.c $(defs_h) $(breakpoint_h) $(command_h) $(gdbcmd_h)
*************** i386-linux-tdep.o: i386-linux-tdep.c $(d
*** 1560,1566 ****
i386v4-nat.o: i386v4-nat.c $(defs_h) $(regcache_h)
i387-tdep.o: i387-tdep.c $(floatformat_h) $(defs_h) $(gdbcore_h) \
! $(inferior_h) language.h $(regcache_h)
i960-tdep.o: i960-tdep.c $(floatformat_h) $(defs_h) $(expression_h) \
$(frame_h) $(gdbtypes_h) $(symtab_h) $(value_h) $(gdbcore_h) \
--- 1566,1572 ----
i386v4-nat.o: i386v4-nat.c $(defs_h) $(regcache_h)
i387-tdep.o: i387-tdep.c $(floatformat_h) $(defs_h) $(gdbcore_h) \
! $(inferior_h) language.h $(regcache_h) $(doublest_h)
i960-tdep.o: i960-tdep.c $(floatformat_h) $(defs_h) $(expression_h) \
$(frame_h) $(gdbtypes_h) $(symtab_h) $(value_h) $(gdbcore_h) \
*************** ia64-linux-tdep.o: ia64-linux-tdep.c $(d
*** 1573,1579 ****
ia64-tdep.o: ia64-tdep.c $(defs_h) $(inferior_h) symfile.h $(gdbcore_h) \
$(arch_utils_h) $(floatformat_h) objfiles.h \
! $(INCLUDE_DIR)/elf/common.h $(regcache_h)
infcmd.o: infcmd.c $(defs_h) environ.h $(gdbcmd_h) $(gdbcore_h) \
$(inferior_h) target.h language.h symfile.h $(gdb_string_h) \
--- 1579,1585 ----
ia64-tdep.o: ia64-tdep.c $(defs_h) $(inferior_h) symfile.h $(gdbcore_h) \
$(arch_utils_h) $(floatformat_h) objfiles.h \
! $(INCLUDE_DIR)/elf/common.h $(regcache_h) $(doublest_h)
infcmd.o: infcmd.c $(defs_h) environ.h $(gdbcmd_h) $(gdbcore_h) \
$(inferior_h) target.h language.h symfile.h $(gdb_string_h) \
*************** rs6000-nat.o: rs6000-nat.c $(bfd_h) $(de
*** 1925,1931 ****
$(regcache_h)
rs6000-tdep.o: rs6000-tdep.c $(defs_h) $(gdbcore_h) $(inferior_h) \
! target.h ppc-tdep.h $(regcache_h)
scm-exp.o: $(defs_h) $(value_h) parser-defs.h language.h c-lang.h \
scm-lang.h scm-tags.h
--- 1931,1937 ----
$(regcache_h)
rs6000-tdep.o: rs6000-tdep.c $(defs_h) $(gdbcore_h) $(inferior_h) \
! target.h ppc-tdep.h $(regcache_h) $(doublest_h)
scm-exp.o: $(defs_h) $(value_h) parser-defs.h language.h c-lang.h \
scm-lang.h scm-tags.h
*************** serial.o: serial.c $(defs_h) serial.h $(
*** 1951,1957 ****
sh-tdep.o: sh-tdep.c $(bfd_h) $(dis-asm_h) \
$(srcdir)/../opcodes/sh-opc.h $(defs_h) $(expression_h) $(frame_h) \
$(gdbcmd_h) $(gdbtypes_h) $(symtab_h) $(value_h) $(arch_utils_h) \
! $(regcache_h)
sh3-rom.o: sh3-rom.c monitor.h $(bfd_h) gdb_wait.h $(defs_h) $(gdbcmd_h) \
$(inferior_h) target.h serial.h terminal.h $(arch_utils_h) \
--- 1957,1963 ----
sh-tdep.o: sh-tdep.c $(bfd_h) $(dis-asm_h) \
$(srcdir)/../opcodes/sh-opc.h $(defs_h) $(expression_h) $(frame_h) \
$(gdbcmd_h) $(gdbtypes_h) $(symtab_h) $(value_h) $(arch_utils_h) \
! $(regcache_h) $(doublest_h)
sh3-rom.o: sh3-rom.c monitor.h $(bfd_h) gdb_wait.h $(defs_h) $(gdbcmd_h) \
$(inferior_h) target.h serial.h terminal.h $(arch_utils_h) \
*************** dsrec.o: dsrec.c $(defs_h) srec.h
*** 1988,1994 ****
stabsread.o: stabsread.c $(bfd_h) $(INCLUDE_DIR)/aout/stab.def \
$(INCLUDE_DIR)/aout/stab_gnu.h buildsym.h complaints.h $(defs_h) \
$(gdbtypes_h) objfiles.h stabsread.h symfile.h $(symtab_h) \
! $(gdb_string_h)
stack.o: stack.c $(defs_h) $(gdbcmd_h) $(gdbcore_h) $(inferior_h) \
language.h target.h $(gdb_string_h) $(ui_out_h)
--- 1994,2000 ----
stabsread.o: stabsread.c $(bfd_h) $(INCLUDE_DIR)/aout/stab.def \
$(INCLUDE_DIR)/aout/stab_gnu.h buildsym.h complaints.h $(defs_h) \
$(gdbtypes_h) objfiles.h stabsread.h symfile.h $(symtab_h) \
! $(gdb_string_h) $(doublest_h)
stack.o: stack.c $(defs_h) $(gdbcmd_h) $(gdbcore_h) $(inferior_h) \
language.h target.h $(gdb_string_h) $(ui_out_h)
*************** utils.o: utils.c $(bfd_h) $(defs_h) $(ex
*** 2059,2076 ****
valarith.o: valarith.c $(bfd_h) $(defs_h) $(expression_h) \
$(gdbtypes_h) language.h $(symtab_h) target.h $(value_h) \
! $(gdb_string_h)
valops.o: valops.c $(defs_h) $(gdbcore_h) $(inferior_h) target.h \
$(gdb_string_h) $(regcache_h) $(cp_abi_h)
valprint.o: valprint.c $(defs_h) $(expression_h) $(gdbcmd_h) \
$(gdbcore_h) $(gdbtypes_h) language.h $(symtab_h) target.h \
! $(value_h) $(gdb_string_h) valprint.h
values.o: values.c $(defs_h) $(expression_h) $(frame_h) $(gdbcmd_h) \
$(gdbcore_h) $(gdbtypes_h) $(symtab_h) target.h $(value_h) \
! $(gdb_string_h) scm-lang.h
vax-tdep.o: vax-tdep.c $(OP_INCLUDE)/vax.h $(defs_h) $(symtab_h)
--- 2065,2082 ----
valarith.o: valarith.c $(bfd_h) $(defs_h) $(expression_h) \
$(gdbtypes_h) language.h $(symtab_h) target.h $(value_h) \
! $(gdb_string_h) $(doublest_h)
valops.o: valops.c $(defs_h) $(gdbcore_h) $(inferior_h) target.h \
$(gdb_string_h) $(regcache_h) $(cp_abi_h)
valprint.o: valprint.c $(defs_h) $(expression_h) $(gdbcmd_h) \
$(gdbcore_h) $(gdbtypes_h) language.h $(symtab_h) target.h \
! $(value_h) $(gdb_string_h) valprint.h $(doublest_h)
values.o: values.c $(defs_h) $(expression_h) $(frame_h) $(gdbcmd_h) \
$(gdbcore_h) $(gdbtypes_h) $(symtab_h) target.h $(value_h) \
! $(gdb_string_h) scm-lang.h $(doublest_h)
vax-tdep.o: vax-tdep.c $(OP_INCLUDE)/vax.h $(defs_h) $(symtab_h)
Index: alpha-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/alpha-tdep.c,v
retrieving revision 1.10
diff -p -r1.10 alpha-tdep.c
*** alpha-tdep.c 2001/07/15 20:10:02 1.10
--- alpha-tdep.c 2001/07/16 15:00:14
***************
*** 32,37 ****
--- 32,38 ----
#include "gdb_string.h"
#include "linespec.h"
#include "regcache.h"
+ #include "doublest.h"
/* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
Index: arm-linux-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/arm-linux-tdep.c,v
retrieving revision 1.9
diff -p -r1.9 arm-linux-tdep.c
*** arm-linux-tdep.c 2001/07/15 20:10:02 1.9
--- arm-linux-tdep.c 2001/07/16 15:00:15
***************
*** 26,31 ****
--- 26,32 ----
#include "gdbcore.h"
#include "frame.h"
#include "regcache.h"
+ #include "doublest.h"
/* For arm_linux_skip_solib_resolver. */
#include "symtab.h"
Index: arm-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/arm-tdep.c,v
retrieving revision 1.13
diff -p -r1.13 arm-tdep.c
*** arm-tdep.c 2001/07/15 20:10:02 1.13
--- arm-tdep.c 2001/07/16 15:00:22
***************
*** 30,35 ****
--- 30,36 ----
#include "dis-asm.h" /* For register flavors. */
#include <ctype.h> /* for isupper () */
#include "regcache.h"
+ #include "doublest.h"
/* Each OS has a different mechanism for accessing the various
registers stored in the sigcontext structure.
Index: ax.h
===================================================================
RCS file: /cvs/src/src/gdb/ax.h,v
retrieving revision 1.4
diff -p -r1.4 ax.h
*** ax.h 2001/03/06 08:21:05 1.4
--- ax.h 2001/07/16 15:00:23
***************
*** 21,26 ****
--- 21,28 ----
#ifndef AGENTEXPR_H
#define AGENTEXPR_H
+ #include "doublest.h" /* For DOUBLEST. */
+
/* It's sometimes useful to be able to debug programs that you can't
really stop for more than a fraction of a second. To this end, the
user can specify a tracepoint (like a breakpoint, but you don't
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.59
diff -p -r1.59 defs.h
*** defs.h 2001/07/16 14:13:05 1.59
--- defs.h 2001/07/16 15:00:27
*************** extern void store_address (void *, int,
*** 1255,1318 ****
extern void store_typed_address (void *buf, struct type *type, CORE_ADDR addr);
- /* Setup definitions for host and target floating point formats. We need to
- consider the format for `float', `double', and `long double' for both target
- and host. We need to do this so that we know what kind of conversions need
- to be done when converting target numbers to and from the hosts DOUBLEST
- data type. */
-
- /* This is used to indicate that we don't know the format of the floating point
- number. Typically, this is useful for native ports, where the actual format
- is irrelevant, since no conversions will be taking place. */
-
- extern const struct floatformat floatformat_unknown;
-
- #if HOST_BYTE_ORDER == BIG_ENDIAN
- #ifndef HOST_FLOAT_FORMAT
- #define HOST_FLOAT_FORMAT &floatformat_ieee_single_big
- #endif
- #ifndef HOST_DOUBLE_FORMAT
- #define HOST_DOUBLE_FORMAT &floatformat_ieee_double_big
- #endif
- #else /* LITTLE_ENDIAN */
- #ifndef HOST_FLOAT_FORMAT
- #define HOST_FLOAT_FORMAT &floatformat_ieee_single_little
- #endif
- #ifndef HOST_DOUBLE_FORMAT
- #define HOST_DOUBLE_FORMAT &floatformat_ieee_double_little
- #endif
- #endif
-
- #ifndef HOST_LONG_DOUBLE_FORMAT
- #define HOST_LONG_DOUBLE_FORMAT &floatformat_unknown
- #endif
-
- /* Use `long double' if the host compiler supports it. (Note that this is not
- necessarily any longer than `double'. On SunOS/gcc, it's the same as
- double.) This is necessary because GDB internally converts all floating
- point values to the widest type supported by the host.
-
- There are problems however, when the target `long double' is longer than the
- host's `long double'. In general, we'll probably reduce the precision of
- any such values and print a warning. */
-
- #ifdef HAVE_LONG_DOUBLE
- typedef long double DOUBLEST;
- #else
- typedef double DOUBLEST;
- #endif
-
- extern void floatformat_to_doublest (const struct floatformat *,
- char *, DOUBLEST *);
- extern void floatformat_from_doublest (const struct floatformat *,
- DOUBLEST *, char *);
-
- extern int floatformat_is_negative (const struct floatformat *, char *);
- extern int floatformat_is_nan (const struct floatformat *, char *);
- extern char *floatformat_mantissa (const struct floatformat *, char *);
-
- extern DOUBLEST extract_floating (void *, int);
- extern void store_floating (void *, int, DOUBLEST);
/* From valops.c */
--- 1255,1260 ----
Index: doublest.c
===================================================================
RCS file: doublest.c
diff -N doublest.c
*** /dev/null Tue May 5 13:32:27 1998
--- doublest.c Mon Jul 16 08:00:28 2001
***************
*** 0 ****
--- 1,627 ----
+ /* Floating point routines for GDB, the GNU debugger.
+ Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
+ 1997, 1998, 1999, 2000, 2001
+ Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ /* Support for converting target fp numbers into host DOUBLEST format. */
+
+ /* XXX - This code should really be in libiberty/floatformat.c,
+ however configuration issues with libiberty made this very
+ difficult to do in the available time. */
+
+ #include "defs.h"
+ #include "doublest.h"
+ #include "floatformat.h"
+ #include "gdb_assert.h"
+ #include "gdb_string.h"
+ #include <math.h> /* ldexp */
+
+ /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
+ going to bother with trying to muck around with whether it is defined in
+ a system header, what we do if not, etc. */
+ #define FLOATFORMAT_CHAR_BIT 8
+
+ static unsigned long get_field (unsigned char *,
+ enum floatformat_byteorders,
+ unsigned int, unsigned int, unsigned int);
+
+ /* Extract a field which starts at START and is LEN bytes long. DATA and
+ TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
+ static unsigned long
+ get_field (unsigned char *data, enum floatformat_byteorders order,
+ unsigned int total_len, unsigned int start, unsigned int len)
+ {
+ unsigned long result;
+ unsigned int cur_byte;
+ int cur_bitshift;
+
+ /* Start at the least significant part of the field. */
+ if (order == floatformat_little || order == floatformat_littlebyte_bigword)
+ {
+ /* We start counting from the other end (i.e, from the high bytes
+ rather than the low bytes). As such, we need to be concerned
+ with what happens if bit 0 doesn't start on a byte boundary.
+ I.e, we need to properly handle the case where total_len is
+ not evenly divisible by 8. So we compute ``excess'' which
+ represents the number of bits from the end of our starting
+ byte needed to get to bit 0. */
+ int excess = FLOATFORMAT_CHAR_BIT - (total_len % FLOATFORMAT_CHAR_BIT);
+ cur_byte = (total_len / FLOATFORMAT_CHAR_BIT)
+ - ((start + len + excess) / FLOATFORMAT_CHAR_BIT);
+ cur_bitshift = ((start + len + excess) % FLOATFORMAT_CHAR_BIT)
+ - FLOATFORMAT_CHAR_BIT;
+ }
+ else
+ {
+ cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
+ cur_bitshift =
+ ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
+ }
+ if (cur_bitshift > -FLOATFORMAT_CHAR_BIT)
+ result = *(data + cur_byte) >> (-cur_bitshift);
+ else
+ result = 0;
+ cur_bitshift += FLOATFORMAT_CHAR_BIT;
+ if (order == floatformat_little || order == floatformat_littlebyte_bigword)
+ ++cur_byte;
+ else
+ --cur_byte;
+
+ /* Move towards the most significant part of the field. */
+ while (cur_bitshift < len)
+ {
+ result |= (unsigned long)*(data + cur_byte) << cur_bitshift;
+ cur_bitshift += FLOATFORMAT_CHAR_BIT;
+ if (order == floatformat_little || order == floatformat_littlebyte_bigword)
+ ++cur_byte;
+ else
+ --cur_byte;
+ }
+ if (len < sizeof(result) * FLOATFORMAT_CHAR_BIT)
+ /* Mask out bits which are not part of the field */
+ result &= ((1UL << len) - 1);
+ return result;
+ }
+
+ /* Convert from FMT to a DOUBLEST.
+ FROM is the address of the extended float.
+ Store the DOUBLEST in *TO. */
+
+ void
+ floatformat_to_doublest (const struct floatformat *fmt, char *from,
+ DOUBLEST *to)
+ {
+ unsigned char *ufrom = (unsigned char *) from;
+ DOUBLEST dto;
+ long exponent;
+ unsigned long mant;
+ unsigned int mant_bits, mant_off;
+ int mant_bits_left;
+ int special_exponent; /* It's a NaN, denorm or zero */
+
+ /* If the mantissa bits are not contiguous from one end of the
+ mantissa to the other, we need to make a private copy of the
+ source bytes that is in the right order since the unpacking
+ algorithm assumes that the bits are contiguous.
+
+ Swap the bytes individually rather than accessing them through
+ "long *" since we have no guarantee that they start on a long
+ alignment, and also sizeof(long) for the host could be different
+ than sizeof(long) for the target. FIXME: Assumes sizeof(long)
+ for the target is 4. */
+
+ if (fmt->byteorder == floatformat_littlebyte_bigword)
+ {
+ static unsigned char *newfrom;
+ unsigned char *swapin, *swapout;
+ int longswaps;
+
+ longswaps = fmt->totalsize / FLOATFORMAT_CHAR_BIT;
+ longswaps >>= 3;
+
+ if (newfrom == NULL)
+ {
+ newfrom = (unsigned char *) xmalloc (fmt->totalsize);
+ }
+ swapout = newfrom;
+ swapin = ufrom;
+ ufrom = newfrom;
+ while (longswaps-- > 0)
+ {
+ /* This is ugly, but efficient */
+ *swapout++ = swapin[4];
+ *swapout++ = swapin[5];
+ *swapout++ = swapin[6];
+ *swapout++ = swapin[7];
+ *swapout++ = swapin[0];
+ *swapout++ = swapin[1];
+ *swapout++ = swapin[2];
+ *swapout++ = swapin[3];
+ swapin += 8;
+ }
+ }
+
+ exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+ fmt->exp_start, fmt->exp_len);
+ /* Note that if exponent indicates a NaN, we can't really do anything useful
+ (not knowing if the host has NaN's, or how to build one). So it will
+ end up as an infinity or something close; that is OK. */
+
+ mant_bits_left = fmt->man_len;
+ mant_off = fmt->man_start;
+ dto = 0.0;
+
+ special_exponent = exponent == 0 || exponent == fmt->exp_nan;
+
+ /* Don't bias NaNs. Use minimum exponent for denorms. For simplicity,
+ we don't check for zero as the exponent doesn't matter. */
+ if (!special_exponent)
+ exponent -= fmt->exp_bias;
+ else if (exponent == 0)
+ exponent = 1 - fmt->exp_bias;
+
+ /* Build the result algebraically. Might go infinite, underflow, etc;
+ who cares. */
+
+ /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
+ increment the exponent by one to account for the integer bit. */
+
+ if (!special_exponent)
+ {
+ if (fmt->intbit == floatformat_intbit_no)
+ dto = ldexp (1.0, exponent);
+ else
+ exponent++;
+ }
+
+ while (mant_bits_left > 0)
+ {
+ mant_bits = min (mant_bits_left, 32);
+
+ mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+ mant_off, mant_bits);
+
+ dto += ldexp ((double) mant, exponent - mant_bits);
+ exponent -= mant_bits;
+ mant_off += mant_bits;
+ mant_bits_left -= mant_bits;
+ }
+
+ /* Negate it if negative. */
+ if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
+ dto = -dto;
+ *to = dto;
+ }
+
+ static void put_field (unsigned char *, enum floatformat_byteorders,
+ unsigned int,
+ unsigned int, unsigned int, unsigned long);
+
+ /* Set a field which starts at START and is LEN bytes long. DATA and
+ TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
+ static void
+ put_field (unsigned char *data, enum floatformat_byteorders order,
+ unsigned int total_len, unsigned int start, unsigned int len,
+ unsigned long stuff_to_put)
+ {
+ unsigned int cur_byte;
+ int cur_bitshift;
+
+ /* Start at the least significant part of the field. */
+ if (order == floatformat_little || order == floatformat_littlebyte_bigword)
+ {
+ int excess = FLOATFORMAT_CHAR_BIT - (total_len % FLOATFORMAT_CHAR_BIT);
+ cur_byte = (total_len / FLOATFORMAT_CHAR_BIT)
+ - ((start + len + excess) / FLOATFORMAT_CHAR_BIT);
+ cur_bitshift = ((start + len + excess) % FLOATFORMAT_CHAR_BIT)
+ - FLOATFORMAT_CHAR_BIT;
+ }
+ else
+ {
+ cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
+ cur_bitshift =
+ ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
+ }
+ if (cur_bitshift > -FLOATFORMAT_CHAR_BIT)
+ {
+ *(data + cur_byte) &=
+ ~(((1 << ((start + len) % FLOATFORMAT_CHAR_BIT)) - 1)
+ << (-cur_bitshift));
+ *(data + cur_byte) |=
+ (stuff_to_put & ((1 << FLOATFORMAT_CHAR_BIT) - 1)) << (-cur_bitshift);
+ }
+ cur_bitshift += FLOATFORMAT_CHAR_BIT;
+ if (order == floatformat_little || order == floatformat_littlebyte_bigword)
+ ++cur_byte;
+ else
+ --cur_byte;
+
+ /* Move towards the most significant part of the field. */
+ while (cur_bitshift < len)
+ {
+ if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT)
+ {
+ /* This is the last byte. */
+ *(data + cur_byte) &=
+ ~((1 << (len - cur_bitshift)) - 1);
+ *(data + cur_byte) |= (stuff_to_put >> cur_bitshift);
+ }
+ else
+ *(data + cur_byte) = ((stuff_to_put >> cur_bitshift)
+ & ((1 << FLOATFORMAT_CHAR_BIT) - 1));
+ cur_bitshift += FLOATFORMAT_CHAR_BIT;
+ if (order == floatformat_little || order == floatformat_littlebyte_bigword)
+ ++cur_byte;
+ else
+ --cur_byte;
+ }
+ }
+
+ #ifdef HAVE_LONG_DOUBLE
+ /* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
+ The range of the returned value is >= 0.5 and < 1.0. This is equivalent to
+ frexp, but operates on the long double data type. */
+
+ static long double ldfrexp (long double value, int *eptr);
+
+ static long double
+ ldfrexp (long double value, int *eptr)
+ {
+ long double tmp;
+ int exp;
+
+ /* Unfortunately, there are no portable functions for extracting the exponent
+ of a long double, so we have to do it iteratively by multiplying or dividing
+ by two until the fraction is between 0.5 and 1.0. */
+
+ if (value < 0.0l)
+ value = -value;
+
+ tmp = 1.0l;
+ exp = 0;
+
+ if (value >= tmp) /* Value >= 1.0 */
+ while (value >= tmp)
+ {
+ tmp *= 2.0l;
+ exp++;
+ }
+ else if (value != 0.0l) /* Value < 1.0 and > 0.0 */
+ {
+ while (value < tmp)
+ {
+ tmp /= 2.0l;
+ exp--;
+ }
+ tmp *= 2.0l;
+ exp++;
+ }
+
+ *eptr = exp;
+ return value / tmp;
+ }
+ #endif /* HAVE_LONG_DOUBLE */
+
+
+ /* The converse: convert the DOUBLEST *FROM to an extended float
+ and store where TO points. Neither FROM nor TO have any alignment
+ restrictions. */
+
+ void
+ floatformat_from_doublest (CONST struct floatformat *fmt, DOUBLEST *from,
+ char *to)
+ {
+ DOUBLEST dfrom;
+ int exponent;
+ DOUBLEST mant;
+ unsigned int mant_bits, mant_off;
+ int mant_bits_left;
+ unsigned char *uto = (unsigned char *) to;
+
+ memcpy (&dfrom, from, sizeof (dfrom));
+ memset (uto, 0, (fmt->totalsize + FLOATFORMAT_CHAR_BIT - 1)
+ / FLOATFORMAT_CHAR_BIT);
+ if (dfrom == 0)
+ return; /* Result is zero */
+ if (dfrom != dfrom) /* Result is NaN */
+ {
+ /* From is NaN */
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
+ fmt->exp_len, fmt->exp_nan);
+ /* Be sure it's not infinity, but NaN value is irrel */
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
+ 32, 1);
+ return;
+ }
+
+ /* If negative, set the sign bit. */
+ if (dfrom < 0)
+ {
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
+ dfrom = -dfrom;
+ }
+
+ if (dfrom + dfrom == dfrom && dfrom != 0.0) /* Result is Infinity */
+ {
+ /* Infinity exponent is same as NaN's. */
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
+ fmt->exp_len, fmt->exp_nan);
+ /* Infinity mantissa is all zeroes. */
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
+ fmt->man_len, 0);
+ return;
+ }
+
+ #ifdef HAVE_LONG_DOUBLE
+ mant = ldfrexp (dfrom, &exponent);
+ #else
+ mant = frexp (dfrom, &exponent);
+ #endif
+
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, fmt->exp_len,
+ exponent + fmt->exp_bias - 1);
+
+ mant_bits_left = fmt->man_len;
+ mant_off = fmt->man_start;
+ while (mant_bits_left > 0)
+ {
+ unsigned long mant_long;
+ mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
+
+ mant *= 4294967296.0;
+ mant_long = ((unsigned long) mant) & 0xffffffffL;
+ mant -= mant_long;
+
+ /* If the integer bit is implicit, then we need to discard it.
+ If we are discarding a zero, we should be (but are not) creating
+ a denormalized number which means adjusting the exponent
+ (I think). */
+ if (mant_bits_left == fmt->man_len
+ && fmt->intbit == floatformat_intbit_no)
+ {
+ mant_long <<= 1;
+ mant_long &= 0xffffffffL;
+ mant_bits -= 1;
+ }
+
+ if (mant_bits < 32)
+ {
+ /* The bits we want are in the most significant MANT_BITS bits of
+ mant_long. Move them to the least significant. */
+ mant_long >>= 32 - mant_bits;
+ }
+
+ put_field (uto, fmt->byteorder, fmt->totalsize,
+ mant_off, mant_bits, mant_long);
+ mant_off += mant_bits;
+ mant_bits_left -= mant_bits;
+ }
+ if (fmt->byteorder == floatformat_littlebyte_bigword)
+ {
+ int count;
+ unsigned char *swaplow = uto;
+ unsigned char *swaphigh = uto + 4;
+ unsigned char tmp;
+
+ for (count = 0; count < 4; count++)
+ {
+ tmp = *swaplow;
+ *swaplow++ = *swaphigh;
+ *swaphigh++ = tmp;
+ }
+ }
+ }
+
+ /* Check if VAL (which is assumed to be a floating point number whose
+ format is described by FMT) is negative. */
+
+ int
+ floatformat_is_negative (const struct floatformat *fmt, char *val)
+ {
+ unsigned char *uval = (unsigned char *) val;
+
+ return get_field (uval, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1);
+ }
+
+ /* Check if VAL is "not a number" (NaN) for FMT. */
+
+ int
+ floatformat_is_nan (const struct floatformat *fmt, char *val)
+ {
+ unsigned char *uval = (unsigned char *) val;
+ long exponent;
+ unsigned long mant;
+ unsigned int mant_bits, mant_off;
+ int mant_bits_left;
+
+ if (! fmt->exp_nan)
+ return 0;
+
+ exponent = get_field (uval, fmt->byteorder, fmt->totalsize,
+ fmt->exp_start, fmt->exp_len);
+
+ if (exponent != fmt->exp_nan)
+ return 0;
+
+ mant_bits_left = fmt->man_len;
+ mant_off = fmt->man_start;
+
+ while (mant_bits_left > 0)
+ {
+ mant_bits = min (mant_bits_left, 32);
+
+ mant = get_field (uval, fmt->byteorder, fmt->totalsize,
+ mant_off, mant_bits);
+
+ /* If there is an explicit integer bit, mask it off. */
+ if (mant_off == fmt->man_start
+ && fmt->intbit == floatformat_intbit_yes)
+ mant &= ~(1 << (mant_bits - 1));
+
+ if (mant)
+ return 1;
+
+ mant_off += mant_bits;
+ mant_bits_left -= mant_bits;
+ }
+
+ return 0;
+ }
+
+ /* Convert the mantissa of VAL (which is assumed to be a floating
+ point number whose format is described by FMT) into a hexadecimal
+ and store it in a static string. Return a pointer to that string. */
+
+ char *
+ floatformat_mantissa (const struct floatformat *fmt, char *val)
+ {
+ unsigned char *uval = (unsigned char *) val;
+ unsigned long mant;
+ unsigned int mant_bits, mant_off;
+ int mant_bits_left;
+ static char res[50];
+ char buf[9];
+
+ /* Make sure we have enough room to store the mantissa. */
+ gdb_assert (sizeof res > ((fmt->man_len + 7) / 8) * 2);
+
+ mant_off = fmt->man_start;
+ mant_bits_left = fmt->man_len;
+ mant_bits = (mant_bits_left % 32) > 0 ? mant_bits_left % 32 : 32;
+
+ mant = get_field (uval, fmt->byteorder, fmt->totalsize,
+ mant_off, mant_bits);
+
+ sprintf (res, "%lx", mant);
+
+ mant_off += mant_bits;
+ mant_bits_left -= mant_bits;
+
+ while (mant_bits_left > 0)
+ {
+ mant = get_field (uval, fmt->byteorder, fmt->totalsize,
+ mant_off, 32);
+
+ sprintf (buf, "%08lx", mant);
+ strcat (res, buf);
+
+ mant_off += 32;
+ mant_bits_left -= 32;
+ }
+
+ return res;
+ }
+
+
+
+ /* Extract a floating-point number from a target-order byte-stream at ADDR.
+ Returns the value as type DOUBLEST.
+
+ If the host and target formats agree, we just copy the raw data into the
+ appropriate type of variable and return, letting the host increase precision
+ as necessary. Otherwise, we call the conversion routine and let it do the
+ dirty work. */
+
+ DOUBLEST
+ extract_floating (void *addr, int len)
+ {
+ DOUBLEST dretval;
+
+ if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
+ {
+ if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
+ {
+ float retval;
+
+ memcpy (&retval, addr, sizeof (retval));
+ return retval;
+ }
+ else
+ floatformat_to_doublest (TARGET_FLOAT_FORMAT, addr, &dretval);
+ }
+ else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
+ {
+ if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
+ {
+ double retval;
+
+ memcpy (&retval, addr, sizeof (retval));
+ return retval;
+ }
+ else
+ floatformat_to_doublest (TARGET_DOUBLE_FORMAT, addr, &dretval);
+ }
+ else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
+ {
+ if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
+ {
+ DOUBLEST retval;
+
+ memcpy (&retval, addr, sizeof (retval));
+ return retval;
+ }
+ else
+ floatformat_to_doublest (TARGET_LONG_DOUBLE_FORMAT, addr, &dretval);
+ }
+ else
+ {
+ error ("Can't deal with a floating point number of %d bytes.", len);
+ }
+
+ return dretval;
+ }
+
+ void
+ store_floating (void *addr, int len, DOUBLEST val)
+ {
+ if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
+ {
+ if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
+ {
+ float floatval = val;
+
+ memcpy (addr, &floatval, sizeof (floatval));
+ }
+ else
+ floatformat_from_doublest (TARGET_FLOAT_FORMAT, &val, addr);
+ }
+ else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
+ {
+ if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
+ {
+ double doubleval = val;
+
+ memcpy (addr, &doubleval, sizeof (doubleval));
+ }
+ else
+ floatformat_from_doublest (TARGET_DOUBLE_FORMAT, &val, addr);
+ }
+ else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
+ {
+ if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
+ memcpy (addr, &val, sizeof (val));
+ else
+ floatformat_from_doublest (TARGET_LONG_DOUBLE_FORMAT, &val, addr);
+ }
+ else
+ {
+ error ("Can't deal with a floating point number of %d bytes.", len);
+ }
+ }
Index: doublest.h
===================================================================
RCS file: doublest.h
diff -N doublest.h
*** /dev/null Tue May 5 13:32:27 1998
--- doublest.h Mon Jul 16 08:00:28 2001
***************
*** 0 ****
--- 1,87 ----
+ /* Floating point definitions for GDB.
+ Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
+ 1997, 1998, 1999, 2000, 2001
+ Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ #ifndef DOUBLEST_H
+ #define DOUBLEST_H
+
+ /* Setup definitions for host and target floating point formats. We need to
+ consider the format for `float', `double', and `long double' for both target
+ and host. We need to do this so that we know what kind of conversions need
+ to be done when converting target numbers to and from the hosts DOUBLEST
+ data type. */
+
+ /* This is used to indicate that we don't know the format of the floating point
+ number. Typically, this is useful for native ports, where the actual format
+ is irrelevant, since no conversions will be taking place. */
+
+ #include "floatformat.h" /* For struct floatformat */
+
+ extern const struct floatformat floatformat_unknown;
+
+ #if HOST_BYTE_ORDER == BIG_ENDIAN
+ #ifndef HOST_FLOAT_FORMAT
+ #define HOST_FLOAT_FORMAT &floatformat_ieee_single_big
+ #endif
+ #ifndef HOST_DOUBLE_FORMAT
+ #define HOST_DOUBLE_FORMAT &floatformat_ieee_double_big
+ #endif
+ #else /* LITTLE_ENDIAN */
+ #ifndef HOST_FLOAT_FORMAT
+ #define HOST_FLOAT_FORMAT &floatformat_ieee_single_little
+ #endif
+ #ifndef HOST_DOUBLE_FORMAT
+ #define HOST_DOUBLE_FORMAT &floatformat_ieee_double_little
+ #endif
+ #endif
+
+ #ifndef HOST_LONG_DOUBLE_FORMAT
+ #define HOST_LONG_DOUBLE_FORMAT &floatformat_unknown
+ #endif
+
+ /* Use `long double' if the host compiler supports it. (Note that this is not
+ necessarily any longer than `double'. On SunOS/gcc, it's the same as
+ double.) This is necessary because GDB internally converts all floating
+ point values to the widest type supported by the host.
+
+ There are problems however, when the target `long double' is longer than the
+ host's `long double'. In general, we'll probably reduce the precision of
+ any such values and print a warning. */
+
+ #ifdef HAVE_LONG_DOUBLE
+ typedef long double DOUBLEST;
+ #else
+ typedef double DOUBLEST;
+ #endif
+
+ extern void floatformat_to_doublest (const struct floatformat *,
+ char *, DOUBLEST *);
+ extern void floatformat_from_doublest (const struct floatformat *,
+ DOUBLEST *, char *);
+
+ extern int floatformat_is_negative (const struct floatformat *, char *);
+ extern int floatformat_is_nan (const struct floatformat *, char *);
+ extern char *floatformat_mantissa (const struct floatformat *, char *);
+
+ extern DOUBLEST extract_floating (void *, int);
+ extern void store_floating (void *, int, DOUBLEST);
+
+ #endif
Index: expression.h
===================================================================
RCS file: /cvs/src/src/gdb/expression.h,v
retrieving revision 1.2
diff -p -r1.2 expression.h
*** expression.h 2000/05/28 01:12:27 1.2
--- expression.h 2001/07/16 15:00:30
***************
*** 23,28 ****
--- 23,29 ----
#include "symtab.h" /* Needed for "struct block" type. */
+ #include "doublest.h" /* Needed for DOUBLEST. */
/* Definitions for saved C expressions. */
Index: findvar.c
===================================================================
RCS file: /cvs/src/src/gdb/findvar.c,v
retrieving revision 1.20
diff -p -r1.20 findvar.c
*** findvar.c 2001/07/10 21:24:48 1.20
--- findvar.c 2001/07/16 15:00:32
*************** store_typed_address (void *buf, struct t
*** 288,389 ****
-
- /* Extract a floating-point number from a target-order byte-stream at ADDR.
- Returns the value as type DOUBLEST.
-
- If the host and target formats agree, we just copy the raw data into the
- appropriate type of variable and return, letting the host increase precision
- as necessary. Otherwise, we call the conversion routine and let it do the
- dirty work. */
-
- DOUBLEST
- extract_floating (void *addr, int len)
- {
- DOUBLEST dretval;
-
- if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
- {
- if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
- {
- float retval;
-
- memcpy (&retval, addr, sizeof (retval));
- return retval;
- }
- else
- floatformat_to_doublest (TARGET_FLOAT_FORMAT, addr, &dretval);
- }
- else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
- {
- if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
- {
- double retval;
-
- memcpy (&retval, addr, sizeof (retval));
- return retval;
- }
- else
- floatformat_to_doublest (TARGET_DOUBLE_FORMAT, addr, &dretval);
- }
- else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
- {
- if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
- {
- DOUBLEST retval;
-
- memcpy (&retval, addr, sizeof (retval));
- return retval;
- }
- else
- floatformat_to_doublest (TARGET_LONG_DOUBLE_FORMAT, addr, &dretval);
- }
- else
- {
- error ("Can't deal with a floating point number of %d bytes.", len);
- }
-
- return dretval;
- }
-
- void
- store_floating (void *addr, int len, DOUBLEST val)
- {
- if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
- {
- if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
- {
- float floatval = val;
-
- memcpy (addr, &floatval, sizeof (floatval));
- }
- else
- floatformat_from_doublest (TARGET_FLOAT_FORMAT, &val, addr);
- }
- else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
- {
- if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
- {
- double doubleval = val;
-
- memcpy (addr, &doubleval, sizeof (doubleval));
- }
- else
- floatformat_from_doublest (TARGET_DOUBLE_FORMAT, &val, addr);
- }
- else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
- {
- if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
- memcpy (addr, &val, sizeof (val));
- else
- floatformat_from_doublest (TARGET_LONG_DOUBLE_FORMAT, &val, addr);
- }
- else
- {
- error ("Can't deal with a floating point number of %d bytes.", len);
- }
- }
-
/* Return a `value' with the contents of register REGNUM
in its virtual format, with the type specified by
REGISTER_VIRTUAL_TYPE.
--- 288,293 ----
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.34
diff -p -r1.34 i386-tdep.c
*** i386-tdep.c 2001/07/15 20:10:02 1.34
--- i386-tdep.c 2001/07/16 15:00:35
***************
*** 32,37 ****
--- 32,38 ----
#include "command.h"
#include "arch-utils.h"
#include "regcache.h"
+ #include "doublest.h"
/* i386_register_byte[i] is the offset into the register file of the
start of register number i. We initialize this from
Index: i387-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i387-tdep.c,v
retrieving revision 1.12
diff -p -r1.12 i387-tdep.c
*** i387-tdep.c 2001/07/07 00:14:06 1.12
--- i387-tdep.c 2001/07/16 15:00:36
***************
*** 28,33 ****
--- 28,34 ----
#include "floatformat.h"
#include "regcache.h"
#include "gdb_assert.h"
+ #include "doublest.h"
/* FIXME: Eliminate the next two functions when we have the time to
Index: ia64-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/ia64-tdep.c,v
retrieving revision 1.21
diff -p -r1.21 ia64-tdep.c
*** ia64-tdep.c 2001/07/15 20:10:02 1.21
--- ia64-tdep.c 2001/07/16 15:00:41
***************
*** 26,31 ****
--- 26,32 ----
#include "arch-utils.h"
#include "floatformat.h"
#include "regcache.h"
+ #include "doublest.h"
#include "objfiles.h"
#include "elf/common.h" /* for DT_PLTGOT value */
Index: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.25
diff -p -r1.25 rs6000-tdep.c
*** rs6000-tdep.c 2001/07/15 20:10:02 1.25
--- rs6000-tdep.c 2001/07/16 15:00:49
***************
*** 31,36 ****
--- 31,37 ----
#include "objfiles.h"
#include "arch-utils.h"
#include "regcache.h"
+ #include "doublest.h"
#include "bfd/libbfd.h" /* for bfd_default_set_arch_mach */
#include "coff/internal.h" /* for libcoff.h */
Index: sh-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh-tdep.c,v
retrieving revision 1.37
diff -p -r1.37 sh-tdep.c
*** sh-tdep.c 2001/07/15 20:10:02 1.37
--- sh-tdep.c 2001/07/16 15:00:53
***************
*** 39,44 ****
--- 39,45 ----
#include "arch-utils.h"
#include "floatformat.h"
#include "regcache.h"
+ #include "doublest.h"
#include "solib-svr4.h"
Index: stabsread.c
===================================================================
RCS file: /cvs/src/src/gdb/stabsread.c,v
retrieving revision 1.13
diff -p -r1.13 stabsread.c
*** stabsread.c 2001/03/24 00:42:59 1.13
--- stabsread.c 2001/07/16 15:01:07
***************
*** 43,48 ****
--- 43,49 ----
#include "complaints.h"
#include "demangle.h"
#include "language.h"
+ #include "doublest.h"
#include <ctype.h>
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.45
diff -p -r1.45 utils.c
*** utils.c 2001/07/15 20:34:14 1.45
--- utils.c 2001/07/16 15:01:12
*************** initialize_utils (void)
*** 2331,2841 ****
#ifdef SIGWINCH_HANDLER_BODY
SIGWINCH_HANDLER_BODY
#endif
-
- /* Support for converting target fp numbers into host DOUBLEST format. */
-
- /* XXX - This code should really be in libiberty/floatformat.c, however
- configuration issues with libiberty made this very difficult to do in the
- available time. */
-
- #include "floatformat.h"
- #include <math.h> /* ldexp */
-
- /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
- going to bother with trying to muck around with whether it is defined in
- a system header, what we do if not, etc. */
- #define FLOATFORMAT_CHAR_BIT 8
-
- static unsigned long get_field (unsigned char *,
- enum floatformat_byteorders,
- unsigned int, unsigned int, unsigned int);
-
- /* Extract a field which starts at START and is LEN bytes long. DATA and
- TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
- static unsigned long
- get_field (unsigned char *data, enum floatformat_byteorders order,
- unsigned int total_len, unsigned int start, unsigned int len)
- {
- unsigned long result;
- unsigned int cur_byte;
- int cur_bitshift;
-
- /* Start at the least significant part of the field. */
- if (order == floatformat_little || order == floatformat_littlebyte_bigword)
- {
- /* We start counting from the other end (i.e, from the high bytes
- rather than the low bytes). As such, we need to be concerned
- with what happens if bit 0 doesn't start on a byte boundary.
- I.e, we need to properly handle the case where total_len is
- not evenly divisible by 8. So we compute ``excess'' which
- represents the number of bits from the end of our starting
- byte needed to get to bit 0. */
- int excess = FLOATFORMAT_CHAR_BIT - (total_len % FLOATFORMAT_CHAR_BIT);
- cur_byte = (total_len / FLOATFORMAT_CHAR_BIT)
- - ((start + len + excess) / FLOATFORMAT_CHAR_BIT);
- cur_bitshift = ((start + len + excess) % FLOATFORMAT_CHAR_BIT)
- - FLOATFORMAT_CHAR_BIT;
- }
- else
- {
- cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
- cur_bitshift =
- ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
- }
- if (cur_bitshift > -FLOATFORMAT_CHAR_BIT)
- result = *(data + cur_byte) >> (-cur_bitshift);
- else
- result = 0;
- cur_bitshift += FLOATFORMAT_CHAR_BIT;
- if (order == floatformat_little || order == floatformat_littlebyte_bigword)
- ++cur_byte;
- else
- --cur_byte;
-
- /* Move towards the most significant part of the field. */
- while (cur_bitshift < len)
- {
- result |= (unsigned long)*(data + cur_byte) << cur_bitshift;
- cur_bitshift += FLOATFORMAT_CHAR_BIT;
- if (order == floatformat_little || order == floatformat_littlebyte_bigword)
- ++cur_byte;
- else
- --cur_byte;
- }
- if (len < sizeof(result) * FLOATFORMAT_CHAR_BIT)
- /* Mask out bits which are not part of the field */
- result &= ((1UL << len) - 1);
- return result;
- }
-
- /* Convert from FMT to a DOUBLEST.
- FROM is the address of the extended float.
- Store the DOUBLEST in *TO. */
-
- void
- floatformat_to_doublest (const struct floatformat *fmt, char *from,
- DOUBLEST *to)
- {
- unsigned char *ufrom = (unsigned char *) from;
- DOUBLEST dto;
- long exponent;
- unsigned long mant;
- unsigned int mant_bits, mant_off;
- int mant_bits_left;
- int special_exponent; /* It's a NaN, denorm or zero */
-
- /* If the mantissa bits are not contiguous from one end of the
- mantissa to the other, we need to make a private copy of the
- source bytes that is in the right order since the unpacking
- algorithm assumes that the bits are contiguous.
-
- Swap the bytes individually rather than accessing them through
- "long *" since we have no guarantee that they start on a long
- alignment, and also sizeof(long) for the host could be different
- than sizeof(long) for the target. FIXME: Assumes sizeof(long)
- for the target is 4. */
-
- if (fmt->byteorder == floatformat_littlebyte_bigword)
- {
- static unsigned char *newfrom;
- unsigned char *swapin, *swapout;
- int longswaps;
-
- longswaps = fmt->totalsize / FLOATFORMAT_CHAR_BIT;
- longswaps >>= 3;
-
- if (newfrom == NULL)
- {
- newfrom = (unsigned char *) xmalloc (fmt->totalsize);
- }
- swapout = newfrom;
- swapin = ufrom;
- ufrom = newfrom;
- while (longswaps-- > 0)
- {
- /* This is ugly, but efficient */
- *swapout++ = swapin[4];
- *swapout++ = swapin[5];
- *swapout++ = swapin[6];
- *swapout++ = swapin[7];
- *swapout++ = swapin[0];
- *swapout++ = swapin[1];
- *swapout++ = swapin[2];
- *swapout++ = swapin[3];
- swapin += 8;
- }
- }
-
- exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
- fmt->exp_start, fmt->exp_len);
- /* Note that if exponent indicates a NaN, we can't really do anything useful
- (not knowing if the host has NaN's, or how to build one). So it will
- end up as an infinity or something close; that is OK. */
-
- mant_bits_left = fmt->man_len;
- mant_off = fmt->man_start;
- dto = 0.0;
-
- special_exponent = exponent == 0 || exponent == fmt->exp_nan;
-
- /* Don't bias NaNs. Use minimum exponent for denorms. For simplicity,
- we don't check for zero as the exponent doesn't matter. */
- if (!special_exponent)
- exponent -= fmt->exp_bias;
- else if (exponent == 0)
- exponent = 1 - fmt->exp_bias;
-
- /* Build the result algebraically. Might go infinite, underflow, etc;
- who cares. */
-
- /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
- increment the exponent by one to account for the integer bit. */
-
- if (!special_exponent)
- {
- if (fmt->intbit == floatformat_intbit_no)
- dto = ldexp (1.0, exponent);
- else
- exponent++;
- }
-
- while (mant_bits_left > 0)
- {
- mant_bits = min (mant_bits_left, 32);
-
- mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
- mant_off, mant_bits);
-
- dto += ldexp ((double) mant, exponent - mant_bits);
- exponent -= mant_bits;
- mant_off += mant_bits;
- mant_bits_left -= mant_bits;
- }
-
- /* Negate it if negative. */
- if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
- dto = -dto;
- *to = dto;
- }
-
- static void put_field (unsigned char *, enum floatformat_byteorders,
- unsigned int,
- unsigned int, unsigned int, unsigned long);
-
- /* Set a field which starts at START and is LEN bytes long. DATA and
- TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
- static void
- put_field (unsigned char *data, enum floatformat_byteorders order,
- unsigned int total_len, unsigned int start, unsigned int len,
- unsigned long stuff_to_put)
- {
- unsigned int cur_byte;
- int cur_bitshift;
-
- /* Start at the least significant part of the field. */
- if (order == floatformat_little || order == floatformat_littlebyte_bigword)
- {
- int excess = FLOATFORMAT_CHAR_BIT - (total_len % FLOATFORMAT_CHAR_BIT);
- cur_byte = (total_len / FLOATFORMAT_CHAR_BIT)
- - ((start + len + excess) / FLOATFORMAT_CHAR_BIT);
- cur_bitshift = ((start + len + excess) % FLOATFORMAT_CHAR_BIT)
- - FLOATFORMAT_CHAR_BIT;
- }
- else
- {
- cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
- cur_bitshift =
- ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
- }
- if (cur_bitshift > -FLOATFORMAT_CHAR_BIT)
- {
- *(data + cur_byte) &=
- ~(((1 << ((start + len) % FLOATFORMAT_CHAR_BIT)) - 1)
- << (-cur_bitshift));
- *(data + cur_byte) |=
- (stuff_to_put & ((1 << FLOATFORMAT_CHAR_BIT) - 1)) << (-cur_bitshift);
- }
- cur_bitshift += FLOATFORMAT_CHAR_BIT;
- if (order == floatformat_little || order == floatformat_littlebyte_bigword)
- ++cur_byte;
- else
- --cur_byte;
-
- /* Move towards the most significant part of the field. */
- while (cur_bitshift < len)
- {
- if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT)
- {
- /* This is the last byte. */
- *(data + cur_byte) &=
- ~((1 << (len - cur_bitshift)) - 1);
- *(data + cur_byte) |= (stuff_to_put >> cur_bitshift);
- }
- else
- *(data + cur_byte) = ((stuff_to_put >> cur_bitshift)
- & ((1 << FLOATFORMAT_CHAR_BIT) - 1));
- cur_bitshift += FLOATFORMAT_CHAR_BIT;
- if (order == floatformat_little || order == floatformat_littlebyte_bigword)
- ++cur_byte;
- else
- --cur_byte;
- }
- }
-
- #ifdef HAVE_LONG_DOUBLE
- /* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
- The range of the returned value is >= 0.5 and < 1.0. This is equivalent to
- frexp, but operates on the long double data type. */
-
- static long double ldfrexp (long double value, int *eptr);
-
- static long double
- ldfrexp (long double value, int *eptr)
- {
- long double tmp;
- int exp;
-
- /* Unfortunately, there are no portable functions for extracting the exponent
- of a long double, so we have to do it iteratively by multiplying or dividing
- by two until the fraction is between 0.5 and 1.0. */
-
- if (value < 0.0l)
- value = -value;
-
- tmp = 1.0l;
- exp = 0;
-
- if (value >= tmp) /* Value >= 1.0 */
- while (value >= tmp)
- {
- tmp *= 2.0l;
- exp++;
- }
- else if (value != 0.0l) /* Value < 1.0 and > 0.0 */
- {
- while (value < tmp)
- {
- tmp /= 2.0l;
- exp--;
- }
- tmp *= 2.0l;
- exp++;
- }
-
- *eptr = exp;
- return value / tmp;
- }
- #endif /* HAVE_LONG_DOUBLE */
-
-
- /* The converse: convert the DOUBLEST *FROM to an extended float
- and store where TO points. Neither FROM nor TO have any alignment
- restrictions. */
-
- void
- floatformat_from_doublest (CONST struct floatformat *fmt, DOUBLEST *from,
- char *to)
- {
- DOUBLEST dfrom;
- int exponent;
- DOUBLEST mant;
- unsigned int mant_bits, mant_off;
- int mant_bits_left;
- unsigned char *uto = (unsigned char *) to;
-
- memcpy (&dfrom, from, sizeof (dfrom));
- memset (uto, 0, (fmt->totalsize + FLOATFORMAT_CHAR_BIT - 1)
- / FLOATFORMAT_CHAR_BIT);
- if (dfrom == 0)
- return; /* Result is zero */
- if (dfrom != dfrom) /* Result is NaN */
- {
- /* From is NaN */
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
- fmt->exp_len, fmt->exp_nan);
- /* Be sure it's not infinity, but NaN value is irrel */
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
- 32, 1);
- return;
- }
-
- /* If negative, set the sign bit. */
- if (dfrom < 0)
- {
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
- dfrom = -dfrom;
- }
-
- if (dfrom + dfrom == dfrom && dfrom != 0.0) /* Result is Infinity */
- {
- /* Infinity exponent is same as NaN's. */
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
- fmt->exp_len, fmt->exp_nan);
- /* Infinity mantissa is all zeroes. */
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
- fmt->man_len, 0);
- return;
- }
-
- #ifdef HAVE_LONG_DOUBLE
- mant = ldfrexp (dfrom, &exponent);
- #else
- mant = frexp (dfrom, &exponent);
- #endif
-
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, fmt->exp_len,
- exponent + fmt->exp_bias - 1);
-
- mant_bits_left = fmt->man_len;
- mant_off = fmt->man_start;
- while (mant_bits_left > 0)
- {
- unsigned long mant_long;
- mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
-
- mant *= 4294967296.0;
- mant_long = ((unsigned long) mant) & 0xffffffffL;
- mant -= mant_long;
-
- /* If the integer bit is implicit, then we need to discard it.
- If we are discarding a zero, we should be (but are not) creating
- a denormalized number which means adjusting the exponent
- (I think). */
- if (mant_bits_left == fmt->man_len
- && fmt->intbit == floatformat_intbit_no)
- {
- mant_long <<= 1;
- mant_long &= 0xffffffffL;
- mant_bits -= 1;
- }
-
- if (mant_bits < 32)
- {
- /* The bits we want are in the most significant MANT_BITS bits of
- mant_long. Move them to the least significant. */
- mant_long >>= 32 - mant_bits;
- }
-
- put_field (uto, fmt->byteorder, fmt->totalsize,
- mant_off, mant_bits, mant_long);
- mant_off += mant_bits;
- mant_bits_left -= mant_bits;
- }
- if (fmt->byteorder == floatformat_littlebyte_bigword)
- {
- int count;
- unsigned char *swaplow = uto;
- unsigned char *swaphigh = uto + 4;
- unsigned char tmp;
-
- for (count = 0; count < 4; count++)
- {
- tmp = *swaplow;
- *swaplow++ = *swaphigh;
- *swaphigh++ = tmp;
- }
- }
- }
-
- /* Check if VAL (which is assumed to be a floating point number whose
- format is described by FMT) is negative. */
-
- int
- floatformat_is_negative (const struct floatformat *fmt, char *val)
- {
- unsigned char *uval = (unsigned char *) val;
-
- return get_field (uval, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1);
- }
-
- /* Check if VAL is "not a number" (NaN) for FMT. */
-
- int
- floatformat_is_nan (const struct floatformat *fmt, char *val)
- {
- unsigned char *uval = (unsigned char *) val;
- long exponent;
- unsigned long mant;
- unsigned int mant_bits, mant_off;
- int mant_bits_left;
-
- if (! fmt->exp_nan)
- return 0;
-
- exponent = get_field (uval, fmt->byteorder, fmt->totalsize,
- fmt->exp_start, fmt->exp_len);
-
- if (exponent != fmt->exp_nan)
- return 0;
-
- mant_bits_left = fmt->man_len;
- mant_off = fmt->man_start;
-
- while (mant_bits_left > 0)
- {
- mant_bits = min (mant_bits_left, 32);
-
- mant = get_field (uval, fmt->byteorder, fmt->totalsize,
- mant_off, mant_bits);
-
- /* If there is an explicit integer bit, mask it off. */
- if (mant_off == fmt->man_start
- && fmt->intbit == floatformat_intbit_yes)
- mant &= ~(1 << (mant_bits - 1));
-
- if (mant)
- return 1;
-
- mant_off += mant_bits;
- mant_bits_left -= mant_bits;
- }
-
- return 0;
- }
-
- /* Convert the mantissa of VAL (which is assumed to be a floating
- point number whose format is described by FMT) into a hexadecimal
- and store it in a static string. Return a pointer to that string. */
-
- char *
- floatformat_mantissa (const struct floatformat *fmt, char *val)
- {
- unsigned char *uval = (unsigned char *) val;
- unsigned long mant;
- unsigned int mant_bits, mant_off;
- int mant_bits_left;
- static char res[50];
- char buf[9];
-
- /* Make sure we have enough room to store the mantissa. */
- gdb_assert (sizeof res > ((fmt->man_len + 7) / 8) * 2);
-
- mant_off = fmt->man_start;
- mant_bits_left = fmt->man_len;
- mant_bits = (mant_bits_left % 32) > 0 ? mant_bits_left % 32 : 32;
-
- mant = get_field (uval, fmt->byteorder, fmt->totalsize,
- mant_off, mant_bits);
-
- sprintf (res, "%lx", mant);
-
- mant_off += mant_bits;
- mant_bits_left -= mant_bits;
-
- while (mant_bits_left > 0)
- {
- mant = get_field (uval, fmt->byteorder, fmt->totalsize,
- mant_off, 32);
-
- sprintf (buf, "%08lx", mant);
- strcat (res, buf);
-
- mant_off += 32;
- mant_bits_left -= 32;
- }
-
- return res;
- }
/* print routines to handle variable size regs, etc. */
--- 2331,2336 ----
Index: valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.7
diff -p -r1.7 valarith.c
*** valarith.c 2001/03/07 02:57:08 1.7
--- valarith.c 2001/07/16 15:01:15
***************
*** 28,33 ****
--- 28,34 ----
#include "target.h"
#include "language.h"
#include "gdb_string.h"
+ #include "doublest.h"
#include <math.h>
/* Define whether or not the C operator '/' truncates towards zero for
Index: valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.14
diff -p -r1.14 valprint.c
*** valprint.c 2001/03/20 01:37:10 1.14
--- valprint.c 2001/07/16 15:01:19
***************
*** 33,38 ****
--- 33,39 ----
#include "annotate.h"
#include "valprint.h"
#include "floatformat.h"
+ #include "doublest.h"
#include <errno.h>
Index: values.c
===================================================================
RCS file: /cvs/src/src/gdb/values.c,v
retrieving revision 1.21
diff -p -r1.21 values.c
*** values.c 2001/07/10 21:24:48 1.21
--- values.c 2001/07/16 15:01:22
***************
*** 32,37 ****
--- 32,38 ----
#include "language.h"
#include "scm-lang.h"
#include "demangle.h"
+ #include "doublest.h"
/* Prototypes for exported functions. */
Index: config/i386/tm-symmetry.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/tm-symmetry.h,v
retrieving revision 1.4
diff -p -r1.4 tm-symmetry.h
*** tm-symmetry.h 2001/03/26 12:25:31 1.4
--- tm-symmetry.h 2001/07/16 15:01:24
***************
*** 25,30 ****
--- 25,31 ----
#define TM_SYMMETRY_H 1
#include "regcache.h"
+ #include "doublest.h"
/* I don't know if this will work for cross-debugging, even if you do get
a copy of the right include file. */
Index: config/i386/xm-fbsd.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/xm-fbsd.h,v
retrieving revision 1.2
diff -p -r1.2 xm-fbsd.h
*** xm-fbsd.h 2001/03/06 08:21:29 1.2
--- xm-fbsd.h 2001/07/16 15:01:24
***************
*** 21,26 ****
--- 21,28 ----
#ifndef XM_FBSD_H
#define XM_FBSD_H
+ #include "doublest.h"
+
#define HOST_BYTE_ORDER LITTLE_ENDIAN
#define HOST_LONG_DOUBLE_FORMAT &floatformat_i387_ext
Index: config/i386/xm-go32.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/xm-go32.h,v
retrieving revision 1.6
diff -p -r1.6 xm-go32.h
*** xm-go32.h 2001/07/05 14:40:51 1.6
--- xm-go32.h 2001/07/16 15:01:24
***************
*** 20,25 ****
--- 20,26 ----
#define HOST_BYTE_ORDER LITTLE_ENDIAN
+ #include "doublest.h"
#include "fopen-bin.h"
#define GDBINIT_FILENAME "gdb.ini"
Index: config/i386/xm-i386gnu.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/xm-i386gnu.h,v
retrieving revision 1.3
diff -p -r1.3 xm-i386gnu.h
*** xm-i386gnu.h 2001/03/06 08:21:29 1.3
--- xm-i386gnu.h 2001/07/16 15:01:24
***************
*** 21,26 ****
--- 21,27 ----
#define HOST_BYTE_ORDER LITTLE_ENDIAN
+ #include "doublest.h"
#define HOST_LONG_DOUBLE_FORMAT &floatformat_i387_ext
/* Do implement the attach and detach commands. */
Index: config/i386/xm-linux.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/xm-linux.h,v
retrieving revision 1.6
diff -p -r1.6 xm-linux.h
*** xm-linux.h 2001/07/14 11:55:29 1.6
--- xm-linux.h 2001/07/16 15:01:24
***************
*** 24,29 ****
--- 24,30 ----
#define HOST_BYTE_ORDER LITTLE_ENDIAN
+ #include "doublest.h"
#define HOST_LONG_DOUBLE_FORMAT &floatformat_i387_ext
#define NEED_POSIX_SETPGID
Index: config/i386/xm-nbsd.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/xm-nbsd.h,v
retrieving revision 1.3
diff -p -r1.3 xm-nbsd.h
*** xm-nbsd.h 2001/03/06 08:21:29 1.3
--- xm-nbsd.h 2001/07/16 15:01:24
***************
*** 21,24 ****
--- 21,25 ----
/* Get generic NetBSD host definitions. */
#include "xm-nbsd.h"
+ #include "doublest.h"
#define HOST_LONG_DOUBLE_FORMAT &floatformat_i387_ext
Index: config/i960/tm-i960.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i960/tm-i960.h,v
retrieving revision 1.3
diff -p -r1.3 tm-i960.h
*** tm-i960.h 2001/03/06 08:21:29 1.3
--- tm-i960.h 2001/07/16 15:01:25
***************
*** 25,30 ****
--- 25,32 ----
#define I80960
#endif
+ #include "doublest.h"
+
/* Hook for the SYMBOL_CLASS of a parameter when decoding DBX symbol
information. In the i960, parameters can be stored as locals or as
args, depending on the type of the debug record.
Index: config/m68k/tm-m68k.h
===================================================================
RCS file: /cvs/src/src/gdb/config/m68k/tm-m68k.h,v
retrieving revision 1.6
diff -p -r1.6 tm-m68k.h
*** tm-m68k.h 2001/03/14 23:23:12 1.6
--- tm-m68k.h 2001/07/16 15:01:26
***************
*** 19,24 ****
--- 19,25 ----
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+ #include "doublest.h"
#include "regcache.h"
/* Generic 68000 stuff, to be included by other tm-*.h files. */
Index: config/m88k/tm-m88k.h
===================================================================
RCS file: /cvs/src/src/gdb/config/m88k/tm-m88k.h,v
retrieving revision 1.6
diff -p -r1.6 tm-m88k.h
*** tm-m88k.h 2001/04/02 14:47:22 1.6
--- tm-m88k.h 2001/07/16 15:01:29
***************
*** 20,25 ****
--- 20,26 ----
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+ #include "doublest.h"
#include "regcache.h"
/* g++ support is not yet included. */