1# Copyright 2017-2023 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# Test "info inferiors" and "info connections" with multiple targets. 17 18load_lib gdb-python.exp 19 20source $srcdir/$subdir/multi-target.exp.tcl 21 22if {![multi_target_prepare]} { 23 return 24} 25 26# Cache the result of calling skip_python_tests into a local variable. 27set run_python_tests [expr ! [skip_python_tests]] 28 29# Test "info inferiors" and "info connections". MULTI_PROCESS 30# indicates whether the multi-process feature of remote targets is 31# turned off or on. 32proc test_info_inferiors {multi_process} { 33 setup "off" 34 35 if { $::run_python_tests } { 36 gdb_test_no_output "source ${::remote_python_file}" "load python file" 37 } 38 39 gdb_test_no_output \ 40 "set remote multiprocess-feature-packet $multi_process" 41 42 # Get the description for inferior INF for when the current 43 # inferior id is CURRENT. 44 proc inf_desc {inf current} { 45 set ws "\[ \t\]+" 46 global decimal 47 upvar multi_process multi_process 48 49 if {($multi_process == "off") && ($inf == 2 || $inf == 5)} { 50 set desc "Remote target" 51 } else { 52 set desc "process ${decimal}" 53 } 54 55 set desc "${inf}${ws}${desc}${ws}" 56 if {$inf == $current} { 57 return "\\* $desc" 58 } else { 59 return " $desc" 60 } 61 } 62 63 # Get the "Num" column for CONNECTION for when the current 64 # inferior id is CURRENT_INF. 65 proc connection_num {connection current_inf} { 66 switch $current_inf { 67 "4" { set current_connection "1"} 68 "5" { set current_connection "4"} 69 "6" { set current_connection "5"} 70 default { set current_connection $current_inf} 71 } 72 if {$connection == $current_connection} { 73 return "\\* $connection" 74 } else { 75 return " $connection" 76 } 77 } 78 79 set ws "\[ \t\]+" 80 global decimal binfile 81 82 # Test "info connections" and "info inferior" by switching to each 83 # inferior one by one. 84 for {set inf 1} {$inf <= 6} {incr inf} { 85 with_test_prefix "inferior $inf" { 86 gdb_test "inferior $inf" "Switching to inferior $inf.*" 87 88 gdb_test "info connections" \ 89 [multi_line \ 90 "Num${ws}What${ws}Description${ws}" \ 91 "[connection_num 1 $inf]${ws}native${ws}Native process${ws}" \ 92 "[connection_num 2 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote target using gdb-specific protocol${ws}" \ 93 "[connection_num 3 $inf]${ws}core${ws}Local core dump file${ws}" \ 94 "[connection_num 4 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote target using gdb-specific protocol${ws}" \ 95 "[connection_num 5 $inf]${ws}core${ws}Local core dump file${ws}" \ 96 ] 97 98 if { $::run_python_tests } { 99 gdb_test "python info_connections()" \ 100 [multi_line \ 101 "Num${ws}What${ws}Description" \ 102 "[connection_num 1 $inf]${ws}native${ws}Native process" \ 103 "[connection_num 2 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote target using gdb-specific protocol" \ 104 "[connection_num 3 $inf]${ws}core${ws}Local core dump file" \ 105 "[connection_num 4 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote target using gdb-specific protocol" \ 106 "[connection_num 5 $inf]${ws}core${ws}Local core dump file" \ 107 ] 108 } 109 110 gdb_test "info inferiors" \ 111 [multi_line \ 112 "Num${ws}Description${ws}Connection${ws}Executable${ws}" \ 113 "[inf_desc 1 $inf]1 \\(native\\)${ws}${binfile}${ws}" \ 114 "[inf_desc 2 $inf]2 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \ 115 "[inf_desc 3 $inf]3 \\(core\\)${ws}${binfile}${ws}" \ 116 "[inf_desc 4 $inf]1 \\(native\\)${ws}${binfile}${ws}" \ 117 "[inf_desc 5 $inf]4 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \ 118 "[inf_desc 6 $inf]5 \\(core\\)${ws}${binfile}${ws}" \ 119 ] 120 121 if { $::run_python_tests } { 122 gdb_test "python info_inferiors()" \ 123 [multi_line \ 124 "Inferior 1, Connection #1: native" \ 125 "Inferior 2, Connection #2: extended-remote localhost:$decimal" \ 126 "Inferior 3, Connection #3: core" \ 127 "Inferior 4, Connection #1: native" \ 128 "Inferior 5, Connection #4: extended-remote localhost:$decimal" \ 129 "Inferior 6, Connection #5: core" \ 130 ] 131 } 132 } 133 } 134} 135 136if { $run_python_tests } { 137 set remote_python_file [gdb_remote_download host \ 138 ${srcdir}/${subdir}/${testfile}.py] 139} 140 141# Test "info inferiors" and "info connections" commands. 142with_test_prefix "info-inferiors" { 143 foreach_with_prefix multi_process {"on" "off"} { 144 test_info_inferiors $multi_process 145 } 146} 147 148multi_target_cleanup 149