public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] const array types
@ 2010-09-15 19:32 Ken Werner
  2010-09-24  4:50 ` Jan Kratochvil
  0 siblings, 1 reply; 12+ messages in thread
From: Ken Werner @ 2010-09-15 19:32 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: Text/Plain, Size: 220 bytes --]

Hi,

The attached patch changes the dwarf parsing of const types. In case the const 
qualifier is applied to an array type, the element type is so qualified, not the 
array type. Comments are welcome.

Thanks
Ken Werner

[-- Attachment #2: const_array.patch --]
[-- Type: text/x-patch, Size: 4685 bytes --]

ChangeLog:

2010-09-15  Ken Werner  <ken.werner@de.ibm.com>

	* gdb/dwarf2read.c (read_tag_const_type): Handle const arrays.

testsuite/ChangeLog:

2010-09-15  Ken Werner  <ken.werner@de.ibm.com>

	* gdb.base/constvars.c (logical, lugged, luck, lunar, lumen, lurk,
	lush, lynx) New constant.
	* gdb.base/constvars.exp: Test const array types.
	* gdb.dwarf2/dw2-strp.exp: Add const qualifier for ptype tests.

Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.457
diff -p -u -r1.457 dwarf2read.c
--- gdb/dwarf2read.c	14 Sep 2010 21:28:53 -0000	1.457
+++ gdb/dwarf2read.c	15 Sep 2010 16:26:41 -0000
@@ -7617,6 +7617,29 @@ read_tag_const_type (struct die_info *di
   if (cv_type)
     return cv_type;
 
+  /* In case the const qualifier is applied to an array type, the element type
+     is so qualified, not the array type (section 6.7.3 of C99).  */
+  if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
+    {
+      struct type *el_type, *inner_array;
+
+      base_type = copy_type (base_type);
+      inner_array = base_type;
+
+      while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
+	{
+	  TYPE_TARGET_TYPE (inner_array) =
+	    copy_type (TYPE_TARGET_TYPE (inner_array));
+	  inner_array = TYPE_TARGET_TYPE (inner_array);
+	}
+
+      el_type = TYPE_TARGET_TYPE (inner_array);
+      TYPE_TARGET_TYPE (inner_array) =
+	make_cv_type (1, TYPE_VOLATILE (el_type), el_type, 0);
+
+      return set_die_type (die, base_type, cu);;
+    }
+
   cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
   return set_die_type (die, cv_type, cu);
 }
Index: gdb/testsuite/gdb.base/constvars.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/constvars.c,v
retrieving revision 1.4
diff -p -u -r1.4 constvars.c
--- gdb/testsuite/gdb.base/constvars.c	12 Nov 2009 19:35:26 -0000	1.4
+++ gdb/testsuite/gdb.base/constvars.c	15 Sep 2010 16:26:41 -0000
@@ -84,6 +84,16 @@ main (void)
   float          *const   lissome   = &leeway;
   double         *const   locust    = &legacy;
 
+  /* constant arrays */
+  const char logical[2] = {laconic, laconic};
+  const unsigned char lugged[2] = {laggard, laggard};
+  const short luck[2] = {lagoon, lagoon};
+  const unsigned short lunar[2] = {laity, laity};
+  const long lumen[2] = {lambent, lambent};
+  const unsigned long lurk[2] = {laminated, laminated};
+  const float lush[2] = {lampoon, lampoon};
+  const double lynx[2] = {languid, languid};
+
   /* volatile variables */
 
   volatile char vox = 'X';
Index: gdb/testsuite/gdb.base/constvars.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/constvars.exp,v
retrieving revision 1.23
diff -p -u -r1.23 constvars.exp
--- gdb/testsuite/gdb.base/constvars.exp	24 May 2010 22:03:59 -0000	1.23
+++ gdb/testsuite/gdb.base/constvars.exp	15 Sep 2010 16:26:41 -0000
@@ -253,6 +253,16 @@ proc do_constvar_tests {} {
     gdb_test "ptype locust" "type = double \\* const"
 
     local_compiler_xfail_check
+    gdb_test "ptype logical" "type = const char \\\[2\\\]"
+    gdb_test "ptype lugged" "type = const unsigned char \\\[2\\\]"
+    gdb_test "ptype luck" "type = const short( int)? \\\[2\\\]"
+    gdb_test "ptype lunar" "type = const (unsigned short|short unsigned)( int)? \\\[2\\\]"
+    gdb_test "ptype lumen" "type = const long( int)? \\\[2\\\]"
+    gdb_test "ptype lurk" "type = const (unsigned long|long unsigned)( int)? \\\[2\\\]"
+    gdb_test "ptype lush" "type = const float \\\[2\\\]"
+    gdb_test "ptype lynx" "type = const double \\\[2\\\]"
+
+    local_compiler_xfail_check
     local_compiler_xfail_check_2
     gdb_test "ptype crass" "type = struct crass \{\[\r\n\]+\[\ \t\]+char \\* const ptr;\[\r\n\]+\}"
     local_compiler_xfail_check
Index: gdb/testsuite/gdb.dwarf2/dw2-strp.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.dwarf2/dw2-strp.exp,v
retrieving revision 1.4
diff -p -u -r1.4 dw2-strp.exp
--- gdb/testsuite/gdb.dwarf2/dw2-strp.exp	1 Jan 2010 07:32:02 -0000	1.4
+++ gdb/testsuite/gdb.dwarf2/dw2-strp.exp	15 Sep 2010 17:14:32 -0000
@@ -49,7 +49,7 @@ gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
 
 gdb_test "p a_string" " = \"hello world!\\\\n\""
-gdb_test "ptype a_string" "type = char \\\[14\\\]"
+gdb_test "ptype a_string" "type = const char \\\[14\\\]"
 
 gdb_test "p a_string2" " = \"hello world2\\\\n\""
-gdb_test "ptype a_string2" "type = char \\\[14\\\]"
+gdb_test "ptype a_string2" "type = const char \\\[14\\\]"

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  2010-09-15 19:32 [patch] const array types Ken Werner
@ 2010-09-24  4:50 ` Jan Kratochvil
  2010-09-24 15:38   ` Jan Kratochvil
                     ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Jan Kratochvil @ 2010-09-24  4:50 UTC (permalink / raw)
  To: Ken Werner; +Cc: gdb-patches

On Wed, 15 Sep 2010 19:20:37 +0200, Ken Werner wrote:
> The attached patch changes the dwarf parsing of const types. In case the const 
> qualifier is applied to an array type, the element type is so qualified, not the 
> array type. Comments are welcome.

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.

It is questionable whether it gets accepted and fixed by GCC and whether you
would like it then fixed in GDB even for older GCCs and non-GCC compilers.

I believe besides TYPE_CODE_ARRAY the same logic should be applied even to all
the fields of TYPE_CODE_STRUCT and TYPE_CODE_UNION (excluding the static
fields).  While ISO C99 does not say so (or does?) GCC behaves correctly:

const struct { int x; } b1;
__typeof__ (b1.x) b2;

(gdb) ptype b1.x
type = int
       ^^^ = The GDB (and possibly even GCC) bug.
(gdb) ptype b2
type = const int
       ^^^^^^^^^ GCC is aware the element is in fact `const'.

