1# Copyright 2003-2015 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# This is a test for the gdb invocation option --args. 17 18 19global GDBFLAGS 20 21# Skip test if target does not support argument passing. 22if [target_info exists noargs] { 23 return 24} 25 26standard_testfile 27 28if {[build_executable $testfile.exp $testfile \ 29 $srcfile {debug nowarnings}] == -1} { 30 untested $testfile.exp 31 return -1 32} 33 34proc args_test { name arglist } { 35 global srcdir 36 global subdir 37 global testfile 38 global hex 39 global decimal 40 41 clean_restart $testfile 42 43 runto_main 44 gdb_breakpoint [gdb_get_line_number "set breakpoint here"] 45 gdb_continue_to_breakpoint "breakpoint for $name" 46 47 set expected_len [expr 1 + [llength $arglist]] 48 gdb_test "print argc" "\\\$$decimal = $expected_len" "argc for $name" 49 50 set i 1 51 foreach arg $arglist { 52 gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \ 53 "argv\[$i\] for $name" 54 set i [expr $i + 1] 55 } 56} 57 58# 59# Test that the --args are processed correctly. 60# 61set old_gdbflags $GDBFLAGS 62 63set GDBFLAGS "$old_gdbflags --args $binfile 1 3" 64args_test basic {{1} {3}} 65 66# 67# Test that the --args are processed correctly even if one of them is empty. 68# The syntax needed is a little peculiar; DejaGNU treats the arguments as a 69# list and expands them itself, since no shell redirection is involved. 70# 71set GDBFLAGS "$old_gdbflags --args $binfile 1 {} 3" 72args_test "one empty" {{1} {} {3}} 73 74# 75# try with 2 empty args 76# 77set GDBFLAGS "$old_gdbflags --args $binfile 1 {} {} 3" 78args_test "two empty" {{1} {} {} 3} 79 80# Try with arguments containing literal single quotes. 81 82set GDBFLAGS "$old_gdbflags --args $binfile 1 '' 3" 83args_test "one empty (with single quotes)" {{1} {''} {3}} 84 85set GDBFLAGS "$old_gdbflags --args $binfile 1 '' '' 3" 86args_test "two empty (with single quotes)" {{1} {''} {''} {3}} 87 88# try with arguments containing literal newlines. 89 90set GDBFLAGS "-nx --args $binfile 1 {\n} 3" 91args_test "one newline" {{1} {\\n} {3}} 92 93set GDBFLAGS "-nx --args $binfile 1 {\n} {\n} 3" 94args_test "two newlines" {{1} {\\n} {\\n} {3}} 95 96set GDBFLAGS $old_gdbflags 97