MIPS: Fix XPA base and Virtualization ASE instruction handling
[deliverable/binutils-gdb.git] / gas / dwarf2dbg.c
index 27b264634bcee2353eb347855c275db562c98da0..e02b6e8f020fa19c7e6d912f6ad67f86080e8785 100644 (file)
@@ -1,5 +1,5 @@
 /* dwarf2dbg.c - DWARF2 debug support
-   Copyright (C) 1999-2016 Free Software Foundation, Inc.
+   Copyright (C) 1999-2017 Free Software Foundation, Inc.
    Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
 
    This file is part of GAS, the GNU Assembler.
 # define DWARF2_USE_FIXED_ADVANCE_PC   linkrelax
 #endif
 
-/* First special line opcde - leave room for the standard opcodes.
+/* First special line opcode - leave room for the standard opcodes.
    Note: If you want to change this, you'll have to update the
    "standard_opcode_lengths" table that is emitted below in
    out_debug_line().  */
@@ -515,9 +515,7 @@ get_filenum (const char *filename, unsigned int num)
              dirs = XRESIZEVEC (char *, dirs, dirs_allocated);
            }
 
-         dirs[dir] = (char *) xmalloc (dir_len + 1);
-         memcpy (dirs[dir], filename, dir_len);
-         dirs[dir][dir_len] = '\0';
+         dirs[dir] = xmemdup0 (filename, dir_len);
          dirs_in_use = dir + 1;
        }
     }
@@ -641,7 +639,7 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
        {
          size_t dir_len = strlen (dirs[files[filenum].dir]);
          size_t file_len = strlen (files[filenum].filename);
-         char *cp = (char *) xmalloc (dir_len + 1 + file_len + 1);
+         char *cp = XNEWVEC (char, dir_len + 1 + file_len + 1);
 
          memcpy (cp, dirs[files[filenum].dir], dir_len);
          INSERT_DIR_SEPARATOR (cp, dir_len);
@@ -1225,7 +1223,7 @@ dwarf2dbg_convert_frag (fragS *frag)
 
   if (DWARF2_USE_FIXED_ADVANCE_PC)
     {
-      /* If linker relaxation is enabled then the distance bewteen the two
+      /* If linker relaxation is enabled then the distance between the two
         symbols in the frag->fr_symbol expression might change.  Hence we
         cannot rely upon the value computed by resolve_symbol_value.
         Instead we leave the expression unfinalized and allow
@@ -1282,7 +1280,7 @@ process_entries (segT seg, struct line_entry *e)
       char * name;
       const char * sec_name;
 
-      /* Switch to the relevent sub-section before we start to emit
+      /* Switch to the relevant sub-section before we start to emit
         the line number table.
 
         FIXME: These sub-sections do not have a normal Line Number
@@ -1297,11 +1295,7 @@ process_entries (segT seg, struct line_entry *e)
       sec_name = bfd_get_section_name (stdoutput, seg);
       if (strcmp (sec_name, ".text") != 0)
        {
-         unsigned int len;
-
-         len = strlen (sec_name);
-         name = xmalloc (len + 11 + 2);
-         sprintf (name, ".debug_line%s", sec_name);
+         name = concat (".debug_line", sec_name, (char *) NULL);
          subseg_set (subseg_get (name, FALSE), 0);
        }
       else
@@ -1732,9 +1726,9 @@ out_debug_abbrev (segT abbrev_seg,
       else
        out_abbrev (DW_AT_ranges, DW_FORM_data8);
     }
-  out_abbrev (DW_AT_name, DW_FORM_string);
-  out_abbrev (DW_AT_comp_dir, DW_FORM_string);
-  out_abbrev (DW_AT_producer, DW_FORM_string);
+  out_abbrev (DW_AT_name, DW_FORM_strp);
+  out_abbrev (DW_AT_comp_dir, DW_FORM_strp);
+  out_abbrev (DW_AT_producer, DW_FORM_strp);
   out_abbrev (DW_AT_language, DW_FORM_data2);
   out_abbrev (0, 0);
 
@@ -1745,15 +1739,11 @@ out_debug_abbrev (segT abbrev_seg,
 /* Emit a description of this compilation unit for .debug_info.  */
 
 static void
-out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg)
+out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg,
+               symbolS *name_sym, symbolS *comp_dir_sym, symbolS *producer_sym)
 {
-  char producer[128];
-  const char *comp_dir;
-  const char *dirname;
   expressionS exp;
   symbolS *info_end;
-  char *p;
-  int len;
   int sizeof_offset;
 
   sizeof_offset = out_header (info_seg, &exp);
@@ -1804,10 +1794,38 @@ out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg)
       TC_DWARF2_EMIT_OFFSET (section_symbol (ranges_seg), sizeof_offset);
     }
 
