1 # Copyright 2011-2022 Free Software Foundation, Inc.
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.
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.
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/>.
18 # This test is Linux-only.
19 if ![istarget *-*-linux*] then {
20 unsupported "info-os.exp"
24 # Support for XML-output is needed to run this test.
25 if [gdb_skip_xml_test] then {
26 unsupported "info-os.exp"
30 # Compile test program.
31 if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] } {
35 if ![runto_main] then {
39 # Get PID of test program.
41 set test "get inferior process ID"
42 gdb_test_multiple "call (int) getpid()" $test {
43 -re ".* = ($decimal).*$gdb_prompt $" {
44 set inferior_pid $expect_out(1,string)
48 if {$inferior_pid == ""} {
49 untested "failed to get pid"
53 gdb_breakpoint ${srcfile}:[gdb_get_line_number "Set breakpoint here"]
54 gdb_continue_to_breakpoint "Set breakpoint here"
56 # Get keys and IDs of the IPC object instances.
58 set test "get shared memory key"
59 gdb_test_multiple "print shmkey" $test {
60 -re ".* = ($decimal).*$gdb_prompt $" {
61 set shmkey $expect_out(1,string)
66 set test "get shared memory ID"
67 gdb_test_multiple "print shmid" $test {
68 -re ".* = ($decimal).*$gdb_prompt $" {
69 set shmid $expect_out(1,string)
75 set test "get semaphore key"
76 gdb_test_multiple "print semkey" $test {
77 -re ".* = ($decimal).*$gdb_prompt $" {
78 set semkey $expect_out(1,string)
84 set test "get semaphore ID"
85 gdb_test_multiple "print semid" $test {
86 -re ".* = ($decimal).*$gdb_prompt $" {
87 set semid $expect_out(1,string)
93 set test "get message queue key"
94 gdb_test_multiple "print msgkey" $test {
95 -re ".* = ($decimal).*$gdb_prompt $" {
96 set msgkey $expect_out(1,string)
102 set test "get message queue ID"
103 gdb_test_multiple "print msqid" $test {
104 -re ".* = ($decimal).*$gdb_prompt $" {
105 set msqid $expect_out(1,string)
110 # Get port number of test socket.
112 set test "get socket port number"
113 gdb_test_multiple "print port" $test {
114 -re ".* = ($decimal).*$gdb_prompt $" {
115 set port $expect_out(1,string)
120 # Act like gdb_test but prevent: +ERROR: internal buffer is full.
122 proc expect_multiline { command expect test } {
125 # Do not duplicate FAILs from gdb_test_multiple.
128 gdb_test_multiple $command $test {
129 -re "^$expect *\r\n" {
133 -re "^$gdb_prompt $" {
144 gdb_assert { $ok } $test
147 # Test output of the 'info os' commands against the expected results.
149 # pid user command cores
150 expect_multiline "info os processes" "$inferior_pid +\\S+ +\\S*info-os +\[0-9,\]+" "get process list"
152 # pgid leader pid command line
153 expect_multiline "info os procgroups" "$inferior_pid +info-os +$inferior_pid +\\S*info-os" "get process groups"
155 # pid command tid core
156 expect_multiline "info os threads" "$inferior_pid +info-os +\\d+ +\\d+" "get threads"
158 # pid command fd name
159 expect_multiline "info os files" "$inferior_pid +info-os +\\d+ +/dev/null" "get file descriptors"
161 # local address l-port remote addr r-port state user family protocol
162 expect_multiline "info os sockets" "0\\.0\\.0\\.0 +$port +0\\.0\\.0\\.0 +0 +LISTEN +\\S+ +INET +STREAM" "get internet-domain sockets"
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
165 expect_multiline "info os shm" "$shmkey +$shmid +666 +4096 +info-os .*" "get shared-memory regions"
167 # key semid perm num semaphores user group creator user creator group last semop() time last semctl() time
168 expect_multiline "info os semaphores" "$semkey +$semid +666 +1 .*" "get semaphores"
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
171 expect_multiline "info os msg" "$msgkey +$msqid +666 .*" "get message queues"
173 gdb_test "info os unknown_entry" [multi_line \
174 "warning: Empty data returned by target. Wrong osdata type\\\?" \
175 "Can not fetch data now."]
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
180 gdb_test "continue" "exited.*"