From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id J4iNBpuDOmlapzEAWB0awg (envelope-from ) for ; Thu, 11 Dec 2025 03:40:59 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=09SADF7u; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=oSCWtIXM; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=x94ETzil; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3zMeJnth; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 090DC1E048; Thu, 11 Dec 2025 03:40:59 -0500 (EST) 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,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 vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 250861E048 for ; Thu, 11 Dec 2025 03:40:53 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id A75C44BA2E28 for ; Thu, 11 Dec 2025 08:40:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A75C44BA2E28 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=09SADF7u; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=oSCWtIXM; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=x94ETzil; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3zMeJnth Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 705594BA2E20 for ; Thu, 11 Dec 2025 08:40:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 705594BA2E20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 705594BA2E20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1765442424; cv=none; b=O0NgLnhJJCM9mQjMFW6bD5aYuu/e4hi5f/27imZTE+RZLiwADM3cs9/TDautmQObmbfaXAsIbdYSfBglqw7G3VnHb3eA8bxgJs6k1B8MAyCQ4fSdjKHwfOTLriQtuzU0dLvI7MXuEH9T21RRes+h2oViuAL+NfF13/dxe0jGrT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1765442424; c=relaxed/simple; bh=WAEAfFic0CrUThrW3YhtI0WkcabPq/qdIabtor+JRMw=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=MJPpFzVjfZe2PkG+JIoh3n1s5U055NsVVm+t5mZ2pd9JPmUdJn3Mf6ayzKkWnQFfQ+4pEKMY6V5Jq1fo5CI/rfoE08yczBe7zwVktrCEX+UxA2knBh+vbjAghYIGyD0oyXpVMnae/guDN8WfpX6Rk0UHpwym1R0ULKLOTRilxAU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 705594BA2E20 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3BD2A337C6; Thu, 11 Dec 2025 08:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1765442423; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xB0j+nWk8XIi0xs81fy646wHtMvTnNrmZELQnGq8Sgk=; b=09SADF7us/pN5KjCHAeY0oft9IPwJBEckLltIKpZvotVPl53kMHIxL8OmPbTMqfaFn1j7Q K82O+QGE345kNyY/0+0a4NbciYlWFGVLtnLlarBhVypF8QJifpC7xnxXArxREsgfVg2hEU vAqSKQ4/p9x7n8k3r4w0xTy+OD/O1lg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1765442423; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xB0j+nWk8XIi0xs81fy646wHtMvTnNrmZELQnGq8Sgk=; b=oSCWtIXMJb1F7aUVpI5VYpEzY4jBSi6IDL4bvIQUbDYCMoPrLqPcjwXh9yn6L0ovfMGtNO uQIKSkfBkcN9Q1Aw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1765442422; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xB0j+nWk8XIi0xs81fy646wHtMvTnNrmZELQnGq8Sgk=; b=x94ETzilZ9zZTF020ZUlVBf8heg82q3AOXljrY3BW0zUILlOYmd7q7FI9dGS3wHGM6/BG+ C58+YHMj3IlmPSZtX+g6Pm1NVlTkCLY/ROf9HZEJ+oHSS7i/flzYYiiON1g/dAMwhEpiDu CFzZ0zpEGrKLiWLq9MMXESNVqbveqLE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1765442422; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xB0j+nWk8XIi0xs81fy646wHtMvTnNrmZELQnGq8Sgk=; b=3zMeJnthpIHQNhaqUnYBsBwtOZpYi71yExfnkqtP0zujSdU7ZK4i35zQluNi/EscOZ86my oYcoOYScomhFFtBQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 278663EA63; Thu, 11 Dec 2025 08:40:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WESAB3aDOmm6TgAAD6G6ig (envelope-from ); Thu, 11 Dec 2025 08:40:22 +0000 Message-ID: <53f7e5a1-eb5c-48e7-9b2f-2e41c9a4f5ba@suse.de> Date: Thu, 11 Dec 2025 09:40:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Fix "unset local-environment" when clearenv not available To: Tom Tromey , gdb-patches@sourceware.org References: <20251210162402.2026139-1-tromey@adacore.com> Content-Language: en-US From: Tom de Vries In-Reply-To: <20251210162402.2026139-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-4.27 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.17)[-0.830]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_MATCH_FROM(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[gdb.base:url, suse.de:mid, suse.de:email, imap1.dmz-prg2.suse.org:helo, make-check-all.sh:url] 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 12/10/25 5:24 PM, Tom Tromey wrote: > Tom de Vries pointed out that clearenv isn't available on all hosts. > Since this seems like a niche command at best, it seemed fine to > disable this command on such platforms. Hi Tom, thanks for fixing this. I've applied this patch to the cross-build setup (--host=x86_64-w64-mingw32) where I ran into this problem, and it fixes the build. I've also applied it to an x86_64-linux build, and ran the test-case using make-check-all.sh. There is one failure with remote host configuration: ... FAIL: gdb.base/local-env.exp: show environment displayed variable ... because that relies on setenv, but that's a pre-existing problem. [ I came across this here ( https://man7.org/linux/man-pages/man3/clearenv.3.html ): ... On systems where clearenv() is unavailable, the assignment environ = NULL; will probably do. ... but I think that the disable-command approach is safer. ] LGTM. Reviewed-By: Tom de Vries Thanks, - Tom > --- > gdb/config.in | 3 +++ > gdb/configure | 1 + > gdb/configure.ac | 1 + > gdb/infcmd.c | 15 ++++++++++++++- > gdb/testsuite/gdb.base/local-env.exp | 24 +++++++++++++++++++----- > 5 files changed, 38 insertions(+), 6 deletions(-) > > diff --git a/gdb/config.in b/gdb/config.in > index 9e2bba42e28..62d9e0eda6d 100644 > --- a/gdb/config.in > +++ b/gdb/config.in > @@ -110,6 +110,9 @@ > the CoreFoundation framework. */ > #undef HAVE_CFPREFERENCESCOPYAPPVALUE > > +/* Define to 1 if you have the `clearenv' function. */ > +#undef HAVE_CLEARENV > + > /* Define if compiling support to gdb compile. */ > #undef HAVE_COMPILE > > diff --git a/gdb/configure b/gdb/configure > index cc446c6e4c8..dcf4fee40dd 100755 > --- a/gdb/configure > +++ b/gdb/configure > @@ -30123,6 +30123,7 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h > > for ac_func in \ > btowc \ > + clearenv \ > getgid \ > getpgid \ > getrlimit \ > diff --git a/gdb/configure.ac b/gdb/configure.ac > index 1b9939b0754..3f44d9e684b 100644 > --- a/gdb/configure.ac > +++ b/gdb/configure.ac > @@ -1458,6 +1458,7 @@ AC_C_BIGENDIAN > > AC_CHECK_FUNCS([ \ > btowc \ > + clearenv \ > getgid \ > getpgid \ > getrlimit \ > diff --git a/gdb/infcmd.c b/gdb/infcmd.c > index 3ba286738a0..ed4fb819faf 100644 > --- a/gdb/infcmd.c > +++ b/gdb/infcmd.c > @@ -2146,12 +2146,25 @@ unset_var_in_environment (gdb_environ *env, const char *var, int from_tty) > { > if (var == 0) > { > + /* If there is no clearenv, don't bother asking the question. */ > +#ifndef HAVE_CLEARENV > + if (env == nullptr) > + from_tty = 0; > +#endif > + > /* If there is no argument, delete all environment variables. > Ask for confirmation if reading from the terminal. */ > if (!from_tty || query (_("Delete all environment variables? "))) > { > + /* This was handled above. */ > if (env == nullptr) > - clearenv (); > + { > +#ifdef HAVE_CLEARENV > + clearenv (); > +#else > + error (_("Cannot clear the local environment on this host.")); > +#endif > + } > else > env->clear (); > } > diff --git a/gdb/testsuite/gdb.base/local-env.exp b/gdb/testsuite/gdb.base/local-env.exp > index fedcf9bc3e4..5bb639e2842 100644 > --- a/gdb/testsuite/gdb.base/local-env.exp > +++ b/gdb/testsuite/gdb.base/local-env.exp > @@ -59,12 +59,26 @@ gdb_test "show local-environment EDITOR" \ > "confirm unset environment variable worked" > > # Verify that we can unset all environment variables. > -gdb_test "unset local-environment" "" "unset all environment variables" \ > - "Delete all environment variables. .y or n. $" \ > - "y" > +# Note that on some platforms this is not possible. > +set can_unset_all 0 > +# Disable confirmation so we don't have to deal with the question. > +gdb_test_multiple "with confirm off -- unset local-environment" \ > + "unset all environment variables" { > + -re -wrap "Cannot clear the local environment on this host." { > + # Nothing. > + pass $gdb_test_name > + } > + > + -re "\r\n$gdb_prompt $" { > + set can_unset_all 1 > + pass $gdb_test_name > + } > + } > > -gdb_test_no_output "show local-environment" \ > - "all environment variables have been unset" > +if {$can_unset_all} { > + gdb_test_no_output "show local-environment" \ > + "all environment variables have been unset" > +} > > # Verify that we can set a specific environment variable. > test_set_show_env_var "EDITOR" "emacs" "set environment variable" > > base-commit: 7979dbef836b1c8035b9fe9dd6e09c342d85a5e2