summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/alias.exp
blob: 7a1a95528c6587e48d01d1b26e28f4d58c3bb6e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Test the alias command.
# Copyright 2011-2023 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir

# Helper to test the -a option to alias.
# Aliases that are abbreviations of commands (e.g. r -> run)
# do not appear in help output.

proc test_abbrev_not_present { alias_name } {
    global gdb_prompt
    set alias_present 0
    set test_name "abbrev $alias_name not present in help command list"
    gdb_test_multiple "help aliases" $test_name {
	-re "\[\r\n\]$alias_name \[^\r\n\]*" {
	    set alias_present 1
	    exp_continue
	}
	-re ".*$gdb_prompt $" {
	    if {!$alias_present} {
		pass $test_name
	    } else {
		fail $test_name
	    }
	}
    }
}

proc test_abbrev_alias { name gdb_command test_value } {
    gdb_test_no_output $gdb_command
    gdb_test_no_output "$name print elements $test_value"
    gdb_test "show print elements" "Limit .* is $test_value\[.\]" "verify $name"
    test_abbrev_not_present $name
}

test_abbrev_alias set2 "alias -a set2=set" 42
test_abbrev_alias set3 "alias -a set3= set" 43
test_abbrev_alias set4 "alias -a set4 =set" 44
test_abbrev_alias set5 "alias -a set5 = set" 45
test_abbrev_alias set6 "alias -a -- set6 = set" 46
test_abbrev_alias -a "alias -a -- -a = set" 47

gdb_test "alias set2=set" "already exists: set2"
gdb_test "alias foo=bar" "Undefined command: \"bar\".  Try \"help\"."

gdb_test_no_output "alias spe = set p elem"
gdb_test_no_output "spe 50"
gdb_test "show print elements" "Limit .* is 50\[.\]" "verify spe"

gdb_test_no_output "alias set pr elms = set p elem"
gdb_test_no_output "set pr elms 51"
gdb_test "show print elements" "Limit .* is 51\[.\]" "verify set pr elms"
gdb_test "help set print" "set print elements, set print elms, spe .*"

# Verify alias command detects a non existing prefix.
gdb_test "alias assigne imprime limite-elements = set print elements" \
    "ALIAS and COMMAND prefixes do not match\." \
    "assigne imprime prefix not defined"

gdb_test "alias set imprime limite-elements = set print elements" \
    "ALIAS and COMMAND prefixes do not match\." \
    "set imprime prefix not defined"

# Verify alias command detects a non matching prefix.
gdb_test "alias set ada limite-elements = set print elements" \
    "ALIAS and COMMAND prefixes do not match\." \
    "mismatched prefix"

# Verify alias command detects a non matching prefix due to length.
gdb_test "alias set imprime-limite-elements = set print elements" \
    "Mismatched command length between ALIAS and COMMAND\." \
    "mismatched length"


# Gradually define the prefixes and the limite-elements command.
gdb_test_no_output "alias assigne = set" "alias assigne"
gdb_test_no_output "alias assigne imprime = set print" "alias assigne imprime"
gdb_test_no_output "alias assigne imprime limite-elements = set print elements" \
    "alias assigne imprime limite-elements"

# Define an alias using the command prefix with a command using an alias prefix.
gdb_test_no_output "alias set print max-elements = assigne imprime elements" \
    "alias set print max-elements using assigne imprime"


# Tests the resulting prefixes and commands.
gdb_test_no_output "assigne print elements 52"
gdb_test "show print elements" "Limit .* is 52\[.\]" "verify 52"

gdb_test_no_output "assigne imprime elements 53"
gdb_test "show print elements" "Limit .* is 53\[.\]" "verify 53"

gdb_test_no_output "assigne imprime limite-elements 54"
gdb_test "show print elements" "Limit .* is 54\[.\]" "verify 54"

gdb_test_no_output "set imprime elements 55"
gdb_test "show print elements" "Limit .* is 55\[.\]" "verify 55"

gdb_test_no_output "set print limite-elements 56"
gdb_test "show print elements" "Limit .* is 56\[.\]" "verify 56"

gdb_test_no_output "set print max-elements 57"
gdb_test "show print elements" "Limit .* is 57\[.\]" "verify 57"

# Test aliases having a common prefix.
gdb_test_no_output "alias abcd  = backtrace"
gdb_test_no_output "alias abcde = backtrace"
gdb_test_no_output "alias fghij = backtrace"
gdb_test_no_output "alias fghi  = backtrace"

# Verify help aliases shows the user defined aliases
gdb_test "help aliases" ".*abcd --.*.*abcde --.*"