From patchwork Fri Jun 8 19:49:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 27722 Received: (qmail 110283 invoked by alias); 8 Jun 2018 19:49:34 -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 110030 invoked by uid 89); 8 Jun 2018 19:49:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=obs, pulls X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Jun 2018 19:49:21 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD069401EF09 for ; Fri, 8 Jun 2018 19:49:19 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43A7B7D4FD for ; Fri, 8 Jun 2018 19:49:19 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed] Make gdbreplay use more common routines Date: Fri, 8 Jun 2018 20:49:18 +0100 Message-Id: <20180608194918.8543-1-palves@redhat.com> This makes gdbreplay share a bit more code with gdbserver, and paves the way to share more in future. Including common-defs.h pulls in defines and headers that gdb and gdbserver assume are always defined/available too, such as for example _(), ansidecl.h or a set of system headers. Including that revealed (static vs extern conflict) gdbreplay had a local copy of perror_with_name (which exited directly instead of throwing an error). So I removed gdbreplay's local copy, and then added enough .o files until gdbreplay linked successfully. Also, use xstrdup instead of strdup. gdb/gdbserver/ChangeLog: 2018-06-08 Pedro Alves * Makefile.in (GDBREPLAY_OBS): Add common/cleanups.o, common/common-exceptions.o, common/common-utils.o, common/errors.o, common/print-utils.o and utils.o. * gdbreplay.c: Include "common-defs.h" instead of the two 'config.h's here. Don't include stdio.h, errno.h, stdlib.h, string.h or alloca.h. (perror_with_name): Delete. (remote_open): Use xstrdup instead of strdup. (main): Rename to ... (captured_main): ... this. (main): New. --- gdb/gdbserver/ChangeLog | 14 +++++++++++ gdb/gdbserver/Makefile.in | 11 +++++++- gdb/gdbserver/gdbreplay.c | 64 +++++++++++++++++++++-------------------------- 3 files changed, 52 insertions(+), 37 deletions(-) diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 4e55c365be0..d040dc1af49 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,17 @@ +2018-06-08 Pedro Alves + + * Makefile.in (GDBREPLAY_OBS): Add common/cleanups.o, + common/common-exceptions.o, common/common-utils.o, + common/errors.o, common/print-utils.o and utils.o. + * gdbreplay.c: Include "common-defs.h" instead of the two + 'config.h's here. Don't include stdio.h, errno.h, stdlib.h, + string.h or alloca.h. + (perror_with_name): Delete. + (remote_open): Use xstrdup instead of strdup. + (main): Rename to ... + (captured_main): ... this. + (main): New. + 2018-06-08 Tom Tromey * linux-low.c (linux_low_read_btrace): Update. diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index 675faa43642..cf04b7d7b5a 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -284,7 +284,16 @@ OBS = \ $(LIBOBJS) \ $(XML_BUILTIN) -GDBREPLAY_OBS = gdbreplay.o version.o +GDBREPLAY_OBS = \ + common/cleanups.o \ + common/common-exceptions.o \ + common/common-utils.o \ + common/errors.o \ + common/print-utils.o \ + gdbreplay.o \ + utils.o \ + version.o + GDBSERVER_LIBS = @GDBSERVER_LIBS@ XM_CLIBS = @LIBS@ CDEPS = $(srcdir)/proc-service.list diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c index c1a639069a6..a4bc8924623 100644 --- a/gdb/gdbserver/gdbreplay.c +++ b/gdb/gdbserver/gdbreplay.c @@ -17,11 +17,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "config.h" -#include "build-gnulib-gdbserver/config.h" +#include "common-defs.h" #include "version.h" -#include #if HAVE_SYS_FILE_H #include #endif @@ -32,9 +30,6 @@ #if HAVE_FCNTL_H #include #endif -#include -#include -#include #include #ifdef HAVE_NETINET_IN_H #include @@ -49,8 +44,6 @@ #include #endif -#include - #if USE_WIN32API #include #endif @@ -115,32 +108,6 @@ strerror (DWORD error) #endif /* __MINGW32CE__ */ -/* Print the system error message for errno, and also mention STRING - as the file name for which the error was encountered. - Then return to command level. */ - -static void -perror_with_name (const char *string) -{ -#ifndef STDC_HEADERS - extern int errno; -#endif - const char *err; - char *combined; - - err = strerror (errno); - if (err == NULL) - err = "unknown error"; - - combined = (char *) alloca (strlen (err) + strlen (string) + 3); - strcpy (combined, string); - strcat (combined, ": "); - strcat (combined, err); - fprintf (stderr, "\n%s.\n", combined); - fflush (stderr); - exit (1); -} - static void sync_error (FILE *fp, const char *desc, int expect, int got) { @@ -422,8 +389,11 @@ gdbreplay_usage (FILE *stream) fprintf (stream, "Report bugs to \"%s\".\n", REPORT_BUGS_TO); } -int -main (int argc, char *argv[]) +/* Main function. This is called by the real "main" function, + wrapped in a TRY_CATCH that handles any uncaught exceptions. */ + +static void ATTRIBUTE_NORETURN +captured_main (int argc, char *argv[]) { FILE *fp; int ch; @@ -471,3 +441,25 @@ main (int argc, char *argv[]) remote_close (); exit (0); } + +int +main (int argc, char *argv[]) +{ + TRY + { + captured_main (argc, argv); + } + CATCH (exception, RETURN_MASK_ALL) + { + if (exception.reason == RETURN_ERROR) + { + fflush (stdout); + fprintf (stderr, "%s\n", exception.message); + } + + exit (1); + } + END_CATCH + + gdb_assert_not_reached ("captured_main should never return"); +}