From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 3/4] gdb/python: convert Frame.read_register to take named arguments
Date: Thu, 30 Mar 2023 13:10:22 +0100 [thread overview]
Message-ID: <aff9b4499f8dc1e575ab897377d23d7c91e2ca78.1680177890.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1680177890.git.aburgess@redhat.com>
Following on from the previous commit, this updates
Frame.read_register to accept named arguments. As with the previous
commit there's no huge benefit for the users in accepting named
arguments here -- this function only takes a single argument after
all.
But I do think it is worth keeping Frame.read_register method in sync
with the PendingFrame.read_register method, this allows for the
possibility that the user has some code that can operate on either a
Frame or a Pending frame.
Minor update to allow for named arguments, and an extra test to check
the new functionality.
---
gdb/doc/python.texi | 2 +-
gdb/python/py-frame.c | 11 +++++++----
gdb/testsuite/gdb.python/py-frame.exp | 6 ++++++
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 4f62ca7d95e..f54909cc05d 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -5380,7 +5380,7 @@
@end defun
@anchor{gdbpy_frame_read_register}
-@defun Frame.read_register (register)
+@defun Frame.read_register (@var{register})
Return the value of @var{register} in this frame. Returns a
@code{Gdb.Value} object. Throws an exception if @var{register} does
not exist. The @var{register} argument must be one of the following:
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 00cd4bee492..3a033ac7570 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -238,13 +238,15 @@ frapy_pc (PyObject *self, PyObject *args)
Returns the value of a register in this frame. */
static PyObject *
-frapy_read_register (PyObject *self, PyObject *args)
+frapy_read_register (PyObject *self, PyObject *args, PyObject *kw)
{
PyObject *pyo_reg_id;
PyObject *result = nullptr;
- if (!PyArg_UnpackTuple (args, "read_register", 1, 1, &pyo_reg_id))
- return NULL;
+ static const char *keywords[] = { "register", nullptr };
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, &pyo_reg_id))
+ return nullptr;
+
try
{
scoped_value_mark free_values;
@@ -766,7 +768,8 @@ Return the reason why it's not possible to find frames older than this." },
{ "pc", frapy_pc, METH_NOARGS,
"pc () -> Long.\n\
Return the frame's resume address." },
- { "read_register", frapy_read_register, METH_VARARGS,
+ { "read_register", (PyCFunction) frapy_read_register,
+ METH_VARARGS | METH_KEYWORDS,
"read_register (register_name) -> gdb.Value\n\
Return the value of the register in the frame." },
{ "block", frapy_block, METH_NOARGS,
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
index 5aebb6beb5f..07997326d09 100644
--- a/gdb/testsuite/gdb.python/py-frame.exp
+++ b/gdb/testsuite/gdb.python/py-frame.exp
@@ -115,6 +115,12 @@ gdb_test "python print ('result = %s' % (f0.read_register('pc') == f0.pc()))" \
" = True" \
"test Frame.read_register(pc)"
+# Repeat the previous test, but this time use named arguments for the
+# read_register method call.
+gdb_test "python print ('result = %s' % (f0.read_register(register = 'pc') == f0.pc()))" \
+ " = True" \
+ "test Frame.read_register() using named arguments"
+
# Test arch-specific register name.
set pc ""
if {[is_amd64_regs_target]} {
--
2.25.4
next prev parent reply other threads:[~2023-03-30 12:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-30 12:10 [PATCH 0/4] Python API: Accept named arguments in a few more places Andrew Burgess
2023-03-30 12:10 ` [PATCH 1/4] gdb/python: have UnwindInfo.add_saved_register accept named args Andrew Burgess
2023-03-30 14:08 ` Eli Zaretskii
2023-04-06 14:10 ` Andrew Burgess
2023-03-30 12:10 ` [PATCH 2/4] gdb/python: have PendingFrame methods accept keyword arguments Andrew Burgess
2023-03-30 14:13 ` Eli Zaretskii
2023-03-30 12:10 ` Andrew Burgess [this message]
2023-03-30 14:10 ` [PATCH 3/4] gdb/python: convert Frame.read_register to take named arguments Eli Zaretskii
2023-03-30 12:10 ` [PATCH 4/4] gdb/python: allow Frame.read_var to accept " Andrew Burgess
2023-03-30 14:11 ` Eli Zaretskii
2023-04-04 18:39 ` [PATCH 0/4] Python API: Accept named arguments in a few more places Tom Tromey
2023-04-06 14:11 ` Andrew Burgess
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=aff9b4499f8dc1e575ab897377d23d7c91e2ca78.1680177890.git.aburgess@redhat.com \
--to=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).