]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/dwarf2/read.c
gdb: add field::type / field::set_type
[thirdparty/binutils-gdb.git] / gdb / dwarf2 / read.c
index 4724738363be70b296cad1ff850d6717b4ff957b..52feff0b23d73c54626d046a593524fb919eaa27 100644 (file)
@@ -3068,9 +3068,10 @@ dwarf2_read_gdb_index
   offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
   struct dwz_file *dwz;
   struct objfile *objfile = per_objfile->objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
   gdb::array_view<const gdb_byte> main_index_contents
-    = get_gdb_index_contents (objfile, per_objfile->per_bfd);
+    = get_gdb_index_contents (objfile, per_bfd);
 
   if (main_index_contents.empty ())
     return 0;
@@ -3089,7 +3090,7 @@ dwarf2_read_gdb_index
 
   /* If there is a .dwz file, read it so we can get its CU list as
      well.  */
-  dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+  dwz = dwarf2_get_dwz_file (per_bfd);
   if (dwz != NULL)
     {
       struct mapped_index dwz_map;
@@ -3114,29 +3115,33 @@ dwarf2_read_gdb_index
        }
     }
 
-  create_cus_from_index (per_objfile->per_bfd, cu_list, cu_list_elements,
-                        dwz_list, dwz_list_elements);
+  create_cus_from_index (per_bfd, cu_list, cu_list_elements, dwz_list,
+                        dwz_list_elements);
 
   if (types_list_elements)
     {
       /* We can only handle a single .debug_types when we have an
         index.  */
-      if (per_objfile->per_bfd->types.size () != 1)
+      if (per_bfd->types.size () != 1)
        return 0;
 
-      dwarf2_section_info *section = &per_objfile->per_bfd->types[0];
+      dwarf2_section_info *section = &per_bfd->types[0];
 
-      create_signatured_type_table_from_index (per_objfile->per_bfd,
-                                              section, types_list,
+      create_signatured_type_table_from_index (per_bfd, section, types_list,
                                               types_list_elements);
     }
 
   create_addrmap_from_index (per_objfile, map.get ());
 
-  per_objfile->per_bfd->index_table = std::move (map);
-  per_objfile->per_bfd->using_index = 1;
-  per_objfile->per_bfd->quick_file_names_table =
-    create_quick_file_names_table (per_objfile->per_bfd->all_comp_units.size ());
+  per_bfd->index_table = std::move (map);
+  per_bfd->using_index = 1;
+  per_bfd->quick_file_names_table =
+    create_quick_file_names_table (per_bfd->all_comp_units.size ());
+
+  /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
+     objfiles using the same BFD.  */
+  gdb_assert (per_bfd->partial_symtabs == nullptr);
+  per_bfd->partial_symtabs = objfile->partial_symtabs;
 
   return 1;
 }
@@ -5205,6 +5210,7 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
   std::unique_ptr<mapped_debug_names> map (new mapped_debug_names);
   mapped_debug_names dwz_map;
   struct objfile *objfile = per_objfile->objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
   if (!read_debug_names_from_section (objfile, objfile_name (objfile),
                                      &per_objfile->per_bfd->debug_names, *map))
@@ -5216,7 +5222,7 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
 
   /* If there is a .dwz file, read it so we can get its CU list as
      well.  */
-  dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+  dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
   if (dwz != NULL)
     {
       if (!read_debug_names_from_section (objfile,
@@ -5229,29 +5235,33 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
        }
     }
 
-  create_cus_from_debug_names (per_objfile->per_bfd, *map, dwz_map);
+  create_cus_from_debug_names (per_bfd, *map, dwz_map);
 
   if (map->tu_count != 0)
     {
       /* We can only handle a single .debug_types when we have an
         index.  */
-      if (per_objfile->per_bfd->types.size () != 1)
+      if (per_bfd->types.size () != 1)
        return false;
 
-      dwarf2_section_info *section = &per_objfile->per_bfd->types[0];
+      dwarf2_section_info *section = &per_bfd->types[0];
 
       create_signatured_type_table_from_debug_names
-       (per_objfile, *map, section, &per_objfile->per_bfd->abbrev);
+       (per_objfile, *map, section, &per_bfd->abbrev);
     }
 
-  create_addrmap_from_aranges (per_objfile,
-                              &per_objfile->per_bfd->debug_aranges);
+  create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges);
 
