Index: Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.190 retrieving revision 1.190.2.2 diff -u -r1.190 -r1.190.2.2 Index: blockframe.c =================================================================== RCS file: /cvs/src/src/gdb/blockframe.c,v retrieving revision 1.27 retrieving revision 1.27.4.3 diff -u -r1.27 -r1.27.4.3 --- blockframe.c 5 May 2002 01:15:12 -0000 1.27 +++ blockframe.c 17 May 2002 15:06:29 -0000 1.27.4.3 @@ -1069,7 +1069,7 @@ CORE_ADDR fp; CORE_ADDR sp; CORE_ADDR top; - char *registers; + struct regcache *regcache; /* Address range of the call dummy code. Look for PC in the range [LO..HI) (after allowing for DECR_PC_AFTER_BREAK). */ @@ -1086,7 +1086,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 regcache * generic_find_dummy_frame (CORE_ADDR pc, CORE_ADDR fp) { struct dummy_frame *dummyframe; @@ -1098,7 +1098,7 @@ || fp == dummyframe->sp || fp == dummyframe->top)) /* The frame in question lies between the saved fp and sp, inclusive */ - return dummyframe->registers; + return dummyframe->regcache; return 0; } @@ -1131,11 +1131,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 regcache *dummy_regs = generic_find_dummy_frame (pc, fp); if (dummy_regs) - return extract_address (&dummy_regs[REGISTER_BYTE (regno)], - REGISTER_RAW_SIZE (regno)); + return regcache_read_as_address (dummy_regs, regno); else return 0; } @@ -1162,7 +1161,7 @@ if (INNER_THAN (dummy_frame->fp, fp)) /* stale -- destroy! */ { dummy_frame_stack = dummy_frame->next; - xfree (dummy_frame->registers); + regcache_xfree (dummy_frame->regcache); xfree (dummy_frame); dummy_frame = dummy_frame_stack; } @@ -1170,13 +1169,13 @@ dummy_frame = dummy_frame->next; dummy_frame = xmalloc (sizeof (struct dummy_frame)); - dummy_frame->registers = xmalloc (REGISTER_BYTES); + dummy_frame->regcache = regcache_xmalloc (current_gdbarch); 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); + regcache_save (dummy_frame->regcache); dummy_frame->next = dummy_frame_stack; dummy_frame_stack = dummy_frame; } @@ -1224,10 +1223,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->regcache); flush_cached_frames (); - xfree (dummy_frame->registers); + regcache_xfree (dummy_frame->regcache); xfree (dummy_frame); } @@ -1320,10 +1319,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)); + regcache_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 retrieving revision 1.88.4.1 diff -u -r1.88 -r1.88.4.1 --- defs.h 18 Apr 2002 18:08:59 -0000 1.88 +++ defs.h 16 May 2002 00:54:55 -0000 1.88.4.1 @@ -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 retrieving revision 1.17.4.2 diff -u -r1.17 -r1.17.4.2 --- frame.h 5 May 2002 02:24:38 -0000 1.17 +++ frame.h 16 May 2002 19:07:58 -0000 1.17.4.2 @@ -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 regcache *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.c =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.c,v retrieving revision 1.127 retrieving revision 1.127.2.2 diff -u -r1.127 -r1.127.2.2 --- gdbarch.c 13 May 2002 17:20:57 -0000 1.127 +++ gdbarch.c 16 May 2002 19:07:58 -0000 1.127.2.2 @@ -1118,8 +1118,8 @@ /* Macro might contain `[{}]' when not multi-arch */ fprintf_unfiltered (file, "gdbarch_dump: %s # %s\n", - "EXTRACT_RETURN_VALUE(type, regbuf, valbuf)", - XSTRING (EXTRACT_RETURN_VALUE (type, regbuf, valbuf))); + "EXTRACT_RETURN_VALUE(type, regcache, valbuf)", + XSTRING (EXTRACT_RETURN_VALUE (type, regcache, valbuf))); #endif if (GDB_MULTI_ARCH) fprintf_unfiltered (file, @@ -1130,8 +1130,8 @@ #ifdef EXTRACT_STRUCT_VALUE_ADDRESS fprintf_unfiltered (file, "gdbarch_dump: %s # %s\n", - "EXTRACT_STRUCT_VALUE_ADDRESS(regbuf)", - XSTRING (EXTRACT_STRUCT_VALUE_ADDRESS (regbuf))); + "EXTRACT_STRUCT_VALUE_ADDRESS(regcache)", + XSTRING (EXTRACT_STRUCT_VALUE_ADDRESS (regcache))); if (GDB_MULTI_ARCH) fprintf_unfiltered (file, "gdbarch_dump: EXTRACT_STRUCT_VALUE_ADDRESS = 0x%08lx\n", @@ -3754,7 +3754,7 @@ } void -gdbarch_extract_return_value (struct gdbarch *gdbarch, struct type *type, char *regbuf, char *valbuf) +gdbarch_extract_return_value (struct gdbarch *gdbarch, struct type *type, struct regcache *regcache, char *valbuf) { gdb_assert (gdbarch != NULL); if (gdbarch->extract_return_value == 0) @@ -3762,7 +3762,7 @@ "gdbarch: gdbarch_extract_return_value invalid"); if (gdbarch_debug >= 2) fprintf_unfiltered (gdb_stdlog, "gdbarch_extract_return_value called\n"); - gdbarch->extract_return_value (type, regbuf, valbuf); + gdbarch->extract_return_value (type, regcache, valbuf); } void @@ -3901,7 +3901,7 @@ } CORE_ADDR -gdbarch_extract_struct_value_address (struct gdbarch *gdbarch, char *regbuf) +gdbarch_extract_struct_value_address (struct gdbarch *gdbarch, struct regcache *regcache) { gdb_assert (gdbarch != NULL); if (gdbarch->extract_struct_value_address == 0) @@ -3909,7 +3909,7 @@ "gdbarch: gdbarch_extract_struct_value_address invalid"); if (gdbarch_debug >= 2) fprintf_unfiltered (gdb_stdlog, "gdbarch_extract_struct_value_address called\n"); - return gdbarch->extract_struct_value_address (regbuf); + return gdbarch->extract_struct_value_address (regcache); } void Index: gdbarch.h =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.h,v retrieving revision 1.95 retrieving revision 1.95.2.2 diff -u -r1.95 -r1.95.2.2 --- gdbarch.h 13 May 2002 17:20:58 -0000 1.95 +++ gdbarch.h 16 May 2002 19:07:59 -0000 1.95.2.2 @@ -46,6 +46,7 @@ struct value; struct objfile; struct minimal_symbol; +struct regcache; extern struct gdbarch *current_gdbarch; @@ -1472,15 +1473,15 @@ #endif #endif -typedef void (gdbarch_extract_return_value_ftype) (struct type *type, char *regbuf, char *valbuf); -extern void gdbarch_extract_return_value (struct gdbarch *gdbarch, struct type *type, char *regbuf, char *valbuf); +typedef void (gdbarch_extract_return_value_ftype) (struct type *type, struct regcache *regcache, char *valbuf); +extern void gdbarch_extract_return_value (struct gdbarch *gdbarch, struct type *type, struct regcache *regcache, char *valbuf); extern void set_gdbarch_extract_return_value (struct gdbarch *gdbarch, gdbarch_extract_return_value_ftype *extract_return_value); #if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (EXTRACT_RETURN_VALUE) #error "Non multi-arch definition of EXTRACT_RETURN_VALUE" #endif #if GDB_MULTI_ARCH #if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) || !defined (EXTRACT_RETURN_VALUE) -#define EXTRACT_RETURN_VALUE(type, regbuf, valbuf) (gdbarch_extract_return_value (current_gdbarch, type, regbuf, valbuf)) +#define EXTRACT_RETURN_VALUE(type, regcache, valbuf) (gdbarch_extract_return_value (current_gdbarch, type, regcache, valbuf)) #endif #endif @@ -1608,18 +1609,18 @@ /* Default (function) for non- multi-arch platforms. */ #if (!GDB_MULTI_ARCH) && !defined (EXTRACT_STRUCT_VALUE_ADDRESS) -#define EXTRACT_STRUCT_VALUE_ADDRESS(regbuf) (internal_error (__FILE__, __LINE__, "EXTRACT_STRUCT_VALUE_ADDRESS"), 0) +#define EXTRACT_STRUCT_VALUE_ADDRESS(regcache) (internal_error (__FILE__, __LINE__, "EXTRACT_STRUCT_VALUE_ADDRESS"), 0) #endif -typedef CORE_ADDR (gdbarch_extract_struct_value_address_ftype) (char *regbuf); -extern CORE_ADDR gdbarch_extract_struct_value_address (struct gdbarch *gdbarch, char *regbuf); +typedef CORE_ADDR (gdbarch_extract_struct_value_address_ftype) (struct regcache *regcache); +extern CORE_ADDR gdbarch_extract_struct_value_address (struct gdbarch *gdbarch, struct regcache *regcache); extern void set_gdbarch_extract_struct_value_address (struct gdbarch *gdbarch, gdbarch_extract_struct_value_address_ftype *extract_struct_value_address); #if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (EXTRACT_STRUCT_VALUE_ADDRESS) #error "Non multi-arch definition of EXTRACT_STRUCT_VALUE_ADDRESS" #endif #if GDB_MULTI_ARCH #if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) || !defined (EXTRACT_STRUCT_VALUE_ADDRESS) -#define EXTRACT_STRUCT_VALUE_ADDRESS(regbuf) (gdbarch_extract_struct_value_address (current_gdbarch, regbuf)) +#define EXTRACT_STRUCT_VALUE_ADDRESS(regcache) (gdbarch_extract_struct_value_address (current_gdbarch, regcache)) #endif #endif Index: gdbarch.sh =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.sh,v retrieving revision 1.138 retrieving revision 1.138.2.2 diff -u -r1.138 -r1.138.2.2 --- gdbarch.sh 13 May 2002 17:20:58 -0000 1.138 +++ gdbarch.sh 16 May 2002 19:07:59 -0000 1.138.2.2 @@ -531,7 +531,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 regcache *regcache, char *valbuf:type, regcache, 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 @@ -539,7 +539,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 regcache *regcache:regcache:::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 @@ -765,6 +765,7 @@ struct value; struct objfile; struct minimal_symbol; +struct regcache; extern struct gdbarch *current_gdbarch; Index: infcmd.c =================================================================== RCS file: /cvs/src/src/gdb/infcmd.c,v retrieving revision 1.46 retrieving revision 1.46.4.3 diff -u -r1.46 -r1.46.4.3 --- infcmd.c 23 Apr 2002 03:00:57 -0000 1.46 +++ infcmd.c 17 May 2002 15:06:29 -0000 1.46.4.3 @@ -40,6 +40,7 @@ #include "ui-out.h" #include "event-top.h" #include "parser-defs.h" +#include "regcache.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 regcache **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 = regcache_dup_no_passthrough (stop_registers); return 0; } Index: inferior.h =================================================================== RCS file: /cvs/src/src/gdb/inferior.h,v retrieving revision 1.27 retrieving revision 1.27.4.2 diff -u -r1.27 -r1.27.4.2 --- inferior.h 24 Apr 2002 16:28:15 -0000 1.27 +++ inferior.h 16 May 2002 19:08:00 -0000 1.27.4.2 @@ -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 regcache **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 regcache *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 retrieving revision 1.58.4.3 diff -u -r1.58 -r1.58.4.3 --- infrun.c 5 May 2002 01:15:13 -0000 1.58 +++ infrun.c 17 May 2002 15:06:30 -0000 1.58.4.3 @@ -62,10 +62,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 +337,7 @@ Thus this contains the return value from the called function (assuming values are returned in a register). */ -char *stop_registers; +struct regcache *stop_registers; /* Nonzero if program stopped due to error trying to insert breakpoints. */ @@ -3505,7 +3501,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 +3907,12 @@ int stop_after_trap; int stop_soon_quietly; CORE_ADDR selected_frame_address; - char *stop_registers; + struct regcache *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 regcache *registers; int selected_level; int breakpoint_proceeded; @@ -3924,24 +3920,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 +3927,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); + regcache_write (inf_status->registers, regno, buf); } /* Save all of the information associated with the inferior<==>gdb @@ -3959,7 +3937,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 +3961,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); + inf_status->stop_registers = regcache_dup_no_passthrough (stop_registers); - read_register_bytes (0, inf_status->registers, REGISTER_BYTES); + inf_status->registers = regcache_dup (current_regcache); record_selected_frame (&(inf_status->selected_frame_address), &(inf_status->selected_level)); @@ -4049,13 +4027,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. */ + regcache_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); + regcache_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 +4063,7 @@ } - free_inferior_status (inf_status); + xfree (inf_status); } static void @@ -4103,7 +4083,9 @@ { /* See save_inferior_status for info on stop_bpstat. */ bpstat_clear (&inf_status->stop_bpstat); - free_inferior_status (inf_status); + regcache_xfree (inf_status->registers); + regcache_xfree (inf_status->stop_registers); + xfree (inf_status); } /* Oft used ptids */ @@ -4194,7 +4176,7 @@ static void build_infrun (void) { - stop_registers = xmalloc (REGISTER_BYTES); + stop_registers = regcache_xmalloc (current_gdbarch); } void @@ -4203,8 +4185,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.36 retrieving revision 1.36.2.4 diff -u -r1.36 -r1.36.2.4 --- regcache.c 15 May 2002 01:01:56 -0000 1.36 +++ regcache.c 17 May 2002 16:17:30 -0000 1.36.2.4 @@ -1,6 +1,7 @@ /* Cache and manage the values of registers for GDB, the GNU debugger. - Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, 2001 - Free Software Foundation, Inc. + + Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, + 2001, 2002 Free Software Foundation, Inc. This file is part of GDB. @@ -33,6 +34,264 @@ * Here is the actual register cache. */ +/* Per-architecture object describing the layout of a register cache. + Computed once when the architecture is created */ + +struct gdbarch_data *regcache_data_handle; + +struct regcache_descr +{ + /* The architecture this descriptor belongs to. */ + struct gdbarch *gdbarch; + /* Total number of registers in the buffer. */ + int nr_registers; + /* Size of the register buffer, over-allocate making room for both + real and pseudo-registers. */ + /* FIXME: cagney/2002-05-11: This over-allocation shouldn't be + necessary. Unfortunatly, some targets store real values in + pseudo-registers and we want to be sure those targets don't crash + GDB. Once that code has been trashed this can be pruned down to + just raw registers. */ + long sizeof_registers; + /* Offset into the register buffer for each register. */ + long *register_offset; + /* Size, in bytes of the register valid array. */ + long sizeof_register_valid_p; + /* Size, in ``bytes'', of a register. */ + long *sizeof_register; +}; + +static struct regcache_descr * +regcache_descr (struct gdbarch *gdbarch) +{ + int i; + struct regcache_descr *descr; + /* FIXME: cagney/2002-05-11: gdbarch_data() should take that + ``gdbarch'' as a parameter. */ + gdb_assert (gdbarch != NULL); + + descr = gdbarch_data (gdbarch, regcache_data_handle); + if (descr != NULL) + return descr; + + descr = XMALLOC (struct regcache_descr); + descr->gdbarch = gdbarch; + + /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers + in the register buffer. Unfortunatly some architectures do. */ + descr->nr_registers = NUM_REGS + NUM_PSEUDO_REGS; + descr->sizeof_register_valid_p = NUM_REGS + NUM_PSEUDO_REGS; + + /* FIXME: cagney/2002-05-11: Instead of using REGISTER_BYTE() this + code should compute the offets et.al. at runtime. This currently + isn't possible because some targets overlap register locations - + see the mess in read_register_bytes() and write_register_bytes() + registers. */ + descr->sizeof_register = XCALLOC (descr->nr_registers, long); + descr->register_offset = XCALLOC (descr->nr_registers, long); + for (i = 0; i < descr->nr_registers; i++) + { + descr->register_offset[i] = REGISTER_BYTE (i); + descr->sizeof_register[i] = REGISTER_RAW_SIZE (i); + } + + /* Come up with the real size of the registers buffer. */ + descr->sizeof_registers = REGISTER_BYTES; /* OK use. */ + for (i = 0; i < descr->nr_registers; 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 = descr->register_offset[i] + descr->sizeof_register[i]; + if (descr->sizeof_registers < regend) + descr->sizeof_registers = regend; + } + set_gdbarch_data (gdbarch, regcache_data_handle, descr); + return descr; +} + +static void +xfree_regcache_descr (struct gdbarch *gdbarch, void *ptr) +{ + struct regcache_descr *descr = ptr; + if (descr == NULL) + return; + xfree (descr->register_offset); + xfree (descr->sizeof_register); + descr->register_offset = NULL; + descr->sizeof_register = NULL; + xfree (descr); +} + +/* For moment, ``struct regcache'' is just a character buffer. */ + +struct regcache +{ + struct regcache_descr *descr; + char *registers; + char *register_valid_p; + /* If a value isn't in the cache should the corresponding target be + queried for a value. */ + int passthrough_p; +}; + +struct regcache * +regcache_xmalloc (struct gdbarch *gdbarch) +{ + struct regcache_descr *descr; + struct regcache *regcache; + gdb_assert (gdbarch != NULL); + descr = regcache_descr (gdbarch); + regcache = XMALLOC (struct regcache); + regcache->descr = descr; + regcache->registers = XCALLOC (descr->sizeof_registers, char); + regcache->register_valid_p = XCALLOC (descr->sizeof_register_valid_p, char); + regcache->passthrough_p = 0; + return regcache; +} + +void +regcache_xfree (struct regcache *regcache) +{ + if (regcache == NULL) + return; + xfree (regcache->registers); + xfree (regcache->register_valid_p); + xfree (regcache); +} + +void +do_regcache_xfree (void *buf) +{ + regcache_xfree (buf); +} + +struct regcache * +regcache_xmalloc_with_cleanup (struct gdbarch *gdbarch) +{ + struct regcache *regcache = regcache_xmalloc (gdbarch); + make_cleanup (do_regcache_xfree, regcache); + return regcache; +} + +void +regcache_cpy (struct regcache *dst, struct regcache *src) +{ + int i; + char *buf = alloca (MAX_REGISTER_RAW_SIZE); + gdb_assert (src != NULL && dst != NULL); + gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); + gdb_assert (src != dst); + /* FIXME: cagney/2002-05-17: To say this bit is bad is being polite. + It keeps the existing code working where things rely on going + through the register cache. */ + if (src == current_regcache + && !gdbarch_register_read_p (src->descr->gdbarch)) + { + /* ULGH!!!! Old way. Use REGISTER bytes and let code below + untangle fetch. */ + read_register_bytes (0, dst->registers, REGISTER_BYTES); + return; + } + /* FIXME: cagney/2002-05-17: To say this bit is bad is being polite. + It keeps the existing code working where things rely on going + through the register cache. */ + if (dst == current_regcache + && !gdbarch_register_read_p (dst->descr->gdbarch)) + { + /* ULGH!!!! Old way. Use REGISTER bytes and let code below + untangle fetch. */ + write_register_bytes (0, src->registers, REGISTER_BYTES); + return; + } + for (i = 0; i < current_regcache->descr->nr_registers; i++) + { + /* Should we worry about the valid bit here? */ + regcache_read (src, i, buf); + regcache_write (dst, i, buf); + } +} + +void +regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src) +{ + int i; + gdb_assert (src != NULL && dst != NULL); + gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); + /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough + move of data into the current_regcache(). Doing this would be + silly - it would mean that valid_p would be completly invalid. */ + gdb_assert (dst != current_regcache); + memcpy (dst->registers, src->registers, + dst->descr->sizeof_registers); + memcpy (dst->register_valid_p, src->register_valid_p, + dst->descr->sizeof_register_valid_p); +} + +struct regcache * +regcache_dup (struct regcache *src) +{ + struct regcache *newbuf; + gdb_assert (current_regcache != NULL); + newbuf = regcache_xmalloc (src->descr->gdbarch); + regcache_cpy (newbuf, src); + return newbuf; +} + +struct regcache * +regcache_dup_no_passthrough (struct regcache *src) +{ + struct regcache *newbuf; + gdb_assert (current_regcache != NULL); + newbuf = regcache_xmalloc (src->descr->gdbarch); + regcache_cpy_no_passthrough (newbuf, src); + return newbuf; +} + +int +regcache_valid_p (struct regcache *regcache, int regnum) +{ + gdb_assert (regcache != NULL); + gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_registers); + return regcache->register_valid_p[regnum]; +} + +CORE_ADDR +regcache_read_as_address (struct regcache *regcache, int regnum) +{ + char *buf; + gdb_assert (regcache != NULL); + gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_registers); + buf = alloca (regcache->descr->sizeof_register[regnum]); + regcache_read (regcache, regnum, buf); + return extract_address (buf, regcache->descr->sizeof_register[regnum]); +} + +char * +grub_around_regcache_for_registers (struct regcache *regcache) +{ + return regcache->registers; +} + +char * +grub_around_regcache_for_register_valid (struct regcache *regcache) +{ + return regcache->register_valid_p; +} + +/* Global structure containing the current regcache. */ +/* FIXME: cagney/2002-05-11: The two global arrays registers[] and + register_valid[] currently point into this structure. */ +struct regcache *current_regcache; + /* 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 @@ -316,11 +575,21 @@ } void -regcache_read (int rawnum, char *buf) +regcache_read (struct regcache *regcache, int regnum, char *buf) { - gdb_assert (rawnum >= 0 && rawnum < (NUM_REGS + NUM_PSEUDO_REGS)); - /* For moment, just use underlying legacy code. Ulgh!!! */ - legacy_read_register_gen (rawnum, buf); + gdb_assert (regcache != NULL && buf != NULL); + gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_registers); + if (regcache->passthrough_p) + /* For moment, just use underlying legacy code. Ulgh!!! This + silently and very indirectly updates the regcache's regcache via + the global register_valid[]. */ + legacy_read_register_gen (regnum, buf); + else + { + memcpy (buf, (regcache->registers + + regcache->descr->register_offset[regnum]), + regcache->descr->sizeof_register[regnum]); + } } void @@ -375,11 +644,21 @@ } void -regcache_write (int rawnum, char *buf) +regcache_write (struct regcache *regcache, int regnum, char *buf) { - gdb_assert (rawnum >= 0 && rawnum < (NUM_REGS + NUM_PSEUDO_REGS)); - /* For moment, just use underlying legacy code. Ulgh!!! */ - legacy_write_register_gen (rawnum, buf); + gdb_assert (regcache != NULL && buf != NULL); + gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_registers); + if (regcache->passthrough_p) + /* For moment, just use underlying legacy code. Ulgh!!! This + silently and very indirectly updates the regcache's regcache via + the global register_valid[]. */ + legacy_write_register_gen (regnum, buf); + else + { + memcpy (regcache->registers + regcache->descr->register_offset[regnum], buf, + regcache->descr->sizeof_register[regnum]); + regcache->register_valid_p[regnum] = 1; + } } void @@ -755,37 +1034,54 @@ static void build_regcache (void) { + current_regcache = regcache_xmalloc (current_gdbarch); + current_regcache->passthrough_p = 1; + registers = grub_around_regcache_for_registers (current_regcache); + register_valid = grub_around_regcache_for_register_valid (current_regcache); +} + +void +regcache_save (struct regcache *regcache) +{ 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); + char *buf = alloca (MAX_REGISTER_RAW_SIZE); + gdb_assert (current_regcache != NULL && regcache != NULL); + gdb_assert (current_regcache->descr->gdbarch == regcache->descr->gdbarch); + regcache_cpy (regcache, current_regcache); +} + +void +regcache_save_no_passthrough (struct regcache *regcache) +{ + gdb_assert (current_regcache != NULL && regcache != NULL); + gdb_assert (current_regcache->descr->gdbarch == regcache->descr->gdbarch); + regcache_cpy_no_passthrough (regcache, current_regcache); +} + +void +regcache_restore (struct regcache *regcache) +{ + int i; + char *buf = alloca (MAX_REGISTER_RAW_SIZE); + gdb_assert (current_regcache != NULL && regcache != NULL); + gdb_assert (current_regcache->descr->gdbarch == regcache->descr->gdbarch); + regcache_cpy (current_regcache, regcache); +} + +void +regcache_restore_no_passthrough (struct regcache *regcache) +{ + char *regcache_registers; + gdb_assert (current_regcache != NULL && regcache != NULL); + gdb_assert (current_regcache->descr->gdbarch == regcache->descr->gdbarch); + regcache_cpy_no_passthrough (current_regcache, regcache); } void _initialize_regcache (void) { + regcache_data_handle = register_gdbarch_data (NULL, xfree_regcache_descr); + REGISTER_GDBARCH_SWAP (current_regcache); register_gdbarch_swap (®isters, sizeof (registers), NULL); register_gdbarch_swap (®ister_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 retrieving revision 1.6.6.4 diff -u -r1.6 -r1.6.6.4 --- regcache.h 15 Nov 2001 06:43:10 -0000 1.6 +++ regcache.h 17 May 2002 16:17:30 -0000 1.6.6.4 @@ -1,6 +1,7 @@ /* Cache and manage the values of registers for GDB, the GNU debugger. - Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, 2001 - Free Software Foundation, Inc. + + Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, + 2001, 2002 Free Software Foundation, Inc. This file is part of GDB. @@ -22,11 +23,20 @@ #ifndef REGCACHE_H #define REGCACHE_H +struct regcache; + +extern struct regcache *current_regcache; + +void regcache_xfree (struct regcache *regcache); +struct regcache *regcache_xmalloc (struct gdbarch *gdbarch); + /* Transfer a raw register [0..NUM_REGS) between core-gdb and the regcache. */ -void regcache_read (int rawnum, char *buf); -void regcache_write (int rawnum, char *buf); +void regcache_read (struct regcache *regcache, int rawnum, char *buf); +void regcache_write (struct regcache *regcache, int rawnum, char *buf); +int regcache_valid_p (struct regcache *regcache, int regnum); +CORE_ADDR regcache_read_as_address (struct regcache *regcache, int rawnum); /* Transfer a raw register [0..NUM_REGS) between the regcache and the target. These functions are called by the target in response to a @@ -46,6 +56,25 @@ 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. + + ``no passthrough'' versions do not go through to the target. They + only save values already in the cache. */ + +extern void regcache_save (struct regcache *regcache); +extern void regcache_restore (struct regcache *regcache); +extern struct regcache *regcache_dup (struct regcache *regcache); +extern void regcache_save_no_passthrough (struct regcache *regcache); +extern void regcache_restore_no_passthrough (struct regcache *regcache); +extern struct regcache *regcache_dup_no_passthrough (struct regcache *regcache); +extern void regcache_cpy (struct regcache *dest, struct regcache *src); +extern void regcache_cpy_no_passthrough (struct regcache *dest, struct regcache *src); + +extern char *grub_around_regcache_for_registers (struct regcache *); +extern char *grub_around_regcache_for_register_valid (struct regcache *); extern int register_cached (int regnum); Index: rs6000-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v retrieving revision 1.64 retrieving revision 1.64.2.2 diff -u -r1.64 -r1.64.2.2 --- rs6000-tdep.c 12 May 2002 02:16:04 -0000 1.64 +++ rs6000-tdep.c 16 May 2002 19:08:01 -0000 1.64.2.2 @@ -46,6 +46,8 @@ #include "solib-svr4.h" #include "ppc-tdep.h" +#include "regcache.h" /* For grub_around_regcache_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 regcache *regs, + char *valbuf) { int offset = 0; struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); + char *regbuf = grub_around_regcache_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 regcache *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.59 retrieving revision 1.59.2.2 diff -u -r1.59 -r1.59.2.2 --- valops.c 13 May 2002 14:00:36 -0000 1.59 +++ valops.c 16 May 2002 19:08:01 -0000 1.59.2.2 @@ -1672,7 +1672,7 @@ SAVE_DUMMY_FRAME_TOS (sp); { - char *retbuf = (char*) alloca (REGISTER_BYTES); + struct regcache *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.31 retrieving revision 1.31.2.2 diff -u -r1.31 -r1.31.2.2 --- value.h 12 May 2002 02:20:38 -0000 1.31 +++ value.h 16 May 2002 19:08:01 -0000 1.31.2.2 @@ -23,6 +23,8 @@ #if !defined (VALUE_H) #define VALUE_H 1 +struct regcache; + #include "doublest.h" /* @@ -406,7 +408,8 @@ extern struct value *value_subscript (struct value *array, struct value *idx); extern struct value *value_being_returned (struct type *valtype, - char *retbuf, int struct_return); + struct regcache *regcache, + 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.35 retrieving revision 1.35.2.2 diff -u -r1.35 -r1.35.2.2 --- values.c 11 May 2002 23:48:23 -0000 1.35 +++ values.c 16 May 2002 19:08:01 -0000 1.35.2.2 @@ -1224,7 +1224,8 @@ /* ARGSUSED */ struct value * -value_being_returned (struct type *valtype, char *retbuf, int struct_return) +value_being_returned (struct type *valtype, struct regcache *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 retrieving revision 1.65.4.2 diff -u -r1.65 -r1.65.4.2 --- mi/ChangeLog 21 Apr 2002 20:23:33 -0000 1.65 +++ mi/ChangeLog 16 May 2002 19:08:05 -0000 1.65.4.2 @@ -1,3 +1,16 @@ +2002-05-16 Andrew Cagney + + * mi-main.c (register_changed_p): Update. + (setup_architecture_data): Update + (_initialize_mi_main): Don't call setup_architecture_data. + +2002-05-11 Andrew Cagney + + * 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 * 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 retrieving revision 1.29.4.2 diff -u -r1.29 -r1.29.4.2 --- mi/mi-main.c 21 Apr 2002 20:23:34 -0000 1.29 +++ mi/mi-main.c 16 May 2002 19:08:05 -0000 1.29.4.2 @@ -41,6 +41,7 @@ #include "gdb.h" #include #include +#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 regcache *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) + regcache_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. */ + regcache_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 = regcache_xmalloc (current_gdbarch); } static void @@ -1501,7 +1497,6 @@ return; init_ui_hook = mi_init_ui; - setup_architecture_data (); register_gdbarch_swap (&old_regs, sizeof (old_regs), NULL); register_gdbarch_swap (NULL, 0, setup_architecture_data); if (event_loop_p)