This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[02/03] Make regcache->aspace never NULL


Hi,

currently it was not fatal to leave regcache->aspace as NULL.  With patch
[03/03] it is fatal and it may not be safe there to ignore NULL aspace.

frame_save_as_regcache had to be moved as the regcache struct is private for
regcache.c

Regression tested with [01/03] on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu.


Thanks,
Jan


2010-01-10  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* frame.c (do_frame_register_read, frame_save_as_regcache): Move to ...
	* regcache.c (do_frame_register_read, frame_save_as_regcache): ... this
	file and set REGCACHE->ASPACE here.
	(regcache_cpy, regcache_cpy_no_passthrough): New assert for SRC->ASPACE.
	* frame.h (frame_save_as_regcache): Move to ...
	* regcache.h (frame_save_as_regcache): ... this file.

	* procfs.c (insert_dbx_link_bpt_in_file): Pass aspace to
	deprecated_insert_raw_breakpoint.
	* rs6000-nat.c (exec_one_dummy_insn): New variable aspace, pass it to
	deprecated_insert_raw_breakpoint.

--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -673,22 +673,6 @@ get_frame_func (struct frame_info *this_frame)
   return next_frame->prev_func.addr;
 }
 
-static int
-do_frame_register_read (void *src, int regnum, gdb_byte *buf)
-{
-  return frame_register_read (src, regnum, buf);
-}
-
-struct regcache *
-frame_save_as_regcache (struct frame_info *this_frame)
-{
-  struct regcache *regcache = regcache_xmalloc (get_frame_arch (this_frame));
-  struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
-  regcache_save (regcache, do_frame_register_read, this_frame);
-  discard_cleanups (cleanups);
-  return regcache;
-}
-
 void
 frame_pop (struct frame_info *this_frame)
 {
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -593,9 +593,6 @@ extern void *frame_obstack_zalloc (unsigned long size);
 #define FRAME_OBSTACK_ZALLOC(TYPE) ((TYPE *) frame_obstack_zalloc (sizeof (TYPE)))
 #define FRAME_OBSTACK_CALLOC(NUMBER,TYPE) ((TYPE *) frame_obstack_zalloc ((NUMBER) * sizeof (TYPE)))
 
-/* Create a regcache, and copy the frame's registers into it.  */
-struct regcache *frame_save_as_regcache (struct frame_info *this_frame);
-
 extern struct block *get_frame_block (struct frame_info *,
                                       CORE_ADDR *addr_in_block);
 
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -5690,7 +5690,8 @@ insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
     {
       /* Insert the breakpoint.  */
       dbx_link_bpt_addr = sym_addr;
-      dbx_link_bpt = deprecated_insert_raw_breakpoint (target_gdbarch, NULL,
+      dbx_link_bpt = deprecated_insert_raw_breakpoint (target_gdbarch,
+						  current_program_space->aspace,
 						       sym_addr);
       if (dbx_link_bpt == NULL)
         {
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -357,6 +357,7 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
   gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
   gdb_assert (src != dst);
   gdb_assert (src->readonly_p || dst->readonly_p);
+  gdb_assert (src->aspace != NULL);
 
   dst->aspace = src->aspace;
 
@@ -378,6 +379,7 @@ regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
      move of data into the current regcache.  Doing this would be
      silly - it would mean that valid_p would be completely invalid.  */
   gdb_assert (dst->readonly_p);
+  gdb_assert (src->aspace != NULL);
 
   dst->aspace = src->aspace;
   memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
@@ -488,6 +490,22 @@ get_current_regcache (void)
   return get_thread_regcache (inferior_ptid);
 }
 
+static int
+do_frame_register_read (void *src, int regnum, gdb_byte *buf)
+{
+  return frame_register_read (src, regnum, buf);
+}
+
+struct regcache *
+frame_save_as_regcache (struct frame_info *this_frame)
+{
+  struct regcache *regcache = regcache_xmalloc (get_frame_arch (this_frame));
+  struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
+  regcache->aspace = get_frame_address_space (this_frame);
+  regcache_save (regcache, do_frame_register_read, this_frame);
+  discard_cleanups (cleanups);
+  return regcache;
+}
 
 /* Observer for the target_changed event.  */
 
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -41,6 +41,9 @@ extern struct gdbarch *get_regcache_arch (const struct regcache *regcache);
 
 extern struct address_space *get_regcache_aspace (const struct regcache *regcache);
 
+/* Create a regcache, and copy the frame's registers into it.  */
+struct regcache *frame_save_as_regcache (struct frame_info *this_frame);
+
 /* Transfer a raw register [0..NUM_REGS) between core-gdb and the
    regcache. */
 
--- a/gdb/rs6000-nat.c
+++ b/gdb/rs6000-nat.c
@@ -582,6 +582,7 @@ exec_one_dummy_insn (struct regcache *regcache)
 #define	DUMMY_INSN_ADDR	AIX_TEXT_SEGMENT_BASE+0x200
 
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct address_space *aspace = get_regcache_aspace (regcache);
   int ret, status, pid;
   CORE_ADDR prev_pc;
   void *bp;
@@ -590,7 +591,7 @@ exec_one_dummy_insn (struct regcache *regcache)
      assume that this address will never be executed again by the real
      code. */
 
-  bp = deprecated_insert_raw_breakpoint (gdbarch, NULL, DUMMY_INSN_ADDR);
+  bp = deprecated_insert_raw_breakpoint (gdbarch, aspace, DUMMY_INSN_ADDR);
 
   /* You might think this could be done with a single ptrace call, and
      you'd be correct for just about every platform I've ever worked


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