Enhance gdb.lookup_objfile so that it works with a symlinked binary.
authorDoug Evans <dje@google.com>
Wed, 14 Jan 2015 01:00:31 +0000 (17:00 -0800)
committerDoug Evans <dje@google.com>
Wed, 14 Jan 2015 01:02:53 +0000 (17:02 -0800)
gdb/Changelog:

* objfiles.c (objfile_filename): New function.
* objfiles.h (objfile_filename): Declare it.
(objfile_name): Add function comment.
* python/py-objfile.c (objfpy_lookup_objfile_by_name): Try both the
bfd file name (which may be realpath'd), and the original name.

gdb/testsuite/ChangeLog:

* gdb.python/py-objfile.exp: Test gdb.lookup_objfile on symlinked
binary.

gdb/ChangeLog
gdb/objfiles.c
gdb/objfiles.h
gdb/python/py-objfile.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-objfile.exp

index 8a725ea82ed0170c94cc0a9cc9cf6255b9e891e6..3431c2ca0ee8c00d7e53b44fa31a1446301a74b8 100644 (file)
@@ -1,3 +1,11 @@
+2015-01-13  Doug Evans  <dje@google.com>
+
+       * objfiles.c (objfile_filename): New function.
+       * objfiles.h (objfile_filename): Declare it.
+       (objfile_name): Add function comment.
+       * python/py-objfile.c (objfpy_lookup_objfile_by_name): Try both the
+       bfd file name (which may be realpath'd), and the original name.
+
 2015-01-13  Joel Brobecker  <brobecker@adacore.com>
 
        * NEWS: Create a new section for the next release branch.
index c397f6872c1a85fa962b682f8a633d1182f75f10..ff20bc8fcffdef56c36451c77f6cfe3727e2e395 100644 (file)
@@ -1492,7 +1492,7 @@ default_iterate_over_objfiles_in_search_order
     }
 }
 
-/* Return canonical name for OBJFILE.  */
+/* See objfiles.h.  */
 
 const char *
 objfile_name (const struct objfile *objfile)
@@ -1505,6 +1505,17 @@ objfile_name (const struct objfile *objfile)
 
 /* See objfiles.h.  */
 
+const char *
+objfile_filename (const struct objfile *objfile)
+{
+  if (objfile->obfd != NULL)
+    return bfd_get_filename (objfile->obfd);
+
+  return NULL;
+}
+
+/* See objfiles.h.  */
+
 const char *
 objfile_debug_name (const struct objfile *objfile)
 {
index 8782797089142d51095e4fe89ae7353ad2bb7884..a0dc69b9207ba481993ec9dc3c861f15b5f6dd38 100644 (file)
@@ -699,8 +699,17 @@ extern void default_iterate_over_objfiles_in_search_order
 
 void set_objfile_per_bfd (struct objfile *obj);
 
+/* Return canonical name for OBJFILE.
+   This is the real file name if the file has been opened.
+   Otherwise it is the original name supplied by the user.  */
+
 const char *objfile_name (const struct objfile *objfile);
 
+/* Return the (real) file name of OBJFILE if the file has been opened,
+   otherwise return NULL.  */
+
+const char *objfile_filename (const struct objfile *objfile);
+
 /* Return the name to print for OBJFILE in debugging messages.  */
 
 extern const char *objfile_debug_name (const struct objfile *objfile);
index bdc483aec51266bf3260c28a7eafd5ee8fbfbe5b..378db58fea7021467feaba785eae7fb0537a06c6 100644 (file)
@@ -438,12 +438,18 @@ objfpy_lookup_objfile_by_name (const char *name)
 
   ALL_OBJFILES (objfile)
     {
+      const char *filename;
+
       if ((objfile->flags & OBJF_NOT_FILENAME) != 0)
        continue;
       /* Don't return separate debug files.  */
       if (objfile->separate_debug_objfile_backlink != NULL)
        continue;
-      if (compare_filenames_for_search (objfile_name (objfile), name))
+
+      filename = objfile_filename (objfile);
+      if (filename != NULL && compare_filenames_for_search (filename, name))
+       return objfile;
+      if (compare_filenames_for_search (objfile->original_name, name))
        return objfile;
     }
 
index 4a903bccb1b68d111713e305468e63db798772b5..fa7ffa9343902d646dc6a7dfb7d5ae9e554253c2 100644 (file)
@@ -1,3 +1,8 @@
+2015-01-13  Doug Evans  <dje@google.com>
+
+       * gdb.python/py-objfile.exp: Test gdb.lookup_objfile on symlinked
+       binary.
+
 2015-01-13  Joel Brobecker  <brobecker@adacore.com>
 
        * Makefile.in (clean mostlyclean): Do not delete *.py.
index 50339a6c9fe13928f1f4d3451d4d3e56b75240bf..cddbd3de89e52af8070894c6073310b09913edc6 100644 (file)
@@ -115,3 +115,14 @@ if { [get_python_valueof "sep_objfile.build_id" "None"] != "None" } {
     gdb_test "python print (gdb.lookup_objfile (sep_objfile.build_id, by_build_id=True))" \
        "Objfile not found\\.\r\n${python_error_text}"
 }
+
+# An objfile that was a symlink to a differently named file is still
+# findable with its original name.
+set symlink_binary [standard_output_file "symlink-binary"]
+remote_exec host "rm -f ${symlink_binary}"
+remote_exec host "ln -sf ${testfile} ${symlink_binary}"
+if [remote_file host exists "${symlink_binary}"] {
+    clean_restart "${symlink_binary}"
+    gdb_test "python print (gdb.lookup_objfile (\"${symlink_binary}\").filename)" \
+       "${testfile}" "gdb.lookup_objfile of symlinked binary"
+}
This page took 0.032441 seconds and 4 git commands to generate.