This is the mail archive of the gdb-cvs@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]

[binutils-gdb] Enhance gdb.lookup_objfile so that it works with a symlinked binary.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e02c96a79949824bbe1da22ddfc6b50d362fb552

commit e02c96a79949824bbe1da22ddfc6b50d362fb552
Author: Doug Evans <dje@google.com>
Date:   Tue Jan 13 17:00:31 2015 -0800

    Enhance gdb.lookup_objfile so that it works with a symlinked binary.
    
    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.

Diff:
---
 gdb/ChangeLog                           |  8 ++++++++
 gdb/objfiles.c                          | 13 ++++++++++++-
 gdb/objfiles.h                          |  9 +++++++++
 gdb/python/py-objfile.c                 |  8 +++++++-
 gdb/testsuite/ChangeLog                 |  5 +++++
 gdb/testsuite/gdb.python/py-objfile.exp | 11 +++++++++++
 6 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8a725ea..3431c2c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index c397f68..ff20bc8 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -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)
@@ -1506,6 +1506,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)
 {
   return lbasename (objfile->original_name);
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 8782797..a0dc69b 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -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);
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index bdc483a..378db58 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -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;
     }
 
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4a903bc..fa7ffa9 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -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.
diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp
index 50339a6..cddbd3d 100644
--- a/gdb/testsuite/gdb.python/py-objfile.exp
+++ b/gdb/testsuite/gdb.python/py-objfile.exp
@@ -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"
+}


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