From patchwork Wed Mar 19 22:31:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 181 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (caibbdcaaahb.dreamhost.com [208.113.200.71]) by wilcox.dreamhost.com (Postfix) with ESMTP id 6BA2936010F for ; Wed, 19 Mar 2014 15:32:04 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id EE39BC86E40; Wed, 19 Mar 2014 15:32:03 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id BBBFF2135A59 for ; Wed, 19 Mar 2014 15:32:03 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:from:to:cc:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=t5+vq204mwTrsHD2cHOwpeyq6Y7zPBF6lcxWrjVv6oW itbFAW6ibv9r4pRtTZzESjfo6DZzqtCX2yGLsCPKENinSJT+xmibqsvA1ng2Uabl CM6DfQntTFP9WcLAZ26bEiHm+k3WNNpYHpQyvEZzTM2A2ces8s+XZXPHwTLCBecI = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:from:to:cc:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=R+478l+fsed1CI1gkvpz2yYgKrg=; b=a2V/+sbIzS0TcJGw9 UmHDLKgE5q6+LQUSgsK0QvIffBnhliV44BrKRwH0DzHy0bKopPrrjpXTMRPXU7RD UJ2xRDqn2tCDhBvi1Le2g+aFNWITJG37eteepo5q5ZzKZmYQtyIU2cTGdrWp/fJH mbYkNcTFhZ2oF8KPRJUe1i1ee4= Received: (qmail 22058 invoked by alias); 19 Mar 2014 22:31:44 -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 22013 invoked by uid 89); 19 Mar 2014 22:31:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Mar 2014 22:31:40 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2JMVYXG019369 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 19 Mar 2014 18:31:35 -0400 Received: from host1.jankratochvil.net (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s2JMVVqp020088; Wed, 19 Mar 2014 18:31:32 -0400 Subject: [PATCH v5 8/8] Tests for validate symbol file using build-id From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: Aleksandar Ristovski Date: Wed, 19 Mar 2014 23:31:31 +0100 Message-ID: <20140319223131.14668.9029.stgit@host1.jankratochvil.net> In-Reply-To: <20140319223004.14668.20989.stgit@host1.jankratochvil.net> References: <20140319223004.14668.20989.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17-dirty MIME-Version: 1.0 X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in Hi, new testcase. Jan gdb/testsuite/ 2014-02-26 Aleksandar Ristovski . */ + + +int _bar = 42; + +int bar(void) +{ + return _bar + 21; +} + +int foo(void) +{ + return _bar; +} diff --git a/gdb/testsuite/gdb.server/solib-mismatch-libmod.c b/gdb/testsuite/gdb.server/solib-mismatch-libmod.c new file mode 100644 index 0000000..fc8827e --- /dev/null +++ b/gdb/testsuite/gdb.server/solib-mismatch-libmod.c @@ -0,0 +1,29 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2014 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 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, see . */ + + +int _bar = 21; + +int bar(void) +{ + return 42 - _bar; +} + +int foo(void) +{ + return 24 + bar(); +} diff --git a/gdb/testsuite/gdb.server/solib-mismatch.c b/gdb/testsuite/gdb.server/solib-mismatch.c new file mode 100644 index 0000000..c8be18a --- /dev/null +++ b/gdb/testsuite/gdb.server/solib-mismatch.c @@ -0,0 +1,56 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2014 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 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, see . */ + + +#include +#include +#include +#include +#include + +/* The following defines must correspond to solib-mismatch.exp . */ + +/* DIRNAME and LIB must be defined at compile time. */ +#ifndef DIRNAME +#error DIRNAME not defined +#endif +#ifndef LIB +#error LIB not defined +#endif + +int main (int argc, char *argv[]) +{ + void *h; + int (*foo) (void); + + if (chdir (DIRNAME) != 0) + { + printf ("ERROR - Could not cd to %s\n", DIRNAME); + return 1; + } + + h = dlopen (LIB, RTLD_NOW); + + if (h == NULL) + { + printf ("ERROR - could not open lib %s\n", LIB); + return 1; + } + foo = dlsym (h, "foo"); /* set breakpoint 1 here */ + dlclose (h); + return 0; +} diff --git a/gdb/testsuite/gdb.server/solib-mismatch.exp b/gdb/testsuite/gdb.server/solib-mismatch.exp new file mode 100644 index 0000000..9dbce7f --- /dev/null +++ b/gdb/testsuite/gdb.server/solib-mismatch.exp @@ -0,0 +1,156 @@ +# Copyright 2014 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 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, see . */ + +standard_testfile +set executable $testfile + +if ![is_remote target] { + untested "only gdbserver supports build-id reporting" + return -1 +} +if [is_remote host] { + untested "only local host is currently supported" + return -1 +} + +# Test overview: +# generate two shared objects. One that will be used by the process +# and another, modified, that will be found by gdb. Gdb should +# detect the mismatch and refuse to use mismatched shared object. + +if { [get_compiler_info] } { + untested "get_compiler_info failed." + return -1 +} + +# First version of the object, to be loaded by ld. +set srclibfilerun ${testfile}-lib.c + +# Modified version of the object to be loaded by gdb +# Code in -libmod.c is tuned so it gives a mismatch but +# leaves .dynamic at the same point. +set srclibfilegdb ${testfile}-libmod.c + +# So file name: +set binlibfilebase lib${testfile}.so + +# Setup run directory (where program is run from) +# It contains executable and '-lib' version of the library. +set binlibfiledirrun [standard_output_file ${testfile}_wd] +set binlibfilerun ${binlibfiledirrun}/${binlibfilebase} + +# Second solib version is in current directory, '-libmod' version. +set binlibfiledirgdb [standard_output_file ""] +set binlibfilegdb ${binlibfiledirgdb}/${binlibfilebase} + +# Executable +set srcfile ${testfile}.c +set executable ${testfile} + +file delete -force -- "${binlibfiledirrun}" +file mkdir "${binlibfiledirrun}" + +set exec_opts {} + +if { ![istarget "*-*-nto-*"] } { + lappend exec_opts "shlib_load" +} + +lappend exec_opts "additional_flags=-DDIRNAME\=\"${binlibfiledirrun}\" -DLIB\=\"./${binlibfilebase}\"" +lappend exec_opts "debug" + +if { [build_executable $testfile.exp $executable $srcfile $exec_opts] != 0 } { + return -1 +} + +if { [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfilerun}" "${binlibfilerun}" [list debug ldflags=-Wl,--build-id]] != "" + || [gdb_gnu_strip_debug "${binlibfilerun}"] + || [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfilegdb}" "${binlibfilegdb}" [list debug ldflags=-Wl,--build-id]] != "" } { + untested "compilation failed." + return -1 +} + +proc solib_matching_test { solibfile symsloaded } { + global gdb_prompt + global testfile + global executable + global srcdir + global subdir + global binlibfiledirrun + global binlibfiledirgdb + global srcfile + + clean_restart ${binlibfiledirrun}/${executable} + + gdb_test_no_output "set solib-search-path \"${binlibfiledirgdb}\"" "" + if { [gdb_test "cd ${binlibfiledirgdb}" "" ""] != 0 } { + untested "cd ${binlibfiledirgdb}" + return -1 + } + + # Do not auto load shared libraries, the test needs to have control + # over when the relevant output gets printed. + gdb_test_no_output "set auto-solib-add off" "" + + if ![runto "${srcfile}:[gdb_get_line_number "set breakpoint 1 here"]"] { + return -1 + } + + gdb_test "sharedlibrary" "" "" + + set nocrlf "\[^\r\n\]*" + set expected_header "From${nocrlf}To${nocrlf}Syms${nocrlf}Read${nocrlf}Shared${nocrlf}" + set expected_line "${symsloaded}${nocrlf}${solibfile}" + + gdb_test "info sharedlibrary ${solibfile}" \ + "${expected_header}\r\n.*${expected_line}.*" \ + "Symbols for ${solibfile} loaded: expected '${symsloaded}'" + + return 0 +} + +# Copy binary to working dir so it pulls in the library from that dir +# (by the virtue of $ORIGIN). +file copy -force "${binlibfiledirgdb}/${executable}" \ + "${binlibfiledirrun}/${executable}" + +# Test unstripped, .dynamic matching +with_test_prefix "test unstripped, .dynamic matching" { + solib_matching_test "${binlibfilebase}" "No" +} + +# Keep original so for debugging purposes +file copy -force "${binlibfilegdb}" "${binlibfilegdb}-orig" +set objcopy_program [transform objcopy] +set result [catch "exec $objcopy_program --only-keep-debug ${binlibfilegdb}"] +if {$result != 0} { + untested "test --only-keep-debug (objcopy)" +} + +# Test --only-keep-debug, .dynamic matching so +with_test_prefix "test --only-keep-debug" { + solib_matching_test "${binlibfilebase}" "No" +} + +# Keep previous so for debugging puroses +file copy -force "${binlibfilegdb}" "${binlibfilegdb}-orig1" + +# Copy loaded so over the one gdb will find +file copy -force "${binlibfilerun}" "${binlibfilegdb}" + +# Now test it does not mis-invalidate matching libraries +with_test_prefix "test matching libraries" { + solib_matching_test "${binlibfilebase}" "Yes" +}