From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D70B33858D20 for ; Fri, 3 Feb 2023 17:18:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D70B33858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675444727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=c1AeUcd2Bb6/1vUEU/cb04KtkLDjd3W/ghcHMgR//B4=; b=ehyJbFTC48ldaHkgmqA5Ox/G8e6yOjpjPW8d4IN0HbLcuq46ahjvpAb7W6IUjogNWGp6A3 P69NYcP6qpcxRD1EzFPzEFI9BLUC2dFhDtk45yOEKwZbL+ABxt5j9tYrbkZYG8NIlp1Jn1 m8mwtc2fRmxkmgpYIy9LGsK0/kBV6To= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-623-_VE0MhaAMZCDlqenT8Vz3A-1; Fri, 03 Feb 2023 12:18:46 -0500 X-MC-Unique: _VE0MhaAMZCDlqenT8Vz3A-1 Received: by mail-qv1-f69.google.com with SMTP id mx2-20020a0562142e0200b0053807f3eb76so3063399qvb.15 for ; Fri, 03 Feb 2023 09:18:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=c1AeUcd2Bb6/1vUEU/cb04KtkLDjd3W/ghcHMgR//B4=; b=ZVs9LpBsLua8s9Jr4WMasx6C/YCmv60smGE1odf+ppfKaTdWI2kykcA+AXU5NdDqM8 6AAgve6PSeZImEKbBsLdI+q04mXrXmE324zUzoqFCwCoha9d8Jg5q6S8SNJO+nk7y1uA faT1xhM9Guok2jHY0xAa8yAlK0WodsmNv01IzmZJoeBtvKRce/ppfTTPx7tjvZPRRF5G +BAQkImp8yT+ceu+tU/LvRQvhmZTLKvQm50zEAeVKPEJ/r3gS29XL0PfrgJEa366g4o6 Fb4CDt5lyfQ/13NoYjsfqk2kRbSIhcTPxypKQPPPrk+x8n/u3g2QUCp/8X4wGbIcu+IF IE8Q== X-Gm-Message-State: AO0yUKXI9RfWPRHU1NnzlxJ4uhSU2H1NS5n1PAWzJq4zkY4kIVMlD7rY OKgZYRQlGevzY1P8QPbYwCI61Nwx/f+kqCb2LPrBKFGO6ifMb9ZmbVFNAnwXZywwCZeQ5WUMr8O c85xXVFwF3Vp4kmPV1DeUxw== X-Received: by 2002:a05:622a:511:b0:3b6:35cc:a5c1 with SMTP id l17-20020a05622a051100b003b635cca5c1mr19455832qtx.20.1675444724291; Fri, 03 Feb 2023 09:18:44 -0800 (PST) X-Google-Smtp-Source: AK7set+FqVfnQZaok5fmDfF7b68J35XPzyykUD/ZPESBPjRXSyxOz3tUG5BjFY/dmqgbMaWcA0azJA== X-Received: by 2002:a05:622a:511:b0:3b6:35cc:a5c1 with SMTP id l17-20020a05622a051100b003b635cca5c1mr19455801qtx.20.1675444724031; Fri, 03 Feb 2023 09:18:44 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id i11-20020a05620a404b00b006ee8874f5fasm2272017qko.53.2023.02.03.09.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:18:43 -0800 (PST) From: Andrew Burgess To: Keith Seitz , gdb-patches@sourceware.org Cc: Wendy.Peikes@netapp.com Subject: Re: [RFC PATCH 1/2] Add $_env convenience function In-Reply-To: <20230125193825.3665649-2-keiths@redhat.com> References: <20230125193825.3665649-1-keiths@redhat.com> <20230125193825.3665649-2-keiths@redhat.com> Date: Fri, 03 Feb 2023 17:18:41 +0000 Message-ID: <87h6w2r7ke.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Keith Seitz via Gdb-patches writes: > This patch adds a new Python convenience function which simply > returns the value of the given environment variable or throws > a KeyError. > > (gdb) p $_env("HOME") > $1 = "/home/keiths" > > [This patch is here for the purposes of demonstarting an alternative > design/implementation to a previously proposed patch. See > https://sourceware.org/pipermail/gdb-patches/2022-October/192396.html .] It probably has value on its own I think. > --- > gdb/data-directory/Makefile.in | 1 + > gdb/python/lib/gdb/function/env.py | 21 +++++++++++++++++++++ > 2 files changed, 22 insertions(+) > create mode 100644 gdb/python/lib/gdb/function/env.py > > diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in > index f1139291eed..3b0a05d61dc 100644 > --- a/gdb/data-directory/Makefile.in > +++ b/gdb/data-directory/Makefile.in > @@ -107,6 +107,7 @@ PYTHON_FILE_LIST = \ > gdb/function/as_string.py \ > gdb/function/caller_is.py \ > gdb/function/strfns.py \ > + gdb/function/env.py \ > gdb/printer/__init__.py \ > gdb/printer/bound_registers.py > > diff --git a/gdb/python/lib/gdb/function/env.py b/gdb/python/lib/gdb/function/env.py > new file mode 100644 > index 00000000000..54a441cea54 > --- /dev/null > +++ b/gdb/python/lib/gdb/function/env.py > @@ -0,0 +1,21 @@ Missing copyright header here. > +"""$_env""" > + > +import gdb > +import os > + > +class _Env(gdb.Function): > + """$_env - return the value of an environment variable. > + > + Usage: $_env("NAME") > + > + Returns: > + Value of the environment variable named NAME or throws KeyError if NAME is > + undefined in the environment.""" > + > + def __init__(self): > + super(_Env, self).__init__("_env") > + > + def invoke(self, name): > + return os.environ[name.string()] Something like this: def invoke(self, name, default=None): if default is not None and not name.string() in os.environ: return default return os.environ[name.string()] would allow users to supply a default: p $_env("UNKNOWN", "default_value") But retains: p $_env("HOME") Might be useful? Thanks, Andrew > + > +_Env() > -- > 2.38.1