Record objfile->original_name as an absolute path
authorJan Kratochvil <jan.kratochvil@redhat.com>
Mon, 2 Dec 2013 21:24:32 +0000 (22:24 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Mon, 2 Dec 2013 21:24:32 +0000 (22:24 +0100)
gdb/
2013-12-02  Doug Evans  <dje@google.com>
    Jan Kratochvil  <jan.kratochvil@redhat.com>

* 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-12-02  Doug Evans  <dje@google.com>

* 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.

gdb/ChangeLog
gdb/objfiles.c
gdb/objfiles.h
gdb/source.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.dwarf2/dwp-symlink.c
gdb/testsuite/gdb.dwarf2/dwp-symlink.exp
gdb/utils.c
gdb/utils.h

index 2e4066457c70958ed33517992bb62e28453315fd..7124ba55269ab67407eb763230c1cbc0bf0c7d1b 100644 (file)
@@ -1,3 +1,13 @@
+2013-12-02  Doug Evans  <dje@google.com>
+           Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       * 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.
+
 2013-12-02  Pedro Alves  <palves@redhat.com>
 
        * dcache.c (dcache_read_line): Use target_read_raw_memory.
index ba930fa31c0987dcf5f0c92d5b7d3b969a2b169f..1b957cc25e5186ff0b81915f07f3b70773458266 100644 (file)
@@ -272,6 +272,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 ();
@@ -286,10 +287,20 @@ allocate_objfile (bfd *abfd, const char *name, int flags)
     {
       gdb_assert (abfd == NULL);
       gdb_assert ((flags & OBJF_NOT_FILENAME) != 0);
-      name = "<<anonymous objfile>>";
+      expanded_name = xstrdup ("<<anonymous objfile>>");
     }
-  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
index 9bca812d5e07a2d19ad5f6218cf7a3d678928229..bc16dc73758f13d582913f62353573ee1229dfff 100644 (file)
@@ -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;
index 095958500296101777cc8e1e7c27fae41de099d5..6234bfc3954b26d0c1f9b3cf01667c4a2828c757 100644 (file)
@@ -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;
index 601517253b5a10456cfffdd3d74cb9b10a6148c5..8be246d9c58297ca62102deda8989dc83718795f 100644 (file)
@@ -1,3 +1,11 @@
+2013-12-02  Doug Evans  <dje@google.com>
+
+       * 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.
+
 2013-11-28  Andrew Burgess  <aburgess@broadcom.com>
 
        * gdb.trace/unavailable.exp (gdb_collect_args_test): Update
index 5be12fb6c5e2037946473f697578f8c5e3cc8627..a93d5e7c48644985076437687dedf39268d69798 100644 (file)
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* 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)
 {
index ad0522b483993531b3f5eab1655867fa97c8e30a..a0daae4b56d583e89152f4e33f6cee53508c543f 100644 (file)
@@ -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
index 10c73d3c76c583dd8d4705c276f8c5aa19b91ab5..975c43288639adf48b23d5c280be8b820da8d821 100644 (file)
@@ -3274,6 +3274,32 @@ gdb_realpath_keepfile (const char *filename)
   return result;
 }
 
+/* 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)
 {
index 208251142bb6c0e6b18ba2f0fc62679cffc61215..d0afe29d08df637edd83c970a1dd202f0f3e23c8 100644 (file)
@@ -130,6 +130,8 @@ extern char *gdb_realpath (const char *);
 
 extern char *gdb_realpath_keepfile (const char *);
 
+extern char *gdb_abspath (const char *);
+
 extern int gdb_filename_fnmatch (const char *pattern, const char *string,
                                 int flags);
 
This page took 0.042331 seconds and 4 git commands to generate.