public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Jan Vrany <jan.vrany@labware.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/python: fix gdb.Objfile.__repr__ () for dynamically compiled code
Date: Tue, 1 Feb 2022 09:22:39 -0500	[thread overview]
Message-ID: <305de069-6b89-dd99-c011-be3ae7ae44c4@polymtl.ca> (raw)
In-Reply-To: <20220201130534.1827188-1-jan.vrany@labware.com>



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] } {
      ...
  }

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

Simon


  reply	other threads:[~2022-02-01 14:22 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 [this message]
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=305de069-6b89-dd99-c011-be3ae7ae44c4@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.vrany@labware.com \
    /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).