From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11119 invoked by alias); 4 Mar 2005 17:51:22 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 11044 invoked from network); 4 Mar 2005 17:51:12 -0000 Received: from unknown (HELO nevyn.them.org) (66.93.172.17) by sourceware.org with SMTP; 4 Mar 2005 17:51:12 -0000 Received: from drow by nevyn.them.org with local (Exim 4.44 #1 (Debian)) id 1D7GxD-0006vw-Bw; Fri, 04 Mar 2005 12:51:11 -0500 Date: Fri, 04 Mar 2005 17:51:00 -0000 From: Daniel Jacobowitz To: "Theodore A. Roth" Cc: Andrew Cagney , gdb-patches@sources.redhat.com Subject: Re: [RFA] initialize err variable in load_section_callback() Message-ID: <20050304175110.GA3986@nevyn.them.org> Mail-Followup-To: "Theodore A. Roth" , Andrew Cagney , gdb-patches@sources.redhat.com References: <4176A188.1030904@gnu.org> <417D9450.2030401@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6+20040907i X-SW-Source: 2005-03/txt/msg00051.txt.bz2 On Mon, Dec 27, 2004 at 06:33:48PM -0800, Theodore A. Roth wrote: > This patch got left hanging. Is it a lost cause or can I get approval to > commit it? Sorry about the delay; a coworker just ran into this, which prodded me to take another look at the problem. I'm committing something similar. Your patch isn't quite right... here's the documented behavior of target_read_memory_partial: /* Make a single attempt at transfering LEN bytes. On a successful transfer, the number of bytes actually transfered is returned and ERR is set to 0. When a transfer fails, -1 is returned (the number of bytes actually transfered is not defined) and ERR is set to a non-zero error indication. */ Here's a bit of target_read_partial: /* Request the transfer of up to LEN 8-bit bytes of the target's OBJECT. The OFFSET, for a seekable object, specifies the starting point. The ANNEX can be used to provide additional data-specific information to the target. Return the number of bytes actually transfered, zero when no further transfer is possible, and -1 when the transfer is not supported. "No further transfer is possible" is an error condition. remote_xfer_partial and inf_ptrace_xfer_partial don't seem to agree about whether an I/O failure is a "return 0" or a "return -1" condition; I am inclined to agree with the inf_ptrace implementation, since the transfer is supported, but failed. An argument could be made for either. This patch makes target_write_memory_partial obey its specification, as long as target_read_partial obeys its. No further transfer and unsupported are both error conditions. The specifications could still use some clarifying (separately). Tested on i686-linux native, and tested by hand that load doesn't blow up any more. > > > - when -ve, set *err -VE return value > > > > I assume -ve is an error code? Sould I extend my patch to also check for > > retval < -1 and if so set *err to retval? He just meant "negative": if the return value is negative, set *err to its absolute value. I stuck with the existing use of errno instead. -- Daniel Jacobowitz CodeSourcery, LLC 2005-03-04 Daniel Jacobowitz * target.c (target_read_memory_partial): Always initialize ERR. (target_write_memory_partial): Likewise. Index: target.c =================================================================== RCS file: /cvs/src/src/gdb/target.c,v retrieving revision 1.101 diff -u -p -r1.101 target.c --- target.c 24 Feb 2005 13:51:35 -0000 1.101 +++ target.c 4 Mar 2005 17:08:12 -0000 @@ -1,7 +1,7 @@ /* Select target systems and architectures at runtime for GDB. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Contributed by Cygnus Support. @@ -1249,8 +1249,26 @@ int target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err) { if (target_xfer_partial_p ()) - return target_xfer_partial (target_stack, TARGET_OBJECT_MEMORY, NULL, - buf, NULL, memaddr, len); + { + int retval; + + retval = target_xfer_partial (target_stack, TARGET_OBJECT_MEMORY, + NULL, buf, NULL, memaddr, len); + + if (retval <= 0) + { + if (errno) + *err = errno; + else + *err = EIO; + return -1; + } + else + { + *err = 0; + return retval; + } + } else return target_xfer_memory_partial (memaddr, buf, len, 0, err); } @@ -1259,8 +1277,26 @@ int target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err) { if (target_xfer_partial_p ()) - return target_xfer_partial (target_stack, TARGET_OBJECT_MEMORY, NULL, - NULL, buf, memaddr, len); + { + int retval; + + retval = target_xfer_partial (target_stack, TARGET_OBJECT_MEMORY, + NULL, NULL, buf, memaddr, len); + + if (retval <= 0) + { + if (errno) + *err = errno; + else + *err = EIO; + return -1; + } + else + { + *err = 0; + return retval; + } + } else return target_xfer_memory_partial (memaddr, buf, len, 1, err); }