This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] Fix gdbserver vRun parsing again
- From: Daniel Jacobowitz <drow at false dot org>
- To: gdb-patches at sourceware dot org, Pedro Alves <pedro at codesourcery dot com>
- Date: Mon, 24 Nov 2008 12:31:35 -0500
- Subject: [patch] Fix gdbserver vRun parsing again
As part of closing PR 2474, I took another look at Pedro's fix last
month to vRun. I approved it at the time but now I can see that he
and I were both a little confused about the documented semantics :-(
With Pedro's patch, "target extended-remote", "run one", "run two"
will never run the program with argv[1] == "two". We're always
supposed to use the new argv. "vRun;" means "old program, no args";
"vRun;;XXXX" means "old program, decoded arg XXXX".
This patch seems to do the right thing; Pedro, want to take a look at
this obviously tricky code before I change it?
--
Daniel Jacobowitz
CodeSourcery
2008-11-24 Daniel Jacobowitz <dan@codesourcery.com>
* server.c (handle_v_run): Always use the supplied argument list.
Index: server.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.c,v
retrieving revision 1.79
diff -u -p -r1.79 server.c
--- server.c 10 Oct 2008 14:06:05 -0000 1.79
+++ server.c 24 Nov 2008 17:24:44 -0000
@@ -1071,7 +1071,7 @@ handle_v_run (char *own_buf, char *statu
new_argc++;
}
- new_argv = malloc ((new_argc + 2) * sizeof (char *));
+ new_argv = calloc (new_argc + 2, sizeof (char *));
i = 0;
for (p = own_buf + strlen ("vRun;"); *p; p = next_p)
{
@@ -1096,10 +1096,8 @@ handle_v_run (char *own_buf, char *statu
if (new_argv[0] == NULL)
{
- /* GDB didn't specify a program to run. Try to use the argv
- from the last run: either from the last vRun with a non-empty
- argv, or from what the user specified if gdbserver was
- started as: `gdbserver :1234 PROG ARGS'. */
+ /* GDB didn't specify a program to run. Use the program from the
+ last run with the new argument list. */
if (program_argv == NULL)
{
@@ -1107,20 +1105,17 @@ handle_v_run (char *own_buf, char *statu
return 0;
}
- /* We can reuse the old args. We don't need this then. */
- free (new_argv);
+ new_argv[0] = strdup (program_argv[0]);
}
- else
+
+ /* Free the old argv. */
+ if (program_argv)
{
- /* Free the old argv. */
- if (program_argv)
- {
- for (pp = program_argv; *pp != NULL; pp++)
- free (*pp);
- free (program_argv);
- }
- program_argv = new_argv;
+ for (pp = program_argv; *pp != NULL; pp++)
+ free (*pp);
+ free (program_argv);
}
+ program_argv = new_argv;
*signal = start_inferior (program_argv, status);
if (*status == 'T')