This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch/rfc] REGISTER_TO_VALUE replacing REGISTER_CONVERT_TO_VIRTUAL


Hello,

The architecture vector contains the methods:

	REGISTER_CONVERT_TO_VIRTUAL
	REGISTER_CONVERT_TO_RAW
	REGISTER_CONVERTIBLE
	REGISTER_VIRTUAL_TYPE
	REGISTER_RAW_SIZE
	REGISTER_VIRTUAL_SIZE

GDB's core uses them in two different ways:

- to convert between a registers raw and virtual representations

   For instance, the MIPS uses this in an attempt to handle an ABI with 
32 bit registers on a 64 bit ISA. (I'm not saying it works mind).

- to convert between a data values memory (normal) and register 
representation

   For instance, the Alpha might store a 32 bit int in a floating point 
register.

The attached patch adds, documents, and uses, a new set of architecture 
methods:

	CONVERT_REGISTER_P
	REGISTER_TO_VALUE
	VALUE_TO_REGISTER

that handle just the second case.  To keep existing architectures 
working they default to corresponding *CONVERT* macros (which means the 
patch really doesn't change anything).

Reviewing the various architectures:

A number could define just the new methods vis:

	alpha

A number [possibly] don't need to define either (but do):

	ia64-tdep.c (should use floatformat)
	rs6000-tdep.c
	x86-64-tdep.c (?)
	i386-tdep.c (?)

and one (*&*!^$(*&^(!@$) still needs the old and new methods.

	MIPS


Thoughts?  I'll look to commit it in a week.

Andrew
2002-05-05  Andrew Cagney  <ac131313@redhat.com>

	* arch-utils.h (legacy_register_to_value): Declare.
	(legacy_value_to_register): Declare.
	(legacy_convert_register_p): Declare.
	* arch-utils.c (legacy_register_to_value): New function.
	(legacy_value_to_register): New function.
	(legacy_convert_register_p): New function.

	* gdbarch.sh (REGISTER_TO_VALUE): Define.
	(VALUE_TO_REGISTER): Define.
	(CONVERT_REGISTER_P): Define.
	* gdbarch.h, gdbarch.c: Regenerate.

	* valops.c (value_assign): Use CONVERT_REGISTER_P and
	VALUE_TO_REGISTER.
	* findvar.c (value_from_register): Use REGISTER_TO_VALUE and
	CONVERT_REGISTER_P.

Index: doc/ChangeLog
2002-05-05  Andrew Cagney  <ac131313@redhat.com>

	* gdbint.texinfo (Target Architecture Definition): Document
	REGISTER_TO_VALUE and VALUE_TO_REGISTER and CONVERT_REGISTER_P.
	(Target Architecture Definition): Revise section `Using Different
	Register and Memory Data Representations'.  Add section `Raw and
	Virtual Register Representations'.

Index: arch-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.c,v
retrieving revision 1.55
diff -u -r1.55 arch-utils.c
--- arch-utils.c	5 May 2002 01:15:12 -0000	1.55
+++ arch-utils.c	6 May 2002 01:22:45 -0000
@@ -437,6 +437,26 @@
   return IN_SIGTRAMP(pc, name);
 }
 
+int
+legacy_convert_register_p (int regnum)
+{
+  return REGISTER_CONVERTIBLE (regnum);
+}
+
+void
+legacy_register_to_value (int regnum, struct type *type,
+			  char *from, char *to)
+{
+  REGISTER_CONVERT_TO_VIRTUAL (regnum, type, from, to);
+}
+
+void
+legacy_value_to_register (struct type *type, int regnum,
+			  char *from, char *to)
+{
+  REGISTER_CONVERT_TO_RAW (type, regnum, from, to);
+}
+
 
 /* Functions to manipulate the endianness of the target.  */
 
Index: arch-utils.h
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.h,v
retrieving revision 1.30
diff -u -r1.30 arch-utils.h
--- arch-utils.h	24 Apr 2002 16:28:14 -0000	1.30
+++ arch-utils.h	6 May 2002 01:22:45 -0000
@@ -160,6 +160,15 @@
 /* Prop up old targets that use various IN_SIGTRAMP() macros.  */
 extern int legacy_pc_in_sigtramp (CORE_ADDR pc, char *name);
 
+/* The orginal register_convert*() functions were overloaded.  They
+   were used to both: convert between virtual and raw register formats
+   (something that is discouraged); and to convert a register to the
+   type of a corresponding variable.  These legacy functions preserve
+   that overloaded behavour in existing targets.  */
+extern int legacy_convert_register_p (int regnum);
+extern void legacy_register_to_value (int regnum, struct type *type, char *from, char *to);
+extern void legacy_value_to_register (struct type *type, int regnum, char *from, char *to);
+
 /* Initialize a ``struct info''.  Can't use memset(0) since some
    default values are not zero.  */
 extern void gdbarch_info_init (struct gdbarch_info *info);
Index: findvar.c
===================================================================
RCS file: /cvs/src/src/gdb/findvar.c,v
retrieving revision 1.32
diff -u -r1.32 findvar.c
--- findvar.c	23 Apr 2002 03:00:57 -0000	1.32
+++ findvar.c	6 May 2002 01:22:45 -0000
@@ -813,12 +813,12 @@
   VALUE_LVAL (v) = lval;
   VALUE_ADDRESS (v) = addr;
 
-  /* Convert raw data to virtual format if necessary.  */
+  /* Convert the raw register to the corresponding data value's memory
+     format, if necessary.  */
 
-  if (REGISTER_CONVERTIBLE (regnum))
+  if (CONVERT_REGISTER_P (regnum))
     {
-      REGISTER_CONVERT_TO_VIRTUAL (regnum, type,
-				   raw_buffer, VALUE_CONTENTS_RAW (v));
+      REGISTER_TO_VALUE (regnum, type, raw_buffer, VALUE_CONTENTS_RAW (v));
     }
   else
     {
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.133
diff -u -r1.133 gdbarch.sh
--- gdbarch.sh	3 May 2002 21:05:36 -0000	1.133
+++ gdbarch.sh	6 May 2002 01:23:30 -0000
@@ -514,6 +514,10 @@
 f:2:REGISTER_CONVERTIBLE:int:register_convertible:int nr:nr:::generic_register_convertible_not::0
 f:2:REGISTER_CONVERT_TO_VIRTUAL:void:register_convert_to_virtual:int regnum, struct type *type, char *from, char *to:regnum, type, from, to:::0::0
 f:2:REGISTER_CONVERT_TO_RAW:void:register_convert_to_raw:struct type *type, int regnum, char *from, char *to:type, regnum, from, to:::0::0
+#
+f:1:CONVERT_REGISTER_P:int:convert_register_p:int regnum:regnum::0:legacy_convert_register_p::0
+f:1:REGISTER_TO_VALUE:void:register_to_value:int regnum, struct type *type, char *from, char *to:regnum, type, from, to::0:legacy_register_to_value::0
+f:1:VALUE_TO_REGISTER:void:value_to_register:struct type *type, int regnum, char *from, char *to:type, regnum, from, to::0:legacy_value_to_register::0
 # This function is called when the value of a pseudo-register needs to
 # be updated.  Typically it will be defined on a per-architecture
 # basis.
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.56
diff -u -r1.56 valops.c
--- valops.c	2 May 2002 19:00:36 -0000	1.56
+++ valops.c	6 May 2002 01:23:39 -0000
@@ -562,11 +562,10 @@
   if (VALUE_REGNO (toval) >= 0)
     {
       int regno = VALUE_REGNO (toval);
-      if (REGISTER_CONVERTIBLE (regno))
+      if (CONVERT_REGISTER_P (regno))
 	{
 	  struct type *fromtype = check_typedef (VALUE_TYPE (fromval));
-	  REGISTER_CONVERT_TO_RAW (fromtype, regno,
-				   VALUE_CONTENTS (fromval), raw_buffer);
+	  VALUE_TO_REGISTER (fromtype, regno, VALUE_CONTENTS (fromval), raw_buffer);
 	  use_buffer = REGISTER_RAW_SIZE (regno);
 	}
     }
Index: doc/gdbint.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdbint.texinfo,v
retrieving revision 1.81
diff -u -r1.81 gdbint.texinfo
--- doc/gdbint.texinfo	4 May 2002 19:57:22 -0000	1.81
+++ doc/gdbint.texinfo	6 May 2002 01:23:55 -0000
@@ -2487,17 +2487,16 @@
 @end deftypefn
 
 
-@section Using Different Register and Memory Data Representations
-@cindex raw representation
-@cindex virtual representation
-@cindex representations, raw and virtual
-@cindex register data formats, converting
-@cindex @code{struct value}, converting register contents to
-
-@emph{Maintainer's note: The way GDB manipulates registers is undergoing
-significant change.  Many of the macros and functions refered to in the
-sections below are likely to be made obsolete.  See the file @file{TODO}
-for more up-to-date information.}
+@section Raw and Virtual Register Representations
+@cindex raw register representation
+@cindex virtual register representation
+@cindex representations, raw and virtual registers
+
+@emph{Maintainer note: This section is pretty much obsolete.  The
+functionality described here has largely been replaced by
+pseudo-registers and the mechanisms described in @ref{Target
+Architecture Definition, , Using Different Register and Memory Data
+Representations}.}
 
 Some architectures use one representation for a value when it lives in a
 register, but use a different representation when it lives in memory.
@@ -2505,6 +2504,10 @@
 the target registers, and the @dfn{virtual} representation is the one
 used in memory, and within @value{GDBN} @code{struct value} objects.
 
+@emph{Maintainer note: Notice that the same mechanism is being used to
+both convert a register to a @code{struct value} and alternative
+register forms.}
+
 For almost all data types on almost all architectures, the virtual and
 raw representations are identical, and no special handling is needed.
 However, they do occasionally differ.  For example:
@@ -2589,6 +2592,85 @@
 @end deftypefn
 
 
+@section Using Different Register and Memory Data Representations
+@cindex register representation
+@cindex memory representation
+@cindex representations, register and memory
+@cindex register data formats, converting
+@cindex @code{struct value}, converting register contents to
+
+@emph{Maintainer's note: The way GDB manipulates registers is undergoing
+significant change.  Many of the macros and functions refered to in this
+section are likely to be subject to further revision.  See
+@uref{http://sources.redhat.com/gdb/current/ari/, A.R. Index} and
+@uref{http://www.gnu.org/software/gdb/bugs, Bug Tracking Database} for
+further information.  cagney/2002-05-06.}
+
+Some architectures can represent a data object in a register using a
+form that is different to the objects more normal memory representation.
+For example:
+
+@itemize @bullet
+
+@item
+The Alpha architecture can represent 32 bit integer values in
+floating-point registers.
+
+@item
+The x86 architecture supports 80-bit floating-point registers.  The
+@code{long double} data type occupies 96 bits in memory but only 80 bits
+when stored in a register.
+
+@end itemize
+
+In general, the register representation of a data type is determined by
+the architecture, or @value{GDBN}'s interface to the architecture, while
+the memory representation is determined by the Application Binary
+Interface.
+
+For almost all data types on almost all architectures, the two
+representations are identical, and no special handling is needed.
+However, they do occasionally differ.  Your architecture may define the
+following macros to request conversions between the register and memory
+representations of a data type:
+
+@deftypefn {Target Macro} int CONVERT_REGISTER_P (int @var{reg})
+Return non-zero if the representation of a data value stored in this
+register may be different to the representation of that same data value
+when stored in memory.
+
+When non-zero, the macros @code{REGISTER_TO_VALUE} and
+@code{VALUE_TO_REGISTER} are used to perform any necessary conversion.
+@end deftypefn
+
+@deftypefn {Target Macro} void REGISTER_TO_VALUE (int @var{reg}, struct type *@var{type}, char *@var{from}, char *@var{to})
+Convert the value of register number @var{reg} to a data object of type
+@var{type}.  The buffer at @var{from} holds the register's value in raw
+format; the converted value should be placed in the buffer at @var{to}.
+
+Note that @code{REGISTER_TO_VALUE} and @code{VALUE_TO_REGISTER} take
+their @var{reg} and @var{type} arguments in different orders.
+
+You should only use @code{REGISTER_TO_VALUE} with registers for which
+the @code{CONVERT_REGISTER_P} macro returns a non-zero value.
+@end deftypefn
+
+@deftypefn {Target Macro} void VALUE_TO_REGISTER (struct type *@var{type}, int @var{reg}, char *@var{from}, char *@var{to})
+Convert a data value of type @var{type} to register number @var{reg}'
+raw format.
+
+Note that @code{REGISTER_TO_VALUE} and @code{VALUE_TO_REGISTER} take
+their @var{reg} and @var{type} arguments in different orders.
+
+You should only use @code{VALUE_TO_REGISTER} with registers for which
+the @code{CONVERT_REGISTER_P} macro returns a non-zero value.
+@end deftypefn
+
+@deftypefn {Target Macro} void REGISTER_CONVERT_TO_TYPE (int @var{regnum}, struct type *@var{type}, char *@var{buf})
+See @file{mips-tdep.c}.  It does not do what you want.
+@end deftypefn
+
+
 @section Frame Interpretation
 
 @section Inferior Call Setup
@@ -2834,6 +2916,12 @@
 @code{default_coerce_float_to_double} provides this behavior; it is the
 default value, for compatibility with older configurations.
 
+@item int CONVERT_REGISTER_P(@var{regnum})
+@findex CONVERT_REGISTER_P
+Return non-zero if register @var{regnum} can represent data values in a
+non-standard form.
+@xref{Target Architecture Definition, , Using Different Register and Memory Data Representations}.
+
 @item CPLUS_MARKER
 @findex CPLUS_MARKERz
 Define this to expand into the character that G@t{++} uses to distinguish
@@ -3171,34 +3259,40 @@
 @item REGISTER_CONVERTIBLE (@var{reg})
 @findex REGISTER_CONVERTIBLE
 Return non-zero if @var{reg} uses different raw and virtual formats.
+@xref{Target Architecture Definition, , Raw and Virtual Register Representations}.
+
+@item REGISTER_TO_VALUE(@var{regnum}, @var{type}, @var{from}, @var{to})
+@findex REGISTER_TO_VALUE
+Convert the raw contents of register @var{regnum} into a value of type
+@var{type}.
 @xref{Target Architecture Definition, , Using Different Register and Memory Data Representations}.
 
 @item REGISTER_RAW_SIZE (@var{reg})
 @findex REGISTER_RAW_SIZE
 Return the raw size of @var{reg}.
-@xref{Target Architecture Definition, , Using Different Register and Memory Data Representations}.
+@xref{Target Architecture Definition, , Raw and Virtual Register Representations}.
 
 @item REGISTER_VIRTUAL_SIZE (@var{reg})
 @findex REGISTER_VIRTUAL_SIZE
 Return the virtual size of @var{reg}.
-@xref{Target Architecture Definition, , Using Different Register and Memory Data Representations}.
+@xref{Target Architecture Definition, , Raw and Virtual Register Representations}.
 
 @item REGISTER_VIRTUAL_TYPE (@var{reg})
 @findex REGISTER_VIRTUAL_TYPE
 Return the virtual type of @var{reg}.
-@xref{Target Architecture Definition, , Using Different Register and Memory Data Representations}.
+@xref{Target Architecture Definition, , Raw and Virtual Register Representations}.
 
 @item REGISTER_CONVERT_TO_VIRTUAL(@var{reg}, @var{type}, @var{from}, @var{to})
 @findex REGISTER_CONVERT_TO_VIRTUAL
 Convert the value of register @var{reg} from its raw form to its virtual
 form.
-@xref{Target Architecture Definition, , Using Different Register and Memory Data Representations}.
+@xref{Target Architecture Definition, , Raw and Virtual Register Representations}.
 
 @item REGISTER_CONVERT_TO_RAW(@var{type}, @var{reg}, @var{from}, @var{to})
 @findex REGISTER_CONVERT_TO_RAW
 Convert the value of register @var{reg} from its virtual form to its raw
 form.
-@xref{Target Architecture Definition, , Using Different Register and Memory Data Representations}.
+@xref{Target Architecture Definition, , Raw and Virtual Register Representations}.
 
 @item RETURN_VALUE_ON_STACK(@var{type})
 @findex RETURN_VALUE_ON_STACK
@@ -3579,6 +3673,12 @@
 being considered is known to have been compiled by GCC; this is helpful
 for systems where GCC is known to use different calling convention than
 other compilers.
+
+@item VALUE_TO_REGISTER(@var{type}, @var{regnum}, @var{from}, @var{to})
+@findex VALUE_TO_REGISTER
+Convert a value of type @var{type} into the raw contents of register
+@var{regnum}'s.
+@xref{Target Architecture Definition, , Using Different Register and Memory Data Representations}.
 
 @item VARIABLES_INSIDE_BLOCK (@var{desc}, @var{gcc_p})
 @findex VARIABLES_INSIDE_BLOCK

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]