diff mbox

[1/9,v2] Move make_cleanup_close to common code

Message ID 1430395542-16017-2-git-send-email-gbenson@redhat.com
State New
Headers show

Commit Message

Gary Benson April 30, 2015, 12:05 p.m. UTC
This commit moves the function make_cleanup_close from gdb/utils.[ch]
to gdb/common/cleanup-utils.[ch] to make it usable from common code.
A new file was created over putting the function in common-utils.[ch]
to avoid having to build cleanups.c into the in-process agent.

gdb/ChangeLog:

	* common/cleanup-utils.h: New file.
	* common/cleanup-utils.c: Likewise.
	* Makefile.in (SFILES): Add common/cleanup-utils.c.
	(HFILES_NO_SRCDIR): Add common/cleanup-utils.h.
	(COMMON_OBS): Add cleanup-utils.o.
	(cleanup-utils.o): New rule.
	* common/common-utils.h (cleanup-utils.h): New include.
	* utils.h (make_cleanup_close): Moved to cleanup-utils.h.
	* utils.c (do_close_cleanup): Moved to cleanup-utils.c.
	(make_cleanup_close): Likewise.

gdb/gdbserver/ChangeLog:

	* Makefile.in (SFILES): Add common/cleanup-utils.c.
	(OBS): Add cleanup-utils.o.
	(cleanup-utils.o): New rule.
---
 gdb/ChangeLog              |   13 +++++++++++++
 gdb/Makefile.in            |   12 +++++++++---
 gdb/common/cleanup-utils.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 gdb/common/cleanup-utils.h |   31 +++++++++++++++++++++++++++++++
 gdb/common/common-utils.h  |    2 ++
 gdb/gdbserver/ChangeLog    |    6 ++++++
 gdb/gdbserver/Makefile.in  |    6 +++++-
 gdb/utils.c                |   17 -----------------
 gdb/utils.h                |    2 +-
 9 files changed, 109 insertions(+), 22 deletions(-)
 create mode 100644 gdb/common/cleanup-utils.c
 create mode 100644 gdb/common/cleanup-utils.h

Comments

Pedro Alves May 21, 2015, 2:56 p.m. UTC | #1
On 04/30/2015 01:05 PM, Gary Benson wrote:
> This commit moves the function make_cleanup_close from gdb/utils.[ch]
> to gdb/common/cleanup-utils.[ch] to make it usable from common code.
> A new file was created over putting the function in common-utils.[ch]
> to avoid having to build cleanups.c into the in-process agent.
> 

Hmm, how about avoiding creating another kitchensync, and
putting this in common/filestuff.[ch]?

Thanks,
Pedro Alves
Gary Benson May 27, 2015, 9:52 a.m. UTC | #2
Pedro Alves wrote:
> On 04/30/2015 01:05 PM, Gary Benson wrote:
> > This commit moves the function make_cleanup_close from gdb/utils.[ch]
> > to gdb/common/cleanup-utils.[ch] to make it usable from common code.
> > A new file was created over putting the function in common-utils.[ch]
> > to avoid having to build cleanups.c into the in-process agent.
> 
> Hmm, how about avoiding creating another kitchensync, and putting
> this in common/filestuff.[ch]?

I can do that.

Cheers,
Gary
diff mbox

Patch

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 95104ef..47b216a 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -888,7 +888,7 @@  SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	common/format.c common/filestuff.c btrace.c record-btrace.c ctf.c \
 	target/waitstatus.c common/print-utils.c common/rsp-low.c \
 	common/errors.c common/common-debug.c common/common-exceptions.c \
-	common/btrace-common.c common/fileio.c \
+	common/btrace-common.c common/fileio.c common/cleanup-utils.c \
 	$(SUBDIR_GCC_COMPILE_SRCS)
 
 LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
@@ -979,7 +979,8 @@  i386-linux-nat.h common/common-defs.h common/errors.h common/common-types.h \
 common/common-debug.h common/cleanups.h common/gdb_setjmp.h \
 common/common-exceptions.h target/target.h common/symbol.h \
 common/common-regcache.h fbsd-tdep.h nat/linux-personality.h \
-common/fileio.h nat/x86-linux.h nat/x86-linux-dregs.h
+common/fileio.h nat/x86-linux.h nat/x86-linux-dregs.h \
+common/cleanup-utils.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
@@ -1079,7 +1080,7 @@  COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
 	format.o registry.o btrace.o record-btrace.o waitstatus.o \
 	print-utils.o rsp-low.o errors.o common-debug.o debug.o \
-	common-exceptions.o btrace-common.o fileio.o \
+	common-exceptions.o btrace-common.o fileio.o cleanup-utils.o \
 	$(SUBDIR_GCC_COMPILE_OBS)
 
 TSOBS = inflow.o
