From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17530 invoked by alias); 14 Apr 2013 14:16:08 -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 17521 invoked by uid 89); 14 Apr 2013 14:16:08 -0000 X-Spam-SWARE-Status: No, score=-6.7 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; Sun, 14 Apr 2013 14:16:06 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3EEG358018470 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 14 Apr 2013 10:16:03 -0400 Received: from host2.jankratochvil.net (ovpn-116-44.ams2.redhat.com [10.36.116.44]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3EEFvJ7005752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Sun, 14 Apr 2013 10:16:01 -0400 Date: Mon, 15 Apr 2013 13:36:00 -0000 From: Jan Kratochvil To: Aleksandar Ristovski Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 4/8] Prepare linux_find_memory_regions_full & co. for move Message-ID: <20130414141556.GB23227@host2.jankratochvil.net> References: <1365521265-28870-1-git-send-email-ARistovski@qnx.com> <1365521265-28870-5-git-send-email-ARistovski@qnx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1365521265-28870-5-git-send-email-ARistovski@qnx.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2013-04/txt/msg00413.txt.bz2 On Tue, 09 Apr 2013 17:27:41 +0200, Aleksandar Ristovski wrote: [...] > --- a/gdb/target.c > +++ b/gdb/target.c > @@ -3476,55 +3476,67 @@ target_fileio_close_cleanup (void *opaque) > target_fileio_close (fd, &target_errno); > } > > +/* Helper for target_fileio_read_alloc_1 to make it interruptible. */ Here should be added (reason: so that one can easily find all the read_alloc_pread_ftype instances): static read_alloc_pread_ftype target_fileio_read_alloc_1_pread; (And move the read_alloc_pread_ftype definition above.) > + > +static int > +target_fileio_read_alloc_1_pread (int handle, gdb_byte *read_buf, int len, > + ULONGEST offset, int *target_errno) > +{ > + QUIT; > + > + return target_fileio_pread (handle, read_buf, len, offset, target_errno); > +} > + > /* Read target file FILENAME. Store the result in *BUF_P and > return the size of the transferred data. PADDING additional bytes are > available in *BUF_P. This is a helper function for > target_fileio_read_alloc; see the declaration of that function for more > information. */ > > +typedef int (read_alloc_pread_ftype) (int handle, gdb_byte *read_buf, int len, > + ULONGEST offset, int *target_errno); Use tabs. > + > static LONGEST > -target_fileio_read_alloc_1 (const char *filename, > - gdb_byte **buf_p, int padding) > +read_alloc (gdb_byte **buf_p, int handle, read_alloc_pread_ftype *pread_func, > + int padding, void **memory_to_free_ptr) > { > - struct cleanup *close_cleanup; > size_t buf_alloc, buf_pos; > gdb_byte *buf; > LONGEST n; > - int fd; > int target_errno; > > - 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); > - > /* Start by reading up to 4K at a time. The target will throttle > this number down if necessary. */ > buf_alloc = 4096; > buf = xmalloc (buf_alloc); > + if (memory_to_free_ptr != NULL) > + { > + gdb_assert (*memory_to_free_ptr == NULL); > + *memory_to_free_ptr = buf; > + } > buf_pos = 0; > while (1) > { > - n = target_fileio_pread (fd, &buf[buf_pos], > - buf_alloc - buf_pos - padding, buf_pos, > - &target_errno); > - if (n < 0) > + n = pread_func (handle, &buf[buf_pos], buf_alloc - buf_pos - padding, > + buf_pos, &target_errno); > + if (n <= 0) > { > - /* An error occurred. */ > - do_cleanups (close_cleanup); > - xfree (buf); > - return -1; > - } > - else if (n == 0) > - { > - /* Read all there was. */ > - do_cleanups (close_cleanup); > - if (buf_pos == 0) > + if (n < 0 || (n == 0 && buf_pos == 0)) > xfree (buf); > else > *buf_p = buf; > - return buf_pos; > + if (memory_to_free_ptr != NULL) > + *memory_to_free_ptr = NULL; > + if (n < 0) > + { > + /* An error occurred. */ > + return -1; > + } > + else > + { > + /* Read all there was. */ > + return buf_pos; > + } > } > > buf_pos += n; > @@ -3534,12 +3546,34 @@ target_fileio_read_alloc_1 (const char *filename, > { > buf_alloc *= 2; > buf = xrealloc (buf, buf_alloc); > + if (memory_to_free_ptr != NULL) > + *memory_to_free_ptr = buf; > } > - > - QUIT; > } > } > Here could be (so that one can easily find all the read_stralloc_func_ftype instances): static read_stralloc_func_ftype target_fileio_read_alloc_1; (And move the read_stralloc_func_ftype definition above.) > +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); > + do_cleanups (close_cleanup); > + return retval; > +} > + > /* Read target file FILENAME. Store the result in *BUF_P and return > the size of the transferred data. See the declaration in "target.h" > function for more information about the return value. */ [...] Thanks, Jan