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] Make "cbfd" a gdb_bfd_ref_ptr


This changes program_space::cbfd to be a gdb_bfd_ref_ptr.  This makes
it somewhat less error-prone to use, because now it manages the
reference counting automatically.

Tested by the buildbot.

2018-05-11  Tom Tromey  <tom@tromey.com>

	* gdbcore.h (core_bfd): Redefine.
	* corelow.c (core_target::close): Update.
	(core_target_open): Update.
	* progspace.h (struct program_space) <cbfd>: Now a
	gdb_bfd_ref_ptr.
---
 gdb/ChangeLog   | 8 ++++++++
 gdb/corelow.c   | 5 ++---
 gdb/gdbcore.h   | 2 +-
 gdb/progspace.h | 3 ++-
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a3a133c036..08e26fc21d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2018-05-11  Tom Tromey  <tom@tromey.com>
+
+	* gdbcore.h (core_bfd): Redefine.
+	* corelow.c (core_target::close): Update.
+	(core_target_open): Update.
+	* progspace.h (struct program_space) <cbfd>: Now a
+	gdb_bfd_ref_ptr.
+
 2018-05-11  Max Filippov  <jcmvbkbc@gmail.com>
 
 	* configure.tgt (xtensa*-*-linux*): Drop gdb_target definition.
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 439fe1338a..c6175279da 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -270,8 +270,7 @@ core_target::close ()
          comments in clear_solib in solib.c.  */
       clear_solib ();
 
-      gdb_bfd_unref (core_bfd);
-      core_bfd = NULL;
+      current_program_space->cbfd.reset (nullptr);
     }
 
   /* Core targets are heap-allocated (see core_target_open), so here
@@ -406,7 +405,7 @@ core_target_open (const char *arg, int from_tty)
 	     filename.get (), bfd_errmsg (bfd_get_error ()));
     }
 
-  core_bfd = temp_bfd.release ();
+  current_program_space->cbfd = std::move (temp_bfd);
 
   core_target *target = new core_target ();
 
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index 04a4b4767a..18ba0d7226 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -133,7 +133,7 @@ extern void specify_exec_file_hook (void (*hook) (const char *filename));
 
 /* Binary File Diddler for the core file.  */
 
-#define core_bfd (current_program_space->cbfd)
+#define core_bfd (current_program_space->cbfd.get ())
 
 /* Whether to open exec and core files read-only or read-write.  */
 
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 835fcfdd5d..456911b29b 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -23,6 +23,7 @@
 
 #include "target.h"
 #include "vec.h"
+#include "gdb_bfd.h"
 #include "gdb_vecs.h"
 #include "registry.h"
 
@@ -158,7 +159,7 @@ struct program_space
   char *pspace_exec_filename = NULL;
 
   /* Binary file diddling handle for the core file.  */
-  bfd *cbfd = NULL;
+  gdb_bfd_ref_ptr cbfd;
 
   /* The address space attached to this program space.  More than one
      program space may be bound to the same address space.  In the
-- 
2.14.3


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