[RFA] bfd_cache_close_all

Jerome Guitton guitton@act-europe.fr
Wed Jun 16 16:17:00 GMT 2004


Hello,

In GDB, it would be useful on several platforms (e.g. win32) to
force BFD to release the file handles. Details are here:

http://sources.redhat.com/ml/gdb-patches/2004-05/msg00678.html

The idea would be to have a function bfd_cache_close_all that would
clear the file descriptor cache.

OK to apply?

--
Jerome
-------------- next part --------------
2004-06-16  Jerome Guitton  <guitton@gnat.com>

	* bfd-in.h (bfd_cache_close_all): New function declaration.
        * bfd-in2.h: Regenerate.
        * cache.c (bfd_cache_close_all): New function definition.

Index: bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.81
diff -u -r1.81 bfd-in.h
--- bfd-in.h	15 Jun 2004 01:24:22 -0000	1.81
+++ bfd-in.h	16 Jun 2004 13:12:59 -0000
@@ -511,6 +511,8 @@
   (bfd *abfd);
 /* NB: This declaration should match the autogenerated one in libbfd.h.  */
 
+extern bfd_boolean bfd_cache_close_all (void);
+
 extern bfd_boolean bfd_record_phdr
   (bfd *, unsigned long, bfd_boolean, flagword, bfd_boolean, bfd_vma,
    bfd_boolean, bfd_boolean, unsigned int, struct bfd_section **);
Index: bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.280
diff -u -r1.280 bfd-in2.h
--- bfd-in2.h	15 Jun 2004 01:24:22 -0000	1.280
+++ bfd-in2.h	16 Jun 2004 13:12:59 -0000
@@ -518,6 +518,8 @@
   (bfd *abfd);
 /* NB: This declaration should match the autogenerated one in libbfd.h.  */
 
+extern bfd_boolean bfd_cache_close_all (void);
+
 extern bfd_boolean bfd_record_phdr
   (bfd *, unsigned long, bfd_boolean, flagword, bfd_boolean, bfd_vma,
    bfd_boolean, bfd_boolean, unsigned int, struct bfd_section **);
Index: cache.c
===================================================================
RCS file: /cvs/src/src/bfd/cache.c,v
retrieving revision 1.14
diff -u -r1.14 cache.c
--- cache.c	5 May 2004 15:39:11 -0000	1.14
+++ cache.c	16 Jun 2004 13:12:59 -0000
@@ -344,6 +344,42 @@
 }
 
 /*
+FUNCTION
+	bfd_cache_close_all
+
+SYNOPSIS
+	bfd_boolean bfd_cache_close_all (void);
+
+DESCRIPTION
+	Remove all BFDs from the cache. If the attached file is open,
+	then close it too.
+
+RETURNS
+	<<FALSE>> is returned if closing one of the file fails, <<TRUE>> is
+	returned if all is well.
+*/
+
+bfd_boolean
+bfd_cache_close_all ()
+{
+  bfd_boolean ret = TRUE;
+  register bfd *kill;
+
+  if (!bfd_last_cache)
+    return TRUE;
+  
+  for (kill = bfd_last_cache->lru_prev;
+       open_files;
+       kill = kill->lru_prev)
+    {
+      ret = ret && bfd_cache_close (kill);
+    }
+
+  return ret;
+}
+
+
+/*
 INTERNAL_FUNCTION
 	bfd_open_file
 


More information about the Binutils mailing list