From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8459 invoked by alias); 1 Sep 2006 23:18:56 -0000 Received: (qmail 8446 invoked by uid 22791); 1 Sep 2006 23:18:53 -0000 X-Spam-Check-By: sourceware.org Received: from ip-160-218-139-130.eurotel.cz (HELO host0.dyn.jankratochvil.net) (160.218.139.130) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 01 Sep 2006 23:18:47 +0000 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.13.7/8.13.7) with ESMTP id k81NIfHL009261 for ; Sat, 2 Sep 2006 01:18:41 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.13.7/8.13.7/Submit) id k81NIbZi009260 for gdb-patches@sourceware.org; Sat, 2 Sep 2006 01:18:37 +0200 Date: Fri, 01 Sep 2006 23:18:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: Re: [patch] TLS resolving for separate_debug_objfile Message-ID: <20060901231837.GA9252@host0.dyn.jankratochvil.net> References: <20060901111241.GA23025@host0.dyn.jankratochvil.net> <20060901125337.GA7408@nevyn.them.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="3V7upXqbjpZ4EhLz" Content-Disposition: inline In-Reply-To: <20060901125337.GA7408@nevyn.them.org> User-Agent: Mutt/1.4.2.2i X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-09/txt/msg00009.txt.bz2 --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1102 On Fri, 01 Sep 2006 14:53:37 +0200, Daniel Jacobowitz wrote: ... > Can you reproduce it on mainline ... > ? OK, provided full testsuite this time. The testsuite also covers the second patch (of `svr4_fetch_objfile_link_map'): If you provided some relative path to the shared library, such as with export LD_LIBRARY_PATH=. then gdb would fail to match the shared library name during the TLS lookup. The testsuite also requires my older patch "gdb-solib-path.patch", still not committed. Posted as <20060622114016.GA21094@host0.dyn.jankratochvil.net>, approved by Kevin Buettner : 2006-06-22 Jan Kratochvil * solib.c (solib_open): Fixed NULL vs. "" refusal to load inferior shared libraries. ChangeLog for "gdb-sharedlibrary-path.patch": 2006-09-01 Jan Kratochvil * dwarf2loc.c (dwarf_expr_tls_address): Fix for separate debuginfo. * solib-svr4.c (svr4_fetch_objfile_link_map): Match even absolute requested pathnames to the internal loaded relative pathnames. Testsuite results not changed. Best Regards, Jan --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-solib-path.patch" Content-length: 1660 Index: solib.c =================================================================== RCS file: /cvs/src/src/gdb/solib.c,v retrieving revision 1.84 diff -u -p -r1.84 solib.c --- solib.c 25 Feb 2006 04:36:39 -0000 1.84 +++ solib.c 1 Sep 2006 18:47:11 -0000 @@ -146,13 +146,17 @@ solib_open (char *in_pathname, char **fo int found_file = -1; char *temp_pathname = NULL; char *p = in_pathname; + int solib_absolute_prefix_is_empty; + + solib_absolute_prefix_is_empty = (solib_absolute_prefix == NULL + || *solib_absolute_prefix == 0); while (*p && !IS_DIR_SEPARATOR (*p)) p++; if (*p) { - if (! IS_ABSOLUTE_PATH (in_pathname) || solib_absolute_prefix == NULL) + if (! IS_ABSOLUTE_PATH (in_pathname) || solib_absolute_prefix_is_empty) temp_pathname = in_pathname; else { @@ -208,14 +212,14 @@ solib_open (char *in_pathname, char **fo &temp_pathname); /* If not found, next search the inferior's $PATH environment variable. */ - if (found_file < 0 && solib_absolute_prefix == NULL) + if (found_file < 0 && solib_absolute_prefix_is_empty) found_file = openp (get_in_environ (inferior_environ, "PATH"), OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, 0, &temp_pathname); /* If not found, next search the inferior's $LD_LIBRARY_PATH environment variable. */ - if (found_file < 0 && solib_absolute_prefix == NULL) + if (found_file < 0 && solib_absolute_prefix_is_empty) found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"), OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, 0, &temp_pathname); --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-sharedlibrary-path.patch" Content-length: 11951 Index: dwarf2loc.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2loc.c,v retrieving revision 1.33 diff -u -p -r1.33 dwarf2loc.c --- dwarf2loc.c 17 Dec 2005 22:33:59 -0000 1.33 +++ dwarf2loc.c 1 Sep 2006 18:47:09 -0000 @@ -198,6 +198,12 @@ dwarf_expr_tls_address (void *baton, COR struct objfile *objfile = debaton->objfile; volatile struct gdb_exception ex; + /* Resolve: Cannot find shared library + `/usr/lib/debug/lib/lib....so.debug' in dynamic linker's load + module list */ + if (objfile->separate_debug_objfile_backlink != NULL) + objfile = objfile->separate_debug_objfile_backlink; + TRY_CATCH (ex, RETURN_MASK_ALL) { CORE_ADDR lm_addr; Index: solib-svr4.c =================================================================== RCS file: /cvs/src/src/gdb/solib-svr4.c,v retrieving revision 1.58 diff -u -p -r1.58 solib-svr4.c --- solib-svr4.c 18 May 2006 20:38:56 -0000 1.58 +++ solib-svr4.c 1 Sep 2006 18:47:10 -0000 @@ -774,62 +774,81 @@ CORE_ADDR svr4_fetch_objfile_link_map (struct objfile *objfile) { CORE_ADDR lm; + int resolve; if ((debug_base = locate_base ()) == 0) return 0; /* failed somehow... */ - /* Position ourselves on the first link map. */ - lm = solib_svr4_r_map (); - while (lm) + for (resolve = 0; resolve <= 1; resolve++) { - /* Get info on the layout of the r_debug and link_map structures. */ - struct link_map_offsets *lmo = svr4_fetch_link_map_offsets (); - int errcode; - char *buffer; - struct lm_info objfile_lm_info; - struct cleanup *old_chain; - CORE_ADDR name_address; - gdb_byte *l_name_buf = xmalloc (lmo->l_name_size); - old_chain = make_cleanup (xfree, l_name_buf); - - /* Set up the buffer to contain the portion of the link_map - structure that gdb cares about. Note that this is not the - whole link_map structure. */ - objfile_lm_info.lm = xzalloc (lmo->link_map_size); - make_cleanup (xfree, objfile_lm_info.lm); - - /* Read the link map into our internal structure. */ - read_memory (lm, objfile_lm_info.lm, lmo->link_map_size); - - /* Read address of name from target memory to GDB. */ - read_memory (lm + lmo->l_name_offset, l_name_buf, lmo->l_name_size); - - /* Extract this object's name. Assume that the address is - unsigned. */ - name_address = extract_unsigned_integer (l_name_buf, lmo->l_name_size); - target_read_string (name_address, &buffer, - SO_NAME_MAX_PATH_SIZE - 1, &errcode); - make_cleanup (xfree, buffer); - if (errcode != 0) - warning (_("Can't read pathname for load map: %s."), - safe_strerror (errcode)); - else - { - /* Is this the linkmap for the file we want? */ - /* If the file is not a shared library and has no name, - we are sure it is the main executable, so we return that. */ - if ((buffer && strcmp (buffer, objfile->name) == 0) - || (!(objfile->flags & OBJF_SHARED) && (strcmp (buffer, "") == 0))) - { - do_cleanups (old_chain); - return lm; - } - } - /* Not the file we wanted, continue checking. Assume that the - address is unsigned. */ - lm = extract_unsigned_integer (objfile_lm_info.lm + lmo->l_next_offset, - lmo->l_next_size); - do_cleanups (old_chain); + /* Position ourselves on the first link map. */ + lm = solib_svr4_r_map (); + while (lm) + { + /* Get info on the layout of the r_debug and link_map structures. */ + struct link_map_offsets *lmo = svr4_fetch_link_map_offsets (); + int errcode; + char *buffer; + struct lm_info objfile_lm_info; + struct cleanup *old_chain; + CORE_ADDR name_address; + gdb_byte *l_name_buf = xmalloc (lmo->l_name_size); + old_chain = make_cleanup (xfree, l_name_buf); + + /* Set up the buffer to contain the portion of the link_map + structure that gdb cares about. Note that this is not the + whole link_map structure. */ + objfile_lm_info.lm = xzalloc (lmo->link_map_size); + make_cleanup (xfree, objfile_lm_info.lm); + + /* Read the link map into our internal structure. */ + read_memory (lm, objfile_lm_info.lm, lmo->link_map_size); + + /* Read address of name from target memory to GDB. */ + read_memory (lm + lmo->l_name_offset, l_name_buf, lmo->l_name_size); + + /* Extract this object's name. Assume that the address is + unsigned. */ + name_address = extract_unsigned_integer (l_name_buf, lmo->l_name_size); + target_read_string (name_address, &buffer, + SO_NAME_MAX_PATH_SIZE - 1, &errcode); + make_cleanup (xfree, buffer); + if (errcode != 0) + warning (_("Can't read pathname for load map: %s."), + safe_strerror (errcode)); + else + { + /* solib_svr4_r_map() may contain relative pathnames while + `objfile->name' is absolute. */ + if (resolve && buffer && buffer[0] != '/') + { + char *absolute; + int fd; + + fd = solib_open (buffer, &absolute); + if (fd != -1) + { + make_cleanup (xfree, absolute); + buffer = absolute; + close (fd); + } + } + /* Is this the linkmap for the file we want? */ + /* If the file is not a shared library and has no name, + we are sure it is the main executable, so we return that. */ + if ((buffer && strcmp (buffer, objfile->name) == 0) + || (!(objfile->flags & OBJF_SHARED) && (strcmp (buffer, "") == 0))) + { + do_cleanups (old_chain); + return lm; + } + } + /* Not the file we wanted, continue checking. Assume that the + address is unsigned. */ + lm = extract_unsigned_integer (objfile_lm_info.lm + lmo->l_next_offset, + lmo->l_next_size); + do_cleanups (old_chain); + } } return 0; } Index: testsuite/gdb.threads/tls-sepdebug-main.c =================================================================== RCS file: testsuite/gdb.threads/tls-sepdebug-main.c diff -N testsuite/gdb.threads/tls-sepdebug-main.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.threads/tls-sepdebug-main.c 1 Sep 2006 18:47:14 -0000 @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2006 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@prep.ai.mit.edu */ + +int main() +{ + return 0; +} Index: testsuite/gdb.threads/tls-sepdebug-shared.c =================================================================== RCS file: testsuite/gdb.threads/tls-sepdebug-shared.c diff -N testsuite/gdb.threads/tls-sepdebug-shared.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.threads/tls-sepdebug-shared.c 1 Sep 2006 18:47:14 -0000 @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2006 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@prep.ai.mit.edu */ + +__thread int var = 42; Index: testsuite/gdb.threads/tls-sepdebug.exp =================================================================== RCS file: testsuite/gdb.threads/tls-sepdebug.exp diff -N testsuite/gdb.threads/tls-sepdebug.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.threads/tls-sepdebug.exp 1 Sep 2006 18:47:14 -0000 @@ -0,0 +1,81 @@ +# Copyright 2006 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 2 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +if $tracelevel then { + strace $tracelevel +} + +set testfile tls-sepdebug +set srcmainfile ${testfile}-main.c +set srcsharedfile ${testfile}-shared.c + +# DO NOT use ${objdir} obsolute reference here as we test relative directories +# below and the absolute pathnames must not get encoded to the binaries. + +set binmainfile ${testfile}-main +set binsharedfile ${testfile}-shared.so +set binshareddebugfile ${testfile}-shared.so.debug + +if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcsharedfile}" "${binsharedfile}" {debug}] != "" } { + untested "Couldn't compile test library" + return -1 +} + +# eu-strip(1) works fine but it is a part of `elfutils', not `binutils'. +if 0 then { + remote_exec build "eu-strip -f ${binshareddebugfile} ${binsharedfile}" +} else { + remote_exec build "objcopy --only-keep-debug ${binsharedfile} ${binshareddebugfile}" + remote_exec build "objcopy --strip-debug ${binsharedfile}" + remote_exec build "objcopy --add-gnu-debuglink=${binshareddebugfile} ${binsharedfile}" +} + +if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcmainfile}" "${binmainfile}" executable [list debug shlib=${binsharedfile}]] != "" } { + untested "Couldn't compile test program" + return -1 +} + +# Get things started. + +# Test also the proper resolving of relative library names to absolute ones. +# \$PWD is easy - it is the absolute way +# ${subdir} would fail on "print var" + +foreach ld_library_path { \$PWD ${subdir} } name { absolute relative } { + + gdb_exit + gdb_start + ###gdb_reinitialize_dir $srcdir/$subdir + + gdb_test "set env LD_LIBRARY_PATH=$ld_library_path" \ + "" \ + "set env LD_LIBRARY_PATH is $name" + + gdb_load ${binmainfile} + + # For C programs, "start" should stop in main(). + + gdb_test "start" \ + "main \\(\\) at .*${srcmainfile}.*" \ + "start" + + # Check for: Cannot find shared library `/usr/lib/debug/lib/libc-2.4.90.so.debug' in dynamic linker's load module list + # as happens with TLS variables and `separate_debug_objfile_backlink'. + + gdb_test "print var" \ + "\\\$1 = \[0-9\].*" \ + "print TLS variable from a shared library with $name-directory separate debug info file" +} --3V7upXqbjpZ4EhLz--