From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/7] Add gdb.Frame.static_link method
Date: Wed, 01 Nov 2023 11:09:36 -0600 [thread overview]
Message-ID: <20231101-dap-nested-function-v1-4-0b0c3b228ac7@adacore.com> (raw)
In-Reply-To: <20231101-dap-nested-function-v1-0-0b0c3b228ac7@adacore.com>
This adds a new gdb.Frame.static_link method to the gdb Python layer.
This can be used to find the static link frame for a given frame.
---
gdb/NEWS | 3 +++
gdb/doc/python.texi | 10 ++++++++++
gdb/python/py-frame.c | 26 ++++++++++++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/gdb/NEWS b/gdb/NEWS
index 95663433f1c..503f53a2ea1 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -17,6 +17,9 @@
** New read/write attribute gdb.Value.bytes that contains a bytes
object holding the contents of this value.
+ ** New method gdb.Frame.static_link that returns the outer frame
+ of a nested function frame.
+
*** Changes in GDB 14
* GDB now supports the AArch64 Scalable Matrix Extension 2 (SME2), which
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 8cc3f92cbfe..afe447644c5 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -5732,6 +5732,16 @@ Set this frame to be the selected frame. @xref{Stack, ,Examining the
Stack}.
@end defun
+@defun Frame.static_link ()
+In some languages (e.g., Ada, but also a GNU C extension), a nested
+function can access the variables in the outer scope. This is done
+via a ``static link'', which is a reference from the nested frame to
+the appropriate outer frame.
+
+This method returns this frame's static link frame, if one exists. If
+there is no static link, this method returns @code{None}.
+@end defun
+
@defun Frame.level ()
Return an integer, the stack frame level for this frame. @xref{Frames, ,Stack Frames}.
@end defun
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 1a55e514e39..0a7e10f09ff 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -622,6 +622,30 @@ frapy_language (PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+/* The static link for this frame. */
+
+static PyObject *
+frapy_static_link (PyObject *self, PyObject *args)
+{
+ frame_info_ptr link;
+
+ try
+ {
+ FRAPY_REQUIRE_VALID (self, link);
+
+ link = frame_follow_static_link (link);
+ }
+ catch (const gdb_exception &except)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+
+ if (link == nullptr)
+ Py_RETURN_NONE;
+
+ return frame_info_to_frame_object (link);
+}
+
/* Implementation of gdb.newest_frame () -> gdb.Frame.
Returns the newest frame object. */
@@ -800,6 +824,8 @@ Return the value of the variable in this frame." },
"The stack level of this frame." },
{ "language", frapy_language, METH_NOARGS,
"The language of this frame." },
+ { "static_link", frapy_static_link, METH_NOARGS,
+ "The static link of this frame, or None." },
{NULL} /* Sentinel */
};
--
2.40.1
next prev parent reply other threads:[~2023-11-01 17:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-01 17:09 [PATCH 0/7] Handle nested functions in DAP Tom Tromey
2023-11-01 17:09 ` [PATCH 1/7] Add two convenience methods to block Tom Tromey
2023-11-01 17:09 ` [PATCH 2/7] Add block::function_block Tom Tromey
2023-11-01 17:09 ` [PATCH 3/7] Move follow_static_link to frame.c Tom Tromey
2023-11-01 17:09 ` Tom Tromey [this message]
2023-11-01 17:17 ` [PATCH 4/7] Add gdb.Frame.static_link method Eli Zaretskii
2023-11-01 17:09 ` [PATCH 5/7] Fix a bug in DAP scopes code Tom Tromey
2023-11-01 17:09 ` [PATCH 6/7] Handle the static link in FrameDecorator Tom Tromey
2023-11-15 12:31 ` Tom de Vries
2023-11-15 13:58 ` Tom Tromey
2023-11-15 14:07 ` Tom de Vries
2023-11-15 14:58 ` Tom Tromey
2023-11-01 17:09 ` [PATCH 7/7] Update gdb.Symbol.is_variable documentation Tom Tromey
2023-11-01 17:15 ` Eli Zaretskii
2023-11-14 15:39 ` [PATCH 0/7] Handle nested functions in DAP Tom Tromey
2023-11-14 16:11 ` Tom Tromey
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=20231101-dap-nested-function-v1-4-0b0c3b228ac7@adacore.com \
--to=tromey@adacore.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).