]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/alias.exp
Ensure class_alias is only used for user-defined aliases.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / alias.exp
1 # Test the alias command.
2 # Copyright 2011-2020 Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 gdb_exit
18 gdb_start
19 gdb_reinitialize_dir $srcdir/$subdir
20
21 # Helper to test the -a option to alias.
22 # Aliases that are abbreviations of commands (e.g. r -> run)
23 # do not appear in help output.
24
25 proc test_abbrev_not_present { alias_name } {
26 global gdb_prompt
27 set alias_present 0
28 set test_name "abbrev $alias_name not present in help command list"
29 gdb_test_multiple "help aliases" $test_name {
30 -re "\[\r\n\]$alias_name \[^\r\n\]*" {
31 set alias_present 1
32 exp_continue
33 }
34 -re ".*$gdb_prompt $" {
35 if { !$alias_present } then {
36 pass $test_name
37 } else {
38 fail $test_name
39 }
40 }
41 }
42 }
43
44 proc test_abbrev_alias { name gdb_command test_value } {
45 gdb_test_no_output $gdb_command
46 gdb_test_no_output "$name print elements $test_value"
47 gdb_test "show print elements" "Limit .* is $test_value\[.\]" "verify $name"
48 test_abbrev_not_present $name
49 }
50
51 test_abbrev_alias set2 "alias -a set2=set" 42
52 test_abbrev_alias set3 "alias -a set3= set" 43
53 test_abbrev_alias set4 "alias -a set4 =set" 44
54 test_abbrev_alias set5 "alias -a set5 = set" 45
55 test_abbrev_alias set6 "alias -a -- set6 = set" 46
56 test_abbrev_alias -a "alias -a -- -a = set" 47
57
58 gdb_test "alias set2=set" "already exists: set2"
59 gdb_test "alias foo=bar" "Invalid command to alias to: bar"
60
61 gdb_test_no_output "alias spe = set p elem"
62 gdb_test_no_output "spe 50"
63 gdb_test "show print elements" "Limit .* is 50\[.\]" "verify spe"
64
65 gdb_test_no_output "alias set pr elms = set p elem"
66 gdb_test_no_output "set pr elms 51"
67 gdb_test "show print elements" "Limit .* is 51\[.\]" "verify set pr elms"
68 gdb_test "help set print" "set print elements, set print elms, spe .*"
69
70 # Verify alias command detects a non existing prefix.
71 gdb_test "alias assigne imprime limite-elements = set print elements" \
72 "ALIAS and COMMAND prefixes do not match\." \
73 "assigne imprime prefix not defined"
74
75 gdb_test "alias set imprime limite-elements = set print elements" \
76 "ALIAS and COMMAND prefixes do not match\." \
77 "set imprime prefix not defined"
78
79 # Verify alias command detects a non matching prefix.
80 gdb_test "alias set ada limite-elements = set print elements" \
81 "ALIAS and COMMAND prefixes do not match\." \
82 "mismatched prefix"
83
84 # Verify alias command detects a non matching prefix due to length.
85 gdb_test "alias set imprime-limite-elements = set print elements" \
86 "Mismatched command length between ALIAS and COMMAND\." \
87 "mismatched length"
88
89
90 # Gradually define the prefixes and the limite-elements command.
91 gdb_test_no_output "alias assigne = set" "alias assigne"
92 gdb_test_no_output "alias assigne imprime = set print" "alias assigne imprime"
93 gdb_test_no_output "alias assigne imprime limite-elements = set print elements" \
94 "alias assigne imprime limite-elements"
95
96 # Define an alias using the command prefix with a command using an alias prefix.
97 gdb_test_no_output "alias set print max-elements = assigne imprime elements" \
98 "alias set print max-elements using assigne imprime"
99
100
101 # Tests the resulting prefixes and commands.
102 gdb_test_no_output "assigne print elements 52"
103 gdb_test "show print elements" "Limit .* is 52\[.\]" "verify 52"
104
105 gdb_test_no_output "assigne imprime elements 53"
106 gdb_test "show print elements" "Limit .* is 53\[.\]" "verify 53"
107
108 gdb_test_no_output "assigne imprime limite-elements 54"
109 gdb_test "show print elements" "Limit .* is 54\[.\]" "verify 54"
110
111 gdb_test_no_output "set imprime elements 55"
112 gdb_test "show print elements" "Limit .* is 55\[.\]" "verify 55"
113
114 gdb_test_no_output "set print limite-elements 56"
115 gdb_test "show print elements" "Limit .* is 56\[.\]" "verify 56"
116
117 gdb_test_no_output "set print max-elements 57"
118 gdb_test "show print elements" "Limit .* is 57\[.\]" "verify 57"
119
120 # Test aliases having a common prefix.
121 gdb_test_no_output "alias abcd = backtrace"
122 gdb_test_no_output "alias abcde = backtrace"
123 gdb_test_no_output "alias fghij = backtrace"
124 gdb_test_no_output "alias fghi = backtrace"
125
126 # Verify help aliases shows the user defined aliases
127 gdb_test "help aliases" ".*abcd --.*.*abcde --.*"