]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/testsuite/gdb.base/foll-exec.exp
Fix some duplicate test names
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / foll-exec.exp
index c4d62a589721354117ea38c7d40a8011e8b5c519..b0e155dd379e01f9dd2b8237beadf7323586a4ab 100644 (file)
-#   Copyright (C) 1997 Free Software Foundation, Inc.
+#   Copyright 1997-2020 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
+# the Free Software Foundation; either version 3 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
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-if $tracelevel then {
-       strace $tracelevel
-       }
+# This is a test of gdb's ability to follow a process through a
+# Unix exec() system call.
 
-if { ![isnative] } then {
+# Until "catch exec" is implemented on other targets...
+#
+if { ![istarget "*-linux*"] } then {
     continue
 }
 
-set prms_id 0
-set bug_id 0
+standard_testfile foll-exec.c
 
-set testfile "foll-exec"
 set testfile2 "execd-prog"
-set srcfile ${testfile}.c
 set srcfile2 ${testfile2}.c
-set binfile ${objdir}/${subdir}/${testfile}
-set binfile2 ${objdir}/${subdir}/${testfile2}
+set binfile2 [standard_output_file ${testfile2}]
+
+set compile_options debug
 
 # build the first test case
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
-     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } {
+     untested "failed to compile"
+     return -1
 }
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
-     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_options] != "" } {
+     untested "failed to compile"
+     return -1
 }
 
