This is the mail archive of the gdb@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]

[wip/rfc] Handle saved regcache using a regbuf


Hello,

Several chunks of code like to make a copy of the global (ulgh) 
registers[] array and then manipulate the copy using REGISTER_BYTE().

For instance:
- after an inferior function call has completed, the inferior function 
call code saves the post-call register state before restoring the 
registers to the pre-call state.  The saved state is then used by 
architecture specific functions to extract return values and the like.
- the dummy frame code, uses a buffer to save the registers of the dummy 
frame

The attached patch is a work-in-progress that rewrites such code to use 
a ``struct regbuf'' object.  regcache_save() is used to save the 
register cache, and regcache_restore_no_writethrough() to later restore 
it (instead of write_register_bytes()).

At this stage, in addition to testing, I'm still trying to figure out 
how to transition target architectures to this new mechanism without 
breaking existing builds.  Interfaces such as 
extract_struct_return_value_address() and extract_return_value() are 
affected.  I suspect I'll be renaming the existing interfaces to 
deprecated_..., and then installing new ones.

Anyway, i'm tableing this for comment.  In a few days, I'll separate out 
the regbuf.[hc] code and post that separatly as a patch.

enjoy,
Andrew
? diffs
? regbuf.h
? regbuf.c
? new-gdbarch.log
? new-gdbarch.h
? new-gdbarch.c
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.2604
diff -u -r1.2604 ChangeLog
--- ChangeLog	11 May 2002 00:40:25 -0000	1.2604
+++ ChangeLog	11 May 2002 19:33:49 -0000
@@ -1,3 +1,111 @@
+2002-05-11  Andrew Cagney  <ac131313@redhat.com>
+
+	* regcache.c (regcache_restore): New function.
+	* regcache.h (regcache_restore): Declare.
+
+	* infrun.c (build_infrun): Allocate stop_registers using
+	regbuf_xmalloc.
+	(_initialize_infrun): Don't call build_infrun.
+
+	* Makefile.in (infrun.o): Add dependency on "regbuf.h".
+
+	* infrun.c: Include "regbuf.h".
+	(struct inferior_status): Change type of stop_registers
+	and registers to ``struct regbuf''.
+	(xmalloc_inferior_status): Allocate stop_registers and registers
+	using regbuf_xmalloc.
+	(free_inferior_status): Free registers and stop_registers using
+	regbuf_xfree.
+	(xmalloc_inferior_status): Delete.
+	(save_inferior_status): XMALLOC inf_status directly.  Use
+	regbuf_dup and regbuf_xmalloc.
+	(free_inferior_status): Delete.
+	(discard_inferior_status): Free inf_status directly.
+	(restore_inferior_status): Free inf_status directly.  Restore
+	stop_registers by replacing buffer.
+	(write_inferior_status_register): Use regbuf_write.
+
+	* Makefile.in (infcmd.o): Add $(regbuf_h).
+
+	* infcmd.c: Include "regbuf.h".
+	(run_stack_dummy): Duplicate the stop_registers.
+
+
+	* rs6000-tdep.c (rs6000_extract_struct_value_address): Change type
+	of regbuf parameter to ``struct regbuf''.
+
+	* Makefile.in (rs6000-tdep.o): Add $(regbuf_h).
+
+	* rs6000-tdep.c: Include "regbuf.h".
+
+	* infrun.c (normal_stop): Use regcache_save.
+
+	* rs6000-tdep.c (rs6000_extract_return_value): Change regbuf type
+	to ``struct regbuf''.  Use grub_around_regbuf_for_registers.
+
+	* inferior.h (stop_registers): Change type to a ``struct regbuf''.
+	* infrun.c (stop_registers): Update.
+
+	* values.c (value_being_returned): Update.
+
+	* infcmd.c (run_stack_dummy): Update.
+
+	* gdbarch.sh (EXTRACT_STRUCT_VALUE_ADDRESS): Change type of regbuf
+	to ``struct regbuf''.
+	(EXTRACT_RETURN_VALUE): 
+
+	* value.h (value_being_returned): Change regbuf parameter type to
+	``struct retbuf''.
+
+	* inferior.h (run_stack_dummy): Change retbuf parameter type to
+	``struct regbuf''.
+	
+	* valops.c (hand_function_call): Make retbuf a ``struct regbuf''.
+
+	* blockframe.c (generic_pop_dummy_frame): Use
+	regcache_restore_no_writethrough and regbuf_xfree.
+
+	* regcache.c (regcache_restore_no_writethrough): New function.
+	(regcache_save): New function.
+	* regcache.h (regcache_save): Declare.
+	(regcache_restore_no_writethrough): Declare.
+
+	* blockframe.c (generic_pop_dummy_frame): Use regbuf_xfree and
+	regcache_restore_regbuf.
+	(generic_get_saved_register): Use regbuf_read.
+
+
+	* blockframe.c: Include "regbuf.h".
+	(generic_push_dummy_frame): Use regbuf_xfree and regcache_save.
+
+	* frame.h (generic_find_dummy_frame): Change return type to
+	``struct regbuf''.
+
+	* Makefile.in (blockframe.o): Add dependency on $(regbuf_h).
+
+	* blockframe.c (struct dummy_frame): Replace registers with
+	regbuf.
+	(generic_find_dummy_frame): Change return type to `struct regbuf',
+	return regbuf.
+	(generic_read_register_dummy): Rewrite using
+	regbuf_read_as_address.
+
+	* regcache.c: Include "regbuf.h".
+	(_initialize_regcache): Register regcache_regbuf for swapping.
+	(regcache_regbuf): Define.
+	(build_regcache): Rewrite using regbuf_xmalloc,
+	grub_around_regbuf_for_registers and
+	grub_around_regbuf_for_register_valid.
+	
+	* Makefile.in (regcache.o): Add $(regbuf_h).
+
+	* defs.h (XCALLOC): Define.
+	* regbuf.c, regbuf.c: New files.
+	* Makefile.in (SFILES): Add regbuf.c.
+	(regbuf_h): Define.
+	(COMMON_OBS): Add regbuf.o.
+	(regbuf.o): Specify dependencies.
+
 2002-05-10  Jason Thorpe  <thorpej@wasabisystems.com>
 
 	From Christian Limpach <chris@Pin.LU>
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.180
diff -u -r1.180 Makefile.in
--- Makefile.in	4 May 2002 15:52:37 -0000	1.180
+++ Makefile.in	11 May 2002 19:33:52 -0000
@@ -530,7 +530,7 @@
 	demangle.c dwarfread.c dwarf2read.c elfread.c environ.c eval.c \
 	event-loop.c event-top.c \
 	expprint.c f-exp.y f-lang.c f-typeprint.c f-valprint.c \
-	findvar.c regcache.c gdbarch.c arch-utils.c gdbtypes.c \
+	findvar.c regcache.c regbuf.c gdbarch.c arch-utils.c gdbtypes.c \
 	inf-loop.c infcmd.c inflow.c infrun.c language.c \
 	kod.c kod-cisco.c \
 	ui-out.c cli-out.c \
@@ -635,6 +635,7 @@
 monitor_h =	monitor.h
 objfiles_h =	objfiles.h
 parser_defs_h =	parser-defs.h $(doublest_h)
+regbuf_h =	regbuf.h
 regcache_h =	regcache.h
 remote_h =	remote.h
 remote_utils_h =  remote-utils.h $(target_h)
@@ -715,7 +716,7 @@
 	gdbarch.o arch-utils.o gdbtypes.o copying.o $(DEPFILES) \
 	memattr.o mem-break.o target.o parse.o language.o $(YYOBJ) buildsym.o \
 	builtin-regs.o std-regs.o \
-	signals.o \
+	signals.o regbuf.o \
 	kod.o kod-cisco.o \
 	gdb-events.o \
 	exec.o bcache.o objfiles.o minsyms.o maint.o demangle.o \
@@ -1289,7 +1290,7 @@
 bcache.o: bcache.c $(bcache_h) $(defs_h)
 
 blockframe.o: blockframe.c $(defs_h) $(gdbcore_h) $(inferior_h) \
-	$(objfiles_h) $(symfile_h) $(target_h) $(regcache_h)
+	$(objfiles_h) $(symfile_h) $(target_h) $(regcache_h) $(regbuf_h)
 
 breakpoint.o: breakpoint.c $(defs_h) $(gdbcmd_h) $(gdbcore_h) \
 	$(inferior_h) $(language_h) $(target_h) $(gdbthread_h) \
@@ -1441,7 +1442,10 @@
 frame.o: frame.c $(defs_h) $(frame_h) $(target_h) $(value_h) $(inferior_h) \
 	$(regcache_h)
 
-regcache.o: regcache.c $(defs_h) $(inferior_h) $(target_h) $(regcache_h)
+regbuf.o: regbuf.c $(defs_h) $(regbuf_h) gdb_assert.h
+
+regcache.o: regcache.c $(defs_h) $(inferior_h) $(target_h) $(regcache_h) \
+	$(regbuf_h)
 
 fork-child.o: fork-child.c gdb_wait.h $(defs_h) $(gdbcore_h) \
 	$(inferior_h) $(target_h) $(terminal_h) $(gdbthread_h) $(gdb_string_h)
@@ -1653,7 +1657,7 @@
 
 infcmd.o: infcmd.c $(defs_h) environ.h $(gdbcmd_h) $(gdbcore_h) \
 	$(inferior_h) $(target_h) $(language_h) $(symfile_h) $(gdb_string_h) \
-	$(ui_out_h) $(completer_h)
+	$(ui_out_h) $(completer_h) $(regbuf_h)
 
 inflow.o: inflow.c $(bfd_h) $(command_h) $(defs_h) $(inferior_h) \
 	$(target_h) $(terminal_h) $(gdbthread_h) $(gdb_string_h)
@@ -1662,9 +1666,9 @@
 	$(gdb_string_h) gdb_wait.h $(command_h) $(regcache_h)
 
 infrun.o: infrun.c gdb_wait.h $(defs_h) $(gdbcmd_h) $(cli_script_h) \
-	$(gdbcore_h) $(value_h) \
-	$(inferior_h) $(target_h) $(gdbthread_h) $(gdb_string_h) $(event_loop_h) \
-	$(event_top_h) $(regcache_h)
+	$(gdbcore_h) $(value_h)	$(inferior_h) $(target_h) $(gdbthread_h) \
+	$(gdb_string_h) $(event_loop_h) $(event_top_h) $(regcache_h) \
+	$(regbuf_h)
 
 inftarg.o: inftarg.c gdb_wait.h $(defs_h) $(gdbcore_h) $(inferior_h) \
 	$(target_h) $(terminal_h) $(command_h)
@@ -1996,7 +2000,8 @@
 	$(gdb_stabs_h) $(regcache_h) $(arch_utils_h)
 
 rs6000-tdep.o: rs6000-tdep.c $(defs_h) $(gdbcore_h) $(inferior_h) \
-	$(target_h) ppc-tdep.h $(regcache_h) $(value_h) $(parser_defs_h)
+	$(target_h) ppc-tdep.h $(regcache_h) $(value_h) $(parser_defs_h) \
+	$(regbuf_h)
 
 s390-tdep.o: s390-tdep.c $(defs_h) $(arch_utils_h) $(frame_h) $(inferior_h) \
 	$(symtab_h) $(target_h) $(gdbcore_h) $(gdbcmd_h) $(symfile_h) \
Index: blockframe.c
===================================================================
RCS file: /cvs/src/src/gdb/blockframe.c,v
retrieving revision 1.27
diff -u -r1.27 blockframe.c
--- blockframe.c	5 May 2002 01:15:12 -0000	1.27
+++ blockframe.c	11 May 2002 19:33:55 -0000
@@ -34,6 +34,7 @@
 #include "inferior.h"		/* for read_pc */
 #include "annotate.h"
 #include "regcache.h"
+#include "regbuf.h"
 
 /* Prototypes for exported functions. */
 
@@ -1069,7 +1070,7 @@
   CORE_ADDR fp;
   CORE_ADDR sp;
   CORE_ADDR top;
-  char *registers;
+  struct regbuf *regbuf;
 
   /* Address range of the call dummy code.  Look for PC in the range
      [LO..HI) (after allowing for DECR_PC_AFTER_BREAK).  */
@@ -1086,7 +1087,7 @@
    adjust for DECR_PC_AFTER_BREAK.  This is because it is only legal
    to call this function after the PC has been adjusted.  */
 
-char *
+struct regbuf *
 generic_find_dummy_frame (CORE_ADDR pc, CORE_ADDR fp)
 {
   struct dummy_frame *dummyframe;
@@ -1098,7 +1099,7 @@
 	    || fp == dummyframe->sp
 	    || fp == dummyframe->top))
       /* The frame in question lies between the saved fp and sp, inclusive */
-      return dummyframe->registers;
+      return dummyframe->regbuf;
 
   return 0;
 }
@@ -1131,11 +1132,10 @@
 CORE_ADDR
 generic_read_register_dummy (CORE_ADDR pc, CORE_ADDR fp, int regno)
 {
-  char *dummy_regs = generic_find_dummy_frame (pc, fp);
+  struct regbuf *dummy_regs = generic_find_dummy_frame (pc, fp);
 
   if (dummy_regs)
-    return extract_address (&dummy_regs[REGISTER_BYTE (regno)],
-			    REGISTER_RAW_SIZE (regno));
+    return regbuf_read_as_address (dummy_regs, regno);
   else
     return 0;
 }
@@ -1162,7 +1162,7 @@
     if (INNER_THAN (dummy_frame->fp, fp))	/* stale -- destroy! */
       {
 	dummy_frame_stack = dummy_frame->next;
-	xfree (dummy_frame->registers);
+	regbuf_xfree (dummy_frame->regbuf);
 	xfree (dummy_frame);
 	dummy_frame = dummy_frame_stack;
       }
@@ -1170,13 +1170,13 @@
       dummy_frame = dummy_frame->next;
 
   dummy_frame = xmalloc (sizeof (struct dummy_frame));
-  dummy_frame->registers = xmalloc (REGISTER_BYTES);
+  dummy_frame->regbuf = regbuf_xmalloc (current_gdbarch);
+  regcache_save (dummy_frame->regbuf);
 
   dummy_frame->pc = read_pc ();
   dummy_frame->sp = read_sp ();
   dummy_frame->top = dummy_frame->sp;
   dummy_frame->fp = fp;
-  read_register_bytes (0, dummy_frame->registers, REGISTER_BYTES);
   dummy_frame->next = dummy_frame_stack;
   dummy_frame_stack = dummy_frame;
 }
@@ -1224,10 +1224,10 @@
   if (!dummy_frame)
     error ("Can't pop dummy frame!");
   dummy_frame_stack = dummy_frame->next;
-  write_register_bytes (0, dummy_frame->registers, REGISTER_BYTES);
+  regcache_restore (dummy_frame->regbuf);
   flush_cached_frames ();
 
-  xfree (dummy_frame->registers);
+  regbuf_xfree (dummy_frame->regbuf);
   xfree (dummy_frame);
 }
 
@@ -1320,10 +1320,8 @@
 	  if (lval)		/* found it in a CALL_DUMMY frame */
 	    *lval = not_lval;
 	  if (raw_buffer)
-	    memcpy (raw_buffer,
-		    generic_find_dummy_frame (frame->pc, frame->frame) +
-		    REGISTER_BYTE (regnum),
-		    REGISTER_RAW_SIZE (regnum));
+	    regbuf_read (generic_find_dummy_frame (frame->pc, frame->frame),
+			 regnum, raw_buffer);
 	  return;
 	}
 
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.88
diff -u -r1.88 defs.h
--- defs.h	18 Apr 2002 18:08:59 -0000	1.88
+++ defs.h	11 May 2002 19:33:58 -0000
@@ -836,10 +836,11 @@
    "libiberty.h". */
 extern void xfree (void *);
 
-/* Utility macro to allocate typed memory.  Avoids errors like
+/* Utility macros to allocate typed memory.  Avoids errors like
    ``struct foo *foo = xmalloc (sizeof bar)'' and ``struct foo *foo =
    (struct foo *) xmalloc (sizeof bar)''.  */
 #define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
+#define XCALLOC(NR, TYPE) ((TYPE*) xcalloc ((NR), sizeof (TYPE)));
 
 /* Like asprintf/vasprintf but get an internal_error if the call
    fails. */
Index: frame.h
===================================================================
RCS file: /cvs/src/src/gdb/frame.h,v
retrieving revision 1.17
diff -u -r1.17 frame.h
--- frame.h	5 May 2002 02:24:38 -0000	1.17
+++ frame.h	11 May 2002 19:33:59 -0000
@@ -268,7 +268,7 @@
 
 extern int generic_pc_in_call_dummy (CORE_ADDR pc,
 				     CORE_ADDR sp, CORE_ADDR fp);
-extern char *generic_find_dummy_frame (CORE_ADDR pc, CORE_ADDR fp);
+extern struct regbuf *generic_find_dummy_frame (CORE_ADDR pc, CORE_ADDR fp);
 
 extern void generic_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun,
 				    int nargs, struct value **args,
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.134
diff -u -r1.134 gdbarch.sh
--- gdbarch.sh	8 May 2002 20:43:04 -0000	1.134
+++ gdbarch.sh	11 May 2002 19:34:12 -0000
@@ -528,7 +528,7 @@
 F:2:INTEGER_TO_ADDRESS:CORE_ADDR:integer_to_address:struct type *type, void *buf:type, buf
 #
 f:2:RETURN_VALUE_ON_STACK:int:return_value_on_stack:struct type *type:type:::generic_return_value_on_stack_not::0
-f:2:EXTRACT_RETURN_VALUE:void:extract_return_value:struct type *type, char *regbuf, char *valbuf:type, regbuf, valbuf::0:0
+f:2:EXTRACT_RETURN_VALUE:void:extract_return_value:struct type *type, struct regbuf *regbuf, char *valbuf:type, regbuf, valbuf::0:0
 f:2:PUSH_ARGUMENTS:CORE_ADDR:push_arguments:int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr:nargs, args, sp, struct_return, struct_addr:::default_push_arguments::0
 f:2:PUSH_DUMMY_FRAME:void:push_dummy_frame:void:-:::0
 F:2:PUSH_RETURN_ADDRESS:CORE_ADDR:push_return_address:CORE_ADDR pc, CORE_ADDR sp:pc, sp:::0
@@ -536,7 +536,7 @@
 #
 f:2:STORE_STRUCT_RETURN:void:store_struct_return:CORE_ADDR addr, CORE_ADDR sp:addr, sp:::0
 f:2:STORE_RETURN_VALUE:void:store_return_value:struct type *type, char *valbuf:type, valbuf:::0
-F:2:EXTRACT_STRUCT_VALUE_ADDRESS:CORE_ADDR:extract_struct_value_address:char *regbuf:regbuf:::0
+F:2:EXTRACT_STRUCT_VALUE_ADDRESS:CORE_ADDR:extract_struct_value_address:struct regbuf *regbuf:regbuf:::0
 f:2:USE_STRUCT_CONVENTION:int:use_struct_convention:int gcc_p, struct type *value_type:gcc_p, value_type:::generic_use_struct_convention::0
 #
 f:2:FRAME_INIT_SAVED_REGS:void:frame_init_saved_regs:struct frame_info *frame:frame::0:0
@@ -762,6 +762,7 @@
 struct value;
 struct objfile;
 struct minimal_symbol;
+struct regbuf;
 
 extern struct gdbarch *current_gdbarch;
 
Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.46
diff -u -r1.46 infcmd.c
--- infcmd.c	23 Apr 2002 03:00:57 -0000	1.46
+++ infcmd.c	11 May 2002 19:34:16 -0000
@@ -40,6 +40,7 @@
 #include "ui-out.h"
 #include "event-top.h"
 #include "parser-defs.h"
+#include "regbuf.h"
 
 /* Functions exported for general use: */
 
@@ -969,7 +970,7 @@
    will eventually be popped when we do hit the dummy end breakpoint).  */
 
 int
-run_stack_dummy (CORE_ADDR addr, char *buffer)
+run_stack_dummy (CORE_ADDR addr, struct regbuf **buffer)
 {
   struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
   int saved_async = 0;
@@ -1042,8 +1043,7 @@
     return 2;
 
   /* On normal return, the stack dummy has been popped already.  */
-
-  memcpy (buffer, stop_registers, REGISTER_BYTES);
+  *buffer = regbuf_dup (stop_registers);
   return 0;
 }
 
Index: inferior.h
===================================================================
RCS file: /cvs/src/src/gdb/inferior.h,v
retrieving revision 1.27
diff -u -r1.27 inferior.h
--- inferior.h	24 Apr 2002 16:28:15 -0000	1.27
+++ inferior.h	11 May 2002 19:34:16 -0000
@@ -24,6 +24,7 @@
 #define INFERIOR_H 1
 
 struct gdbarch;
+struct regbuf;
 
 /* For bpstat.  */
 #include "breakpoint.h"
@@ -153,7 +154,7 @@
 
 extern void terminal_ours (void);
 
-extern int run_stack_dummy (CORE_ADDR, char *);
+extern int run_stack_dummy (CORE_ADDR, struct regbuf **retbuf);
 
 extern CORE_ADDR read_pc (void);
 
@@ -396,7 +397,7 @@
    Thus this contains the return value from the called function (assuming
    values are returned in a register).  */
 
-extern char *stop_registers;
+extern struct regbuf *stop_registers;
 
 /* Nonzero if the child process in inferior_ptid was attached rather
    than forked.  */
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.58
diff -u -r1.58 infrun.c
--- infrun.c	5 May 2002 01:15:13 -0000	1.58
+++ infrun.c	11 May 2002 19:34:30 -0000
@@ -42,6 +42,7 @@
 #include "inf-loop.h"
 #include "regcache.h"
 #include "value.h"
+#include "regbuf.h"
 
 /* Prototypes for local functions */
 
@@ -62,10 +63,6 @@
 static void set_follow_fork_mode_command (char *arg, int from_tty,
 					  struct cmd_list_element * c);
 
-static struct inferior_status *xmalloc_inferior_status (void);
-
-static void free_inferior_status (struct inferior_status *);
-
 static int restore_selected_frame (void *);
 
 static void build_infrun (void);
@@ -341,7 +338,7 @@
    Thus this contains the return value from the called function (assuming
    values are returned in a register).  */
 
-char *stop_registers;
+struct regbuf *stop_registers;
 
 /* Nonzero if program stopped due to error trying to insert breakpoints.  */
 
@@ -3505,7 +3502,7 @@
   /* Save the function value return registers, if we care.
      We might be about to restore their previous contents.  */
   if (proceed_to_finish)
-    read_register_bytes (0, stop_registers, REGISTER_BYTES);
+    regcache_save (stop_registers);
 
   if (stop_stack_dummy)
     {
@@ -3911,12 +3908,12 @@
   int stop_after_trap;
   int stop_soon_quietly;
   CORE_ADDR selected_frame_address;
-  char *stop_registers;
+  struct regbuf *stop_registers;
 
   /* These are here because if call_function_by_hand has written some
      registers and then decides to call error(), we better not have changed
      any registers.  */
-  char *registers;
+  struct regbuf *registers;
 
   int selected_level;
   int breakpoint_proceeded;
@@ -3924,24 +3921,6 @@
   int proceed_to_finish;
 };
 
-static struct inferior_status *
-xmalloc_inferior_status (void)
-{
-  struct inferior_status *inf_status;
-  inf_status = xmalloc (sizeof (struct inferior_status));
-  inf_status->stop_registers = xmalloc (REGISTER_BYTES);
-  inf_status->registers = xmalloc (REGISTER_BYTES);
-  return inf_status;
-}
-
-static void
-free_inferior_status (struct inferior_status *inf_status)
-{
-  xfree (inf_status->registers);
-  xfree (inf_status->stop_registers);
-  xfree (inf_status);
-}
-
 void
 write_inferior_status_register (struct inferior_status *inf_status, int regno,
 				LONGEST val)
@@ -3949,7 +3928,7 @@
   int size = REGISTER_RAW_SIZE (regno);
   void *buf = alloca (size);
   store_signed_integer (buf, size, val);
-  memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size);
+  regbuf_write (inf_status->registers, regno, buf);
 }
 
 /* Save all of the information associated with the inferior<==>gdb
@@ -3959,7 +3938,7 @@
 struct inferior_status *
 save_inferior_status (int restore_stack_info)
 {
-  struct inferior_status *inf_status = xmalloc_inferior_status ();
+  struct inferior_status *inf_status = XMALLOC (struct inferior_status);
 
   inf_status->stop_signal = stop_signal;
   inf_status->stop_pc = stop_pc;
@@ -3983,9 +3962,9 @@
   inf_status->restore_stack_info = restore_stack_info;
   inf_status->proceed_to_finish = proceed_to_finish;
 
-  memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
-
-  read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
+  inf_status->stop_registers = regbuf_dup (stop_registers);
+  inf_status->registers = regbuf_xmalloc (current_gdbarch);
+  regcache_save (inf_status->registers);
 
   record_selected_frame (&(inf_status->selected_frame_address),
 			 &(inf_status->selected_level));
@@ -4049,13 +4028,15 @@
   breakpoint_proceeded = inf_status->breakpoint_proceeded;
   proceed_to_finish = inf_status->proceed_to_finish;
 
-  /* FIXME: Is the restore of stop_registers always needed */
-  memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
+  /* FIXME: Is the restore of stop_registers always needed?  */
+  regbuf_xfree (stop_registers);
+  stop_registers = inf_status->stop_registers;
 
   /* The inferior can be gone if the user types "print exit(0)"
      (and perhaps other times).  */
   if (target_has_execution)
-    write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
+    regcache_restore (inf_status->registers);
+  regbuf_xfree (inf_status->registers);
 
   /* FIXME: If we are being called after stopping in a function which
      is called from gdb, we should not be trying to restore the
@@ -4083,7 +4064,7 @@
 
     }
 
-  free_inferior_status (inf_status);
+  xfree (inf_status);
 }
 
 static void
@@ -4103,7 +4084,9 @@
 {
   /* See save_inferior_status for info on stop_bpstat. */
   bpstat_clear (&inf_status->stop_bpstat);
-  free_inferior_status (inf_status);
+  regbuf_xfree (inf_status->registers);
+  regbuf_xfree (inf_status->stop_registers);
+  xfree (inf_status);
 }
 
 /* Oft used ptids */
@@ -4194,7 +4177,7 @@
 static void
 build_infrun (void)
 {
-  stop_registers = xmalloc (REGISTER_BYTES);
+  stop_registers = regbuf_xmalloc (current_gdbarch);
 }
 
 void
@@ -4203,8 +4186,6 @@
   register int i;
   register int numsigs;
   struct cmd_list_element *c;
-
-  build_infrun ();
 
   register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL);
   register_gdbarch_swap (NULL, 0, build_infrun);
Index: regcache.c
===================================================================
RCS file: /cvs/src/src/gdb/regcache.c,v
retrieving revision 1.34
diff -u -r1.34 regcache.c
--- regcache.c	6 Apr 2002 00:02:50 -0000	1.34
+++ regcache.c	11 May 2002 19:34:31 -0000
@@ -26,6 +26,7 @@
 #include "gdbcmd.h"
 #include "regcache.h"
 #include "gdb_assert.h"
+#include "regbuf.h"
 
 /*
  * DATA STRUCTURE
@@ -33,6 +34,12 @@
  * Here is the actual register cache.
  */
 
+/* Global structure containing the current regbuf.  */
+/* FIXME: cagney/2002-05-11: The two global arrays registers[] and
+   register_valid[] currently point into this structure.  */
+
+struct regbuf *regcache_regbuf;
+
 /* NOTE: this is a write-through cache.  There is no "dirty" bit for
    recording if the register values have been changed (eg. by the
    user).  Therefore all registers must be written back to the
@@ -751,37 +758,40 @@
 static void
 build_regcache (void)
 {
-  int i;
-  int sizeof_register_valid;
-  /* Come up with the real size of the registers buffer.  */
-  int sizeof_registers = REGISTER_BYTES; /* OK use.  */
-  for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
-    {
-      long regend;
-      /* Keep extending the buffer so that there is always enough
-         space for all registers.  The comparison is necessary since
-         legacy code is free to put registers in random places in the
-         buffer separated by holes.  Once REGISTER_BYTE() is killed
-         this can be greatly simplified.  */
-      /* FIXME: cagney/2001-12-04: This code shouldn't need to use
-         REGISTER_BYTE().  Unfortunatly, legacy code likes to lay the
-         buffer out so that certain registers just happen to overlap.
-         Ulgh!  New targets use gdbarch's register read/write and
-         entirely avoid this uglyness.  */
-      regend = REGISTER_BYTE (i) + REGISTER_RAW_SIZE (i);
-      if (sizeof_registers < regend)
-	sizeof_registers = regend;
-    }
-  registers = xmalloc (sizeof_registers);
-  sizeof_register_valid = ((NUM_REGS + NUM_PSEUDO_REGS)
-			   * sizeof (*register_valid));
-  register_valid = xmalloc (sizeof_register_valid);
-  memset (register_valid, 0, sizeof_register_valid);
+  regcache_regbuf = regbuf_xmalloc (current_gdbarch);
+  registers = grub_around_regbuf_for_registers (regcache_regbuf);
+  register_valid = grub_around_regbuf_for_register_valid (regcache_regbuf);
+}
+
+void
+regcache_save (struct regbuf *regbuf)
+{
+  /* FIXME: cagney/2002-05-11: This assumes that the current
+     architecture and the regbuf architecture are identical.  */
+  char *regbuf_registers = grub_around_regbuf_for_registers (regbuf);
+  char *regbuf_register_valid = grub_around_regbuf_for_register_valid (regbuf);
+  memcpy (regbuf_registers, registers, REGISTER_BYTES);
+  memcpy (regbuf_register_valid, register_valid, NUM_REGS + NUM_PSEUDO_REGS);
+}
+
+void
+regcache_restore (struct regbuf *regbuf)
+{
+  char *regbuf_registers = grub_around_regbuf_for_registers (regbuf);
+  write_register_bytes (0, regbuf_registers, REGISTER_BYTES);
+}
+
+void
+regcache_restore_no_writethrough (struct regbuf *regbuf)
+{
+  char *regbuf_registers = grub_around_regbuf_for_registers (regbuf);
+  memcpy (registers, regbuf_registers, REGISTER_BYTES);
 }
 
 void
 _initialize_regcache (void)
 {
+  REGISTER_GDBARCH_SWAP (regcache_regbuf);
   register_gdbarch_swap (&registers, sizeof (registers), NULL);
   register_gdbarch_swap (&register_valid, sizeof (register_valid), NULL);
   register_gdbarch_swap (NULL, 0, build_regcache);
Index: regcache.h
===================================================================
RCS file: /cvs/src/src/gdb/regcache.h,v
retrieving revision 1.6
diff -u -r1.6 regcache.h
--- regcache.h	15 Nov 2001 06:43:10 -0000	1.6
+++ regcache.h	11 May 2002 19:34:31 -0000
@@ -22,6 +22,8 @@
 #ifndef REGCACHE_H
 #define REGCACHE_H
 
+struct regbuf;
+
 /* Transfer a raw register [0..NUM_REGS) between core-gdb and the
    regcache. */
 
@@ -46,6 +48,14 @@
    referenced thread. */
 
 extern signed char *register_valid;
+
+/* Save/restore the register cache using the regbuf.  The operation is
+   write through - it is strictly for code that needs to restore the
+   target's registers to a previous state.  */
+
+extern void regcache_save (struct regbuf *regbuf);
+extern void regcache_restore (struct regbuf *regbufx);
+extern void regcache_restore_no_writethrough (struct regbuf *regbufx);
 
 extern int register_cached (int regnum);
 
Index: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.63
diff -u -r1.63 rs6000-tdep.c
--- rs6000-tdep.c	30 Apr 2002 23:36:11 -0000	1.63
+++ rs6000-tdep.c	11 May 2002 19:34:50 -0000
@@ -46,6 +46,8 @@
 #include "solib-svr4.h"
 #include "ppc-tdep.h"
 
+#include "regbuf.h"		/* For grub_around_regbuf_for_registers.  */
+
 /* If the kernel has to deliver a signal, it pushes a sigcontext
    structure on the stack and then calls the signal handler, passing
    the address of the sigcontext in an argument register. Usually
@@ -1143,10 +1145,12 @@
    REGBUF, and copy that return value into VALBUF in virtual format. */
 
 static void
-rs6000_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
+rs6000_extract_return_value (struct type *valtype, struct regbuf *regs,
+			     char *valbuf)
 {
   int offset = 0;
   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  char *regbuf = grub_around_regbuf_for_registers (regs);
 
   if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
     {
@@ -1947,8 +1951,9 @@
    as a CORE_ADDR (or an expression that can be used as one).  */
 
 static CORE_ADDR
-rs6000_extract_struct_value_address (char *regbuf)
+rs6000_extract_struct_value_address (struct regbuf *regs)
 {
+  /* FIXME: cagney/2002-05-11: This global variable is just a hack!  */
   return rs6000_struct_return_address;
 }
 
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	11 May 2002 19:34:53 -0000
@@ -1672,7 +1672,7 @@
     SAVE_DUMMY_FRAME_TOS (sp);
 
   {
-    char *retbuf = (char*) alloca (REGISTER_BYTES);
+    struct regbuf *retbuf = NULL;
     char *name;
     struct symbol *symbol;
 
@@ -1704,7 +1704,7 @@
     /* Execute the stack dummy routine, calling FUNCTION.
        When it is done, discard the empty frame
        after storing the contents of all regs into retbuf.  */
-    rc = run_stack_dummy (real_pc + CALL_DUMMY_START_OFFSET, retbuf);
+    rc = run_stack_dummy (real_pc + CALL_DUMMY_START_OFFSET, &retbuf);
 
     if (rc == 1)
       {
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.29
diff -u -r1.29 value.h
--- value.h	17 Mar 2002 01:32:54 -0000	1.29
+++ value.h	11 May 2002 19:34:53 -0000
@@ -23,6 +23,8 @@
 #if !defined (VALUE_H)
 #define VALUE_H 1
 
+struct regbuf;
+
 #include "doublest.h"
 
 /*
@@ -409,7 +411,8 @@
 					     struct type *type);
 
 extern struct value *value_being_returned (struct type *valtype,
-					   char *retbuf, int struct_return);
+					   struct regbuf *retbuf,
+					   int struct_return);
 
 extern struct value *value_in (struct value *element, struct value *set);
 
Index: values.c
===================================================================
RCS file: /cvs/src/src/gdb/values.c,v
retrieving revision 1.34
diff -u -r1.34 values.c
--- values.c	29 Jan 2002 03:08:26 -0000	1.34
+++ values.c	11 May 2002 19:34:57 -0000
@@ -1313,7 +1313,8 @@
 
 /* ARGSUSED */
 struct value *
-value_being_returned (struct type *valtype, char *retbuf, int struct_return)
+value_being_returned (struct type *valtype, struct regbuf *retbuf,
+		      int struct_return)
 {
   struct value *val;
   CORE_ADDR addr;
Index: mi/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/mi/ChangeLog,v
retrieving revision 1.65
diff -u -r1.65 ChangeLog
--- mi/ChangeLog	21 Apr 2002 20:23:33 -0000	1.65
+++ mi/ChangeLog	11 May 2002 19:35:01 -0000
@@ -1,3 +1,10 @@
+2002-05-11  Andrew Cagney  <ac131313@redhat.com>
+
+	* mi-main.c: Include "regbuf.h".
+	(old_regs): Change type of old_regs to a regbuf.
+	(register_changed_p): Use regbuf_read and regbuf_write.
+	(setup_architecture_data): Use regbuf_xmalloc.
+
 2002-04-14  Andrew Cagney  <ac131313@redhat.com>
 
 	* mi-main.c (mi_cmd_exec_return): 
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.29
diff -u -r1.29 mi-main.c
--- mi/mi-main.c	21 Apr 2002 20:23:34 -0000	1.29
+++ mi/mi-main.c	11 May 2002 19:35:04 -0000
@@ -41,6 +41,7 @@
 #include "gdb.h"
 #include <ctype.h>
 #include <sys/time.h>
+#include "regbuf.h"
 
 enum
   {
@@ -55,7 +56,7 @@
 static char *last_async_command;
 static char *previous_async_command;
 static char *mi_error_message;
-static char *old_regs;
+static struct regbuf *old_regs;
 
 extern void _initialize_mi_main (void);
 static char *mi_input (char *);
@@ -367,19 +368,16 @@
 register_changed_p (int regnum)
 {
   char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
+  char *old_buffer = alloca (MAX_REGISTER_RAW_SIZE);
 
   if (! frame_register_read (selected_frame, regnum, raw_buffer))
     return -1;
-
-  if (memcmp (&old_regs[REGISTER_BYTE (regnum)], raw_buffer,
-	      REGISTER_RAW_SIZE (regnum)) == 0)
+  regbuf_read (old_regs, regnum, old_buffer);
+  if (memcmp (old_buffer, raw_buffer, REGISTER_RAW_SIZE (regnum)) == 0)
     return 0;
 
-  /* Found a changed register. Return 1. */
-
-  memcpy (&old_regs[REGISTER_BYTE (regnum)], raw_buffer,
-	  REGISTER_RAW_SIZE (regnum));
-
+  /* Found a changed register.  Update the buffer and return 1.  */
+  regbuf_write (old_regs, regnum, raw_buffer);
   return 1;
 }
 
@@ -1473,9 +1471,7 @@
 static void
 setup_architecture_data (void)
 {
-  /* don't trust REGISTER_BYTES to be zero. */
-  old_regs = xmalloc (REGISTER_BYTES + 1);
-  memset (old_regs, 0, REGISTER_BYTES + 1);
+  old_regs = regbuf_xmalloc (current_gdbarch);
 }
 
 static void

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