Home | History | Annotate | Line # | Download | only in dwarf2
macro.c revision 1.1.1.1.2.1
      1          1.1  christos /* Read DWARF macro information
      2          1.1  christos 
      3  1.1.1.1.2.1  perseant    Copyright (C) 1994-2023 Free Software Foundation, Inc.
      4          1.1  christos 
      5          1.1  christos    Adapted by Gary Funck (gary (at) intrepid.com), Intrepid Technology,
      6          1.1  christos    Inc.  with support from Florida State University (under contract
      7          1.1  christos    with the Ada Joint Program Office), and Silicon Graphics, Inc.
      8          1.1  christos    Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
      9          1.1  christos    based on Fred Fish's (Cygnus Support) implementation of DWARF 1
     10          1.1  christos    support.
     11          1.1  christos 
     12          1.1  christos    This file is part of GDB.
     13          1.1  christos 
     14          1.1  christos    This program is free software; you can redistribute it and/or modify
     15          1.1  christos    it under the terms of the GNU General Public License as published by
     16          1.1  christos    the Free Software Foundation; either version 3 of the License, or
     17          1.1  christos    (at your option) any later version.
     18          1.1  christos 
     19          1.1  christos    This program is distributed in the hope that it will be useful,
     20          1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     21          1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     22          1.1  christos    GNU General Public License for more details.
     23          1.1  christos 
     24          1.1  christos    You should have received a copy of the GNU General Public License
     25          1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     26          1.1  christos 
     27          1.1  christos #include "defs.h"
     28          1.1  christos #include "dwarf2/read.h"
     29          1.1  christos #include "dwarf2/leb.h"
     30          1.1  christos #include "dwarf2/expr.h"
     31          1.1  christos #include "dwarf2/line-header.h"
     32          1.1  christos #include "dwarf2/section.h"
     33          1.1  christos #include "dwarf2/macro.h"
     34          1.1  christos #include "dwarf2/dwz.h"
     35          1.1  christos #include "buildsym.h"
     36          1.1  christos #include "macrotab.h"
     37          1.1  christos #include "complaints.h"
     38  1.1.1.1.2.1  perseant #include "objfiles.h"
     39          1.1  christos 
     40          1.1  christos static void
     41          1.1  christos dwarf2_macro_malformed_definition_complaint (const char *arg1)
     42          1.1  christos {
     43          1.1  christos   complaint (_("macro debug info contains a "
     44          1.1  christos 	       "malformed macro definition:\n`%s'"),
     45          1.1  christos 	     arg1);
     46          1.1  christos }
     47          1.1  christos 
     48          1.1  christos static struct macro_source_file *
     49          1.1  christos macro_start_file (buildsym_compunit *builder,
     50          1.1  christos 		  int file, int line,
     51  1.1.1.1.2.1  perseant 		  struct macro_source_file *current_file,
     52  1.1.1.1.2.1  perseant 		  const struct line_header *lh)
     53          1.1  christos {
     54          1.1  christos   /* File name relative to the compilation directory of this source file.  */
     55  1.1.1.1.2.1  perseant   const file_entry *fe = lh->file_name_at (file);
     56  1.1.1.1.2.1  perseant   std::string file_name;
     57  1.1.1.1.2.1  perseant 
     58  1.1.1.1.2.1  perseant   if (fe != nullptr)
     59  1.1.1.1.2.1  perseant     file_name = lh->file_file_name (*fe);
     60  1.1.1.1.2.1  perseant   else
     61  1.1.1.1.2.1  perseant     {
     62  1.1.1.1.2.1  perseant       /* The compiler produced a bogus file number.  We can at least
     63  1.1.1.1.2.1  perseant 	 record the macro definitions made in the file, even if we
     64  1.1.1.1.2.1  perseant 	 won't be able to find the file by name.  */
     65  1.1.1.1.2.1  perseant       complaint (_("bad file number in macro information (%d)"),
     66  1.1.1.1.2.1  perseant 		 file);
     67  1.1.1.1.2.1  perseant 
     68  1.1.1.1.2.1  perseant       file_name = string_printf ("<bad macro file number %d>", file);
     69  1.1.1.1.2.1  perseant     }
     70          1.1  christos 
     71          1.1  christos   if (! current_file)
     72          1.1  christos     {
     73          1.1  christos       /* Note: We don't create a macro table for this compilation unit
     74          1.1  christos 	 at all until we actually get a filename.  */
     75          1.1  christos       struct macro_table *macro_table = builder->get_macro_table ();
     76          1.1  christos 
     77          1.1  christos       /* If we have no current file, then this must be the start_file
     78          1.1  christos 	 directive for the compilation unit's main source file.  */
     79  1.1.1.1.2.1  perseant       current_file = macro_set_main (macro_table, file_name.c_str ());
     80          1.1  christos       macro_define_special (macro_table);
     81          1.1  christos     }
     82          1.1  christos   else
     83  1.1.1.1.2.1  perseant     current_file = macro_include (current_file, line, file_name.c_str ());
     84          1.1  christos 
     85          1.1  christos   return current_file;
     86          1.1  christos }
     87          1.1  christos 
     88          1.1  christos static const char *
     89          1.1  christos consume_improper_spaces (const char *p, const char *body)
     90          1.1  christos {
     91          1.1  christos   if (*p == ' ')
     92          1.1  christos     {
     93          1.1  christos       complaint (_("macro definition contains spaces "
     94          1.1  christos 		   "in formal argument list:\n`%s'"),
     95          1.1  christos 		 body);
     96          1.1  christos 
     97          1.1  christos       while (*p == ' ')
     98  1.1.1.1.2.1  perseant 	p++;
     99          1.1  christos     }
    100          1.1  christos 
    101          1.1  christos   return p;
    102          1.1  christos }
    103          1.1  christos 
    104          1.1  christos 
    105          1.1  christos static void
    106          1.1  christos parse_macro_definition (struct macro_source_file *file, int line,
    107  1.1.1.1.2.1  perseant 			const char *body)
    108          1.1  christos {
    109          1.1  christos   const char *p;
    110          1.1  christos 
    111          1.1  christos   /* The body string takes one of two forms.  For object-like macro
    112          1.1  christos      definitions, it should be:
    113          1.1  christos 
    114  1.1.1.1.2.1  perseant 	<macro name> " " <definition>
    115          1.1  christos 
    116          1.1  christos      For function-like macro definitions, it should be:
    117          1.1  christos 
    118  1.1.1.1.2.1  perseant 	<macro name> "() " <definition>
    119          1.1  christos      or
    120  1.1.1.1.2.1  perseant 	<macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
    121          1.1  christos 
    122          1.1  christos      Spaces may appear only where explicitly indicated, and in the
    123          1.1  christos      <definition>.
    124          1.1  christos 
    125          1.1  christos      The Dwarf 2 spec says that an object-like macro's name is always
    126          1.1  christos      followed by a space, but versions of GCC around March 2002 omit
    127          1.1  christos      the space when the macro's definition is the empty string.
    128          1.1  christos 
    129          1.1  christos      The Dwarf 2 spec says that there should be no spaces between the
    130          1.1  christos      formal arguments in a function-like macro's formal argument list,
    131          1.1  christos      but versions of GCC around March 2002 include spaces after the
    132          1.1  christos      commas.  */
    133          1.1  christos 
    134          1.1  christos 
    135          1.1  christos   /* Find the extent of the macro name.  The macro name is terminated
    136          1.1  christos      by either a space or null character (for an object-like macro) or
    137          1.1  christos      an opening paren (for a function-like macro).  */
    138          1.1  christos   for (p = body; *p; p++)
    139          1.1  christos     if (*p == ' ' || *p == '(')
    140          1.1  christos       break;
    141          1.1  christos 
    142          1.1  christos   if (*p == ' ' || *p == '\0')
    143          1.1  christos     {
    144          1.1  christos       /* It's an object-like macro.  */
    145          1.1  christos       int name_len = p - body;
    146          1.1  christos       std::string name (body, name_len);
    147          1.1  christos       const char *replacement;
    148          1.1  christos 
    149          1.1  christos       if (*p == ' ')
    150  1.1.1.1.2.1  perseant 	replacement = body + name_len + 1;
    151          1.1  christos       else
    152  1.1.1.1.2.1  perseant 	{
    153          1.1  christos 	  dwarf2_macro_malformed_definition_complaint (body);
    154  1.1.1.1.2.1  perseant 	  replacement = body + name_len;
    155  1.1.1.1.2.1  perseant 	}
    156          1.1  christos 
    157          1.1  christos       macro_define_object (file, line, name.c_str (), replacement);
    158          1.1  christos     }
    159          1.1  christos   else if (*p == '(')
    160          1.1  christos     {
    161          1.1  christos       /* It's a function-like macro.  */
    162          1.1  christos       std::string name (body, p - body);
    163          1.1  christos       int argc = 0;
    164          1.1  christos       int argv_size = 1;
    165          1.1  christos       char **argv = XNEWVEC (char *, argv_size);
    166          1.1  christos 
    167          1.1  christos       p++;
    168          1.1  christos 
    169          1.1  christos       p = consume_improper_spaces (p, body);
    170          1.1  christos 
    171          1.1  christos       /* Parse the formal argument list.  */
    172          1.1  christos       while (*p && *p != ')')
    173  1.1.1.1.2.1  perseant 	{
    174  1.1.1.1.2.1  perseant 	  /* Find the extent of the current argument name.  */
    175  1.1.1.1.2.1  perseant 	  const char *arg_start = p;
    176          1.1  christos 
    177  1.1.1.1.2.1  perseant 	  while (*p && *p != ',' && *p != ')' && *p != ' ')
    178  1.1.1.1.2.1  perseant 	    p++;
    179          1.1  christos 
    180  1.1.1.1.2.1  perseant 	  if (! *p || p == arg_start)
    181          1.1  christos 	    dwarf2_macro_malformed_definition_complaint (body);
    182  1.1.1.1.2.1  perseant 	  else
    183  1.1.1.1.2.1  perseant 	    {
    184  1.1.1.1.2.1  perseant 	      /* Make sure argv has room for the new argument.  */
    185  1.1.1.1.2.1  perseant 	      if (argc >= argv_size)
    186  1.1.1.1.2.1  perseant 		{
    187  1.1.1.1.2.1  perseant 		  argv_size *= 2;
    188  1.1.1.1.2.1  perseant 		  argv = XRESIZEVEC (char *, argv, argv_size);
    189  1.1.1.1.2.1  perseant 		}
    190  1.1.1.1.2.1  perseant 
    191  1.1.1.1.2.1  perseant 	      argv[argc++] = savestring (arg_start, p - arg_start);
    192  1.1.1.1.2.1  perseant 	    }
    193  1.1.1.1.2.1  perseant 
    194  1.1.1.1.2.1  perseant 	  p = consume_improper_spaces (p, body);
    195  1.1.1.1.2.1  perseant 
    196  1.1.1.1.2.1  perseant 	  /* Consume the comma, if present.  */
    197  1.1.1.1.2.1  perseant 	  if (*p == ',')
    198  1.1.1.1.2.1  perseant 	    {
    199  1.1.1.1.2.1  perseant 	      p++;
    200  1.1.1.1.2.1  perseant 
    201  1.1.1.1.2.1  perseant 	      p = consume_improper_spaces (p, body);
    202  1.1.1.1.2.1  perseant 	    }
    203  1.1.1.1.2.1  perseant 	}
    204          1.1  christos 
    205          1.1  christos       if (*p == ')')
    206  1.1.1.1.2.1  perseant 	{
    207  1.1.1.1.2.1  perseant 	  p++;
    208          1.1  christos 
    209  1.1.1.1.2.1  perseant 	  if (*p == ' ')
    210  1.1.1.1.2.1  perseant 	    /* Perfectly formed definition, no complaints.  */
    211  1.1.1.1.2.1  perseant 	    macro_define_function (file, line, name.c_str (),
    212  1.1.1.1.2.1  perseant 				   argc, (const char **) argv,
    213  1.1.1.1.2.1  perseant 				   p + 1);
    214  1.1.1.1.2.1  perseant 	  else if (*p == '\0')
    215  1.1.1.1.2.1  perseant 	    {
    216  1.1.1.1.2.1  perseant 	      /* Complain, but do define it.  */
    217          1.1  christos 	      dwarf2_macro_malformed_definition_complaint (body);
    218  1.1.1.1.2.1  perseant 	      macro_define_function (file, line, name.c_str (),
    219  1.1.1.1.2.1  perseant 				     argc, (const char **) argv,
    220  1.1.1.1.2.1  perseant 				     p);
    221  1.1.1.1.2.1  perseant 	    }
    222  1.1.1.1.2.1  perseant 	  else
    223  1.1.1.1.2.1  perseant 	    /* Just complain.  */
    224          1.1  christos 	    dwarf2_macro_malformed_definition_complaint (body);
    225  1.1.1.1.2.1  perseant 	}
    226          1.1  christos       else
    227  1.1.1.1.2.1  perseant 	/* Just complain.  */
    228          1.1  christos 	dwarf2_macro_malformed_definition_complaint (body);
    229          1.1  christos 
    230          1.1  christos       {
    231  1.1.1.1.2.1  perseant 	int i;
    232          1.1  christos 
    233  1.1.1.1.2.1  perseant 	for (i = 0; i < argc; i++)
    234  1.1.1.1.2.1  perseant 	  xfree (argv[i]);
    235          1.1  christos       }
    236          1.1  christos       xfree (argv);
    237          1.1  christos     }
    238          1.1  christos   else
    239          1.1  christos     dwarf2_macro_malformed_definition_complaint (body);
    240          1.1  christos }
    241          1.1  christos 
    242          1.1  christos /* Skip some bytes from BYTES according to the form given in FORM.
    243          1.1  christos    Returns the new pointer.  */
    244          1.1  christos 
    245          1.1  christos static const gdb_byte *
    246          1.1  christos skip_form_bytes (bfd *abfd, const gdb_byte *bytes, const gdb_byte *buffer_end,
    247          1.1  christos 		 enum dwarf_form form,
    248          1.1  christos 		 unsigned int offset_size,
    249          1.1  christos 		 const struct dwarf2_section_info *section)
    250          1.1  christos {
    251          1.1  christos   unsigned int bytes_read;
    252          1.1  christos 
    253          1.1  christos   switch (form)
    254          1.1  christos     {
    255          1.1  christos     case DW_FORM_data1:
    256          1.1  christos     case DW_FORM_flag:
    257          1.1  christos       ++bytes;
    258          1.1  christos       break;
    259          1.1  christos 
    260          1.1  christos     case DW_FORM_data2:
    261          1.1  christos       bytes += 2;
    262          1.1  christos       break;
    263          1.1  christos 
    264          1.1  christos     case DW_FORM_data4:
    265          1.1  christos       bytes += 4;
    266          1.1  christos       break;
    267          1.1  christos 
    268          1.1  christos     case DW_FORM_data8:
    269          1.1  christos       bytes += 8;
    270          1.1  christos       break;
    271          1.1  christos 
    272          1.1  christos     case DW_FORM_data16:
    273          1.1  christos       bytes += 16;
    274          1.1  christos       break;
    275          1.1  christos 
    276          1.1  christos     case DW_FORM_string:
    277          1.1  christos       read_direct_string (abfd, bytes, &bytes_read);
    278          1.1  christos       bytes += bytes_read;
    279          1.1  christos       break;
    280          1.1  christos 
    281          1.1  christos     case DW_FORM_sec_offset:
    282          1.1  christos     case DW_FORM_strp:
    283          1.1  christos     case DW_FORM_GNU_strp_alt:
    284          1.1  christos       bytes += offset_size;
    285          1.1  christos       break;
    286          1.1  christos 
    287          1.1  christos     case DW_FORM_block:
    288          1.1  christos       bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
    289          1.1  christos       bytes += bytes_read;
    290          1.1  christos       break;
    291          1.1  christos 
    292          1.1  christos     case DW_FORM_block1:
    293          1.1  christos       bytes += 1 + read_1_byte (abfd, bytes);
    294          1.1  christos       break;
    295          1.1  christos     case DW_FORM_block2:
    296          1.1  christos       bytes += 2 + read_2_bytes (abfd, bytes);
    297          1.1  christos       break;
    298          1.1  christos     case DW_FORM_block4:
    299          1.1  christos       bytes += 4 + read_4_bytes (abfd, bytes);
    300          1.1  christos       break;
    301          1.1  christos 
    302          1.1  christos     case DW_FORM_addrx:
    303          1.1  christos     case DW_FORM_sdata:
    304          1.1  christos     case DW_FORM_strx:
    305          1.1  christos     case DW_FORM_udata:
    306          1.1  christos     case DW_FORM_GNU_addr_index:
    307          1.1  christos     case DW_FORM_GNU_str_index:
    308          1.1  christos       bytes = gdb_skip_leb128 (bytes, buffer_end);
    309          1.1  christos       if (bytes == NULL)
    310          1.1  christos 	{
    311          1.1  christos 	  section->overflow_complaint ();
    312          1.1  christos 	  return NULL;
    313          1.1  christos 	}
    314          1.1  christos       break;
    315          1.1  christos 
    316          1.1  christos     case DW_FORM_implicit_const:
    317          1.1  christos       break;
    318          1.1  christos 
    319          1.1  christos     default:
    320          1.1  christos       {
    321          1.1  christos 	complaint (_("invalid form 0x%x in `%s'"),
    322          1.1  christos 		   form, section->get_name ());
    323          1.1  christos 	return NULL;
    324          1.1  christos       }
    325          1.1  christos     }
    326          1.1  christos 
    327          1.1  christos   return bytes;
    328          1.1  christos }
    329          1.1  christos 
    330          1.1  christos /* A helper for dwarf_decode_macros that handles skipping an unknown
    331          1.1  christos    opcode.  Returns an updated pointer to the macro data buffer; or,
    332          1.1  christos    on error, issues a complaint and returns NULL.  */
    333          1.1  christos 
    334          1.1  christos static const gdb_byte *
    335          1.1  christos skip_unknown_opcode (unsigned int opcode,
    336          1.1  christos 		     const gdb_byte **opcode_definitions,
    337          1.1  christos 		     const gdb_byte *mac_ptr, const gdb_byte *mac_end,
    338          1.1  christos 		     bfd *abfd,
    339          1.1  christos 		     unsigned int offset_size,
    340          1.1  christos 		     const struct dwarf2_section_info *section)
    341          1.1  christos {
    342          1.1  christos   unsigned int bytes_read, i;
    343          1.1  christos   unsigned long arg;
    344          1.1  christos   const gdb_byte *defn;
    345          1.1  christos 
    346          1.1  christos   if (opcode_definitions[opcode] == NULL)
    347          1.1  christos     {
    348  1.1.1.1.2.1  perseant       complaint (_("unrecognized DW_MACINFO or DW_MACRO opcode 0x%x"),
    349          1.1  christos 		 opcode);
    350          1.1  christos       return NULL;
    351          1.1  christos     }
    352          1.1  christos 
    353          1.1  christos   defn = opcode_definitions[opcode];
    354          1.1  christos   arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
    355          1.1  christos   defn += bytes_read;
    356          1.1  christos 
    357          1.1  christos   for (i = 0; i < arg; ++i)
    358          1.1  christos     {
    359          1.1  christos       mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end,
    360          1.1  christos 				 (enum dwarf_form) defn[i], offset_size,
    361          1.1  christos 				 section);
    362          1.1  christos       if (mac_ptr == NULL)
    363          1.1  christos 	{
    364          1.1  christos 	  /* skip_form_bytes already issued the complaint.  */
    365          1.1  christos 	  return NULL;
    366          1.1  christos 	}
    367          1.1  christos     }
    368          1.1  christos 
    369          1.1  christos   return mac_ptr;
    370          1.1  christos }
    371          1.1  christos 
    372          1.1  christos /* A helper function which parses the header of a macro section.
    373          1.1  christos    If the macro section is the extended (for now called "GNU") type,
    374          1.1  christos    then this updates *OFFSET_SIZE.  Returns a pointer to just after
    375          1.1  christos    the header, or issues a complaint and returns NULL on error.  */
    376          1.1  christos 
    377          1.1  christos static const gdb_byte *
    378          1.1  christos dwarf_parse_macro_header (const gdb_byte **opcode_definitions,
    379          1.1  christos 			  bfd *abfd,
    380          1.1  christos 			  const gdb_byte *mac_ptr,
    381          1.1  christos 			  unsigned int *offset_size,
    382          1.1  christos 			  int section_is_gnu)
    383          1.1  christos {
    384          1.1  christos   memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
    385          1.1  christos 
    386          1.1  christos   if (section_is_gnu)
    387          1.1  christos     {
    388          1.1  christos       unsigned int version, flags;
    389          1.1  christos 
    390          1.1  christos       version = read_2_bytes (abfd, mac_ptr);
    391          1.1  christos       if (version != 4 && version != 5)
    392          1.1  christos 	{
    393          1.1  christos 	  complaint (_("unrecognized version `%d' in .debug_macro section"),
    394          1.1  christos 		     version);
    395          1.1  christos 	  return NULL;
    396          1.1  christos 	}
    397          1.1  christos       mac_ptr += 2;
    398          1.1  christos 
    399          1.1  christos       flags = read_1_byte (abfd, mac_ptr);
    400          1.1  christos       ++mac_ptr;
    401          1.1  christos       *offset_size = (flags & 1) ? 8 : 4;
    402          1.1  christos 
    403          1.1  christos       if ((flags & 2) != 0)
    404          1.1  christos 	/* We don't need the line table offset.  */
    405          1.1  christos 	mac_ptr += *offset_size;
    406          1.1  christos 
    407          1.1  christos       /* Vendor opcode descriptions.  */
    408          1.1  christos       if ((flags & 4) != 0)
    409          1.1  christos 	{
    410          1.1  christos 	  unsigned int i, count;
    411          1.1  christos 
    412          1.1  christos 	  count = read_1_byte (abfd, mac_ptr);
    413          1.1  christos 	  ++mac_ptr;
    414          1.1  christos 	  for (i = 0; i < count; ++i)
    415          1.1  christos 	    {
    416          1.1  christos 	      unsigned int opcode, bytes_read;
    417          1.1  christos 	      unsigned long arg;
    418          1.1  christos 
    419          1.1  christos 	      opcode = read_1_byte (abfd, mac_ptr);
    420          1.1  christos 	      ++mac_ptr;
    421          1.1  christos 	      opcode_definitions[opcode] = mac_ptr;
    422          1.1  christos 	      arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    423          1.1  christos 	      mac_ptr += bytes_read;
    424          1.1  christos 	      mac_ptr += arg;
    425          1.1  christos 	    }
    426          1.1  christos 	}
    427          1.1  christos     }
    428          1.1  christos 
    429          1.1  christos   return mac_ptr;
    430          1.1  christos }
    431          1.1  christos 
    432          1.1  christos /* A helper for dwarf_decode_macros that handles the GNU extensions,
    433          1.1  christos    including DW_MACRO_import.  */
    434          1.1  christos 
    435          1.1  christos static void
    436          1.1  christos dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
    437          1.1  christos 			  buildsym_compunit *builder,
    438          1.1  christos 			  bfd *abfd,
    439          1.1  christos 			  const gdb_byte *mac_ptr, const gdb_byte *mac_end,
    440          1.1  christos 			  struct macro_source_file *current_file,
    441          1.1  christos 			  const struct line_header *lh,
    442          1.1  christos 			  const struct dwarf2_section_info *section,
    443          1.1  christos 			  int section_is_gnu, int section_is_dwz,
    444          1.1  christos 			  unsigned int offset_size,
    445  1.1.1.1.2.1  perseant 			  struct dwarf2_section_info *str_section,
    446  1.1.1.1.2.1  perseant 			  struct dwarf2_section_info *str_offsets_section,
    447  1.1.1.1.2.1  perseant 			  gdb::optional<ULONGEST> str_offsets_base,
    448  1.1.1.1.2.1  perseant 			  htab_t include_hash, struct dwarf2_cu *cu)
    449          1.1  christos {
    450          1.1  christos   struct objfile *objfile = per_objfile->objfile;
    451          1.1  christos   enum dwarf_macro_record_type macinfo_type;
    452          1.1  christos   int at_commandline;
    453          1.1  christos   const gdb_byte *opcode_definitions[256];
    454          1.1  christos 
    455          1.1  christos   mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
    456          1.1  christos 				      &offset_size, section_is_gnu);
    457          1.1  christos   if (mac_ptr == NULL)
    458          1.1  christos     {
    459          1.1  christos       /* We already issued a complaint.  */
    460          1.1  christos       return;
    461          1.1  christos     }
    462          1.1  christos 
    463          1.1  christos   /* Determines if GDB is still before first DW_MACINFO_start_file.  If true
    464          1.1  christos      GDB is still reading the definitions from command line.  First
    465          1.1  christos      DW_MACINFO_start_file will need to be ignored as it was already executed
    466          1.1  christos      to create CURRENT_FILE for the main source holding also the command line
    467          1.1  christos      definitions.  On first met DW_MACINFO_start_file this flag is reset to
    468          1.1  christos      normally execute all the remaining DW_MACINFO_start_file macinfos.  */
    469          1.1  christos 
    470          1.1  christos   at_commandline = 1;
    471          1.1  christos 
    472          1.1  christos   do
    473          1.1  christos     {
    474          1.1  christos       /* Do we at least have room for a macinfo type byte?  */
    475          1.1  christos       if (mac_ptr >= mac_end)
    476          1.1  christos 	{
    477          1.1  christos 	  section->overflow_complaint ();
    478          1.1  christos 	  break;
    479          1.1  christos 	}
    480          1.1  christos 
    481          1.1  christos       macinfo_type = (enum dwarf_macro_record_type) read_1_byte (abfd, mac_ptr);
    482          1.1  christos       mac_ptr++;
    483          1.1  christos 
    484          1.1  christos       /* Note that we rely on the fact that the corresponding GNU and
    485          1.1  christos 	 DWARF constants are the same.  */
    486          1.1  christos       DIAGNOSTIC_PUSH
    487          1.1  christos       DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
    488          1.1  christos       switch (macinfo_type)
    489          1.1  christos 	{
    490          1.1  christos 	  /* A zero macinfo type indicates the end of the macro
    491          1.1  christos 	     information.  */
    492          1.1  christos 	case 0:
    493          1.1  christos 	  break;
    494          1.1  christos 
    495  1.1.1.1.2.1  perseant 	case DW_MACRO_define:
    496  1.1.1.1.2.1  perseant 	case DW_MACRO_undef:
    497          1.1  christos 	case DW_MACRO_define_strp:
    498          1.1  christos 	case DW_MACRO_undef_strp:
    499          1.1  christos 	case DW_MACRO_define_sup:
    500          1.1  christos 	case DW_MACRO_undef_sup:
    501  1.1.1.1.2.1  perseant 	  {
    502  1.1.1.1.2.1  perseant 	    unsigned int bytes_read;
    503  1.1.1.1.2.1  perseant 	    int line;
    504  1.1.1.1.2.1  perseant 	    const char *body;
    505          1.1  christos 	    int is_define;
    506          1.1  christos 
    507          1.1  christos 	    line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    508          1.1  christos 	    mac_ptr += bytes_read;
    509          1.1  christos 
    510          1.1  christos 	    if (macinfo_type == DW_MACRO_define
    511          1.1  christos 		|| macinfo_type == DW_MACRO_undef)
    512          1.1  christos 	      {
    513          1.1  christos 		body = read_direct_string (abfd, mac_ptr, &bytes_read);
    514          1.1  christos 		mac_ptr += bytes_read;
    515          1.1  christos 	      }
    516          1.1  christos 	    else
    517          1.1  christos 	      {
    518          1.1  christos 		LONGEST str_offset;
    519          1.1  christos 
    520          1.1  christos 		str_offset = read_offset (abfd, mac_ptr, offset_size);
    521          1.1  christos 		mac_ptr += offset_size;
    522          1.1  christos 
    523          1.1  christos 		if (macinfo_type == DW_MACRO_define_sup
    524          1.1  christos 		    || macinfo_type == DW_MACRO_undef_sup
    525          1.1  christos 		    || section_is_dwz)
    526          1.1  christos 		  {
    527  1.1.1.1.2.1  perseant 		    dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd,
    528  1.1.1.1.2.1  perseant 							 true);
    529          1.1  christos 
    530          1.1  christos 		    body = dwz->read_string (objfile, str_offset);
    531          1.1  christos 		  }
    532          1.1  christos 		else
    533          1.1  christos 		  body = per_objfile->per_bfd->str.read_string (objfile,
    534          1.1  christos 								str_offset,
    535          1.1  christos 								"DW_FORM_strp");
    536          1.1  christos 	      }
    537          1.1  christos 
    538          1.1  christos 	    is_define = (macinfo_type == DW_MACRO_define
    539          1.1  christos 			 || macinfo_type == DW_MACRO_define_strp
    540          1.1  christos 			 || macinfo_type == DW_MACRO_define_sup);
    541  1.1.1.1.2.1  perseant 	    if (! current_file)
    542          1.1  christos 	      {
    543          1.1  christos 		/* DWARF violation as no main source is present.  */
    544          1.1  christos 		complaint (_("debug info with no main source gives macro %s "
    545          1.1  christos 			     "on line %d: %s"),
    546          1.1  christos 			   is_define ? _("definition") : _("undefinition"),
    547          1.1  christos 			   line, body);
    548          1.1  christos 		break;
    549          1.1  christos 	      }
    550          1.1  christos 	    if ((line == 0 && !at_commandline)
    551          1.1  christos 		|| (line != 0 && at_commandline))
    552          1.1  christos 	      complaint (_("debug info gives %s macro %s with %s line %d: %s"),
    553          1.1  christos 			 at_commandline ? _("command-line") : _("in-file"),
    554          1.1  christos 			 is_define ? _("definition") : _("undefinition"),
    555          1.1  christos 			 line == 0 ? _("zero") : _("non-zero"), line, body);
    556          1.1  christos 
    557          1.1  christos 	    if (body == NULL)
    558          1.1  christos 	      {
    559          1.1  christos 		/* Fedora's rpm-build's "debugedit" binary
    560          1.1  christos 		   corrupted .debug_macro sections.
    561          1.1  christos 
    562          1.1  christos 		   For more info, see
    563          1.1  christos 		   https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
    564          1.1  christos 		complaint (_("debug info gives %s invalid macro %s "
    565          1.1  christos 			     "without body (corrupted?) at line %d "
    566          1.1  christos 			     "on file %s"),
    567          1.1  christos 			   at_commandline ? _("command-line") : _("in-file"),
    568          1.1  christos 			   is_define ? _("definition") : _("undefinition"),
    569          1.1  christos 			   line, current_file->filename);
    570          1.1  christos 	      }
    571          1.1  christos 	    else if (is_define)
    572          1.1  christos 	      parse_macro_definition (current_file, line, body);
    573          1.1  christos 	    else
    574          1.1  christos 	      {
    575          1.1  christos 		gdb_assert (macinfo_type == DW_MACRO_undef
    576          1.1  christos 			    || macinfo_type == DW_MACRO_undef_strp
    577          1.1  christos 			    || macinfo_type == DW_MACRO_undef_sup);
    578          1.1  christos 		macro_undef (current_file, line, body);
    579          1.1  christos 	      }
    580  1.1.1.1.2.1  perseant 	  }
    581  1.1.1.1.2.1  perseant 	  break;
    582  1.1.1.1.2.1  perseant 
    583  1.1.1.1.2.1  perseant 	case DW_MACRO_define_strx:
    584  1.1.1.1.2.1  perseant 	case DW_MACRO_undef_strx:
    585  1.1.1.1.2.1  perseant 	  {
    586  1.1.1.1.2.1  perseant 	    unsigned int bytes_read;
    587  1.1.1.1.2.1  perseant 
    588  1.1.1.1.2.1  perseant 	    int line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    589  1.1.1.1.2.1  perseant 	    mac_ptr += bytes_read;
    590  1.1.1.1.2.1  perseant 	    int offset_index = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    591  1.1.1.1.2.1  perseant 	    mac_ptr += bytes_read;
    592  1.1.1.1.2.1  perseant 
    593  1.1.1.1.2.1  perseant 	    /* Use of the strx operators requires a DW_AT_str_offsets_base.  */
    594  1.1.1.1.2.1  perseant 	    if (!str_offsets_base.has_value ())
    595  1.1.1.1.2.1  perseant 	      {
    596  1.1.1.1.2.1  perseant 		complaint (_("use of %s with unknown string offsets base "
    597  1.1.1.1.2.1  perseant 			     "[in module %s]"),
    598  1.1.1.1.2.1  perseant 			   (macinfo_type == DW_MACRO_define_strx
    599  1.1.1.1.2.1  perseant 			    ? "DW_MACRO_define_strx"
    600  1.1.1.1.2.1  perseant 			    : "DW_MACRO_undef_strx"),
    601  1.1.1.1.2.1  perseant 			   objfile_name (objfile));
    602  1.1.1.1.2.1  perseant 		break;
    603  1.1.1.1.2.1  perseant 	      }
    604  1.1.1.1.2.1  perseant 
    605  1.1.1.1.2.1  perseant 	    str_offsets_section->read (objfile);
    606  1.1.1.1.2.1  perseant 	    const gdb_byte *info_ptr = (str_offsets_section->buffer
    607  1.1.1.1.2.1  perseant 					+ *str_offsets_base
    608  1.1.1.1.2.1  perseant 					+ offset_index * offset_size);
    609  1.1.1.1.2.1  perseant 
    610  1.1.1.1.2.1  perseant 	    const char *macinfo_str = (macinfo_type == DW_MACRO_define_strx ?
    611  1.1.1.1.2.1  perseant 				       "DW_MACRO_define_strx" : "DW_MACRO_undef_strx");
    612  1.1.1.1.2.1  perseant 
    613  1.1.1.1.2.1  perseant 	    if (*str_offsets_base + offset_index * offset_size
    614  1.1.1.1.2.1  perseant 		>= str_offsets_section->size)
    615  1.1.1.1.2.1  perseant 	      {
    616  1.1.1.1.2.1  perseant 		complaint (_("%s pointing outside of .debug_str_offsets section "
    617  1.1.1.1.2.1  perseant 			     "[in module %s]"), macinfo_str, objfile_name (objfile));
    618  1.1.1.1.2.1  perseant 		break;
    619  1.1.1.1.2.1  perseant 	      }
    620  1.1.1.1.2.1  perseant 
    621  1.1.1.1.2.1  perseant 	    ULONGEST str_offset = read_offset (abfd, info_ptr, offset_size);
    622  1.1.1.1.2.1  perseant 
    623  1.1.1.1.2.1  perseant 	    const char *body = str_section->read_string (objfile, str_offset,
    624  1.1.1.1.2.1  perseant 							 macinfo_str);
    625  1.1.1.1.2.1  perseant 	    if (current_file == nullptr)
    626  1.1.1.1.2.1  perseant 	      {
    627  1.1.1.1.2.1  perseant 		/* DWARF violation as no main source is present.  */
    628  1.1.1.1.2.1  perseant 		complaint (_("debug info with no main source gives macro %s "
    629  1.1.1.1.2.1  perseant 			     "on line %d: %s"),
    630  1.1.1.1.2.1  perseant 			     macinfo_type == DW_MACRO_define_strx ? _("definition")
    631  1.1.1.1.2.1  perseant 			     : _("undefinition"), line, body);
    632  1.1.1.1.2.1  perseant 		break;
    633  1.1.1.1.2.1  perseant 	      }
    634  1.1.1.1.2.1  perseant 
    635  1.1.1.1.2.1  perseant 	    if (macinfo_type == DW_MACRO_define_strx)
    636  1.1.1.1.2.1  perseant 	      parse_macro_definition (current_file, line, body);
    637  1.1.1.1.2.1  perseant 	    else
    638  1.1.1.1.2.1  perseant 	      macro_undef (current_file, line, body);
    639  1.1.1.1.2.1  perseant 	   }
    640  1.1.1.1.2.1  perseant 	   break;
    641  1.1.1.1.2.1  perseant 
    642  1.1.1.1.2.1  perseant 	case DW_MACRO_start_file:
    643  1.1.1.1.2.1  perseant 	  {
    644  1.1.1.1.2.1  perseant 	    unsigned int bytes_read;
    645  1.1.1.1.2.1  perseant 	    int line, file;
    646          1.1  christos 
    647  1.1.1.1.2.1  perseant 	    line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    648  1.1.1.1.2.1  perseant 	    mac_ptr += bytes_read;
    649  1.1.1.1.2.1  perseant 	    file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    650  1.1.1.1.2.1  perseant 	    mac_ptr += bytes_read;
    651          1.1  christos 
    652          1.1  christos 	    if ((line == 0 && !at_commandline)
    653          1.1  christos 		|| (line != 0 && at_commandline))
    654          1.1  christos 	      complaint (_("debug info gives source %d included "
    655          1.1  christos 			   "from %s at %s line %d"),
    656          1.1  christos 			 file, at_commandline ? _("command-line") : _("file"),
    657          1.1  christos 			 line == 0 ? _("zero") : _("non-zero"), line);
    658          1.1  christos 
    659          1.1  christos 	    if (at_commandline)
    660          1.1  christos 	      {
    661          1.1  christos 		/* This DW_MACRO_start_file was executed in the
    662          1.1  christos 		   pass one.  */
    663          1.1  christos 		at_commandline = 0;
    664          1.1  christos 	      }
    665          1.1  christos 	    else
    666          1.1  christos 	      current_file = macro_start_file (builder, file, line,
    667          1.1  christos 					       current_file, lh);
    668  1.1.1.1.2.1  perseant 	  }
    669  1.1.1.1.2.1  perseant 	  break;
    670          1.1  christos 
    671  1.1.1.1.2.1  perseant 	case DW_MACRO_end_file:
    672  1.1.1.1.2.1  perseant 	  if (! current_file)
    673          1.1  christos 	    complaint (_("macro debug info has an unmatched "
    674          1.1  christos 			 "`close_file' directive"));
    675  1.1.1.1.2.1  perseant 	  else if (current_file->included_by == nullptr
    676  1.1.1.1.2.1  perseant 		   && producer_is_clang (cu))
    677  1.1.1.1.2.1  perseant 	    {
    678  1.1.1.1.2.1  perseant 	      /* Clang, until the current version, misplaces some macro
    679  1.1.1.1.2.1  perseant 		 definitions - such as ones defined in the command line,
    680  1.1.1.1.2.1  perseant 		 putting them after the last DW_MACRO_end_file instead of
    681  1.1.1.1.2.1  perseant 		 before the first DW_MACRO_start_file.  Since at the time
    682  1.1.1.1.2.1  perseant 		 of writing there is no clang version with this bug fixed,
    683  1.1.1.1.2.1  perseant 		 we check for any clang producer.  This should be changed
    684  1.1.1.1.2.1  perseant 		 to producer_is_clang_lt_XX when possible. */
    685  1.1.1.1.2.1  perseant 	    }
    686  1.1.1.1.2.1  perseant 	  else
    687  1.1.1.1.2.1  perseant 	    {
    688  1.1.1.1.2.1  perseant 	      current_file = current_file->included_by;
    689  1.1.1.1.2.1  perseant 	      if (! current_file)
    690  1.1.1.1.2.1  perseant 		{
    691  1.1.1.1.2.1  perseant 		  enum dwarf_macro_record_type next_type;
    692  1.1.1.1.2.1  perseant 
    693  1.1.1.1.2.1  perseant 		  /* GCC circa March 2002 doesn't produce the zero
    694  1.1.1.1.2.1  perseant 		     type byte marking the end of the compilation
    695  1.1.1.1.2.1  perseant 		     unit.  Complain if it's not there, but exit no
    696  1.1.1.1.2.1  perseant 		     matter what.  */
    697  1.1.1.1.2.1  perseant 
    698  1.1.1.1.2.1  perseant 		  /* Do we at least have room for a macinfo type byte?  */
    699  1.1.1.1.2.1  perseant 		  if (mac_ptr >= mac_end)
    700  1.1.1.1.2.1  perseant 		    {
    701          1.1  christos 		      section->overflow_complaint ();
    702  1.1.1.1.2.1  perseant 		      return;
    703  1.1.1.1.2.1  perseant 		    }
    704          1.1  christos 
    705  1.1.1.1.2.1  perseant 		  /* We don't increment mac_ptr here, so this is just
    706  1.1.1.1.2.1  perseant 		     a look-ahead.  */
    707  1.1.1.1.2.1  perseant 		  next_type
    708          1.1  christos 		    = (enum dwarf_macro_record_type) read_1_byte (abfd,
    709          1.1  christos 								  mac_ptr);
    710  1.1.1.1.2.1  perseant 		  if (next_type != 0)
    711          1.1  christos 		    complaint (_("no terminating 0-type entry for "
    712          1.1  christos 				 "macros in `.debug_macinfo' section"));
    713          1.1  christos 
    714  1.1.1.1.2.1  perseant 		  return;
    715  1.1.1.1.2.1  perseant 		}
    716  1.1.1.1.2.1  perseant 	    }
    717  1.1.1.1.2.1  perseant 	  break;
    718          1.1  christos 
    719          1.1  christos 	case DW_MACRO_import:
    720          1.1  christos 	case DW_MACRO_import_sup:
    721          1.1  christos 	  {
    722          1.1  christos 	    LONGEST offset;
    723          1.1  christos 	    void **slot;
    724          1.1  christos 	    bfd *include_bfd = abfd;
    725          1.1  christos 	    const struct dwarf2_section_info *include_section = section;
    726          1.1  christos 	    const gdb_byte *include_mac_end = mac_end;
    727          1.1  christos 	    int is_dwz = section_is_dwz;
    728          1.1  christos 	    const gdb_byte *new_mac_ptr;
    729          1.1  christos 
    730          1.1  christos 	    offset = read_offset (abfd, mac_ptr, offset_size);
    731          1.1  christos 	    mac_ptr += offset_size;
    732          1.1  christos 
    733          1.1  christos 	    if (macinfo_type == DW_MACRO_import_sup)
    734          1.1  christos 	      {
    735  1.1.1.1.2.1  perseant 		dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd,
    736  1.1.1.1.2.1  perseant 						     true);
    737          1.1  christos 
    738          1.1  christos 		dwz->macro.read (objfile);
    739          1.1  christos 
    740          1.1  christos 		include_section = &dwz->macro;
    741          1.1  christos 		include_bfd = include_section->get_bfd_owner ();
    742          1.1  christos 		include_mac_end = dwz->macro.buffer + dwz->macro.size;
    743          1.1  christos 		is_dwz = 1;
    744          1.1  christos 	      }
    745          1.1  christos 
    746          1.1  christos 	    new_mac_ptr = include_section->buffer + offset;
    747          1.1  christos 	    slot = htab_find_slot (include_hash, new_mac_ptr, INSERT);
    748          1.1  christos 
    749          1.1  christos 	    if (*slot != NULL)
    750          1.1  christos 	      {
    751          1.1  christos 		/* This has actually happened; see
    752          1.1  christos 		   http://sourceware.org/bugzilla/show_bug.cgi?id=13568.  */
    753          1.1  christos 		complaint (_("recursive DW_MACRO_import in "
    754          1.1  christos 			     ".debug_macro section"));
    755          1.1  christos 	      }
    756          1.1  christos 	    else
    757          1.1  christos 	      {
    758          1.1  christos 		*slot = (void *) new_mac_ptr;
    759          1.1  christos 
    760          1.1  christos 		dwarf_decode_macro_bytes (per_objfile, builder, include_bfd,
    761          1.1  christos 					  new_mac_ptr, include_mac_end,
    762          1.1  christos 					  current_file, lh, section,
    763          1.1  christos 					  section_is_gnu, is_dwz, offset_size,
    764  1.1.1.1.2.1  perseant 					  str_section, str_offsets_section,
    765  1.1.1.1.2.1  perseant 					  str_offsets_base, include_hash, cu);
    766          1.1  christos 
    767          1.1  christos 		htab_remove_elt (include_hash, (void *) new_mac_ptr);
    768          1.1  christos 	      }
    769          1.1  christos 	  }
    770          1.1  christos 	  break;
    771          1.1  christos 
    772  1.1.1.1.2.1  perseant 	case DW_MACINFO_vendor_ext:
    773          1.1  christos 	  if (!section_is_gnu)
    774          1.1  christos 	    {
    775          1.1  christos 	      unsigned int bytes_read;
    776          1.1  christos 
    777          1.1  christos 	      /* This reads the constant, but since we don't recognize
    778          1.1  christos 		 any vendor extensions, we ignore it.  */
    779          1.1  christos 	      read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    780          1.1  christos 	      mac_ptr += bytes_read;
    781          1.1  christos 	      read_direct_string (abfd, mac_ptr, &bytes_read);
    782          1.1  christos 	      mac_ptr += bytes_read;
    783          1.1  christos 
    784          1.1  christos 	      /* We don't recognize any vendor extensions.  */
    785          1.1  christos 	      break;
    786          1.1  christos 	    }
    787          1.1  christos 	  /* FALLTHROUGH */
    788          1.1  christos 
    789          1.1  christos 	default:
    790          1.1  christos 	  mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
    791          1.1  christos 					 mac_ptr, mac_end, abfd, offset_size,
    792          1.1  christos 					 section);
    793          1.1  christos 	  if (mac_ptr == NULL)
    794          1.1  christos 	    return;
    795          1.1  christos 	  break;
    796  1.1.1.1.2.1  perseant 	}
    797          1.1  christos       DIAGNOSTIC_POP
    798          1.1  christos     } while (macinfo_type != 0);
    799          1.1  christos }
    800          1.1  christos 
    801          1.1  christos void
    802          1.1  christos dwarf_decode_macros (dwarf2_per_objfile *per_objfile,
    803          1.1  christos 		     buildsym_compunit *builder,
    804          1.1  christos 		     const dwarf2_section_info *section,
    805          1.1  christos 		     const struct line_header *lh, unsigned int offset_size,
    806  1.1.1.1.2.1  perseant 		     unsigned int offset, struct dwarf2_section_info *str_section,
    807  1.1.1.1.2.1  perseant 		     struct dwarf2_section_info *str_offsets_section,
    808  1.1.1.1.2.1  perseant 		     gdb::optional<ULONGEST> str_offsets_base,
    809  1.1.1.1.2.1  perseant 		     int section_is_gnu, struct dwarf2_cu *cu)
    810          1.1  christos {
    811          1.1  christos   bfd *abfd;
    812          1.1  christos   const gdb_byte *mac_ptr, *mac_end;
    813          1.1  christos   struct macro_source_file *current_file = 0;
    814          1.1  christos   enum dwarf_macro_record_type macinfo_type;
    815          1.1  christos   const gdb_byte *opcode_definitions[256];
    816          1.1  christos   void **slot;
    817          1.1  christos 
    818          1.1  christos   abfd = section->get_bfd_owner ();
    819          1.1  christos 
    820          1.1  christos   /* First pass: Find the name of the base filename.
    821          1.1  christos      This filename is needed in order to process all macros whose definition
    822          1.1  christos      (or undefinition) comes from the command line.  These macros are defined
    823          1.1  christos      before the first DW_MACINFO_start_file entry, and yet still need to be
    824          1.1  christos      associated to the base file.
    825          1.1  christos 
    826          1.1  christos      To determine the base file name, we scan the macro definitions until we
    827          1.1  christos      reach the first DW_MACINFO_start_file entry.  We then initialize
    828          1.1  christos      CURRENT_FILE accordingly so that any macro definition found before the
    829          1.1  christos      first DW_MACINFO_start_file can still be associated to the base file.  */
    830          1.1  christos 
    831          1.1  christos   mac_ptr = section->buffer + offset;
    832          1.1  christos   mac_end = section->buffer + section->size;
    833          1.1  christos 
    834          1.1  christos   mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
    835          1.1  christos 				      &offset_size, section_is_gnu);
    836          1.1  christos   if (mac_ptr == NULL)
    837          1.1  christos     {
    838          1.1  christos       /* We already issued a complaint.  */
    839          1.1  christos       return;
    840          1.1  christos     }
    841          1.1  christos 
    842          1.1  christos   do
    843          1.1  christos     {
    844          1.1  christos       /* Do we at least have room for a macinfo type byte?  */
    845          1.1  christos       if (mac_ptr >= mac_end)
    846  1.1.1.1.2.1  perseant 	{
    847          1.1  christos 	  /* Complaint is printed during the second pass as GDB will probably
    848          1.1  christos 	     stop the first pass earlier upon finding
    849          1.1  christos 	     DW_MACINFO_start_file.  */
    850          1.1  christos 	  break;
    851  1.1.1.1.2.1  perseant 	}
    852          1.1  christos 
    853          1.1  christos       macinfo_type = (enum dwarf_macro_record_type) read_1_byte (abfd, mac_ptr);
    854          1.1  christos       mac_ptr++;
    855          1.1  christos 
    856          1.1  christos       /* Note that we rely on the fact that the corresponding GNU and
    857          1.1  christos 	 DWARF constants are the same.  */
    858          1.1  christos       DIAGNOSTIC_PUSH
    859          1.1  christos       DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
    860          1.1  christos       switch (macinfo_type)
    861  1.1.1.1.2.1  perseant 	{
    862  1.1.1.1.2.1  perseant 	  /* A zero macinfo type indicates the end of the macro
    863  1.1.1.1.2.1  perseant 	     information.  */
    864  1.1.1.1.2.1  perseant 	case 0:
    865          1.1  christos 	  break;
    866          1.1  christos 
    867          1.1  christos 	case DW_MACRO_define:
    868          1.1  christos 	case DW_MACRO_undef:
    869          1.1  christos 	  /* Only skip the data by MAC_PTR.  */
    870          1.1  christos 	  {
    871          1.1  christos 	    unsigned int bytes_read;
    872          1.1  christos 
    873          1.1  christos 	    read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    874          1.1  christos 	    mac_ptr += bytes_read;
    875          1.1  christos 	    read_direct_string (abfd, mac_ptr, &bytes_read);
    876          1.1  christos 	    mac_ptr += bytes_read;
    877          1.1  christos 	  }
    878          1.1  christos 	  break;
    879          1.1  christos 
    880          1.1  christos 	case DW_MACRO_start_file:
    881          1.1  christos 	  {
    882          1.1  christos 	    unsigned int bytes_read;
    883          1.1  christos 	    int line, file;
    884          1.1  christos 
    885          1.1  christos 	    line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    886          1.1  christos 	    mac_ptr += bytes_read;
    887          1.1  christos 	    file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    888          1.1  christos 	    mac_ptr += bytes_read;
    889          1.1  christos 
    890          1.1  christos 	    current_file = macro_start_file (builder, file, line,
    891          1.1  christos 					     current_file, lh);
    892          1.1  christos 	  }
    893          1.1  christos 	  break;
    894          1.1  christos 
    895          1.1  christos 	case DW_MACRO_end_file:
    896          1.1  christos 	  /* No data to skip by MAC_PTR.  */
    897          1.1  christos 	  break;
    898          1.1  christos 
    899          1.1  christos 	case DW_MACRO_define_strp:
    900          1.1  christos 	case DW_MACRO_undef_strp:
    901          1.1  christos 	case DW_MACRO_define_sup:
    902          1.1  christos 	case DW_MACRO_undef_sup:
    903          1.1  christos 	  {
    904          1.1  christos 	    unsigned int bytes_read;
    905          1.1  christos 
    906          1.1  christos 	    read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    907          1.1  christos 	    mac_ptr += bytes_read;
    908          1.1  christos 	    mac_ptr += offset_size;
    909          1.1  christos 	  }
    910          1.1  christos 	  break;
    911  1.1.1.1.2.1  perseant 	case DW_MACRO_define_strx:
    912  1.1.1.1.2.1  perseant 	case DW_MACRO_undef_strx:
    913  1.1.1.1.2.1  perseant 	  {
    914  1.1.1.1.2.1  perseant 	    unsigned int bytes_read;
    915  1.1.1.1.2.1  perseant 
    916  1.1.1.1.2.1  perseant 	    read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    917  1.1.1.1.2.1  perseant 	    mac_ptr += bytes_read;
    918  1.1.1.1.2.1  perseant 	    read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    919  1.1.1.1.2.1  perseant 	    mac_ptr += bytes_read;
    920  1.1.1.1.2.1  perseant 	  }
    921  1.1.1.1.2.1  perseant 	  break;
    922          1.1  christos 
    923          1.1  christos 	case DW_MACRO_import:
    924          1.1  christos 	case DW_MACRO_import_sup:
    925          1.1  christos 	  /* Note that, according to the spec, a transparent include
    926          1.1  christos 	     chain cannot call DW_MACRO_start_file.  So, we can just
    927          1.1  christos 	     skip this opcode.  */
    928          1.1  christos 	  mac_ptr += offset_size;
    929          1.1  christos 	  break;
    930          1.1  christos 
    931          1.1  christos 	case DW_MACINFO_vendor_ext:
    932          1.1  christos 	  /* Only skip the data by MAC_PTR.  */
    933          1.1  christos 	  if (!section_is_gnu)
    934          1.1  christos 	    {
    935          1.1  christos 	      unsigned int bytes_read;
    936          1.1  christos 
    937          1.1  christos 	      read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
    938          1.1  christos 	      mac_ptr += bytes_read;
    939          1.1  christos 	      read_direct_string (abfd, mac_ptr, &bytes_read);
    940          1.1  christos 	      mac_ptr += bytes_read;
    941          1.1  christos 	    }
    942          1.1  christos 	  /* FALLTHROUGH */
    943          1.1  christos 
    944          1.1  christos 	default:
    945          1.1  christos 	  mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
    946          1.1  christos 					 mac_ptr, mac_end, abfd, offset_size,
    947          1.1  christos 					 section);
    948          1.1  christos 	  if (mac_ptr == NULL)
    949          1.1  christos 	    return;
    950          1.1  christos 	  break;
    951          1.1  christos 	}
    952          1.1  christos       DIAGNOSTIC_POP
    953          1.1  christos     } while (macinfo_type != 0 && current_file == NULL);
    954          1.1  christos 
    955          1.1  christos   /* Second pass: Process all entries.
    956          1.1  christos 
    957          1.1  christos      Use the AT_COMMAND_LINE flag to determine whether we are still processing
    958          1.1  christos      command-line macro definitions/undefinitions.  This flag is unset when we
    959          1.1  christos      reach the first DW_MACINFO_start_file entry.  */
    960          1.1  christos 
    961          1.1  christos   htab_up include_hash (htab_create_alloc (1, htab_hash_pointer,
    962          1.1  christos 					   htab_eq_pointer,
    963          1.1  christos 					   NULL, xcalloc, xfree));
    964          1.1  christos   mac_ptr = section->buffer + offset;
    965          1.1  christos   slot = htab_find_slot (include_hash.get (), mac_ptr, INSERT);
    966          1.1  christos   *slot = (void *) mac_ptr;
    967          1.1  christos   dwarf_decode_macro_bytes (per_objfile, builder, abfd, mac_ptr, mac_end,
    968          1.1  christos 			    current_file, lh, section, section_is_gnu, 0,
    969  1.1.1.1.2.1  perseant 			    offset_size, str_section, str_offsets_section,
    970  1.1.1.1.2.1  perseant 			    str_offsets_base, include_hash.get (), cu);
    971          1.1  christos }
    972