From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86247 invoked by alias); 12 Apr 2017 00:24:55 -0000 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 Received: (qmail 86209 invoked by uid 89); 12 Apr 2017 00:24:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS,UNSUBSCRIBE_BODY autolearn=ham version=3.3.2 spammy=tiny X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Apr 2017 00:24:53 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A0E43C04B948 for ; Wed, 12 Apr 2017 00:24:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A0E43C04B948 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sergiodj@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A0E43C04B948 Received: from localhost (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7718518F00; Wed, 12 Apr 2017 00:24:53 +0000 (UTC) From: Sergio Durigan Junior To: Pedro Alves Cc: GDB Patches Subject: Re: [PATCH v5 3/5] C++-fy and prepare for sharing fork_inferior References: <1482464361-4068-1-git-send-email-sergiodj@redhat.com> <20170330014915.4894-1-sergiodj@redhat.com> <20170330014915.4894-4-sergiodj@redhat.com> Date: Wed, 12 Apr 2017 00:24:00 -0000 In-Reply-To: (Pedro Alves's message of "Fri, 7 Apr 2017 19:30:14 +0100") Message-ID: <877f2q3223.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00303.txt.bz2 On Friday, April 07 2017, Pedro Alves wrote: > On 03/30/2017 02:49 AM, Sergio Durigan Junior wrote: >> As a preparation for the next patch, which will move fork_inferior >> from GDB to common/ (and therefore share it with gdbserver), it is >> interesting to convert a few functions to C++. > > I've meanwhile realized that fork_inferior should move to "nat/", > not "common/" ... This is code only used by the native targets. > Sorry for not pointing it out sooner... :-/. Alright. I'll address that in the next version, thanks for the heads-up. I won't rename the file in this case, leaving it as "nat/fork-child.c". >> This patch touches functions related to parsing command-line arguments >> to the inferior (see gdb/fork-child.c:breakup_args), the way the >> arguments are stored on fork_inferior (using std::vector instead of >> char **), and the code responsible for dealing with argv also on >> gdbserver. >> >> I've taken this opportunity and decided to constify a few arguments to >> fork_inferior/create_inferior as well, in order to make the code >> cleaner. And now, on gdbserver, we're using xstrdup everywhere and >> aren't checking for memory allocation failures anymore, as requested >> by Pedro. > > It'd be good to say here _why_ that's the right thing to do. Sure, I'll copy-and-adjust your rationale from the last message. > I.e., write to the future hacker doing archaeology. > >> --- a/gdb/fork-child.c >> +++ b/gdb/fork-child.c >> @@ -1,4 +1,4 @@ >> -/* Fork a Unix child process, and set up to debug it, for GDB. >> + /* Fork a Unix child process, and set up to debug it, for GDB. > > Spurious whitespace change. Fixed. >> static void >> -breakup_args (char *scratch, char **argv) >> +breakup_args (const std::string &scratch, std::vector &argv) >> { > > ... > >> + >> + std::string arg = scratch.substr (cur_pos, next_sep - cur_pos); >> + > > This creates a temporary string (heap allocates) ... > >> + argv.push_back (xstrdup (arg.c_str ())); > > ... and here you create yet another copy. > > You should be able to avoid it by using e.g., savestring: > > char *arg = savestring (scratch.c_str () + cur_pos, next_sep - cur_pos); > argv.push_back (arg); Fair enough. I had my mind on "C++-only mode" when writing this code. >> + >> + cur_pos = next_sep; >> } >> >> - /* Null-terminate the vector. */ >> - *argv = NULL; >> + /* NULL-terminating the vector. */ > > FYI, the non-gerund version of the text reads as more > natural English to me. Reverted. >> + argv.push_back (NULL); >> } >> > > >> --- a/gdb/go32-nat.c >> +++ b/gdb/go32-nat.c >> @@ -631,8 +631,9 @@ go32_kill_inferior (struct target_ops *ops) >> } >> >> static void >> -go32_create_inferior (struct target_ops *ops, char *exec_file, >> - char *args, char **env, int from_tty) >> +go32_create_inferior (struct target_ops *ops, >> + const char *exec_file, >> + const std::string &allargs, char **env, int from_tty) >> { >> extern char **environ; >> jmp_buf start_state; >> @@ -641,6 +642,7 @@ go32_create_inferior (struct target_ops *ops, char *exec_file, >> size_t cmdlen; >> struct inferior *inf; >> int result; >> + char *args = (char *) allargs.c_str (); > > AFAICS, this could be const. Right, fixed. > Note that when you really need to append a single character, > it's a tiny bit more efficient to write what you mean: > > shell_command += ' '; > > instead of appending a string that happens to have one character: > > + shell_command += " "; > + shell_command += "'"; > > because the later means you're calling the operator+= overload that > needs to handle / count the string length. > > > I saw a few of those in the patch. Hm, indeed. Fixed. > Anyway, with those addressed and with any missing xstrdup > that -Wwrite-string may have flagged added, this is good to > go. > > I believe this stands on its own and doesn't have any dependency > on the previous patches, so please go ahead and push. OK, thanks. I'll work on patch 1/5 and get that out of the way first, and the I'll push this in. Thanks! -- Sergio GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36 Please send encrypted e-mail if possible http://sergiodj.net/