Create a typedef for record_line: record_line_ftype.
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 2563418344b033d7cabfb377ef6ccd3ebda9af45..57a2e65246132cf8ce37143d5212ef9c8abae4fc 100644 (file)
@@ -72,8 +72,6 @@
 #include "build-id.h"
 
 #include <fcntl.h>
-#include <string.h>
-#include "gdb_assert.h"
 #include <sys/types.h>
 
 typedef struct symbol *symbolp;
@@ -613,8 +611,8 @@ struct dwarf2_per_cu_data
      However we can enter this file with just a "per_cu" handle.  */
   struct objfile *objfile;
 
-  /* When using partial symbol tables, the 'psymtab' field is active.
-     Otherwise the 'quick' field is active.  */
+  /* When dwarf2_per_objfile->using_index is true, the 'quick' field
+     is active.  Otherwise, the 'psymtab' field is active.  */
   union
   {
     /* The partial symbol table associated with this compilation unit,
@@ -14098,6 +14096,36 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
   return set_die_type (die, type, cu);
 }
 
+/* Add the given cv-qualifiers to the element type of the array.  GCC
+   outputs DWARF type qualifiers that apply to an array, not the
+   element type.  But GDB relies on the array element type to carry
+   the cv-qualifiers.  This mimics section 6.7.3 of the C99
+   specification.  */
+
+static struct type *
+add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
+                  struct type *base_type, int cnst, int voltl)
+{
+  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);
+  cnst |= TYPE_CONST (el_type);
+  voltl |= TYPE_VOLATILE (el_type);
+  TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, NULL);
+
+  return set_die_type (die, base_type, cu);
+}
+
 static struct type *
 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
 {
@@ -14113,25 +14141,7 @@ read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
   /* 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);
-    }
+    return add_array_cv_type (die, cu, base_type, 1, 0);
 
   cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
   return set_die_type (die, cv_type, cu);
@@ -14149,6 +14159,12 @@ read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
   if (cv_type)
     return cv_type;
 
+  /* In case the volatile 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)
+    return add_array_cv_type (die, cu, base_type, 0, 1);
+
   cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
   return set_die_type (die, cv_type, cu);
 }
@@ -17109,7 +17125,9 @@ psymtab_include_file_name (const struct line_header *lh, int file_index,
         include_name = "hello.c"
         dir_name = "."
         DW_AT_comp_dir = comp_dir = "/tmp"
-        DW_AT_name = "./hello.c"  */
+        DW_AT_name = "./hello.c"
+
+      */
 
       if (dir_name != NULL)
        {
@@ -17156,22 +17174,47 @@ noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
   return;
 }
 
+/* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
+   in the line table of subfile SUBFILE.  */
+
+static void
+dwarf_record_line (struct gdbarch *gdbarch, struct subfile *subfile,
+                  unsigned int line, CORE_ADDR address,
+                  record_line_ftype p_record_line)
+{
+  CORE_ADDR addr = gdbarch_addr_bits_remove (gdbarch, address);
+
+  (*p_record_line) (current_subfile, line, addr);
+}
+
+/* Subroutine of dwarf_decode_lines_1 to simplify it.
+   Mark the end of a set of line number records.
+   The arguments are the same as for dwarf_record_line.
+   If SUBFILE is NULL the request is ignored.  */
+
+static void
+dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile,
+                  CORE_ADDR address, record_line_ftype p_record_line)
+{
+  if (subfile != NULL)
+    dwarf_record_line (gdbarch, subfile, 0, address, p_record_line);
+}
+
 /* Subroutine of dwarf_decode_lines to simplify it.
    Process the line number information in LH.  */
 
 static void
 dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
