Bug 23669 - gdb.execute("show commands") doesn't work
Summary: gdb.execute("show commands") doesn't work
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 8.2.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-16 13:18 UTC by Simon Marchi
Modified: 2021-10-04 22:20 UTC (History)
11 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 Simon Marchi 2018-09-16 13:18:37 UTC
With gdb 8.2:

This command:

(gdb) show commands
   32  commands
   33  commands
   34  python gdb.execute("show commands")
   35  python gdb.execute("show version")
   36  python gdb.execute("show version")
   37  python gdb.execute("show commands")
   38  python gdb.execute("show commands")
   39  help
   40  show commands
   41  show commands

When executed with gdb.execute, doesn't work:

(gdb) python gdb.execute("show commands")
warning: bad breakpoint number at or near '0'

GDB appears to try to run the "commands" command and complain about the lack of breakpoint number.  With GDB master, it still tries to invoke the "commands" command, but the output is silent.
Comment 1 Simon Marchi 2018-09-16 17:43:26 UTC
This started to fail at

  56bcdbea2bed ("Let gdb.execute handle multi-line commands")

which means it started to fail in gdb 8.2.  A fix for this could make its way in gdb 8.2.1.  I have a tentative fix, which is to get rid of command_name_equals.
Comment 2 Sourceware Commits 2018-09-17 12:28:04 UTC
The master branch has been updated by Simon Marchi <simark@sourceware.org>:

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

commit 8588b356927dabd582d1d67f87a161027cb2aed1
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Mon Sep 17 08:26:24 2018 -0400

    python: Make gdb.execute("show commands") work (PR 23669)
    
    Since commit
    
      56bcdbea2bed ("Let gdb.execute handle multi-line commands")
    
    trying to use a command like gdb.execute("show commands") in Python
    fails.  GDB ends up trying to run the "commands" command.
    
    The reason is that GDB gets confused with the special "commands"
    command.  In process_next_line, the lookup_cmd_1 function returns the
    cmd_list_element representing the "commands" sub-command of "show".
    Lower, we check the cmd_list_element to see if it matches various
    control commands by name, including the "commands" command.  This is
    where we wrongfully conclude that the executed command must be
    "commands", when in reality it was "show commands".
    
    The fix proposed in this patch removes the comparisons by name, instead
    comparing the cmd_list_element object by pointer with the objects
    created at initialization time.
    
    Tested on the buildbot, though on a single builder (Fedora-x86_64-m64).
    
    gdb/ChangeLog:
    
    	PR python/23669
    	* breakpoint.c (commands_cmd_element): New.
    	(_initialize_breakpoint): Assign commands_cmd_element.
    	* breakpoint.h (commands_cmd_element): New.
    	* cli/cli-script.c (while_cmd_element, if_command,
    	define_cmd_element): New.
    	(command_name_equals): Remove.
    	(process_next_line): Compare commands by pointer, not by name.
    	(_initialize_cli_script): Assign the various cmd_list_element
    	variables.
    	* compile/compile.c (compile_cmd_element): New.
    	(_initialize_compile): Assign compile_cmd_element.
    	* compile/compile.h (compile_cmd_element): New.
    	* guile/guile.c (guile_cmd_element): New.
    	(install_gdb_commands): Assign guile_cmd_element.
    	* guile/guile.h (guile_cmd_element): New.
    	* python/python.c (python_cmd_element): New.
    	(_initialize_python): Assign python_cmd_element.
    	* python/python.h (python_cmd_element): New.
    	* tracepoint.c (while_stepping_cmd_element): New.
    	(_initialize_tracepoint): Assign while_stepping_cmd_element.
    	* tracepoint.h (while_stepping_cmd_element): New.
    
    gdb/testsuite/ChangeLog:
    
    	PR python/23669
    	* gdb.python/python.exp: Test gdb.execute("show commands").
Comment 3 Sourceware Commits 2018-09-17 18:18:23 UTC
The gdb-8.2-branch branch has been updated by Simon Marchi <simark@sourceware.org>:

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

