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 that -list-thread-groups --available works. 17 18load_lib mi-support.exp 19set MIFLAGS "-i=mi" 20 21standard_testfile 22 23# Support for XML is needed to run this test. 24if {[gdb_skip_xml_test]} { 25 unsupported "list-thread-groups-available.exp" 26 return -1 27} 28 29if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 30 untested "failed to compile" 31 return -1 32} 33 34if [mi_gdb_start] { 35 return 36} 37 38if ![can_spawn_for_attach] { 39 return 40} 41 42set string_re {(?:[^\\"]|\\.)*} 43 44set id_re "id=\"$decimal\"" 45set type_re "type=\"process\"" 46set description_re "description=\"$string_re\"" 47set user_re "user=\"$string_re\"" 48 49# The CORES_RE regexp allows a process to be running on zero or more 50# cores. The former can happen if a process exits while GDB is 51# reading information out of /proc. 52set cores_re "cores=\\\[(\"$decimal\"(,\"$decimal\")*)?\\\]" 53 54# List all available processes. 55set process_entry_re "{${id_re},${type_re}(,$description_re)?(,$user_re)?(,$cores_re)?}" 56 57# The list can be long, so read entries one by one to avoid hitting the 58# timeout (especially when running with check-read1). 59set cmd "-list-thread-groups --available" 60set test "list available thread groups" 61gdb_test_multiple $cmd $test -prompt "$mi_gdb_prompt" { 62 -re "\\^done,groups=\\\[" { 63 # The beginning of the response. 64 exp_continue 65 } 66 67 -re "${process_entry_re}," { 68 # All entries except the last one. 69 exp_continue 70 } 71 72 -re "${process_entry_re}\\\]\r\n${mi_gdb_prompt}" { 73 # The last entry. 74 pass $gdb_test_name 75 } 76} 77 78# List specific processes, make sure there are two entries. 79set spawn_id_1 [remote_spawn target $binfile] 80set pid_1 [spawn_id_get_pid $spawn_id_1] 81set id_re_1 "id=\"$pid_1\"" 82 83set spawn_id_2 [remote_spawn target $binfile] 84set pid_2 [spawn_id_get_pid $spawn_id_2] 85set id_re_2 "id=\"$pid_2\"" 86 87# Unlike the earlier CORES_RE this list must contain at least one 88# core. Given that we know these processes will not exit while GDB is 89# reading their information from /proc we can expect at least one core 90# for each process. 91set cores_re "cores=\\\[\"$decimal\"(,\"$decimal\")*\\\]" 92 93set process_entry_re_1 "{${id_re_1},${type_re}(,$description_re)?(,$user_re)?(,$cores_re)?}" 94set process_entry_re_2 "{${id_re_2},${type_re}(,$description_re)?(,$user_re)?(,$cores_re)?}" 95 96set process_list_re "(${process_entry_re_1},${process_entry_re_2}|${process_entry_re_2},${process_entry_re_1})" 97 98mi_gdb_test \ 99 "-list-thread-groups --available i${pid_1} i${pid_2}" \ 100 "\\^done,groups=\\\[${process_list_re}\\\]" \ 101 "list available thread groups with filter" 102 103kill_wait_spawned_process $spawn_id_1 104kill_wait_spawned_process $spawn_id_2 105