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

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