commit b13ab533d38674e6273eb78eeef261d5b0655bbf
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Mon Sep 17 08:26:24 2018 -0400

    python: Make gdb.execute("show commands") work (PR 23669)
    
    Since commit
    
      56bcdbea2bed ("Let gdb.execute handle multi-line commands")
    
    trying to use a command like gdb.execute("show commands") in Python
    fails.  GDB ends up trying to run the "commands" command.
    
    The reason is that GDB gets confused with the special "commands"
    command.  In process_next_line, the lookup_cmd_1 function returns the
    cmd_list_element representing the "commands" sub-command of "show".
    Lower, we check the cmd_list_element to see if it matches various
    control commands by name, including the "commands" command.  This is
    where we wrongfully conclude that the executed command must be
    "commands", when in reality it was "show commands".
    
    The fix proposed in this patch removes the comparisons by name, instead
    comparing the cmd_list_element object by pointer with the objects
    created at initialization time.
    
    Tested on the buildbot, though on a single builder (Fedora-x86_64-m64).
    
    gdb/ChangeLog:
    
    	PR python/23669
    	* breakpoint.c (commands_cmd_element): New.
    	(_initialize_breakpoint): Assign commands_cmd_element.
    	* breakpoint.h (commands_cmd_element): New.
    	* cli/cli-script.c (while_cmd_element, if_command,
    	define_cmd_element): New.
    	(command_name_equals): Remove.
    	(process_next_line): Compare commands by pointer, not by name.
    	(_initialize_cli_script): Assign the various cmd_list_element
    	variables.
    	* compile/compile.c (compile_cmd_element): New.
    	(_initialize_compile): Assign compile_cmd_element.
    	* compile/compile.h (compile_cmd_element): New.
    	* guile/guile.c (guile_cmd_element): New.
    	(install_gdb_commands): Assign guile_cmd_element.
    	* guile/guile.h (guile_cmd_element): New.
    	* python/python.c (python_cmd_element): New.
    	(_initialize_python): Assign python_cmd_element.
    	* python/python.h (python_cmd_element): New.
    	* tracepoint.c (while_stepping_cmd_element): New.
    	(_initialize_tracepoint): Assign while_stepping_cmd_element.
    	* tracepoint.h (while_stepping_cmd_element): New.
    
    gdb/testsuite/ChangeLog:
    
    	PR python/23669
    	* gdb.python/python.exp: Test gdb.execute("show commands").
Comment 4 Simon Marchi 2018-09-17 18:19:17 UTC
Fixed by the patch above.
Comment 5 John Sydow 2020-03-10 01:28:59 UTC Comment hidden (spam)
Comment 6 Jack Marrow 2020-11-20 08:17:05 UTC Comment hidden (spam)
Comment 7 Harber Candelario 2020-12-24 06:24:41 UTC Comment hidden (spam)
Comment 8 James Khun 2021-03-09 07:04:36 UTC Comment hidden (spam)
Comment 9 Malikova 2021-03-13 16:34:12 UTC Comment hidden (spam)
Comment 10 Neolan Pressman 2021-05-06 12:59:06 UTC Comment hidden (spam)
Comment 11 Leo 2021-05-07 12:33:32 UTC Comment hidden (spam)
Comment 12 aya 2021-05-13 07:02:37 UTC Comment hidden (spam)
Comment 13 aya 2021-05-13 07:03:04 UTC Comment hidden (spam)
Comment 14 Joe Anderson 2021-06-01 06:00:34 UTC Comment hidden (spam)
Comment 15 Neolan Pressman 2021-06-22 12:39:08 UTC Comment hidden (spam)
Comment 16 Ken Hobbs 2021-06-22 17:24:50 UTC Comment hidden (spam)
Comment 17 David Montoya 2021-10-04 22:18:28 UTC Comment hidden (spam)
Comment 18 David Montoya 2021-10-04 22:20:05 UTC Comment hidden (spam)