[RFA,04/23] Use gdb_file_up in fbsd-nat.c

Message ID 20170503224626.2818-5-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey May 3, 2017, 10:46 p.m. UTC
  This updates fbsd-nat.c to use gdb_file_up.  This removes a use of a
cleanup, and helps remove make_cleanup_fclose in a later patch.

I have no way to test this patch.

2017-05-02  Tom Tromey  <tom@tromey.com>

	* fbsd-nat.c (fbsd_find_memory_regions): Update.
---
 gdb/ChangeLog  | 4 ++++
 gdb/fbsd-nat.c | 6 ++----
 2 files changed, 6 insertions(+), 4 deletions(-)
  

Comments

John Baldwin May 3, 2017, 11:50 p.m. UTC | #1
On Wednesday, May 03, 2017 04:46:07 PM Tom Tromey wrote:
> This updates fbsd-nat.c to use gdb_file_up.  This removes a use of a
> cleanup, and helps remove make_cleanup_fclose in a later patch.
> 
> I have no way to test this patch.

This looks fine to me.  On the other hand, it's also not used on most
modern versions of FreeBSD (so I don't have a good way to test it either).
The new interface using sysctl has been available since FreeBSD 7.1
(released in January of 2009).
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 76c53be..799b727 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@ 
 2017-05-02  Tom Tromey  <tom@tromey.com>
 
+	* fbsd-nat.c (fbsd_find_memory_regions): Update.
+
+2017-05-02  Tom Tromey  <tom@tromey.com>
+
 	* cli/cli-cmds.c (find_and_open_script): Return gdb_file_p.
 	Remove "streamp" argument.  Change "full_path" to a
 	unique_xmalloc_ptr.
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index ef5ad1e..3a84abc 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -160,7 +160,6 @@  fbsd_find_memory_regions (struct target_ops *self,
 {
   pid_t pid = ptid_get_pid (inferior_ptid);
   char *mapfilename;
-  FILE *mapfile;
   unsigned long start, end, size;
   char protection[4];
   int read, write, exec;
@@ -168,17 +167,16 @@  fbsd_find_memory_regions (struct target_ops *self,
 
   mapfilename = xstrprintf ("/proc/%ld/map", (long) pid);
   cleanup = make_cleanup (xfree, mapfilename);
-  mapfile = fopen (mapfilename, "r");
+  gdb_file_up mapfile = fopen (mapfilename, "r");
   if (mapfile == NULL)
     error (_("Couldn't open %s."), mapfilename);
-  make_cleanup_fclose (mapfile);
 
   if (info_verbose)
     fprintf_filtered (gdb_stdout, 
 		      "Reading memory regions from %s\n", mapfilename);
 
   /* Now iterate until end-of-file.  */
-  while (fbsd_read_mapping (mapfile, &start, &end, &protection[0]))
+  while (fbsd_read_mapping (mapfile.get (), &start, &end, &protection[0]))
     {
       size = end - start;