| # Copyright (C) 1998 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 2 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, write to the Free Software |
| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| |
| # Please email any bugs, comments, and/or additions to this file to: |
| # bug-gdb@prep.ai.mit.edu |
| |
| # This file was written by Elena Zannoni (ezannoni@cygnus.com) |
| |
| # This file is part of the gdb testsuite |
| # |
| # tests for pointer arithmetic and pointer dereferencing |
| # with integer type variables and pointers to integers |
| # |
| |
| if $tracelevel then { |
| strace $tracelevel |
| } |
| |
| # |
| # test running programs |
| # |
| set prms_id 0 |
| set bug_id 0 |
| |
| set testfile "pointers" |
| set srcfile ${testfile}.c |
| set binfile ${objdir}/${subdir}/${testfile} |
| |
| if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } { |
| gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." |
| } |
| |
| |
| gdb_exit |
| gdb_start |
| gdb_reinitialize_dir $srcdir/$subdir |
| gdb_load ${binfile} |
| |
| |
| # |
| # set it up at a breakpoint so we can play with the variable values |
| # |
| |
| if ![runto_main] then { |
| perror "couldn't run to breakpoint" |
| continue |
| } |
| |
| gdb_test "next" "return 0;" "continuing after dummy()" |
| |
| |
| # |
| # let's see if gdb catches some illegal operations on pointers |
| # |
| # I must comment these out because strict type checking is not |
| # supported in this version of GDB. I do not really know |
| # what the expected gdb reply is. |
| # |
| |
| #send_gdb "print v_int_pointer2 = &v_int_pointer\n" |
| #gdb_expect { |
| # -re ".*.*$gdb_prompt $" { |
| # pass "illegal pointer assignment rejected" |
| # } |
| # -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" } |
| # timeout { fail "(timeout) illegal pointer assignment rejected" } |
| # } |
| |
| |
| #send_gdb "print v_unsigned_int_pointer = &v_int\n" |
| #gdb_expect { |
| # -re ".*.*$gdb_prompt $" { |
| # pass "illegal pointer assignment rejected" |
| # } |
| # -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" } |
| # timeout { fail "(timeout) ilegal pointer assignment rejected" } |
| # } |
| |
| #send_gdb "print v_unsigned_int_pointer == v_double_pointer\n" |
| #gdb_expect { |
| # -re ".*.*$gdb_prompt $" { |
| # pass "illegal pointer operation (+) rejected" |
| # } |
| # -re ".*$gdb_prompt $" { fail "illegal pointer operation (+) rejected" } |
| # timeout { fail "(timeout) illegal pointer operation (+) rejected" } |
| # } |
| |
| |
| #send_gdb "print v_unsigned_int_pointer * v_double_pointer\n" |
| #gdb_expect { |
| # -re ".*Argument to arithmetic operation not a number or boolean.*$gdb_prompt $" { |
| # pass "illegal pointer operation (*) rejected" |
| # } |
| # -re ".*$gdb_prompt $" { fail "illegal pointer operation (*) rejected" } |
| # timeout { fail "(timeout) illegal pointer operation (*) rejected" } |
| # } |
| |
| |
| #send_gdb "print v_unsigned_int_pointer = v_double_pointer\n" |
| #gdb_expect { |
| # -re ".*.*$gdb_prompt $" { |
| # pass "ilegal pointer assignment rejected" |
| # } |
| # -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" } |
| # timeout { fail "(timeout) illegal pointer assignment rejected" } |
| # } |
| |
| |
| #send_gdb "print v_unsigned_int_pointer = v_unsigned_int\n" |
| #gdb_expect { |
| # -re ".*.*$gdb_prompt $" { |
| # pass "illegal pointer assignment rejected" |
| # } |
| # -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" } |
| # timeout { fail "(timeout) illegal pointer assignment rejected" } |
| # } |
| |
| gdb_test "set variable v_int_pointer=&v_int_array\[0\]" "" "set pointer to beginning of array" |
| gdb_test "set variable v_int_pointer2=&v_int_array\[1\]" "" "set pointer to end of array" |
| |
| |
| send_gdb "print *v_int_pointer\n" |
| gdb_expect { |
| -re ".*= 6.*$gdb_prompt $" { |
| pass "print object pointed to" |
| } |
| -re ".*$gdb_prompt $" { fail "print object pointed to" } |
| timeout { fail "(timeout) print object pointed to" } |
| } |
| |
| send_gdb "print *v_int_pointer2\n" |
| gdb_expect { |
| -re ".*= 18.*$gdb_prompt $" { |
| pass "print object pointed to" |
| } |
| -re ".*$gdb_prompt $" { fail "print object pointed to" } |
| timeout { fail "(timeout) print object pointed to" } |
| } |
| |
| |
| send_gdb "print v_int_pointer == v_int_pointer2\n" |
| gdb_expect { |
| -re ".*= 0.*$gdb_prompt $" { |
| pass "pointer1==pointer2" |
| } |
| -re ".*$gdb_prompt $" { fail "pointer1==pointer2" } |
| timeout { fail "(timeout) pointer1==pointer2" } |
| } |
| |
| send_gdb "print v_int_pointer != v_int_pointer2\n" |
| gdb_expect { |
| -re ".*= 1.*$gdb_prompt $" { |
| pass "pointer1!=pointer2" |
| } |
| -re ".*$gdb_prompt $" { fail "pointer1!=pointer2" } |
| timeout { fail "(timeout) pointer1!=pointer2" } |
| } |
| |
| |
| send_gdb "print v_int_pointer <= v_int_pointer2\n" |
| gdb_expect { |
| -re ".*= 1.*$gdb_prompt $" { |
| pass "pointer1<=pointer2" |
| } |
| -re ".*$gdb_prompt $" { fail "pointer1<=pointer2" } |
| timeout { fail "(timeout) pointer1<=pointer2" } |
| } |
| |
| |
| send_gdb "print v_int_pointer >= v_int_pointer2\n" |
| gdb_expect { |
| -re ".*= 0.*$gdb_prompt $" { |
| pass "pointer1>=pointer2" |
| } |
| -re ".*$gdb_prompt $" { fail "pointer1>=pointer2" } |
| timeout { fail "(timeout) pointer1>=pointer2" } |
| } |
| |
| |
| send_gdb "print v_int_pointer < v_int_pointer2\n" |
| gdb_expect { |
| -re ".*= 1.*$gdb_prompt $" { |
| pass "pointer1<pointer2" |
| } |
| -re ".*$gdb_prompt $" { fail "pointer1<pointer2" } |
| timeout { fail "(timeout) pointer1<pointer2" } |
| } |
| |
| send_gdb "print v_int_pointer > v_int_pointer2\n" |
| gdb_expect { |
| -re ".*= 0.*$gdb_prompt $" { |
| pass "pointer1>pointer2" |
| } |
| -re ".*$gdb_prompt $" { fail "pointer1>pointer2" } |
| timeout { fail "(timeout) pointer1>pointer2" } |
| } |
| |
| |
| gdb_test "set variable y = *v_int_pointer++" "" "set y = *v_int_pointer++" |
| send_gdb "print y\n" |
| gdb_expect { |
| -re ".*= 6.*$gdb_prompt $" { |
| send_gdb "print *v_int_pointer\n" |
| gdb_expect { |
| -re ".*= 18.*$gdb_prompt $" { |
| pass "pointer assignment and increment" |
| } |
| -re ".*$gdb_prompt $" { fail "pointer assignment and increment" } |
| timeout { fail "(timeout) pointer assignment and increment" } |
| } |
| } |
| -re ".*$gdb_prompt $" { fail "pointer assignment and increment" } |
| timeout { fail "(timeout) pointer assignment and increment" } |
| } |
| |
| |
| |
| |
| gdb_test "set variable y = *--v_int_pointer2" "" "set y = *--v_int_pointer2" |
| send_gdb "print y\n" |
| gdb_expect { |
| -re ".*= 6.*$gdb_prompt $" { |
| send_gdb "print *v_int_pointer2\n" |
| gdb_expect { |
| -re ".*= 6.*$gdb_prompt $" { |
| pass "pointer decrement and assignment" |
| } |
| -re ".*$gdb_prompt $" { fail "pointer decrement and assignment" } |
| timeout { fail "(timeout) pointer decrement and assignment" } |
| } |
| } |
| -re ".*$gdb_prompt $" { fail "pointer decrement and assignment" } |
| timeout { fail "(timeout) pointer decrement and assignment" } |
| } |
| |
| gdb_test "set variable y =v_int_pointer-v_int_pointer2" "" "set y =v_int_pointer-v_int_pointer2" |
| send_gdb "print y\n" |
| gdb_expect { |
| -re ".*= 1.*$gdb_prompt $" { |
| pass "pointer1-pointer2" |
| } |
| -re ".*$gdb_prompt $" { fail "pointer1-pointer2" } |
| timeout { fail "(timeout) pointer1-pointer2" } |
| } |
| |
| gdb_test "set variable v_int_pointer=v_int_array" "" "set v_int_pointer=v_int_array" |
| send_gdb "print *v_int_pointer\n" |
| gdb_expect { |
| -re ".*= 6.*$gdb_prompt $" { |
| pass "print array element through pointer" |
| } |
| -re ".*$gdb_prompt $" { fail "print array element through pointer" } |
| timeout { fail "(timeout) print array element through pointer" } |
| } |
| |
| |
| send_gdb "print *(v_int_pointer+1)\n" |
| gdb_expect { |
| -re ".*= 18.*$gdb_prompt $" { |
| pass "print array element through pointer" |
| } |
| -re ".*$gdb_prompt $" { fail "print array element through pointer" } |
| timeout { fail "(timeout) print array element through pointer" } |
| } |
| |
| # test print elements of array through pointers |
| |
| send_gdb "print (*rptr)\[0\]\n" |
| gdb_expect { |
| -re ".*= 0.*$gdb_prompt $" { |
| pass "print array element through pointer" |
| } |
| -re ".*$gdb_prompt $" { fail "print array element through pointer" } |
| timeout { fail "(timeout) print array element through pointer" } |
| } |
| |
| send_gdb "print (*rptr)\[1\]\n" |
| gdb_expect { |
| -re ".*= 1.*$gdb_prompt $" { |
| pass "print array element through pointer" |
| } |
| -re ".*$gdb_prompt $" { fail "print array element through pointer" } |
| timeout { fail "(timeout) print array element through pointer" } |
| } |
| |
| |
| send_gdb "print (*rptr)\[2\]\n" |
| gdb_expect { |
| -re ".*= 2.*$gdb_prompt $" { |
| pass "print array element through pointer" |
| } |
| -re ".*$gdb_prompt $" { fail "print array element through pointer" } |
| timeout { fail "(timeout) print array element through pointer" } |
| } |
| |
| gdb_test "set variable rptr = rptr+1" "" "increment rptr" |
| |
| send_gdb "print (*rptr)\[0\]\n" |
| gdb_expect { |
| -re ".*= 3.*$gdb_prompt $" { |
| pass "print array element through pointer" |
| } |
| -re ".*$gdb_prompt $" { fail "print array element through pointer" } |
| timeout { fail "(timeout) print array element through pointer" } |
| } |
| |
| |
| send_gdb "print (*rptr)\[1\]\n" |
| gdb_expect { |
| -re ".*= 4.*$gdb_prompt $" { |
| pass "print array element through pointer" |
| } |
| -re ".*$gdb_prompt $" { fail "print array element through pointer" } |
| timeout { fail "(timeout) print array element through pointer" } |
| } |
| |
| |
| send_gdb "print (*rptr)\[2\]\n" |
| gdb_expect { |
| -re ".*= 5.*$gdb_prompt $" { |
| pass "print array element through pointer" |
| } |
| -re ".*$gdb_prompt $" { fail "print array element through pointer" } |
| timeout { fail "(timeout) print array element through pointer" } |
| } |
| |
| |
| send_gdb "print *( *(matrix+1) +2)\n" |
| gdb_expect { |
| -re ".*= 5.*$gdb_prompt $" { |
| pass "print array element w/ pointer arithmetic" |
| } |
| -re ".*$gdb_prompt $" { fail "print array element w/ pointer arithemtic" } |
| timeout { fail "(timeout) print array element w/ pointer arithmetic" } |
| } |
| |
| |
| send_gdb "print **ptr_to_ptr_to_float\n" |
| gdb_expect { |
| -re ".*= 100.*$gdb_prompt $" { |
| pass "print through ptr to ptr" |
| } |
| -re ".*$gdb_prompt $" { fail "print through ptr to ptr" } |
| timeout { fail "(timeout) print through ptr to ptr" } |
| } |