-  per_objfile->per_bfd->debug_names_table = std::move (map);
-  per_objfile->per_bfd->using_index = 1;
-  per_objfile->per_bfd->quick_file_names_table =
+  per_bfd->debug_names_table = std::move (map);
+  per_bfd->using_index = 1;
+  per_bfd->quick_file_names_table =
     create_quick_file_names_table (per_objfile->per_bfd->all_comp_units.size ());
 
+  /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
+     objfiles using the same BFD.  */
+  gdb_assert (per_bfd->partial_symtabs == nullptr);
+  per_bfd->partial_symtabs = objfile->partial_symtabs;
+
   return true;
 }
 
@@ -5972,6 +5982,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
   if (per_bfd->debug_names_table != nullptr)
     {
       *index_kind = dw_index_kind::DEBUG_NAMES;
+      per_objfile->objfile->partial_symtabs = per_bfd->partial_symtabs;
       per_objfile->resize_symtabs ();
       return true;
     }
@@ -5981,6 +5992,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
   if (per_bfd->index_table != nullptr)
     {
       *index_kind = dw_index_kind::GDB_INDEX;
+      per_objfile->objfile->partial_symtabs = per_bfd->partial_symtabs;
       per_objfile->resize_symtabs ();
       return true;
     }
@@ -8146,6 +8158,9 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
            case DW_TAG_subprogram:
            case DW_TAG_inlined_subroutine:
              add_partial_subprogram (pdi, lowpc, highpc, set_addrmap, cu);
+             if (cu->language == language_cplus)
+               scan_partial_symbols (pdi->die_child, lowpc, highpc,
+                                     set_addrmap, cu);
              break;
            case DW_TAG_constant:
            case DW_TAG_variable:
@@ -9489,7 +9504,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
        ((struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field)));
 
       /* Put the discriminant at index 0.  */
-      TYPE_FIELD_TYPE (type, 0) = field_type;
+      type->field (0).set_type (field_type);
       TYPE_FIELD_ARTIFICIAL (type, 0) = 1;
       TYPE_FIELD_NAME (type, 0) = "<<discriminant>>";
       SET_FIELD_BITPOS (type->field (0), bit_offset);
@@ -9508,7 +9523,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
                              name);
       struct type *dataless_type = init_type (objfile, TYPE_CODE_VOID, 0,
                                              dataless_name);
-      TYPE_FIELD_TYPE (type, 2) = dataless_type;
+      type->field (2).set_type (dataless_type);
       /* NAME points into the original discriminant name, which
         already has the correct lifetime.  */
       TYPE_FIELD_NAME (type, 2) = name;
@@ -14524,7 +14539,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       /* Data member other than a C++ static data member.  */
 
       /* Get type of field.  */
-      fp->type = die_type (die, cu);
+      fp->set_type (die_type (die, cu));
 
       SET_FIELD_BITPOS (*fp, 0);
 
@@ -14578,7 +14593,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
                     the bit field must be inferred from the type
                     attribute of the data member containing the
                     bit field.  */
-                 anonymous_size = TYPE_LENGTH (fp->type);
+                 anonymous_size = TYPE_LENGTH (fp->type ());
                }
              SET_FIELD_BITPOS (*fp,
                                (FIELD_BITPOS (*fp)
@@ -14644,7 +14659,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       /* The name is already allocated along with this objfile, so we don't
         need to duplicate it for the type.  */
       SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
-      FIELD_TYPE (*fp) = die_type (die, cu);
+      fp->set_type (die_type (die, cu));
       FIELD_NAME (*fp) = fieldname;
     }
   else if (die->tag == DW_TAG_inheritance)
@@ -14652,8 +14667,8 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       /* C++ base class field.  */
       handle_data_member_location (die, cu, fp);
       FIELD_BITSIZE (*fp) = 0;
-      FIELD_TYPE (*fp) = die_type (die, cu);
-      FIELD_NAME (*fp) = fp->type->name ();
+      fp->set_type (die_type (die, cu));
+      FIELD_NAME (*fp) = fp->type ()->name ();
     }
   else
     gdb_assert_not_reached ("missing case in dwarf2_add_field");
