/* Register support routines for the remote server for GDB.
- Copyright (C) 2001, 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2002, 2004, 2005, 2007, 2008
+ Free Software Foundation, Inc.
This file is part of GDB.
for_each_inferior (&all_threads, regcache_invalidate_one);
}
-int
-registers_length (void)
-{
- return 2 * register_bytes;
-}
-
void *
new_register_cache (void)
{
struct inferior_regcache_data *regcache;
- regcache = malloc (sizeof (*regcache));
+ if (register_bytes == 0)
+ return NULL; /* The architecture hasn't been initialized yet. */
+
+ regcache = xmalloc (sizeof (*regcache));
/* Make sure to zero-initialize the register cache when it is created,
in case there are registers the target never fetches. This way they'll
read as zero instead of garbage. */
- regcache->registers = calloc (1, register_bytes);
+ regcache->registers = xcalloc (1, register_bytes);
if (regcache->registers == NULL)
fatal ("Could not allocate register cache.");
struct inferior_regcache_data *regcache
= (struct inferior_regcache_data *) regcache_p;
- free (regcache->registers);
- free (regcache);
+ if (regcache)
+ {
+ free (regcache->registers);
+ free (regcache);
+ }
+}
+
+static void
+realloc_register_cache (struct inferior_list_entry *thread_p)
+{
+ struct thread_info *thread = (struct thread_info *) thread_p;
+
+ free_register_cache (inferior_regcache_data (thread));
+ set_inferior_regcache_data (thread, new_register_cache ());
}
void
}
register_bytes = offset / 8;
+
+ /* Make sure PBUFSIZ is large enough to hold a full register packet. */
+ if (2 * register_bytes + 32 > PBUFSIZ)
+ fatal ("Register packet size exceeds PBUFSIZ.");
+
+ /* Re-allocate all pre-existing register caches. */
+ for_each_inferior (&all_threads, realloc_register_cache);
}
void