Re: Multiplexed registers and invalidating the register cache

Orjan Friberg
2004-04-23T15:20:37Z

Andrew Cagney wrote:
> Yes, on all counts!

Wohoo! Patches below:

2004-04-23 Orjan Friberg <orjanf@axis.com>

* observer.texi (GDB Observers): Add target_changed event.

Index: doc/observer.texi
===================================================================
RCS file: /cvs/src/src/gdb/doc/observer.texi,v
retrieving revision 1.3
diff -u -p -r1.3 observer.texi
--- doc/observer.texi 15 Apr 2004 14:29:21 -0000 1.3
+++ doc/observer.texi 23 Apr 2004 15:02:02 -0000
@@ -73,3 +73,7 @@ The following observable events are defi
@deftypefun void normal_stop (struct bpstats *@var{bs})
The inferior has stopped for real.
@end deftypefun
+
+@deftypefun void target_changed (struct target_ops *@var{current_target})
+The target's register contents has changed.
+@end deftypefun

2004-04-23 Orjan Friberg <orjanf@axis.com>

* frame.c: Include "observer.h".
(frame_observer_target_changed): New function.
(_initialize_frame): Attach target_changed observer.
* regcache.c: Include "observer.h".
(regcache_observer_target_changed): New function.
(_initialize_regcache): Attach target_changed observer.
* valops.c: Include "observer.h".
(value_assign): Notify target_changed event when modifying register.

Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.172
diff -u -p -r1.172 frame.c
--- frame.c 21 Apr 2004 23:52:20 -0000 1.172
+++ frame.c 23 Apr 2004 15:17:59 -0000
@@ -39,6 +39,7 @@
#include "frame-base.h"
#include "command.h"
#include "gdbcmd.h"
+#include "observer.h"

static struct frame_info *get_prev_frame_1 (struct frame_info *this_frame);

@@ -1237,6 +1238,14 @@ get_next_frame (struct frame_info *this_
return NULL;
}

+/* Observer for the target_changed event. */
+
+void
+frame_observer_target_changed (struct target_ops *current_target)
+{
+ flush_cached_frames ();
+}
+
/* Flush the entire frame cache. */

void
@@ -2355,6 +2364,8 @@ void
_initialize_frame (void)
{
obstack_init (&frame_cache_obstack);
+
+ observer_attach_target_changed (frame_observer_target_changed);

add_prefix_cmd ("backtrace", class_maintenance, set_backtrace_cmd, "\
Set backtrace specific variables.\n\
Index: regcache.c
===================================================================
RCS file: /cvs/src/src/gdb/regcache.c,v
retrieving revision 1.112
diff -u -p -r1.112 regcache.c
--- regcache.c 21 Apr 2004 23:52:20 -0000 1.112
+++ regcache.c 23 Apr 2004 15:17:59 -0000
@@ -30,6 +30,7 @@
#include "gdb_assert.h"
#include "gdb_string.h"
#include "gdbcmd.h" /* For maintenanceprintlist. */
+#include "observer.h"

/*
* DATA STRUCTURE
@@ -566,6 +567,14 @@ real_register (int regnum)
return regnum >= 0 && regnum < NUM_REGS;
}

+/* Observer for the target_changed event. */
+
+void
+regcache_observer_target_changed (struct target_ops *current_target)
+{
+ registers_changed ();
+}
+
/* Low level examining and depositing of registers.

The caller is responsible for making sure that the inferior is
@@ -1696,6 +1705,8 @@ _initialize_regcache (void)
DEPRECATED_REGISTER_GDBARCH_SWAP (deprecated_registers);
DEPRECATED_REGISTER_GDBARCH_SWAP (deprecated_register_valid);
deprecated_register_gdbarch_swap (NULL, 0, build_regcache);
+
+ observer_attach_target_changed (regcache_observer_target_changed);

add_com ("flushregs", class_maintenance, reg_flush_command,
"Force gdb to flush its register cache (maintainer command)");
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.123
diff -u -p -r1.123 valops.c
--- valops.c 21 Apr 2004 23:52:21 -0000 1.123
+++ valops.c 23 Apr 2004 15:18:00 -0000
@@ -42,6 +42,7 @@
#include "gdb_string.h"
#include "gdb_assert.h"
#include "cp-support.h"
+#include "observer.h"

extern int overload_debug;
/* Local functions. */
@@ -701,6 +702,7 @@ value_assign (struct value *toval, struc
if (deprecated_register_changed_hook)
deprecated_register_changed_hook (-1);
target_changed_event ();
+ observer_notify_target_changed (current_target);
break;
}

--
Orjan Friberg
Axis Communications