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