@@ -2260,6 +2261,11 @@  btrace-common.o: ${srcdir}/common/btrace-common.c
 fileio.o: ${srcdir}/common/fileio.c
 	$(COMPILE) $(srcdir)/common/fileio.c
 	$(POSTCOMPILE)
+
+cleanup-utils.o: ${srcdir}/common/cleanup-utils.c
+	$(COMPILE) $(srcdir)/common/cleanup-utils.c
+	$(POSTCOMPILE)
+
 #
 # gdb/target/ dependencies
 #
diff --git a/gdb/common/cleanup-utils.c b/gdb/common/cleanup-utils.c
new file mode 100644
index 0000000..829d067
--- /dev/null
+++ b/gdb/common/cleanup-utils.c
@@ -0,0 +1,42 @@ 
+/* Cleanup utilities for GDB, the GNU debugger.
+
+   Copyright (C) 1986-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+#include "cleanup-utils.h"
+
+/* Helper function which does the work for make_cleanup_close.  */
+
+static void
+do_close_cleanup (void *arg)
+{
+  int *fd = arg;
+
+  close (*fd);
+}
+
+/* See cleanup-utils.h.  */
+
+struct cleanup *
+make_cleanup_close (int fd)
+{
+  int *saved_fd = xmalloc (sizeof (fd));
+
+  *saved_fd = fd;
+  return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree);
+}
diff --git a/gdb/common/cleanup-utils.h b/gdb/common/cleanup-utils.h
new file mode 100644
index 0000000..c5a0d50
--- /dev/null
+++ b/gdb/common/cleanup-utils.h
@@ -0,0 +1,31 @@ 
+/* Cleanup utilities for GDB, the GNU debugger.
+
+   Copyright (C) 1986-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Cleanup utilities.  These are not declared in cleanups.h
+   (nor defined in cleanups.c) because, while they use the
+   cleanup API, they are not part of the cleanup API.  */
+
+#ifndef CLEANUP_UTILS_H
+#define CLEANUP_UTILS_H
+
+/* Return a new cleanup that closes FD.  */
+
+extern struct cleanup *make_cleanup_close (int fd);
+
+#endif /* CLEANUP_UTILS_H */
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index cd2665a..dc3ceea 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -20,6 +20,8 @@ 
 #ifndef COMMON_UTILS_H
 #define COMMON_UTILS_H
 
+#include "cleanup-utils.h"
+
 /* If possible, define FUNCTION_NAME, a macro containing the name of
    the function being defined.  Since this macro may not always be
    defined, all uses must be protected by appropriate macro definition
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index a981ee8..8ba88d4 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -180,7 +180,7 @@  SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
 	$(srcdir)/common/common-debug.c $(srcdir)/common/cleanups.c \
 	$(srcdir)/common/common-exceptions.c $(srcdir)/symbol.c \
 	$(srcdir)/common/btrace-common.c \
-	$(srcdir)/common/fileio.c
+	$(srcdir)/common/fileio.c $(srcdir)/common/cleanup-utils.c
 
 DEPFILES = @GDBSERVER_DEPFILES@
 
@@ -195,6 +195,7 @@  OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o \
       common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
       tdesc.o print-utils.o rsp-low.o errors.o common-debug.o cleanups.o \
       common-exceptions.o symbol.o btrace-common.o fileio.o \
+      cleanup-utils.o \
       $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
 GDBREPLAY_OBS = gdbreplay.o version.o
 GDBSERVER_LIBS = @GDBSERVER_LIBS@
@@ -615,6 +616,9 @@  x86-linux.o: ../nat/x86-linux.c
 x86-linux-dregs.o: ../nat/x86-linux-dregs.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+cleanup-utils.o: ../common/cleanup-utils.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 
 aarch64.c : $(srcdir)/../regformats/aarch64.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/aarch64.dat aarch64.c
diff --git a/gdb/utils.c b/gdb/utils.c
index aaaf9c5..1c1ced4 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -191,23 +191,6 @@  make_cleanup_bfd_unref (bfd *abfd)
   return make_cleanup (do_bfd_close_cleanup, abfd);
 }
 
-static void
-do_close_cleanup (void *arg)
-{
-  int *fd = arg;
-
-  close (*fd);
-}
-
-struct cleanup *
-make_cleanup_close (int fd)
-{
-  int *saved_fd = xmalloc (sizeof (fd));
-
-  *saved_fd = fd;
-  return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree);
-}
-
 /* Helper function which does the work for make_cleanup_fclose.  */
 
 static void
diff --git a/gdb/utils.h b/gdb/utils.h
index cae1ac0..423feb5 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -80,7 +80,7 @@  struct section_addr_info;
 extern struct cleanup *(make_cleanup_free_section_addr_info 
                         (struct section_addr_info *));
 
-extern struct cleanup *make_cleanup_close (int fd);
+/* For make_cleanup_close see common/cleanup-utils.h.  */
 
 extern struct cleanup *make_cleanup_fclose (FILE *file);