From: Jan Vrany <jan.vrany@labware.com>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/python: fix gdb.Objfile.__repr__ () for dynamically compiled code
Date: Tue, 01 Feb 2022 14:39:45 +0000 [thread overview]
Message-ID: <34bea212957111e1b52a414f7be56ce229132c7b.camel@labware.com> (raw)
In-Reply-To: <305de069-6b89-dd99-c011-be3ae7ae44c4@polymtl.ca>
On Tue, 2022-02-01 at 09:22 -0500, Simon Marchi wrote:
>
> On 2022-02-01 08:05, Jan Vrany via Gdb-patches wrote:
> > 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"
> > }
> > }
> >
> >
> >
> >
>
> LGTM, except that these tests should probably be guarded by a
>
> if { ![skip_python_tests] } {
> ...
> }
True! I'll add the guard and push.
>
> so that they don't fail on a build without Python.
>
> Orthogonal to this patch, but IWBN to make these objfiles have a better
> name, at least so that we can differentiate them from one another.
> Like, maybe include the address of the jited object:
>
> << JIT compiled code at 0x%x >>
I'll make another patch for this.
Thanks!
Jan
prev parent reply other threads:[~2022-02-01 14:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-01 13:05 Jan Vrany
2022-02-01 14:22 ` Simon Marchi
2022-02-01 14:39 ` Jan Vrany [this message]
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=34bea212957111e1b52a414f7be56ce229132c7b.camel@labware.com \
--to=jan.vrany@labware.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/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).