public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective
@ 2020-09-08 15:23 grees at undo dot io
  2020-09-08 16:33 ` [Bug python/26586] " grees at undo dot io
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: grees at undo dot io @ 2020-09-08 15:23 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

            Bug ID: 26586
           Summary: from_tty argument to Python's gdb.execute is no longer
                    effective
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: grees at undo dot io
  Target Milestone: ---

Created attachment 12822
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12822&action=edit
Patch fixing the from_tty argument and adding a test case

Prior to commit 56bcdbea2b, the from_tty keyword argument to the
Python function gdb.execute controlled whether the command took input
from the terminal. For example, after "apt install gdb" on Ubuntu
18.04:

    $ gdb -v | head -1
    GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
    $ gdb -q /bin/true
    Reading symbols from /bin/true...(no debugging symbols found)...done.
    (gdb) starti
    Starting program: /bin/true 

    Program stopped.
    0x00007ffff7dd6090 in _start () from /lib64/ld-linux-x86-64.so.2

When from_tty=True, the "starti" command prompts the user:

    (gdb) python gdb.execute("starti", from_tty=True)
    The program being debugged has been started already.
    Start it from the beginning? (y or n) y
    Starting program: /bin/true 

    Program stopped.
    0x00007ffff7dd6090 in _start () from /lib64/ld-linux-x86-64.so.2

When from_tty=False, it does not prompt the user, and "yes" is assumed:

    (gdb) python gdb.execute('starti', from_tty=False)

    Program stopped.
    0x00007ffff7dd6090 in _start () from /lib64/ld-linux-x86-64.so.2


However, after commit 56bcdbea2b, the from_tty keyword argument no
longer has this effect. For example, as of commit 7ade7fba75:

    $ ./gdb -data-directory data-directory -v | head -1
    GNU gdb (GDB) 10.0.50.20200908-git
    $ ./gdb -data-directory data-directory -q /bin/true
    Reading symbols from /bin/true...
    (No debugging symbols found in /bin/true)
    (gdb) starti
    Starting program: /bin/true 

    Program stopped.
    0x00007ffff7dd6090 in ?? () from /lib64/ld-linux-x86-64.so.2
    (gdb) python gdb.execute('starti', from_tty=True)
    The program being debugged has been started already.
    Start it from the beginning? (y or n) [answered Y; input not from terminal]
    Starting program: /bin/true 

    Program stopped.
    0x00007ffff7dd6090 in ?? () from /lib64/ld-linux-x86-64.so.2

Note the "[answered Y; input not from terminal]" in the output even
though from_tty=True was requested.


Supporting the from_tty argument is essential for any use case in
which you are implementing a command in Python that delegates to a GDB
command that might need to prompt the user. As a concrete example,
imagine writing a Python command that switches to the executable for
test number n:

    class RunTest(gdb.Command):
        def invoke(self, argument, from_tty):
            n = int(argument)
            test_file = test_directory / f"test-{n:04d}"
            gdb.execute(f"file {test_file}", from_tty=from_tty)

Here we want the GDB "file" command to prompt the user with "A program
is being debugged already. Are you sure you want to change the file?"
if the command was entered interactively at the terminal, that is, if
from_tty=True.

Looking at commit 56bcdbea2b, it seems that the behaviour of the
from_tty argument was changed accidentally. The commit message says:

    Let gdb.execute handle multi-line commands

    This changes the Python API so that gdb.execute can now handle
    multi-line commands, like "commands" or "define".

and there is no mention of changing the effect of the from_tty
argument. It looks as though the code for setting the instream to 0
was accidentally moved from execute_user_command() to
execute_control_commands() along with the code for iterating over a
series of command lines.

Accordingly, the simplest way to fix this is to partially reverse
commit 56bcdbea2b by moving the code for setting the instream to 0
back to execute_user_command() where it was to begin with.

I've attached a patch file which does this and which adds a test case
to avoid this accidentally being broken in future.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
@ 2020-09-08 16:33 ` grees at undo dot io
  2020-09-08 17:05 ` brobecker at gnat dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: grees at undo dot io @ 2020-09-08 16:33 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

Gareth Rees <grees at undo dot io> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |grees at undo dot io

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
  2020-09-08 16:33 ` [Bug python/26586] " grees at undo dot io
@ 2020-09-08 17:05 ` brobecker at gnat dot com
  2020-09-10 17:35 ` simark at simark dot ca
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: brobecker at gnat dot com @ 2020-09-08 17:05 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

Joel Brobecker <brobecker at gnat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.1
                 CC|                            |brobecker at gnat dot com

