From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16070 invoked by alias); 9 Oct 2013 14:46:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 16059 invoked by uid 89); 9 Oct 2013 14:46:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 09 Oct 2013 14:46:38 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r99EkYKr005102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 9 Oct 2013 10:46:35 -0400 Received: from host2.jankratochvil.net (ovpn-116-51.ams2.redhat.com [10.36.116.51]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r99EkUWU016714 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Wed, 9 Oct 2013 10:46:32 -0400 Date: Wed, 09 Oct 2013 14:46:00 -0000 From: Jan Kratochvil To: Doug Evans Cc: gdb-patches@sourceware.org Subject: [patchv2] Record objfile->original_name as an absolute path Message-ID: <20131009144629.GC27355@host2.jankratochvil.net> References: <20130926084713.GA11031@host2.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130926084713.GA11031@host2.jankratochvil.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00275.txt.bz2 Hi Doug, here is an updated+rebased patch. The testcase is kept as is. No regressions on {x86_64,x86_64-m32,i686}-fedora21pre-linux-gnu. Thanks, Jan gdb/ 2013-09-25 Doug Evans Jan Kratochvil * objfiles.c (allocate_objfile): Save original_name as an absolute path. * objfiles.h (struct objfile): Expand comment on original_name. * source.c (openp): Call gdb_abspath. * utils.c (gdb_abspath): New function. * utils.h (gdb_abspath): Declare. gdb/testsuite/ 2013-09-25 Doug Evans * gdb.dwarf/dwp-symlink.c: Fake out gdb to not load debug info at start. * gdb.dwarf/dwp-symlink.exp: Test trying to load dwp when the binary has been specified with a relative path and we have chdir'd before accessing the debug info. diff --git a/gdb/objfiles.c b/gdb/objfiles.c index d1f3121..8cc93c5 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -276,6 +276,7 @@ struct objfile * allocate_objfile (bfd *abfd, const char *name, int flags) { struct objfile *objfile; + char *expanded_name; objfile = (struct objfile *) xzalloc (sizeof (struct objfile)); objfile->psymbol_cache = psymbol_bcache_init (); @@ -290,10 +291,20 @@ allocate_objfile (bfd *abfd, const char *name, int flags) { gdb_assert (abfd == NULL); gdb_assert ((flags & OBJF_NOT_FILENAME) != 0); - name = "<>"; + expanded_name = xstrdup ("<>"); } - objfile->original_name = obstack_copy0 (&objfile->objfile_obstack, name, - strlen (name)); + else if ((flags & OBJF_NOT_FILENAME) != 0) + expanded_name = xstrdup (name); + else + expanded_name = gdb_abspath (name); + objfile->original_name = obstack_copy0 (&objfile->objfile_obstack, + expanded_name, + strlen (expanded_name)); + xfree (expanded_name); + + /* Update the per-objfile information that comes from the bfd, ensuring + that any data that is reference is saved in the per-objfile data + region. */ /* Update the per-objfile information that comes from the bfd, ensuring that any data that is reference is saved in the per-objfile data diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 08771d0..9f3d35f 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -212,8 +212,10 @@ struct objfile struct objfile *next; - /* The object file's name, tilde-expanded and absolute. This - pointer is never NULL. This does not have to be freed; it is + /* The object file's original name as specified by the user, + made absolute, and tilde-expanded. However, it is not canonicalized + (i.e., it has not been passed through gdb_realpath). + This pointer is never NULL. This does not have to be freed; it is guaranteed to have a lifetime at least as long as the objfile. */ char *original_name; diff --git a/gdb/source.c b/gdb/source.c index 9fa99b4..b115d79 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -853,28 +853,10 @@ done: /* If a file was opened, canonicalize its filename. */ if (fd < 0) *filename_opened = NULL; + else if ((opts & OPF_RETURN_REALPATH) != 0) + *filename_opened = gdb_realpath (filename); else - { - char *(*realpath_fptr) (const char *); - - realpath_fptr = ((opts & OPF_RETURN_REALPATH) != 0 - ? gdb_realpath : xstrdup); - - if (IS_ABSOLUTE_PATH (filename)) - *filename_opened = realpath_fptr (filename); - else - { - /* Beware the // my son, the Emacs barfs, the botch that catch... */ - - char *f = concat (current_directory, - IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]) - ? "" : SLASH_STRING, - filename, (char *)NULL); - - *filename_opened = realpath_fptr (f); - xfree (f); - } - } + *filename_opened = gdb_abspath (filename); } return fd; diff --git a/gdb/testsuite/gdb.dwarf2/dwp-symlink.c b/gdb/testsuite/gdb.dwarf2/dwp-symlink.c index 5be12fb..a93d5e7 100644 --- a/gdb/testsuite/gdb.dwarf2/dwp-symlink.c +++ b/gdb/testsuite/gdb.dwarf2/dwp-symlink.c @@ -15,6 +15,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +/* Cheezy hack to prevent set_initial_language from trying to look up main. + We do this so that gdb won't try to open the dwp file when the file is + first selected. This gives us a chance to do a chdir before attempting + to access the debug info. */ +asm (".globl main.main"); +asm ("main.main: .byte 0"); + int main (int argc, char **argv) { diff --git a/gdb/testsuite/gdb.dwarf2/dwp-symlink.exp b/gdb/testsuite/gdb.dwarf2/dwp-symlink.exp index ad0522b..a0daae4 100644 --- a/gdb/testsuite/gdb.dwarf2/dwp-symlink.exp +++ b/gdb/testsuite/gdb.dwarf2/dwp-symlink.exp @@ -75,3 +75,23 @@ gdb_test "ptype main" {type = int \(\)} "binary default, dwp at symlink" clean_restart "$thelink" gdb_test "ptype main" {type = int \(int, char \*\*\)} "binary symlink, dwp at symlink" + +# Verify we can still find the dwp if we change directories and we specified +# a relative path for the program. + +set saved_pwd [pwd] + +# This is clean_restart, but specifying a relative path to the binary. +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_test "cd [file dirname [standard_output_file ${thelink}]]" \ + "Working directory .*" +gdb_load "./${thelink}" + +gdb_test "cd .." "Working directory .*" + +gdb_test "ptype main" {type = int \(int, char \*\*\)} \ + "relative path, binary symlink, dwp at symlink" + +cd $saved_pwd diff --git a/gdb/utils.c b/gdb/utils.c index 26879ec..62d07d6 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3204,6 +3204,32 @@ gdb_realpath (const char *filename) return xstrdup (filename); } +/* Return PATH in absolute form, performing tilde-expansion if necessary. + PATH cannot be NULL or the empty string. + This does not resolve symlinks however, use gdb_realpath for that. + Space for the result is allocated with malloc. + If the path is already absolute, it is strdup'd. + If there is a problem computing the absolute path, the path is returned + unchanged (still strdup'd). */ + +char * +gdb_abspath (const char *path) +{ + gdb_assert (path != NULL && path[0] != '\0'); + + if (path[0] == '~') + return tilde_expand (path); + + if (IS_ABSOLUTE_PATH (path)) + return xstrdup (path); + + /* Beware the // my son, the Emacs barfs, the botch that catch... */ + return concat (current_directory, + IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]) + ? "" : SLASH_STRING, + path, (char *) NULL); +} + ULONGEST align_up (ULONGEST v, int n) { diff --git a/gdb/utils.h b/gdb/utils.h index 3492f09..29f79d5 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -128,6 +128,8 @@ extern struct cleanup *make_bpstat_clear_actions_cleanup (void); extern char *gdb_realpath (const char *); +extern char *gdb_abspath (const char *); + extern int gdb_filename_fnmatch (const char *pattern, const char *string, int flags);