public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>
Subject: [PATCH] gdb/python: fix gdb.Objfile.__repr__ () for dynamically compiled code
Date: Tue,  1 Feb 2022 13:05:34 +0000	[thread overview]
Message-ID: <20220201130534.1827188-1-jan.vrany@labware.com> (raw)

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


             reply	other threads:[~2022-02-01 13:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01 13:05 Jan Vrany [this message]
2022-02-01 14:22 ` Simon Marchi
2022-02-01 14:39   ` 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=20220201130534.1827188-1-jan.vrany@labware.com \
    --to=jan.vrany@labware.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).