This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[1/3, ppc64, gdb FYI testcase] eu-strip vs. func addresses for GDB inferior calls


Hi,

this is IMO an elfutils + bfd bug affecting GDB but not a GDB bug.

Contrary to binutils --strip-debug/--only-keep-debug the strip command from
elfutils (eu-strip) moves even the .symtab section into the .debug file.

If you pass address of an inferior function to a different inferior function it
will fail if the inferior has separate debug info file from current eu-strip.
That is GDB convert_code_addr_to_desc_addr will fail on these, passing the code
address instead of the function descriptor, jumping to a garbage address.


(gdb) ptype callfunc
type = int (int (*)(void))
(gdb) ptype func
type = int (void)

before the fix:
(gdb) p callfunc (func)
Program received signal SIGSEGV, Segmentation fault.
0xfbe1fff8f821ffc0 in ?? ()
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on".
Evaluation of the expression containing the function
(callfunc) will be abandoned.
When the function is done executing, GDB will silently stop.
(gdb) FAIL: gdb.base/eu-strip-infcall.exp: infcall

after the fix:
(gdb) p callfunc (func)
$1 = 2
(gdb) PASS: gdb.base/eu-strip-infcall.exp: infcall


The elfutils patch reason:
The bfd/elf64-ppc.c line
	ent = bfd_get_64 (abfd, contents + syms[i]->value);
fails to read the real address from .opd while it reads the .symtab section in
the .debug file as the .opd section is SHT_NOBITS there.  Therefore proposing
to keep an .opd copy both in the main and in the .debug file.  While BFD reads
the .debug file it has no real link to the binary file (only GDB has such
link).

The bfd patch reason:
BFD will assign the wrong (.opd instead of expected .text) section for the
code artificial symbol as the .text section is SHT_NOBITS in the .debug file.
GDB will then fail to find the minimal symbol due to the non-matchin section.

Providing a GDB testcase but only FYI as it depends on elfutils so I will keep
it only in the Fedora testsuite.


Thanks,
Jan


gdb/testsuite/
2011-03-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.base/eu-strip-infcall.c: New file.
	* gdb.base/eu-strip-infcall.exp: New file.

--- /dev/null
+++ b/gdb/testsuite/gdb.base/eu-strip-infcall.c
@@ -0,0 +1,34 @@
+/* Copyright 2011 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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
+func (void)
+{
+  return 1;
+}
+
+int
+callfunc (int (*funcp) (void))
+{
+  return funcp () * 2;
+}
+
+int
+main (void)
+{
+  return callfunc (func);
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.base/eu-strip-infcall.exp
@@ -0,0 +1,36 @@
+# Copyright (C) 2011 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/>.
+
+set testfile eu-strip-infcall
+set binfile ${objdir}/${subdir}/${testfile}
+
+if {[build_executable ${testfile}.exp $testfile] == -1} {
+    return -1
+}
+
+set test "eu-strip"
+set status [remote_exec build "eu-strip -f ${binfile}.debug $binfile"]
+if {[lindex $status 0] != 0} {
+    untested ${testfile}.exp
+    return 0
+}
+
+clean_restart $testfile
+
+if ![runto_main] {
+    return -1
+}
+
+gdb_test "p callfunc (func)" " = 2" "infcall"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]