@@ -17212,7 +17227,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
       /* TYPE_FIELD_TYPE must never be NULL.  Pre-fill the array to ensure it
         even if we error out during the parameters reading below.  */
       for (iparams = 0; iparams < nparams; iparams++)
-       TYPE_FIELD_TYPE (ftype, iparams) = void_type;
+       ftype->field (iparams).set_type (void_type);
 
       iparams = 0;
       child_die = die->child;
@@ -17269,7 +17284,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
                                             arg_type, 0);
                }
 
-             TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
+             ftype->field (iparams).set_type (arg_type);
              iparams++;
            }
          child_die = child_die->sibling;
@@ -18246,7 +18261,8 @@ load_partial_dies (const struct die_reader_specs *reader,
       if (!load_all
          && cu->language == language_cplus
          && parent_die != NULL
-         && parent_die->tag == DW_TAG_subprogram)
+         && parent_die->tag == DW_TAG_subprogram
+         && abbrev->tag != DW_TAG_inlined_subroutine)
        {
          info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
          continue;
@@ -20040,6 +20056,15 @@ private:
   /* The last file a line number was recorded for.  */
   struct subfile *m_last_subfile = NULL;
 
+  /* The address of the last line entry.  */
+  CORE_ADDR m_last_address;
+
+  /* Set to true when a previous line at the same address (using
+     m_last_address) had m_is_stmt true.  This is reset to false when a
+     line entry at a new address (m_address different to m_last_address) is
+     processed.  */
+  bool m_stmt_at_address = false;
+
   /* When true, record the lines we decode.  */
   bool m_currently_recording_lines = false;
 
@@ -20233,14 +20258,34 @@ lnp_state_machine::record_line (bool end_sequence)
       fe->included_p = 1;
       if (m_record_lines_p)
        {
-         if (m_last_subfile != m_cu->get_builder ()->get_current_subfile ()
-             || end_sequence)
+         /* When we switch files we insert an end maker in the first file,
+            switch to the second file and add a new line entry.  The
+            problem is that the end marker inserted in the first file will
+            discard any previous line entries at the same address.  If the
+            line entries in the first file are marked as is-stmt, while
+            the new line in the second file is non-stmt, then this means
+            the end marker will discard is-stmt lines so we can have a
+            non-stmt line.  This means that there are less addresses at
+            which the user can insert a breakpoint.
+
+            To improve this we track the last address in m_last_address,
+            and whether we have seen an is-stmt at this address.  Then
+            when switching files, if we have seen a stmt at the current
+            address, and we are switching to create a non-stmt line, then
+            discard the new line.  */
+         bool file_changed
+           = m_last_subfile != m_cu->get_builder ()->get_current_subfile ();
+         bool ignore_this_line
+           = (file_changed && !end_sequence && m_last_address == m_address
+              && !m_is_stmt && m_stmt_at_address);
+
+         if ((file_changed && !ignore_this_line) || end_sequence)
            {
              dwarf_finish_line (m_gdbarch, m_last_subfile, m_address,
                                 m_currently_recording_lines ? m_cu : nullptr);
            }
 
-         if (!end_sequence)
+         if (!end_sequence && !ignore_this_line)
            {
              bool is_stmt = producer_is_codewarrior (m_cu) || m_is_stmt;
 
@@ -20259,6 +20304,15 @@ lnp_state_machine::record_line (bool end_sequence)
            }
        }
     }
+
+  /* Track whether we have seen any m_is_stmt true at m_address in case we
+     have multiple line table entries all at m_address.  */
+  if (m_last_address != m_address)
+    {
+      m_stmt_at_address = false;
+      m_last_address = m_address;
+    }
+  m_stmt_at_address |= m_is_stmt;
 }
 
 lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
@@ -20278,6 +20332,9 @@ lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
   m_address = gdbarch_adjust_dwarf2_line (arch, 0, 0);
   m_is_stmt = lh->default_is_stmt;
   m_discriminator = 0;
+
+  m_last_address = m_address;
+  m_stmt_at_address = false;
 }
 
 void