This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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]

[patch+7.4] Fix gdbserver qXfer:libraries-svr4 regression in special cases


Hi,

in a special case of running gdbserver IIRC by Daniel Jacobowitz before (I did
not try to find that mail) there is a 7.4 regression by the
qXfer:libraries-svr4 latency optimization.

+# In some cases gdbserver cannot find the DT_DEBUG library list on its own and
+# it needs to fall back to GDB solib-svr4.c look up via symbols from the main
+# executable.
+# gdbserver :1234 ld-linux-x86-64.so.2 /bin/prog
+# gdb /bin/prog
+# (gdb) target remote ...

No regressions on {x86_64,x86_64-m32,i686}-fedora17-linux-gnu in non-extended
gdbserver mode.

I had even coded this fallback before for the cases where the new gdbserver
code fails but later decided in such case it is better to fix gdbserver
instead.  I did not realize there may be cases where gdbserver just cannot
find the list while GDB can.

OTOH sure there may be a way of figuring out the shared library list in such
a case by gdbserver itself.  I did not investigate the details.  Still
I believe the fallback cases are negligible enough to need to care about
optimizing them.

I found it from the following mail but in fact it is completely unrelated:
	gdbserver: Unexpected missing PT_PHDR when running break-interp.exp
	http://sourceware.org/ml/gdb-patches/2012-03/msg00095.html

The testcase is a bit ugly.


Sorry,
Jan


gdb/
2012-03-03  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* solib-svr4.c (svr4_current_sos): New comment on
	svr4_current_sos_via_xfer_libraries fall back.

gdb/gdbserver/
2012-03-03  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* linux-low.c (linux_qxfer_libraries_svr4): Return -1 if R_DEBUG is -1.

Gdb/testsuite/
2012-03-03  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.server/solib-list-lib.c: New file.
	* gdb.server/solib-list-main.c: New file.
	* gdb.server/solib-list.exp: New file.

--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1260,6 +1260,14 @@ svr4_current_sos (void)
   int ignore_first;
   struct svr4_library_list library_list;
 
+  /* Fall back to manual examination of the target if the packet is not
+     supported or gdbserver failed to find DT_DEBUG.  gdb.server/solib-list.exp
+     tests a case where gdbserver cannot find the shared libraries list while
+     GDB itself is able to find it via SYMFILE_OBJFILE.
+
+     Unfortunately statically linked inferiors will also fall back through this
+     suboptimal code path.  */
+
   if (svr4_current_sos_via_xfer_libraries (&library_list))
     {
       if (library_list.main_lm)
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -5400,6 +5400,12 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
   if (priv->r_debug == 0)
     priv->r_debug = get_r_debug (pid, is_elf64);
 
+  /* We failed to find DT_DEBUG.  Such situation will not change for this
+     inferior - do not retry it.  Report it to GDB as E01, see for the reasons
+     at the GDB solib-svr4.c side.  */
+  if (priv->r_debug == (CORE_ADDR) -1)
+    return -1;
+
   if (priv->r_debug == (CORE_ADDR) -1 || priv->r_debug == 0)
     {
       document = xstrdup ("<library-list-svr4 version=\"1.0\"/>\n");
--- /dev/null
+++ b/gdb/testsuite/gdb.server/solib-list-lib.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012 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 <signal.h>
+
+static int libvar = 23;
+
+int
+libfunc (void)
+{
+  raise (SIGUSR1);
+
+  return libvar;
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.server/solib-list-main.c
@@ -0,0 +1,25 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012 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/>.  */
+
+extern int libfunc (void);
+
+int
+main (void)
+{
+  libfunc ();
+  return 0;
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.server/solib-list.exp
@@ -0,0 +1,68 @@
+# Copyright 2010-2012 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/>.  */
+
+# In some cases gdbserver cannot find the DT_DEBUG library list on its own and
+# it needs to fall back to GDB solib-svr4.c look up via symbols from the main
+# executable.
+# gdbserver :1234 ld-linux-x86-64.so.2 /bin/prog
+# gdb /bin/prog
+# (gdb) target remote ...
+
+load_lib gdbserver-support.exp
+load_lib prelink-support.exp
+
+if {[skip_gdbserver_tests] || [skip_shlib_tests]} {
+    return
+}
+
+set testfile "solib-list"
+set srclibfile ${testfile}-lib.c
+set srcfile ${testfile}-main.c
+set binlibfile ${objdir}/${subdir}/${testfile}.so
+set executable ${testfile}
+set objfile ${objdir}/${subdir}/${executable}.o
+set binfile ${objdir}/${subdir}/${executable}
+
+if { [get_compiler_info unused]
+     || [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfile}" "${binlibfile}" [list debug ldflags=-Wl,-soname,${binlibfile}]] != ""
+     || [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug}] != ""
+     || [gdb_compile "${objfile} ${binlibfile}" "${binfile}" executable {}] != "" } {
+    untested "could not compile sources"
+    return -1
+}
+
+set interp_system [section_get ${binfile} .interp]
+verbose -log "system interpreter is: $interp_system"
+
+# clean_restart assumes ${objdir}/${subdir}/ which is not applicable
+# for ${interp_system}.
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${interp_system}
+gdb_load_shlibs ${binfile}
+gdb_load_shlibs ${binlibfile}
+
+# Make sure we're disconnected, in case we're testing with an
+# extended-remote board, therefore already connected.
+gdb_test "disconnect" ".*"
+    
+gdbserver_run ${binfile}
+
+gdb_test "file ${binfile}" {Reading symbols from .*\.\.\.done\.} "file binfile" \
+	 {(Are you sure you want to change the file|Load new symbol table from ".*")\? \(y or n\) } "y"
+gdb_test "continue" "Program received signal SIGUSR1, .*"
+
+gdb_test "p libvar" " = 23"


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