From 19f6550ebbc922f88026c5c7ebeb04019d47cac2 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 29 Oct 2020 15:04:33 -0600 Subject: [PATCH] Change program_space::ebfd to a gdb_bfd_ref_ptr This changes program_space::ebfd to a gdb_bfd_ref_ptr, removing some manual management. gdb/ChangeLog 2020-10-29 Tom Tromey * exec.c (exec_file_attach): Update. * progspace.c (program_space::exec_close): Update. * progspace.h (struct program_space) : Now a gdb_bfd_ref_ptr. : Change argument type. : Update. --- gdb/ChangeLog | 9 +++++++++ gdb/exec.c | 2 +- gdb/progspace.c | 6 ++---- gdb/progspace.h | 8 ++++---- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 028329e7988..06f42436d25 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2020-10-29 Tom Tromey + + * exec.c (exec_file_attach): Update. + * progspace.c (program_space::exec_close): Update. + * progspace.h (struct program_space) : Now a + gdb_bfd_ref_ptr. + : Change argument type. + : Update. + 2020-10-29 Tom Tromey * windows-tdep.c (windows_solib_create_inferior_hook): Update. diff --git a/gdb/exec.c b/gdb/exec.c index 2c93391791f..684f4dfc041 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -453,7 +453,7 @@ exec_file_attach (const char *filename, int from_tty) FOPEN_RUB, scratch_chan); else temp = gdb_bfd_open (canonical_pathname, gnutarget, scratch_chan); - current_program_space->set_exec_bfd (temp.release ()); + current_program_space->set_exec_bfd (std::move (temp)); if (!current_program_space->exec_bfd ()) { diff --git a/gdb/progspace.c b/gdb/progspace.c index 57edc298da7..52482ca8f64 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -228,13 +228,11 @@ program_space::solibs () const void program_space::exec_close () { - if (ebfd) + if (ebfd != nullptr) { - gdb_bfd_unref (ebfd); - /* Removing target sections may close the exec_ops target. Clear ebfd before doing so to prevent recursion. */ - ebfd = NULL; + ebfd.reset (nullptr); ebfd_mtime = 0; remove_target_sections (&ebfd); diff --git a/gdb/progspace.h b/gdb/progspace.h index 5e49083884a..8150d8a2a62 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -279,13 +279,13 @@ struct program_space /* Return the exec BFD for this program space. */ bfd *exec_bfd () const { - return ebfd; + return ebfd.get (); } /* Set the exec BFD for this program space to ABFD. */ - void set_exec_bfd (bfd *abfd) + void set_exec_bfd (gdb_bfd_ref_ptr &&abfd) { - ebfd = abfd; + ebfd = std::move (abfd); } /* Unique ID number. */ @@ -295,7 +295,7 @@ struct program_space managed by the exec target. */ /* The BFD handle for the main executable. */ - bfd *ebfd = NULL; + gdb_bfd_ref_ptr ebfd; /* The last-modified time, from when the exec was brought in. */ long ebfd_mtime = 0; /* Similar to bfd_get_filename (exec_bfd) but in original form given -- 2.30.2