I would find this patch OK even if it fixes only the TYPE_CODE_ARRAY.


> +      while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)

The type can be opaque and TYPE_TARGET_TYPE is then NULL.  Opaque type should
not be possible to be produced for an array element but some `error' call
would be nice there.


> +	make_cv_type (1, TYPE_VOLATILE (el_type), el_type, 0);
                                                           ^ NULL?
I would find NULL for a pointer parameter more readable.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  2010-09-24  4:50 ` Jan Kratochvil
@ 2010-09-24 15:38   ` Jan Kratochvil
  2010-09-24 16:27   ` Joel Brobecker
  2010-09-24 18:36   ` Ken Werner
  2 siblings, 0 replies; 12+ messages in thread
From: Jan Kratochvil @ 2010-09-24 15:38 UTC (permalink / raw)
  To: Ken Werner; +Cc: gdb-patches

On Fri, 24 Sep 2010 00:37:09 +0200, Jan Kratochvil wrote:
> > +      while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
> 
> The type can be opaque and TYPE_TARGET_TYPE is then NULL.  Opaque type should
> not be possible to be produced for an array element but some `error' call
> would be nice there.

Pleas discard this comment, there is always at least a reference to
builtin_void.


Sorry,
Jan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  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
  2010-09-24 18:36   ` Ken Werner
  2 siblings, 1 reply; 12+ messages in thread
From: Joel Brobecker @ 2010-09-24 16:27 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Ken Werner, gdb-patches

> 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 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'?

> > +	make_cv_type (1, TYPE_VOLATILE (el_type), el_type, 0);
>                                                            ^ NULL?
> I would find NULL for a pointer parameter more readable.

I agree.

-- 
Joel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  2010-09-24 16:27   ` Joel Brobecker
@ 2010-09-24 16:40     ` Pedro Alves
  2010-09-24 23:00       ` Joel Brobecker
  0 siblings, 1 reply; 12+ messages in thread
