# Copyright 2003 # Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Please email any bugs, comments, and/or additions to this file to: # bug-gdb@prep.ai.mit.edu # This file was written by Jason Molenda (jmolenda@apple.com) # The "info pid" and "-pid-info" commands were added for Xcode's benefit, # so it can find the process ID of the inferior program via gdb. ## Test both "info pid" and the MI command "-pid-info" in three cases: # 1. Before the inferior has started running. # 2. While the inferior is running. # 3. After the inferior has exited. ## Additionally, run the commands in console, mi1, and console-quoted ## interpreter modes to make sure all fo them work. A little fancy ## regexping is necessary to switch between the modes, but it's not that ## bad. if $tracelevel then { strace $tracelevel } load_lib mi-support.exp set MIFLAGS "-i=mi1" set timeout 30 set prms_id 0 set bug_id 0 set testfile "info-pid" set binfile ${objdir}/${subdir}/${testfile} set srcfile ${testfile}.c if { [gdb_compile "${srcdir}/${subdir}/info-pid.c" "${binfile}" executable {debug}] != "" } { gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." } # Start with a fresh gdb gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load ${binfile} gdb_test "info pid" "The program being debugged is not being run." "info pid errors when not running" send_gdb "set interpreter mi1\n" mi_gdb_test "37-pid-info" "37\\^error,msg=\"The program being debugged is not being run.\"" "-pid-info errors when not running" # FIXME: There's a race condition in info-pid.exp, on the "switch to # console quoted" test. Since it uses mi_gdb_test, and the switch to # console stuff ends up printing two GDB prompts, if only half of the # response comes through in a given read(), it will match one of the # mi_gdb_test failure cases instead of waiting for the rest of the # data to come through. At some point, we should clean up the # prompt-printing part of the interpreter switching code. In the # meantime, we can use a specific test instead of mi_gdb_test. # mi_gdb_test "38-gdb-set interpreter console-quoted" ".*Switching to interpreter .\"console-quoted.\".*38\\^done" "switch to console-quoted 1" send_gdb "38-gdb-set interpreter console-quoted\n" gdb_expect { -re ".*Switching to interpreter .\"console-quoted.\".*38\\^done.*$gdb_prompt\[\r\n ]*" { pass "switch to console-quoted 1" } timeout { fail "switch to console-quoted 1 (timeout)" } } gdb_test "info pid" "\\&\"The program being debugged is not being run..n\"" "info pid in console-quoted errors when not running" gdb_test "set interpreter console" "Switching to interpreter \"console\"\..*" "switch back to console 1" if ![runto_main] then { fail "info-pid tests suppressed" return -1 } set inferior_pid -1 send_gdb "call (int) getpid()\n" gdb_expect { -re ".1 = ($decimal)..$gdb_prompt $" { pass "get inferior pid via call" set inferior_pid $expect_out(1,string) } -re "$gdb_prompt $" { fail "get inferior pid via call" } timeout { fail "get inferior pid via call (timeout)" } } gdb_test "info pid" "Inferior has process ID $inferior_pid\." "Get pid via info pid in interp console mode" send_gdb "set interpreter mi1\n" mi_gdb_test "83-pid-info" "83\\^done,process-id=\"$inferior_pid\"" "Get pid via -pid-info in mi1 mode" mi_gdb_test "84-gdb-set interpreter console-quoted" ".*Switching to interpreter .\"console-quoted.\".*84\\^done" "switch to console-quoted 2" gdb_test "info pid" "\\~\"Inferior has process ID $inferior_pid\..n\"" "Get pid via info pid in console-quoted" gdb_test "set interpreter console" "Switching to interpreter \"console\"\..*" "switch back to console 2" gdb_test "call print_pid ()" "$inferior_pid" "Get pid via print_pid() call." gdb_test "break [gdb_get_line_number "sleep"]" "Breakpoint $decimal at $hex: file.*" "set breakpoint on sleep" gdb_test "continue" "Continuing.*Breakpoint.*" "continue to sleep" send_gdb "set keep_looping = 0\n" gdb_expect { -re ".$gdb_prompt $" { } } gdb_test "continue" "Continuing.*Program exited normally." "run program to exit" gdb_test "info pid" "The program being debugged is not being run." "info pid errors after program exits" send_gdb "set interpreter mi1\n" mi_gdb_test "92-pid-info" "92\\^error,msg=\"The program being debugged is not being run.\"" "-pid-info errors after program exits" send_gdb "94-gdb-set interpreter console\n" gdb_expect { -re ".*Switching to interpreter \"console\".*94\\^done.*$gdb_prompt\[\r\n ]*" { pass "Switch to console 3" } timeout { fail "Switch to console 3 (timeout)" } } gdb_exit return 0