From patchwork Thu Apr 30 12:05:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 6506 Received: (qmail 59954 invoked by alias); 30 Apr 2015 12:41:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 59929 invoked by uid 89); 30 Apr 2015 12:41:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 30 Apr 2015 12:41:44 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3UC5nWk010353 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Apr 2015 08:05:50 -0400 Received: from blade.nx (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3UC5lqk032678; Thu, 30 Apr 2015 08:05:48 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 654E5263E57; Thu, 30 Apr 2015 13:05:47 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Cc: Eli Zaretskii , Pedro Alves , Doug Evans , =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= Subject: [PATCH 1/9 v2] Move make_cleanup_close to common code Date: Thu, 30 Apr 2015 13:05:34 +0100 Message-Id: <1430395542-16017-2-git-send-email-gbenson@redhat.com> In-Reply-To: <1429186791-6867-1-git-send-email-gbenson@redhat.com> References: <1429186791-6867-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes 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 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 . */ + +#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 . */ + +/* 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);