Home | History | Annotate | Line # | Download | only in gdb.mi
mi-var-invalidate-shlib.exp revision 1.1.1.2
      1  1.1.1.2  christos # Copyright 2007-2024 Free Software Foundation, Inc.
      2      1.1  christos 
      3      1.1  christos # This program is free software; you can redistribute it and/or modify
      4      1.1  christos # it under the terms of the GNU General Public License as published by
      5      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6      1.1  christos # (at your option) any later version.
      7      1.1  christos #
      8      1.1  christos # This program is distributed in the hope that it will be useful,
      9      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11      1.1  christos # GNU General Public License for more details.
     12      1.1  christos #
     13      1.1  christos # You should have received a copy of the GNU General Public License
     14      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15      1.1  christos #
     16      1.1  christos # Test that varobj are invalidated after the shlib they point to goes
     17      1.1  christos # away.
     18      1.1  christos 
     19      1.1  christos 
     20      1.1  christos load_lib mi-support.exp
     21      1.1  christos set MIFLAGS "-i=mi"
     22      1.1  christos 
     23  1.1.1.2  christos require allow_shlib_tests
     24      1.1  christos 
     25      1.1  christos standard_testfile .c -lib.c
     26      1.1  christos set shlib_path [standard_output_file ${testfile}-lib.so]
     27      1.1  christos 
     28      1.1  christos if { [gdb_compile_shlib $srcdir/$subdir/$srcfile2 $shlib_path {debug}] != "" } {
     29      1.1  christos     untested "failed to compile"
     30      1.1  christos     return -1
     31      1.1  christos }
     32      1.1  christos 
     33  1.1.1.2  christos set shlib_path_target [gdb_download_shlib $shlib_path]
     34      1.1  christos 
     35  1.1.1.2  christos set opts [list shlib_load debug additional_flags=-DSHLIB_PATH="${shlib_path_target}"]
     36      1.1  christos if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } {
     37      1.1  christos     untested "failed to compile"
     38      1.1  christos     return -1
     39      1.1  christos }
     40      1.1  christos 
     41      1.1  christos proc do_test { separate_debuginfo } {
     42      1.1  christos     if { [mi_clean_restart] } {
     43      1.1  christos 	unsupported "failed to start GDB"
     44      1.1  christos 	return
     45      1.1  christos     }
     46      1.1  christos 
     47      1.1  christos     # Start the process once and create varobjs referencing the loaded objfiles.
     48      1.1  christos     with_test_prefix "setup" {
     49  1.1.1.2  christos 	mi_locate_shlib $::shlib_path
     50      1.1  christos 	if { $separate_debuginfo } {
     51      1.1  christos 	    mi_load_shlibs ${::shlib_path}.debug
     52      1.1  christos 	}
     53      1.1  christos 	mi_delete_breakpoints
     54      1.1  christos 	mi_gdb_reinitialize_dir $::srcdir/$::subdir
     55      1.1  christos 	mi_gdb_load $::binfile
     56      1.1  christos 
     57      1.1  christos 	mi_runto foo -pending
     58      1.1  christos 
     59      1.1  christos 	mi_create_varobj global_var global_var "create global global_var"
     60      1.1  christos 	mi_create_varobj global_shlib_var global_shlib_var "create global gloal_shlib_var"
     61      1.1  christos 	mi_create_floating_varobj floating_local local_var "create floating local_var"
     62      1.1  christos 
     63      1.1  christos 	# Advance to a point where the shlib's objfile have been deleted.
     64      1.1  christos 	mi_continue_to "no_varobj_in_scope"
     65      1.1  christos     }
     66      1.1  christos 
     67      1.1  christos     with_test_prefix "after objfile deleted" {
     68      1.1  christos 	# The global shlib var was invalidated when the objfile got unloaded.
     69      1.1  christos 	mi_gdb_test "-var-update global_shlib_var" \
     70      1.1  christos 	    "\\^done,changelist=\\\[\{name=\"global_shlib_var\",in_scope=\"invalid\",has_more=\"0\"\}\]" \
     71      1.1  christos 	    "global_shlib_var invalidated"
     72      1.1  christos 
     73      1.1  christos 	# The floating var is still valid but not in scope.
     74      1.1  christos 	mi_gdb_test "-var-update floating_local" \
     75      1.1  christos 	    "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"false\",type_changed=\"false\",has_more=\"0\"}\\\]" \
     76      1.1  christos 	    "floating_local still valid but not in scope"
     77      1.1  christos 
     78      1.1  christos 	mi_gdb_test "-var-update global_var" \
     79      1.1  christos 	    "\\^done,changelist=\\\[\\\]" \
     80      1.1  christos 	    "global_var still valid"
     81      1.1  christos 
     82      1.1  christos 	# The varobj can be re-evaluated if the expression is valid in the current
     83      1.1  christos 	# frame.
     84      1.1  christos 	mi_continue_to "floating_varobj_in_scope"
     85      1.1  christos 	mi_gdb_test "-var-update floating_local" \
     86      1.1  christos 	    "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"true\",type_changed=\"true\",new_type=\"int\",new_num_children=\"0\",has_more=\"0\"}\\\]" \
     87      1.1  christos 	    "floating_local in scope with new type and value"
     88      1.1  christos     }
     89      1.1  christos 
     90      1.1  christos     # Reload the entire process
     91      1.1  christos     with_test_prefix "restart process" {
     92      1.1  christos 	mi_delete_breakpoints
     93      1.1  christos 	mi_gdb_load ${::binfile}
     94      1.1  christos 	mi_runto_main
     95      1.1  christos     }
     96      1.1  christos 
     97      1.1  christos     with_test_prefix "in new process" {
     98      1.1  christos 	# When reloading the symbol file, only the var for the global in the main
     99      1.1  christos 	# executable is re-created.
    100      1.1  christos 	mi_gdb_test "-var-update global_var" \
    101      1.1  christos 	    "\\^done,changelist=\\\[\\\]" \
    102      1.1  christos 	    "global_var recreated"
    103      1.1  christos 	mi_gdb_test "-var-update global_shlib_var" \
    104      1.1  christos 	    "\\^done,changelist=\\\[{name=\"global_shlib_var\",in_scope=\"invalid\",has_more=\"0\"}\\\]" \
    105      1.1  christos 	    "global_shlib_var invalid"
    106      1.1  christos 
    107      1.1  christos 	# Floating varobj should still be valid, but out of scope at the moment.
    108      1.1  christos 	mi_gdb_test "-var-update floating_local" \
    109      1.1  christos 	    "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"false\",type_changed=\"false\",has_more=\"0\"}\\\]" \
    110      1.1  christos 	    "floating_local still valid but not in scope"
    111      1.1  christos 
    112      1.1  christos 	# Continue inside foo
    113      1.1  christos 	mi_gdb_test "299-break-insert -f -t foo" \
    114      1.1  christos 	    "&\"Function \\\\\"foo\\\\\" not defined.\\\\n\"\r\n299\\^done,[mi_make_breakpoint_pending -type breakpoint -disp del -pending foo]"
    115      1.1  christos 	mi_send_resuming_command "exec-continue" "continue to foo"
    116      1.1  christos 	mi_expect_stop "breakpoint-hit" foo ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "arrived at foo"
    117      1.1  christos 
    118      1.1  christos 	# Floating varobj is still valid, and now in scope.
    119      1.1  christos 	mi_gdb_test "-var-update floating_local" \
    120      1.1  christos 	    "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"true\",type_changed=\"true\",new_type=\"struct bar\",new_num_children=\"2\",has_more=\"0\"}\\\]" \
    121      1.1  christos 	    "floating_local still valid and in scope"
    122      1.1  christos 
    123      1.1  christos 	# The var for the global in the shlib stays invalid even after reloading the shlib.
    124      1.1  christos 	mi_gdb_test "-var-update global_shlib_var" \
    125      1.1  christos 	    "\\^done,changelist=\\\[{name=\"global_shlib_var\",in_scope=\"invalid\",has_more=\"0\"}\\\]" \
    126      1.1  christos 	    "global_shlib_var invalid after shlib loaded"
    127      1.1  christos     }
    128      1.1  christos }
    129      1.1  christos 
    130      1.1  christos proc_with_prefix local_not_invalidated { separate_debuginfo } {
    131      1.1  christos     if { [mi_clean_restart] } {
    132      1.1  christos 	unsupported "failed to start GDB"
    133      1.1  christos 	return
    134      1.1  christos     }
    135      1.1  christos 
    136      1.1  christos     # Start the process once and create varobjs referencing the loaded objfiles.
    137      1.1  christos     with_test_prefix "setup" {
    138      1.1  christos 	mi_load_shlibs $::shlib_path
    139      1.1  christos 	if { $separate_debuginfo } {
    140      1.1  christos 	    mi_load_shlibs ${::shlib_path}.debug
    141      1.1  christos 	}
    142      1.1  christos 
    143      1.1  christos 	mi_gdb_reinitialize_dir $::srcdir/$::subdir
    144      1.1  christos 	mi_gdb_load $::binfile
    145      1.1  christos 
    146      1.1  christos 	mi_runto foo -pending
    147      1.1  christos 	mi_next "next"
    148      1.1  christos 	mi_create_varobj local_var local_var "create local varobj"
    149      1.1  christos     }
    150      1.1  christos 
    151      1.1  christos     # At this point we are stopped in the shared library.  If we reload symbols
    152      1.1  christos     # for the main binary, symbols for the shared library remain valid.  A
    153      1.1  christos     # varobj tracking variables in the scope of the shared library only should
    154      1.1  christos     # not be invalidated.
    155      1.1  christos     mi_gdb_load ${::binfile}
    156      1.1  christos     mi_gdb_test "-var-update local_var" \
    157      1.1  christos 	"\\^done,changelist=\\\[\\\]" \
    158      1.1  christos 	"local_var preserved"
    159      1.1  christos }
    160      1.1  christos 
    161      1.1  christos foreach_with_prefix separate_debuginfo {0 1} {
    162      1.1  christos     if { $separate_debuginfo } {
    163      1.1  christos 	gdb_gnu_strip_debug $::shlib_path
    164      1.1  christos     }
    165      1.1  christos 
    166      1.1  christos     do_test $separate_debuginfo
    167      1.1  christos     local_not_invalidated $separate_debuginfo
    168      1.1  christos }
    169