public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/python: fix gdb.Objfile.__repr__ () for dynamically compiled code
@ 2022-02-01 13:05 Jan Vrany
  2022-02-01 14:22 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Vrany @ 2022-02-01 13:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

While experimenting with JIT reader API I realized that calling repr ()
on objfile created by JIT reader crashes GDB.

The problem was that objfpy_repr () called objfile_filename () which
returned NULL, causing PyString_FromFormat () to crash.

This commit fixes this problem by using objfile_name () instead of
objfile_filename (). This also makes consistent with the value of gdb.Objfile.filename variable.
---
 gdb/python/py-objfile.c               | 2 +-
 gdb/testsuite/gdb.base/jit-reader.exp | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 6055a42260b..48d2eb306d1 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -513,7 +513,7 @@ objfpy_repr (PyObject *self_)
     return PyString_FromString ("<gdb.Objfile (invalid)>");
 
   return PyString_FromFormat ("<gdb.Objfile filename=%s>",
-			      objfile_filename (obj));
+			      objfile_name (obj));
 }
 
 /* Subroutine of gdbpy_lookup_objfile_by_build_id to simplify it.
diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp
index 7ee16d69c84..3084f755a02 100644
--- a/gdb/testsuite/gdb.base/jit-reader.exp
+++ b/gdb/testsuite/gdb.base/jit-reader.exp
@@ -227,6 +227,14 @@ proc jit_reader_test {} {
 		    "Attempt to assign to an unmodifiable value\." \
 		    "cannot assign to register"
 	    }
+
+	    gdb_test "python print(gdb.objfiles())" \
+		"$any<gdb.Objfile filename=<< JIT compiled code >>>$any" \
+		"python gdb.Objfile.__repr__ ()"
+
+	    gdb_test "python print(list(map(lambda objf : objf.filename, gdb.objfiles())))" \
+		"$any'<< JIT compiled code >>'$any" \
+		"python gdb.Objfile.filename"
 	}
     }
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-01 14:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 13:05 [PATCH] gdb/python: fix gdb.Objfile.__repr__ () for dynamically compiled code Jan Vrany
2022-02-01 14:22 ` Simon Marchi
2022-02-01 14:39   ` Jan Vrany

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).