Bug 23714 - Command repetition stops working after gdb.execute
Summary: Command repetition stops working after gdb.execute
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: 8.2
: P2 normal
Target Milestone: 8.2.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-25 19:20 UTC by Gonçalo Santos
Modified: 2018-11-21 18:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gonçalo Santos 2018-09-25 19:20:04 UTC
GDB Dashboard is an init configuration which provides a modular visual interface for GDB using the Python scripting support. 

In order to get some information it needs, it may call gdb.execute(command, to_string=True) (which implies from_tty=False). Some of the commands that cause the dashboard to redraw (which, in turn, makes it call gdb.execute), cannot be repeated by just entering an empty line. 

When disabling the components that call that function, the functionality is restored.

A simpler reproduction is to enter "python gdb.execute('echo asd')" as a command, and see that it is not repeated when entering empty lines. In prior GDB versions, it will successfully print asd on each enter.

This bug was initially discussed here: https://github.com/cyrus-and/gdb-dashboard/issues/128
Comment 1 Benno Fünfstück 2018-10-19 21:46:17 UTC
This is similar to https://sourceware.org/bugzilla/show_bug.cgi?id=12216 and regressed due to the recent changes to make gdb.execute support multi-line.

The following patch has a test and should fix the issue:

diff --git a/gdb/python/python.c b/gdb/python/python.c
index 8fbce78469..784b56cec5 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -583,6 +583,8 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
 
   std::string to_string_res;
 
+  scoped_restore preventer = prevent_dont_repeat ();
+
   TRY
     {
       struct interp *interp;
@@ -612,7 +614,6 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
 	interp = interp_lookup (current_ui, "console");
 	current_uiout = interp->interp_ui_out ();
 
-	scoped_restore preventer = prevent_dont_repeat ();
 	if (to_string)
 	  to_string_res = execute_control_commands_to_string (lines.get (),
 							      from_tty);
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index 0723507af3..cb76a0f8e6 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -121,6 +121,7 @@ gdb_test "python print (x)" "23"
 
 gdb_test "python gdb.execute('echo 2\\necho 3\\\\n\\n')" "23" \
     "multi-line execute"
+gdb_test " " "23" "test that gdb.execute does not affect repeat history"
 
 # Test post_event.
 gdb_py_test_multiple "post event insertion" \
Comment 2 Tom Tromey 2018-11-14 15:59:41 UTC
(In reply to Benno Fünfstück from comment #1)
> This is similar to https://sourceware.org/bugzilla/show_bug.cgi?id=12216 and
> regressed due to the recent changes to make gdb.execute support multi-line.
> 
> The following patch has a test and should fix the issue:

Thanks for the patch.
gdb patches are reviewed on the mailing list; see
https://sourceware.org/gdb/wiki/ContributionChecklist
for the contribution guidelines.  Would you mind sending it
to the list, following that checklist?
Comment 3 cvs-commit@gcc.gnu.org 2018-11-21 17:09:01 UTC
The master branch has been updated by Pedro Alves <palves@sourceware.org>:

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

commit 1c97054b87495b008c6028d697deff61c9fb0b6e
Author: Benno F�nfst�ck <benno.fuenfstueck@gmail.com>
Date:   Wed Nov 21 17:06:05 2018 +0000

    Make command-repeat work after gdb.execute
    
    Since commit
    
      56bcdbea2bed ("Let gdb.execute handle multi-line commands")
    
    command repetition after using the `gdb.execute` Python function
    fails (the previous command is not repeated anymore). This happens
    because read_command_lines_1 sets dont_repeat, but the call to
    prevent_dont_repeat in execute_gdb_command is later.
    
    The fix is to move the call to prevent_dont_repeat to the beginning of
    the function.
    
    Tested on my laptop (ArchLinux-x86_64).
    
    gdb/ChangeLog:
    
    	PR python/23714
    	* gdb/python/python.c (execute_gdb_command): Call
    	prevent_dont_repeat earlier to avoid affecting dont_repeat.
    
    gdb/testuite/ChangeLog:
    
    	PR python/23714
    	* gdb.python/python.exp: Test command repetition after
    	gdb.execute.
Comment 4 cvs-commit@gcc.gnu.org 2018-11-21 17:25:44 UTC
The gdb-8.2-branch branch has been updated by Pedro Alves <palves@sourceware.org>:

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

commit 7d9e516326ff542b3c9c85a3c08be2622d9126b6
Author: Benno F�nfst�ck <benno.fuenfstueck@gmail.com>
Date:   Wed Nov 21 17:16:25 2018 +0000

    Make command-repeat work after gdb.execute
    
    Since commit
    
      56bcdbea2bed ("Let gdb.execute handle multi-line commands")
    
    command repetition after using the `gdb.execute` Python function
    fails (the previous command is not repeated anymore). This happens
    because read_command_lines_1 sets dont_repeat, but the call to
    prevent_dont_repeat in execute_gdb_command is later.
    
    The fix is to move the call to prevent_dont_repeat to the beginning of
    the function.
    
    Tested on my laptop (ArchLinux-x86_64).
    
    gdb/ChangeLog:
    
    	PR python/23714
    	* gdb/python/python.c (execute_gdb_command): Call
    	prevent_dont_repeat earlier to avoid affecting dont_repeat.
    
    gdb/testuite/ChangeLog:
    
    	PR python/23714
    	* gdb.python/python.exp: Test command repetition after
    	gdb.execute.
Comment 5 Pedro Alves 2018-11-21 18:07:04 UTC
Fix merged.