This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit] Fix another corruption in remote.c
- From: Daniel Jacobowitz <drow at false dot org>
- To: gdb-patches at sourceware dot org
- Date: Thu, 5 Oct 2006 15:24:01 -0400
- Subject: [commit] Fix another corruption in remote.c
I'm still glad I switched remote.c away from using alloca - it really needed
doing - but I keep running into unforeseen problems :-( I've done as
thorough an audit as I can, and this is the only remaining one I know of.
The problem arises in set_thread:
xsnprintf (&buf[2], get_remote_packet_size () - 2, "-%x", -th);
The call to get_remote_packet_size fetches the architecture-specific gdbarch
data. Because the gdbarch data mechanism isn't set up to initialize
immediately on creation of the gdbarch, but lazily at first access, which
this is after remote_open_1 is called, this line triggers an unexpected call
to init_remote_state which in turn may change rs->buf.
So, let's make sure that when we get access to rs->buf the architecture is
always set up.
Tested x86_64-pc-linux-gnu and committed.
--
Daniel Jacobowitz
CodeSourcery
2006-10-05 Daniel Jacobowitz <dan@codesourcery.com>
* remote.c (get_remote_state_raw): Renamed from get_remote_state.
(get_remote_state): New function.
(init_remote_state, _initialize_remote): Use get_remote_state_raw.
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.230
diff -u -p -r1.230 remote.c
--- remote.c 22 Sep 2006 13:50:36 -0000 1.230
+++ remote.c 5 Oct 2006 19:14:01 -0000
@@ -244,7 +244,7 @@ struct remote_state
static struct remote_state remote_state;
static struct remote_state *
-get_remote_state (void)
+get_remote_state_raw (void)
{
return &remote_state;
}
@@ -294,11 +294,26 @@ get_remote_arch_state (void)
return gdbarch_data (current_gdbarch, remote_gdbarch_data_handle);
}
+/* Fetch the global remote target state. */
+
+static struct remote_state *
+get_remote_state (void)
+{
+ /* Make sure that the remote architecture state has been
+ initialized, because doing so might reallocate rs->buf. Any
+ function which calls getpkt also needs to be mindful of changes
+ to rs->buf, but this call limits the number of places which run
+ into trouble. */
+ get_remote_arch_state ();
+
+ return get_remote_state_raw ();
+}
+
static void *
init_remote_state (struct gdbarch *gdbarch)
{
int regnum;
- struct remote_state *rs = get_remote_state ();
+ struct remote_state *rs = get_remote_state_raw ();
struct remote_arch_state *rsa;
rsa = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_arch_state);
@@ -6141,7 +6156,7 @@ _initialize_remote (void)
of these, not one per target. Only one target is active at a
time. The default buffer size is unimportant; it will be expanded
whenever a larger buffer is needed. */
- rs = get_remote_state ();
+ rs = get_remote_state_raw ();
rs->buf_size = 400;
rs->buf = xmalloc (rs->buf_size);