From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 54C8D384A034 for ; Thu, 7 May 2020 22:15:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 54C8D384A034 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.193] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id CBBF01E79B; Thu, 7 May 2020 18:15:12 -0400 (EDT) Subject: Re: [PATCH 4/4] [PR gdbserver/25893]: Add gdbserver test for argument with space in it To: Michael Weghorn , gdb-patches@sourceware.org References: <20200429111638.1327262-1-m.weghorn@posteo.de> <20200429111638.1327262-6-m.weghorn@posteo.de> From: Simon Marchi Message-ID: <1190e73a-8f10-dc6d-4d59-b9a2929530ad@simark.ca> Date: Thu, 7 May 2020 18:15:12 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200429111638.1327262-6-m.weghorn@posteo.de> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, 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: Thu, 07 May 2020 22:15:14 -0000 On 2020-04-29 7:16 a.m., Michael Weghorn via Gdb-patches wrote: > This adds a test to call gdbserver with a program > that is passed an argument containing a space and > checks that argv[1] actually contains the value > of this arg. > > gdb/testsuite/ChangeLog: > > 2020-04-29 Michael Weghorn > > PR gdbserver/25893 > * gdb.server/arg-with-space.exp: New test that > covers running program with arg containing > a space with gdbserver > --- > gdb/testsuite/gdb.server/arg-with-space.exp | 41 +++++++++++++++++++++ > 1 file changed, 41 insertions(+) > create mode 100644 gdb/testsuite/gdb.server/arg-with-space.exp > > diff --git a/gdb/testsuite/gdb.server/arg-with-space.exp b/gdb/testsuite/gdb.server/arg-with-space.exp > new file mode 100644 > index 0000000000..d768b7ca0f > --- /dev/null > +++ b/gdb/testsuite/gdb.server/arg-with-space.exp > @@ -0,0 +1,41 @@ > +# This testcase is part of GDB, the GNU debugger. > +# > +# Copyright 2020 Free Software Foundation, Inc. > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Test gdbserver to properly handle a program arg with a space in it > +# as a single argument. > + > +load_lib gdbserver-support.exp > + > +standard_testfile "normal.c" > + > +if {[skip_gdbserver_tests]} { > + return 0 > +} > + > +if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { > + return -1 > +} > +clean_restart ${testfile} > + > +gdbserver_run "\"hello world\"" > + > +gdb_breakpoint main > +gdb_continue main > + > +# check that program arg was passed properly > +gdb_test "print argc" "2" > +gdb_test "print argv\[1\]" "\"hello world\"" > -- > 2.26.2 > It would be nice to write a test in such a way that it can cover this use case when using GDB (without GDBserver) too. It's possible to run the same test using plain GDB with: make check TESTS="gdb.base/foo.exp" or make check TESTS="gdb.base/foo.exp" RUNTESTFLAGS="--target_board=unix" unix is the default DejaGNU (runtest) board, so these two are equivalent. It's also possible to run a test using gdbserver as a target: make check TESTS="gdb.base/foo.exp" RUNTESTFLAGS="--target_board=native-gdbserver" make check TESTS="gdb.base/foo.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver" So it should be possible to write a test that runs a process with arguments containing spaces. However, it's not currently possible with the testsuite to pass arguments to a test program using the native-gdbserver board. These arguments would have to be forwarded all the way to gdbserver's command line, exactly like when you start gdbserver by hand. This will require a bit of testsuite refactoring, I'll try to look into it. With native-extended-gdbserver, the args could be passed to the `run` command, just like the native debugging case. It's by playing with this that I noticed gdbserver crashing with this patchset applied when trying to remotely run a process with arguments. Simon