aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2018-09-17 08:26:24 -0400
committerSimon Marchi <simon.marchi@ericsson.com>2018-09-17 08:26:24 -0400
commit8588b356927dabd582d1d67f87a161027cb2aed1 (patch)
tree2a2f8d2519cb33f2efd5c40fa9d72a40187b584e /gdb/python
parenta0a8a9340dc79116297627a0884c6a01543e4b34 (diff)
downloadgdb-8588b356927dabd582d1d67f87a161027cb2aed1.zip
gdb-8588b356927dabd582d1d67f87a161027cb2aed1.tar.gz
gdb-8588b356927dabd582d1d67f87a161027cb2aed1.tar.bz2
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").
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/python.c5
-rw-r--r--gdb/python/python.h3
2 files changed, 7 insertions, 1 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 1a0562a..c16305b 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1745,6 +1745,9 @@ do_start_initialization ()
#endif /* HAVE_PYTHON */
+/* See python.h. */
+cmd_list_element *python_cmd_element = nullptr;
+
void
_initialize_python (void)
{
@@ -1774,7 +1777,7 @@ This command is only a placeholder.")
);
add_com_alias ("pi", "python-interactive", class_obscure, 1);
- add_com ("python", class_obscure, python_command,
+ python_cmd_element = add_com ("python", class_obscure, python_command,
#ifdef HAVE_PYTHON
_("\
Evaluate a Python command.\n\
diff --git a/gdb/python/python.h b/gdb/python/python.h
index de58fd8..4b36f83 100644
--- a/gdb/python/python.h
+++ b/gdb/python/python.h
@@ -25,4 +25,7 @@
/* This is all that python exports to gdb. */
extern const struct extension_language_defn extension_language_python;
+/* Command element for the 'python' command. */
+extern cmd_list_element *python_cmd_element;
+
#endif /* GDB_PYTHON_H */