From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id hVLTEA//yWgJQAcAWB0awg (envelope-from ) for ; Tue, 16 Sep 2025 20:21:35 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=aCYAr9dW; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2EEEE1E0BA; Tue, 16 Sep 2025 20:21:35 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 84C721E047 for ; Tue, 16 Sep 2025 20:21:34 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C35FC3858C62 for ; Wed, 17 Sep 2025 00:21:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C35FC3858C62 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=aCYAr9dW Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 2F2C13858D33 for ; Wed, 17 Sep 2025 00:19:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F2C13858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2F2C13858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758068354; cv=none; b=oZMj8GgI5OELk/9qhkzmMOYuqurXaC/q+OCg3L+kWMuAuPn+Ir3vwG3d9+ZiyCyDLIuSLbzZ+ii1cLYUoRjRhGBNVJV1fO0LV0pcuD+HXXs/X6e8+8lklDJ2I2A/c0YA2qsimn9IObI7IV5qjnOW16scYP6LgwBuwttTaVuULYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758068354; c=relaxed/simple; bh=9J2uzGA+SS58jabeBKD2ce46WfSb6DYIK51n0D1UQ/0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=fh50G3cqCLJ9SGRxz7nkU3hYIq0HMegraAres5b18GDwKaj2sTGu+Sz5Drz1eu8QcUBvTiF/bSSwznqXUbL2g5pnlxQg1UA4geOwP7nnuq/XTgGScMT2QND9qy7z4kRTyvObCUhvpct9SZr3YpDyV4pgYt+KJrs8pj2g6lQUloU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F2C13858D33 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3ec4d6ba12eso990864f8f.1 for ; Tue, 16 Sep 2025 17:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758068353; x=1758673153; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=X5hzKorben35tEVGh4E0UZBaS/QAtowLsLFT6kKE86c=; b=aCYAr9dWFdTfa8+XVBzYPYC6Tez8IFmN1WThdDcDjNbLjYQ+ca4coCmmiL1gHVBeAx HxpoAZJn54Cyay8UPRqd/uguioUidAFOxD3LkP0Wxw4zD7Sfue0kGT65QXGN6Tcshja/ n2DVwvJ8Dk++DTjNH7611j85CwSQDG4c6XShHrvDhGF5fgjFPYN0q73Jw+G7d3Bb7Rhj XRKYjtaB85Z7v+1wtEZpaR3XkoRpJhtJCipsEKw/pBS+lAlhFOkQAOIeDIflzLP+sbgg MLb7f51LsN2hgNVpU4apLphlax0Zx8+HSnmlx1S3CHdpRNkhb8m4+sdllvtCgOtlEamq m9Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758068353; x=1758673153; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X5hzKorben35tEVGh4E0UZBaS/QAtowLsLFT6kKE86c=; b=sZqGvxXHfqvjG1PLyxEw1u6q0KJ0KIypuvqwgYkrK/oF7cIfuRt6ZD9Tf8d8Z9Qzus 9cnrcgCOVdMKG11sdgDtOR3YqhB9JsfZyFMeR/sCHEoEBTvU4q0RbraZ+TM7HrfM6k3T /dHIJ4VScOH4u9XVsDQZL5+YavnzZHKr69dwUe0Go3t1OvphHNXgFN3dS/P8bRza1sHv 5hgrrmvTJpa9ulINdZik2UHYl718q4lQ/Ji472yhm61/qTZhlz6t5aIVrXwUoVvwOMaH X0MvfSH9ZTZbxuyisLxSVA65A6gOqV5w81w+Sx6cfN/s63R1f8qtsSk3GVqT7+ACerwq G94g== X-Forwarded-Encrypted: i=1; AJvYcCUeNUe0OJNuAy17s2Q1Mqa+G6uwAkcj1EiN5tlh5y+UiRqRFeoibAndjk8PP1pZ7QKZJKurvEmHi6VDGQ==@sourceware.org X-Gm-Message-State: AOJu0YzE0jXD8nR+/lZR9WVb9bl0eaf17172OLloCnConNDN5wQaQ3Lb AFb8ia4jpti5UkUgnRw3XAFoudNaPnp5PKkzL5LLZ7QSPAubPF47gDak X-Gm-Gg: ASbGncsxlXA+S1YZv6fO1tdSZAkUEJ9uIvpPKkDRbrgXM7LRMyfGSN/cuYwoxOP9S8M qdWVq3J5WWnhao/zk0DYhs5+JfmYA+wG+NMuz7Mvnc5LsfMTQcrYE8B+tBScGilntQ+0EQAr8HS IBW55Oqye3S/zoKExQAYs3nt9ysfbHIvuX3Wb+wOK5tNcCquciK8SIP0nSK/2zIVhL2pqbWU47v wxnReUI94n1qzdjOojlKTPP29VnwZ3NPG3x7Lou5SHi4J7SJM4CjJm9UCkaMh4n5csiEmw36Jfn xAzEFNymYfJfk/kAZD80dthojgalpsBHn/UX7ObteF2Aot42t73ohQZeYv8byfuQwonFWcXuH8C v9D3/RWmfflzP46cRLMs1tIS57/x+BEdUVR0= X-Google-Smtp-Source: AGHT+IHK2M19fc4THi+nURp1MGigZ8Tvfdsb1rhg0Felg6BJK7CHb0ZHO+7yCAqLiEI5PiBOdYN4Hg== X-Received: by 2002:a05:6000:2313:b0:3ea:2ed6:9e37 with SMTP id ffacd0b85a97d-3ecdf9e50fcmr166597f8f.24.1758068352590; Tue, 16 Sep 2025 17:19:12 -0700 (PDT) Received: from [192.168.0.38] ([86.12.216.189]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3e8237cfdddsm17177052f8f.60.2025.09.16.17.19.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Sep 2025 17:19:12 -0700 (PDT) Message-ID: Date: Wed, 17 Sep 2025 01:19:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb/gdbserver: pass inferior arguments as a single string Content-Language: en-US To: Andrew Burgess Cc: Kevin Buettner , gdb-patches@sourceware.org, Michael Weghorn , Eli Zaretskii , Guinevere Larsen References: <20250624145052.4659642b@f41-zbm-amd> <874it8htc2.fsf@redhat.com> <87ikhigygr.fsf@redhat.com> From: Luis In-Reply-To: <87ikhigygr.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 16/09/2025 17:21, Andrew Burgess wrote: > Luis writes: > >> I think I'm running into a change in behavior for --args, where it now says >> no program was specified when previously it was ok. >> >> Just a standard.... >> >> ./gdb/gdb -ex run --args gdb/gdb gdb/gdb -ex start >> >> Did something change in terms of invocation format? > > Here's a proper fix, with tests. > > Let me know what you think. > > Thanks, > Andrew > > --- > > commit 5dfd9f9da130c5deae9ac81fcda1bd18f8951eac > Author: Andrew Burgess > Date: Tue Sep 16 17:02:01 2025 +0100 > > gdb: fix --args handling when inferior argument have dash > > After the commit: > > commit e5e76451fa82e0bc00599af96382b361c3d6ac32 > Date: Fri Oct 22 07:19:29 2021 +0000 > > gdb/gdbserver: add a '--no-escape-args' command line option > > Inferior argument handling on the GDB command line was broken: > > $ gdb --args /bin/ls --foo > ./gdb/gdb: unrecognized option '--foo' > ./gdb/gdb: `--args' specified but no program specified > > Before the above patch the definition of the '--args' argument in the > long_options array (in captured_main_1) was such that the > getopt_long_only call would directly set the 'set_args' variable to > true if '--args' was seen. > > This meant that, immediately after the getopt_long_only call, we could > inspect set_args and break out of the argument processing loop if > needed. > > After the above patch '--args' (and the new '--no-escape-args') no > longer set set_args directly via the getopt_long_only call. Instead > the getopt_long_only call returns an OPT_* enum value, which we then > use in the following switch statement in order to set the set_args > variable. > > What this means is that, immediately after the getopt_long_only call, > set_args no longer (immediately) indicates if --args was seen. After > the switch statement, when set_args has been updated, we go around the > argument processing loop again and call getopt_long_only once more. > > This extra getopt_long_only call will, if it finds another argument > that starts with a dash, update the global optind to point to this > option. At this point things have gone wrong, GDB has now lost track > of the argument containing the program name the user wanted us to > start. This leads to GDB existing with the above error. s/existing/exiting? > > The solution is to move the check of set_args to either before the > getopt_long_only call, or to after the switch statement. I chose to > move it earlier as this keeps all the loop exiting checks near the > beginning. > > I've added more tests that cover this issue. > > diff --git a/gdb/main.c b/gdb/main.c > index 04c33638bec..f3049600a06 100644 > --- a/gdb/main.c > +++ b/gdb/main.c > @@ -866,9 +866,14 @@ captured_main_1 (struct captured_main_args *context) > { > int option_index; > > + /* If the previous argument was --args or --no-escape-args, then > + stop argument processing. */ > + if (set_args != NO_ARGS) > + break; > + > c = getopt_long_only (argc, argv, "", > long_options, &option_index); > - if (c == EOF || set_args != NO_ARGS) > + if (c == EOF) > break; > > /* Long option that takes an argument. */ > diff --git a/gdb/testsuite/gdb.base/args.exp b/gdb/testsuite/gdb.base/args.exp > index 573543cc1f8..03e5e57ee20 100644 > --- a/gdb/testsuite/gdb.base/args.exp > +++ b/gdb/testsuite/gdb.base/args.exp > @@ -186,6 +186,18 @@ proc run_all_tests {} { > set ::env(TEST) "ABCD" > args_test "shell variable" {{$TEST}} {\\$TEST} {{ABCD}} > } > + > + # At one point we had a bug where, if the last inferior argument, > + # appearing after --args, looked like an option GDB might be able > + # to process, e.g. started with a dash, then GDB would try to > + # process it. This would mean all leave GDB in a broken state, Maybe a typo in "mean all". It doesn´t sound clear to me. Maybe you meant "we'll"? If you think it is worth it, we could mention the specific example of the invocation that ran into issues. > + # and so GDB would fail to start. > + foreach_with_prefix flag { args no-escape-args } { > + args_test "with trailing GDB flag" [list "--${flag}"] > + } > + args_test "with trailing GDB option and value" [list "--ex" "start"] > + args_test "with trailing double dash option" [list "--foo"] > + args_test "with trailing single dash option" [list "-foo"] > } > > run_all_tests > Thanks. The above fixed it for me. Approved-By: Luis Machado Tested-By: Luis Machado