1*56bb7041Schristos /* DWARF 2 debugging format support for GDB.
2*56bb7041Schristos 
3*56bb7041Schristos    Copyright (C) 1994-2020 Free Software Foundation, Inc.
4*56bb7041Schristos 
5*56bb7041Schristos    This file is part of GDB.
6*56bb7041Schristos 
7*56bb7041Schristos    This program is free software; you can redistribute it and/or modify
8*56bb7041Schristos    it under the terms of the GNU General Public License as published by
9*56bb7041Schristos    the Free Software Foundation; either version 3 of the License, or
10*56bb7041Schristos    (at your option) any later version.
11*56bb7041Schristos 
12*56bb7041Schristos    This program is distributed in the hope that it will be useful,
13*56bb7041Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*56bb7041Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*56bb7041Schristos    GNU General Public License for more details.
16*56bb7041Schristos 
17*56bb7041Schristos    You should have received a copy of the GNU General Public License
18*56bb7041Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19*56bb7041Schristos 
20*56bb7041Schristos #include "defs.h"
21*56bb7041Schristos #include "dwarf2/comp-unit.h"
22*56bb7041Schristos #include "dwarf2/leb.h"
23*56bb7041Schristos #include "dwarf2/line-header.h"
24*56bb7041Schristos #include "dwarf2/read.h"
25*56bb7041Schristos #include "complaints.h"
26*56bb7041Schristos #include "filenames.h"
27*56bb7041Schristos 
28*56bb7041Schristos void
add_include_dir(const char * include_dir)29*56bb7041Schristos line_header::add_include_dir (const char *include_dir)
30*56bb7041Schristos {
31*56bb7041Schristos   if (dwarf_line_debug >= 2)
32*56bb7041Schristos     {
33*56bb7041Schristos       size_t new_size;
34*56bb7041Schristos       if (version >= 5)
35*56bb7041Schristos         new_size = m_include_dirs.size ();
36*56bb7041Schristos       else
37*56bb7041Schristos         new_size = m_include_dirs.size () + 1;
38*56bb7041Schristos       fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
39*56bb7041Schristos 			  new_size, include_dir);
40*56bb7041Schristos     }
41*56bb7041Schristos   m_include_dirs.push_back (include_dir);
42*56bb7041Schristos }
43*56bb7041Schristos 
44*56bb7041Schristos void
add_file_name(const char * name,dir_index d_index,unsigned int mod_time,unsigned int length)45*56bb7041Schristos line_header::add_file_name (const char *name,
46*56bb7041Schristos 			    dir_index d_index,
47*56bb7041Schristos 			    unsigned int mod_time,
48*56bb7041Schristos 			    unsigned int length)
49*56bb7041Schristos {
50*56bb7041Schristos   if (dwarf_line_debug >= 2)
51*56bb7041Schristos     {
52*56bb7041Schristos       size_t new_size;
53*56bb7041Schristos       if (version >= 5)
54*56bb7041Schristos         new_size = file_names_size ();
55*56bb7041Schristos       else
56*56bb7041Schristos         new_size = file_names_size () + 1;
57*56bb7041Schristos       fprintf_unfiltered (gdb_stdlog, "Adding file %zu: %s\n",
58*56bb7041Schristos 			  new_size, name);
59*56bb7041Schristos     }
60*56bb7041Schristos   m_file_names.emplace_back (name, d_index, mod_time, length);
61*56bb7041Schristos }
62*56bb7041Schristos 
63*56bb7041Schristos gdb::unique_xmalloc_ptr<char>
file_file_name(int file)64*56bb7041Schristos line_header::file_file_name (int file) const
65*56bb7041Schristos {
66*56bb7041Schristos   /* Is the file number a valid index into the line header's file name
67*56bb7041Schristos      table?  Remember that file numbers start with one, not zero.  */
68*56bb7041Schristos   if (is_valid_file_index (file))
69*56bb7041Schristos     {
70*56bb7041Schristos       const file_entry *fe = file_name_at (file);
71*56bb7041Schristos 
72*56bb7041Schristos       if (!IS_ABSOLUTE_PATH (fe->name))
73*56bb7041Schristos 	{
74*56bb7041Schristos 	  const char *dir = fe->include_dir (this);
75*56bb7041Schristos 	  if (dir != NULL)
76*56bb7041Schristos 	    return gdb::unique_xmalloc_ptr<char> (concat (dir, SLASH_STRING,
77*56bb7041Schristos 							  fe->name,
78*56bb7041Schristos 							  (char *) NULL));
79*56bb7041Schristos 	}
80*56bb7041Schristos       return make_unique_xstrdup (fe->name);
81*56bb7041Schristos     }
82*56bb7041Schristos   else
83*56bb7041Schristos     {
84*56bb7041Schristos       /* The compiler produced a bogus file number.  We can at least
85*56bb7041Schristos          record the macro definitions made in the file, even if we
86*56bb7041Schristos          won't be able to find the file by name.  */
87*56bb7041Schristos       char fake_name[80];
88*56bb7041Schristos 
89*56bb7041Schristos       xsnprintf (fake_name, sizeof (fake_name),
90*56bb7041Schristos 		 "<bad macro file number %d>", file);
91*56bb7041Schristos 
92*56bb7041Schristos       complaint (_("bad file number in macro information (%d)"),
93*56bb7041Schristos                  file);
94*56bb7041Schristos 
95*56bb7041Schristos       return make_unique_xstrdup (fake_name);
96*56bb7041Schristos     }
97*56bb7041Schristos }
98*56bb7041Schristos 
99*56bb7041Schristos gdb::unique_xmalloc_ptr<char>
file_full_name(int file,const char * comp_dir)100*56bb7041Schristos line_header::file_full_name (int file, const char *comp_dir) const
101*56bb7041Schristos {
102*56bb7041Schristos   /* Is the file number a valid index into the line header's file name
103*56bb7041Schristos      table?  Remember that file numbers start with one, not zero.  */
104*56bb7041Schristos   if (is_valid_file_index (file))
105*56bb7041Schristos     {
106*56bb7041Schristos       gdb::unique_xmalloc_ptr<char> relative = file_file_name (file);
107*56bb7041Schristos 
108*56bb7041Schristos       if (IS_ABSOLUTE_PATH (relative.get ()) || comp_dir == NULL)
109*56bb7041Schristos 	return relative;
110*56bb7041Schristos       return gdb::unique_xmalloc_ptr<char> (concat (comp_dir, SLASH_STRING,
111*56bb7041Schristos 						    relative.get (),
112*56bb7041Schristos 						    (char *) NULL));
113*56bb7041Schristos     }
114*56bb7041Schristos   else
115*56bb7041Schristos     return file_file_name (file);
116*56bb7041Schristos }
117*56bb7041Schristos 
118*56bb7041Schristos static void
dwarf2_statement_list_fits_in_line_number_section_complaint(void)119*56bb7041Schristos dwarf2_statement_list_fits_in_line_number_section_complaint (void)
120*56bb7041Schristos {
121*56bb7041Schristos   complaint (_("statement list doesn't fit in .debug_line section"));
122*56bb7041Schristos }
123*56bb7041Schristos 
124*56bb7041Schristos /* Cover function for read_initial_length.
125*56bb7041Schristos    Returns the length of the object at BUF, and stores the size of the
126*56bb7041Schristos    initial length in *BYTES_READ and stores the size that offsets will be in
127*56bb7041Schristos    *OFFSET_SIZE.
128*56bb7041Schristos    If the initial length size is not equivalent to that specified in
129*56bb7041Schristos    CU_HEADER then issue a complaint.
130*56bb7041Schristos    This is useful when reading non-comp-unit headers.  */
131*56bb7041Schristos 
132*56bb7041Schristos 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)133*56bb7041Schristos read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf,
134*56bb7041Schristos 					const struct comp_unit_head *cu_header,
135*56bb7041Schristos 					unsigned int *bytes_read,
136*56bb7041Schristos 					unsigned int *offset_size)
137*56bb7041Schristos {
138*56bb7041Schristos   LONGEST length = read_initial_length (abfd, buf, bytes_read);
139*56bb7041Schristos 
140*56bb7041Schristos   gdb_assert (cu_header->initial_length_size == 4
141*56bb7041Schristos 	      || cu_header->initial_length_size == 8
142*56bb7041Schristos 	      || cu_header->initial_length_size == 12);
143*56bb7041Schristos 
144*56bb7041Schristos   if (cu_header->initial_length_size != *bytes_read)
145*56bb7041Schristos     complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
146*56bb7041Schristos 
147*56bb7041Schristos   *offset_size = (*bytes_read == 4) ? 4 : 8;
148*56bb7041Schristos   return length;
149*56bb7041Schristos }
150*56bb7041Schristos 
151*56bb7041Schristos /* Read directory or file name entry format, starting with byte of
152*56bb7041Schristos    format count entries, ULEB128 pairs of entry formats, ULEB128 of
153*56bb7041Schristos    entries count and the entries themselves in the described entry
154*56bb7041Schristos    format.  */
155*56bb7041Schristos 
156*56bb7041Schristos static void
read_formatted_entries(dwarf2_per_objfile * 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))157*56bb7041Schristos read_formatted_entries (dwarf2_per_objfile *per_objfile, bfd *abfd,
158*56bb7041Schristos 			const gdb_byte **bufp, struct line_header *lh,
159*56bb7041Schristos 			const struct comp_unit_head *cu_header,
160*56bb7041Schristos 			void (*callback) (struct line_header *lh,
161*56bb7041Schristos 					  const char *name,
162*56bb7041Schristos 					  dir_index d_index,
163*56bb7041Schristos 					  unsigned int mod_time,
164*56bb7041Schristos 					  unsigned int length))
165*56bb7041Schristos {
166*56bb7041Schristos   gdb_byte format_count, formati;
167*56bb7041Schristos   ULONGEST data_count, datai;
168*56bb7041Schristos   const gdb_byte *buf = *bufp;
169*56bb7041Schristos   const gdb_byte *format_header_data;
170*56bb7041Schristos   unsigned int bytes_read;
171*56bb7041Schristos 
172*56bb7041Schristos   format_count = read_1_byte (abfd, buf);
173*56bb7041Schristos   buf += 1;
174*56bb7041Schristos   format_header_data = buf;
175*56bb7041Schristos   for (formati = 0; formati < format_count; formati++)
176*56bb7041Schristos     {
177*56bb7041Schristos       read_unsigned_leb128 (abfd, buf, &bytes_read);
178*56bb7041Schristos       buf += bytes_read;
179*56bb7041Schristos       read_unsigned_leb128 (abfd, buf, &bytes_read);
180*56bb7041Schristos       buf += bytes_read;
181*56bb7041Schristos     }
182*56bb7041Schristos 
183*56bb7041Schristos   data_count = read_unsigned_leb128 (abfd, buf, &bytes_read);
184*56bb7041Schristos   buf += bytes_read;
185*56bb7041Schristos   for (datai = 0; datai < data_count; datai++)
186*56bb7041Schristos     {
187*56bb7041Schristos       const gdb_byte *format = format_header_data;
188*56bb7041Schristos       struct file_entry fe;
189*56bb7041Schristos 
190*56bb7041Schristos       for (formati = 0; formati < format_count; formati++)
191*56bb7041Schristos 	{
192*56bb7041Schristos 	  ULONGEST content_type = read_unsigned_leb128 (abfd, format, &bytes_read);
193*56bb7041Schristos 	  format += bytes_read;
194*56bb7041Schristos 
195*56bb7041Schristos 	  ULONGEST form  = read_unsigned_leb128 (abfd, format, &bytes_read);
196*56bb7041Schristos 	  format += bytes_read;
197*56bb7041Schristos 
198*56bb7041Schristos 	  gdb::optional<const char *> string;
199*56bb7041Schristos 	  gdb::optional<unsigned int> uint;
200*56bb7041Schristos 
201*56bb7041Schristos 	  switch (form)
202*56bb7041Schristos 	    {
203*56bb7041Schristos 	    case DW_FORM_string:
204*56bb7041Schristos 	      string.emplace (read_direct_string (abfd, buf, &bytes_read));
205*56bb7041Schristos 	      buf += bytes_read;
206*56bb7041Schristos 	      break;
207*56bb7041Schristos 
208*56bb7041Schristos 	    case DW_FORM_line_strp:
209*56bb7041Schristos 	      string.emplace
210*56bb7041Schristos 		(per_objfile->read_line_string (buf, cu_header, &bytes_read));
211*56bb7041Schristos 	      buf += bytes_read;
212*56bb7041Schristos 	      break;
213*56bb7041Schristos 
214*56bb7041Schristos 	    case DW_FORM_data1:
215*56bb7041Schristos 	      uint.emplace (read_1_byte (abfd, buf));
216*56bb7041Schristos 	      buf += 1;
217*56bb7041Schristos 	      break;
218*56bb7041Schristos 
219*56bb7041Schristos 	    case DW_FORM_data2:
220*56bb7041Schristos 	      uint.emplace (read_2_bytes (abfd, buf));
221*56bb7041Schristos 	      buf += 2;
222*56bb7041Schristos 	      break;
223*56bb7041Schristos 
224*56bb7041Schristos 	    case DW_FORM_data4:
225*56bb7041Schristos 	      uint.emplace (read_4_bytes (abfd, buf));
226*56bb7041Schristos 	      buf += 4;
227*56bb7041Schristos 	      break;
228*56bb7041Schristos 
229*56bb7041Schristos 	    case DW_FORM_data8:
230*56bb7041Schristos 	      uint.emplace (read_8_bytes (abfd, buf));
231*56bb7041Schristos 	      buf += 8;
232*56bb7041Schristos 	      break;
233*56bb7041Schristos 
234*56bb7041Schristos 	    case DW_FORM_data16:
235*56bb7041Schristos 	      /*  This is used for MD5, but file_entry does not record MD5s. */
236*56bb7041Schristos 	      buf += 16;
237*56bb7041Schristos 	      break;
238*56bb7041Schristos 
239*56bb7041Schristos 	    case DW_FORM_udata:
240*56bb7041Schristos 	      uint.emplace (read_unsigned_leb128 (abfd, buf, &bytes_read));
241*56bb7041Schristos 	      buf += bytes_read;
242*56bb7041Schristos 	      break;
243*56bb7041Schristos 
244*56bb7041Schristos 	    case DW_FORM_block:
245*56bb7041Schristos 	      /* It is valid only for DW_LNCT_timestamp which is ignored by
246*56bb7041Schristos 		 current GDB.  */
247*56bb7041Schristos 	      break;
248*56bb7041Schristos 	    }
249*56bb7041Schristos 
250*56bb7041Schristos 	  switch (content_type)
251*56bb7041Schristos 	    {
252*56bb7041Schristos 	    case DW_LNCT_path:
253*56bb7041Schristos 	      if (string.has_value ())
254*56bb7041Schristos 		fe.name = *string;
255*56bb7041Schristos 	      break;
256*56bb7041Schristos 	    case DW_LNCT_directory_index:
257*56bb7041Schristos 	      if (uint.has_value ())
258*56bb7041Schristos 		fe.d_index = (dir_index) *uint;
259*56bb7041Schristos 	      break;
260*56bb7041Schristos 	    case DW_LNCT_timestamp:
261*56bb7041Schristos 	      if (uint.has_value ())
262*56bb7041Schristos 		fe.mod_time = *uint;
263*56bb7041Schristos 	      break;
264*56bb7041Schristos 	    case DW_LNCT_size:
265*56bb7041Schristos 	      if (uint.has_value ())
266*56bb7041Schristos 		fe.length = *uint;
267*56bb7041Schristos 	      break;
268*56bb7041Schristos 	    case DW_LNCT_MD5:
269*56bb7041Schristos 	      break;
270*56bb7041Schristos 	    default:
271*56bb7041Schristos 	      complaint (_("Unknown format content type %s"),
272*56bb7041Schristos 			 pulongest (content_type));
273*56bb7041Schristos 	    }
274*56bb7041Schristos 	}
275*56bb7041Schristos 
276*56bb7041Schristos       callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length);
277*56bb7041Schristos     }
278*56bb7041Schristos 
279*56bb7041Schristos   *bufp = buf;
280*56bb7041Schristos }
281*56bb7041Schristos 
282*56bb7041Schristos /* See line-header.h.  */
283*56bb7041Schristos 
284*56bb7041Schristos line_header_up
dwarf_decode_line_header(sect_offset sect_off,bool is_dwz,dwarf2_per_objfile * per_objfile,struct dwarf2_section_info * section,const struct comp_unit_head * cu_header)285*56bb7041Schristos dwarf_decode_line_header  (sect_offset sect_off, bool is_dwz,
286*56bb7041Schristos 			   dwarf2_per_objfile *per_objfile,
287*56bb7041Schristos 			   struct dwarf2_section_info *section,
288*56bb7041Schristos 			   const struct comp_unit_head *cu_header)
289*56bb7041Schristos {
290*56bb7041Schristos   const gdb_byte *line_ptr;
291*56bb7041Schristos   unsigned int bytes_read, offset_size;
292*56bb7041Schristos   int i;
293*56bb7041Schristos   const char *cur_dir, *cur_file;
294*56bb7041Schristos 
295*56bb7041Schristos   bfd *abfd = section->get_bfd_owner ();
296*56bb7041Schristos 
297*56bb7041Schristos   /* Make sure that at least there's room for the total_length field.
298*56bb7041Schristos      That could be 12 bytes long, but we're just going to fudge that.  */
299*56bb7041Schristos   if (to_underlying (sect_off) + 4 >= section->size)
300*56bb7041Schristos     {
301*56bb7041Schristos       dwarf2_statement_list_fits_in_line_number_section_complaint ();
302*56bb7041Schristos       return 0;
303*56bb7041Schristos     }
304*56bb7041Schristos 
305*56bb7041Schristos   line_header_up lh (new line_header ());
306*56bb7041Schristos 
307*56bb7041Schristos   lh->sect_off = sect_off;
308*56bb7041Schristos   lh->offset_in_dwz = is_dwz;
309*56bb7041Schristos 
310*56bb7041Schristos   line_ptr = section->buffer + to_underlying (sect_off);
311*56bb7041Schristos 
312*56bb7041Schristos   /* Read in the header.  */
313*56bb7041Schristos   lh->total_length =
314*56bb7041Schristos     read_checked_initial_length_and_offset (abfd, line_ptr, cu_header,
315*56bb7041Schristos 					    &bytes_read, &offset_size);
316*56bb7041Schristos   line_ptr += bytes_read;
317*56bb7041Schristos 
318*56bb7041Schristos   const gdb_byte *start_here = line_ptr;
319*56bb7041Schristos 
320*56bb7041Schristos   if (line_ptr + lh->total_length > (section->buffer + section->size))
321*56bb7041Schristos     {
322*56bb7041Schristos       dwarf2_statement_list_fits_in_line_number_section_complaint ();
323*56bb7041Schristos       return 0;
324*56bb7041Schristos     }
325*56bb7041Schristos   lh->statement_program_end = start_here + lh->total_length;
326*56bb7041Schristos   lh->version = read_2_bytes (abfd, line_ptr);
327*56bb7041Schristos   line_ptr += 2;
328*56bb7041Schristos   if (lh->version > 5)
329*56bb7041Schristos     {
330*56bb7041Schristos       /* This is a version we don't understand.  The format could have
331*56bb7041Schristos 	 changed in ways we don't handle properly so just punt.  */
332*56bb7041Schristos       complaint (_("unsupported version in .debug_line section"));
333*56bb7041Schristos       return NULL;
334*56bb7041Schristos     }
335*56bb7041Schristos   if (lh->version >= 5)
336*56bb7041Schristos     {
337*56bb7041Schristos       gdb_byte segment_selector_size;
338*56bb7041Schristos 
339*56bb7041Schristos       /* Skip address size.  */
340*56bb7041Schristos       read_1_byte (abfd, line_ptr);
341*56bb7041Schristos       line_ptr += 1;
342*56bb7041Schristos 
343*56bb7041Schristos       segment_selector_size = read_1_byte (abfd, line_ptr);
344*56bb7041Schristos       line_ptr += 1;
345*56bb7041Schristos       if (segment_selector_size != 0)
346*56bb7041Schristos 	{
347*56bb7041Schristos 	  complaint (_("unsupported segment selector size %u "
348*56bb7041Schristos 		       "in .debug_line section"),
349*56bb7041Schristos 		     segment_selector_size);
350*56bb7041Schristos 	  return NULL;
351*56bb7041Schristos 	}
352*56bb7041Schristos     }
353*56bb7041Schristos   lh->header_length = read_offset (abfd, line_ptr, offset_size);
354*56bb7041Schristos   line_ptr += offset_size;
355*56bb7041Schristos   lh->statement_program_start = line_ptr + lh->header_length;
356*56bb7041Schristos   lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
357*56bb7041Schristos   line_ptr += 1;
358*56bb7041Schristos   if (lh->version >= 4)
359*56bb7041Schristos     {
360*56bb7041Schristos       lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
361*56bb7041Schristos       line_ptr += 1;
362*56bb7041Schristos     }
363*56bb7041Schristos   else
364*56bb7041Schristos     lh->maximum_ops_per_instruction = 1;
365*56bb7041Schristos 
366*56bb7041Schristos   if (lh->maximum_ops_per_instruction == 0)
367*56bb7041Schristos     {
368*56bb7041Schristos       lh->maximum_ops_per_instruction = 1;
369*56bb7041Schristos       complaint (_("invalid maximum_ops_per_instruction "
370*56bb7041Schristos 		   "in `.debug_line' section"));
371*56bb7041Schristos     }
372*56bb7041Schristos 
373*56bb7041Schristos   lh->default_is_stmt = read_1_byte (abfd, line_ptr);
374*56bb7041Schristos   line_ptr += 1;
375*56bb7041Schristos   lh->line_base = read_1_signed_byte (abfd, line_ptr);
376*56bb7041Schristos   line_ptr += 1;
377*56bb7041Schristos   lh->line_range = read_1_byte (abfd, line_ptr);
378*56bb7041Schristos   line_ptr += 1;
379*56bb7041Schristos   lh->opcode_base = read_1_byte (abfd, line_ptr);
380*56bb7041Schristos   line_ptr += 1;
381*56bb7041Schristos   lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_base]);
382*56bb7041Schristos 
383*56bb7041Schristos   lh->standard_opcode_lengths[0] = 1;  /* This should never be used anyway.  */
384*56bb7041Schristos   for (i = 1; i < lh->opcode_base; ++i)
385*56bb7041Schristos     {
386*56bb7041Schristos       lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
387*56bb7041Schristos       line_ptr += 1;
388*56bb7041Schristos     }
389*56bb7041Schristos 
390*56bb7041Schristos   if (lh->version >= 5)
391*56bb7041Schristos     {
392*56bb7041Schristos       /* Read directory table.  */
393*56bb7041Schristos       read_formatted_entries (per_objfile, abfd, &line_ptr, lh.get (),
394*56bb7041Schristos 			      cu_header,
395*56bb7041Schristos 			      [] (struct line_header *header, const char *name,
396*56bb7041Schristos 				  dir_index d_index, unsigned int mod_time,
397*56bb7041Schristos 				  unsigned int length)
398*56bb7041Schristos 	{
399*56bb7041Schristos 	  header->add_include_dir (name);
400*56bb7041Schristos 	});
401*56bb7041Schristos 
402*56bb7041Schristos       /* Read file name table.  */
403*56bb7041Schristos       read_formatted_entries (per_objfile, abfd, &line_ptr, lh.get (),
404*56bb7041Schristos 			      cu_header,
405*56bb7041Schristos 			      [] (struct line_header *header, const char *name,
406*56bb7041Schristos 				  dir_index d_index, unsigned int mod_time,
407*56bb7041Schristos 				  unsigned int length)
408*56bb7041Schristos 	{
409*56bb7041Schristos 	  header->add_file_name (name, d_index, mod_time, length);
410*56bb7041Schristos 	});
411*56bb7041Schristos     }
412*56bb7041Schristos   else
413*56bb7041Schristos     {
414*56bb7041Schristos       /* Read directory table.  */
415*56bb7041Schristos       while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
416*56bb7041Schristos 	{
417*56bb7041Schristos 	  line_ptr += bytes_read;
418*56bb7041Schristos 	  lh->add_include_dir (cur_dir);
419*56bb7041Schristos 	}
420*56bb7041Schristos       line_ptr += bytes_read;
421*56bb7041Schristos 
422*56bb7041Schristos       /* Read file name table.  */
423*56bb7041Schristos       while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
424*56bb7041Schristos 	{
425*56bb7041Schristos 	  unsigned int mod_time, length;
426*56bb7041Schristos 	  dir_index d_index;
427*56bb7041Schristos 
428*56bb7041Schristos 	  line_ptr += bytes_read;
429*56bb7041Schristos 	  d_index = (dir_index) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
430*56bb7041Schristos 	  line_ptr += bytes_read;
431*56bb7041Schristos 	  mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
432*56bb7041Schristos 	  line_ptr += bytes_read;
433*56bb7041Schristos 	  length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
434*56bb7041Schristos 	  line_ptr += bytes_read;
435*56bb7041Schristos 
436*56bb7041Schristos 	  lh->add_file_name (cur_file, d_index, mod_time, length);
437*56bb7041Schristos 	}
438*56bb7041Schristos       line_ptr += bytes_read;
439*56bb7041Schristos     }
440*56bb7041Schristos 
441*56bb7041Schristos   if (line_ptr > (section->buffer + section->size))
442*56bb7041Schristos     complaint (_("line number info header doesn't "
443*56bb7041Schristos 		 "fit in `.debug_line' section"));
444*56bb7041Schristos 
445*56bb7041Schristos   return lh;
446*56bb7041Schristos }
447