From patchwork Thu Jul 3 15:18:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 1887 Received: (qmail 27016 invoked by alias); 3 Jul 2014 15:19:07 -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 26899 invoked by uid 89); 3 Jul 2014 15:19:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 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, 03 Jul 2014 15:19:02 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s63FJ1sI011959 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 3 Jul 2014 11:19:01 -0400 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s63FIu97024009 for ; Thu, 3 Jul 2014 11:19:00 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 3/9] Move catch_command_errors and catch_command_errors_const to main.c Date: Thu, 3 Jul 2014 16:18:50 +0100 Message-Id: <1404400736-17307-4-git-send-email-palves@redhat.com> In-Reply-To: <1404400736-17307-1-git-send-email-palves@redhat.com> References: <1404400736-17307-1-git-send-email-palves@redhat.com> We'll need to add error handling code to commands run before the event loop starts (commands in .gdbinit, -ex commands, etc.). Turns out those are run through catch_command_errors, and, catch_command_errors is used nowhere else. Move it (and the _const variant) to main.c, so that we can further specialize it freely. gdb/ 2014-07-03 Pedro Alves * exceptions.c (catch_command_errors, catch_command_errors_const): Moved to main.c. * exceptions.h (catch_command_errors_ftype) (catch_command_errors_const_ftype): Moved to main.c. (catch_command_errors, catch_command_errors_const): Delete declarations. * main.c (catch_command_errors_ftype) (catch_command_errors_const_ftype): Moved here from exceptions.h. (catch_command_errors, catch_command_errors_const)): Moved here from exceptions.c and make static. --- gdb/exceptions.c | 32 -------------------------------- gdb/exceptions.h | 13 ------------- gdb/main.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/gdb/exceptions.c b/gdb/exceptions.c index 8ee428d..def1f41 100644 --- a/gdb/exceptions.c +++ b/gdb/exceptions.c @@ -521,35 +521,3 @@ catch_errors (catch_errors_ftype *func, void *func_args, char *errstring, return 0; return val; } - -int -catch_command_errors (catch_command_errors_ftype *command, - char *arg, int from_tty, return_mask mask) -{ - volatile struct gdb_exception e; - - TRY_CATCH (e, mask) - { - command (arg, from_tty); - } - exception_print (gdb_stderr, e); - if (e.reason < 0) - return 0; - return 1; -} - -int -catch_command_errors_const (catch_command_errors_const_ftype *command, - const char *arg, int from_tty, return_mask mask) -{ - volatile struct gdb_exception e; - - TRY_CATCH (e, mask) - { - command (arg, from_tty); - } - exception_print (gdb_stderr, e); - if (e.reason < 0) - return 0; - return 1; -} diff --git a/gdb/exceptions.h b/gdb/exceptions.h index b8dadc7..e5e1a49 100644 --- a/gdb/exceptions.h +++ b/gdb/exceptions.h @@ -255,17 +255,4 @@ extern int catch_exceptions_with_msg (struct ui_out *uiout, typedef int (catch_errors_ftype) (void *); extern int catch_errors (catch_errors_ftype *, void *, char *, return_mask); -/* Template to catch_errors() that wraps calls to command - functions. */ - -typedef void (catch_command_errors_ftype) (char *, int); -extern int catch_command_errors (catch_command_errors_ftype *func, - char *arg, int from_tty, return_mask); - -/* Like catch_command_errors, but works with const command and args. */ - -typedef void (catch_command_errors_const_ftype) (const char *, int); -extern int catch_command_errors_const (catch_command_errors_const_ftype *func, - const char *arg, int from_tty, return_mask); - #endif diff --git a/gdb/main.c b/gdb/main.c index 0d4d512..1d77bd3 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -337,6 +337,50 @@ captured_command_loop (void *data) return 1; } +/* Type of the command callback passed to catch_command_errors. */ + +typedef void (catch_command_errors_ftype) (char *, int); + +/* Wrap calls to commands run before the event loop is started. */ + +static int +catch_command_errors (catch_command_errors_ftype *command, + char *arg, int from_tty, return_mask mask) +{ + volatile struct gdb_exception e; + + TRY_CATCH (e, mask) + { + command (arg, from_tty); + } + exception_print (gdb_stderr, e); + if (e.reason < 0) + return 0; + return 1; +} + +/* Type of the command callback passed to catch_command_errors_const. */ + +typedef void (catch_command_errors_const_ftype) (const char *, int); + +/* Like catch_command_errors, but works with const command and args. */ + +static int +catch_command_errors_const (catch_command_errors_const_ftype *command, + const char *arg, int from_tty, return_mask mask) +{ + volatile struct gdb_exception e; + + TRY_CATCH (e, mask) + { + command (arg, from_tty); + } + exception_print (gdb_stderr, e); + if (e.reason < 0) + return 0; + return 1; +} + /* Arguments of --command option and its counterpart. */ typedef struct cmdarg { /* Type of this option. */