From patchwork Thu Oct 16 06:25:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 3240 Received: (qmail 7548 invoked by alias); 16 Oct 2014 06:29:34 -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 7537 invoked by uid 89); 16 Oct 2014 06:29:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Oct 2014 06:29:32 +0000 Received: from svr-orw-fem-05.mgc.mentorg.com ([147.34.97.43]) by relay1.mentorg.com with esmtp id 1XeeYz-0005UE-9O from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Wed, 15 Oct 2014 23:29:29 -0700 Received: from qiyao.dyndns.org.com (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.3.181.6; Wed, 15 Oct 2014 23:29:28 -0700 From: Yao Qi To: Subject: [PATCH] Skip argv0-symlink.exp on target argv[0] isn't available Date: Thu, 16 Oct 2014 14:25:12 +0800 Message-ID: <1413440712-3645-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes I see the following two fails on arm-none-eabi target, because argv[0] isn't available. print argv[0]^M $1 = 0x1f78 "/dev/null"^M (gdb) FAIL: gdb.base/argv0-symlink.exp: kept file symbolic link name print argv[0]^M $1 = 0x1f78 "/dev/null"^M (gdb) FAIL: gdb.base/argv0-symlink.exp: kept directory symbolic link name My first thought is to check [target_info exists noargs], and skip the test if it returns true. However, noargs is set in gdbserver board files, so argv0-symlink.exp will be skipped on gdbserver board file. The change is too aggressive. When the program is running with gdbserver, argv[1] to argv[N] aren't available, but argv[0] is. Fortunately, argv0-symlink.exp only requires argv[0]. argv0-symlink.exp can be run with gdbserver board file, as what we do now. What we need to check is whether argv[0] is available, so I add a new proc gdb_has_argv0 to do so by starting a program, and check argc/argv[0] to see whether argv[0] is available. Dan fixed the similar problem by checking noargs, which is too strong. https://sourceware.org/ml/gdb-patches/2010-02/msg00398.html as a result, the test is skipped on gdbserver. This patch fixed it too. Re-run argv0-symlink.exp, scm-value.exp, and py-value.exp on x86-linux (both native and gdbserver) and arm-none-eabi. No fail on x86-linux, and argv0-symlink.exp is skipped on arm-none-eabi target. gdb/testsuite: 2014-10-16 Yao Qi * gdb.base/argv0-symlink.exp: Skip it if gdb_has_argv0 return false. * gdb.guile/scm-value.exp (test_value_in_inferior): Don't check [target_info exists noargs], check [gdb_has_argv0] instead. * gdb.python/py-value.exp (test_value_in_inferior): Likewise. * lib/gdb.exp (gdb_has_argv0, gdb_has_argv0_1): New procedures. --- gdb/testsuite/gdb.base/argv0-symlink.exp | 5 ++ gdb/testsuite/gdb.guile/scm-value.exp | 5 +- gdb/testsuite/gdb.python/py-value.exp | 5 +- gdb/testsuite/lib/gdb.exp | 79 ++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.base/argv0-symlink.exp b/gdb/testsuite/gdb.base/argv0-symlink.exp index d849b4c..183fd70 100644 --- a/gdb/testsuite/gdb.base/argv0-symlink.exp +++ b/gdb/testsuite/gdb.base/argv0-symlink.exp @@ -13,6 +13,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if { ![gdb_has_argv0] } { + unsupported "Can't get argv\[0\]." + return +} + standard_testfile if { [build_executable ${testfile}.exp ${testfile} ${srcfile}] == -1 } { diff --git a/gdb/testsuite/gdb.guile/scm-value.exp b/gdb/testsuite/gdb.guile/scm-value.exp index ae80d1b..2b49134 100644 --- a/gdb/testsuite/gdb.guile/scm-value.exp +++ b/gdb/testsuite/gdb.guile/scm-value.exp @@ -20,6 +20,8 @@ load_lib gdb-guile.exp standard_testfile +set has_argv0 [gdb_has_argv0] + # Build inferior to language specification. # LANG is one of "c" or "c++". proc build_inferior {exefile lang} { @@ -86,7 +88,8 @@ proc test_value_in_inferior {} { "set arg0" # Check that the dereferenced value is sane. - if { ! [target_info exists noargs] } { + global has_argv0 + if { $has_argv0 } { gdb_test "gu (print arg0)" \ "0x.*$testfile\"" "verify dereferenced value" } diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index 0d18bef..afa55a5 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -20,6 +20,8 @@ load_lib gdb-python.exp standard_testfile +set has_argv0 [gdb_has_argv0] + # Build inferior to language specification. # LANG is one of "c" or "c++". proc build_inferior {exefile lang} { @@ -221,7 +223,8 @@ proc test_value_in_inferior {} { gdb_py_test_silent_cmd "python arg0 = argv.dereference ()" "dereference value" 1 # Check that the dereferenced value is sane - if { ! [target_info exists noargs] } { + global has_argv0 + if { $has_argv0 } { gdb_test "python print (arg0)" "0x.*$testfile\"" "verify dereferenced value" } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 7b2a402..dd525dc 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4227,6 +4227,85 @@ gdb_caching_proc gdb_skip_xml_test { return $xml_missing } +# Return true if argv[0] is available. + +gdb_caching_proc gdb_has_argv0 { + set result 0 + + # Set up, compile, and execute a test program to check whether + # argv[0] is available. + set src [standard_temp_file has_argv0[pid].c] + set exe [standard_temp_file has_argv0[pid].x] + + gdb_produce_source $src { + int main (int argc, char **argv) { + return 0; + } + } + + gdb_compile $src $exe executable {debug} + + # Helper proc. + proc gdb_has_argv0_1 { exe } { + global srcdir subdir + global gdb_prompt hex decimal + + gdb_exit + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load "$exe" + + # Set breakpoint on main. + send_gdb "break main\n" + gdb_expect { + -re "Breakpoint.*${gdb_prompt} $" { + } + -re "${gdb_prompt} $" { + return 0 + } + } + + # Run to main. + gdb_run_cmd + gdb_expect { + -re "Breakpoint.*${gdb_prompt} $" { + } + -re "${gdb_prompt} $" { + return 0 + } + } + + # Check whether argc is 1. + send_gdb "p argc\n" + gdb_expect { + -re " = 1\r\n${gdb_prompt} $" { + + send_gdb "p argv\[0\]\n" + gdb_expect { + -re " = $hex \".*$exe\"\r\n${gdb_prompt} $" { + return 1 + } + -re "${gdb_prompt} $" { + return 0 + } + } + } + -re "${gdb_prompt} $" { + return 0 + } + } + return 0 + } + + set result [gdb_has_argv0_1 $exe] + + gdb_exit + file delete $src + file delete $exe + + return $result +} + # Note: the procedure gdb_gnu_strip_debug will produce an executable called # ${binfile}.dbglnk, which is just like the executable ($binfile) but without # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains