binutils-gdb/gdb/cli
Simon Marchi 8588b35692 python: Make gdb.execute("show commands") work (PR 23669)
Since commit

  56bcdbea2b ("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").
2018-09-17 08:26:24 -04:00
..
cli-cmds.c Remove unnecessary casts from cli-cmds.c 2018-09-05 09:23:22 -06:00
cli-cmds.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cli-decode.c Remove old lint code 2018-07-30 08:29:47 -06:00
cli-decode.h Use counted_command_line everywhere 2018-05-04 15:58:06 -06:00
cli-dump.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cli-interp.c Use thread_info and inferior pointers more throughout 2018-06-21 17:09:31 +01:00
cli-interp.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cli-logging.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cli-script.c python: Make gdb.execute("show commands") work (PR 23669) 2018-09-17 08:26:24 -04:00
cli-script.h Let gdb.execute handle multi-line commands 2018-05-04 15:58:09 -06:00
cli-setshow.c Convert observers to C++ 2018-03-19 09:37:49 -06:00
cli-setshow.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cli-utils.c Add helper functions parse_flags and parse_flags_qcs 2018-07-12 22:50:26 +02:00
cli-utils.h Add helper functions parse_flags and parse_flags_qcs 2018-07-12 22:50:26 +02:00