| # Test the alias command. |
| # Copyright 2011-2021 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 } then { |
| 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 --.*" |