diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3031dc4bc6..e1d6cb07fa 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2010-10-06 Ken Werner + + * dwarf2read.c (read_tag_const_type): Handle const arrays. + 2010-10-06 Doug Evans Create subdir data-directory. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index bf36e01e11..02304cbeb4 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -7607,6 +7607,29 @@ read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) 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); } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index ded8355d92..3686c823ab 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2010-10-06 Ken Werner + + * 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. + 2010-10-06 Doug Evans * gdb.base/catch-syscall.exp (do_syscall_tests): Update location diff --git a/gdb/testsuite/gdb.base/constvars.c b/gdb/testsuite/gdb.base/constvars.c index 9c11c386b6..289b8e747c 100644 --- a/gdb/testsuite/gdb.base/constvars.c +++ b/gdb/testsuite/gdb.base/constvars.c @@ -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'; diff --git a/gdb/testsuite/gdb.base/constvars.exp b/gdb/testsuite/gdb.base/constvars.exp index 4d698d8115..375f360c91 100644 --- a/gdb/testsuite/gdb.base/constvars.exp +++ b/gdb/testsuite/gdb.base/constvars.exp @@ -252,6 +252,23 @@ proc do_constvar_tests {} { local_compiler_xfail_check 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\]+\}" diff --git a/gdb/testsuite/gdb.dwarf2/dw2-strp.exp b/gdb/testsuite/gdb.dwarf2/dw2-strp.exp index 3895204158..536f773de8 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-strp.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-strp.exp @@ -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\\\]"