This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch/rfc] Introduce regcache (version 3?)
- From: Andrew Cagney <ac131313 at cygnus dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Thu, 23 May 2002 14:49:41 -0400
- Subject: [patch/rfc] Introduce regcache (version 3?)
The attached (jumbo) patch introduces a ``struct regcache''. It isn't
being committed as is mind :-)
Breaking it down, it does the following:
- Adds a ``struct regcache *'' object and numerious methods - copy, dup,
restore, read, write, ...
- Modifies regcache_read and regcache_write so that they handle the
pre/post gdbarch_register_read() / gdbarch_register_write() cases
separatly. The post case now avoids any legacy_*() functions.
- Updates the generic dummy frame code to use the regcache instead of
raw register buffers when saving and restoring frame registers.
- Updates the infrun/infcmd code to use a regcache (grep for
stop_registers) instead of raw register buffers.
- Updates the methods EXTRACT_RETURN_VALUE and
EXTRACT_STRUCT_VALUE_ADDRESS so that they take a regcache instead of raw
register buffers as a parameter.
- Adds a global [ulgh!] ``current_regcache'' (kept in sync with the
other globals registers[] and register_valid[]). So that existing code
that assumes a single register cache still works. I believe we're now
down to just target side code doing this.
What doesn't it do?
- add a gdbarch parameter to methods like gdbarch_register_read / write.
- allow more than one active register cache (as would be needed with
threads). Still it is a good starting point.
Where to from here?
The first two steps will be:
- Rearange/rename the EXTRACT_RETURN_VALUE and
EXTRACT_STRUCT_VALUE_ADDRESS gdbarch methods to make way for versions
that take a struct gdbarch
- add the regcache code (unused) so that it is exposed to the compiler
After that, slowly integrate the remaining code.
Right now this only affects SH5 so I'd better find a working toolchain.
comments?
Andrew
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.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.5
diff -u -r1.36 -r1.36.2.5
--- regcache.c 15 May 2002 01:01:56 -0000 1.36
+++ regcache.c 23 May 2002 18:03:25 -0000 1.36.2.5
@@ -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,364 @@
* 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;
+
+ /* Is this a ``legacy'' register cache? Such caches reserve space
+ for raw and pseudo registers and allow access to both. */
+ int legacy_p;
+
+ /* The raw register cache. This should contain just [0
+ .. NUM_RAW_REGISTERS). However, for older targets, it contains
+ space for the full [0 .. NUM_RAW_REGISTERS +
+ NUM_PSEUDO_REGISTERS). */
+ int nr_raw_registers;
+ long sizeof_raw_registers;
+ long sizeof_raw_register_valid_p;
+
+ /* Offset, in bytes, of reach register in the raw register cache.
+ Pseudo registers have an offset even though they don't
+ (shouldn't) have a correspoinding space in the register cache.
+ It is to keep existing code, that relies on
+ write/write_register_bytes working. */
+ long *register_offset;
+
+ /* The cooked / frame / virtual register space. The registers in
+ the range [0..NR_RAW_REGISTERS) should be mapped directly onto
+ the corresponding raw register. The next [NR_RAW_REGISTERS
+ .. NR_REGISTERS) should have been mapped, via
+ gdbarch_register_read/write onto either raw registers or memory. */
+ int nr_registers;
+ long *sizeof_register;
+ long max_register_size;
+
+};
+
+static struct regcache_descr *
+legacy_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;
+ descr->legacy_p = 1;
+
+ /* 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->nr_raw_registers = descr->nr_registers;
+ descr->sizeof_raw_register_valid_p = descr->nr_registers;
+
+ /* 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);
+ descr->max_register_size = 0;
+ for (i = 0; i < descr->nr_registers; i++)
+ {
+ descr->register_offset[i] = REGISTER_BYTE (i);
+ descr->sizeof_register[i] = REGISTER_RAW_SIZE (i);
+ if (descr->max_register_size < REGISTER_RAW_SIZE (i))
+ descr->max_register_size = REGISTER_RAW_SIZE (i);
+ }
+
+ /* Come up with the real size of the registers buffer. */
+ descr->sizeof_raw_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_raw_registers < regend)
+ descr->sizeof_raw_registers = regend;
+ }
+ set_gdbarch_data (gdbarch, regcache_data_handle, descr);
+ return descr;
+}
+
+static struct regcache_descr *
+regcache_descr (struct gdbarch *gdbarch)
+{
+ int i;
+ struct regcache_descr *descr;
+ gdb_assert (gdbarch != NULL);
+
+ /* If the value has previously been computed, just return that. */
+ descr = gdbarch_data (gdbarch, regcache_data_handle);
+ if (descr != NULL)
+ return descr;
+
+ /* If an old style architecture, construct the register cache
+ description using all the register macros. */
+ if (!gdbarch_register_read_p (gdbarch)
+ && !gdbarch_register_write_p (gdbarch))
+ return legacy_regcache_descr (gdbarch);
+
+ descr = XMALLOC (struct regcache_descr);
+ descr->gdbarch = gdbarch;
+ descr->legacy_p = 0;
+
+ /* Total size of the register space. The raw registers should
+ directly map onto the raw register cache while the pseudo's are
+ either mapped onto raw-registers or memory. */
+ descr->nr_registers = NUM_REGS + NUM_PSEUDO_REGS;
+
+ /* Construct a strictly RAW register cache. Don't allow pseudo's
+ into the register cache. */
+ descr->nr_raw_registers = NUM_REGS;
+ descr->sizeof_raw_register_valid_p = NUM_REGS;
+
+ /* Lay out the register cache. The pseud-registers are included in
+ the layout even though their value isn't stored in the register
+ cache. Some code, via read_register_bytes() access a register
+ using an offset/length rather than a register number.
+
+ NOTE: cagney/2002-05-22: Only REGISTER_VIRTUAL_TYPE() needs to be
+ used when constructing the register cache. It is assumed that
+ register raw size, virtual size and type length of the type are
+ all the same. */
+
+ {
+ long offset = 0;
+ descr->sizeof_register = XCALLOC (descr->nr_registers, long);
+ descr->register_offset = XCALLOC (descr->nr_registers, long);
+ descr->max_register_size = 0;
+ for (i = 0; i < descr->nr_registers; i++)
+ {
+ descr->sizeof_register[i] = TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (i));
+ descr->register_offset[i] = offset;
+ offset += descr->sizeof_register[i];
+ if (descr->max_register_size < descr->sizeof_register[i])
+ descr->max_register_size = descr->sizeof_register[i];
+ }
+ /* Set the real size of the register cache buffer. */
+ /* FIXME: cagney/2002-05-22: Should only need to allocate space
+ for the raw registers. Unfortunatly some code still accesses
+ the register array directly using the global registers[].
+ Until that code has been purged, play safe and over allocating
+ the register buffer. Ulgh! */
+ descr->sizeof_raw_registers = offset;
+ /* = descr->register_offset[descr->nr_raw_registers]; */
+ }
+
+ set_gdbarch_data (gdbarch, regcache_data_handle, descr);
+
+ /* Sanity check. Confirm that the assumptions about gdbarch are
+ true. The REGCACHE_DATA_HANDLE is set before doing the checks so
+ that targets using the generic methods supplied by regcache don't
+ go into infinite recursion trying to, again, create the regcache. */
+ for (i = 0; i < descr->nr_registers; i++)
+ {
+ gdb_assert (descr->sizeof_register[i] == REGISTER_RAW_SIZE (i));
+ gdb_assert (descr->sizeof_register[i] == REGISTER_VIRTUAL_SIZE (i));
+ gdb_assert (descr->register_offset[i] == REGISTER_BYTE (i));
+ }
+ /* gdb_assert (descr->sizeof_raw_registers == REGISTER_BYTES (i)); */
+ 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);
+}
+
+/* The register cache for storing raw register values. */
+
+struct regcache
+{
+ struct regcache_descr *descr;
+ char *raw_registers;
+ char *raw_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->raw_registers
+ = XCALLOC (descr->sizeof_raw_registers, char);
+ regcache->raw_register_valid_p
+ = XCALLOC (descr->sizeof_raw_register_valid_p, char);
+ regcache->passthrough_p = 0;
+ return regcache;
+}
+
+void
+regcache_xfree (struct regcache *regcache)
+{
+ if (regcache == NULL)
+ return;
+ xfree (regcache->raw_registers);
+ xfree (regcache->raw_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;
+ 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 to the register cache. */
+ if (src == current_regcache && src->descr->legacy_p)
+ {
+ /* ULGH!!!! Old way. Use REGISTER bytes and let code below
+ untangle fetch. */
+ read_register_bytes (0, dst->raw_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 to the register cache. */
+ if (dst == current_regcache && dst->descr->legacy_p)
+ {
+ /* ULGH!!!! Old way. Use REGISTER bytes and let code below
+ untangle fetch. */
+ write_register_bytes (0, src->raw_registers, REGISTER_BYTES);
+ return;
+ }
+ buf = alloca (src->descr->max_register_size);
+ for (i = 0; i < src->descr->nr_raw_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->raw_registers, src->raw_registers,
+ dst->descr->sizeof_raw_registers);
+ memcpy (dst->raw_register_valid_p, src->raw_register_valid_p,
+ dst->descr->sizeof_raw_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_raw_registers);
+ return regcache->raw_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_raw_registers);
+ buf = alloca (regcache->descr->sizeof_register[regnum]);
+ regcache_read (regcache, regnum, buf);
+ return extract_address (buf, regcache->descr->sizeof_register[regnum]);
+}
+
+char *
+deprecated_grub_regcache_for_registers (struct regcache *regcache)
+{
+ return regcache->raw_registers;
+}
+
+char *
+deprecated_grub_regcache_for_register_valid (struct regcache *regcache)
+{
+ return regcache->raw_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
@@ -97,10 +456,9 @@
else return a pointer to the start of the cache buffer. */
static char *
-register_buffer (int regnum)
+register_buffer (struct regcache *regcache, int regnum)
{
- gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
- return ®isters[REGISTER_BYTE (regnum)];
+ return regcache->raw_registers + regcache->descr->register_offset[regnum];
}
/* Return whether register REGNUM is a real register. */
@@ -311,22 +669,52 @@
if (!register_cached (regnum))
fetch_register (regnum);
- memcpy (myaddr, register_buffer (regnum),
+ memcpy (myaddr, register_buffer (current_regcache, regnum),
REGISTER_RAW_SIZE (regnum));
}
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_raw_registers);
+ if (regcache->descr->legacy_p
+ && regcache->passthrough_p)
+ {
+ gdb_assert (regcache == current_regcache);
+ /* 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);
+ return;
+ }
+ /* Make certain that the register cache is up-to-date with respect
+ to the current thread. This switching shouldn't be necessary
+ only there is still only one target side register cache. Sigh!
+ On the bright side, at least there is a regcache object. */
+ if (regcache->passthrough_p)
+ {
+ gdb_assert (regcache == current_regcache);
+ if (! ptid_equal (registers_ptid, inferior_ptid))
+ {
+ registers_changed ();
+ registers_ptid = inferior_ptid;
+ }
+ if (!register_cached (regnum))
+ fetch_register (regnum);
+ }
+ /* Copy the value directly into the register cache. */
+ memcpy (buf, (regcache->raw_registers
+ + regcache->descr->register_offset[regnum]),
+ regcache->descr->sizeof_register[regnum]);
}
void
read_register_gen (int regnum, char *buf)
{
- if (! gdbarch_register_read_p (current_gdbarch))
+ gdb_assert (current_regcache != NULL);
+ gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
+ if (current_regcache->descr->legacy_p)
{
legacy_read_register_gen (regnum, buf);
return;
@@ -362,30 +750,80 @@
/* If we have a valid copy of the register, and new value == old
value, then don't bother doing the actual store. */
if (register_cached (regnum)
- && memcmp (register_buffer (regnum), myaddr, size) == 0)
+ && (memcmp (register_buffer (current_regcache, regnum), myaddr, size)
+ == 0))
return;
else
target_prepare_to_store ();
}
- memcpy (register_buffer (regnum), myaddr, size);
+ memcpy (register_buffer (current_regcache, regnum), myaddr, size);
set_register_cached (regnum, 1);
store_register (regnum);
}
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_raw_registers);
+
+ if (regcache->passthrough_p
+ && regcache->descr->legacy_p)
+ {
+ /* For moment, just use underlying legacy code. Ulgh!!! This
+ silently and very indirectly updates the regcache's buffers
+ via the globals register_valid[] and registers[]. */
+ gdb_assert (regcache == current_regcache);
+ legacy_write_register_gen (regnum, buf);
+ return;
+ }
+
+ /* On the sparc, writing %g0 is a no-op, so we don't even want to
+ change the registers array if something writes to this register. */
+ if (CANNOT_STORE_REGISTER (regnum))
+ return;
+
+ /* Handle the simple case first -> not write through so just store
+ value in cache. */
+ if (!regcache->passthrough_p)
+ {
+ memcpy ((regcache->raw_registers
+ + regcache->descr->register_offset[regnum]), buf,
+ regcache->descr->sizeof_register[regnum]);
+ regcache->raw_register_valid_p[regnum] = 1;
+ return;
+ }
+
+ /* Make certain that the correct cache is selected. */
+ gdb_assert (regcache == current_regcache);
+ if (! ptid_equal (registers_ptid, inferior_ptid))
+ {
+ registers_changed ();
+ registers_ptid = inferior_ptid;
+ }
+
+ /* If we have a valid copy of the register, and new value == old
+ value, then don't bother doing the actual store. */
+ if (regcache_valid_p (regcache, regnum)
+ && (memcmp (register_buffer (regcache, regnum), buf,
+ regcache->descr->sizeof_register[regnum]) == 0))
+ return;
+
+ target_prepare_to_store ();
+ memcpy (register_buffer (regcache, regnum), buf,
+ regcache->descr->sizeof_register[regnum]);
+ regcache->raw_register_valid_p[regnum] = 1;
+ store_register (regnum);
}
void
write_register_gen (int regnum, char *buf)
{
- if (! gdbarch_register_write_p (current_gdbarch))
+ gdb_assert (current_regcache != NULL);
+ gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
+ if (current_regcache->descr->legacy_p)
{
legacy_write_register_gen (regnum, buf);
return;
@@ -564,10 +1002,10 @@
set_register_cached (regnum, 1);
if (val)
- memcpy (register_buffer (regnum), val,
+ memcpy (register_buffer (current_regcache, regnum), val,
REGISTER_RAW_SIZE (regnum));
else
- memset (register_buffer (regnum), '\000',
+ memset (register_buffer (current_regcache, regnum), '\000',
REGISTER_RAW_SIZE (regnum));
/* On some architectures, e.g. HPPA, there are a few stray bits in
@@ -587,7 +1025,8 @@
void
regcache_collect (int regnum, void *buf)
{
- memcpy (buf, register_buffer (regnum), REGISTER_RAW_SIZE (regnum));
+ memcpy (buf, register_buffer (current_regcache, regnum),
+ REGISTER_RAW_SIZE (regnum));
}
@@ -755,37 +1194,52 @@
static void
build_regcache (void)
{
+ current_regcache = regcache_xmalloc (current_gdbarch);
+ current_regcache->passthrough_p = 1;
+ registers = deprecated_grub_regcache_for_registers (current_regcache);
+ register_valid = deprecated_grub_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);
+ 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;
+ 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.5
diff -u -r1.6 -r1.6.6.5
--- regcache.h 15 Nov 2001 06:43:10 -0000 1.6
+++ regcache.h 23 May 2002 18:03:25 -0000 1.6.6.5
@@ -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 *deprecated_grub_regcache_for_registers (struct regcache *);
+extern char *deprecated_grub_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.3
diff -u -r1.64 -r1.64.2.3
--- rs6000-tdep.c 12 May 2002 02:16:04 -0000 1.64
+++ rs6000-tdep.c 23 May 2002 18:03:25 -0000 1.64.2.3
@@ -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 = deprecated_grub_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 <ac131313@redhat.com>
+
+ * 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 <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
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 <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 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)