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

RFA: share debug-link function with BFD


Right now, gdb and BFD both have equivalent copies of the
get_debug_link_info function.

This patch exports the function from BFD, so that gdb can just drop its
copy.

Ok for BFD?

I built and regtested gdb with this patch on x86-64 Fedora 16.

I think that there isn't any more we can share with BFD here, due to
gdb's use of remote BFDs; the rest of the separate-debug code in BFD is
very similar to gdb, but is tied to regular files.

Tom

	* opncls.c (bfd_get_debug_link_info): Rename from
	get_debug_link_info.  Export.  Update comment.
	(find_separate_debug_file): Update.
	* bfd-in2.h: Rebuild.

	* symfile.c (get_debug_link_info): Remove.
	(find_separate_debug_file_by_debuglink): Use
	bfd_get_debug_link_info.
---
 bfd/bfd-in2.h |    2 ++
 bfd/opncls.c  |   18 ++++++++++--------
 gdb/symfile.c |   32 +-------------------------------
 3 files changed, 13 insertions(+), 39 deletions(-)

diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 3561e19..1b3d5ec 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -1049,6 +1049,8 @@ void *bfd_zalloc (bfd *abfd, bfd_size_type wanted);
 unsigned long bfd_calc_gnu_debuglink_crc32
    (unsigned long crc, const unsigned char *buf, bfd_size_type len);
 
+char *bfd_get_debug_link_info (bfd *abfd, unsigned long *crc32_out);
+
 char *bfd_follow_gnu_debuglink (bfd *abfd, const char *dir);
 
 struct bfd_section *bfd_create_gnu_debuglink_section
diff --git a/bfd/opncls.c b/bfd/opncls.c
index c18d08a..0685708 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -1,6 +1,6 @@
 /* opncls.c -- open and close a BFD.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013
    Free Software Foundation, Inc.
 
    Written by Cygnus Support.
@@ -1140,20 +1140,22 @@ bfd_calc_gnu_debuglink_crc32 (unsigned long crc,
 
 
 /*
-INTERNAL_FUNCTION
-	get_debug_link_info
+FUNCTION
+	bfd_get_debug_link_info
 
 SYNOPSIS
-	char *get_debug_link_info (bfd *abfd, unsigned long *crc32_out);
+	char *bfd_get_debug_link_info (bfd *abfd, unsigned long *crc32_out);
 
 DESCRIPTION
 	fetch the filename and CRC32 value for any separate debuginfo
 	associated with @var{abfd}. Return NULL if no such info found,
-	otherwise return filename and update @var{crc32_out}.
+	otherwise return filename and update @var{crc32_out}.  The
+	returned filename is allocated with @code{malloc}; freeing it
+	is the responsibility of the caller.
 */
 
-static char *
-get_debug_link_info (bfd *abfd, unsigned long *crc32_out)
+char *
+bfd_get_debug_link_info (bfd *abfd, unsigned long *crc32_out)
 {
   asection *sect;
   unsigned long crc32;
@@ -1261,7 +1263,7 @@ find_separate_debug_file (bfd *abfd, const char *debug_file_directory)
       return NULL;
     }
 
-  base = get_debug_link_info (abfd, & crc32);
+  base = bfd_get_debug_link_info (abfd, & crc32);
   if (base == NULL)
     return NULL;
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 0515898..4d65889 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1348,36 +1348,6 @@ symbol_file_clear (int from_tty)
     printf_unfiltered (_("No symbol file now.\n"));
 }
 
-static char *
-get_debug_link_info (struct objfile *objfile, unsigned long *crc32_out)
-{
-  asection *sect;
-  bfd_size_type debuglink_size;
-  unsigned long crc32;
-  char *contents;
-  int crc_offset;
-
-  sect = bfd_get_section_by_name (objfile->obfd, ".gnu_debuglink");
-
-  if (sect == NULL)
-    return NULL;
-
-  debuglink_size = bfd_section_size (objfile->obfd, sect);
-
-  contents = xmalloc (debuglink_size);
-  bfd_get_section_contents (objfile->obfd, sect, contents,
-			    (file_ptr)0, (bfd_size_type)debuglink_size);
-
-  /* Crc value is stored after the filename, aligned up to 4 bytes.  */
-  crc_offset = strlen (contents) + 1;
-  crc_offset = (crc_offset + 3) & ~3;
-
-  crc32 = bfd_get_32 (objfile->obfd, (bfd_byte *) (contents + crc_offset));
-
-  *crc32_out = crc32;
-  return contents;
-}
-
 /* Return 32-bit CRC for ABFD.  If successful store it to *FILE_CRC_RETURN and
    return 1.  Otherwise print a warning and return 0.  ABFD seek position is
    not preserved.  */
@@ -1628,7 +1598,7 @@ find_separate_debug_file_by_debuglink (struct objfile *objfile)
   unsigned long crc32;
   struct cleanup *cleanups;
 
-  debuglink = get_debug_link_info (objfile, &crc32);
+  debuglink = bfd_get_debug_link_info (objfile->obfd, &crc32);
 
   if (debuglink == NULL)
     {
-- 
1.7.7.6


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