+proc do_exec_tests {} {
+   global binfile srcfile srcfile2 testfile testfile2
+   global gdb_prompt
 
-# Until "catch exec" is implemented on other targets...
-#
-if ![istarget "hppa*-hp-hpux*"] then {
-    continue
-}
+   # Start the program running, and stop at main.
+   #
+   if ![runto_main] then {
+     fail "couldn't run ${testfile}"
+     return
+   }
 
-proc zap_session {} {
-   global gdb_prompt
-   global binfile
+   # Verify that the system supports "catch exec".
+   gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert first exec catchpoint"
+   set has_exec_catchpoints 0
+   gdb_test_multiple "continue" "continue to first exec catchpoint" {
+     -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
+       unsupported "continue to first exec catchpoint"
+     }
+     -re ".*Catchpoint.*$gdb_prompt $" {
+       set has_exec_catchpoints 1
+       pass "continue to first exec catchpoint"
+     }
+   }
 
-   send_gdb "kill\n"
-   gdb_expect {
-     -re ".*Kill the program being debugged.*y or n. $" {
-       send_gdb "y\n"
-       send_gdb "file $binfile\n"
-       gdb_expect {
-         -re ".*Load new symbol table from.*y or n. $" {
-           send_gdb "y\n"
-           gdb_expect {
-             -re "Reading symbols from.*$gdb_prompt $" {}
-             timeout { fail "loading symbols (timeout)"; return }
-           }
-         }
-         -re ".*gdb_prompt $" {}
-         timeout { fail "loading symbols (timeout)"; return }
-       }
-    }
-    -re ".*$gdb_prompt $" {}
-    timeout { fail "killing inferior (timeout)" ; return }
+   if {$has_exec_catchpoints == 0} {
+     unsupported "exec catchpoints"
+     return
    }
-}
 
-proc do_exec_tests {} {
-   global gdb_prompt
-   global binfile
-   global srcfile
-   global srcfile2
-   global testfile
-   global testfile2
+   clean_restart $binfile
 
    # Start the program running, and stop at main.
    #
    if ![runto_main] then {
-     perror "Couldn't run ${testfile}"
+     fail "couldn't run ${testfile}"
      return
    }
 
+   with_test_prefix "1st run" {
+       # Execute the code setting up variable PROG.
+       set tbreak_line [gdb_get_line_number " tbreak-execlp " $srcfile]
+       gdb_test "tbreak ${tbreak_line}" "" "insert breakpoint"
+       gdb_continue_to_breakpoint "line tbreak-execlp" ".*execlp \\(.*"
+   }
+
    # Verify that we can see various global and local variables
    # in this program, and that they have expected values.  Some
    # of these variables are also declared in the program we'll
    # exec in a moment.
    #
-   send_gdb "next 3\n"
-   gdb_expect {
-     -re "20.*execlp.*$gdb_prompt $"\
-                     {pass "step to exec call"}
-     -re "$gdb_prompt $" {fail "step to exec call"}
-     timeout         {fail "(timeout) step to exec call"}
-   }
+
    send_gdb "print global_i\n"
    gdb_expect {
      -re ".* = 100.*$gdb_prompt $"\
@@ -129,9 +117,10 @@ proc do_exec_tests {} {
    # Try stepping through an execlp call, without catching it.
    # We should stop in execd-program, at its first statement.
    #
+   set execd_line [gdb_get_line_number "after-exec" $srcfile2]
    send_gdb "next\n"
    gdb_expect {
-     -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int  local_j = argc;.*$gdb_prompt $"\
+     -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int  local_j = argc;.*$gdb_prompt $"\
                      {pass "step through execlp call"}
      -re "$gdb_prompt $" {fail "step through execlp call"}
      timeout         {fail "(timeout) step through execlp call"}
@@ -142,7 +131,7 @@ proc do_exec_tests {} {
    #
    send_gdb "next\n"
    gdb_expect {
-     -re "26.*printf.*$gdb_prompt $"\
+     -re "printf \\(.Hello .*$gdb_prompt $"\
                      {pass "step after execlp call"}
      -re "$gdb_prompt $" {fail "step after execlp call"}
      timeout         {fail "(timeout) step after execlp call"}
@@ -171,12 +160,12 @@ proc do_exec_tests {} {
 
    # Explicitly kill this program, or a subsequent rerun actually runs
    # the exec'd program, not the original program...
-   zap_session
+   clean_restart $binfile
 
    # Start the program running, and stop at main.
    #
    if ![runto_main] then {
-     perror "Couldn't run ${testfile} (2nd try)"
+     fail "couldn't run ${testfile} (2nd try)"
      return
    }
 
@@ -196,23 +185,16 @@ proc do_exec_tests {} {
    # Verify that the catchpoint is mentioned in an "info breakpoints",
    # and further that the catchpoint mentions no program name.
    #
-   send_gdb "info breakpoints\n"
-   gdb_expect {
-     -re ".*catch exec.*keep y.*$gdb_prompt $"\
-                     {pass "info shows catchpoint without exec pathname"}
-     -re ".*catch exec.*program \"\".*$gdb_prompt $"\
-                     {fail "info shows catchpoint without exec pathname"}
-     -re "$gdb_prompt $" {fail "info shows catchpoint without exec pathname"}
-     timeout         {fail "(timeout) info shows catchpoint without exec pathname"}
+   set msg "info shows catchpoint without exec pathname"
+   gdb_test_multiple "info breakpoints" $msg {
+       -re ".*catchpoint.*keep y.*exec\[\n\r\]+$gdb_prompt $" {
+           pass $msg
+       }
    }
 
-   # DTS CLLbs16760
-   # PA64 doesn't know about $START$ in dld.sl at this point.  It should.
-   # - Michael Coulter
-   setup_xfail hppa2.0w-hp-hpux* CLLbs16760
    send_gdb "continue\n"
    gdb_expect {
-     -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .START..*$gdb_prompt $"\
+     -re ".*xecuting new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*$gdb_prompt $"\
                      {pass "hit catch exec"}
      -re "$gdb_prompt $" {fail "hit catch exec"}
      timeout         {fail "(timeout) hit catch exec"}
@@ -227,12 +209,11 @@ proc do_exec_tests {} {
    # and further that the catchpoint managed to capture the exec'd
    # program's name.
    #
-   send_gdb "info breakpoints\n"
-   gdb_expect {
-     -re ".*catch exec .*program \".*${testfile2}\".*$gdb_prompt $"\
-                     {pass "info shows catchpoint exec pathname"}
-     -re "$gdb_prompt $" {fail "info shows catchpoint exec pathname"}
-     timeout         {fail "(timeout) info shows catchpoint exec pathname"}
+   set msg "info shows catchpoint exec pathname"
+   gdb_test_multiple "info breakpoints" $msg {
+       -re ".*catchpoint.*keep y.*exec, program \".*${testfile2}\".*$gdb_prompt $" {
+           pass $msg
+       }
    }
 
    # Verify that we can continue from the catchpoint, and land in the
@@ -240,7 +221,7 @@ proc do_exec_tests {} {
    #
    send_gdb "continue\n"
    gdb_expect {
-     -re ".*${srcfile2}:23.*$gdb_prompt $"\
+     -re ".*${srcfile2}:${execd_line}.*$gdb_prompt $"\
                      {pass "continue after hit catch exec"}
      -re "$gdb_prompt $" {fail "continue after hit catch exec"}
      timeout         {fail "(timeout) continue after hit catch exec"}
@@ -248,28 +229,36 @@ proc do_exec_tests {} {
 
    # Explicitly kill this program, or a subsequent rerun actually runs
    # the exec'd program, not the original program...
-   zap_session
+   clean_restart $binfile
 
    # Start the program running, and stop at main.
    #
    if ![runto_main] then {
-     perror "Couldn't run ${testfile} (3rd try)"
+     fail "couldn't run ${testfile} (3rd try)"
      return
    }
 
+   with_test_prefix "2nd run" {
+       # Execute the code setting up variable PROG.
+       set tbreak_line [gdb_get_line_number " tbreak-execlp " $srcfile]
+       gdb_test "tbreak ${tbreak_line}" "" "insert breakpoint"
+       gdb_continue_to_breakpoint "line tbreak-execlp" ".*execlp \\(.*"
+   }
+
    # Verify that we can follow through follow an execl()
    # call.  (We must jump around earlier exec* calls.)
    #
-   send_gdb "tbreak 27\n"
+   set tbreak_line [gdb_get_line_number " tbreak-execl " $srcfile]
+   send_gdb "tbreak ${tbreak_line}\n"
    gdb_expect {
-     -re "Breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
+     -re "Temporary breakpoint .*file .*${srcfile}, line ${tbreak_line}.*$gdb_prompt $"\
                      {pass "prepare to jump to execl call"}
      -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
      timeout         {fail "(timeout) prepare to jump to execl call"}
    }
-   send_gdb "jump 27\n"
+   send_gdb "jump ${tbreak_line}\n"
    gdb_expect {
-     -re "main.* at .*${srcfile}:27.*$gdb_prompt $"\
+     -re "main.* at .*${srcfile}:${tbreak_line}.*$gdb_prompt $"\
                      {pass "jump to execl call"}
      -re "$gdb_prompt $" {fail "jump to execl call"}
      timeout         {fail "(timeout) jump to execl call"}
@@ -282,14 +271,14 @@ proc do_exec_tests {} {
    #
    send_gdb "next 2\n"
    gdb_expect {
-     -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int  local_j = argc;.*$gdb_prompt $"\
+     -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int  local_j = argc;.*$gdb_prompt $"\
                      {pass "step through execl call"}
      -re "$gdb_prompt $" {fail "step through execl call"}
      timeout         {fail "(timeout) step through execl call"}
    }
    send_gdb "next\n"
    gdb_expect {
-     -re "26.*printf.*$gdb_prompt $"\
+     -re "printf \\(.Hello .*$gdb_prompt $"\
                      {pass "step after execl call"}
      -re "$gdb_prompt $" {fail "step after execl call"}
      timeout         {fail "(timeout) step after execl call"}
@@ -308,42 +297,50 @@ proc do_exec_tests {} {
 
    # Explicitly kill this program, or a subsequent rerun actually runs
    # the exec'd program, not the original program...
-   zap_session
+   clean_restart $binfile
 
    # Start the program running, and stop at main.
    #
    if ![runto_main] then {
-     perror "Couldn't run ${testfile} (4th try)"
+     fail "couldn't run ${testfile} (4th try)"
      return
    }
 
+   with_test_prefix "3rd run" {
+       # Execute the code setting up variable PROG.
+       set tbreak_line [gdb_get_line_number " tbreak-execlp " $srcfile]
+       gdb_test "tbreak ${tbreak_line}" "" "insert breakpoint"
+       gdb_continue_to_breakpoint "line tbreak-execlp" ".*execlp \\(.*"
+   }
+
    # Verify that we can follow through follow an execv()
    # call.  (We must jump around earlier exec* calls.)
    #
-   send_gdb "tbreak 41\n"
+   set tbreak_line [gdb_get_line_number "tbreak-execv"]
+   send_gdb "tbreak ${tbreak_line}\n"
    gdb_expect {
-     -re "Breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
+     -re "Temporary breakpoint .*file .*${srcfile}, line ${tbreak_line}.*$gdb_prompt $"\
                      {pass "prepare to jump to execv call"}
      -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
      timeout         {fail "(timeout) prepare to jump to execv call"}
    }
-   send_gdb "jump 41\n"
+   send_gdb "jump ${tbreak_line}\n"
    gdb_expect {
-     -re "main.* at .*${srcfile}:41.*$gdb_prompt $"\
+     -re "main.* at .*${srcfile}:${tbreak_line}.*$gdb_prompt $"\
                      {pass "jump to execv call"}
      -re "$gdb_prompt $" {fail "jump to execv call"}
      timeout         {fail "(timeout) jump to execv call"}
    }
    send_gdb "next\n"
    gdb_expect {
-     -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int  local_j = argc;.*$gdb_prompt $"\
+     -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int  local_j = argc;.*$gdb_prompt $"\
                      {pass "step through execv call"}
      -re "$gdb_prompt $" {fail "step through execv call"}
      timeout         {fail "(timeout) step through execv call"}
    }
    send_gdb "next\n"
    gdb_expect {
-     -re "26.*printf.*$gdb_prompt $"\
+     -re "printf \\(.Hello .*$gdb_prompt $"\
                      {pass "step after execv call"}
      -re "$gdb_prompt $" {fail "step after execv call"}
      timeout         {fail "(timeout) step after execv call"}
@@ -362,12 +359,12 @@ proc do_exec_tests {} {
 
    # Explicitly kill this program, or a subsequent rerun actually runs
    # the exec'd program, not the original program...
-   zap_session
+   clean_restart $binfile
 
    # Start the program running, and stop at main.
    #
    if ![runto_main] then {
-     perror "Couldn't run ${testfile} (5th try)"
+     fail "couldn't run ${testfile} (5th try)"
      return
    }
 
@@ -377,7 +374,7 @@ proc do_exec_tests {} {
    #
    send_gdb "continue\n"
    gdb_expect {
-     -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int  local_j = argc;.*$gdb_prompt $"\
+     -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int  local_j = argc;.*$gdb_prompt $"\
                      {pass "continue through exec"}
      -re "$gdb_prompt $" {fail "continue through exec"}
      timeout         {fail "(timeout) continue through exec"}
@@ -387,14 +384,8 @@ proc do_exec_tests {} {
 # Start with a fresh gdb
 
 gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
+clean_restart $binfile
 
-# This is a test of gdb's ability to follow a process through a
-# Unix exec() system call.
-#
 do_exec_tests
 
 return 0