This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit] Prevent NULL aspace in register caches
- From: Daniel Jacobowitz <dan at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 28 Jan 2010 17:06:20 -0500
- Subject: [commit] Prevent NULL aspace in register caches
While working on ARM Linux, I started getting assertion failures after
the "return" command. This uses frame_save_as_regcache to create a
new regcache, populated with register values from the unwinder.
Unfortunately, only regcache_cpy and get_thread_arch_regcache set
the register cache's aspace, which I was later retrieving via
get_regcache_aspace.
This patch rearranges things so that you must pass an aspace
to regcache_xmalloc, which cures the problem.
The only thing of any interest here is the ppc-linux-tdep.c change.
Instead of a NULL aspace, the created regcache will now have the
previous frame's aspace. At some point, maybe we'll make each SPE a
separate aspace - at that point, this will have to change, but until
we do there's nothing to change it to.
Tested on arm-none-linux-gnueabi; checked in.
--
Daniel Jacobowitz
CodeSourcery
2010-01-28 Daniel Jacobowitz <dan@codesourcery.com>
* regcache.c (regcache_xmalloc): Add aspace argument. Use it
for the new regcache. All callers updated.
(regcache_cpy, regcache_cpy_no_passthrough): Do not set aspace here.
(get_thread_arch_regcache): Do not set aspace here.
* regcache.h (regcache_xmalloc): Update declaration.
* frame.c, infcall.c, ppc-linux-tdep.c: Calls to
regcache_xmalloc updated.
---
gdb/frame.c | 4 +++-
gdb/infcall.c | 3 ++-
gdb/ppc-linux-tdep.c | 3 ++-
gdb/regcache.c | 15 ++++++---------
gdb/regcache.h | 3 ++-
5 files changed, 15 insertions(+), 13 deletions(-)
Index: gdb-mainline/gdb/frame.c
===================================================================
--- gdb-mainline.orig/gdb/frame.c 2010-01-28 12:21:54.000000000 -0800
+++ gdb-mainline/gdb/frame.c 2010-01-28 13:06:00.000000000 -0800
@@ -682,7 +682,9 @@ do_frame_register_read (void *src, int r
struct regcache *
frame_save_as_regcache (struct frame_info *this_frame)
{
- struct regcache *regcache = regcache_xmalloc (get_frame_arch (this_frame));
+ struct address_space *aspace = get_frame_address_space (this_frame);
+ struct regcache *regcache = regcache_xmalloc (get_frame_arch (this_frame),
+ aspace);
struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
regcache_save (regcache, do_frame_register_read, this_frame);
discard_cleanups (cleanups);
Index: gdb-mainline/gdb/infcall.c
===================================================================
--- gdb-mainline.orig/gdb/infcall.c 2010-01-28 12:21:54.000000000 -0800
+++ gdb-mainline/gdb/infcall.c 2010-01-28 13:06:00.000000000 -0800
@@ -998,7 +998,8 @@ When the function is done executing, GDB
and the dummy frame has already been popped. */
{
- struct regcache *retbuf = regcache_xmalloc (gdbarch);
+ struct address_space *aspace = get_regcache_aspace (stop_registers);
+ struct regcache *retbuf = regcache_xmalloc (gdbarch, aspace);
struct cleanup *retbuf_cleanup = make_cleanup_regcache_xfree (retbuf);
struct value *retval = NULL;
Index: gdb-mainline/gdb/ppc-linux-tdep.c
===================================================================
--- gdb-mainline.orig/gdb/ppc-linux-tdep.c 2010-01-28 12:21:54.000000000 -0800
+++ gdb-mainline/gdb/ppc-linux-tdep.c 2010-01-28 13:06:00.000000000 -0800
@@ -1421,7 +1421,8 @@ ppu2spu_sniffer (const struct frame_unwi
struct ppu2spu_cache *cache
= FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
- struct regcache *regcache = regcache_xmalloc (data.gdbarch);
+ struct address_space *aspace = get_frame_address_space (this_frame);
+ struct regcache *regcache = regcache_xmalloc (data.gdbarch, aspace);
struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
regcache_save (regcache, ppu2spu_unwind_register, &data);
discard_cleanups (cleanups);
Index: gdb-mainline/gdb/regcache.c
===================================================================
--- gdb-mainline.orig/gdb/regcache.c 2010-01-28 12:21:54.000000000 -0800
+++ gdb-mainline/gdb/regcache.c 2010-01-28 13:13:12.000000000 -0800
@@ -212,7 +212,7 @@ struct regcache
};
struct regcache *
-regcache_xmalloc (struct gdbarch *gdbarch)
+regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace)
{
struct regcache_descr *descr;
struct regcache *regcache;
@@ -224,7 +224,7 @@ regcache_xmalloc (struct gdbarch *gdbarc
= XCALLOC (descr->sizeof_raw_registers, gdb_byte);
regcache->register_valid_p
= XCALLOC (descr->sizeof_raw_register_valid_p, gdb_byte);
- regcache->aspace = NULL;
+ regcache->aspace = aspace;
regcache->readonly_p = 1;
regcache->ptid = minus_one_ptid;
return regcache;
@@ -358,8 +358,6 @@ regcache_cpy (struct regcache *dst, stru
gdb_assert (src != dst);
gdb_assert (src->readonly_p || dst->readonly_p);
- dst->aspace = src->aspace;
-
if (!src->readonly_p)
regcache_save (dst, do_cooked_read, src);
else if (!dst->readonly_p)
@@ -379,7 +377,6 @@ regcache_cpy_no_passthrough (struct regc
silly - it would mean that valid_p would be completely invalid. */
gdb_assert (dst->readonly_p);
- dst->aspace = src->aspace;
memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
memcpy (dst->register_valid_p, src->register_valid_p,
dst->descr->sizeof_raw_register_valid_p);
@@ -389,7 +386,7 @@ struct regcache *
regcache_dup (struct regcache *src)
{
struct regcache *newbuf;
- newbuf = regcache_xmalloc (src->descr->gdbarch);
+ newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src));
regcache_cpy (newbuf, src);
return newbuf;
}
@@ -398,7 +395,7 @@ struct regcache *
regcache_dup_no_passthrough (struct regcache *src)
{
struct regcache *newbuf;
- newbuf = regcache_xmalloc (src->descr->gdbarch);
+ newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src));
regcache_cpy_no_passthrough (newbuf, src);
return newbuf;
}
@@ -453,10 +450,10 @@ get_thread_arch_regcache (ptid_t ptid, s
&& get_regcache_arch (list->regcache) == gdbarch)
return list->regcache;
- new_regcache = regcache_xmalloc (gdbarch);
+ new_regcache = regcache_xmalloc (gdbarch,
+ target_thread_address_space (ptid));
new_regcache->readonly_p = 0;
new_regcache->ptid = ptid;
- new_regcache->aspace = target_thread_address_space (ptid);
gdb_assert (new_regcache->aspace != NULL);
list = xmalloc (sizeof (struct regcache_list));
Index: gdb-mainline/gdb/regcache.h
===================================================================
--- gdb-mainline.orig/gdb/regcache.h 2010-01-28 12:21:54.000000000 -0800
+++ gdb-mainline/gdb/regcache.h 2010-01-28 13:06:00.000000000 -0800
@@ -31,7 +31,8 @@ extern struct regcache *get_thread_arch_
void regcache_xfree (struct regcache *regcache);
struct cleanup *make_cleanup_regcache_xfree (struct regcache *regcache);
-struct regcache *regcache_xmalloc (struct gdbarch *gdbarch);
+struct regcache *regcache_xmalloc (struct gdbarch *gdbarch,
+ struct address_space *aspace);
/* Return REGCACHE's architecture. */