From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by sourceware.org (Postfix) with ESMTPS id BC2A6388A811 for ; Wed, 13 May 2020 09:58:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BC2A6388A811 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 96EF416005F for ; Wed, 13 May 2020 11:58:10 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 49MVVB0tzkz6tmQ; Wed, 13 May 2020 11:58:10 +0200 (CEST) Subject: Re: [PATCH v3 5/6] [PR gdbserver/25893]: Use construct_inferior_arguments which handles special chars To: Simon Marchi , gdb-patches@sourceware.org References: <20200429111638.1327262-1-m.weghorn@posteo.de> <20200512154211.1311364-1-m.weghorn@posteo.de> <20200512154211.1311364-5-m.weghorn@posteo.de> <75e9c38c-9e19-4c2a-7512-47f74890eb3e@simark.ca> <3f61a671-760d-6556-7895-090de6f5a1bf@simark.ca> From: Michael Weghorn Message-ID: <35cf59d3-5522-6d06-544c-fa16459ec4bb@posteo.de> Date: Wed, 13 May 2020 11:58:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <3f61a671-760d-6556-7895-090de6f5a1bf@simark.ca> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 May 2020 09:58:13 -0000 On 13/05/2020 02.54, Simon Marchi wrote: > On 2020-05-12 8:52 p.m., Simon Marchi wrote: >> On 2020-05-12 11:42 a.m., Michael Weghorn via Gdb-patches wrote: >>> Use the construct_inferior_arguments function instead of >>> stringify_argv to construct a string from the program >>> arguments in those places where that one is then passed >>> to fork_inferior (linux-low, lyn-low), since >>> construct_inferior_arguments properly takes care of >>> special characters, while stringify_argv does not. >>> Using construct_inferior_arguments seems "natural", since its >>> documentation also mentions that it "does the >>> same shell processing as fork_inferior". >>> >>> Since construct_inferior_args has been extended to do >>> proper quoting for Windows shells in commit >>> 5d60742e2dd3c9b475dce54b56043a358751bbb8 >>> ("Fix quoting of special characters for the MinGW build.", >>> 2012-06-12), use it for the Windows case as well. >>> (I could not test that case myself, though.) >>> >>> Adapt handling of empty args in function 'handle_v_run' >>> in gdbserver/server.cc to just insert an empty string >>> for an empty arg, since that one is now properly handled >>> in 'construct_inferior_arguments' already (and inserting >>> a "''" string in 'handle_v_run' would otherwise >>> cause that one to be treated as a string literally >>> containing two quote characters, which >>> 'construct_inferior_args' would preserve by adding >>> extra escaping). >>> >>> This makes gdbserver properly handle program args containing special >>> characters (like spaces), e.g. (example from PR25893) >>> >>> $ gdbserver localhost:50505 myprogram "hello world" >>> >>> now properly handles "hello world" as a single arg, not two separate >>> ones ("hello", "world"). >>> >>> 2020-05-12 Michael Weghorn >>> >>> PR gdbserver/25893 >>> * linux-low.cc (linux_process_target::create_inferior), >>> lynx-low.cc (lynx_process_target::create_inferior), >>> win32-low.cc (win32_process_target::create_inferior): Use >>> construct_inferior_arguments instead of stringify_argv >>> to get string representation which properly escapes >>> special characters. >>> * server.cc (handle_v_run): Just pass empty program arg >>> as such, since any further processing is now handled via >>> construct_inferior_arguments >> >> This patch LGTM. >> >> Simon >> > > I forgot to mention, I built this on mingw-w64 and confirmed that it > fixed the same problem. It also handles empty arguments correctly, both > on gdbserver's command line and "run". > > Unfortunately, I wasn't able to run my test case, but that's because of > separate issues. Thanks a lot for testing it actually works and all reviewing! Michael