Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Aleksandar Ristovski <aristovski@qnx.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 6/8] gdbserver build-id attribute generator
Date: Thu, 18 Apr 2013 10:08:00 -0000	[thread overview]
Message-ID: <20130417203330.GE2090@host2.jankratochvil.net> (raw)
In-Reply-To: <516D6AE7.8030700@qnx.com>

On Tue, 16 Apr 2013 17:14:47 +0200, Aleksandar Ristovski wrote:
> On 13-04-14 10:16 AM, Jan Kratochvil wrote:
> >On Tue, 09 Apr 2013 17:27:43 +0200, Aleksandar Ristovski wrote:
> >>+	      break;
> >>+	    }
> >>+
> >>+	  nhdr = (void *) pt_note;
> >>+	  while ((void *) nhdr < (void *) pt_end)
> >
> >When it is all const there should be (const void *).  But in fact it is easier
> >to use const gdb_byte * when pt_end is already such type:
> >	  while ((const gdb_byte *) nhdr < pt_end)
> 
> gdb_byte * is o.k., but there is no really a need for const - when
> casting is for the purpose of pointer comparison, IMO const only
> clutters the reading.

As stated also elsewhere in this review one of the review purposes is to keep
the GDB (and GNU) coding unified (when not explicitly defined by GNU Coding
Standards).

GDB was not formerly using const at all, it is moving now towards to
const-correct typing.  AFAIK const is never used for values in GDB, only for
targets.  Too many const attributes are a problem for GNU Coding Standards
compliant code as the narrow 80 columns formatting then needs multi-line
statements which are difficult to read.

But when I agreed even with const values when you are used to it please do not
break the const-correctness afterwards.  I do not see what is a purpose of all
the const attributes when in the end there are free de-const-ing casts.