-                     struct dwarf2_cu *cu, struct partial_symtab *pst)
+                     struct dwarf2_cu *cu, const int decode_for_pst_p)
 {
   const gdb_byte *line_ptr, *extended_end;
   const gdb_byte *line_end;
   unsigned int bytes_read, extended_len;
-  unsigned char op_code, extended_op, adj_opcode;
+  unsigned char op_code, extended_op;
   CORE_ADDR baseaddr;
   struct objfile *objfile = cu->objfile;
   bfd *abfd = objfile->obfd;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  const int decode_for_pst_p = (pst != NULL);
   struct subfile *last_subfile = NULL;
   void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
     = record_line;
@@ -17188,11 +17231,8 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
       CORE_ADDR address = 0;
       unsigned int file = 1;
       unsigned int line = 1;
-      unsigned int column = 0;
       int is_stmt = lh->default_is_stmt;
-      int basic_block = 0;
       int end_sequence = 0;
-      CORE_ADDR addr;
       unsigned char op_index = 0;
 
       if (!decode_for_pst_p && lh->num_file_names >= file)
@@ -17223,7 +17263,9 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
 
          if (op_code >= lh->opcode_base)
            {
-             /* Special operand.  */
+             /* Special opcode.  */
+             unsigned char adj_opcode;
+
              adj_opcode = op_code - lh->opcode_base;
              address += (((op_index + (adj_opcode / lh->line_range))
                           / lh->maximum_ops_per_instruction)
@@ -17242,17 +17284,15 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
                    {
                      if (last_subfile != current_subfile)
                        {
-                         addr = gdbarch_addr_bits_remove (gdbarch, address);
-                         if (last_subfile)
-                           (*p_record_line) (last_subfile, 0, addr);
+                         dwarf_finish_line (gdbarch, last_subfile,
+                                            address, p_record_line);
                          last_subfile = current_subfile;
                        }
                      /* Append row to matrix using current values.  */
-                     addr = gdbarch_addr_bits_remove (gdbarch, address);
-                     (*p_record_line) (current_subfile, line, addr);
+                     dwarf_record_line (gdbarch, current_subfile,
+                                        line, address, p_record_line);
                    }
                }
-             basic_block = 0;
            }
          else switch (op_code)
            {
@@ -17285,6 +17325,8 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
                                   "[in module %s]"),
                                 line_offset, objfile_name (objfile));
                      p_record_line = noop_record_line;
+                     /* Note: p_record_line is left as noop_record_line
+                        until we see DW_LNE_end_sequence.  */
                    }
 
                  op_index = 0;
@@ -17341,16 +17383,14 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
                    {
                      if (last_subfile != current_subfile)
                        {
-                         addr = gdbarch_addr_bits_remove (gdbarch, address);
-                         if (last_subfile)
-                           (*p_record_line) (last_subfile, 0, addr);
+                         dwarf_finish_line (gdbarch, last_subfile,
+                                            address, p_record_line);
                          last_subfile = current_subfile;
                        }
-                     addr = gdbarch_addr_bits_remove (gdbarch, address);
-                     (*p_record_line) (current_subfile, line, addr);
+                     dwarf_record_line (gdbarch, current_subfile,
+                                        line, address, p_record_line);
                    }
                }
-             basic_block = 0;
              break;
            case DW_LNS_advance_pc:
              {
@@ -17395,14 +17435,13 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
               }
              break;
            case DW_LNS_set_column:
-             column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+             (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
              line_ptr += bytes_read;
              break;
            case DW_LNS_negate_stmt:
              is_stmt = (!is_stmt);
              break;
            case DW_LNS_set_basic_block:
-             basic_block = 1;
              break;
            /* Add to the address register of the state machine the
               address increment value corresponding to special opcode
@@ -17445,8 +17484,8 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
           lh->file_names[file - 1].included_p = 1;
           if (!decode_for_pst_p)
            {
-             addr = gdbarch_addr_bits_remove (gdbarch, address);
-             (*p_record_line) (current_subfile, 0, addr);
+             dwarf_finish_line (gdbarch, current_subfile, address,
+                                p_record_line);
            }
         }
     }
@@ -17484,7 +17523,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
   struct subfile *first_subfile = current_subfile;
 
   if (want_line_info)
-    dwarf_decode_lines_1 (lh, comp_dir, cu, pst);
+    dwarf_decode_lines_1 (lh, comp_dir, cu, decode_for_pst_p);
 
   if (decode_for_pst_p)
     {
@@ -21655,6 +21694,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
 {
   struct dwarf2_per_cu_offset_and_type **slot, ofs;
   struct objfile *objfile = cu->objfile;
+  struct attribute *attr;
+  struct dynamic_prop prop;
 
   /* For Ada types, make sure that the gnat-specific data is always
      initialized (if not already set).  There are a few types where
@@ -21669,6 +21710,15 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
       && !HAVE_GNAT_AUX_INFO (type))
     INIT_GNAT_SPECIFIC (type);
 
+  /* Read DW_AT_data_location and set in type.  */
+  attr = dwarf2_attr (die, DW_AT_data_location, cu);
+  if (attr_to_dynamic_prop (attr, die, cu, &prop))
+    {
+      TYPE_DATA_LOCATION (type)
+        = obstack_alloc (&objfile->objfile_obstack, sizeof (prop));
+      *TYPE_DATA_LOCATION (type) = prop;
+    }
+
   if (dwarf2_per_objfile->die_type_hash == NULL)
     {
       dwarf2_per_objfile->die_type_hash =
This page took 0.033292 seconds and 4 git commands to generate.