--- Comment #1 from Joel Brobecker <brobecker at gnat dot com> ---
Not really a regression (gdb-8.2 and gdb-9-branch have the patch identified as
the cause of this failure), but seems like a good fix to have if we can.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
  2020-09-08 16:33 ` [Bug python/26586] " grees at undo dot io
  2020-09-08 17:05 ` brobecker at gnat dot com
@ 2020-09-10 17:35 ` simark at simark dot ca
  2020-09-10 17:35 ` simark at simark dot ca
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2020-09-10 17:35 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

Simon Marchi <simark at simark dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simark at simark dot ca

--- Comment #2 from Simon Marchi <simark at simark dot ca> ---
Created attachment 12832
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12832&action=edit
Patch 1 to improve test case

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
                   ` (2 preceding siblings ...)
  2020-09-10 17:35 ` simark at simark dot ca
@ 2020-09-10 17:35 ` simark at simark dot ca
  2020-09-10 17:36 ` simark at simark dot ca
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2020-09-10 17:35 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

--- Comment #3 from Simon Marchi <simark at simark dot ca> ---
Arg sorry, wrong bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
                   ` (3 preceding siblings ...)
  2020-09-10 17:35 ` simark at simark dot ca
@ 2020-09-10 17:36 ` simark at simark dot ca
  2020-09-19 15:39 ` cbiesinger at google dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2020-09-10 17:36 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

Simon Marchi <simark at simark dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #12832|0                           |1
        is obsolete|                            |

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
                   ` (4 preceding siblings ...)
  2020-09-10 17:36 ` simark at simark dot ca
@ 2020-09-19 15:39 ` cbiesinger at google dot com
  2020-09-22 10:24 ` grees at undo dot io
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cbiesinger at google dot com @ 2020-09-19 15:39 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

Christian Biesinger <cbiesinger at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cbiesinger at google dot com

--- Comment #4 from Christian Biesinger <cbiesinger at google dot com> ---
Gareth, could you send the patch to the gdb-patches mailing list as described
in https://sourceware.org/gdb/wiki/ContributionChecklist ? Thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
                   ` (5 preceding siblings ...)
  2020-09-19 15:39 ` cbiesinger at google dot com
@ 2020-09-22 10:24 ` grees at undo dot io
  2020-09-26 18:02 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: grees at undo dot io @ 2020-09-22 10:24 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

--- Comment #5 from Gareth Rees <grees at undo dot io> ---
Patch submitted as requested:
https://sourceware.org/pipermail/gdb-patches/2020-September/172000.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
                   ` (6 preceding siblings ...)
  2020-09-22 10:24 ` grees at undo dot io
@ 2020-09-26 18:02 ` cvs-commit at gcc dot gnu.org
  2020-09-28 20:16 ` cvs-commit at gcc dot gnu.org
  2020-10-08 17:42 ` simark at simark dot ca
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-26 18:02 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

--- Comment #6 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Joel Brobecker <brobecke@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8f9929bb97dc0f0fdf60269ac8c9a7d50746646f

commit 8f9929bb97dc0f0fdf60269ac8c9a7d50746646f
Author: Gareth Rees <grees@undo.io>
Date:   Sat Sep 26 11:01:45 2020 -0700

    gdb: Fix from_tty argument to gdb.execute in Python.

    Prior to commit 56bcdbea2b, the from_tty keyword argument to the
    Python function gdb.execute controlled whether the command took input
    from the terminal. When from_tty=True, "starti" and similar commands
    prompted the user:

        (gdb) python gdb.execute("starti", from_tty=True)
        The program being debugged has been started already.
        Start it from the beginning? (y or n) y
        Starting program: /bin/true

        Program stopped.

    When from_tty=False, these commands did not prompt the user, and "yes"
    was assumed:

        (gdb) python gdb.execute("starti", from_tty=False)

        Program stopped.

    However, after commit 56bcdbea2b, the from_tty keyword argument no
    longer had this effect. For example, as of commit 7ade7fba75:

        (gdb) python gdb.execute("starti", from_tty=True)
        The program being debugged has been started already.
        Start it from the beginning? (y or n) [answered Y; input not from
terminal]
        Starting program: /bin/true

        Program stopped.

    Note the "[answered Y; input not from terminal]" in the output even
    though from_tty=True was requested.

    Looking at commit 56bcdbea2b, it seems that the behaviour of the
    from_tty argument was changed accidentally. The commit message said:

        Let gdb.execute handle multi-line commands

        This changes the Python API so that gdb.execute can now handle
        multi-line commands, like "commands" or "define".

    and there was no mention of changing the effect of the from_tty
    argument. It looks as though the code for setting the instream to
    nullptr was accidentally moved from execute_user_command() to
    execute_control_commands() along with the other scoped restores.

    Accordingly, the simplest way to fix this is to partially reverse
    commit 56bcdbea2b by moving the code for setting the instream to
    nullptr back to execute_user_command() where it was to begin with.

    Additionally, add a test case to reduce the risk of similar breakage
    in future.

    gdb/ChangeLog:

            PR python/26586
            * cli/cli-script.c (execute_control_commands): don't set
            instream to nullptr here as this breaks the from_tty argument
            to gdb.execute in Python.
            (execute_user_command): set instream to nullptr here instead.

    gdb/testsuite/ChangeLog:

            PR python/26586
            * gdb.python/python.exp: add test cases for the from_tty
            argument to gdb.execute.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
                   ` (7 preceding siblings ...)
  2020-09-26 18:02 ` cvs-commit at gcc dot gnu.org
