This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch/rfc] Convert ``stop_registers'' into a ``struct regcache''
- From: Andrew Cagney <ac131313 at cygnus dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sat, 22 Jun 2002 18:53:12 -0400
- Subject: [patch/rfc] Convert ``stop_registers'' into a ``struct regcache''
Hello,
The attached patch is the next in the series introducing the ``struct
regcache''.
This patch converts the global ``char *stop_registers'' into a regcache.
It mostly affects infrun.c. The only slightly strange thing in the
change is the code restoring the stop_registers. Instead of copying the
saved stop_registers into the global, it replaces the global with the
saved regcache.
I'll commit it in a few days.
enjoy,
Andrew
2002-06-22 Andrew Cagney <ac131313@redhat.com>
* infrun.c (stop_registers): Change variable's type to ``struct
regcache'''.
(xmalloc_inferior_status): Delete function.
(free_inferior_status): Delete function.
(normal_stop): Use regcache_cpy.
(struct inferior_status): Change type of fields ``stop_registers''
and ``registers'' to ``struct regcache''.
(write_inferior_status_register): Use regcache_write.
(save_inferior_status): Instead of calling
xmalloc_inferior_status, allocate the inf_status buffer directly.
Use regcache_dup_no_passthrough and regcache_dup to save the
buffers.
(restore_inferior_status): Use regcache_xfree and regcache_cpy.
Replace the stop_registers regcache instead of overriding it. Use
regcache_xfree. Instead of calling free_inferior_status, xfree
the buffer directly.
(discard_inferior_status): Use regcache_xfree. Instead of calling
free_inferior_status, xfree the buffer directly.
(build_infrun): Use regcache_xmalloc.
(_initialize_infrun): Delete redundant call to build_infrun.
* Makefile.in (infcmd.o): Add $(regcache_h).
* infcmd.c: Include "regcache.h".
(run_stack_dummy): Use deprecated_grub_regcache_for_registers to
obtain the address of `stop_registers' register buffer.
(print_return_value): Ditto.
* inferior.h (struct regcache): Add opaque declaration.
(stop_registers): Change variable's declared type to ``struct
regcache''.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.211
diff -u -r1.211 Makefile.in
--- Makefile.in 21 Jun 2002 23:48:32 -0000 1.211
+++ Makefile.in 22 Jun 2002 22:38:58 -0000
@@ -1709,7 +1709,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) $(regcache_h)
inflow.o: inflow.c $(bfd_h) $(command_h) $(defs_h) $(inferior_h) \
$(target_h) $(terminal_h) $(gdbthread_h) $(gdb_string_h)
Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.47
diff -u -r1.47 infcmd.c
--- infcmd.c 11 Jun 2002 02:30:59 -0000 1.47
+++ infcmd.c 22 Jun 2002 22:39:01 -0000
@@ -41,6 +41,8 @@
#include "event-top.h"
#include "parser-defs.h"
+#include "regcache.h" /* for deprecated_grub_regcache_for_registers(). */
+
/* Functions exported for general use: */
void nofp_registers_info (char *, int);
@@ -1043,7 +1045,8 @@
/* On normal return, the stack dummy has been popped already. */
- memcpy (buffer, stop_registers, REGISTER_BYTES);
+ memcpy (buffer, deprecated_grub_regcache_for_registers (stop_registers),
+ REGISTER_BYTES);
return 0;
}
@@ -1143,7 +1146,15 @@
if (!structure_return)
{
+#if 0
value = value_being_returned (value_type, stop_registers, structure_return);
+#else
+ /* FIXME: cagney/2002-06-22: Function value_being_returned()
+ should take a regcache as a parameter. */
+ value = value_being_returned
+ (value_type, deprecated_grub_regcache_for_registers (stop_registers),
+ structure_return);
+#endif
stb = ui_out_stream_new (uiout);
ui_out_text (uiout, "Value returned is ");
ui_out_field_fmt (uiout, "gdb-result-var", "$%d", record_latest_value (value));
@@ -1164,7 +1175,15 @@
ui_out_text (uiout, ".");
ui_out_text (uiout, " Cannot determine contents\n");
#else
+#if 0
value = value_being_returned (value_type, stop_registers, structure_return);
+#else
+ /* FIXME: cagney/2002-06-22: Function value_being_returned()
+ should take a regcache as a parameter. */
+ value = value_being_returned
+ (value_type, deprecated_grub_regcache_for_registers (stop_registers),
+ structure_return);
+#endif
stb = ui_out_stream_new (uiout);
ui_out_text (uiout, "Value returned is ");
ui_out_field_fmt (uiout, "gdb-result-var", "$%d", record_latest_value (value));
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 22 Jun 2002 22:39:01 -0000
@@ -24,6 +24,7 @@
#define INFERIOR_H 1
struct gdbarch;
+struct regcache;
/* For bpstat. */
#include "breakpoint.h"
@@ -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.60
diff -u -r1.60 infrun.c
--- infrun.c 22 Jun 2002 22:04:33 -0000 1.60
+++ infrun.c 22 Jun 2002 22:39:08 -0000
@@ -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,9 @@
/* 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);
+ /* NB: The copy goes through to the target picking up the value of
+ all the registers. */
+ regcache_cpy (stop_registers, current_regcache);
if (stop_stack_dummy)
{
@@ -3910,12 +3908,12 @@
CORE_ADDR step_resume_break_address;
int stop_after_trap;
int stop_soon_quietly;
- 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;
/* A frame unique identifier. */
struct frame_id selected_frame_id;
@@ -3925,24 +3923,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)
@@ -3950,7 +3930,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
@@ -3960,7 +3940,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;
@@ -3984,9 +3964,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);
get_frame_id (selected_frame, &inf_status->selected_frame_id);
return inf_status;
@@ -4033,13 +4013,16 @@
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);
+ /* NB: The register write goes through to the target. */
+ regcache_cpy (current_regcache, 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
@@ -4062,7 +4045,7 @@
}
- free_inferior_status (inf_status);
+ xfree (inf_status);
}
static void
@@ -4082,7 +4065,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 */
@@ -4173,7 +4158,7 @@
static void
build_infrun (void)
{
- stop_registers = xmalloc (REGISTER_BYTES);
+ stop_registers = regcache_xmalloc (current_gdbarch);
}
void