1# Copyright 2011-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 16standard_testfile .c 17 18# This test is Linux-only. 19if {![istarget *-*-linux*]} { 20 unsupported "info-os.exp" 21 return -1 22} 23 24# Support for XML-output is needed to run this test. 25if {[gdb_skip_xml_test]} { 26 unsupported "info-os.exp" 27 return -1 28} 29 30# Compile test program. 31if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] } { 32 return -1 33} 34 35if {![runto_main]} { 36 return -1 37} 38 39# Get PID of test program. 40set inferior_pid "" 41set test "get inferior process ID" 42gdb_test_multiple "call ((int (*) (void)) getpid) ()" $test { 43 -re ".* = ($decimal).*$gdb_prompt $" { 44 set inferior_pid $expect_out(1,string) 45 pass $test 46 } 47} 48if {$inferior_pid == ""} { 49 untested "failed to get pid" 50 return 51} 52 53gdb_breakpoint ${srcfile}:[gdb_get_line_number "Set breakpoint here"] 54gdb_continue_to_breakpoint "Set breakpoint here" 55 56# Get keys and IDs of the IPC object instances. 57set shmkey -1 58set test "get shared memory key" 59gdb_test_multiple "print shmkey" $test { 60 -re ".* = ($decimal).*$gdb_prompt $" { 61 set shmkey $expect_out(1,string) 62 pass $test 63 } 64} 65set shmid -1 66set test "get shared memory ID" 67gdb_test_multiple "print shmid" $test { 68 -re ".* = ($decimal).*$gdb_prompt $" { 69 set shmid $expect_out(1,string) 70 pass $test 71 } 72} 73 74set semkey -1 75set test "get semaphore key" 76gdb_test_multiple "print semkey" $test { 77 -re ".* = ($decimal).*$gdb_prompt $" { 78 set semkey $expect_out(1,string) 79 pass $test 80 } 81} 82 83set semid -1 84set test "get semaphore ID" 85gdb_test_multiple "print semid" $test { 86 -re ".* = ($decimal).*$gdb_prompt $" { 87 set semid $expect_out(1,string) 88 pass $test 89 } 90} 91 92set msgkey -1 93set test "get message queue key" 94gdb_test_multiple "print msgkey" $test { 95 -re ".* = ($decimal).*$gdb_prompt $" { 96 set msgkey $expect_out(1,string) 97 pass $test 98 } 99} 100 101set msqid -1 102set test "get message queue ID" 103gdb_test_multiple "print msqid" $test { 104 -re ".* = ($decimal).*$gdb_prompt $" { 105 set msqid $expect_out(1,string) 106 pass $test 107 } 108} 109 110# Get port number of test socket. 111set port -1 112set test "get socket port number" 113gdb_test_multiple "print port" $test { 114 -re ".* = ($decimal).*$gdb_prompt $" { 115 set port $expect_out(1,string) 116 pass $test 117 } 118} 119 120# Act like gdb_test but prevent: +ERROR: internal buffer is full. 121 122proc expect_multiline { command expect test } { 123 global gdb_prompt 124 125 # Do not duplicate FAILs from gdb_test_multiple. 126 set found 0 127 set ok 0 128 gdb_test_multiple $command $test { 129 -re "^$expect *\r\n" { 130 set found 1 131 exp_continue 132 } 133 -re "^$gdb_prompt $" { 134 if $found { 135 set ok 1 136 } 137 # Exit the loop. 138 } 139 -re "\r\n" { 140 # Drop the buffer. 141 exp_continue 142 } 143 } 144 gdb_assert { $ok } $test 145} 146 147# Test output of the 'info os' commands against the expected results. 148 149# pid user command cores 150expect_multiline "info os processes" "$inferior_pid +\\S+ +\\S*info-os +\[0-9,\]+" "get process list" 151 152# pgid leader pid command line 153expect_multiline "info os procgroups" "$inferior_pid +info-os +$inferior_pid +\\S*info-os" "get process groups" 154 155# pid command tid core 156expect_multiline "info os threads" "$inferior_pid +info-os +\\d+ +\\d+" "get threads" 157 158# pid command fd name 159expect_multiline "info os files" "$inferior_pid +info-os +\\d+ +/dev/null" "get file descriptors" 160 161# local address l-port remote addr r-port state user family protocol 162expect_multiline "info os sockets" "0\\.0\\.0\\.0 +$port +0\\.0\\.0\\.0 +0 +LISTEN +\\S+ +INET +STREAM" "get internet-domain sockets" 163 164# key shmid perm size creator command last op command num attached user group creator user creator group last shmat() time last shmdt() time last shmctl() time 165expect_multiline "info os shm" "$shmkey +$shmid +666 +4096 +info-os .*" "get shared-memory regions" 166 167# key semid perm num semaphores user group creator user creator group last semop() time last semctl() time 168expect_multiline "info os semaphores" "$semkey +$semid +666 +1 .*" "get semaphores" 169 170# key msqid perm num used bytes num messages last msgsnd() command last msgrcv() command user group creator user creator group last msgsnd() time last msgrcv() time last msgctl() time 171expect_multiline "info os msg" "$msgkey +$msqid +666 .*" "get message queues" 172 173gdb_test "info os unknown_entry" [multi_line \ 174 "warning: Empty data returned by target. Wrong osdata type\\\?" \ 175 "Can not fetch data now."] 176 177# The SysV IPC primitives linger on after the creating process is killed 178# unless they are destroyed explicitly, so allow the test program to tidy 179# up after itself. 180gdb_test "continue" "exited.*" 181