@ 2020-09-28 20:16 ` cvs-commit at gcc dot gnu.org
  2020-10-08 17:42 ` simark at simark dot ca
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-28 20:16 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

--- Comment #7 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The gdb-10-branch branch has been updated by Joel Brobecker
<brobecke@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f6c03ee4ad37c883c008f62d603dba043c424a54

commit f6c03ee4ad37c883c008f62d603dba043c424a54
Author: Gareth Rees <grees@undo.io>
Date:   Sat Sep 26 11:01:45 2020 -0700

    gdb: Fix from_tty argument to gdb.execute in Python.

    Prior to commit 56bcdbea2b, the from_tty keyword argument to the
    Python function gdb.execute controlled whether the command took input
    from the terminal. When from_tty=True, "starti" and similar commands
    prompted the user:

        (gdb) python gdb.execute("starti", from_tty=True)
        The program being debugged has been started already.
        Start it from the beginning? (y or n) y
        Starting program: /bin/true

        Program stopped.

    When from_tty=False, these commands did not prompt the user, and "yes"
    was assumed:

        (gdb) python gdb.execute("starti", from_tty=False)

        Program stopped.

    However, after commit 56bcdbea2b, the from_tty keyword argument no
    longer had this effect. For example, as of commit 7ade7fba75:

        (gdb) python gdb.execute("starti", from_tty=True)
        The program being debugged has been started already.
        Start it from the beginning? (y or n) [answered Y; input not from
terminal]
        Starting program: /bin/true

        Program stopped.

    Note the "[answered Y; input not from terminal]" in the output even
    though from_tty=True was requested.

    Looking at commit 56bcdbea2b, it seems that the behaviour of the
    from_tty argument was changed accidentally. The commit message said:

        Let gdb.execute handle multi-line commands

        This changes the Python API so that gdb.execute can now handle
        multi-line commands, like "commands" or "define".

    and there was no mention of changing the effect of the from_tty
    argument. It looks as though the code for setting the instream to
    nullptr was accidentally moved from execute_user_command() to
    execute_control_commands() along with the other scoped restores.

    Accordingly, the simplest way to fix this is to partially reverse
    commit 56bcdbea2b by moving the code for setting the instream to
    nullptr back to execute_user_command() where it was to begin with.

    Additionally, add a test case to reduce the risk of similar breakage
    in future.

    gdb/ChangeLog:

            PR python/26586
            * cli/cli-script.c (execute_control_commands): don't set
            instream to nullptr here as this breaks the from_tty argument
            to gdb.execute in Python.
            (execute_user_command): set instream to nullptr here instead.

    gdb/testsuite/ChangeLog:

            PR python/26586
            * gdb.python/python.exp: add test cases for the from_tty
            argument to gdb.execute.

    (cherry picked from commit 8f9929bb97dc0f0fdf60269ac8c9a7d50746646f)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug python/26586] from_tty argument to Python's gdb.execute is no longer effective
  2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
                   ` (8 preceding siblings ...)
  2020-09-28 20:16 ` cvs-commit at gcc dot gnu.org
@ 2020-10-08 17:42 ` simark at simark dot ca
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2020-10-08 17:42 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26586

Simon Marchi <simark at simark dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Simon Marchi <simark at simark dot ca> ---
Marking as fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2020-10-08 17:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 15:23 [Bug python/26586] New: from_tty argument to Python's gdb.execute is no longer effective grees at undo dot io
2020-09-08 16:33 ` [Bug python/26586] " grees at undo dot io
2020-09-08 17:05 ` brobecker at gnat dot com
2020-09-10 17:35 ` simark at simark dot ca
2020-09-10 17:35 ` simark at simark dot ca
2020-09-10 17:36 ` simark at simark dot ca
2020-09-19 15:39 ` cbiesinger at google dot com
2020-09-22 10:24 ` grees at undo dot io
2020-09-26 18:02 ` cvs-commit at gcc dot gnu.org
2020-09-28 20:16 ` cvs-commit at gcc dot gnu.org
2020-10-08 17:42 ` simark at simark dot ca

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