From: Jerome Guitton <guitton@adacore.com>
To: gdb-patches@sourceware.org
Cc: Jerome Guitton <guitton@adacore.com>
Subject: [RFA] testcase for code/data elimination
Date: Wed, 21 Jul 2010 13:44:00 -0000 [thread overview]
Message-ID: <1279719831-14906-1-git-send-email-guitton@adacore.com> (raw)
I have written this testcase in the context of
http://sourceware.org/ml/gdb-patches/2010-07/msg00206.html but it is a
bit more general than that: it tests that GDB can handle properly
application that have been built with code and data elimination
(-fdata-sections, -ffunction-sections and -gc-sections) and that no
"ghost" code/data symbols shows up in symtab/psymtab.
OK to apply?
gdb/testsuite/ChangeLog:
* gdb.base/code_elim.exp: New file.
* gdb.base/code_elim1.c: New file.
* gdb.base/code_elim2.c: New file.
---
gdb/testsuite/gdb.base/code_elim.exp | 174 ++++++++++++++++++++++++++++++++++
gdb/testsuite/gdb.base/code_elim1.c | 37 +++++++
gdb/testsuite/gdb.base/code_elim2.c | 35 +++++++
3 files changed, 246 insertions(+), 0 deletions(-)
create mode 100644 gdb/testsuite/gdb.base/code_elim.exp
create mode 100644 gdb/testsuite/gdb.base/code_elim1.c
create mode 100644 gdb/testsuite/gdb.base/code_elim2.c
diff --git a/gdb/testsuite/gdb.base/code_elim.exp b/gdb/testsuite/gdb.base/code_elim.exp
new file mode 100644
index 0000000..ce08231
--- /dev/null
+++ b/gdb/testsuite/gdb.base/code_elim.exp
@@ -0,0 +1,174 @@
+# Copyright 2002, 2003, 2005, 2007, 2008, 2009, 2010
+# 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/>. */
+
+# code_elim.exp -- tests that GDB can handle executables where some data/code
+# has been eliminated by the linker.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set testfile1 code_elim1
+set testfile2 code_elim2
+set srcfile1 ${testfile1}.c
+set srcfile2 ${testfile2}.c
+set binfile1 ${objdir}/${subdir}/${testfile1}
+set binfile2 ${objdir}/${subdir}/${testfile2}
+set opts [list debug]
+lappend opts "additional_flags=-ffunction-sections"
+lappend opts "additional_flags=-fdata-sections"
+lappend opts "additional_flags=-Wl,-gc-sections"
+lappend opts "additional_flags=-Wl,-e,main"
+
+remote_exec build "rm -f ${binfile1}"
+remote_exec build "rm -f ${binfile2}"
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable $opts] != "" } {
+ untested code_elim.exp
+ return -1
+}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $opts] != "" } {
+ untested code_elim.exp
+ return -1
+}
+
+proc get_var_address { var } {
+ global gdb_prompt hex
+
+ # Match output like:
+ # $1 = (int *) 0x0
+ # $5 = (int (*)()) 0
+ # $6 = (int (*)()) 0x24 <function_bar>
+
+ gdb_test_multiple "print &${var}" "get address of ${var}" {
+ -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
+ pass "get address of ${var}"
+ if { $expect_out(1,string) == "0" } {
+ return "0x0"
+ } else {
+ return $expect_out(1,string)
+ }
+ }
+ }
+ return ""
+}
+
+proc not_null_var_address { var } {
+
+ # Same as get_var_address, expect that it reports a failure if a null
+ # address is returned by gdb.
+
+ set address [get_var_address $var]
+ regexp "0x\[0-9a-fA-F\]+" $address address
+ if { "$address" == "0x0" } {
+ fail "$var has null address"
+ }
+}
+
+proc test_eliminated_var { var } {
+ global gdb_prompt hex
+
+ # Match output 'No symbol "${var}" in current context'
+
+ gdb_test_multiple "print &${var}" "test eliminated var ${var}" {
+ -re "No symbol \"${var}\" in current context" {
+ pass "test eliminated var ${var}"
+ }
+ -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
+ fail "test eliminated var ${var}"
+ }
+ }
+ return ""
+}
+
+# Check that the code and data eliminated in binfile1 are not included
+# into partial symtab... and that non-eliminated symbols are still there.
+
+gdb_exit
+gdb_start
+
+gdb_test "add-symbol-file ${binfile1} 0x100000" \
+ "Reading symbols from .*${testfile1}\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
+ "add-symbol-file ${testfile1} 0x100000" \
+ "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
+ "y"
+
+test_eliminated_var my_global_symbol
+test_eliminated_var my_static_symbol
+test_eliminated_var my_global_func
+not_null_var_address main
+
+# Same thing for symtabs
+
+gdb_exit
+global GDBFLAGS
+set saved_gdbflags $GDBFLAGS
+set GDBFLAGS "$GDBFLAGS --readnow $binfile1"
+gdb_start
+set GDBFLAGS $saved_gdbflags
+
+test_eliminated_var my_global_symbol
+test_eliminated_var my_static_symbol
+test_eliminated_var my_global_func
+not_null_var_address main
+
+# binfile2 contains the symbols that have been eliminated in binfile1. Check
+# the eliminated symbols does not hide these valid ones.
+
+gdb_exit
+gdb_start
+
+gdb_test "add-symbol-file ${binfile1} 0x100000" \
+ "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
+ "add-symbol-file ${testfile1} 0x100000" \
+ "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
+ "y"
+
+gdb_test "add-symbol-file ${binfile2} 0x200000" \
+ "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
+ "add-symbol-file ${testfile2} 0x200000" \
+ "add symbol table from file \".*${testfile2}\" at\[ \t\r\n\]+\.text_addr = 0x200000\[\r\n\]+\\(y or n\\) " \
+ "y"
+
+not_null_var_address my_global_symbol
+not_null_var_address my_static_symbol
+not_null_var_address my_global_func
+not_null_var_address main
+
+# Same thing, but loading binfile2 before binfile1.
+
+gdb_exit
+gdb_start
+
+gdb_test "add-symbol-file ${binfile2} 0x200000" \
+ "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
+ "add-symbol-file ${testfile2} 0x200000" \
+ "add symbol table from file \".*${testfile2}\" at\[ \t\r\n\]+\.text_addr = 0x200000\[\r\n\]+\\(y or n\\) " \
+ "y"
+
+gdb_test "add-symbol-file ${binfile1} 0x100000" \
+ "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
+ "add-symbol-file ${testfile1} 0x100000" \
+ "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
+ "y"
+
+not_null_var_address my_global_symbol
+not_null_var_address my_static_symbol
+not_null_var_address my_global_func
+not_null_var_address main
+
+
diff --git a/gdb/testsuite/gdb.base/code_elim1.c b/gdb/testsuite/gdb.base/code_elim1.c
new file mode 100644
index 0000000..6aef483
--- /dev/null
+++ b/gdb/testsuite/gdb.base/code_elim1.c
@@ -0,0 +1,37 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2010
+ 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 my_global_symbol = 42;
+
+static int my_static_symbol;
+
+int
+main ()
+{
+ int v_in_main;
+
+ return v_in_main;
+}
+
+int
+my_global_func ()
+{
+ int v_in_global_func;
+
+ return v_in_global_func;
+}
diff --git a/gdb/testsuite/gdb.base/code_elim2.c b/gdb/testsuite/gdb.base/code_elim2.c
new file mode 100644
index 0000000..61a4556
--- /dev/null
+++ b/gdb/testsuite/gdb.base/code_elim2.c
@@ -0,0 +1,35 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2010
+ 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 my_global_symbol = 42;
+
+static int my_static_symbol;
+
+int
+main ()
+{
+ return my_global_func ();
+}
+
+int
+my_global_func ()
+{
+ my_static_symbol = my_global_symbol;
+ my_global_symbol = my_static_symbol + my_global_symbol;
+ return my_global_symbol;
+}
--
1.6.5.rc2
next reply other threads:[~2010-07-21 13:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-21 13:44 Jerome Guitton [this message]
2010-07-21 19:29 ` Jan Kratochvil
2010-07-22 9:01 ` Jerome Guitton
2010-07-23 22:47 ` Tom Tromey
2010-07-26 9:40 ` Jerome Guitton
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=1279719831-14906-1-git-send-email-guitton@adacore.com \
--to=guitton@adacore.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).