43 complaint (_(
"macro debug info contains a "
44 "malformed macro definition:\n`%s'"),
56 std::string file_name;
65 complaint (_(
"bad file number in macro information (%d)"),
68 file_name = string_printf (
"<bad macro file number %d>", file);
83 current_file =
macro_include (current_file, line, file_name.c_str ());
93 complaint (_(
"macro definition contains spaces "
94 "in formal argument list:\n`%s'"),
138 for (p = body; *p; p++)
139 if (*p ==
' ' || *p ==
'(')
142 if (*p ==
' ' || *p ==
'\0')
145 int name_len = p - body;
146 std::string
name (body, name_len);
147 const char *replacement;
150 replacement = body + name_len + 1;
154 replacement = body + name_len;
162 std::string
name (body, p - body);
165 char **argv = XNEWVEC (
char *, argv_size);
172 while (*p && *p !=
')')
175 const char *arg_start = p;
177 while (*p && *p !=
',' && *p !=
')' && *p !=
' ')
180 if (! *p || p == arg_start)
185 if (argc >= argv_size)
188 argv = XRESIZEVEC (
char *, argv, argv_size);
191 argv[argc++] = savestring (arg_start, p - arg_start);
212 argc, (
const char **) argv,
219 argc, (
const char **) argv,
233 for (i = 0; i < argc; i++)
245static const gdb_byte *
247 enum dwarf_form form,
248 unsigned int offset_size,
251 unsigned int bytes_read;
281 case DW_FORM_sec_offset:
283 case DW_FORM_GNU_strp_alt:
284 bytes += offset_size;
306 case DW_FORM_GNU_addr_index:
307 case DW_FORM_GNU_str_index:
316 case DW_FORM_implicit_const:
321 complaint (_(
"invalid form 0x%x in `%s'"),
334static const gdb_byte *
336 const gdb_byte **opcode_definitions,
337 const gdb_byte *mac_ptr,
const gdb_byte *mac_end,
339 unsigned int offset_size,
342 unsigned int bytes_read, i;
344 const gdb_byte *defn;
346 if (opcode_definitions[opcode] == NULL)
348 complaint (_(
"unrecognized DW_MACINFO or DW_MACRO opcode 0x%x"),
353 defn = opcode_definitions[opcode];
357 for (i = 0; i < arg; ++i)
360 (
enum dwarf_form) defn[i], offset_size,
377static const gdb_byte *
380 const gdb_byte *mac_ptr,
381 unsigned int *offset_size,
384 memset (opcode_definitions, 0, 256 *
sizeof (gdb_byte *));
393 complaint (_(
"unrecognized version `%d' in .debug_macro section"),
401 *offset_size = (
flags & 1) ? 8 : 4;
403 if ((
flags & 2) != 0)
405 mac_ptr += *offset_size;
408 if ((
flags & 4) != 0)
410 unsigned int i, count;
414 for (i = 0; i < count; ++i)
416 unsigned int opcode, bytes_read;
421 opcode_definitions[opcode] = mac_ptr;
423 mac_ptr += bytes_read;
439 const gdb_byte *mac_ptr,
const gdb_byte *mac_end,
443 int section_is_gnu,
int section_is_dwz,
444 unsigned int offset_size,
447 gdb::optional<ULONGEST> str_offsets_base,
448 htab_t include_hash,
struct dwarf2_cu *cu)
451 enum dwarf_macro_record_type macinfo_type;
453 const gdb_byte *opcode_definitions[256];
456 &offset_size, section_is_gnu);
475 if (mac_ptr >= mac_end)
481 macinfo_type = (
enum dwarf_macro_record_type)
read_1_byte (abfd, mac_ptr);
487 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
488 switch (macinfo_type)
495 case DW_MACRO_define:
497 case DW_MACRO_define_strp:
498 case DW_MACRO_undef_strp:
499 case DW_MACRO_define_sup:
500 case DW_MACRO_undef_sup:
502 unsigned int bytes_read;
508 mac_ptr += bytes_read;
510 if (macinfo_type == DW_MACRO_define
511 || macinfo_type == DW_MACRO_undef)
514 mac_ptr += bytes_read;
520 str_offset =
read_offset (abfd, mac_ptr, offset_size);
521 mac_ptr += offset_size;
523 if (macinfo_type == DW_MACRO_define_sup
524 || macinfo_type == DW_MACRO_undef_sup
538 is_define = (macinfo_type == DW_MACRO_define
539 || macinfo_type == DW_MACRO_define_strp
540 || macinfo_type == DW_MACRO_define_sup);
544 complaint (_(
"debug info with no main source gives macro %s "
546 is_define ? _(
"definition") : _(
"undefinition"),
550 if ((line == 0 && !at_commandline)
551 || (line != 0 && at_commandline))
552 complaint (_(
"debug info gives %s macro %s with %s line %d: %s"),
553 at_commandline ? _(
"command-line") : _(
"in-file"),
554 is_define ? _(
"definition") : _(
"undefinition"),
555 line == 0 ? _(
"zero") : _(
"non-zero"), line, body);
564 complaint (_(
"debug info gives %s invalid macro %s "
565 "without body (corrupted?) at line %d "
567 at_commandline ? _(
"command-line") : _(
"in-file"),
568 is_define ? _(
"definition") : _(
"undefinition"),
575 gdb_assert (macinfo_type == DW_MACRO_undef
576 || macinfo_type == DW_MACRO_undef_strp
577 || macinfo_type == DW_MACRO_undef_sup);
583 case DW_MACRO_define_strx:
584 case DW_MACRO_undef_strx:
586 unsigned int bytes_read;
589 mac_ptr += bytes_read;
591 mac_ptr += bytes_read;
594 if (!str_offsets_base.has_value ())
596 complaint (_(
"use of %s with unknown string offsets base "
598 (macinfo_type == DW_MACRO_define_strx
599 ?
"DW_MACRO_define_strx"
600 :
"DW_MACRO_undef_strx"),
606 const gdb_byte *info_ptr = (str_offsets_section->
buffer
608 + offset_index * offset_size);
610 const char *macinfo_str = (macinfo_type == DW_MACRO_define_strx ?
611 "DW_MACRO_define_strx" :
"DW_MACRO_undef_strx");
613 if (*str_offsets_base + offset_index * offset_size
614 >= str_offsets_section->
size)
616 complaint (_(
"%s pointing outside of .debug_str_offsets section "
621 ULONGEST str_offset =
read_offset (abfd, info_ptr, offset_size);
625 if (current_file ==
nullptr)
628 complaint (_(
"debug info with no main source gives macro %s "
630 macinfo_type == DW_MACRO_define_strx ? _(
"definition")
631 : _(
"undefinition"), line, body);
635 if (macinfo_type == DW_MACRO_define_strx)
642 case DW_MACRO_start_file:
644 unsigned int bytes_read;
648 mac_ptr += bytes_read;
650 mac_ptr += bytes_read;
652 if ((line == 0 && !at_commandline)
653 || (line != 0 && at_commandline))
654 complaint (_(
"debug info gives source %d included "
655 "from %s at %s line %d"),
656 file, at_commandline ? _(
"command-line") : _(
"file"),
657 line == 0 ? _(
"zero") : _(
"non-zero"), line);
671 case DW_MACRO_end_file:
673 complaint (_(
"macro debug info has an unmatched "
674 "`close_file' directive"));
691 enum dwarf_macro_record_type next_type;
699 if (mac_ptr >= mac_end)
708 = (
enum dwarf_macro_record_type)
read_1_byte (abfd,
711 complaint (_(
"no terminating 0-type entry for "
712 "macros in `.debug_macinfo' section"));
719 case DW_MACRO_import:
720 case DW_MACRO_import_sup:
724 bfd *include_bfd = abfd;
726 const gdb_byte *include_mac_end = mac_end;
727 int is_dwz = section_is_dwz;
728 const gdb_byte *new_mac_ptr;
731 mac_ptr += offset_size;
733 if (macinfo_type == DW_MACRO_import_sup)
740 include_section = &dwz->
macro;
742 include_mac_end = dwz->
macro.buffer + dwz->
macro.size;
746 new_mac_ptr = include_section->
buffer + offset;
747 slot = htab_find_slot (include_hash, new_mac_ptr, INSERT);
753 complaint (_(
"recursive DW_MACRO_import in "
754 ".debug_macro section"));
758 *slot = (
void *) new_mac_ptr;
761 new_mac_ptr, include_mac_end,
763 section_is_gnu, is_dwz, offset_size,
764 str_section, str_offsets_section,
765 str_offsets_base, include_hash, cu);
767 htab_remove_elt (include_hash, (
void *) new_mac_ptr);
772 case DW_MACINFO_vendor_ext:
775 unsigned int bytes_read;
780 mac_ptr += bytes_read;
782 mac_ptr += bytes_read;
791 mac_ptr, mac_end, abfd, offset_size,
798 }
while (macinfo_type != 0);
805 const struct line_header *lh,
unsigned int offset_size,
808 gdb::optional<ULONGEST> str_offsets_base,
809 int section_is_gnu,
struct dwarf2_cu *cu)
812 const gdb_byte *mac_ptr, *mac_end;
814 enum dwarf_macro_record_type macinfo_type;
815 const gdb_byte *opcode_definitions[256];
831 mac_ptr = section->
buffer + offset;
835 &offset_size, section_is_gnu);
845 if (mac_ptr >= mac_end)
853 macinfo_type = (
enum dwarf_macro_record_type)
read_1_byte (abfd, mac_ptr);
859 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
860 switch (macinfo_type)
867 case DW_MACRO_define:
871 unsigned int bytes_read;
874 mac_ptr += bytes_read;
876 mac_ptr += bytes_read;
880 case DW_MACRO_start_file:
882 unsigned int bytes_read;
886 mac_ptr += bytes_read;
888 mac_ptr += bytes_read;
895 case DW_MACRO_end_file:
899 case DW_MACRO_define_strp:
900 case DW_MACRO_undef_strp:
901 case DW_MACRO_define_sup:
902 case DW_MACRO_undef_sup:
904 unsigned int bytes_read;
907 mac_ptr += bytes_read;
908 mac_ptr += offset_size;
911 case DW_MACRO_define_strx:
912 case DW_MACRO_undef_strx:
914 unsigned int bytes_read;
917 mac_ptr += bytes_read;
919 mac_ptr += bytes_read;
923 case DW_MACRO_import:
924 case DW_MACRO_import_sup:
928 mac_ptr += offset_size;
931 case DW_MACINFO_vendor_ext:
935 unsigned int bytes_read;
938 mac_ptr += bytes_read;
940 mac_ptr += bytes_read;
946 mac_ptr, mac_end, abfd, offset_size,
953 }
while (macinfo_type != 0 && current_file == NULL);
961 htab_up include_hash (htab_create_alloc (1, htab_hash_pointer,
964 mac_ptr = section->
buffer + offset;
965 slot = htab_find_slot (include_hash.get (), mac_ptr, INSERT);
966 *slot = (
void *) mac_ptr;
968 current_file, lh, section, section_is_gnu, 0,
969 offset_size, str_section, str_offsets_section,
970 str_offsets_base, include_hash.get (), cu);
void * xcalloc(size_t number, size_t size)
#define complaint(FMT,...)
struct dwz_file * dwarf2_get_dwz_file(dwarf2_per_bfd *per_bfd, bool require)
static const gdb_byte * gdb_skip_leb128(const gdb_byte *buf, const gdb_byte *buf_end)
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
ULONGEST read_unsigned_leb128(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read_ptr)
LONGEST read_offset(bfd *abfd, const gdb_byte *buf, unsigned int offset_size)
static unsigned int read_4_bytes(bfd *abfd, const gdb_byte *buf)
static const char * read_direct_string(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read_ptr)
static unsigned int read_1_byte(bfd *abfd, const gdb_byte *buf)
static unsigned int read_2_bytes(bfd *abfd, const gdb_byte *buf)
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)
static void dwarf2_macro_malformed_definition_complaint(const char *arg1)
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, struct dwarf2_section_info *str_section, struct dwarf2_section_info *str_offsets_section, gdb::optional< ULONGEST > str_offsets_base, htab_t include_hash, struct dwarf2_cu *cu)
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)
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)
static const char * consume_improper_spaces(const char *p, const char *body)
static void parse_macro_definition(struct macro_source_file *file, int line, const char *body)
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, struct dwarf2_section_info *str_section, struct dwarf2_section_info *str_offsets_section, gdb::optional< ULONGEST > str_offsets_base, int section_is_gnu, struct dwarf2_cu *cu)
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)
void macro_define_object(struct macro_source_file *source, int line, const char *name, const char *replacement)
struct macro_source_file * macro_set_main(struct macro_table *t, const char *filename)
struct macro_source_file * macro_include(struct macro_source_file *source, int line, const char *included)
void macro_define_function(struct macro_source_file *source, int line, const char *name, int argc, const char **argv, const char *replacement)
void macro_define_special(struct macro_table *table)
void macro_undef(struct macro_source_file *source, int line, const char *name)
const char * objfile_name(const struct objfile *objfile)
bool producer_is_clang(struct dwarf2_cu *cu)
struct macro_table * get_macro_table()
struct dwarf2_per_bfd * per_bfd
void read(struct objfile *objfile)
const char * get_name() const
void overflow_complaint() const
const char * read_string(struct objfile *objfile, LONGEST str_offset, const char *form_name)
struct bfd * get_bfd_owner() const
const char * read_string(struct objfile *objfile, LONGEST str_offset)
struct macro_source_file * included_by