From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17176 invoked by alias); 2 Apr 2013 13:07:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 17119 invoked by uid 89); 2 Apr 2013 13:07:44 -0000 X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 02 Apr 2013 13:07:41 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r32D7cxh031258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 2 Apr 2013 09:07:38 -0400 Received: from host2.jankratochvil.net (ovpn-116-23.ams2.redhat.com [10.36.116.23]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r32D7XuM008308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 2 Apr 2013 09:07:36 -0400 Date: Tue, 02 Apr 2013 13:41:00 -0000 From: Jan Kratochvil To: Aleksandar Ristovski Cc: "gdb-patches@sourceware.org" Subject: Re: [patch 4/6] Prepare linux_find_memory_regions_full & co. for move Message-ID: <20130402130733.GA11748@host2.jankratochvil.net> References: <51278984.3070208@qnx.com> <20130310210820.GE21130@host2.jankratochvil.net> <514C56CB.4070207@qnx.com> <20130326165242.GA12291@host2.jankratochvil.net> <515353C4.2050203@qnx.com> <20130328202805.GB9375@host2.jankratochvil.net> <5159E384.1040709@qnx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5159E384.1040709@qnx.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2013-04/txt/msg00033.txt.bz2 On Mon, 01 Apr 2013 21:44:04 +0200, Aleksandar Ristovski wrote: [...] > --- a/gdb/target.c > +++ b/gdb/target.c [...] > +static LONGEST > +target_fileio_read_alloc_1 (const char *filename, > + gdb_byte **buf_p, int padding) > +{ > + struct cleanup *close_cleanup; > + int fd, target_errno; > + void *memory_to_free = NULL; > + LONGEST retval; > + > + fd = target_fileio_open (filename, FILEIO_O_RDONLY, 0700, &target_errno); > + if (fd == -1) > + return -1; > + > + close_cleanup = make_cleanup (target_fileio_close_cleanup, &fd); > + > + make_cleanup (free_current_contents, &memory_to_free); > + retval = read_alloc (buf_p, fd, target_fileio_read_alloc_1_pread, padding, > + &memory_to_free); > + if (retval >= 0) > + { > + /* Returned allocated memory is interesting for the caller. */ > + memory_to_free = NULL; > } BTW ">= 0" is incorrect, the decision of filled in *BUF_P should be "> 0", see target_fileio_read_stralloc in FSF GDB: if (transferred < 0) return NULL; if (transferred == 0) return xstrdup (""); bufstr[transferred] = 0; or even the documentation of target_fileio_read_alloc: If a positive value is returned, a sufficiently large buffer will be allocated using xmalloc and returned in *BUF_P containing the contents of the object. But I find you wrote a workaround of my bug in the code of read_alloc, the should have been: if (n < 0 || (n == 0 && buf_pos == 0)) xfree (buf); else *buf_p = buf; if (memory_to_free_ptr != NULL) *memory_to_free_ptr = NULL; Then target_fileio_read_alloc_1 can contain just (if you want): gdb_assert (memory_to_free == NULL); Thanks, Jan