From patchwork Mon Sep 28 19:27:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 8870 Received: (qmail 4110 invoked by alias); 28 Sep 2015 19:27:04 -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 4100 invoked by uid 89); 28 Sep 2015 19:27:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-pd0-f201.google.com Received: from mail-pd0-f201.google.com (HELO mail-pd0-f201.google.com) (209.85.192.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 28 Sep 2015 19:27:01 +0000 Received: by pdbou10 with SMTP id ou10so13657688pdb.0 for ; Mon, 28 Sep 2015 12:27:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:date:subject:from:to :content-type; bh=rMhtCr8lW98cUQ69HXmgDM8eRY1m/Q48nsSjiBEFsAU=; b=kg7UZ9fgTPaCs7jMX3eO6ZqWwoBsFy+qYWOiGBJBf6ZaYqEws9cEQOzYE7SlU+YAZ0 qQTH8snnUvOQlWwtJ5nF3AT1FuvO0lGA0kbSKi7Uw0EDh06jnenAvwR3FSGnVtcZ13iH GlgM4u1Rw7wfP8tOJp90tKpqZMpLGuGgmS8OZ6qfYmAn7ySnKogfaylstMcPi7X453BB qYyzZ8zpQuKXvr9dyJgJIvI6Tb31s7ricUlQ0gdepVwqStnWLeOuP8zu1iWgOxsb0tIE gqmj/cZejsx2A1269zL91H1mSqMvUxKsA2nUUlIkZYnnozXpvLrQZOEMzO/rsmiTKU9+ DIHA== X-Gm-Message-State: ALoCoQkkeDkJkyLsJQyFKvLPp8i7dmF79GNDFvyftVcn0x6cGR3ZBWWF5Yc/ExuKcqal3Ypmzd1GCtt9/JEjHO1aE4mUKBDFSxc/w2S4f4oopJRoCf93WyNA7XuEL4KYrSBARFl3v1hAK+E0vAcWL7+gmkDeW63s7oT7RI+l2V4/y+BSBUZC9hg= MIME-Version: 1.0 X-Received: by 10.68.138.132 with SMTP id qq4mr19774253pbb.11.1443468420097; Mon, 28 Sep 2015 12:27:00 -0700 (PDT) Message-ID: <047d7b15aa736cfe890520d3ae29@google.com> Date: Mon, 28 Sep 2015 19:27:00 +0000 Subject: [PATCH 2/3] debugging with yama: add suberror code to gdb_exception From: Doug Evans To: gdb-patches@sourceware.org X-IsSubscribed: yes Hi. This patch basically just adds a suberror code to struct gdb_exception so that we can pass errno in the exception, and then makes passing of errno explicit in a couple of places. 2015-09-28 Doug Evans * common/common-exceptions.c (exceptions_state_mc_init): Initialize suberror. (throw_it): New arg suberror. All callers updated. (throw_error_with_suberror): New function. * common/common-exceptions.h (enum errors): New enum value SYSCALL_FAILED_ERROR. (struct gdb_exception): New member suberror. (throw_error_with_suberror): Declare. * utils.c (perror_string): New arg errno_value. All callers updated. (throw_perror_with_name): Ditto. Call throw_error_with_suberror. extern void perror_warning_with_name (const char *string); diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c index 8ee96ab..b88b232 100644 --- a/gdb/common/common-exceptions.c +++ b/gdb/common/common-exceptions.c @@ -20,7 +20,7 @@ #include "common-defs.h" #include "common-exceptions.h" -const struct gdb_exception exception_none = { 0, GDB_NO_ERROR, NULL }; +const struct gdb_exception exception_none = { 0, GDB_NO_ERROR, 0, NULL }; #ifndef __cplusplus @@ -314,9 +314,9 @@ static char **exception_messages; /* The number of currently allocated entries in exception_messages. */ static int exception_messages_size; -static void ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0) -throw_it (enum return_reason reason, enum errors error, const char *fmt, - va_list ap) +static void ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (4, 0) +throw_it (enum return_reason reason, enum errors error, int suberror, + const char *fmt, va_list ap) { struct gdb_exception e; char *new_message; @@ -348,6 +348,7 @@ throw_it (enum return_reason reason, enum errors error, const char *fmt, /* Create the exception. */ e.reason = reason; e.error = error; + e.suberror = suberror; e.message = new_message; /* Throw the exception. */ @@ -357,13 +358,13 @@ throw_it (enum return_reason reason, enum errors error, const char *fmt, void throw_verror (enum errors error, const char *fmt, va_list ap) { - throw_it (RETURN_ERROR, error, fmt, ap); + throw_it (RETURN_ERROR, error, 0, fmt, ap); } void throw_vquit (const char *fmt, va_list ap) { - throw_it (RETURN_QUIT, GDB_NO_ERROR, fmt, ap); + throw_it (RETURN_QUIT, GDB_NO_ERROR, 0, fmt, ap); } void @@ -376,6 +377,19 @@ throw_error (enum errors error, const char *fmt, ...) va_end (args); } +/* Throw ERROR with suberror value SUBERROR. */ + +void +throw_error_with_suberror (enum errors error, int suberror, + const char *fmt, ...) +{ + va_list args; + + va_start (args, fmt); + throw_it (RETURN_ERROR, error, suberror, fmt, args); + va_end (args); +} + void throw_quit (const char *fmt, ...) { diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h index 2e6a6d9..45054c1 100644 --- a/gdb/common/common-exceptions.h +++ b/gdb/common/common-exceptions.h @@ -105,6 +105,10 @@ enum errors { "_ERROR" is appended to the name. */ MAX_COMPLETIONS_REACHED_ERROR, + /* A system call failed. + The "errno" value is in gdb_exception.suberror. */ + SYSCALL_FAILED_ERROR, + /* Add more errors here. */ NR_ERRORS }; @@ -113,6 +117,9 @@ struct gdb_exception { enum return_reason reason; enum errors error; + /* Extra information to describe ERROR. Unless the error is documented to + provide a suberror code, this value is zero. */ + int suberror; const char *message; }; @@ -262,6 +269,9 @@ extern void throw_vquit (const char *fmt, va_list ap) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 0); extern void throw_error (enum errors error, const char *fmt, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3); +extern void throw_error_with_suberror (enum errors error, int suberror, + const char *fmt, ...) + ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 4); extern void throw_quit (const char *fmt, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2); diff --git a/gdb/utils.c b/gdb/utils.c index c7f00d9..a6b5744 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -934,17 +916,17 @@ add_internal_problem_command (struct internal_problem *problem) } /* Return a newly allocated string, containing the PREFIX followed - by the system error message for errno (separated by a colon). + by the system error message for ERRNO_VALUE (separated by a colon). The result must be deallocated after use. */ static char * -perror_string (const char *prefix) +perror_string (const char *prefix, int errno_value) { char *err; char *combined; - err = safe_strerror (errno); + err = safe_strerror (errno_value); combined = (char *) xmalloc (strlen (err) + strlen (prefix) + 3); strcpy (combined, prefix); strcat (combined, ": "); @@ -953,16 +935,16 @@ perror_string (const char *prefix) return combined; } -/* Print the system error message for errno, and also mention STRING - as the file name for which the error was encountered. Use ERRCODE - for the thrown exception. Then return to command level. */ +/* Throw an error with the system error message for ERRNO_VAL, and also mention + STRING as the file name or system call for which the error was encountered. + Use ERRCODE for the thrown exception. */ void -throw_perror_with_name (enum errors errcode, const char *string) +throw_perror_with_name (enum errors errcode, int errno_val, const char *string) { char *combined; - combined = perror_string (string); + combined = perror_string (string, errno_val); make_cleanup (xfree, combined); /* I understand setting these is a matter of taste. Still, some people @@ -971,7 +953,9 @@ throw_perror_with_name (enum errors errcode, const char *string) bfd_set_error (bfd_error_no_error); errno = 0; - throw_error (errcode, _("%s."), combined); + throw_error_with_suberror (errcode, + errcode == SYSCALL_FAILED_ERROR ? errno_val : 0, + _("%s."), combined); } /* See throw_perror_with_name, ERRCODE defaults here to GENERIC_ERROR. */ @@ -979,7 +963,7 @@ throw_perror_with_name (enum errors errcode, const char *string) void perror_with_name (const char *string) { - throw_perror_with_name (GENERIC_ERROR, string); + throw_perror_with_name (GENERIC_ERROR, errno, string); } /* Same as perror_with_name except that it prints a warning instead @@ -990,7 +974,7 @@ perror_warning_with_name (const char *string) { char *combined; - combined = perror_string (string); + combined = perror_string (string, errno); warning (_("%s"), combined); xfree (combined); } diff --git a/gdb/utils.h b/gdb/utils.h index 995a1cf..d1111fa 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -267,7 +263,8 @@ extern CORE_ADDR string_to_core_addr (const char *my_string); extern void fprintf_symbol_filtered (struct ui_file *, const char *, enum language, int); -extern void throw_perror_with_name (enum errors errcode, const char *string) +extern void throw_perror_with_name (enum errors errcode, int errno_val, + const char *string) ATTRIBUTE_NORETURN;