public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Lancelot SIX <lancelot.six@amd.com>
To: Tom Tromey <tromey@adacore.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH v4 3/4] Rewrite "python" command exception handling
Date: Thu, 7 Mar 2024 10:00:09 +0000	[thread overview]
Message-ID: <20240307095930.442bsjiva4ss6hig@khazad-dum> (raw)
In-Reply-To: <20240227-py-simple-exc-v4-3-3341d342c126@adacore.com>

On Tue, Feb 27, 2024 at 07:45:51AM -0700, Tom Tromey wrote:
> The "python" command (and the Python implementation of the gdb
> "source" command) does not handle Python exceptions in the same way as
> other gdb-facing Python code.  In particular, exceptions are turned
> into a generic error rather than being routed through
> gdbpy_handle_exception, which takes care of converting to 'quit' as
> appropriate.
> 
> I think this was done this way because PyRun_SimpleFile and friends do
> not propagate the Python exception -- they simply indicate that one
> occurred.
> 
> This patch reimplements these functions to respect the general gdb
> convention here.  As a bonus, some Windows-specific code can be
> removed, as can the _execute_file function.
> 
> The bulk of this change is tweaking the test suite to match the new
> way that exceptions are displayed.  These changes are largely
> uninteresting.  However, it's worth pointing out the py-error.exp
> change.  Here, the failure changes because the test changes the host
> charset to something that isn't supported by Python.  This then
> results in a weird error in the new setup.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31354
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
> Acked-By: Tom de Vries <tdevries@suse.de>

Hi Tom,

Our internal testing caught a regression introduced by this change.

Let's say you have a python script like this in /tmp/foo.py:

    if __name__ == "__main__":
        print(__file__)

Before this patch, we would have:

    $ gdb -batch -quiet -x /tmp/foo.py
    /tmp/foo.py

With this patch, we now have:

    $ gdb -batch -quiet -x /tmp/foo.py
    Python Exception <class 'NameError'>: name '__file__' is not defined
    Error occurred in Python: name '__file__' is not defined

I have not looked into much details, but can try to have a look if you
don't have time.

Best,
Lancelot.


  parent reply	other threads:[~2024-03-07 10:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 14:45 [PATCH v4 0/4] Fix DAP pause bug Tom Tromey
2024-02-27 14:45 ` [PATCH v4 1/4] Introduce read_remainder_of_file Tom Tromey
2024-02-27 14:45 ` [PATCH v4 2/4] Fix formatting buglet in python.c Tom Tromey
2024-02-27 14:45 ` [PATCH v4 3/4] Rewrite "python" command exception handling Tom Tromey
2024-02-27 16:03   ` Tom de Vries
2024-02-27 16:04   ` Eli Zaretskii
2024-03-07 10:00   ` Lancelot SIX [this message]
2024-03-08 16:19     ` Tom Tromey
2024-03-08 19:24       ` Tom Tromey
2024-02-27 14:45 ` [PATCH v4 4/4] Use the .py file in gdb.dap/pause.exp Tom Tromey
2024-02-27 16:56 ` [PATCH v4 0/4] Fix DAP pause bug Tom Tromey

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=20240307095930.442bsjiva4ss6hig@khazad-dum \
    --to=lancelot.six@amd.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.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).