Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>, Eli Zaretskii <eliz@gnu.org>
Subject: [RFC v5 09/18] gdb/python: add unlink () method to gdb.Objfile object
Date: Mon, 23 Jun 2025 17:10:04 +0100	[thread overview]
Message-ID: <20250623161013.650814-10-jan.vrany@labware.com> (raw)
In-Reply-To: <20250623161013.650814-1-jan.vrany@labware.com>

This commit adds method allowing one remove any objfile. This is meant
to be used to remove objfiles for dynamic code when this dynamic code
is discarded. However gdb.Objfile.unlink() makes no attempt to ensure
this - to make it consistent with other Python API to create and modify
objfiles related structures (compunits, symbol tables and so on).

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
---
 gdb/doc/python.texi                     |  6 ++++++
 gdb/python/py-objfile.c                 | 18 ++++++++++++++++++
 gdb/testsuite/gdb.python/py-objfile.exp | 12 ++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ad9d65636b7..eac12bec4d3 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -5847,6 +5847,12 @@ Return a sequence of @code{gdb.Compunit} associated with this objfile.
 @xref{Compunits In Python}.
 @end defun
 
+@defun Objfile.unlink ()
+Remove this objfile.  This should be used only on objfiles created by
+Python (see @code{Objfile.__init__} above) but @code{Objfile.unlink} does
+not make any checks.
+@end defun
+
 @node Frames In Python
 @subsubsection Accessing inferior stack frames from Python
 
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 6403db583a7..dc43e2c9e7d 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -608,6 +608,20 @@ objfpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
   Py_RETURN_NONE;
 }
 
+/* Implementation of gdb.Objfile.unlink ().  */
+
+static PyObject *
+objfpy_unlink (PyObject *self, PyObject *args)
+{
+  objfile_object *obj = (objfile_object *) self;
+
+  OBJFPY_REQUIRE_VALID (obj);
+
+  obj->objfile->unlink();
+
+  Py_RETURN_NONE;
+}
+
 /* Implement repr() for gdb.Objfile.  */
 
 static PyObject *
@@ -873,6 +887,10 @@ Look up a static-linkage global symbol in this objfile and return it." },
     "compunits () -> List.\n\
 Return a sequence of compunits associated to this objfile." },
 
+  { "unlink", objfpy_unlink, METH_NOARGS,
+    "unlink ().\n\
+Remove this objfile." },
+
   { NULL }
 };
 
diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp
index 055a35cea41..1938350174d 100644
--- a/gdb/testsuite/gdb.python/py-objfile.exp
+++ b/gdb/testsuite/gdb.python/py-objfile.exp
@@ -210,3 +210,15 @@ gdb_test "python print( gdb.Objfile(\"Test objfile 4\", gdb))" \
 gdb_test "python print( gdb.Objfile(\"Test objfile 5\", gdb.selected_inferior(), gdb.selected_inferior()))" \
 	"TypeError.*:.*" \
 	"create objfile with valid inferior but invalid arch"
+
+gdb_test "python print(objfile.unlink())" \
+	"None" \
+	"remove (dynamic) objfile"
+
+gdb_test "python print(objfile in gdb.objfiles())" \
+	"False" \
+	"removed (dynamic) objfile no longer in gdb.objfiles()"
+
+gdb_test "python print(objfile.is_valid())" \
+	"False" \
+	"removes (dynamic) objfile is no longer valid"
-- 
2.47.2


  parent reply	other threads:[~2025-06-23 16:14 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-23 16:09 [RFC v5 00/19] Add Python "JIT" API Jan Vrany
2025-06-23 16:09 ` [RFC v5 01/18] gdb: introduce expand_symtabs_maybe_overlapping Jan Vrany
2025-06-24 15:22   ` Tom Tromey
2025-06-26 15:05     ` Jan Vraný
2025-06-23 16:09 ` [RFC v5 02/18] gdb: introduce compunit_symtab::maybe_contains Jan Vrany
2025-06-23 16:09 ` [RFC v5 03/18] gdb: update is_addr_in_objfile to support "dynamic" objfiles Jan Vrany
2025-06-23 16:09 ` [RFC v5 04/18] gdb: introduce new function create_function_type Jan Vrany
2025-06-24 15:29   ` Tom Tromey
2025-06-26 11:12     ` Jan Vraný
2025-06-27 14:21       ` Tom Tromey
2025-06-27 14:30         ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 05/18] gdb/python: add function () method to gdb.Type object Jan Vrany
2025-06-24 16:11   ` Tom Tromey
2025-06-26 11:13     ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 06/18] gdb: use std::vector<> to hold on blocks in struct blockvector Jan Vrany
2025-06-23 16:10 ` [RFC v5 07/18] gdb/python: add gdb.Compunit Jan Vrany
2025-06-23 16:10 ` [RFC v5 08/18] gdb/python: allow instantiation of gdb.Objfile from Python Jan Vrany
2025-06-23 16:10 ` Jan Vrany [this message]
2025-06-23 16:10 ` [RFC v5 10/18] gdb/python: allow instantiation of gdb.Compunit " Jan Vrany
2025-06-23 16:10 ` [RFC v5 11/18] gdb/python: allow instantiation of gdb.Symtab " Jan Vrany
2025-06-23 16:10 ` [RFC v5 12/18] gdb/python: allow instantiation of gdb.Block " Jan Vrany
2025-06-23 16:10 ` [RFC v5 13/18] gdb/python: allow instantiation of gdb.Symbol " Jan Vrany
2025-06-23 16:10 ` [RFC v5 14/18] gdb/python: add add_symbol () method to gdb.Block Jan Vrany
2025-08-29 14:10   ` Andrew Burgess
2025-08-29 14:14     ` Andrew Burgess
2025-06-23 16:10 ` [RFC v5 15/18] gdb/python: add more attributes to gdb.LinetableEntry objects Jan Vrany
2025-08-29 14:00   ` Andrew Burgess
2025-09-02 11:03     ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 16/18] gdb/python: allow instantiation of gdb.LineTableEntry objects Jan Vrany
2025-06-23 16:10 ` [RFC v5 17/18] gdb/python: allow instantiation of gdb.LineTable objects Jan Vrany
2025-06-23 16:10 ` [RFC v5 18/18] gdb/python: add section in documentation on implementing JIT interface Jan Vrany

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=20250623161013.650814-10-jan.vrany@labware.com \
    --to=jan.vrany@labware.com \
    --cc=eliz@gnu.org \
    --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