+ if ((table->num_dirs % DIR_ALLOC_CHUNK) == 0)
+ {
+ char **tmp;
+ size_t amt;
+
+ amt = table->num_dirs + DIR_ALLOC_CHUNK;
+ amt *= sizeof (char *);
+
+ tmp = (char **) bfd_realloc (table->dirs, amt);
+ if (tmp == NULL)
+ return FALSE;
+ table->dirs = tmp;
+ }
+
+ table->dirs[table->num_dirs++] = cur_dir;
+ return TRUE;
+}
+
+static bfd_boolean
+line_info_add_include_dir_stub (struct line_info_table *table, char *cur_dir,
+ unsigned int dir ATTRIBUTE_UNUSED,
+ unsigned int xtime ATTRIBUTE_UNUSED,
+ unsigned int size ATTRIBUTE_UNUSED)
+{
+ return line_info_add_include_dir (table, cur_dir);
+}
+
+/* Add file to TABLE. CUR_FILE memory ownership is taken by TABLE. */
+
+static bfd_boolean
+line_info_add_file_name (struct line_info_table *table, char *cur_file,
+ unsigned int dir, unsigned int xtime,
+ unsigned int size)
+{
+ if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
+ {
+ struct fileinfo *tmp;
+ size_t amt;
+
+ amt = table->num_files + FILE_ALLOC_CHUNK;
+ amt *= sizeof (struct fileinfo);
+
+ tmp = (struct fileinfo *) bfd_realloc (table->files, amt);
+ if (tmp == NULL)
+ return FALSE;
+ table->files = tmp;
+ }
+
+ table->files[table->num_files].name = cur_file;
+ table->files[table->num_files].dir = dir;
+ table->files[table->num_files].time = xtime;
+ table->files[table->num_files].size = size;
+ table->num_files++;
+ return TRUE;
+}
+
+/* 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 bfd_boolean
+read_formatted_entries (struct comp_unit *unit, bfd_byte **bufp,
+ bfd_byte *buf_end, struct line_info_table *table,
+ bfd_boolean (*callback) (struct line_info_table *table,
+ char *cur_file,
+ unsigned int dir,
+ unsigned int time,
+ unsigned int size))
+{
+ bfd *abfd = unit->abfd;
+ bfd_byte format_count, formati;
+ bfd_vma data_count, datai;
+ bfd_byte *buf = *bufp;
+ bfd_byte *format_header_data;
+ unsigned int bytes_read;
+
+ format_count = read_1_byte (abfd, buf, buf_end);
+ buf += 1;
+ format_header_data = buf;
+ for (formati = 0; formati < format_count; formati++)
+ {
+ _bfd_safe_read_leb128 (abfd, buf, &bytes_read, FALSE, buf_end);
+ buf += bytes_read;
+ _bfd_safe_read_leb128 (abfd, buf, &bytes_read, FALSE, buf_end);
+ buf += bytes_read;
+ }
+
+ data_count = _bfd_safe_read_leb128 (abfd, buf, &bytes_read, FALSE, buf_end);
+ buf += bytes_read;
+ if (format_count == 0 && data_count != 0)
+ {
+ _bfd_error_handler (_("DWARF error: zero format count"));
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
+ /* PR 22210. Paranoia check. Don't bother running the loop
+ if we know that we are going to run out of buffer. */
+ if (data_count > (bfd_vma) (buf_end - buf))
+ {
+ _bfd_error_handler
+ (_("DWARF error: data count (%" PRIx64 ") larger than buffer size"),
+ (uint64_t) data_count);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
+ for (datai = 0; datai < data_count; datai++)
+ {
+ bfd_byte *format = format_header_data;
+ struct fileinfo fe;
+
+ memset (&fe, 0, sizeof fe);
+ for (formati = 0; formati < format_count; formati++)
+ {
+ bfd_vma content_type, form;
+ char *string_trash;
+ char **stringp = &string_trash;
+ unsigned int uint_trash, *uintp = &uint_trash;
+ struct attribute attr;
+
+ content_type = _bfd_safe_read_leb128 (abfd, format, &bytes_read,
+ FALSE, buf_end);
+ format += bytes_read;
+ switch (content_type)
+ {
+ case DW_LNCT_path:
+ stringp = &fe.name;
+ break;
+ case DW_LNCT_directory_index:
+ uintp = &fe.dir;
+ break;
+ case DW_LNCT_timestamp:
+ uintp = &fe.time;
+ break;
+ case DW_LNCT_size:
+ uintp = &fe.size;
+ break;
+ case DW_LNCT_MD5:
+ break;
+ default:
+ _bfd_error_handler
+ (_("DWARF error: unknown format content type %" PRIu64),
+ (uint64_t) content_type);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
+ form = _bfd_safe_read_leb128 (abfd, format, &bytes_read, FALSE,
+ buf_end);
+ format += bytes_read;
+
+ buf = read_attribute_value (&attr, form, 0, unit, buf, buf_end);
+ if (buf == NULL)
+ return FALSE;
+ switch (form)
+ {
+ case DW_FORM_string:
+ case DW_FORM_line_strp:
+ *stringp = attr.u.str;
+ break;
+
+ case DW_FORM_data1:
+ case DW_FORM_data2:
+ case DW_FORM_data4:
+ case DW_FORM_data8:
+ case DW_FORM_udata:
+ *uintp = attr.u.val;
+ break;
+ }
+ }
+
+ if (!callback (table, fe.name, fe.dir, fe.time, fe.size))
+ return FALSE;
+ }
+
+ *bufp = buf;
+ return TRUE;
+}
+
+/* Decode the line number information for UNIT. */
+
+static struct line_info_table*
+decode_line_info (struct comp_unit *unit)
+{
+ bfd *abfd = unit->abfd;
+ struct dwarf2_debug *stash = unit->stash;
+ struct dwarf2_debug_file *file = unit->file;
+ struct line_info_table* table;
+ bfd_byte *line_ptr;
+ bfd_byte *line_end;
+ struct line_head lh;