[BACK]Return to dwarf2dbg.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / external / gpl3 / binutils.old / dist / gas

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/external/gpl3/binutils.old/dist/gas/dwarf2dbg.c between version 1.6 and 1.7

version 1.6, 2020/04/03 17:51:08 version 1.7, 2022/12/23 17:09:21
Line 1 
Line 1 
 /* dwarf2dbg.c - DWARF2 debug support  /* dwarf2dbg.c - DWARF2 debug support
    Copyright (C) 1999-2018 Free Software Foundation, Inc.     Copyright (C) 1999-2020 Free Software Foundation, Inc.
    Contributed by David Mosberger-Tang <davidm@hpl.hp.com>     Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
   
    This file is part of GAS, the GNU Assembler.     This file is part of GAS, the GNU Assembler.
Line 97 
Line 97 
 #define DWARF2_ARANGES_VERSION 2  #define DWARF2_ARANGES_VERSION 2
 #endif  #endif
   
 /* This implementation output version 2 .debug_line information. */  /* This implementation outputs version 3 .debug_line information.  */
 #ifndef DWARF2_LINE_VERSION  #ifndef DWARF2_LINE_VERSION
 #define DWARF2_LINE_VERSION 2  #define DWARF2_LINE_VERSION 3
 #endif  #endif
   
 #include "subsegs.h"  #include "subsegs.h"
