]> 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 358c84c878e0867fa45085d70185b6449cadccd2..b0e155dd379e01f9dd2b8237beadf7323586a4ab 100644 (file)
@@ -1,4 +1,4 @@
-#   Copyright 1997, 1999, 2007, 2008 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
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-if { [is_remote target] || ![isnative] } then {
+# This is a test of gdb's ability to follow a process through a
+# Unix exec() system call.
+
+# 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}] != "" } {
-     untested foll-exec.exp
+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}] != "" } {
-     untested foll-exec.exp
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_options] != "" } {
+     untested "failed to compile"
      return -1
 }
 
-
-# Until "catch exec" is implemented on other targets...
-#
-if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
-    continue
-}
-
-proc zap_session {} {
-   global gdb_prompt
-   global binfile
-
-   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 }
-   }
-}
-
 proc do_exec_tests {} {
+   global binfile srcfile srcfile2 testfile testfile2
    global gdb_prompt
-   global binfile
-   global srcfile
-   global srcfile2
-   global testfile
-   global testfile2
 
    # Start the program running, and stop at main.
    #
    if ![runto_main] then {
-     perror "Couldn't run ${testfile}"
+     fail "couldn't run ${testfile}"
      return
    }
 
@@ -90,7 +56,7 @@ proc do_exec_tests {} {
    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 exec catchpoints.*$gdb_prompt $" {
+     -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
        unsupported "continue to first exec catchpoint"
      }
      -re ".*Catchpoint.*$gdb_prompt $" {
@@ -104,27 +70,28 @@ proc do_exec_tests {} {
      return
    }
 
-   zap_session
+   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 $"\
@@ -150,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"}
@@ -163,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"}
@@ -192,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
    }
 
@@ -224,13 +192,9 @@ proc do_exec_tests {} {
        }
    }
 
-   # 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 .*$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"}
@@ -257,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"}
@@ -265,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 "Temporary 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"}
@@ -299,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"}
@@ -325,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 "Temporary 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"}
@@ -379,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
    }
 
@@ -394,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"}
@@ -404,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