From patchwork Wed Sep 17 12:41:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 2885 Received: (qmail 8885 invoked by alias); 17 Sep 2014 12:41:27 -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 8872 invoked by uid 89); 17 Sep 2014 12:41:27 -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, MSGID_FROM_MTA_HEADER, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: e06smtp12.uk.ibm.com Received: from e06smtp12.uk.ibm.com (HELO e06smtp12.uk.ibm.com) (195.75.94.108) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 17 Sep 2014 12:41:25 +0000 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 17 Sep 2014 13:41:21 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 17 Sep 2014 13:41:20 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id E58D717D8045 for ; Wed, 17 Sep 2014 13:43:23 +0100 (BST) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id s8HCfJ4h23658546 for ; Wed, 17 Sep 2014 12:41:19 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s8HCfIDg007592 for ; Wed, 17 Sep 2014 06:41:19 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with SMTP id s8HCfHqs007521; Wed, 17 Sep 2014 06:41:17 -0600 Message-Id: <201409171241.s8HCfHqs007521@d06av02.portsmouth.uk.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Wed, 17 Sep 2014 14:41:17 +0200 Subject: Re: [PATCH] [PR tdep/17379] Fix internal-error when stack pointer is invalid To: palves@redhat.com (Pedro Alves) Date: Wed, 17 Sep 2014 14:41:17 +0200 (CEST) From: "Ulrich Weigand" Cc: emachado@linux.vnet.ibm.com (Edjunior Barbosa Machado), gdb-patches@sourceware.org In-Reply-To: <54195D36.2080001@redhat.com> from "Pedro Alves" at Sep 17, 2014 11:06:46 AM MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14091712-8372-0000-0000-000001365B73 Pedro Alves wrote: > See https://sourceware.org/bugzilla/show_bug.cgi?id=17384 . > > When safe_read_memory_integer call fails, GDB prints a > surprising/confusing error message, more so in case the unwinder > is triggered for some reason other than the "bt" command, like > with "step"/"next". I take you're now seeing the same errors > with this patch. > > IMO, printing the error is not something a low-level helper function > like safe_read_memory_integer should be doing, as GDB uses it when > probing with heuristics because it can't sure its guesses make sense > (whether there's a frame at all, etc.) safe_frame_unwind_memory, which is > used in rs6000_in_function_epilogue_p doesn't print the error either. Agreed, it doesn't make sense for safe_read_memory_integer to ever print an error. In fact, it doesn't make sense for it to start using a routine that raises exceptions and then attempt to catch it. The following patch simplifies the whole logic by just using target_read_memory directly. Does this look reasonable? [ B.t.w. the naming of safe_frame_unwind_memory is a bit weird. This should either be "safe_read_memory" in corefile.c, or else something like safe_get_frame_memory in analogy to get_frame_memory. ] Tested on powerpc64le-linux. Bye, Ulrich gdb/ChangeLog: * corefile.c (struct captured_read_memory_integer_arguments): Remove. (do_captured_read_memory_integer): Remove. (safe_read_memory_integer): Use target_read_memory directly instead of catching errors in do_captured_read_memory_integer. diff --git a/gdb/corefile.c b/gdb/corefile.c index 1617392..a0bb2aa 100644 --- a/gdb/corefile.c +++ b/gdb/corefile.c @@ -290,40 +290,6 @@ read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len) memory_error (status, memaddr); } -/* Argument / return result struct for use with - do_captured_read_memory_integer(). MEMADDR and LEN are filled in - by gdb_read_memory_integer(). RESULT is the contents that were - successfully read from MEMADDR of length LEN. */ - -struct captured_read_memory_integer_arguments -{ - CORE_ADDR memaddr; - int len; - enum bfd_endian byte_order; - LONGEST result; -}; - -/* Helper function for gdb_read_memory_integer(). DATA must be a - pointer to a captured_read_memory_integer_arguments struct. - Return 1 if successful. Note that the catch_errors() interface - will return 0 if an error occurred while reading memory. This - choice of return code is so that we can distinguish between - success and failure. */ - -static int -do_captured_read_memory_integer (void *data) -{ - struct captured_read_memory_integer_arguments *args - = (struct captured_read_memory_integer_arguments*) data; - CORE_ADDR memaddr = args->memaddr; - int len = args->len; - enum bfd_endian byte_order = args->byte_order; - - args->result = read_memory_integer (memaddr, len, byte_order); - - return 1; -} - /* Read memory at MEMADDR of length LEN and put the contents in RETURN_VALUE. Return 0 if MEMADDR couldn't be read and non-zero if successful. */ @@ -333,19 +299,13 @@ safe_read_memory_integer (CORE_ADDR memaddr, int len, enum bfd_endian byte_order, LONGEST *return_value) { - int status; - struct captured_read_memory_integer_arguments args; - - args.memaddr = memaddr; - args.len = len; - args.byte_order = byte_order; + gdb_byte buf[sizeof (LONGEST)]; - status = catch_errors (do_captured_read_memory_integer, &args, - "", RETURN_MASK_ALL); - if (status) - *return_value = args.result; + if (target_read_memory (memaddr, buf, len)) + return 0; - return status; + *return_value = extract_signed_integer (buf, len, byte_order); + return 1; } LONGEST