From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5705 invoked by alias); 24 Nov 2008 17:32:26 -0000 Received: (qmail 5601 invoked by uid 22791); 24 Nov 2008 17:32:25 -0000 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 24 Nov 2008 17:31:45 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 06D5410D50; Mon, 24 Nov 2008 17:31:36 +0000 (GMT) Received: from caradoc.them.org (209.195.188.212.nauticom.net [209.195.188.212]) by nan.false.org (Postfix) with ESMTP id D7D2110AD3; Mon, 24 Nov 2008 17:31:35 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.69) (envelope-from ) id 1L4fHb-0002Sh-6A; Mon, 24 Nov 2008 12:31:35 -0500 Date: Mon, 24 Nov 2008 20:11:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org, Pedro Alves Subject: [patch] Fix gdbserver vRun parsing again Message-ID: <20081124173135.GA9091@caradoc.them.org> Mail-Followup-To: gdb-patches@sourceware.org, Pedro Alves MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.17 (2008-05-11) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-11/txt/msg00650.txt.bz2 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 * 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')