From patchwork Fri Mar 6 19:58:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 5501 Received: (qmail 52693 invoked by alias); 6 Mar 2015 19:58:11 -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 52680 invoked by uid 89); 6 Mar 2015 19:58:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_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; Fri, 06 Mar 2015 19:58:10 +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 t26Jw8pc022506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 6 Mar 2015 14:58:08 -0500 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t26Jw60l024787 for ; Fri, 6 Mar 2015 14:58:08 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 1/6] Move throw_perror_with_name to common/ Date: Fri, 6 Mar 2015 19:58:01 +0000 Message-Id: <1425671886-7798-2-git-send-email-palves@redhat.com> In-Reply-To: <1425671886-7798-1-git-send-email-palves@redhat.com> References: <1425671886-7798-1-git-send-email-palves@redhat.com> I have a use for throw_perror_with_name in nat/, but currently, only perror_with_name is available to common gdb+gdbserver code. This patch makes throw_perror_with_name the function that client need to implement (instead of perror_with_name), and adds a common perror_with_name as a wrapper over throw_perror_with_name, just like GDB's is currently. gdb/ChangeLog: 2015-03-06 Pedro Alves * utils.c (perror_with_name): Move ... * common/errors.c (perror_with_name): ... here. * common/errors.h: Include common-exceptions.h. (throw_perror_with_name): Declare. (perror_with_name): Update comment. gdb/gdbserver/ChangeLog: 2015-03-06 Pedro Alves * utils.c (perror_with_name): Rename to ... (throw_perror_with_name): ... this. Use throw_error in gdbserver. --- gdb/common/errors.c | 8 ++++++++ gdb/common/errors.h | 13 +++++++++++-- gdb/gdbserver/utils.c | 6 +++++- gdb/utils.c | 8 -------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/gdb/common/errors.c b/gdb/common/errors.c index 00b325e..5fd4a80 100644 --- a/gdb/common/errors.c +++ b/gdb/common/errors.c @@ -67,3 +67,11 @@ internal_warning (const char *file, int line, const char *fmt, ...) internal_vwarning (file, line, fmt, ap); va_end (ap); } + +/* See common/errors.h. */ + +void +perror_with_name (const char *string) +{ + throw_perror_with_name (GENERIC_ERROR, string); +} diff --git a/gdb/common/errors.h b/gdb/common/errors.h index 36e2c49..c7d85f1 100644 --- a/gdb/common/errors.h +++ b/gdb/common/errors.h @@ -20,6 +20,8 @@ #ifndef COMMON_ERRORS_H #define COMMON_ERRORS_H +#include "common-exceptions.h" + /* A problem was detected, but the requested operation can still proceed. A warning message is constructed using a printf- or vprintf-style argument list. The function "vwarning" must be @@ -76,8 +78,15 @@ extern void internal_vwarning (const char *file, int line, /* Like "error", but the error message is constructed by combining - STRING with the system error message for errno. This function does - not return. This function must be provided by the client. */ + STRING with the system error message for errno. Uses ERRCODE for + the thrown exception. This function does not return. This + function must be provided by the client. */ + +extern void throw_perror_with_name (enum errors errcode, const char *string) + ATTRIBUTE_NORETURN; + +/* Convenience wrapper for "throw_perror_with_name" that throws + GENERIC_ERROR. */ extern void perror_with_name (const char *string) ATTRIBUTE_NORETURN; diff --git a/gdb/gdbserver/utils.c b/gdb/gdbserver/utils.c index e89a862..cd5734b 100644 --- a/gdb/gdbserver/utils.c +++ b/gdb/gdbserver/utils.c @@ -54,7 +54,7 @@ xstrdup (const char *s) Then return to command level. */ void -perror_with_name (const char *string) +throw_perror_with_name (enum errors errcode, const char *string) { const char *err; char *combined; @@ -68,7 +68,11 @@ perror_with_name (const char *string) strcat (combined, ": "); strcat (combined, err); +#ifdef IN_PROCESS_AGENT error ("%s.", combined); +#else + throw_error (errcode, "%s.", combined); +#endif } /* Print an error message and return to top level. */ diff --git a/gdb/utils.c b/gdb/utils.c index 7172bba..6b1aa89 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -990,14 +990,6 @@ throw_perror_with_name (enum errors errcode, const char *string) throw_error (errcode, _("%s."), combined); } -/* See throw_perror_with_name, ERRCODE defaults here to GENERIC_ERROR. */ - -void -perror_with_name (const char *string) -{ - throw_perror_with_name (GENERIC_ERROR, string); -} - /* Same as perror_with_name except that it prints a warning instead of throwing an error. */