Line 251  generic_dwarf2_emit_offset (symbolS *sym
Line 251  generic_dwarf2_emit_offset (symbolS *sym
 {  {
   expressionS exp;    expressionS exp;
   
     memset (&exp, 0, sizeof exp);
   exp.X_op = O_symbol;    exp.X_op = O_symbol;
   exp.X_add_symbol = symbol;    exp.X_add_symbol = symbol;
   exp.X_add_number = 0;    exp.X_add_number = 0;
Line 379  set_or_check_view (struct line_entry *e,
Line 380  set_or_check_view (struct line_entry *e,
           if (view_assert_failed)            if (view_assert_failed)
             {              {
               expressionS chk;                expressionS chk;
   
               memset (&chk, 0, sizeof (chk));                memset (&chk, 0, sizeof (chk));
               chk.X_unsigned = 1;                chk.X_unsigned = 1;
               chk.X_op = O_add;                chk.X_op = O_add;
Line 424  set_or_check_view (struct line_entry *e,
Line 426  set_or_check_view (struct line_entry *e,
   if (!S_IS_DEFINED (e->loc.view))    if (!S_IS_DEFINED (e->loc.view))
     {      {
       symbol_set_value_expression (e->loc.view, &viewx);        symbol_set_value_expression (e->loc.view, &viewx);
       S_SET_SEGMENT (e->loc.view, absolute_section);        S_SET_SEGMENT (e->loc.view, expr_section);
       symbol_set_frag (e->loc.view, &zero_address_frag);        symbol_set_frag (e->loc.view, &zero_address_frag);
     }      }
   
Line 440  set_or_check_view (struct line_entry *e,
Line 442  set_or_check_view (struct line_entry *e,
       gas_assert (r == p);        gas_assert (r == p);
       /* Set or check views until we find a defined or absent view.  */        /* Set or check views until we find a defined or absent view.  */
       do        do
         set_or_check_view (r, r->next, NULL);          {
             /* Do not define the head of a (sub?)segment view while
                handling others.  It would be defined too early, without
                regard to the last view of other subsegments.
                set_or_check_view will be called for every head segment
                that needs it.  */
             if (r == h)
               break;
             set_or_check_view (r, r->next, NULL);
           }
       while (r->next && r->next->loc.view && !S_IS_DEFINED (r->next->loc.view)        while (r->next && r->next->loc.view && !S_IS_DEFINED (r->next->loc.view)
              && (r = r->next));               && (r = r->next));
   
Line 452  set_or_check_view (struct line_entry *e,
Line 463  set_or_check_view (struct line_entry *e,
          simplify the view expressions, until we do so to P.  */           simplify the view expressions, until we do so to P.  */
       do        do
         {          {
             /* The head view of a subsegment may remain undefined while
                handling other elements, before it is linked to the last
                view of the previous subsegment.  */
             if (r == h)
               continue;
           gas_assert (S_IS_DEFINED (r->loc.view));            gas_assert (S_IS_DEFINED (r->loc.view));
           resolve_expression (symbol_get_value_expression (r->loc.view));            resolve_expression (symbol_get_value_expression (r->loc.view));
         }          }
Line 478  dwarf2_gen_line_info_1 (symbolS *label, 
Line 494  dwarf2_gen_line_info_1 (symbolS *label, 
   
   lss = get_line_subseg (now_seg, now_subseg, TRUE);    lss = get_line_subseg (now_seg, now_subseg, TRUE);
   
   if (loc->view)    /* Subseg heads are chained to previous subsegs in
        dwarf2_finish.  */
     if (loc->view && lss->head)
     set_or_check_view (e,      set_or_check_view (e,
                        !lss->head ? NULL : (struct line_entry *)lss->ptail,                         (struct line_entry *)lss->ptail,
                        lss->head);                         lss->head);
   
   *lss->ptail = e;    *lss->ptail = e;
Line 577  dwarf2_emit_insn (int size)
Line 595  dwarf2_emit_insn (int size)
   
   dwarf2_where (&loc);    dwarf2_where (&loc);
   
   dwarf2_gen_line_info (frag_now_fix () - size, &loc);    dwarf2_gen_line_info ((frag_now_fix_octets () - size) / OCTETS_PER_BYTE, &loc);
   dwarf2_consume_line_info ();    dwarf2_consume_line_info ();
 }  }
   
Line 639  dwarf2_emit_label (symbolS *label)
Line 657  dwarf2_emit_label (symbolS *label)
     return;      return;
   if (S_GET_SEGMENT (label) != now_seg)    if (S_GET_SEGMENT (label) != now_seg)
     return;      return;
   if (!(bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE))    if (!(bfd_section_flags (now_seg) & SEC_CODE))
     return;      return;
   if (files_in_use == 0 && debug_type != DEBUG_DWARF2)    if (files_in_use == 0 && debug_type != DEBUG_DWARF2)
     return;      return;
Line 733  get_filenum (const char *filename, unsig
Line 751  get_filenum (const char *filename, unsig
       unsigned int old = files_allocated;        unsigned int old = files_allocated;
   
       files_allocated = i + 32;        files_allocated = i + 32;
       files = XRESIZEVEC (struct file_entry, files, files_allocated);        /* Catch wraparound.  */
         if (files_allocated <= old)
           {
             as_bad (_("file number %lu is too big"), (unsigned long) i);
             return 0;
           }
   
         files = XRESIZEVEC (struct file_entry, files, files_allocated);
       memset (files + old, 0, (i + 32 - old) * sizeof (struct file_entry));        memset (files + old, 0, (i + 32 - old) * sizeof (struct file_entry));
     }      }
   
   files[i].filename = num ? file : xstrdup (file);    files[i].filename = file;
   files[i].dir = dir;    files[i].dir = dir;
   if (files_in_use < i + 1)    if (files_in_use < i + 1)
     files_in_use = i + 1;      files_in_use = i + 1;
Line 757  get_filenum (const char *filename, unsig
Line 781  get_filenum (const char *filename, unsig
 char *  char *
 dwarf2_directive_filename (void)  dwarf2_directive_filename (void)
 {  {
   offsetT num;    valueT num;
   char *filename;    char *filename;
   int filename_len;    int filename_len;
   
Line 775  dwarf2_directive_filename (void)
Line 799  dwarf2_directive_filename (void)
     return NULL;      return NULL;
   demand_empty_rest_of_line ();    demand_empty_rest_of_line ();
   
   if (num < 1)    if ((offsetT) num < 1)
     {      {
       as_bad (_("file number less than one"));        as_bad (_("file number less than one"));
       return NULL;        return NULL;
Line 785  dwarf2_directive_filename (void)
Line 809  dwarf2_directive_filename (void)
      being supplied.  Turn off gas generated debug info.  */       being supplied.  Turn off gas generated debug info.  */
   debug_type = DEBUG_NONE;    debug_type = DEBUG_NONE;
   
   if (num < (int) files_in_use && files[num].filename != 0)    if (num != (unsigned int) num
         || num >= (size_t) -1 / sizeof (struct file_entry) - 32)
       {
         as_bad (_("file number %lu is too big"), (unsigned long) num);
         return NULL;
       }
     if (num < files_in_use && files[num].filename != 0)
     {      {
       as_bad (_("file number %ld already allocated"), (long) num);        as_bad (_("file number %u already allocated"), (unsigned int) num);
       return NULL;        return NULL;
     }      }
   
   get_filenum (filename, num);    get_filenum (filename, (unsigned int) num);
   
   return filename;    return filename;
 }  }
Line 958  dwarf2_directive_loc (int dummy ATTRIBUT
Line 988  dwarf2_directive_loc (int dummy ATTRIBUT
               if (!name)                if (!name)
                 return;                  return;
               sym = symbol_find_or_make (name);                sym = symbol_find_or_make (name);
               if (S_IS_DEFINED (sym))                if (S_IS_DEFINED (sym) || symbol_equated_p (sym))
                 {                  {
                   if (!S_CAN_BE_REDEFINED (sym))                    if (S_IS_VOLATILE (sym))
                     as_bad (_("symbol `%s' is already defined"), name);  
                   else  
                     sym = symbol_clone (sym, 1);                      sym = symbol_clone (sym, 1);
                   S_SET_SEGMENT (sym, undefined_section);                    else if (!S_CAN_BE_REDEFINED (sym))
                   S_SET_VALUE (sym, 0);                      {
                   symbol_set_frag (sym, &zero_address_frag);                        as_bad (_("symbol `%s' is already defined"), name);
                         return;
                       }
                 }                  }
                 S_SET_SEGMENT (sym, undefined_section);
                 S_SET_VALUE (sym, 0);
                 symbol_set_frag (sym, &zero_address_frag);
             }              }
           current.view = sym;            current.view = sym;
         }          }
Line 1108  out_set_addr (symbolS *sym)
Line 1141  out_set_addr (symbolS *sym)
 {  {
   expressionS exp;    expressionS exp;
   
     memset (&exp, 0, sizeof exp);
   out_opcode (DW_LNS_extended_op);    out_opcode (DW_LNS_extended_op);
   out_uleb128 (sizeof_address + 1);    out_uleb128 (sizeof_address + 1);
   
Line 1127  scale_addr_delta (addressT *addr_delta)
Line 1161  scale_addr_delta (addressT *addr_delta)
   if (DWARF2_LINE_MIN_INSN_LENGTH > 1)    if (DWARF2_LINE_MIN_INSN_LENGTH > 1)
     {      {
       if (*addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0  && !printed_this)        if (*addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0  && !printed_this)
         {          {
           as_bad("unaligned opcodes detected in executable segment");            as_bad("unaligned opcodes detected in executable segment");
           printed_this = 1;            printed_this = 1;
         }          }
       *addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH;        *addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH;
     }      }
 }  }
Line 1158  size_inc_line_addr (int line_delta, addr
Line 1192  size_inc_line_addr (int line_delta, addr
     {      {
       if (addr_delta == MAX_SPECIAL_ADDR_DELTA)        if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
         len = 1;          len = 1;
       else        else if (addr_delta)
         len = 1 + sizeof_leb128 (addr_delta, 0);          len = 1 + sizeof_leb128 (addr_delta, 0);
       return len + 3;        return len + 3;
     }      }
Line 1222  emit_inc_line_addr (int line_delta, addr
Line 1256  emit_inc_line_addr (int line_delta, addr
     {      {
       if (addr_delta == MAX_SPECIAL_ADDR_DELTA)        if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
         *p++ = DW_LNS_const_add_pc;          *p++ = DW_LNS_const_add_pc;
       else        else if (addr_delta)
         {          {
           *p++ = DW_LNS_advance_pc;            *p++ = DW_LNS_advance_pc;
           p += output_leb128 (p, addr_delta, 0);            p += output_leb128 (p, addr_delta, 0);
Line 1373  emit_fixed_inc_line_addr (int line_delta
Line 1407  emit_fixed_inc_line_addr (int line_delta
       symbolS *to_sym;        symbolS *to_sym;
       expressionS exp;        expressionS exp;
   
         memset (&exp, 0, sizeof exp);
       gas_assert (pexp->X_op == O_subtract);        gas_assert (pexp->X_op == O_subtract);
       to_sym = pexp->X_add_symbol;        to_sym = pexp->X_add_symbol;
   
Line 1413  relax_inc_line_addr (int line_delta, sym
Line 1448  relax_inc_line_addr (int line_delta, sym
   expressionS exp;    expressionS exp;
   int max_chars;    int max_chars;
   
     memset (&exp, 0, sizeof exp);
   exp.X_op = O_subtract;    exp.X_op = O_subtract;
   exp.X_add_symbol = to_sym;    exp.X_add_symbol = to_sym;
   exp.X_op_symbol = from_sym;    exp.X_op_symbol = from_sym;
Line 1546  process_entries (segT seg, struct line_e
Line 1582  process_entries (segT seg, struct line_e
          that all of the sub-sections are merged into a proper           that all of the sub-sections are merged into a proper
          .debug_line section before a debugger sees them.  */           .debug_line section before a debugger sees them.  */
   
       sec_name = bfd_get_section_name (stdoutput, seg);        sec_name = bfd_section_name (seg);
       if (strcmp (sec_name, ".text") != 0)        if (strcmp (sec_name, ".text") != 0)
         {          {
           name = concat (".debug_line", sec_name, (char *) NULL);            name = concat (".debug_line", sec_name, (char *) NULL);
Line 1703  out_file_list (void)
Line 1739  out_file_list (void)
       out_uleb128 (files[i].dir);       /* directory number */        out_uleb128 (files[i].dir);       /* directory number */
       /* Output the last modification timestamp.  */        /* Output the last modification timestamp.  */
       out_uleb128 (DWARF2_FILE_TIME_NAME (files[i].filename,        out_uleb128 (DWARF2_FILE_TIME_NAME (files[i].filename,
                                           files[i].dir ? dirs [files [i].dir] : ""));                                            files[i].dir ? dirs [files [i].dir] : ""));
       /* Output the filesize.  */        /* Output the filesize.  */
       out_uleb128 (DWARF2_FILE_SIZE_NAME (files[i].filename,        out_uleb128 (DWARF2_FILE_SIZE_NAME (files[i].filename,
                                           files[i].dir ? dirs [files [i].dir] : ""));                                            files[i].dir ? dirs [files [i].dir] : ""));
     }      }
   
   /* Terminate filename list.  */    /* Terminate filename list.  */
Line 1737  out_header (asection *sec, expressionS *
Line 1773  out_header (asection *sec, expressionS *
     }      }
   else    else
     {      {
       start_sym = symbol_temp_new_now ();        start_sym = symbol_temp_new_now_octets ();
       end_sym = symbol_temp_make ();        end_sym = symbol_temp_make ();
     }      }
   
Line 1780  out_debug_line (segT line_seg)
Line 1816  out_debug_line (segT line_seg)
   struct line_seg *s;    struct line_seg *s;
   int sizeof_offset;    int sizeof_offset;
   
     memset (&exp, 0, sizeof exp);
   sizeof_offset = out_header (line_seg, &exp);    sizeof_offset = out_header (line_seg, &exp);
   line_end = exp.X_add_symbol;    line_end = exp.X_add_symbol;
   
Line 1850  out_debug_ranges (segT ranges_seg)
Line 1887  out_debug_ranges (segT ranges_seg)
   expressionS exp;    expressionS exp;
   unsigned int i;    unsigned int i;
   
     memset (&exp, 0, sizeof exp);
   subseg_set (ranges_seg, 0);    subseg_set (ranges_seg, 0);
   
   /* Base Address Entry.  */    /* Base Address Entry.  */
Line 1903  out_debug_aranges (segT aranges_seg, seg
Line 1941  out_debug_aranges (segT aranges_seg, seg
   char *p;    char *p;
   int sizeof_offset;    int sizeof_offset;
   
     memset (&exp, 0, sizeof exp);
   sizeof_offset = out_header (aranges_seg, &exp);    sizeof_offset = out_header (aranges_seg, &exp);
   aranges_end = exp.X_add_symbol;    aranges_end = exp.X_add_symbol;
   size = -exp.X_add_number;    size = -exp.X_add_number;
Line 2012  out_debug_info (segT info_seg, segT abbr
Line 2051  out_debug_info (segT info_seg, segT abbr
   symbolS *info_end;    symbolS *info_end;
   int sizeof_offset;    int sizeof_offset;
   
     memset (&exp, 0, sizeof exp);
   sizeof_offset = out_header (info_seg, &exp);    sizeof_offset = out_header (info_seg, &exp);
   info_end = exp.X_add_symbol;    info_end = exp.X_add_symbol;
   
Line 2091  out_debug_str (segT str_seg, symbolS **n
Line 2131  out_debug_str (segT str_seg, symbolS **n
      on the command line, so assume files[1] is the main input file.       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       We're not supposed to get called unless at least one line number
      entry was emitted, so this should always be defined.  */       entry was emitted, so this should always be defined.  */
   *name_sym = symbol_temp_new_now ();    *name_sym = symbol_temp_new_now_octets ();
   if (files_in_use == 0)    if (files_in_use == 0)
     abort ();      abort ();
   if (files[1].dir)    if (files[1].dir)
Line 2113  out_debug_str (segT str_seg, symbolS **n
Line 2153  out_debug_str (segT str_seg, symbolS **n
   memcpy (p, files[1].filename, len);    memcpy (p, files[1].filename, len);
   
   /* DW_AT_comp_dir */    /* DW_AT_comp_dir */
   *comp_dir_sym = symbol_temp_new_now ();    *comp_dir_sym = symbol_temp_new_now_octets ();
   comp_dir = remap_debug_filename (getpwd ());    comp_dir = remap_debug_filename (getpwd ());
   len = strlen (comp_dir) + 1;    len = strlen (comp_dir) + 1;
   p = frag_more (len);    p = frag_more (len);
   memcpy (p, comp_dir, len);    memcpy (p, comp_dir, len);
   
   /* DW_AT_producer */    /* DW_AT_producer */
   *producer_sym = symbol_temp_new_now ();    *producer_sym = symbol_temp_new_now_octets ();
   sprintf (producer, "GNU AS %s", VERSION);    sprintf (producer, "GNU AS %s", VERSION);
   len = strlen (producer) + 1;    len = strlen (producer) + 1;
   p = frag_more (len);    p = frag_more (len);
Line 2131  void
Line 2171  void
 dwarf2_init (void)  dwarf2_init (void)
 {  {
   last_seg_ptr = &all_segs;    last_seg_ptr = &all_segs;
   
     /* Select the default CIE version to produce here.  The global
        starts with a value of -1 and will be modified to a valid value
        either by the user providing a command line option, or some
        targets will select their own default in md_after_parse_args.  If
        we get here and the global still contains -1 then it is up to us
        to pick a sane default.  The default we choose is 1, this is the
        CIE version gas has produced for a long time, and there seems no
        reason to change it yet.  */
     if (flag_dwarf_cie_version == -1)
       flag_dwarf_cie_version = 1;
 }  }
   
   
Line 2175  dwarf2_finish (void)
Line 2226  dwarf2_finish (void)
   
   /* Create and switch to the line number section.  */    /* Create and switch to the line number section.  */
   line_seg = subseg_new (".debug_line", 0);    line_seg = subseg_new (".debug_line", 0);
   bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY | SEC_DEBUGGING);    bfd_set_section_flags (line_seg, SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
   
   /* For each subsection, chain the debug entries together.  */    /* For each subsection, chain the debug entries together.  */
   for (s = all_segs; s; s = s->next)    for (s = all_segs; s; s = s->next)
Line 2183  dwarf2_finish (void)
Line 2234  dwarf2_finish (void)
       struct line_subseg *lss = s->head;        struct line_subseg *lss = s->head;
       struct line_entry **ptail = lss->ptail;        struct line_entry **ptail = lss->ptail;
   
         /* Reset the initial view of the first subsection of the
            section.  */
         if (lss->head && lss->head->loc.view)
           set_or_check_view (lss->head, NULL, NULL);
   
       while ((lss = lss->next) != NULL)        while ((lss = lss->next) != NULL)
         {          {
             /* Link the first view of subsequent subsections to the
                previous view.  */
             if (lss->head && lss->head->loc.view)
               set_or_check_view (lss->head,
                                  !s->head ? NULL : (struct line_entry *)ptail,
                                  s->head ? s->head->head : NULL);
           *ptail = lss->head;            *ptail = lss->head;
           ptail = lss->ptail;            ptail = lss->ptail;
         }          }
Line 2210  dwarf2_finish (void)
Line 2272  dwarf2_finish (void)
       aranges_seg = subseg_new (".debug_aranges", 0);        aranges_seg = subseg_new (".debug_aranges", 0);
       str_seg = subseg_new (".debug_str", 0);        str_seg = subseg_new (".debug_str", 0);
   
       bfd_set_section_flags (stdoutput, info_seg,        bfd_set_section_flags (info_seg,
                              SEC_READONLY | SEC_DEBUGGING);                                SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
       bfd_set_section_flags (stdoutput, abbrev_seg,        bfd_set_section_flags (abbrev_seg,
                              SEC_READONLY | SEC_DEBUGGING);                                SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
       bfd_set_section_flags (stdoutput, aranges_seg,        bfd_set_section_flags (aranges_seg,
                              SEC_READONLY | SEC_DEBUGGING);                                SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
       bfd_set_section_flags (stdoutput, str_seg,        bfd_set_section_flags (str_seg,
                              (SEC_READONLY | SEC_DEBUGGING                                SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS
                               | SEC_MERGE | SEC_STRINGS));                                         | SEC_MERGE | SEC_STRINGS);
       str_seg->entsize = 1;        str_seg->entsize = 1;
   
       record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);        record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);
Line 2228  dwarf2_finish (void)
Line 2290  dwarf2_finish (void)
       else        else
         {          {
           ranges_seg = subseg_new (".debug_ranges", 0);            ranges_seg = subseg_new (".debug_ranges", 0);
           bfd_set_section_flags (stdoutput, ranges_seg,            bfd_set_section_flags (ranges_seg,
                                  SEC_READONLY | SEC_DEBUGGING);                                   SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
           record_alignment (ranges_seg, ffs (2 * sizeof_address) - 1);            record_alignment (ranges_seg, ffs (2 * sizeof_address) - 1);
           out_debug_ranges (ranges_seg);            out_debug_ranges (ranges_seg);
         }          }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

CVSweb <webmaster@jp.NetBSD.org>