From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Cc: Wendy.Peikes@netapp.com
Subject: [RFC PATCH 1/2] Add $_env convenience function
Date: Wed, 25 Jan 2023 11:38:24 -0800 [thread overview]
Message-ID: <20230125193825.3665649-2-keiths@redhat.com> (raw)
In-Reply-To: <20230125193825.3665649-1-keiths@redhat.com>
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 .]
---
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 @@
+"""$_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()]
+
+_Env()
--
2.38.1
next prev parent reply other threads:[~2023-01-25 19:38 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 ` Keith Seitz [this message]
2023-02-03 17:18 ` [RFC PATCH 1/2] Add $_env convenience function Andrew Burgess
2023-02-03 18:34 ` Keith Seitz
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=20230125193825.3665649-2-keiths@redhat.com \
--to=keiths@redhat.com \
--cc=Wendy.Peikes@netapp.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).