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