+  /* DW_AT_name, DW_AT_comp_dir and DW_AT_producer.  Symbols in .debug_str
+     setup in out_debug_str below.  */
+  TC_DWARF2_EMIT_OFFSET (name_sym, sizeof_offset);
+  TC_DWARF2_EMIT_OFFSET (comp_dir_sym, sizeof_offset);
+  TC_DWARF2_EMIT_OFFSET (producer_sym, sizeof_offset);
+
+  /* DW_AT_language.  Yes, this is probably not really MIPS, but the
+     dwarf2 draft has no standard code for assembler.  */
+  out_two (DW_LANG_Mips_Assembler);
+
+  symbol_set_value_now (info_end);
+}
+
+/* Emit the three debug strings needed in .debug_str and setup symbols
+   to them for use in out_debug_info.  */
+static void
+out_debug_str (segT str_seg, symbolS **name_sym, symbolS **comp_dir_sym,
+              symbolS **producer_sym)
+{
+  char producer[128];
+  const char *comp_dir;
+  const char *dirname;
+  char *p;
+  int len;
+
+  subseg_set (str_seg, 0);
+
   /* DW_AT_name.  We don't have the actual file name that was present
      on the command line, so assume files[1] is the main input file.
      We're not supposed to get called unless at least one line number
      entry was emitted, so this should always be defined.  */
+  *name_sym = symbol_temp_new_now ();
   if (files_in_use == 0)
     abort ();
   if (files[1].dir)
@@ -1829,22 +1847,18 @@ out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg)
   memcpy (p, files[1].filename, len);
 
   /* DW_AT_comp_dir */
+  *comp_dir_sym = symbol_temp_new_now ();
   comp_dir = remap_debug_filename (getpwd ());
   len = strlen (comp_dir) + 1;
   p = frag_more (len);
   memcpy (p, comp_dir, len);
 
   /* DW_AT_producer */
+  *producer_sym = symbol_temp_new_now ();
   sprintf (producer, "GNU AS %s", VERSION);
   len = strlen (producer) + 1;
   p = frag_more (len);
   memcpy (p, producer, len);
-
-  /* DW_AT_language.  Yes, this is probably not really MIPS, but the
-     dwarf2 draft has no standard code for assembler.  */
-  out_two (DW_LANG_Mips_Assembler);
-
-  symbol_set_value_now (info_end);
 }
 
 void
@@ -1913,19 +1927,22 @@ dwarf2_finish (void)
   out_debug_line (line_seg);
 
   /* If this is assembler generated line info, and there is no
-     debug_info already, we need .debug_info and .debug_abbrev
-     sections as well.  */
+     debug_info already, we need .debug_info, .debug_abbrev and
+     .debug_str sections as well.  */
   if (emit_other_sections)
     {
       segT abbrev_seg;
       segT aranges_seg;
       segT ranges_seg;
+      segT str_seg;
+      symbolS *name_sym, *comp_dir_sym, *producer_sym;
 
       gas_assert (all_segs);
 
       info_seg = subseg_new (".debug_info", 0);
       abbrev_seg = subseg_new (".debug_abbrev", 0);
       aranges_seg = subseg_new (".debug_aranges", 0);
+      str_seg = subseg_new (".debug_str", 0);
 
       bfd_set_section_flags (stdoutput, info_seg,
                             SEC_READONLY | SEC_DEBUGGING);
@@ -1933,6 +1950,10 @@ dwarf2_finish (void)
                             SEC_READONLY | SEC_DEBUGGING);
       bfd_set_section_flags (stdoutput, aranges_seg,
                             SEC_READONLY | SEC_DEBUGGING);
+      bfd_set_section_flags (stdoutput, str_seg,
+                            (SEC_READONLY | SEC_DEBUGGING
+                             | SEC_MERGE | SEC_STRINGS));
+      str_seg->entsize = 1;
 
       record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);
 
@@ -1949,6 +1970,8 @@ dwarf2_finish (void)
 
       out_debug_aranges (aranges_seg, info_seg);
       out_debug_abbrev (abbrev_seg, info_seg, line_seg);
-      out_debug_info (info_seg, abbrev_seg, line_seg, ranges_seg);
+      out_debug_str (str_seg, &name_sym, &comp_dir_sym, &producer_sym);
+      out_debug_info (info_seg, abbrev_seg, line_seg, ranges_seg,
+                     name_sym, comp_dir_sym, producer_sym);
     }
 }
This page took 0.02742 seconds and 4 git commands to generate.