Home | History | Annotate | Line # | Download | only in gdb.mi
mi-var-invalidate-shlib.exp revision 1.1
      1  1.1  christos # Copyright 2007-2023 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  christos if { [skip_shlib_tests] } {
     24  1.1  christos     return 0
     25  1.1  christos }
     26  1.1  christos 
     27  1.1  christos standard_testfile .c -lib.c
     28  1.1  christos set shlib_path [standard_output_file ${testfile}-lib.so]
     29  1.1  christos 
     30  1.1  christos if { [gdb_compile_shlib $srcdir/$subdir/$srcfile2 $shlib_path {debug}] != "" } {
     31  1.1  christos     untested "failed to compile"
     32  1.1  christos     return -1
     33  1.1  christos }
     34  1.1  christos 
     35  1.1  christos 
     36  1.1  christos set opts [list shlib_load debug additional_flags=-DSHLIB_PATH="${shlib_path}"]
     37  1.1  christos if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } {
     38  1.1  christos     untested "failed to compile"
     39  1.1  christos     return -1
     40  1.1  christos }
     41  1.1  christos 
     42  1.1  christos proc do_test { separate_debuginfo } {
     43  1.1  christos     if { [mi_clean_restart] } {
     44  1.1  christos 	unsupported "failed to start GDB"
     45  1.1  christos 	return
     46  1.1  christos     }
     47  1.1  christos 
     48  1.1  christos     # Start the process once and create varobjs referencing the loaded objfiles.
     49  1.1  christos     with_test_prefix "setup" {
     50  1.1  christos 	mi_load_shlibs $::shlib_path
     51  1.1  christos 	if { $separate_debuginfo } {
     52  1.1  christos 	    mi_load_shlibs ${::shlib_path}.debug
     53  1.1  christos 	}
     54  1.1  christos 	mi_delete_breakpoints
     55  1.1  christos 	mi_gdb_reinitialize_dir $::srcdir/$::subdir
     56  1.1  christos 	mi_gdb_load $::binfile
     57  1.1  christos 
     58  1.1  christos 	mi_runto foo -pending
     59  1.1  christos 
     60  1.1  christos 	mi_create_varobj global_var global_var "create global global_var"
     61  1.1  christos 	mi_create_varobj global_shlib_var global_shlib_var "create global gloal_shlib_var"
     62  1.1  christos 	mi_create_floating_varobj floating_local local_var "create floating local_var"
     63  1.1  christos 
     64  1.1  christos 	# Advance to a point where the shlib's objfile have been deleted.
     65  1.1  christos 	mi_continue_to "no_varobj_in_scope"
     66  1.1  christos     }
     67  1.1  christos 
     68  1.1  christos     with_test_prefix "after objfile deleted" {
     69  1.1  christos 	# The global shlib var was invalidated when the objfile got unloaded.
     70  1.1  christos 	mi_gdb_test "-var-update global_shlib_var" \
     71  1.1  christos 	    "\\^done,changelist=\\\[\{name=\"global_shlib_var\",in_scope=\"invalid\",has_more=\"0\"\}\]" \
     72  1.1  christos 	    "global_shlib_var invalidated"
     73  1.1  christos 
     74  1.1  christos 	# The floating var is still valid but not in scope.
     75  1.1  christos 	mi_gdb_test "-var-update floating_local" \
     76  1.1  christos 	    "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"false\",type_changed=\"false\",has_more=\"0\"}\\\]" \
     77  1.1  christos 	    "floating_local still valid but not in scope"
     78  1.1  christos 
     79  1.1  christos 	mi_gdb_test "-var-update global_var" \
     80  1.1  christos 	    "\\^done,changelist=\\\[\\\]" \
     81  1.1  christos 	    "global_var still valid"
     82  1.1  christos 
     83  1.1  christos 	# The varobj can be re-evaluated if the expression is valid in the current
     84  1.1  christos 	# frame.
     85  1.1  christos 	mi_continue_to "floating_varobj_in_scope"
     86  1.1  christos 	mi_gdb_test "-var-update floating_local" \
     87  1.1  christos 	    "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"true\",type_changed=\"true\",new_type=\"int\",new_num_children=\"0\",has_more=\"0\"}\\\]" \
     88  1.1  christos 	    "floating_local in scope with new type and value"
     89  1.1  christos     }
     90  1.1  christos 
     91  1.1  christos     # Reload the entire process
     92  1.1  christos     with_test_prefix "restart process" {
     93  1.1  christos 	mi_delete_breakpoints
     94  1.1  christos 	mi_gdb_load ${::binfile}
     95  1.1  christos 	mi_runto_main
     96  1.1  christos     }
     97  1.1  christos 
     98  1.1  christos     with_test_prefix "in new process" {
     99  1.1  christos 	# When reloading the symbol file, only the var for the global in the main
    100  1.1  christos 	# executable is re-created.
    101  1.1  christos 	mi_gdb_test "-var-update global_var" \
    102  1.1  christos 	    "\\^done,changelist=\\\[\\\]" \
    103  1.1  christos 	    "global_var recreated"
    104  1.1  christos 	mi_gdb_test "-var-update global_shlib_var" \
    105  1.1  christos 	    "\\^done,changelist=\\\[{name=\"global_shlib_var\",in_scope=\"invalid\",has_more=\"0\"}\\\]" \
    106  1.1  christos 	    "global_shlib_var invalid"
    107  1.1  christos 
    108  1.1  christos 	# Floating varobj should still be valid, but out of scope at the moment.
    109  1.1  christos 	mi_gdb_test "-var-update floating_local" \
    110  1.1  christos 	    "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"false\",type_changed=\"false\",has_more=\"0\"}\\\]" \
    111  1.1  christos 	    "floating_local still valid but not in scope"
    112  1.1  christos 
    113  1.1  christos 	# Continue inside foo
    114  1.1  christos 	mi_gdb_test "299-break-insert -f -t foo" \
    115  1.1  christos 	    "&\"Function \\\\\"foo\\\\\" not defined.\\\\n\"\r\n299\\^done,[mi_make_breakpoint_pending -type breakpoint -disp del -pending foo]"
    116  1.1  christos 	mi_send_resuming_command "exec-continue" "continue to foo"
    117  1.1  christos 	mi_expect_stop "breakpoint-hit" foo ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "arrived at foo"
    118  1.1  christos 
    119  1.1  christos 	# Floating varobj is still valid, and now in scope.
    120  1.1  christos 	mi_gdb_test "-var-update floating_local" \
    121  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\"}\\\]" \
    122  1.1  christos 	    "floating_local still valid and in scope"
    123  1.1  christos 
    124  1.1  christos 	# The var for the global in the shlib stays invalid even after reloading the shlib.
    125  1.1  christos 	mi_gdb_test "-var-update global_shlib_var" \
    126  1.1  christos 	    "\\^done,changelist=\\\[{name=\"global_shlib_var\",in_scope=\"invalid\",has_more=\"0\"}\\\]" \
    127  1.1  christos 	    "global_shlib_var invalid after shlib loaded"
    128  1.1  christos     }
    129  1.1  christos }
    130  1.1  christos 
    131  1.1  christos proc_with_prefix local_not_invalidated { separate_debuginfo } {
    132  1.1  christos     if { [mi_clean_restart] } {
    133  1.1  christos 	unsupported "failed to start GDB"
    134  1.1  christos 	return
    135  1.1  christos     }
    136  1.1  christos 
    137  1.1  christos     # Start the process once and create varobjs referencing the loaded objfiles.
    138  1.1  christos     with_test_prefix "setup" {
    139  1.1  christos 	mi_load_shlibs $::shlib_path
    140  1.1  christos 	if { $separate_debuginfo } {
    141  1.1  christos 	    mi_load_shlibs ${::shlib_path}.debug
    142  1.1  christos 	}
    143  1.1  christos 
    144  1.1  christos 	mi_gdb_reinitialize_dir $::srcdir/$::subdir
    145  1.1  christos 	mi_gdb_load $::binfile
    146  1.1  christos 
    147  1.1  christos 	mi_runto foo -pending
    148  1.1  christos 	mi_next "next"
    149  1.1  christos 	mi_create_varobj local_var local_var "create local varobj"
    150  1.1  christos     }
    151  1.1  christos 
    152  1.1  christos     # At this point we are stopped in the shared library.  If we reload symbols
    153  1.1  christos     # for the main binary, symbols for the shared library remain valid.  A
    154  1.1  christos     # varobj tracking variables in the scope of the shared library only should
    155  1.1  christos     # not be invalidated.
    156  1.1  christos     mi_gdb_load ${::binfile}
    157  1.1  christos     mi_gdb_test "-var-update local_var" \
    158  1.1  christos 	"\\^done,changelist=\\\[\\\]" \
    159  1.1  christos 	"local_var preserved"
    160  1.1  christos }
    161  1.1  christos 
    162  1.1  christos foreach_with_prefix separate_debuginfo {0 1} {
    163  1.1  christos     if { $separate_debuginfo } {
    164  1.1  christos 	gdb_gnu_strip_debug $::shlib_path
    165  1.1  christos     }
    166  1.1  christos 
    167  1.1  christos     do_test $separate_debuginfo
    168  1.1  christos     local_not_invalidated $separate_debuginfo
    169  1.1  christos }
    170