From: Pedro Alves @ 2010-09-24 16:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker, Jan Kratochvil, Ken Werner

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  2010-09-24  4:50 ` Jan Kratochvil
  2010-09-24 15:38   ` Jan Kratochvil
  2010-09-24 16:27   ` Joel Brobecker
@ 2010-09-24 18:36   ` Ken Werner
  2010-10-05 18:25     ` Ulrich Weigand
  2 siblings, 1 reply; 12+ messages in thread
From: Ken Werner @ 2010-09-24 18:36 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

[-- Attachment #1: Type: Text/Plain, Size: 1593 bytes --]

On Friday, September 24, 2010 12:37:09 am Jan Kratochvil wrote:
> On Wed, 15 Sep 2010 19:20:37 +0200, Ken Werner wrote:
> > The attached patch changes the dwarf parsing of const types. In case the
> > const qualifier is applied to an array type, the element type is so
> > qualified, not the array type. Comments are welcome.
> 
> 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.
> 
> It is questionable whether it gets accepted and fixed by GCC and whether
> you would like it then fixed in GDB even for older GCCs and non-GCC
> compilers.
> 
> I believe besides TYPE_CODE_ARRAY the same logic should be applied even to
> all the fields of TYPE_CODE_STRUCT and TYPE_CODE_UNION (excluding the
> static fields).  While ISO C99 does not say so (or does?) GCC behaves
> correctly:

C99 is pretty clear for const arrays but structs and unions seem to be 
different. Section 6.5.2.3 says that the result of the . and -> operators have 
the const version of the type. So, in that case we probably don't want to copy 
the type in the dwarf reader but alter the result types in case of field 
access.

> I would find this patch OK even if it fixes only the TYPE_CODE_ARRAY.
Thanks for reviewing. I've changed the last make_cv_type argument to NULL and 
attached a new version of that patch, OK to apply?

> > +	make_cv_type (1, TYPE_VOLATILE (el_type), el_type, 0);
> 
>                                                            ^ NULL?
> I would find NULL for a pointer parameter more readable.
Fixed.

Regards
Ken

[-- Attachment #2: const_array.patch --]
[-- Type: text/x-patch, Size: 4689 bytes --]

ChangeLog:

2010-09-24  Ken Werner  <ken.werner@de.ibm.com>

	* gdb/dwarf2read.c (read_tag_const_type): Handle const arrays.

testsuite/ChangeLog:

2010-09-24  Ken Werner  <ken.werner@de.ibm.com>

	* gdb.base/constvars.c (logical, lugged, luck, lunar, lumen, lurk,
	lush, lynx) New constant.
	* gdb.base/constvars.exp: Test const array types.
	* gdb.dwarf2/dw2-strp.exp: Add const qualifier for ptype tests.


Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.460
diff -p -u -r1.460 dwarf2read.c
--- gdb/dwarf2read.c	22 Sep 2010 19:22:44 -0000	1.460
+++ gdb/dwarf2read.c	24 Sep 2010 15:17:02 -0000
@@ -7632,6 +7632,29 @@ read_tag_const_type (struct die_info *di
   if (cv_type)
     return cv_type;
 
+  /* In case the const qualifier is applied to an array type, the element type
+     is so qualified, not the array type (section 6.7.3 of C99).  */
+  if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
+    {
+      struct type *el_type, *inner_array;
+
+      base_type = copy_type (base_type);
+      inner_array = base_type;
+
+      while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
+	{
+	  TYPE_TARGET_TYPE (inner_array) =
+	    copy_type (TYPE_TARGET_TYPE (inner_array));
+	  inner_array = TYPE_TARGET_TYPE (inner_array);
+	}
+
+      el_type = TYPE_TARGET_TYPE (inner_array);
+      TYPE_TARGET_TYPE (inner_array) =
+	make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
+
+      return set_die_type (die, base_type, cu);;
+    }
+
   cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
   return set_die_type (die, cv_type, cu);
 }
Index: gdb/testsuite/gdb.base/constvars.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/constvars.c,v
retrieving revision 1.4
diff -p -u -r1.4 constvars.c
--- gdb/testsuite/gdb.base/constvars.c	12 Nov 2009 19:35:26 -0000	1.4
+++ gdb/testsuite/gdb.base/constvars.c	24 Sep 2010 15:17:02 -0000
@@ -84,6 +84,16 @@ main (void)
   float          *const   lissome   = &leeway;
   double         *const   locust    = &legacy;
 
+  /* constant arrays */
+  const char logical[2] = {laconic, laconic};
+  const unsigned char lugged[2] = {laggard, laggard};
+  const short luck[2] = {lagoon, lagoon};
+  const unsigned short lunar[2] = {laity, laity};
+  const long lumen[2] = {lambent, lambent};
+  const unsigned long lurk[2] = {laminated, laminated};
+  const float lush[2] = {lampoon, lampoon};
+  const double lynx[2] = {languid, languid};
+
   /* volatile variables */
 
   volatile char vox = 'X';
Index: gdb/testsuite/gdb.base/constvars.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/constvars.exp,v
retrieving revision 1.23
diff -p -u -r1.23 constvars.exp
--- gdb/testsuite/gdb.base/constvars.exp	24 May 2010 22:03:59 -0000	1.23
+++ gdb/testsuite/gdb.base/constvars.exp	24 Sep 2010 15:17:02 -0000
@@ -253,6 +253,16 @@ proc do_constvar_tests {} {
     gdb_test "ptype locust" "type = double \\* const"
 
     local_compiler_xfail_check
+    gdb_test "ptype logical" "type = const char \\\[2\\\]"
+    gdb_test "ptype lugged" "type = const unsigned char \\\[2\\\]"
+    gdb_test "ptype luck" "type = const short( int)? \\\[2\\\]"
+    gdb_test "ptype lunar" "type = const (unsigned short|short unsigned)( int)? \\\[2\\\]"
+    gdb_test "ptype lumen" "type = const long( int)? \\\[2\\\]"
+    gdb_test "ptype lurk" "type = const (unsigned long|long unsigned)( int)? \\\[2\\\]"
+    gdb_test "ptype lush" "type = const float \\\[2\\\]"
+    gdb_test "ptype lynx" "type = const double \\\[2\\\]"
+
+    local_compiler_xfail_check
     local_compiler_xfail_check_2
     gdb_test "ptype crass" "type = struct crass \{\[\r\n\]+\[\ \t\]+char \\* const ptr;\[\r\n\]+\}"
     local_compiler_xfail_check
Index: gdb/testsuite/gdb.dwarf2/dw2-strp.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.dwarf2/dw2-strp.exp,v
retrieving revision 1.4
diff -p -u -r1.4 dw2-strp.exp
--- gdb/testsuite/gdb.dwarf2/dw2-strp.exp	1 Jan 2010 07:32:02 -0000	1.4
+++ gdb/testsuite/gdb.dwarf2/dw2-strp.exp	24 Sep 2010 15:17:02 -0000
@@ -49,7 +49,7 @@ gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
 
 gdb_test "p a_string" " = \"hello world!\\\\n\""
-gdb_test "ptype a_string" "type = char \\\[14\\\]"
+gdb_test "ptype a_string" "type = const char \\\[14\\\]"
 
 gdb_test "p a_string2" " = \"hello world2\\\\n\""
-gdb_test "ptype a_string2" "type = char \\\[14\\\]"
+gdb_test "ptype a_string2" "type = const char \\\[14\\\]"

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  2010-09-24 16:40     ` Pedro Alves
@ 2010-09-24 23:00       ` Joel Brobecker
  0 siblings, 0 replies; 12+ messages in thread
From: Joel Brobecker @ 2010-09-24 23:00 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Jan Kratochvil, Ken Werner

> I disagree:

I certainly understimated the consequences of this little distinction
(I haven't used C++ 1994 or 1995)!

> 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 see you point. Perhaps this should be clarified at the DWARF level
as well?

> 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):

Ugh!

-- 
Joel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  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
  0 siblings, 2 replies; 12+ messages in thread
From: Ulrich Weigand @ 2010-10-05 18:25 UTC (permalink / raw)
  To: Ken Werner; +Cc: Jan Kratochvil, gdb-patches, brobecker, pedro

Ken Werner wrote:

> +      return set_die_type (die, base_type, cu);;

Extra semicolon.

>      local_compiler_xfail_check
> +    gdb_test "ptype logical" "type = const char \\\[2\\\]"
> +    gdb_test "ptype lugged" "type = const unsigned char \\\[2\\\]"
> +    gdb_test "ptype luck" "type = const short( int)? \\\[2\\\]"
> +    gdb_test "ptype lunar" "type = const (unsigned short|short unsigned)( int)? \\\[2\\\]"
> +    gdb_test "ptype lumen" "type = const long( int)? \\\[2\\\]"
> +    gdb_test "ptype lurk" "type = const (unsigned long|long unsigned)( int)? \\\[2\\\]"
> +    gdb_test "ptype lush" "type = const float \\\[2\\\]"
> +    gdb_test "ptype lynx" "type = const double \\\[2\\\]"

Do we need the local_compiler_xfail_check for these tests?  If so, we'd need
it before each of the tests; if not, we don't need it at all ...

Otherwise, this patch looks good to me.

Joel, if I followed the discussion correctly, you still had some concerns;
have they been resolved now?

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  2010-10-05 18:25     ` Ulrich Weigand
@ 2010-10-05 18:43       ` Joel Brobecker
  2010-10-06 15:38       ` Ken Werner
  1 sibling, 0 replies; 12+ messages in thread
