1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2019-2023 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Test the "default-args" arguments and completion of alias command.
20 load_lib completion-support.exp
24 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
28 clean_restart $binfile
30 # Basic/core tests using user-visible commands.
31 with_test_prefix "basics" {
32 # Define an alias to pretty print something.
33 gdb_test "print g_s" " = {a = 1, b = 2, c = 3}" "simple print"
34 gdb_test_no_output "alias PP = print -pretty --" "alias PP"
35 gdb_test "help PP" "print, PP, inspect, p\r\n alias PP = print -pretty --\r\n.*"
44 # Define an alias of frame apply all with some default args.
45 gdb_test_no_output "alias frame apply tout = frame apply all -past-entry -past-main" \
46 "alias frame apply tout"
47 gdb_test "help frame apply tout" \
48 "frame apply all, frame apply tout\r\n alias frame apply tout = frame apply all -past-entry -past-main\r\n.*"
51 gdb_test "help aliases" \
53 "User-defined aliases of other commands." \
57 "PP -- Print value of expression EXP." \
58 " alias PP = print -pretty --" \
59 "frame apply tout -- Apply a command to all frames." \
60 " alias frame apply tout = frame apply all -past-entry -past-main" \
66 with_test_prefix "errors" {
67 # Try an unknown root setting.
68 gdb_test "alias wrong = xxxx yyyy -someoption" \
69 "Undefined command: \"xxxx\". Try \"help\"\\."
71 # Try ambiguous command.
72 gdb_test "alias wrong = a" \
73 "Ambiguous command \"a\":.*" "ambiguous a"
74 gdb_test "alias wrong = frame a" \
75 "Ambiguous frame command \"a\":.*" "ambiguous frame a"
80 with_test_prefix "completion" {
81 test_gdb_complete_unique \
85 test_gdb_complete_unique \
86 "alias set print items = set pri" \
87 "alias set print items = set print"
89 test_gdb_complete_unique \
90 "alias set print items = set print ele" \
91 "alias set print items = set print elements"
93 test_gdb_complete_unique \
94 "alias btfu = backt" \
95 "alias btfu = backtrace"
97 test_gdb_complete_unique \
98 "alias btfu = backtrace -fu" \
99 "alias btfu = backtrace -full"
101 test_gdb_complete_unique \
102 "alias btfu = backtrace -full -past-e" \
103 "alias btfu = backtrace -full -past-entry"
105 gdb_test_no_output "alias btfu = backtrace -full -past-entry" \
110 # Check alias of alias.
111 with_test_prefix "alias_of_alias" {
112 # Verify we can alias an alias that has no default args.
113 # We allow an alias of an alias, to be backward compatible with
115 gdb_test_no_output "alias aaa = backtrace"
116 gdb_test_no_output "alias bbb = backtrace"
118 # Verify that we cannot define an alias of an alias that has default args.
119 gdb_test_no_output "alias ccc = backtrace -full"
120 gdb_test "alias ddd = ccc" \
121 "Cannot define an alias of an alias that has default args"