From patchwork Thu Jan 21 12:42:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 10502 Received: (qmail 10955 invoked by alias); 21 Jan 2016 12:42:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 10935 invoked by uid 89); 21 Jan 2016 12:42:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=execdprog, execd-prog, 64, 6, 517 X-HELO: mail-pf0-f181.google.com Received: from mail-pf0-f181.google.com (HELO mail-pf0-f181.google.com) (209.85.192.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 21 Jan 2016 12:42:28 +0000 Received: by mail-pf0-f181.google.com with SMTP id q63so23829862pfb.1 for ; Thu, 21 Jan 2016 04:42:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=00sSQRVHwv/o83lnAhh7idUvHI5VVtoPv83mbn2y6P8=; b=gdqV7hBkA1d2JgKSK266DV8CKdy2kSgjDFU2NueCg7Ryd5b27Z2OOVM0m7HTxdjHfu DEHh3S6s1HeBnTM/syQ4an7xNPxC1OLNTZv3HYptqKgGQlmZ4nSrYuOsygfInZ/cF6VK FI+DsFC9j5XXMCUWzjJMqiOiqqo7D+FlHmV8p+baffJ4qTFLcHPa8/OXItPfhdg3GQE8 YvBxZ5+GNlsp3IGkCNFkasyYENhi05+gCn/OInKpFLy8lzgrMqTWXEolQdtlwpB/k4yE FKmVesRhh6GPqR+gJBeeW6dSqTquFaVeuM/WexJ5I7gBdsDi44nVuBsoZF8b9QAQKMRo HbSw== X-Gm-Message-State: ALoCoQnDIWivcZRqgF5vtsf+V8rCuU6uGpZsWTD/p/Ik1R/uzxGwTaBAbttef7B6XvNcux8zFMlel0CEfqE3MnrdSxGMuPiWGg== X-Received: by 10.98.72.200 with SMTP id q69mr59742021pfi.159.1453380146726; Thu, 21 Jan 2016 04:42:26 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id 16sm2523800pfh.48.2016.01.21.04.42.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Jan 2016 04:42:26 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH] [testsuite] Remove BASEDIR Date: Thu, 21 Jan 2016 12:42:21 +0000 Message-Id: <1453380141-21687-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes BASEDIR was added by https://sourceware.org/ml/gdb-patches/2013-10/msg00587.html in order to handle the different directory layout in serial testing and parallel testing. BASEDIR is "gdb.base" in serial testing and is "outputs/gdb.base/TESTNAME" in parallel testing. However, it doesn't work if the GDBserver is in remote target, like this, $ make check RUNTESTFLAGS='--target_board=remote-gdbserver-on-localhost foll-vfork.exp foll-exec.exp' FAIL: gdb.base/foll-exec.exp: continue to first exec catchpoint (the program exited) FAIL: gdb.base/foll-vfork.exp: exec: vfork and exec child follow, to main bp: continue to bp (the program exited) FAIL: gdb.base/foll-vfork.exp: exec: vfork child follow, finish after tcatch vfork: finish (the program exited) FAIL: gdb.base/foll-vfork.exp: exec: vfork relations in info inferiors: continue to bp (the program exited) these tests fail because the executable can't be found. With target board native-gdbserver, the program is spawned this way, spawn ../gdbserver/gdbserver --once :2347 /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/gdb.base/foll-vfork so BASEDIR is correct. However, with target board remote-gdbserver-on-localhost, the program is spawned spawn /usr/bin/ssh -l yao localhost /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/../gdbserver/gdbserver --once :2346 /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/gdb.base/foll-vfork so BASEDIR (either "gdb.base" or "outputs/gdb.base/TESTNAME") makes no sense. I had a fix that pass absolute directory to BASEDIR, but it assumes that directory structure is the same on build and target, and it doesn't work in remote host case. The current fix in this patch is to get the directory from argv[0]. In any case, the program to be exec'ed is at the same directory with the main program. Note that these tests do "next N" to let program stop at the desired line, but it is fragile, because GDB for different targets may skip function prologue slightly differently, so I replace some of them by "tbreak on LINE NUMBER and continue". Re-run these affected tests with board file unix in both serial and parallel tests. Also run them with board file native-gdbserver and remote-gdbserver-on-localhost. Re-run them in remote testing for arm-linux and aarch64-linux. gdb/testsuite: 2016-01-21 Yao Qi * gdb.base/foll-exec-mode.c: Include limits.h. (main): Add parameters argc and argv. Get directory from argv[0]. * gdb.base/foll-exec-mode.exp: Don't pass -DBASEDIR in compilation. * gdb.base/foll-exec.c: Include limits.h. (main): Add parameters argc and argv. Get directory from argv[0]. * gdb.base/foll-exec.exp: Don't pass -DBASEDIR in compilation. Adjust tests on the number of lines as source code changed. * gdb.base/foll-vfork-exit.c: Include limits.h. (main): Add one line of statement before vfork. * gdb.base/foll-vfork.c: Include limits.h and string.h. (main): Add parameters argc and argv. Get directory from argv[0]. * gdb.base/foll-vfork.exp: Don't pass -DBASEDIR in compilation. (setup_gdb): Set tbreak to skip some source lines. * gdb.multi/bkpt-multi-exec.c: Include limits.h. (main): Add parameters argc and argv. Get directory from argv[0]. * gdb.multi/bkpt-multi-exec.exp: Don't pass -DBASEDIR in compilation. * gdb.multi/multi-arch-exec.c: Include limits.h and string.h. (main): Add parameters argc and argv. Get directory from argv[0]. * gdb.multi/multi-arch-exec.exp: Don't pass -DBASEDIR in compilation. --- gdb/testsuite/gdb.base/foll-exec-mode.c | 13 +++++++++++-- gdb/testsuite/gdb.base/foll-exec-mode.exp | 2 -- gdb/testsuite/gdb.base/foll-exec.c | 26 +++++++++++++++++++------- gdb/testsuite/gdb.base/foll-exec.exp | 24 ++++++++++++++---------- gdb/testsuite/gdb.base/foll-vfork-exit.c | 5 ++++- gdb/testsuite/gdb.base/foll-vfork.c | 22 +++++++++++++++++++--- gdb/testsuite/gdb.base/foll-vfork.exp | 8 +++++--- gdb/testsuite/gdb.multi/bkpt-multi-exec.c | 16 +++++++++++++--- gdb/testsuite/gdb.multi/bkpt-multi-exec.exp | 2 -- gdb/testsuite/gdb.multi/multi-arch-exec.c | 17 ++++++++++++++--- gdb/testsuite/gdb.multi/multi-arch-exec.exp | 4 +--- 11 files changed, 100 insertions(+), 39 deletions(-) diff --git a/gdb/testsuite/gdb.base/foll-exec-mode.c b/gdb/testsuite/gdb.base/foll-exec-mode.c index 1a482a5..67686d7 100644 --- a/gdb/testsuite/gdb.base/foll-exec-mode.c +++ b/gdb/testsuite/gdb.base/foll-exec-mode.c @@ -19,17 +19,26 @@ #include #include #include +#include int global_i = 100; -int main (void) +int main (int argc, char ** argv) { int local_j = global_i + 1; int local_k = local_j + 1; + char prog[PATH_MAX]; + int len; + + strcpy (prog, argv[0]); + len = strlen (prog); + /* Replace "foll-exec-mode" with "execd-prog". */ + memcpy (prog + len - 14, "execd-prog", 10); + prog[len - 4] = 0; printf ("foll-exec is about to execlp(execd-prog)...\n"); - execlp (BASEDIR "/execd-prog", /* Set breakpoint here. */ + execlp (prog, /* Set breakpoint here. */ "/execd-prog", "execlp arg1 from foll-exec", (char *) 0); diff --git a/gdb/testsuite/gdb.base/foll-exec-mode.exp b/gdb/testsuite/gdb.base/foll-exec-mode.exp index 41d788b..aa7b4143 100644 --- a/gdb/testsuite/gdb.base/foll-exec-mode.exp +++ b/gdb/testsuite/gdb.base/foll-exec-mode.exp @@ -46,8 +46,6 @@ set srcfile2 ${testfile2}.c set binfile2 [standard_output_file ${testfile2}] set compile_options debug -set dirname [relative_filename [pwd] [file dirname $binfile]] -lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\"" # build the first test case if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } { diff --git a/gdb/testsuite/gdb.base/foll-exec.c b/gdb/testsuite/gdb.base/foll-exec.c index 639698c..1ae171f 100644 --- a/gdb/testsuite/gdb.base/foll-exec.c +++ b/gdb/testsuite/gdb.base/foll-exec.c @@ -20,36 +20,48 @@ #include #include +#include + int global_i = 100; -int main (void) +int main (int argc, char ** argv) { int local_j = global_i + 1; int local_k = local_j + 1; + char prog[PATH_MAX]; + int len; printf ("foll-exec is about to execlp(execd-prog)...\n"); - execlp (BASEDIR "/execd-prog", - BASEDIR "/execd-prog", + strcpy (prog, argv[0]); + len = strlen (prog); + /* Replace "foll-exec" with "execd-prog". */ + memcpy (prog + len - 9, "execd-prog", 10); + prog[len + 1] = 0; + + execlp (prog, /* tbreak-execlp */ + prog, "execlp arg1 from foll-exec", (char *) 0); printf ("foll-exec is about to execl(execd-prog)...\n"); - execl (BASEDIR "/execd-prog", /* tbreak-execl */ - BASEDIR "/execd-prog", + execl (prog, /* tbreak-execl */ + prog, "execl arg1 from foll-exec", "execl arg2 from foll-exec", (char *) 0); { static char * argv[] = { - (char *) BASEDIR "/execd-prog", + (char *) "", (char *) "execv arg1 from foll-exec", (char *) 0}; + argv[0] = prog; + printf ("foll-exec is about to execv(execd-prog)...\n"); - execv (BASEDIR "/execd-prog", argv); /* tbreak-execv */ + execv (prog, argv); /* tbreak-execv */ } } diff --git a/gdb/testsuite/gdb.base/foll-exec.exp b/gdb/testsuite/gdb.base/foll-exec.exp index 7d86d01..8859f9f 100644 --- a/gdb/testsuite/gdb.base/foll-exec.exp +++ b/gdb/testsuite/gdb.base/foll-exec.exp @@ -29,8 +29,6 @@ set srcfile2 ${testfile2}.c set binfile2 [standard_output_file ${testfile2}] set compile_options debug -set dirname [relative_filename [pwd] [file dirname $binfile]] -lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\"" # build the first test case if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } { @@ -80,19 +78,17 @@ proc do_exec_tests {} { fail "Couldn't run ${testfile}" return } + # Execute the code setting up variable PROG. + set tbreak_line [gdb_get_line_number " tbreak-execlp " $srcfile] + gdb_test "tbreak ${tbreak_line}" + 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 "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 $"\ @@ -238,11 +234,15 @@ proc do_exec_tests {} { fail "Couldn't run ${testfile} (3rd try)" return } + # Execute the code setting up variable PROG. + set tbreak_line [gdb_get_line_number " tbreak-execlp " $srcfile] + gdb_test "tbreak ${tbreak_line}" + 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.) # - set tbreak_line [gdb_get_line_number "tbreak-execl" $srcfile] + set tbreak_line [gdb_get_line_number " tbreak-execl " $srcfile] send_gdb "tbreak ${tbreak_line}\n" gdb_expect { -re "Temporary breakpoint .*file .*${srcfile}, line ${tbreak_line}.*$gdb_prompt $"\ @@ -299,6 +299,10 @@ proc do_exec_tests {} { fail "Couldn't run ${testfile} (4th try)" return } + # Execute the code setting up variable PROG. + set tbreak_line [gdb_get_line_number " tbreak-execlp " $srcfile] + gdb_test "tbreak ${tbreak_line}" + 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.) diff --git a/gdb/testsuite/gdb.base/foll-vfork-exit.c b/gdb/testsuite/gdb.base/foll-vfork-exit.c index 6f168e2..c431ded 100644 --- a/gdb/testsuite/gdb.base/foll-vfork-exit.c +++ b/gdb/testsuite/gdb.base/foll-vfork-exit.c @@ -23,7 +23,10 @@ main () { int pid; - pid = vfork (); + /* A statement before vfork to make sure a breakpoint on main isn't + set on vfork below. */ + pid = 1; + pid = vfork (); /* VFORK */ if (pid == 0) { printf ("I'm the child!\n"); diff --git a/gdb/testsuite/gdb.base/foll-vfork.c b/gdb/testsuite/gdb.base/foll-vfork.c index 24b2a53..5949d45 100644 --- a/gdb/testsuite/gdb.base/foll-vfork.c +++ b/gdb/testsuite/gdb.base/foll-vfork.c @@ -18,14 +18,30 @@ #include #include -int main (void) +#include +#include + +int +main (int argc, char ** argv) { int pid; - pid = vfork (); + /* A statement before vfork to make sure a breakpoint on main isn't + set on vfork below. */ + pid = 1 + argc; + pid = vfork (); /* VFORK */ if (pid == 0) { + char prog[PATH_MAX]; + int len; + + strcpy (prog, argv[0]); + len = strlen (prog); + /* Replace "foll-vfork" with "vforked-prog". */ + memcpy (prog + len - 10, "vforked-prog", 12); + prog[len + 2] = 0; + printf ("I'm the child!\n"); - execlp (BASEDIR "/vforked-prog", BASEDIR "/vforked-prog", (char *)0); + execlp (prog, prog, (char *) 0); perror ("exec failed"); _exit (1); } diff --git a/gdb/testsuite/gdb.base/foll-vfork.exp b/gdb/testsuite/gdb.base/foll-vfork.exp index bf9b893..481dcb7 100644 --- a/gdb/testsuite/gdb.base/foll-vfork.exp +++ b/gdb/testsuite/gdb.base/foll-vfork.exp @@ -28,8 +28,6 @@ if {![istarget "*-linux*"]} then { standard_testfile set compile_options debug -set dirname [relative_filename [pwd] [file dirname $binfile]] -lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\"" if {[build_executable $testfile.exp $testfile $srcfile $compile_options] == -1} { untested "failed to compile $testfile" @@ -53,7 +51,7 @@ set timeout [expr "$timeout + 10"] # error, behave as "return", so we don't try to continue testing with # a borked session. proc setup_gdb {} { - global testfile + global testfile srcfile clean_restart $testfile @@ -64,6 +62,10 @@ proc setup_gdb {} { if ![runto_main] { return -code return } + + set tbreak_line [gdb_get_line_number " VFORK " $srcfile] + gdb_test "tbreak ${tbreak_line}" + gdb_continue_to_breakpoint ".*" } proc check_vfork_catchpoints {} { diff --git a/gdb/testsuite/gdb.multi/bkpt-multi-exec.c b/gdb/testsuite/gdb.multi/bkpt-multi-exec.c index 94c9668..eb002fb 100644 --- a/gdb/testsuite/gdb.multi/bkpt-multi-exec.c +++ b/gdb/testsuite/gdb.multi/bkpt-multi-exec.c @@ -2,12 +2,22 @@ #include #include #include +#include -int main (void) +int main (int argc, char ** argv) { + char prog[PATH_MAX]; + int len; + + strcpy (prog, argv[0]); + len = strlen (prog); + /* Replace "bkpt-multi-exec" with "crashme". */ + memcpy (prog + len - 15, "crashme", 7); + prog[len - 8] = 0; + printf ("foll-exec is about to execl(crashme)...\n"); - execl (BASEDIR "/crashme", - BASEDIR "/crashme", + execl (prog, + prog, (char *)0); } diff --git a/gdb/testsuite/gdb.multi/bkpt-multi-exec.exp b/gdb/testsuite/gdb.multi/bkpt-multi-exec.exp index b7662df..e522413 100644 --- a/gdb/testsuite/gdb.multi/bkpt-multi-exec.exp +++ b/gdb/testsuite/gdb.multi/bkpt-multi-exec.exp @@ -34,8 +34,6 @@ set srcfile2 ${exec2}.c set binfile2 [standard_output_file ${exec2}] set compile_options {debug} -set dirname [relative_filename [pwd] [file dirname $binfile1]] -lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\"" if { [build_executable ${testfile}.exp ${exec1} "${srcfile1}" $compile_options] == -1 } { return -1 diff --git a/gdb/testsuite/gdb.multi/multi-arch-exec.c b/gdb/testsuite/gdb.multi/multi-arch-exec.c index 864e264..168b484 100644 --- a/gdb/testsuite/gdb.multi/multi-arch-exec.c +++ b/gdb/testsuite/gdb.multi/multi-arch-exec.c @@ -18,12 +18,23 @@ #include #include #include +#include +#include int -main () +main (int argc, char ** argv) { - execl (BASEDIR "/multi-arch-exec-hello", - BASEDIR "/multi-arch-exec-hello", + char prog[PATH_MAX]; + int len; + + strcpy (prog, argv[0]); + len = strlen (prog); + /* Replace "multi-arch-exec" with "multi-arch-exec-hello". */ + memcpy (prog + len - 15, "multi-arch-exec-hello", 21); + prog[len + 6] = 0; + + execl (prog, + prog, (char *) NULL); perror ("execl failed"); exit (1); diff --git a/gdb/testsuite/gdb.multi/multi-arch-exec.exp b/gdb/testsuite/gdb.multi/multi-arch-exec.exp index 5e9b59a..88e5a62 100644 --- a/gdb/testsuite/gdb.multi/multi-arch-exec.exp +++ b/gdb/testsuite/gdb.multi/multi-arch-exec.exp @@ -52,11 +52,9 @@ if [istarget "s390*-*-*"] { set march2 "-m32" } -set dirname [relative_filename [pwd] [file dirname $binfile2]] if { [prepare_for_testing ${testfile}.exp ${exec1} "${srcfile1}" \ [list debug \ - additional_flags=${march1} \ - additional_flags=-DBASEDIR=\"$dirname\"]] } { + additional_flags=${march1}]] } { return -1 }