From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iq7PBcKeOWl9MiwAWB0awg (envelope-from ) for ; Wed, 10 Dec 2025 11:24:34 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=kbsWU94v; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 0143A1E08D; Wed, 10 Dec 2025 11:24:33 -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 4B9781E08D for ; Wed, 10 Dec 2025 11:24:33 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id C07264BA2E1E for ; Wed, 10 Dec 2025 16:24:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C07264BA2E1E Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=kbsWU94v Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by sourceware.org (Postfix) with ESMTPS id 468A54BA2E00 for ; Wed, 10 Dec 2025 16:24:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 468A54BA2E00 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 468A54BA2E00 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.210.42 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1765383846; cv=none; b=YlLxWwymO3wqsErZzeihUVE6cEdjJQtlTtf1byHTWi7rlQZpQtXA57JSZcuJ18um1We0KFRYr1T1AsLCXCeJjhjGgO0z51hseEoUefECwQQu1q109dwikaAjbDAT/IqHibMUQjNnl0TQdnx9FMcEJK83T379KJQfRrfUyA0MjSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1765383846; c=relaxed/simple; bh=SvYyq35OOCncSWhDMcQTTtwSp7w+hocBycQSDkhhrBg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Ilosgx7RGW1WWMdfqV7DpS+b2uc4l1zUvd79sd7y14qtJGFQZndsoVl0KQ1ORqjI55MpAqNFrHl2s7Vsp2YNRSbGGgsq9kpPKs6DWdfnyh/xQkM/9HmOm9qmTvdZx+4ciovk9M7mu80HDKH7E9hgzVjnuArJ1I0AmlMo/8T1drE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 468A54BA2E00 Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-7c76d855ddbso13612a34.3 for ; Wed, 10 Dec 2025 08:24:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1765383845; x=1765988645; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8iwU/WAiLAWfE6z05Mk5NsLog3/uEex0PXiu82y4yV8=; b=kbsWU94vbcwZpqSikNn27k1N1kjhbSNSDFnIqoiFqyILhJL/QOILS4/UsbTcaFZJl5 gVZCAQZpVlt2j6U5VxM3nmRJbrPcIvAaz3Shj1t6u4RKQk9gkEzEbys5n0VJKERCSSOU ItHariRDXqYfDawBPUbNwoJR7F6Qrv/LVgiQr3DGfCZ2SdkZak/7S7PIQCNEKq+tiuv6 bua98cRmAAIVymkOCu8fxepOWB1n3UeIT2fWcxHj+W4Bg+QqLdYgKDo8xi8Hf0lg9sD+ 3gVdNVCBYPzp0lQ8BQ/A8xobde9SV7fWfYgre+2jJBkroJDkUOPjNllnRB/cVUyl6EA/ fXhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765383845; x=1765988645; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8iwU/WAiLAWfE6z05Mk5NsLog3/uEex0PXiu82y4yV8=; b=sJpIeHSUIKip89CQ4ASmw4fI69bNXpFKB/I9/TuH1WYHzSPfUtx7WcaSxlqCpBuQ/t tX2kUGUKgpV3rZb7qGg0DPnGA1nD8eBqExe43azi49+ttvhIShzSksNT032gLDw+iNi6 BopC10OMnCInJkw8pUwmiboCuWS+kmXvv15fnwGS6HR+aY9LMDmx/eDlGAuYqcw/YxiX gEnwZMTZQ2Jjzqo7GB7JNm7fhJ/5+Eev2tY52Wr1PuloECzlXb1aGYW+KhX49BVA07Fj 41cn9HfdbsafLVMCxNyYbSPnprJjKmdGC51bh9aeaks9DVfIuTSowkFjhuawRw1ke0tw /F6A== X-Gm-Message-State: AOJu0YzNwMwWgyKpsnxegfiE8VBATafp3HrVtdQ6qrXTGkA0Ao1FibL4 6wp6CS57xnmcExm+urorOnFag1BKgdQFWInfpv2fbd+mkSeSWR37PPLNYsb/k+puMmu5P94oC1g TJHc= X-Gm-Gg: ASbGnctih8t3CXeEmSJtko2x0jue6qwoigga6qsWsjtlnQ8Pega5smyMcp4+vMPvmsq eNbyDN8aE+T2rhS0clwEzJ2m5sAFeaUamKORL9PE/w8agQlPTvGxbZyxod0rhnaLHq8eHJvxDiA YSDsheWkl2gseuWvZSVREsf2nX5xc9fHiIbETtWDMc2N/ZLPdjheOixobyKvKuH3LoHD8ABY/SZ nKGZZ017lKiIIM7hqA/mndT4Ow+vtBUI9KITqGades1oKqaHSqAvpmGUgys5vQtEQ5NDwtt1DYb fjWOw6QMw6FGsbQWPLQfZB9JP6ZVKYcWR4QdKJ3atTnMrE9S9mpIovaqOvzvP84kr+Wv0dKDgDf QkYVw7A1YfCX6DMgw6hz8CKFnU4cFYdhU532RHPNcrA+dFLGEiQG9tjGe5THA+z7zkNbAwn3vi8 kSRJksbSoovnyRzKOY1BCueOUIuiitXnBMAQ== X-Google-Smtp-Source: AGHT+IGsVZ2ds/uvd6ziG4qlfstebvBcr7lrA5RNXtH6U4bR5Rd3zaQC8tPh3IB4UPxvCSgC4Wui0Q== X-Received: by 2002:a05:6830:4c08:b0:7c9:5a1d:333a with SMTP id 46e09a7af769-7caceab8a9amr1687796a34.0.1765383845555; Wed, 10 Dec 2025 08:24:05 -0800 (PST) Received: from bapiya (97-122-120-205.hlrn.qwest.net. [97.122.120.205]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7cad8b05343sm89789a34.13.2025.12.10.08.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Dec 2025 08:24:04 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix "unset local-environment" when clearenv not available Date: Wed, 10 Dec 2025 09:24:02 -0700 Message-ID: <20251210162402.2026139-1-tromey@adacore.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 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 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. --- 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 -- 2.52.0