diff options
author | Yao Qi <yao.qi@linaro.org> | 2017-05-17 14:22:04 +0100 |
---|---|---|
committer | Yao Qi <yao.qi@linaro.org> | 2017-05-17 14:22:35 +0100 |
commit | 21873064e835ffb16e92048482e34f19e6a415da (patch) | |
tree | 55a7255c003a78c18b43e618c6b9c7a5f0120c8b /gdb | |
parent | 2b351b19efc8dd36ac8a8bda005c7411536b93ec (diff) | |
download | gdb-21873064e835ffb16e92048482e34f19e6a415da.zip gdb-21873064e835ffb16e92048482e34f19e6a415da.tar.gz gdb-21873064e835ffb16e92048482e34f19e6a415da.tar.bz2 |
Add alias command to cmd_list_element
When we add alias command, we call add_alias_cmd and pass the alias name
and command name. This implicitly requires the command and its prefix
commands are already added to cmdlist. This may not be true, for example,
add_com_alias ("tty", "set inferior-tty", class_alias, 0);
"inferior-tty" command is added to setlist, but setlist may not be added
to cmdlist (It depends on the order of related _initialize_XXX functions
called) so that we can't find "set inferior-tty" from cmdlist.
This patch fixes this problem by passing cmd_list_element of "inferior-tty"
to add_alias_cmd, so that cmd_list_element of "inferior-tty" doesn't have
to be reachable from cmdlist at that moment.
gdb:
2017-05-17 Yao Qi <yao.qi@linaro.org>
* cli/cli-decode.c (add_alias_cmd): New function.
* command.h (add_alias_cmd): Declare.
* infcmd.c (_initialize_infcmd): Don't call add_com_alias,
instead call add_alias_cmd.
gdb/testsuite:
2017-05-17 Simon Marchi <simon.marchi@ericsson.com>
* gdb.base/set-inferior-tty.exp (test_set_inferior_tty): Add
argument command.
(top-level): Invoke test_set_inferior_tty.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/cli/cli-decode.c | 29 | ||||
-rw-r--r-- | gdb/command.h | 6 | ||||
-rw-r--r-- | gdb/infcmd.c | 5 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/set-inferior-tty.exp | 10 |
6 files changed, 48 insertions, 15 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f2068d2..fdc2a40 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2017-05-17 Yao Qi <yao.qi@linaro.org> + + * cli/cli-decode.c (add_alias_cmd): New function. + * command.h (add_alias_cmd): Declare. + * infcmd.c (_initialize_infcmd): Don't call add_com_alias, + instead call add_alias_cmd. + 2017-05-17 Pedro Alves <palves@redhat.com> * Makefile.in (nat_extra_makefile_frag): Rename to ... diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index d45733e..d386d02 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -284,16 +284,10 @@ deprecate_cmd (struct cmd_list_element *cmd, const char *replacement) } struct cmd_list_element * -add_alias_cmd (const char *name, const char *oldname, enum command_class theclass, - int abbrev_flag, struct cmd_list_element **list) +add_alias_cmd (const char *name, cmd_list_element *old, + enum command_class theclass, int abbrev_flag, + struct cmd_list_element **list) { - const char *tmp; - struct cmd_list_element *old; - struct cmd_list_element *c; - - tmp = oldname; - old = lookup_cmd (&tmp, *list, "", 1, 1); - if (old == 0) { struct cmd_list_element *prehook, *prehookee, *posthook, *posthookee; @@ -307,7 +301,7 @@ add_alias_cmd (const char *name, const char *oldname, enum command_class theclas return 0; } - c = add_cmd (name, theclass, NULL, old->doc, list); + struct cmd_list_element *c = add_cmd (name, theclass, NULL, old->doc, list); /* If OLD->DOC can be freed, we should make another copy. */ if (old->doc_allocated) @@ -330,6 +324,21 @@ add_alias_cmd (const char *name, const char *oldname, enum command_class theclas return c; } +struct cmd_list_element * +add_alias_cmd (const char *name, const char *oldname, + enum command_class theclass, int abbrev_flag, + struct cmd_list_element **list) +{ + const char *tmp; + struct cmd_list_element *old; + + tmp = oldname; + old = lookup_cmd (&tmp, *list, "", 1, 1); + + return add_alias_cmd (name, old, theclass, abbrev_flag, list); +} + + /* Like add_cmd but adds an element for a command prefix: a name that should be followed by a subcommand to be looked up in another command list. PREFIXLIST should be the address of the variable diff --git a/gdb/command.h b/gdb/command.h index ae20021..aa179e9 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -141,6 +141,12 @@ extern struct cmd_list_element *add_alias_cmd (const char *, const char *, enum command_class, int, struct cmd_list_element **); +extern struct cmd_list_element *add_alias_cmd (const char *, + cmd_list_element *, + enum command_class, int, + struct cmd_list_element **); + + extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class, cmd_cfunc_ftype *fun, const char *, diff --git a/gdb/infcmd.c b/gdb/infcmd.c index f42c6d1..09060b5 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -3210,7 +3210,10 @@ is restored."), set_inferior_tty_command, show_inferior_tty_command, &setlist, &showlist); - add_com_alias ("tty", "set inferior-tty", class_alias, 0); + cmd_name = "inferior-tty"; + c = lookup_cmd (&cmd_name, setlist, "", -1, 1); + gdb_assert (c != NULL); + add_alias_cmd ("tty", c, class_alias, 0, &cmdlist); cmd_name = "args"; add_setshow_string_noescape_cmd (cmd_name, class_run, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index b672df3..91712e2 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-05-17 Simon Marchi <simon.marchi@ericsson.com> + + * gdb.base/set-inferior-tty.exp (test_set_inferior_tty): Add + argument command. + (top-level): Invoke test_set_inferior_tty. + 2017-05-04 Pedro Alves <palves@redhat.com> * gdb.python/py-record-btrace-threads.exp (check_insn_for_thread): diff --git a/gdb/testsuite/gdb.base/set-inferior-tty.exp b/gdb/testsuite/gdb.base/set-inferior-tty.exp index d84d4a3..480cffa 100644 --- a/gdb/testsuite/gdb.base/set-inferior-tty.exp +++ b/gdb/testsuite/gdb.base/set-inferior-tty.exp @@ -21,20 +21,22 @@ if {[build_executable $testfile.exp $testfile ${srcfile} ${compile_options}] == return -1 } -proc test_set_inferior_tty { } { +proc test_set_inferior_tty { command } { global binfile clean_restart ${binfile} - gdb_test_no_output "set inferior-tty hello" "set inferior-tty to hello" + gdb_test_no_output "$command hello" "set inferior-tty to hello" gdb_test "show inferior-tty" \ "Terminal for future runs of program being debugged is \"hello\"." \ "show inferior-tty shows hello" - gdb_test_no_output "set inferior-tty" "set inferior-tty to empty" + gdb_test_no_output "$command" "set inferior-tty to empty" gdb_test "show inferior-tty" \ "Terminal for future runs of program being debugged is \"\"." \ "show inferior-tty shows empty" } -test_set_inferior_tty +foreach_with_prefix command {"set inferior-tty" "tty"} { + test_set_inferior_tty $command +} |