From: Joel Brobecker @ 2010-10-05 18:43 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: Ken Werner, Jan Kratochvil, gdb-patches, pedro

> Joel, if I followed the discussion correctly, you still had some concerns;
> have they been resolved now?

Yep, no concern at all on my end anymore. :)

-- 
Joel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  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
  1 sibling, 1 reply; 12+ messages in thread
From: Ken Werner @ 2010-10-06 15:38 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: Jan Kratochvil, brobecker, pedro, gdb-patches

[-- Attachment #1: Type: Text/Plain, Size: 574 bytes --]

On Tuesday, October 05, 2010 8:25:05 pm Ulrich Weigand wrote:
> Ken Werner wrote:
> > +      return set_die_type (die, base_type, cu);;
> 
> Extra semicolon.

Fixed.

> Do we need the local_compiler_xfail_check for these tests?  If so, we'd
> need it before each of the tests; if not, we don't need it at all ...

Good point. Since const seems to be broken with gcc 2 -gstabs for primitives I 
guess this is also the case for arrays. Therefore I've put the 
local_compiler_xfail_check in front of each test.

Attached is a new version of the patch.
Ok to apply?

Thanks
Ken

[-- Attachment #2: const_array.patch --]
[-- Type: text/x-patch, Size: 4907 bytes --]

ChangeLog:

2010-10-06  Ken Werner  <ken.werner@de.ibm.com>

	* gdb/dwarf2read.c (read_tag_const_type): Handle const arrays.

testsuite/ChangeLog:

2010-10-06  Ken Werner  <ken.werner@de.ibm.com>

	* gdb.base/constvars.c (logical, lugged, luck, lunar, lumen, lurk,
	lush, lynx) New constant.
	* gdb.base/constvars.exp: Test const array types.
	* gdb.dwarf2/dw2-strp.exp: Add const qualifier for ptype tests.


Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.468
diff -p -u -r1.468 dwarf2read.c
--- gdb/dwarf2read.c	5 Oct 2010 03:10:28 -0000	1.468
+++ gdb/dwarf2read.c	6 Oct 2010 11:49:33 -0000
@@ -7607,6 +7607,29 @@ read_tag_const_type (struct die_info *di
   if (cv_type)
     return cv_type;
 
+  /* In case the const qualifier is applied to an array type, the element type
+     is so qualified, not the array type (section 6.7.3 of C99).  */
+  if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
+    {
+      struct type *el_type, *inner_array;
+
+      base_type = copy_type (base_type);
+      inner_array = base_type;
+
+      while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
+	{
+	  TYPE_TARGET_TYPE (inner_array) =
+	    copy_type (TYPE_TARGET_TYPE (inner_array));
+	  inner_array = TYPE_TARGET_TYPE (inner_array);
+	}
+
+      el_type = TYPE_TARGET_TYPE (inner_array);
+      TYPE_TARGET_TYPE (inner_array) =
+	make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
+
+      return set_die_type (die, base_type, cu);
+    }
+
   cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
   return set_die_type (die, cv_type, cu);
 }
Index: gdb/testsuite/gdb.base/constvars.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/constvars.c,v
retrieving revision 1.4
diff -p -u -r1.4 constvars.c
--- gdb/testsuite/gdb.base/constvars.c	12 Nov 2009 19:35:26 -0000	1.4
+++ gdb/testsuite/gdb.base/constvars.c	6 Oct 2010 11:49:33 -0000
@@ -84,6 +84,16 @@ main (void)
   float          *const   lissome   = &leeway;
   double         *const   locust    = &legacy;
 
+  /* constant arrays */
+  const char logical[2] = {laconic, laconic};
+  const unsigned char lugged[2] = {laggard, laggard};
+  const short luck[2] = {lagoon, lagoon};
+  const unsigned short lunar[2] = {laity, laity};
+  const long lumen[2] = {lambent, lambent};
+  const unsigned long lurk[2] = {laminated, laminated};
+  const float lush[2] = {lampoon, lampoon};
+  const double lynx[2] = {languid, languid};
+
   /* volatile variables */
 
   volatile char vox = 'X';
Index: gdb/testsuite/gdb.base/constvars.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/constvars.exp,v
retrieving revision 1.23
diff -p -u -r1.23 constvars.exp
--- gdb/testsuite/gdb.base/constvars.exp	24 May 2010 22:03:59 -0000	1.23
+++ gdb/testsuite/gdb.base/constvars.exp	6 Oct 2010 11:49:33 -0000
@@ -253,6 +253,23 @@ proc do_constvar_tests {} {
     gdb_test "ptype locust" "type = double \\* const"
 
     local_compiler_xfail_check
+    gdb_test "ptype logical" "type = const char \\\[2\\\]"
+    local_compiler_xfail_check
+    gdb_test "ptype lugged" "type = const unsigned char \\\[2\\\]"
+    local_compiler_xfail_check
+    gdb_test "ptype luck" "type = const short( int)? \\\[2\\\]"
+    local_compiler_xfail_check
+    gdb_test "ptype lunar" "type = const (unsigned short|short unsigned)( int)? \\\[2\\\]"
+    local_compiler_xfail_check
+    gdb_test "ptype lumen" "type = const long( int)? \\\[2\\\]"
+    local_compiler_xfail_check
+    gdb_test "ptype lurk" "type = const (unsigned long|long unsigned)( int)? \\\[2\\\]"
+    local_compiler_xfail_check
+    gdb_test "ptype lush" "type = const float \\\[2\\\]"
+    local_compiler_xfail_check
+    gdb_test "ptype lynx" "type = const double \\\[2\\\]"
+
+    local_compiler_xfail_check
     local_compiler_xfail_check_2
     gdb_test "ptype crass" "type = struct crass \{\[\r\n\]+\[\ \t\]+char \\* const ptr;\[\r\n\]+\}"
     local_compiler_xfail_check
Index: gdb/testsuite/gdb.dwarf2/dw2-strp.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.dwarf2/dw2-strp.exp,v
retrieving revision 1.4
diff -p -u -r1.4 dw2-strp.exp
--- gdb/testsuite/gdb.dwarf2/dw2-strp.exp	1 Jan 2010 07:32:02 -0000	1.4
+++ gdb/testsuite/gdb.dwarf2/dw2-strp.exp	6 Oct 2010 11:49:33 -0000
@@ -49,7 +49,7 @@ gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
 
 gdb_test "p a_string" " = \"hello world!\\\\n\""
-gdb_test "ptype a_string" "type = char \\\[14\\\]"
+gdb_test "ptype a_string" "type = const char \\\[14\\\]"
 
 gdb_test "p a_string2" " = \"hello world2\\\\n\""
-gdb_test "ptype a_string2" "type = char \\\[14\\\]"
+gdb_test "ptype a_string2" "type = const char \\\[14\\\]"

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  2010-10-06 15:38       ` Ken Werner
@ 2010-10-06 15:55         ` Ulrich Weigand
  2010-10-06 16:18           ` Ken Werner
  0 siblings, 1 reply; 12+ messages in thread
From: Ulrich Weigand @ 2010-10-06 15:55 UTC (permalink / raw)
  To: Ken Werner; +Cc: Jan Kratochvil, brobecker, pedro, gdb-patches

Ken Werner wrote:

> ChangeLog:
> 
> 2010-10-06  Ken Werner  <ken.werner@de.ibm.com>
> 
> 	* gdb/dwarf2read.c (read_tag_const_type): Handle const arrays.
> 
> testsuite/ChangeLog:
> 
> 2010-10-06  Ken Werner  <ken.werner@de.ibm.com>
> 
> 	* gdb.base/constvars.c (logical, lugged, luck, lunar, lumen, lurk,
> 	lush, lynx) New constant.
> 	* gdb.base/constvars.exp: Test const array types.
> 	* gdb.dwarf2/dw2-strp.exp: Add const qualifier for ptype tests.

This is OK.

Thanks,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch] const array types
  2010-10-06 15:55         ` Ulrich Weigand
@ 2010-10-06 16:18           ` Ken Werner
  0 siblings, 0 replies; 12+ messages in thread
From: Ken Werner @ 2010-10-06 16:18 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: Jan Kratochvil, brobecker, pedro, gdb-patches

On Wednesday, October 06, 2010 5:55:31 pm Ulrich Weigand wrote:
> Ken Werner wrote:
> > ChangeLog:
> > 
> > 2010-10-06  Ken Werner  <ken.werner@de.ibm.com>
> > 
> > 	* gdb/dwarf2read.c (read_tag_const_type): Handle const arrays.
> > 
> > testsuite/ChangeLog:
> > 
> > 2010-10-06  Ken Werner  <ken.werner@de.ibm.com>
> > 
> > 	* gdb.base/constvars.c (logical, lugged, luck, lunar, lumen, lurk,
> > 	lush, lynx) New constant.
> > 	* gdb.base/constvars.exp: Test const array types.
> > 	* gdb.dwarf2/dw2-strp.exp: Add const qualifier for ptype tests.
> 
> This is OK.

I've checked this patch in now.
http://sourceware.org/ml/gdb-cvs/2010-10/msg00037.html

Regards
Ken Werner

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-10-06 16:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-15 19:32 [patch] const array types 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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).