Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Aleksandar Ristovski <aristovski@qnx.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [patch 4/6] Prepare linux_find_memory_regions_full & co. for move
Date: Tue, 02 Apr 2013 13:41:00 -0000	[thread overview]
Message-ID: <515ADD4B.9030409@qnx.com> (raw)
In-Reply-To: <20130402130733.GA11748@host2.jankratochvil.net>

On 13-04-02 09:07 AM, Jan Kratochvil wrote:
> 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);
>
>

Ok, diff from the code at patch 4 (i.e. after applying patches 1-4) that 
I will incorporate into patch 4 is pasted below.

I did not put any assert in target_fileio_read_alloc_1 - I don't think 
it's useful.

Thanks,

Aleksandar




diff --git a/gdb/target.c b/gdb/target.c
index d8ab056..ed0f3bf 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3522,17 +3522,11 @@ read_alloc (gdb_byte **buf_p, int handle, 
read_alloc_pre
        if (n <= 0)
         {
           if (n < 0 || (n == 0 && buf_pos == 0))
-           {
-             if (memory_to_free_ptr != NULL)
-               {
-                 gdb_assert (buf == *memory_to_free_ptr);
-                 *memory_to_free_ptr = NULL;
-               }
-             xfree (buf);
-           }
+           xfree (buf);
           else
             *buf_p = buf;
-
+         if (memory_to_free_ptr != NULL)
+           *memory_to_free_ptr = NULL;
           if (n < 0)
             {
               /* An error occurred.  */
@@ -3576,11 +3570,6 @@ target_fileio_read_alloc_1 (const char *filename,
    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;
-    }
    do_cleanups (close_cleanup);
    return retval;
  }





  reply	other threads:[~2013-04-02 13:30 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-22 15:07 [patch] gdbserver build-id in qxfer_libraries reply Aleksandar Ristovski
2013-02-22 18:39 ` Aleksandar Ristovski
2013-02-26 12:01   ` Pedro Alves
2013-02-27 17:25     ` Aleksandar Ristovski
2013-02-27 17:31       ` Aleksandar Ristovski
2013-02-27 18:44       ` Eli Zaretskii
2013-03-10 21:07 ` [draft patch 0/6] Split FYI and some review notes Jan Kratochvil
2013-03-11 14:25   ` Aleksandar Ristovski
2013-03-11 15:07     ` Jan Kratochvil
2013-03-14 18:43       ` Gary Benson
2013-03-14 19:55         ` Tom Tromey
2013-03-15 15:35         ` Aleksandar Ristovski
2013-03-15 15:44   ` Aleksandar Ristovski
2013-03-15 15:38     ` Aleksandar Ristovski
2013-03-15 16:28     ` Jan Kratochvil
2013-03-15 16:43       ` Aleksandar Ristovski
2013-03-10 21:08 ` [draft patch 3/6] Create empty common/linux-maps.[ch] Jan Kratochvil
2013-03-22 14:54   ` [patch " Aleksandar Ristovski
2013-03-22 13:06     ` Aleksandar Ristovski
2013-04-05 13:25     ` Aleksandar Ristovski
2013-03-10 21:08 ` [draft patch 4/6] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
2013-03-22 13:34   ` [patch " Aleksandar Ristovski
2013-03-22 13:54     ` Aleksandar Ristovski
2013-03-26 18:11     ` Jan Kratochvil
2013-03-27 20:44       ` Aleksandar Ristovski
2013-03-27 21:54         ` Aleksandar Ristovski
2013-03-28 23:02         ` Jan Kratochvil
2013-03-29  0:26           ` Aleksandar Ristovski
2013-03-29  0:29             ` Pedro Alves
2013-04-01 22:39           ` Aleksandar Ristovski
2013-04-01 21:13             ` Aleksandar Ristovski
2013-04-02 13:41             ` Jan Kratochvil
2013-04-02 13:41               ` Aleksandar Ristovski [this message]
2013-04-02 13:41                 ` Jan Kratochvil
2013-04-05 15:37                   ` Aleksandar Ristovski
2013-04-07 14:28                     ` Aleksandar Ristovski
2013-03-10 21:08 ` [draft patch 1/6] Move utility functions to common/ Jan Kratochvil
2013-03-22 13:13   ` [patch " Aleksandar Ristovski
2013-03-22 13:05     ` Aleksandar Ristovski
2013-04-07 18:54     ` Aleksandar Ristovski
2013-04-05 13:06       ` Aleksandar Ristovski
2013-03-10 21:08 ` [draft patch 2/6] Merge multiple hex conversions Jan Kratochvil
2013-03-22 13:05   ` [patch " Aleksandar Ristovski
2013-04-05 16:07     ` Aleksandar Ristovski
2013-03-10 21:09 ` [draft patch 6/6] gdbserver build-id attribute generator (unfixed) Jan Kratochvil
2013-03-10 22:04   ` Eli Zaretskii
2013-03-22 13:05   ` [patch 6/6] gdbserver build-id attribute generator Aleksandar Ristovski
2013-03-22 15:19     ` Aleksandar Ristovski
2013-03-22 17:24     ` Eli Zaretskii
2013-03-26 23:45     ` Jan Kratochvil
2013-03-27 17:54       ` Aleksandar Ristovski
2013-03-27 18:08         ` Jan Kratochvil
2013-03-27 18:12           ` Eli Zaretskii
2013-03-27 20:46           ` Aleksandar Ristovski
2013-03-29  0:13             ` Aleksandar Ristovski
2013-03-29  0:20               ` Aleksandar Ristovski
2013-03-29 16:19               ` Jan Kratochvil
     [not found]               ` <20130331174322.GB21374@host2.jankratochvil.net>
2013-04-02 17:18                 ` Aleksandar Ristovski
2013-04-04  2:22                   ` Jan Kratochvil
2013-04-05 15:05                     ` Aleksandar Ristovski
2013-04-09 15:28                       ` Gary Benson
2013-04-09 15:28                         ` Jan Kratochvil
2013-04-09 15:29                           ` Aleksandar Ristovski
2013-04-09 15:29                           ` Gary Benson
2013-04-09 15:28                         ` Aleksandar Ristovski
2013-04-09 19:26                           ` Gary Benson
2013-04-12 15:28                             ` Jan Kratochvil
2013-03-10 21:09 ` [draft patch 5/6] Move linux_find_memory_regions_full & co Jan Kratochvil
2013-03-22 13:05   ` [patch " Aleksandar Ristovski
2013-03-22 13:34     ` Aleksandar Ristovski
2013-03-26 18:27     ` Jan Kratochvil
2013-03-27 21:25       ` Aleksandar Ristovski
2013-03-28 22:38         ` Jan Kratochvil
2013-04-01 23:19           ` Aleksandar Ristovski
2013-04-02  2:33             ` Jan Kratochvil
2013-04-07 18:54               ` Aleksandar Ristovski
2013-04-05 15:37                 ` Aleksandar Ristovski
2013-04-02  2:33             ` Aleksandar Ristovski
2013-04-04 16:08 ` [patch] gdbserver build-id in qxfer_libraries reply Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=515ADD4B.9030409@qnx.com \
    --to=aristovski@qnx.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox