Recognize names of array types
authorTom Tromey <tromey@adacore.com>
Wed, 4 Nov 2020 15:49:16 +0000 (08:49 -0700)
committerTom Tromey <tromey@adacore.com>
Wed, 4 Nov 2020 15:49:19 +0000 (08:49 -0700)
With -fgnat-encodings=minimal, Gnat will emit DW_TAG_array_type that
has a name -- and this is the only time the name is emitted for the
type.  (For comparison, in C a typedef would be emitted in this
situation.)

This patch changes gdb to recognize the name of an array type.  This
is limited to Ada, to avoid any potential problems if some rogue DWARF
happens to name an array type in some other language, and to avoid
loading unnecessary partial DIEs.

gdb/ChangeLog
2020-11-04  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.c (add_partial_symbol, process_die):
Handle DW_TAG_array_type.
(is_type_tag_for_partial): Add "lang" parameter.
(load_partial_dies, new_symbol): Handle DW_TAG_array_type.

gdb/testsuite/ChangeLog
2020-11-04  Tom Tromey  <tromey@adacore.com>

* gdb.ada/tick_length_array_enum_idx.exp: Add ptype test.
* gdb.ada/tick_length_array_enum_idx/foo_n207_004.adb
(PT_Full): New variable.
* gdb.ada/tick_length_array_enum_idx/pck.adb
(Full_PT): New type.

gdb/ChangeLog
gdb/dwarf2/read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp
gdb/testsuite/gdb.ada/tick_length_array_enum_idx/foo_n207_004.adb
gdb/testsuite/gdb.ada/tick_length_array_enum_idx/pck.ads

index d4ea435ff5c3f5007cfadaff5f2f74a1887dbe28..913b7ecc5e15958d3a6d941d12eb8c343b3d5cb0 100644 (file)
@@ -1,3 +1,10 @@
+2020-11-04  Tom Tromey  <tromey@adacore.com>
+
+       * dwarf2/read.c (add_partial_symbol, process_die):
+       Handle DW_TAG_array_type.
+       (is_type_tag_for_partial): Add "lang" parameter.
+       (load_partial_dies, new_symbol): Handle DW_TAG_array_type.
+
 2020-11-04  Tom Tromey  <tromey@adacore.com>
 
        * ada-lang.c (ada_value_slice_from_ptr): Use bit size.
index a41712765d679636546b5cb81abce6f2eeeec913..57db648061e538434fe08b2e574f214131ef281b 100644 (file)
@@ -8575,6 +8575,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          where = psymbol_placement::STATIC;
        }
       break;
+    case DW_TAG_array_type:
     case DW_TAG_typedef:
     case DW_TAG_base_type:
     case DW_TAG_subrange_type:
@@ -10202,7 +10203,6 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
        read them on-demand through read_type_die.  */
     case DW_TAG_subroutine_type:
     case DW_TAG_set_type:
-    case DW_TAG_array_type:
     case DW_TAG_pointer_type:
     case DW_TAG_ptr_to_member_type:
     case DW_TAG_reference_type:
@@ -10210,6 +10210,13 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_string_type:
       break;
 
+    case DW_TAG_array_type:
+      /* We only need to handle this case for Ada -- in other
+        languages, it's normal for the compiler to emit a typedef
+        instead.  */
+      if (cu->language != language_ada)
+       break;
+      /* FALLTHROUGH */
     case DW_TAG_base_type:
     case DW_TAG_subrange_type:
     case DW_TAG_typedef:
@@ -18984,20 +18991,27 @@ read_full_die (const struct die_reader_specs *reader,
    symbol for.  */
 
 static int
-is_type_tag_for_partial (int tag)
+is_type_tag_for_partial (int tag, enum language lang)
 {
   switch (tag)
     {
 #if 0
     /* Some types that would be reasonable to generate partial symbols for,
-       that we don't at present.  */
-    case DW_TAG_array_type:
+       that we don't at present.  Note that normally this does not
+       matter, mainly because C compilers don't give names to these
+       types, but instead emit DW_TAG_typedef.  */
     case DW_TAG_file_type:
     case DW_TAG_ptr_to_member_type:
     case DW_TAG_set_type:
     case DW_TAG_string_type:
     case DW_TAG_subroutine_type:
 #endif
+
+      /* GNAT may emit an array with a name, but no typedef, so we
+        need to make a symbol in this case.  */
+    case DW_TAG_array_type:
+      return lang == language_ada;
+
     case DW_TAG_base_type:
     case DW_TAG_class_type:
     case DW_TAG_interface_type:
@@ -19091,7 +19105,7 @@ load_partial_dies (const struct die_reader_specs *reader,
         later variables referencing them via DW_AT_specification (for
         static members).  */
       if (!load_all
-         && !is_type_tag_for_partial (abbrev->tag)
+         && !is_type_tag_for_partial (abbrev->tag, cu->language)
          && abbrev->tag != DW_TAG_constant
          && abbrev->tag != DW_TAG_enumerator
          && abbrev->tag != DW_TAG_subprogram
@@ -19135,6 +19149,7 @@ load_partial_dies (const struct die_reader_specs *reader,
          && pdi.is_declaration == 0
          && ((pdi.tag == DW_TAG_typedef && !pdi.has_children)
              || pdi.tag == DW_TAG_base_type
+             || pdi.tag == DW_TAG_array_type
              || pdi.tag == DW_TAG_subrange_type))
        {
          if (building_psymtab && pdi.raw_name != NULL)
@@ -22028,6 +22043,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
          SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
          list_to_add = cu->list_in_scope;
          break;
+       case DW_TAG_array_type:
        case DW_TAG_base_type:
        case DW_TAG_subrange_type:
          SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
index fe97b070cd45aa12736fba446ede2b05ac13129e..745413a2e7a8074026c2b6e835191bc9f4357529 100644 (file)
@@ -1,3 +1,11 @@
+2020-11-04  Tom Tromey  <tromey@adacore.com>
+
+       * gdb.ada/tick_length_array_enum_idx.exp: Add ptype test.
+       * gdb.ada/tick_length_array_enum_idx/foo_n207_004.adb
+       (PT_Full): New variable.
+       * gdb.ada/tick_length_array_enum_idx/pck.adb
+       (Full_PT): New type.
+
 2020-11-04  Tom Tromey  <tromey@adacore.com>
 
        * gdb.ada/array_of_variant.exp: New file.
index 52715cf68e17906b493943db356175b320572bdd..6dd01aca2b63ee3245c1fa603ad5faa6ac34fe46 100644 (file)
@@ -41,3 +41,4 @@ gdb_test "ptype vars'length" "type = <$decimal-byte integer>"
 gdb_test "ptype full_table'length" "type = <$decimal-byte integer>"
 gdb_test "ptype primary_table'length" "type = <$decimal-byte integer>"
 gdb_test "ptype variable_table'length" "type = <$decimal-byte integer>"
+gdb_test "ptype full_pt'length" "type = <$decimal-byte integer>"
index 934a7f8ae853ede76c88c129ae0eace5f2dd823c..0b2584fa73c8d56058d5ddbff23d569532a40648 100644 (file)
@@ -20,9 +20,11 @@ procedure Foo_n207_004 is
    Prim : Primary_Table := (True, False, False);
    Cold : Variable_Table := (Green => False, Blue => True, White => True);
    Vars : Variable_Table :=  New_Variable_Table (Low => Red, High => Green);
+   PT_Full : Full_PT := (False, True, False, True, False);
 begin
    Do_Nothing (Full'Address);  -- STOP
    Do_Nothing (Prim'Address);
    Do_Nothing (Cold'Address);
    Do_Nothing (Vars'Address);
+   Do_Nothing (PT_Full'Address);
 end Foo_n207_004;
index 112caf1f651c6826906deab0cf0d913cf62d70ab..461bee5377a8f7c186b2c3aefc61395bdca3feb9 100644 (file)
@@ -21,6 +21,9 @@ package Pck is
    type Primary_Table is array (Color range Red .. Blue) of Boolean;
    type Variable_Table is array (Color range <>) of Boolean;
 
+   type Full_PT is array (Color) of Boolean;
+   pragma Pack (Full_PT);
+
    function New_Variable_Table (Low: Color; High: Color) return Variable_Table;
 
    procedure Do_Nothing (A : System.Address);
This page took 0.048573 seconds and 4 git commands to generate.