From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Cc: Aleksandar Ristovski <ARistovski@qnx.com>
Subject: [PATCH v7 10/10] Tests for validate symbol file using build-id
Date: Sun, 14 Jun 2015 19:27:00 -0000 [thread overview]
Message-ID: <20150614192703.18346.41595.stgit@host1.jankratochvil.net> (raw)
In-Reply-To: <20150614192542.18346.87859.stgit@host1.jankratochvil.net>
Hi,
new testcase.
There was no explicit approval by Tom Tromey in the series a year ago.
Jan
gdb/testsuite/ChangeLog
2014-02-26 Aleksandar Ristovski <aristovski@qnx.com
Tests for validate symbol file using build-id.
* gdb.base/solib-mismatch-lib.c: New file.
* gdb.base/solib-mismatch-libmod.c: New file.
* gdb.base/solib-mismatch.c: New file.
* gdb.base/solib-mismatch.exp: New file.
---
gdb/testsuite/gdb.base/solib-mismatch-lib.c | 29 ++++
gdb/testsuite/gdb.base/solib-mismatch-libmod.c | 29 ++++
gdb/testsuite/gdb.base/solib-mismatch.c | 56 +++++++++
gdb/testsuite/gdb.base/solib-mismatch.exp | 156 ++++++++++++++++++++++++
4 files changed, 270 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/solib-mismatch-lib.c
create mode 100644 gdb/testsuite/gdb.base/solib-mismatch-libmod.c
create mode 100644 gdb/testsuite/gdb.base/solib-mismatch.c
create mode 100644 gdb/testsuite/gdb.base/solib-mismatch.exp
diff --git a/gdb/testsuite/gdb.base/solib-mismatch-lib.c b/gdb/testsuite/gdb.base/solib-mismatch-lib.c
new file mode 100644
index 0000000..b22863a
--- /dev/null
+++ b/gdb/testsuite/gdb.base/solib-mismatch-lib.c
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 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 <http://www.gnu.org/licenses/>. */
+
+
+int _bar = 42;
+
+int bar(void)
+{
+ return _bar + 21;
+}
+
+int foo(void)
+{
+ return _bar;
+}
diff --git a/gdb/testsuite/gdb.base/solib-mismatch-libmod.c b/gdb/testsuite/gdb.base/solib-mismatch-libmod.c
new file mode 100644
index 0000000..9c3f37e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/solib-mismatch-libmod.c
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 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 <http://www.gnu.org/licenses/>. */
+
+
+int _bar = 21;
+
+int bar(void)
+{
+ return 42 - _bar;
+}
+
+int foo(void)
+{
+ return 24 + bar();
+}
diff --git a/gdb/testsuite/gdb.base/solib-mismatch.c b/gdb/testsuite/gdb.base/solib-mismatch.c
new file mode 100644
index 0000000..0979c81
--- /dev/null
+++ b/gdb/testsuite/gdb.base/solib-mismatch.c
@@ -0,0 +1,56 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 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 <http://www.gnu.org/licenses/>. */
+
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+
+/* 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.base/solib-mismatch.exp b/gdb/testsuite/gdb.base/solib-mismatch.exp
new file mode 100644
index 0000000..4983429
--- /dev/null
+++ b/gdb/testsuite/gdb.base/solib-mismatch.exp
@@ -0,0 +1,156 @@
+# Copyright 2015 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 <http://www.gnu.org/licenses/>. */
+
+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"
+}
next prev parent reply other threads:[~2015-06-14 19:27 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
2015-06-14 19:25 ` [PATCH v7 01/10] Move utility functions to common/ Jan Kratochvil
2015-06-15 13:22 ` Joel Brobecker
2015-06-15 15:07 ` [commit] " Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 06/10] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 02/10] Merge multiple hex conversions Jan Kratochvil
2015-06-15 13:33 ` Joel Brobecker
2015-06-15 15:09 ` [commit] " Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 04/10] Create empty nat/linux-maps.[ch] and common/target-utils.[ch] Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags Jan Kratochvil
2015-06-15 13:34 ` Joel Brobecker
2015-06-15 15:12 ` [commit] " Jan Kratochvil
2015-07-08 14:38 ` Pedro Alves
2015-06-14 19:26 ` [PATCH v7 07/10] Move linux_find_memory_regions_full & co Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 05/10] Move gdb_regex* to common/ Jan Kratochvil
2015-07-08 14:39 ` Pedro Alves
2015-07-14 20:13 ` Jan Kratochvil
2015-06-14 19:27 ` [PATCH v7 08/10] gdbserver build-id attribute generator Jan Kratochvil
2015-07-08 14:41 ` Pedro Alves
2015-06-14 19:27 ` Jan Kratochvil [this message]
2015-07-08 14:44 ` [PATCH v7 10/10] Tests for validate symbol file using build-id Pedro Alves
2015-06-14 19:27 ` [PATCH v7 09/10] Validate " Jan Kratochvil
2015-06-21 10:16 ` [PATCH v8 " Jan Kratochvil
2015-06-22 12:55 ` Aleksandar Ristovski
2015-06-22 20:37 ` Jan Kratochvil
2015-06-22 20:41 ` Aleksandar Ristovski
2015-06-22 22:25 ` Doug Evans
2015-06-23 20:47 ` Jan Kratochvil
2015-07-08 14:44 ` Pedro Alves
2015-07-12 19:09 ` Jan Kratochvil
2015-07-12 19:29 ` [PATCH v9 " Jan Kratochvil
2015-07-12 19:54 ` Eli Zaretskii
2015-07-12 20:01 ` Jan Kratochvil
2015-07-13 2:30 ` Eli Zaretskii
2015-07-13 10:34 ` Pedro Alves
2015-07-13 12:38 ` Jan Kratochvil
2015-07-14 16:14 ` Doug Evans
2015-07-15 8:21 ` Jan Kratochvil
2015-07-15 14:59 ` Doug Evans
2015-06-27 21:05 ` [PATCH v8 " Jan Kratochvil
2015-07-08 15:40 ` Doug Evans
2015-07-12 19:27 ` Jan Kratochvil
2015-07-15 16:36 ` [commit] [PATCH v7 00/10] Validate binary before use Jan Kratochvil
2015-07-15 18:33 ` [revert] " Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150614192703.18346.41595.stgit@host1.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=ARistovski@qnx.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).