From: Keith Seitz <keiths@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Cc: Wendy.Peikes@netapp.com
Subject: Re: [RFC PATCH 1/2] Add $_env convenience function
Date: Fri, 3 Feb 2023 10:34:54 -0800 [thread overview]
Message-ID: <053131f9-2138-d1d3-b03d-90d2d67b3986@redhat.com> (raw)
In-Reply-To: <87h6w2r7ke.fsf@redhat.com>
On 2/3/23 09:18, Andrew Burgess wrote:
>> 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.
It *was* just an RFC. :-P
I will, of course, add appropriate header, copyright, etc
when I submit for final approval (after I write a few tests
and docs).
I will submit independently of the expression-evaluation
substitution patch (#2 in this series).
>
>> +"""$_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?
That's a very good idea. I'll steal that. :-)
Keith
next prev parent reply other threads:[~2023-02-03 18:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <BYAPR06MB6117A6A68D09026F27C310D4E54C9@BYAPR06MB6117.namprd06.prod.outlook.com>
[not found] ` <BYAPR06MB611721469E1454F0CD94259DE55D9@BYAPR06MB6117.namprd06.prod.outlook.com>
2022-10-05 23:19 ` [PATCH] gdb: allow env var specifications in cmds 'set log', 'source', 'shell' Peikes, Wendy
2022-10-05 23:19 ` Peikes, Wendy
2022-10-06 19:34 ` Keith Seitz
2022-10-26 0:25 ` Peikes, Wendy
2023-01-25 19:38 ` [RFC PATCH 0/2] Command expression evaulation substitution Keith Seitz
2023-01-25 19:38 ` [RFC PATCH 1/2] Add $_env convenience function Keith Seitz
2023-02-03 17:18 ` Andrew Burgess
2023-02-03 18:34 ` Keith Seitz [this message]
2023-01-25 19:38 ` [RFC PATCH 2/2] Allow and evaluate expressions in command arguments Keith Seitz
2023-02-03 17:22 ` Andrew Burgess
2023-02-03 18:49 ` Keith Seitz
2023-02-17 22:31 ` Pedro Alves
2023-01-25 20:21 ` [RFC PATCH 0/2] Command expression evaulation substitution Peikes, Wendy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=053131f9-2138-d1d3-b03d-90d2d67b3986@redhat.com \
--to=keiths@redhat.com \
--cc=Wendy.Peikes@netapp.com \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).