Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>,
	Jan Kratochvil <jan.kratochvil@redhat.com>,
	Ken Werner <ken@linux.vnet.ibm.com>
Subject: Re: [patch] const array types
Date: Fri, 24 Sep 2010 16:40:00 -0000	[thread overview]
Message-ID: <201009241638.27072.pedro@codesourcery.com> (raw)
In-Reply-To: <20100924144234.GF3007@adacore.com>

On Friday 24 September 2010 15:42:34, Joel Brobecker wrote:
> > I have filed now http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45765 as
> > I believe it could be fixed more at the DWARF producer side.
> 
> For what it's worth, I tend to agree that this should be fixed
> on the compiler side.

I disagree:

const struct { int x; } a;

struct S { int x; };
const struct S b;

It looks sane to me to not emit a whole new struct
type based on struct S that includes a
`const inst x' just for `b' (rather than DW_TAG_const_type
pointing at struct S).  Is `a' really any different?

> > I would find this patch OK even if it fixes only the TYPE_CODE_ARRAY.
> 
> I'm a little hesitant, still (but not objecting!). It it was a one-liner,
> I'd be less reluctant, but I just want to make sure that the improvement
> is worth the code we're adding. Yes, the output is more accurate, but
> is it really all that bad to be missing the `const'?

E.g., out of the blue, in C++ it can make the user call the
wrong function from gdb, when there are overloads
involved (, or templates, I guess):

$ cat const.cc
#include <stdio.h>

const struct { int x; } a = {0};

struct S { int x; };

const struct S b = {0};

__typeof__ (a.x) i1 = 0;
__typeof__ (b.x) i2 = 0;

void
function (int *f)
{
  printf ("called function (int *)\n");
}

void
function (const int *f)
{
  printf ("called function (const int *)\n");
}

int
main ()
{
  function (&a.x);
  function (&b.x);
  function (&i1);
  function (&i2);
}

$ ./gdb ./const 
...
(gdb) start
Temporary breakpoint 1 at 0x400638: file const.cc, line 27.
...
Temporary breakpoint 1, main () at const.cc:27
27        function (&a.x);

(gdb) call function(&a.x)
called function (int *)
^^^^^^^^^^^^^^^^^^^^^^^
(gdb) n
called function (const int *)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28        function (&b.x);

-- 
Pedro Alves


  reply	other threads:[~2010-09-24 15:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-15 19:32 Ken Werner
2010-09-24  4:50 ` Jan Kratochvil
2010-09-24 15:38   ` Jan Kratochvil
2010-09-24 16:27   ` Joel Brobecker
2010-09-24 16:40     ` Pedro Alves [this message]
2010-09-24 23:00       ` Joel Brobecker
2010-09-24 18:36   ` Ken Werner
2010-10-05 18:25     ` Ulrich Weigand
2010-10-05 18:43       ` Joel Brobecker
2010-10-06 15:38       ` Ken Werner
2010-10-06 15:55         ` Ulrich Weigand
2010-10-06 16:18           ` Ken Werner

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=201009241638.27072.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=ken@linux.vnet.ibm.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