+ DW_STRING (attr) = read_indirect_string_from_dwz (objfile,
+ dwz, str_offset);
+ DW_STRING_IS_CANONICAL (attr) = 0;
+ info_ptr += bytes_read;
+ }
+ break;
+ case DW_FORM_exprloc:
+ case DW_FORM_block:
+ blk = dwarf_alloc_block (cu);
+ blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+ info_ptr += bytes_read;
+ blk->data = read_n_bytes (abfd, info_ptr, blk->size);
+ info_ptr += blk->size;
+ DW_BLOCK (attr) = blk;
+ break;
+ case DW_FORM_block1:
+ blk = dwarf_alloc_block (cu);
+ blk->size = read_1_byte (abfd, info_ptr);
+ info_ptr += 1;
+ blk->data = read_n_bytes (abfd, info_ptr, blk->size);
+ info_ptr += blk->size;
+ DW_BLOCK (attr) = blk;
+ break;
+ case DW_FORM_data1:
+ DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
+ info_ptr += 1;
+ break;
+ case DW_FORM_flag:
+ DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
+ info_ptr += 1;
+ break;
+ case DW_FORM_flag_present:
+ DW_UNSND (attr) = 1;
+ break;
+ case DW_FORM_sdata:
+ DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
+ info_ptr += bytes_read;
+ break;
+ case DW_FORM_udata:
+ DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+ info_ptr += bytes_read;
+ break;
+ case DW_FORM_ref1:
+ DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
+ + read_1_byte (abfd, info_ptr));
+ info_ptr += 1;
+ break;
+ case DW_FORM_ref2:
+ DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
+ + read_2_bytes (abfd, info_ptr));
+ info_ptr += 2;
+ break;
+ case DW_FORM_ref4:
+ DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
+ + read_4_bytes (abfd, info_ptr));
+ info_ptr += 4;
+ break;
+ case DW_FORM_ref8:
+ DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
+ + read_8_bytes (abfd, info_ptr));
+ info_ptr += 8;
+ break;
+ case DW_FORM_ref_sig8:
+ DW_SIGNATURE (attr) = read_8_bytes (abfd, info_ptr);
+ info_ptr += 8;
+ break;
+ case DW_FORM_ref_udata:
+ DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
+ + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
+ info_ptr += bytes_read;
+ break;
+ case DW_FORM_indirect:
+ form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+ info_ptr += bytes_read;
+ if (form == DW_FORM_implicit_const)
+ {
+ implicit_const = read_signed_leb128 (abfd, info_ptr, &bytes_read);
+ info_ptr += bytes_read;
+ }
+ info_ptr = read_attribute_value (reader, attr, form, implicit_const,
+ info_ptr);
+ break;
+ case DW_FORM_implicit_const:
+ DW_SND (attr) = implicit_const;
+ break;
+ case DW_FORM_GNU_addr_index:
+ if (reader->dwo_file == NULL)
+ {
+ /* For now flag a hard error.
+ Later we can turn this into a complaint. */
+ error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
+ dwarf_form_name (form),
+ bfd_get_filename (abfd));
+ }
+ DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read);
+ info_ptr += bytes_read;
+ break;
+ case DW_FORM_GNU_str_index:
+ if (reader->dwo_file == NULL)
+ {
+ /* For now flag a hard error.
+ Later we can turn this into a complaint if warranted. */
+ error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
+ dwarf_form_name (form),
+ bfd_get_filename (abfd));
+ }
+ {
+ ULONGEST str_index =
+ read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+
+ DW_STRING (attr) = read_str_index (reader, str_index);
+ DW_STRING_IS_CANONICAL (attr) = 0;
+ info_ptr += bytes_read;
+ }
+ break;
+ default:
+ error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
+ dwarf_form_name (form),
+ bfd_get_filename (abfd));
+ }
+
+ /* Super hack. */
+ if (cu->per_cu->is_dwz && attr_form_is_ref (attr))
+ attr->form = DW_FORM_GNU_ref_alt;
+
+ /* We have seen instances where the compiler tried to emit a byte
+ size attribute of -1 which ended up being encoded as an unsigned
+ 0xffffffff. Although 0xffffffff is technically a valid size value,
+ an object of this size seems pretty unlikely so we can relatively
+ safely treat these cases as if the size attribute was invalid and
+ treat them as zero by default. */
+ if (attr->name == DW_AT_byte_size
+ && form == DW_FORM_data4
+ && DW_UNSND (attr) >= 0xffffffff)
+ {
+ complaint
+ (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
+ hex_string (DW_UNSND (attr)));
+ DW_UNSND (attr) = 0;
+ }
+
+ return info_ptr;
+}
+
+/* Read an attribute described by an abbreviated attribute. */
+
+static const gdb_byte *
+read_attribute (const struct die_reader_specs *reader,
+ struct attribute *attr, struct attr_abbrev *abbrev,
+ const gdb_byte *info_ptr)
+{
+ attr->name = abbrev->name;
+ return read_attribute_value (reader, attr, abbrev->form,
+ abbrev->implicit_const, info_ptr);
+}
+
+/* Read dwarf information from a buffer. */
+
+static unsigned int
+read_1_byte (bfd *abfd, const gdb_byte *buf)
+{
+ return bfd_get_8 (abfd, buf);
+}
+
+static int
+read_1_signed_byte (bfd *abfd, const gdb_byte *buf)
+{
+ return bfd_get_signed_8 (abfd, buf);
+}
+
+static unsigned int
+read_2_bytes (bfd *abfd, const gdb_byte *buf)
+{
+ return bfd_get_16 (abfd, buf);
+}
+
+static int
+read_2_signed_bytes (bfd *abfd, const gdb_byte *buf)
+{
+ return bfd_get_signed_16 (abfd, buf);
+}
+
+static unsigned int
+read_4_bytes (bfd *abfd, const gdb_byte *buf)
+{
+ return bfd_get_32 (abfd, buf);
+}
+
+static int
+read_4_signed_bytes (bfd *abfd, const gdb_byte *buf)
+{
+ return bfd_get_signed_32 (abfd, buf);
+}
+
+static ULONGEST
+read_8_bytes (bfd *abfd, const gdb_byte *buf)
+{
+ return bfd_get_64 (abfd, buf);
+}
+
+static CORE_ADDR
+read_address (bfd *abfd, const gdb_byte *buf, struct dwarf2_cu *cu,
+ unsigned int *bytes_read)
+{
+ struct comp_unit_head *cu_header = &cu->header;
+ CORE_ADDR retval = 0;
+
+ if (cu_header->signed_addr_p)
+ {
+ switch (cu_header->addr_size)
+ {
+ case 2:
+ retval = bfd_get_signed_16 (abfd, buf);
+ break;
+ case 4:
+ retval = bfd_get_signed_32 (abfd, buf);
+ break;
+ case 8:
+ retval = bfd_get_signed_64 (abfd, buf);
+ break;
+ default:
+ internal_error (__FILE__, __LINE__,
+ _("read_address: bad switch, signed [in module %s]"),
+ bfd_get_filename (abfd));
+ }
+ }
+ else
+ {
+ switch (cu_header->addr_size)
+ {
+ case 2:
+ retval = bfd_get_16 (abfd, buf);
+ break;
+ case 4:
+ retval = bfd_get_32 (abfd, buf);
+ break;
+ case 8:
+ retval = bfd_get_64 (abfd, buf);
+ break;
+ default:
+ internal_error (__FILE__, __LINE__,
+ _("read_address: bad switch, "
+ "unsigned [in module %s]"),
+ bfd_get_filename (abfd));
+ }
+ }
+
+ *bytes_read = cu_header->addr_size;
+ return retval;
+}
+
+/* Read the initial length from a section. The (draft) DWARF 3
+ specification allows the initial length to take up either 4 bytes
+ or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
+ bytes describe the length and all offsets will be 8 bytes in length
+ instead of 4.
+
+ An older, non-standard 64-bit format is also handled by this
+ function. The older format in question stores the initial length
+ as an 8-byte quantity without an escape value. Lengths greater
+ than 2^32 aren't very common which means that the initial 4 bytes
+ is almost always zero. Since a length value of zero doesn't make
+ sense for the 32-bit format, this initial zero can be considered to
+ be an escape value which indicates the presence of the older 64-bit
+ format. As written, the code can't detect (old format) lengths
+ greater than 4GB. If it becomes necessary to handle lengths
+ somewhat larger than 4GB, we could allow other small values (such
+ as the non-sensical values of 1, 2, and 3) to also be used as
+ escape values indicating the presence of the old format.
+
+ The value returned via bytes_read should be used to increment the
+ relevant pointer after calling read_initial_length().
+
+ [ Note: read_initial_length() and read_offset() are based on the
+ document entitled "DWARF Debugging Information Format", revision
+ 3, draft 8, dated November 19, 2001. This document was obtained
+ from:
+
+ http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
+
+ This document is only a draft and is subject to change. (So beware.)
+
+ Details regarding the older, non-standard 64-bit format were
+ determined empirically by examining 64-bit ELF files produced by
+ the SGI toolchain on an IRIX 6.5 machine.
+
+ - Kevin, July 16, 2002
+ ] */
+
+static LONGEST
+read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read)
+{
+ LONGEST length = bfd_get_32 (abfd, buf);
+
+ if (length == 0xffffffff)
+ {
+ length = bfd_get_64 (abfd, buf + 4);
+ *bytes_read = 12;
+ }
+ else if (length == 0)
+ {
+ /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
+ length = bfd_get_64 (abfd, buf);
+ *bytes_read = 8;
+ }
+ else
+ {
+ *bytes_read = 4;
+ }
+
+ return length;
+}
+
+/* Cover function for read_initial_length.
+ Returns the length of the object at BUF, and stores the size of the
+ initial length in *BYTES_READ and stores the size that offsets will be in
+ *OFFSET_SIZE.
+ If the initial length size is not equivalent to that specified in
+ CU_HEADER then issue a complaint.
+ This is useful when reading non-comp-unit headers. */
+
+static LONGEST
+read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf,
+ const struct comp_unit_head *cu_header,
+ unsigned int *bytes_read,
+ unsigned int *offset_size)
+{
+ LONGEST length = read_initial_length (abfd, buf, bytes_read);
+
+ gdb_assert (cu_header->initial_length_size == 4
+ || cu_header->initial_length_size == 8
+ || cu_header->initial_length_size == 12);
+
+ if (cu_header->initial_length_size != *bytes_read)
+ complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
+
+ *offset_size = (*bytes_read == 4) ? 4 : 8;
+ return length;
+}
+
+/* Read an offset from the data stream. The size of the offset is
+ given by cu_header->offset_size. */
+
+static LONGEST
+read_offset (bfd *abfd, const gdb_byte *buf,
+ const struct comp_unit_head *cu_header,
+ unsigned int *bytes_read)
+{
+ LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
+
+ *bytes_read = cu_header->offset_size;
+ return offset;
+}
+
+/* Read an offset from the data stream. */
+
+static LONGEST
+read_offset_1 (bfd *abfd, const gdb_byte *buf, unsigned int offset_size)
+{
+ LONGEST retval = 0;
+
+ switch (offset_size)
+ {
+ case 4:
+ retval = bfd_get_32 (abfd, buf);
+ break;
+ case 8:
+ retval = bfd_get_64 (abfd, buf);
+ break;
+ default:
+ internal_error (__FILE__, __LINE__,
+ _("read_offset_1: bad switch [in module %s]"),
+ bfd_get_filename (abfd));
+ }
+
+ return retval;
+}
+
+static const gdb_byte *
+read_n_bytes (bfd *abfd, const gdb_byte *buf, unsigned int size)
+{
+ /* If the size of a host char is 8 bits, we can return a pointer
+ to the buffer, otherwise we have to copy the data to a buffer
+ allocated on the temporary obstack. */
+ gdb_assert (HOST_CHAR_BIT == 8);
+ return buf;
+}
+
+static const char *
+read_direct_string (bfd *abfd, const gdb_byte *buf,
+ unsigned int *bytes_read_ptr)
+{
+ /* If the size of a host char is 8 bits, we can return a pointer
+ to the string, otherwise we have to copy the string to a buffer
+ allocated on the temporary obstack. */
+ gdb_assert (HOST_CHAR_BIT == 8);
+ if (*buf == '\0')
+ {
+ *bytes_read_ptr = 1;
+ return NULL;
+ }
+ *bytes_read_ptr = strlen ((const char *) buf) + 1;
+ return (const char *) buf;
+}
+
+/* Return pointer to string at section SECT offset STR_OFFSET with error
+ reporting strings FORM_NAME and SECT_NAME. */
+
+static const char *
+read_indirect_string_at_offset_from (struct objfile *objfile,
+ bfd *abfd, LONGEST str_offset,
+ struct dwarf2_section_info *sect,
+ const char *form_name,
+ const char *sect_name)
+{
+ dwarf2_read_section (objfile, sect);
+ if (sect->buffer == NULL)
+ error (_("%s used without %s section [in module %s]"),
+ form_name, sect_name, bfd_get_filename (abfd));
+ if (str_offset >= sect->size)
+ error (_("%s pointing outside of %s section [in module %s]"),
+ form_name, sect_name, bfd_get_filename (abfd));
+ gdb_assert (HOST_CHAR_BIT == 8);
+ if (sect->buffer[str_offset] == '\0')
+ return NULL;
+ return (const char *) (sect->buffer + str_offset);
+}
+
+/* Return pointer to string at .debug_str offset STR_OFFSET. */
+
+static const char *
+read_indirect_string_at_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
+ bfd *abfd, LONGEST str_offset)
+{
+ return read_indirect_string_at_offset_from (dwarf2_per_objfile->objfile,
+ abfd, str_offset,
+ &dwarf2_per_objfile->str,
+ "DW_FORM_strp", ".debug_str");
+}
+
+/* Return pointer to string at .debug_line_str offset STR_OFFSET. */
+
+static const char *
+read_indirect_line_string_at_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
+ bfd *abfd, LONGEST str_offset)
+{
+ return read_indirect_string_at_offset_from (dwarf2_per_objfile->objfile,
+ abfd, str_offset,
+ &dwarf2_per_objfile->line_str,
+ "DW_FORM_line_strp",
+ ".debug_line_str");
+}
+
+/* Read a string at offset STR_OFFSET in the .debug_str section from
+ the .dwz file DWZ. Throw an error if the offset is too large. If
+ the string consists of a single NUL byte, return NULL; otherwise
+ return a pointer to the string. */
+
+static const char *
+read_indirect_string_from_dwz (struct objfile *objfile, struct dwz_file *dwz,
+ LONGEST str_offset)
+{
+ dwarf2_read_section (objfile, &dwz->str);
+
+ if (dwz->str.buffer == NULL)
+ error (_("DW_FORM_GNU_strp_alt used without .debug_str "
+ "section [in module %s]"),
+ bfd_get_filename (dwz->dwz_bfd));
+ if (str_offset >= dwz->str.size)
+ error (_("DW_FORM_GNU_strp_alt pointing outside of "
+ ".debug_str section [in module %s]"),
+ bfd_get_filename (dwz->dwz_bfd));
+ gdb_assert (HOST_CHAR_BIT == 8);
+ if (dwz->str.buffer[str_offset] == '\0')
+ return NULL;
+ return (const char *) (dwz->str.buffer + str_offset);
+}
+
+/* Return pointer to string at .debug_str offset as read from BUF.
+ BUF is assumed to be in a compilation unit described by CU_HEADER.
+ Return *BYTES_READ_PTR count of bytes read from BUF. */
+
+static const char *
+read_indirect_string (struct dwarf2_per_objfile *dwarf2_per_objfile, bfd *abfd,
+ const gdb_byte *buf,
+ const struct comp_unit_head *cu_header,
+ unsigned int *bytes_read_ptr)
+{
+ LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
+
+ return read_indirect_string_at_offset (dwarf2_per_objfile, abfd, str_offset);
+}
+
+/* Return pointer to string at .debug_line_str offset as read from BUF.
+ BUF is assumed to be in a compilation unit described by CU_HEADER.
+ Return *BYTES_READ_PTR count of bytes read from BUF. */
+
+static const char *
+read_indirect_line_string (struct dwarf2_per_objfile *dwarf2_per_objfile,
+ bfd *abfd, const gdb_byte *buf,
+ const struct comp_unit_head *cu_header,
+ unsigned int *bytes_read_ptr)
+{
+ LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
+
+ return read_indirect_line_string_at_offset (dwarf2_per_objfile, abfd,
+ str_offset);
+}
+
+ULONGEST
+read_unsigned_leb128 (bfd *abfd, const gdb_byte *buf,
+ unsigned int *bytes_read_ptr)
+{
+ ULONGEST result;
+ unsigned int num_read;
+ int shift;
+ unsigned char byte;
+
+ result = 0;
+ shift = 0;
+ num_read = 0;
+ while (1)
+ {
+ byte = bfd_get_8 (abfd, buf);
+ buf++;
+ num_read++;
+ result |= ((ULONGEST) (byte & 127) << shift);
+ if ((byte & 128) == 0)
+ {
+ break;
+ }
+ shift += 7;
+ }
+ *bytes_read_ptr = num_read;
+ return result;
+}
+
+static LONGEST
+read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
+ unsigned int *bytes_read_ptr)
+{
+ ULONGEST result;
+ int shift, num_read;
+ unsigned char byte;
+
+ result = 0;
+ shift = 0;
+ num_read = 0;
+ while (1)
+ {
+ byte = bfd_get_8 (abfd, buf);
+ buf++;
+ num_read++;
+ result |= ((ULONGEST) (byte & 127) << shift);
+ shift += 7;
+ if ((byte & 128) == 0)
+ {
+ break;
+ }
+ }
+ if ((shift < 8 * sizeof (result)) && (byte & 0x40))
+ result |= -(((ULONGEST) 1) << shift);
+ *bytes_read_ptr = num_read;
+ return result;
+}
+
+/* Given index ADDR_INDEX in .debug_addr, fetch the value.
+ ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
+ ADDR_SIZE is the size of addresses from the CU header. */
+
+static CORE_ADDR
+read_addr_index_1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
+ unsigned int addr_index, ULONGEST addr_base, int addr_size)
+{
+ struct objfile *objfile = dwarf2_per_objfile->objfile;
+ bfd *abfd = objfile->obfd;
+ const gdb_byte *info_ptr;
+
+ dwarf2_read_section (objfile, &dwarf2_per_objfile->addr);
+ if (dwarf2_per_objfile->addr.buffer == NULL)
+ error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
+ objfile_name (objfile));
+ if (addr_base + addr_index * addr_size >= dwarf2_per_objfile->addr.size)
+ error (_("DW_FORM_addr_index pointing outside of "
+ ".debug_addr section [in module %s]"),
+ objfile_name (objfile));
+ info_ptr = (dwarf2_per_objfile->addr.buffer
+ + addr_base + addr_index * addr_size);
+ if (addr_size == 4)
+ return bfd_get_32 (abfd, info_ptr);
+ else
+ return bfd_get_64 (abfd, info_ptr);
+}
+
+/* Given index ADDR_INDEX in .debug_addr, fetch the value. */
+
+static CORE_ADDR
+read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index)
+{
+ return read_addr_index_1 (cu->per_cu->dwarf2_per_objfile, addr_index,
+ cu->addr_base, cu->header.addr_size);
+}
+
+/* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
+
+static CORE_ADDR
+read_addr_index_from_leb128 (struct dwarf2_cu *cu, const gdb_byte *info_ptr,
+ unsigned int *bytes_read)
+{
+ bfd *abfd = cu->per_cu->dwarf2_per_objfile->objfile->obfd;
+ unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
+
+ return read_addr_index (cu, addr_index);
+}
+
+/* Data structure to pass results from dwarf2_read_addr_index_reader
+ back to dwarf2_read_addr_index. */
+
+struct dwarf2_read_addr_index_data
+{
+ ULONGEST addr_base;
+ int addr_size;
+};
+
+/* die_reader_func for dwarf2_read_addr_index. */
+
+static void
+dwarf2_read_addr_index_reader (const struct die_reader_specs *reader,
+ const gdb_byte *info_ptr,
+ struct die_info *comp_unit_die,
+ int has_children,
+ void *data)
+{
+ struct dwarf2_cu *cu = reader->cu;
+ struct dwarf2_read_addr_index_data *aidata =
+ (struct dwarf2_read_addr_index_data *) data;
+
+ aidata->addr_base = cu->addr_base;
+ aidata->addr_size = cu->header.addr_size;
+}
+
+/* Given an index in .debug_addr, fetch the value.
+ NOTE: This can be called during dwarf expression evaluation,
+ long after the debug information has been read, and thus per_cu->cu
+ may no longer exist. */
+
+CORE_ADDR
+dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
+ unsigned int addr_index)
+{
+ struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
+ struct dwarf2_cu *cu = per_cu->cu;
+ ULONGEST addr_base;
+ int addr_size;
+
+ /* We need addr_base and addr_size.
+ If we don't have PER_CU->cu, we have to get it.
+ Nasty, but the alternative is storing the needed info in PER_CU,
+ which at this point doesn't seem justified: it's not clear how frequently
+ it would get used and it would increase the size of every PER_CU.
+ Entry points like dwarf2_per_cu_addr_size do a similar thing
+ so we're not in uncharted territory here.
+ Alas we need to be a bit more complicated as addr_base is contained
+ in the DIE.
+
+ We don't need to read the entire CU(/TU).
+ We just need the header and top level die.
+
+ IWBN to use the aging mechanism to let us lazily later discard the CU.
+ For now we skip this optimization. */
+
+ if (cu != NULL)
+ {
+ addr_base = cu->addr_base;
+ addr_size = cu->header.addr_size;
+ }
+ else
+ {
+ struct dwarf2_read_addr_index_data aidata;
+
+ /* Note: We can't use init_cutu_and_read_dies_simple here,
+ we need addr_base. */
+ init_cutu_and_read_dies (per_cu, NULL, 0, 0, false,
+ dwarf2_read_addr_index_reader, &aidata);
+ addr_base = aidata.addr_base;
+ addr_size = aidata.addr_size;
+ }
+
+ return read_addr_index_1 (dwarf2_per_objfile, addr_index, addr_base,
+ addr_size);
+}
+
+/* Given a DW_FORM_GNU_str_index, fetch the string.
+ This is only used by the Fission support. */
+
+static const char *
+read_str_index (const struct die_reader_specs *reader, ULONGEST str_index)
+{
+ struct dwarf2_cu *cu = reader->cu;
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = cu->per_cu->dwarf2_per_objfile;
+ struct objfile *objfile = dwarf2_per_objfile->objfile;
+ const char *objf_name = objfile_name (objfile);
+ bfd *abfd = objfile->obfd;
+ struct dwarf2_section_info *str_section = &reader->dwo_file->sections.str;
+ struct dwarf2_section_info *str_offsets_section =
+ &reader->dwo_file->sections.str_offsets;
+ const gdb_byte *info_ptr;
+ ULONGEST str_offset;
+ static const char form_name[] = "DW_FORM_GNU_str_index";
+
+ dwarf2_read_section (objfile, str_section);
+ dwarf2_read_section (objfile, str_offsets_section);
+ if (str_section->buffer == NULL)
+ error (_("%s used without .debug_str.dwo section"
+ " in CU at offset %s [in module %s]"),
+ form_name, sect_offset_str (cu->header.sect_off), objf_name);
+ if (str_offsets_section->buffer == NULL)
+ error (_("%s used without .debug_str_offsets.dwo section"
+ " in CU at offset %s [in module %s]"),
+ form_name, sect_offset_str (cu->header.sect_off), objf_name);
+ if (str_index * cu->header.offset_size >= str_offsets_section->size)
+ error (_("%s pointing outside of .debug_str_offsets.dwo"
+ " section in CU at offset %s [in module %s]"),
+ form_name, sect_offset_str (cu->header.sect_off), objf_name);
+ info_ptr = (str_offsets_section->buffer
+ + str_index * cu->header.offset_size);
+ if (cu->header.offset_size == 4)
+ str_offset = bfd_get_32 (abfd, info_ptr);
+ else
+ str_offset = bfd_get_64 (abfd, info_ptr);
+ if (str_offset >= str_section->size)
+ error (_("Offset from %s pointing outside of"
+ " .debug_str.dwo section in CU at offset %s [in module %s]"),
+ form_name, sect_offset_str (cu->header.sect_off), objf_name);
+ return (const char *) (str_section->buffer + str_offset);
+}
+
+/* Return the length of an LEB128 number in BUF. */
+
+static int
+leb128_size (const gdb_byte *buf)
+{
+ const gdb_byte *begin = buf;
+ gdb_byte byte;
+
+ while (1)
+ {
+ byte = *buf++;
+ if ((byte & 128) == 0)
+ return buf - begin;
+ }
+}
+
+static void
+set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
+{
+ switch (lang)
+ {
+ case DW_LANG_C89:
+ case DW_LANG_C99:
+ case DW_LANG_C11:
+ case DW_LANG_C:
+ case DW_LANG_UPC:
+ cu->language = language_c;
+ break;
+ case DW_LANG_Java:
+ case DW_LANG_C_plus_plus:
+ case DW_LANG_C_plus_plus_11:
+ case DW_LANG_C_plus_plus_14:
+ cu->language = language_cplus;
+ break;
+ case DW_LANG_D:
+ cu->language = language_d;
+ break;
+ case DW_LANG_Fortran77:
+ case DW_LANG_Fortran90:
+ case DW_LANG_Fortran95:
+ case DW_LANG_Fortran03:
+ case DW_LANG_Fortran08:
+ cu->language = language_fortran;
+ break;
+ case DW_LANG_Go:
+ cu->language = language_go;
+ break;
+ case DW_LANG_Mips_Assembler:
+ cu->language = language_asm;
+ break;
+ case DW_LANG_Ada83:
+ case DW_LANG_Ada95:
+ cu->language = language_ada;
+ break;
+ case DW_LANG_Modula2:
+ cu->language = language_m2;
+ break;
+ case DW_LANG_Pascal83:
+ cu->language = language_pascal;
+ break;
+ case DW_LANG_ObjC:
+ cu->language = language_objc;
+ break;
+ case DW_LANG_Rust:
+ case DW_LANG_Rust_old:
+ cu->language = language_rust;
+ break;
+ case DW_LANG_Cobol74:
+ case DW_LANG_Cobol85:
+ default:
+ cu->language = language_minimal;
+ break;
+ }
+ cu->language_defn = language_def (cu->language);
+}
+
+/* Return the named attribute or NULL if not there. */
+
+static struct attribute *
+dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
+{
+ for (;;)
+ {
+ unsigned int i;
+ struct attribute *spec = NULL;
+
+ for (i = 0; i < die->num_attrs; ++i)
+ {
+ if (die->attrs[i].name == name)
+ return &die->attrs[i];
+ if (die->attrs[i].name == DW_AT_specification
+ || die->attrs[i].name == DW_AT_abstract_origin)
+ spec = &die->attrs[i];
+ }
+
+ if (!spec)
+ break;
+
+ die = follow_die_ref (die, spec, &cu);
+ }
+
+ return NULL;
+}
+
+/* Return the named attribute or NULL if not there,
+ but do not follow DW_AT_specification, etc.
+ This is for use in contexts where we're reading .debug_types dies.
+ Following DW_AT_specification, DW_AT_abstract_origin will take us
+ back up the chain, and we want to go down. */
+
+static struct attribute *
+dwarf2_attr_no_follow (struct die_info *die, unsigned int name)
+{
+ unsigned int i;
+
+ for (i = 0; i < die->num_attrs; ++i)
+ if (die->attrs[i].name == name)
+ return &die->attrs[i];
+
+ return NULL;
+}
+
+/* Return the string associated with a string-typed attribute, or NULL if it
+ is either not found or is of an incorrect type. */
+
+static const char *
+dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
+{
+ struct attribute *attr;
+ const char *str = NULL;
+
+ attr = dwarf2_attr (die, name, cu);
+
+ if (attr != NULL)
+ {
+ if (attr->form == DW_FORM_strp || attr->form == DW_FORM_line_strp
+ || attr->form == DW_FORM_string
+ || attr->form == DW_FORM_GNU_str_index
+ || attr->form == DW_FORM_GNU_strp_alt)
+ str = DW_STRING (attr);
+ else
+ complaint (_("string type expected for attribute %s for "
+ "DIE at %s in module %s"),
+ dwarf_attr_name (name), sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ }
+
+ return str;
+}
+
+/* Return non-zero iff the attribute NAME is defined for the given DIE,
+ and holds a non-zero value. This function should only be used for
+ DW_FORM_flag or DW_FORM_flag_present attributes. */
+
+static int
+dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
+{
+ struct attribute *attr = dwarf2_attr (die, name, cu);
+
+ return (attr && DW_UNSND (attr));
+}
+
+static int
+die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
+{
+ /* A DIE is a declaration if it has a DW_AT_declaration attribute
+ which value is non-zero. However, we have to be careful with
+ DIEs having a DW_AT_specification attribute, because dwarf2_attr()
+ (via dwarf2_flag_true_p) follows this attribute. So we may
+ end up accidently finding a declaration attribute that belongs
+ to a different DIE referenced by the specification attribute,
+ even though the given DIE does not have a declaration attribute. */
+ return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
+ && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
+}
+
+/* Return the die giving the specification for DIE, if there is
+ one. *SPEC_CU is the CU containing DIE on input, and the CU
+ containing the return value on output. If there is no
+ specification, but there is an abstract origin, that is
+ returned. */
+
+static struct die_info *
+die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
+{
+ struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
+ *spec_cu);
+
+ if (spec_attr == NULL)
+ spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
+
+ if (spec_attr == NULL)
+ return NULL;
+ else
+ return follow_die_ref (die, spec_attr, spec_cu);
+}
+
+/* Stub for free_line_header to match void * callback types. */
+
+static void
+free_line_header_voidp (void *arg)
+{
+ struct line_header *lh = (struct line_header *) arg;
+
+ delete lh;
+}
+
+void
+line_header::add_include_dir (const char *include_dir)
+{
+ if (dwarf_line_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
+ include_dirs.size () + 1, include_dir);
+
+ include_dirs.push_back (include_dir);
+}
+
+void
+line_header::add_file_name (const char *name,
+ dir_index d_index,
+ unsigned int mod_time,
+ unsigned int length)
+{
+ if (dwarf_line_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "Adding file %u: %s\n",
+ (unsigned) file_names.size () + 1, name);
+
+ file_names.emplace_back (name, d_index, mod_time, length);
+}
+
+/* A convenience function to find the proper .debug_line section for a CU. */
+
+static struct dwarf2_section_info *
+get_debug_line_section (struct dwarf2_cu *cu)
+{
+ struct dwarf2_section_info *section;
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = cu->per_cu->dwarf2_per_objfile;
+
+ /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
+ DWO file. */
+ if (cu->dwo_unit && cu->per_cu->is_debug_types)
+ section = &cu->dwo_unit->dwo_file->sections.line;
+ else if (cu->per_cu->is_dwz)
+ {
+ struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+
+ section = &dwz->line;
+ }
+ else
+ section = &dwarf2_per_objfile->line;
+
+ return section;
+}
+
+/* Read directory or file name entry format, starting with byte of
+ format count entries, ULEB128 pairs of entry formats, ULEB128 of
+ entries count and the entries themselves in the described entry
+ format. */
+
+static void
+read_formatted_entries (struct dwarf2_per_objfile *dwarf2_per_objfile,
+ bfd *abfd, const gdb_byte **bufp,
+ struct line_header *lh,
+ const struct comp_unit_head *cu_header,
+ void (*callback) (struct line_header *lh,
+ const char *name,
+ dir_index d_index,
+ unsigned int mod_time,
+ unsigned int length))
+{
+ gdb_byte format_count, formati;
+ ULONGEST data_count, datai;
+ const gdb_byte *buf = *bufp;
+ const gdb_byte *format_header_data;
+ unsigned int bytes_read;
+
+ format_count = read_1_byte (abfd, buf);
+ buf += 1;
+ format_header_data = buf;
+ for (formati = 0; formati < format_count; formati++)
+ {
+ read_unsigned_leb128 (abfd, buf, &bytes_read);
+ buf += bytes_read;
+ read_unsigned_leb128 (abfd, buf, &bytes_read);
+ buf += bytes_read;
+ }
+
+ data_count = read_unsigned_leb128 (abfd, buf, &bytes_read);
+ buf += bytes_read;
+ for (datai = 0; datai < data_count; datai++)
+ {
+ const gdb_byte *format = format_header_data;
+ struct file_entry fe;
+
+ for (formati = 0; formati < format_count; formati++)
+ {
+ ULONGEST content_type = read_unsigned_leb128 (abfd, format, &bytes_read);
+ format += bytes_read;
+
+ ULONGEST form = read_unsigned_leb128 (abfd, format, &bytes_read);
+ format += bytes_read;
+
+ gdb::optional<const char *> string;
+ gdb::optional<unsigned int> uint;
+
+ switch (form)
+ {
+ case DW_FORM_string:
+ string.emplace (read_direct_string (abfd, buf, &bytes_read));
+ buf += bytes_read;
+ break;
+
+ case DW_FORM_line_strp:
+ string.emplace (read_indirect_line_string (dwarf2_per_objfile,
+ abfd, buf,
+ cu_header,
+ &bytes_read));
+ buf += bytes_read;
+ break;
+
+ case DW_FORM_data1:
+ uint.emplace (read_1_byte (abfd, buf));
+ buf += 1;
+ break;
+
+ case DW_FORM_data2:
+ uint.emplace (read_2_bytes (abfd, buf));
+ buf += 2;
+ break;
+
+ case DW_FORM_data4:
+ uint.emplace (read_4_bytes (abfd, buf));
+ buf += 4;
+ break;
+
+ case DW_FORM_data8:
+ uint.emplace (read_8_bytes (abfd, buf));
+ buf += 8;
+ break;
+
+ case DW_FORM_udata:
+ uint.emplace (read_unsigned_leb128 (abfd, buf, &bytes_read));
+ buf += bytes_read;
+ break;
+
+ case DW_FORM_block:
+ /* It is valid only for DW_LNCT_timestamp which is ignored by
+ current GDB. */
+ break;
+ }
+
+ switch (content_type)
+ {
+ case DW_LNCT_path:
+ if (string.has_value ())
+ fe.name = *string;
+ break;
+ case DW_LNCT_directory_index:
+ if (uint.has_value ())
+ fe.d_index = (dir_index) *uint;
+ break;
+ case DW_LNCT_timestamp:
+ if (uint.has_value ())
+ fe.mod_time = *uint;
+ break;
+ case DW_LNCT_size:
+ if (uint.has_value ())
+ fe.length = *uint;
+ break;
+ case DW_LNCT_MD5:
+ break;
+ default:
+ complaint (_("Unknown format content type %s"),
+ pulongest (content_type));
+ }
+ }
+
+ callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length);
+ }
+
+ *bufp = buf;
+}
+
+/* Read the statement program header starting at OFFSET in
+ .debug_line, or .debug_line.dwo. Return a pointer
+ to a struct line_header, allocated using xmalloc.
+ Returns NULL if there is a problem reading the header, e.g., if it
+ has a version we don't understand.
+
+ NOTE: the strings in the include directory and file name tables of
+ the returned object point into the dwarf line section buffer,
+ and must not be freed. */
+
+static line_header_up
+dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
+{
+ const gdb_byte *line_ptr;
+ unsigned int bytes_read, offset_size;
+ int i;
+ const char *cur_dir, *cur_file;
+ struct dwarf2_section_info *section;
+ bfd *abfd;
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = cu->per_cu->dwarf2_per_objfile;
+
+ section = get_debug_line_section (cu);
+ dwarf2_read_section (dwarf2_per_objfile->objfile, section);
+ if (section->buffer == NULL)
+ {
+ if (cu->dwo_unit && cu->per_cu->is_debug_types)
+ complaint (_("missing .debug_line.dwo section"));
+ else
+ complaint (_("missing .debug_line section"));
+ return 0;
+ }
+
+ /* We can't do this until we know the section is non-empty.
+ Only then do we know we have such a section. */
+ abfd = get_section_bfd_owner (section);
+
+ /* Make sure that at least there's room for the total_length field.
+ That could be 12 bytes long, but we're just going to fudge that. */
+ if (to_underlying (sect_off) + 4 >= section->size)
+ {
+ dwarf2_statement_list_fits_in_line_number_section_complaint ();
+ return 0;
+ }
+
+ line_header_up lh (new line_header ());
+
+ lh->sect_off = sect_off;
+ lh->offset_in_dwz = cu->per_cu->is_dwz;
+
+ line_ptr = section->buffer + to_underlying (sect_off);
+
+ /* Read in the header. */
+ lh->total_length =
+ read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
+ &bytes_read, &offset_size);
+ line_ptr += bytes_read;
+ if (line_ptr + lh->total_length > (section->buffer + section->size))
+ {
+ dwarf2_statement_list_fits_in_line_number_section_complaint ();
+ return 0;
+ }
+ lh->statement_program_end = line_ptr + lh->total_length;
+ lh->version = read_2_bytes (abfd, line_ptr);
+ line_ptr += 2;
+ if (lh->version > 5)
+ {
+ /* This is a version we don't understand. The format could have
+ changed in ways we don't handle properly so just punt. */
+ complaint (_("unsupported version in .debug_line section"));
+ return NULL;
+ }
+ if (lh->version >= 5)
+ {
+ gdb_byte segment_selector_size;
+
+ /* Skip address size. */
+ read_1_byte (abfd, line_ptr);
+ line_ptr += 1;
+
+ segment_selector_size = read_1_byte (abfd, line_ptr);
+ line_ptr += 1;
+ if (segment_selector_size != 0)
+ {
+ complaint (_("unsupported segment selector size %u "
+ "in .debug_line section"),
+ segment_selector_size);
+ return NULL;
+ }
+ }
+ lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
+ line_ptr += offset_size;
+ lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
+ line_ptr += 1;
+ if (lh->version >= 4)
+ {
+ lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
+ line_ptr += 1;
+ }
+ else
+ lh->maximum_ops_per_instruction = 1;
+
+ if (lh->maximum_ops_per_instruction == 0)
+ {
+ lh->maximum_ops_per_instruction = 1;
+ complaint (_("invalid maximum_ops_per_instruction "
+ "in `.debug_line' section"));
+ }
+
+ lh->default_is_stmt = read_1_byte (abfd, line_ptr);
+ line_ptr += 1;
+ lh->line_base = read_1_signed_byte (abfd, line_ptr);
+ line_ptr += 1;
+ lh->line_range = read_1_byte (abfd, line_ptr);
+ line_ptr += 1;
+ lh->opcode_base = read_1_byte (abfd, line_ptr);
+ line_ptr += 1;
+ lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_base]);
+
+ lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
+ for (i = 1; i < lh->opcode_base; ++i)
+ {
+ lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
+ line_ptr += 1;
+ }
+
+ if (lh->version >= 5)
+ {
+ /* Read directory table. */
+ read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
+ &cu->header,
+ [] (struct line_header *header, const char *name,
+ dir_index d_index, unsigned int mod_time,
+ unsigned int length)
+ {
+ header->add_include_dir (name);
+ });
+
+ /* Read file name table. */
+ read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
+ &cu->header,
+ [] (struct line_header *header, const char *name,
+ dir_index d_index, unsigned int mod_time,
+ unsigned int length)
+ {
+ header->add_file_name (name, d_index, mod_time, length);
+ });
+ }
+ else
+ {
+ /* Read directory table. */
+ while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
+ {
+ line_ptr += bytes_read;
+ lh->add_include_dir (cur_dir);
+ }
+ line_ptr += bytes_read;
+
+ /* Read file name table. */
+ while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
+ {
+ unsigned int mod_time, length;
+ dir_index d_index;
+
+ line_ptr += bytes_read;
+ d_index = (dir_index) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+ line_ptr += bytes_read;
+ mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+ line_ptr += bytes_read;
+ length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+ line_ptr += bytes_read;
+
+ lh->add_file_name (cur_file, d_index, mod_time, length);
+ }
+ line_ptr += bytes_read;
+ }
+ lh->statement_program_start = line_ptr;
+
+ if (line_ptr > (section->buffer + section->size))
+ complaint (_("line number info header doesn't "
+ "fit in `.debug_line' section"));
+
+ return lh;
+}
+
+/* Subroutine of dwarf_decode_lines to simplify it.
+ Return the file name of the psymtab for included file FILE_INDEX
+ in line header LH of PST.
+ COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
+ If space for the result is malloc'd, *NAME_HOLDER will be set.
+ Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
+
+static const char *
+psymtab_include_file_name (const struct line_header *lh, int file_index,
+ const struct partial_symtab *pst,
+ const char *comp_dir,
+ gdb::unique_xmalloc_ptr<char> *name_holder)
+{
+ const file_entry &fe = lh->file_names[file_index];
+ const char *include_name = fe.name;
+ const char *include_name_to_compare = include_name;
+ const char *pst_filename;
+ int file_is_pst;
+
+ const char *dir_name = fe.include_dir (lh);
+
+ gdb::unique_xmalloc_ptr<char> hold_compare;
+ if (!IS_ABSOLUTE_PATH (include_name)
+ && (dir_name != NULL || comp_dir != NULL))
+ {
+ /* Avoid creating a duplicate psymtab for PST.
+ We do this by comparing INCLUDE_NAME and PST_FILENAME.
+ Before we do the comparison, however, we need to account
+ for DIR_NAME and COMP_DIR.
+ First prepend dir_name (if non-NULL). If we still don't
+ have an absolute path prepend comp_dir (if non-NULL).
+ However, the directory we record in the include-file's
+ psymtab does not contain COMP_DIR (to match the
+ corresponding symtab(s)).
+
+ Example:
+
+ bash$ cd /tmp
+ bash$ gcc -g ./hello.c
+ include_name = "hello.c"
+ dir_name = "."
+ DW_AT_comp_dir = comp_dir = "/tmp"
+ DW_AT_name = "./hello.c"
+
+ */
+
+ if (dir_name != NULL)
+ {
+ name_holder->reset (concat (dir_name, SLASH_STRING,
+ include_name, (char *) NULL));
+ include_name = name_holder->get ();
+ include_name_to_compare = include_name;
+ }
+ if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
+ {
+ hold_compare.reset (concat (comp_dir, SLASH_STRING,
+ include_name, (char *) NULL));
+ include_name_to_compare = hold_compare.get ();
+ }
+ }
+
+ pst_filename = pst->filename;
+ gdb::unique_xmalloc_ptr<char> copied_name;
+ if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
+ {
+ copied_name.reset (concat (pst->dirname, SLASH_STRING,
+ pst_filename, (char *) NULL));
+ pst_filename = copied_name.get ();
+ }
+
+ file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
+
+ if (file_is_pst)
+ return NULL;
+ return include_name;
+}
+
+/* State machine to track the state of the line number program. */
+
+class lnp_state_machine
+{
+public:
+ /* Initialize a machine state for the start of a line number
+ program. */
+ lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch, line_header *lh,
+ bool record_lines_p);
+
+ file_entry *current_file ()
+ {
+ /* lh->file_names is 0-based, but the file name numbers in the
+ statement program are 1-based. */
+ return m_line_header->file_name_at (m_file);
+ }
+
+ /* Record the line in the state machine. END_SEQUENCE is true if
+ we're processing the end of a sequence. */
+ void record_line (bool end_sequence);
+
+ /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
+ nop-out rest of the lines in this sequence. */
+ void check_line_address (struct dwarf2_cu *cu,
+ const gdb_byte *line_ptr,
+ CORE_ADDR unrelocated_lowpc, CORE_ADDR address);
+
+ void handle_set_discriminator (unsigned int discriminator)
+ {
+ m_discriminator = discriminator;
+ m_line_has_non_zero_discriminator |= discriminator != 0;
+ }
+
+ /* Handle DW_LNE_set_address. */
+ void handle_set_address (CORE_ADDR baseaddr, CORE_ADDR address)
+ {
+ m_op_index = 0;
+ address += baseaddr;
+ m_address = gdbarch_adjust_dwarf2_line (m_gdbarch, address, false);
+ }
+
+ /* Handle DW_LNS_advance_pc. */
+ void handle_advance_pc (CORE_ADDR adjust);
+
+ /* Handle a special opcode. */
+ void handle_special_opcode (unsigned char op_code);
+
+ /* Handle DW_LNS_advance_line. */
+ void handle_advance_line (int line_delta)
+ {
+ advance_line (line_delta);
+ }
+
+ /* Handle DW_LNS_set_file. */
+ void handle_set_file (file_name_index file);
+
+ /* Handle DW_LNS_negate_stmt. */
+ void handle_negate_stmt ()
+ {
+ m_is_stmt = !m_is_stmt;
+ }
+
+ /* Handle DW_LNS_const_add_pc. */
+ void handle_const_add_pc ();
+
+ /* Handle DW_LNS_fixed_advance_pc. */
+ void handle_fixed_advance_pc (CORE_ADDR addr_adj)
+ {
+ m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
+ m_op_index = 0;
+ }
+
+ /* Handle DW_LNS_copy. */
+ void handle_copy ()
+ {
+ record_line (false);
+ m_discriminator = 0;
+ }
+
+ /* Handle DW_LNE_end_sequence. */
+ void handle_end_sequence ()
+ {
+ m_currently_recording_lines = true;
+ }
+
+private:
+ /* Advance the line by LINE_DELTA. */
+ void advance_line (int line_delta)
+ {
+ m_line += line_delta;
+
+ if (line_delta != 0)
+ m_line_has_non_zero_discriminator = m_discriminator != 0;
+ }
+
+ struct dwarf2_cu *m_cu;
+
+ gdbarch *m_gdbarch;
+
+ /* True if we're recording lines.
+ Otherwise we're building partial symtabs and are just interested in
+ finding include files mentioned by the line number program. */
+ bool m_record_lines_p;
+
+ /* The line number header. */
+ line_header *m_line_header;
+
+ /* These are part of the standard DWARF line number state machine,
+ and initialized according to the DWARF spec. */
+
+ unsigned char m_op_index = 0;
+ /* The line table index (1-based) of the current file. */
+ file_name_index m_file = (file_name_index) 1;
+ unsigned int m_line = 1;
+
+ /* These are initialized in the constructor. */
+
+ CORE_ADDR m_address;
+ bool m_is_stmt;
+ unsigned int m_discriminator;
+
+ /* Additional bits of state we need to track. */
+
+ /* The last file that we called dwarf2_start_subfile for.
+ This is only used for TLLs. */
+ unsigned int m_last_file = 0;
+ /* The last file a line number was recorded for. */
+ struct subfile *m_last_subfile = NULL;
+
+ /* When true, record the lines we decode. */
+ bool m_currently_recording_lines = false;
+
+ /* The last line number that was recorded, used to coalesce
+ consecutive entries for the same line. This can happen, for
+ example, when discriminators are present. PR 17276. */
+ unsigned int m_last_line = 0;
+ bool m_line_has_non_zero_discriminator = false;
+};
+
+void
+lnp_state_machine::handle_advance_pc (CORE_ADDR adjust)
+{
+ CORE_ADDR addr_adj = (((m_op_index + adjust)
+ / m_line_header->maximum_ops_per_instruction)
+ * m_line_header->minimum_instruction_length);
+ m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
+ m_op_index = ((m_op_index + adjust)
+ % m_line_header->maximum_ops_per_instruction);
+}
+
+void
+lnp_state_machine::handle_special_opcode (unsigned char op_code)
+{
+ unsigned char adj_opcode = op_code - m_line_header->opcode_base;
+ CORE_ADDR addr_adj = (((m_op_index
+ + (adj_opcode / m_line_header->line_range))
+ / m_line_header->maximum_ops_per_instruction)
+ * m_line_header->minimum_instruction_length);
+ m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
+ m_op_index = ((m_op_index + (adj_opcode / m_line_header->line_range))
+ % m_line_header->maximum_ops_per_instruction);