Home | History | Annotate | Line # | Download | only in gdb.fortran
      1 # Copyright 2024-2025 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 standard_testfile "pointers.f90"
     17 load_lib fortran.exp
     18 
     19 if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
     20     {debug f90 quiet}]} {
     21     return -1
     22 }
     23 
     24 if {![fortran_runto_main]} {
     25     untested "could not run to main"
     26     return -1
     27 }
     28 
     29 # Depending on the compiler being used, the type names can be printed
     30 # differently.
     31 set logical [fortran_logical4]
     32 set real [fortran_real4]
     33 set int [fortran_int4]
     34 set complex [fortran_complex4]
     35 
     36 gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
     37 gdb_continue_to_breakpoint "Before pointer assignment"
     38 gdb_test "print logp" "= \\(PTR TO -> \\( $logical \\)\\) 0x0" \
     39     "print logp, not associated"
     40 gdb_test "print *logp" "Cannot access memory at address 0x0" \
     41     "print *logp, not associated"
     42 gdb_test "print comp" "= \\(PTR TO -> \\( $complex \\)\\) 0x0" \
     43     "print comp, not associated"
     44 gdb_test "print *comp" "Cannot access memory at address 0x0" \
     45     "print *comp, not associated"
     46 gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1 \\)\\) 0x0" \
     47     "print charp, not associated"
     48 gdb_test "print *charp" "Cannot access memory at address 0x0" \
     49     "print *charp, not associated"
     50 gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3 \\)\\) 0x0" \
     51     "print charap, not associated"
     52 gdb_test "print *charap" "Cannot access memory at address 0x0" \
     53     "print *charap, not associated"
     54 gdb_test "print intp" "= \\(PTR TO -> \\( $int \\)\\) 0x0" \
     55     "print intp, not associated"
     56 gdb_test "print *intp" "Cannot access memory at address 0x0" \
     57     "print *intp, not associated"
     58 gdb_test "print intap" " = <not associated>" "print intap, not associated"
     59 gdb_test "print realp" "= \\(PTR TO -> \\( $real \\)\\) 0x0" \
     60     "print realp, not associated"
     61 gdb_test "print *realp" "Cannot access memory at address 0x0" \
     62     "print *realp, not associated"
     63 gdb_test "print \$my_var = intp" "= \\(PTR TO -> \\( $int \\)\\) 0x0"
     64 gdb_test "print cyclicp1" "= \\( i = -?\\d+, p = 0x0 \\)" \
     65     "print cyclicp1, not associated"
     66 gdb_test "print cyclicp1%p" \
     67     "= \\(PTR TO -> \\( Type typewithpointer \\)\\) 0x0" \
     68     "print cyclicp1%p, not associated"
     69 
     70 gdb_breakpoint [gdb_get_line_number "Before value assignment"]
     71 gdb_continue_to_breakpoint "Before value assignment"
     72 gdb_test "print *(twop)%ivla2" "= <not allocated>"
     73 
     74 gdb_breakpoint [gdb_get_line_number "After value assignment"]
     75 gdb_continue_to_breakpoint "After value assignment"
     76 gdb_test "print logp" "= \\(PTR TO -> \\( $logical \\)\\) $hex\( <.*>\)?"
     77 gdb_test "print *logp" "= \\.TRUE\\."
     78 gdb_test "print comp" "= \\(PTR TO -> \\( $complex \\)\\) $hex\( <.*>\)?"
     79 gdb_test "print *comp" "= \\(1,2\\)"
     80 gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1 \\)\\) $hex\( <.*>\)?"
     81 gdb_test "print *charp" "= 'a'"
     82 gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3 \\)\\) $hex\( <.*>\)?"
     83 gdb_test "print *charap" "= 'abc'"
     84 gdb_test "print intp" "= \\(PTR TO -> \\( $int \\)\\) $hex\( <.*>\)?"
     85 gdb_test "print *intp" "= 10"
     86 gdb_test "print intap" "= \\(\\(1, 1, 3(, 1){7}\\) \\(1(, 1){9}\\)\\)" \
     87     "print intap, associated"
     88 gdb_test "print intvlap" "= \\(2, 2, 2, 4(, 2){6}\\)" \
     89     "print intvlap, associated"
     90 gdb_test "print realp" "= \\(PTR TO -> \\( $real \\)\\) $hex\( <.*>\)?"
     91 gdb_test "print *realp" "= 3\\.14000\\d+"
     92 gdb_test "print arrayOfPtr(2)%p" "= \\(PTR TO -> \\( Type two \\)\\) $hex\( <.*>\)?"
     93 gdb_test "print *(arrayOfPtr(2)%p)" \
     94     "= \\( ivla1 = \\(11, 12, 13\\), ivla2 = \\(\\(211, 221\\) \\(212, 222\\)\\) \\)"
     95 gdb_test "print arrayOfPtr(3)%p" "= \\(PTR TO -> \\( Type two \\)\\) 0x0" \
     96     "print arrayOfPtr(3)%p"
     97 
     98 gdb_test_multiple "print *(arrayOfPtr(3)%p)" \
     99     "print *(arrayOfPtr(3)%p), associated" {
    100     # gfortran
    101     -re -wrap "Cannot access memory at address 0x0" {
    102 	pass $gdb_test_name
    103     }
    104     # ifx
    105     -re -wrap "Location address is not set." {
    106 	pass $gdb_test_name
    107     }
    108 }
    109 
    110 gdb_test "print cyclicp1" "= \\( i = 1, p = $hex\( <.*>\)? \\)"
    111 gdb_test "print cyclicp1%p" "= \\(PTR TO -> \\( Type typewithpointer \\)\\) $hex\( <.*>\)?"
    112 gdb_test "print *((integer*) &inta + 2)" "= 3" "print temporary pointer, array"
    113 gdb_test "print *((integer*) &intvla + 3)" "= 4" "print temporary pointer, allocated vla"
    114 gdb_test "print \$pc" "\\(PTR TO -> \\( void \\(\\) \\(\\) \\)\\) $hex <pointers\\+\\d+>" \
    115     "Print program counter"
    116