> >>+	    {
> >>+	      const size_t namesz
> >>+		= ELFXX_ROUNDUP (ELFXX_FLD (*nhdr, n_namesz));
> >>+	      const size_t descsz
> >>+		= ELFXX_ROUNDUP (ELFXX_FLD (*nhdr, n_descsz));
> >>+	      const size_t note_sz = ELFXX_SIZEOF (*nhdr) + namesz + descsz;
> >>+
> >>+	      if (((gdb_byte *) nhdr + note_sz) > pt_end || note_sz == 0
> >
> >It should be (const gdb_byte *) because nhdr is already const *.
> 
> I like using const, as you may have noticed, unless it only
> clutters, like is the case when casting is used for the purpose of
> pointer comparison like here.

It really does not matter what you like, it matters what is the current GDB
coding practice.

And when a pointer is const type * I find a bug to cast it to non-const type *.
What if the caller really pointed it to a read-only segment.  non-const type *
is at least confusing in such case.


> >>+		  break;
> >>+		}
> >>+	      if (ELFXX_FLD (*nhdr, n_type) == NT_GNU_BUILD_ID
> >>+		  && ELFXX_FLD (*nhdr, n_namesz) == 4)
> >>+		{
> >>+		  const char gnu[4] = "GNU\0";
> >>+		  const char *const pname
> >>+		    = (char *) nhdr + ELFXX_SIZEOF (*nhdr);
> >
> >It should be (const char *) because nhdr is already const *.
> 
> When assigning to const, then const in the cast for pointer
> arithmetic does not matter and IMO only clutters.

const * cast to non-const * cast is a bug.

When there is even no agreement on how to use const it is better to keep the
GDB standards and not to use too many const keywords.


> >>+	}
> >>  		{
> >>  		  /* Expand to guarantee sufficient storage.  */
> >>-		  uintptr_t document_len = p - document;
> >>+		  const ptrdiff_t document_len = p - document;
> >>
> >>-		  document = xrealloc (document, 2 * allocated);
> >>  		  allocated *= 2;
> >>+		  document = xrealloc (document, allocated);
> >>  		  p = document + document_len;
> >>  		}
> >
> >This "code cleanup" change is unrelated to this patch.  But it is IMO not
> >worth checking in separately, it does not improve it anyhow IMO.
> 
> It uses correct type for pointer difference and does not repeat
> arithmetic. I removed it, it will probably reduce clash with Gary's
> patch.

You are right ptrdiff_t is more correct there but this 64-bit correctness is
unreal to be ever violated.  GDB has more serious 64-bit sizes violations...


Thanks,
Jan


  reply	other threads:[~2013-04-17 20:33 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 16:15 [PATCH 0/8] v2 - validate binary before use Aleksandar Ristovski
2013-04-09 15:53 ` [PATCH 1/8] Move utility functions to common/ Aleksandar Ristovski
2013-04-09 16:01 ` [PATCH 2/8] Merge multiple hex conversions Aleksandar Ristovski
2013-04-09 16:03 ` [PATCH 3/8] Create empty common/linux-maps.[ch] and common/common-target.[ch] Aleksandar Ristovski
2013-04-15 13:34   ` Jan Kratochvil
2013-04-09 16:39 ` [PATCH 4/8] Prepare linux_find_memory_regions_full & co. for move Aleksandar Ristovski
2013-04-15 13:36   ` Jan Kratochvil
2013-04-16 17:19     ` Aleksandar Ristovski
2013-04-09 16:48 ` [PATCH 5/8] Move linux_find_memory_regions_full & co Aleksandar Ristovski
2013-04-15 13:52   ` Jan Kratochvil
2013-04-16 15:46     ` Aleksandar Ristovski
2013-04-09 16:55 ` [PATCH 6/8] gdbserver build-id attribute generator Aleksandar Ristovski
2013-04-09 18:52   ` Eli Zaretskii
2013-04-15 14:23   ` Jan Kratochvil
2013-04-16 16:40     ` Aleksandar Ristovski
2013-04-18 10:08       ` Jan Kratochvil [this message]
2013-04-09 17:37 ` [PATCH 8/8] Tests for validate symbol file using build-id Aleksandar Ristovski
2013-04-15 15:12   ` Jan Kratochvil
2013-04-16 17:25     ` Aleksandar Ristovski
2013-04-18  5:37       ` Jan Kratochvil
2013-04-09 17:50 ` [PATCH 7/8] Validate " Aleksandar Ristovski
2013-04-10 22:35   ` Aleksandar Ristovski
2013-04-10 19:58     ` Aleksandar Ristovski
2013-04-11  1:26     ` Jan Kratochvil
2013-04-11  2:43       ` Aleksandar Ristovski
2013-04-15 14:58   ` Jan Kratochvil
2013-04-16 19:14     ` Aleksandar Ristovski
2013-04-18 10:23       ` Jan Kratochvil
2013-04-09 17:53 ` [PATCH 0/8] v2 - validate binary before use Jan Kratochvil
2013-04-09 18:09   ` Aleksandar Ristovski
2013-04-16 18:03 ` Aleksandar Ristovski
2013-04-16 18:30   ` [PATCH 7/8] Validate symbol file using build-id Aleksandar Ristovski
2013-04-16 18:30   ` [PATCH 2/8] Merge multiple hex conversions Aleksandar Ristovski
2013-04-16 18:31   ` [PATCH 6/8] gdbserver build-id attribute generator Aleksandar Ristovski
2013-04-18  7:40     ` Jan Kratochvil
2013-04-16 18:31   ` [PATCH 5/8] Move linux_find_memory_regions_full & co Aleksandar Ristovski
2013-04-16 18:31   ` [PATCH 8/8] Tests for validate symbol file using build-id Aleksandar Ristovski
2013-04-18 10:15     ` Jan Kratochvil
2013-04-16 18:31   ` [PATCH 4/8] Prepare linux_find_memory_regions_full & co. for move Aleksandar Ristovski
2013-04-18  8:58     ` Jan Kratochvil
2013-04-16 18:31   ` [PATCH 1/8] Move utility functions to common/ Aleksandar Ristovski
2013-04-16 20:24   ` [PATCH 3/8] Create empty common/linux-maps.[ch] and common/common-target.[ch] Aleksandar Ristovski

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=20130417203330.GE2090@host2.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=aristovski@qnx.com \
    --cc=gdb-patches@sourceware.org \
    /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