xref: /illumos-gate/usr/src/lib/libdwarf/common/dwarf_line_table_reader_common.h (revision 4d9fdb46b215739778ebc12079842c9905586999)
1 /*
2    Copyright (C) 2000-2006 Silicon Graphics, Inc.  All Rights Reserved.
3    Portions Copyright (C) 2007-2018 David Anderson. All Rights Reserved.
4    Portions Copyright (C) 2010-2012 SN Systems Ltd. All Rights Reserved.
5    Portions Copyright (C) 2015-2015 Google, Inc. All Rights Reserved.
6 
7    This program is free software; you can redistribute it
8    and/or modify it under the terms of version 2.1 of the
9    GNU Lesser General Public License as published by the Free
10    Software Foundation.
11 
12    This program is distributed in the hope that it would be
13    useful, but WITHOUT ANY WARRANTY; without even the implied
14    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    PURPOSE.
16 
17    Further, this software is distributed without any warranty
18    that it is free of the rightful claim of any third person
19    regarding infringement or the like.  Any license provided
20    herein, whether implied or otherwise, applies only to this
21    software file.  Patent licenses, if any, provided herein
22    do not apply to combinations of this program with other
23    software, or any other product whatsoever.
24 
25    You should have received a copy of the GNU Lesser General
26    Public License along with this program; if not, write
27    the Free Software Foundation, Inc., 51 Franklin Street -
28    Fifth Floor, Boston MA 02110-1301, USA.
29 
30 */
31 
32 /*  This is #included twice. Once for
33     libdwarf callers and one for dwarfdump which prints
34     the internals.
35 
36     This way we have just one blob of code that reads
37     the table operations.  */
38 
39 #define TRUE 1
40 #define FALSE 0
41 
42 static unsigned char
43 dwarf_standard_opcode_operand_count[STANDARD_OPERAND_COUNT_TWO_LEVEL] = {
44     /* DWARF2 */
45     0,
46     1, 1, 1, 1,
47     0, 0, 0,
48     1,
49     /* Following are new for DWARF3. */
50     0, 0, 1,
51     /* Experimental opcodes. */
52     1, 2, 0,
53 };
54 
55 /* We have a normal standard opcode base, but
56    an arm compiler emitted a non-standard table!
57    This could lead to problems...
58    ARM C/C++ Compiler, RVCT4.0 [Build 4
59    00] seems to get the table wrong .  */
60 static unsigned char
61 dwarf_arm_standard_opcode_operand_count[STANDARD_OPERAND_COUNT_DWARF3] = {
62     /* DWARF2 */
63     0,
64     1, 1, 1, 1,
65     0, 0, 0,
66     0,  /* <<< --- this is wrong */
67     /* Following are new for DWARF3. */
68     0, 0, 1
69 };
70 
71 /* Rather like memcmp but identifies which value pair
72     mismatches (the return value is non-zero if mismatch,
73     zero if match)..
74     mismatch_entry returns the table index that mismatches.
75     tabval returns the table byte value.
76     lineval returns the value from the line table header.  */
77 static int
operandmismatch(unsigned char * table,unsigned table_length,unsigned char * linetable,unsigned check_count,unsigned * mismatch_entry,unsigned * tabval,unsigned * lineval)78 operandmismatch(unsigned char * table,unsigned table_length,
79     unsigned char *linetable,
80     unsigned check_count,
81     unsigned * mismatch_entry, unsigned * tabval,unsigned *lineval)
82 {
83     unsigned i = 0;
84 
85     /* check_count better be <= table_length */
86     for (i = 0; i<check_count; ++i) {
87         if (i > table_length) {
88             *mismatch_entry = i;
89             *lineval = linetable[i];
90             *tabval = 0; /* No entry present. */
91             /* A kind of mismatch */
92             return  TRUE;
93         }
94         if (table[i] == linetable[i]) {
95             continue;
96         }
97         *mismatch_entry = i;
98         *tabval = table[i];
99         *lineval = linetable[i];
100         return  TRUE;
101     }
102     /* Matches. */
103     return FALSE;
104 }
105 
106 /*  Encapsulates DECODE_LEB128_UWORD_CK
107     so the caller can free resources
108     in case of problems. */
109 static int
read_uword_de(Dwarf_Small ** lp,Dwarf_Unsigned * out_p,Dwarf_Debug dbg,Dwarf_Error * err,Dwarf_Small * lpend)110 read_uword_de(Dwarf_Small **lp,
111     Dwarf_Unsigned *out_p,
112     Dwarf_Debug dbg,
113     Dwarf_Error *err,
114     Dwarf_Small *lpend)
115 {
116     Dwarf_Small *inptr = *lp;
117     Dwarf_Unsigned out = 0;
118     DECODE_LEB128_UWORD_CK(inptr,
119         out,
120         dbg,err,lpend);
121     *lp = inptr;
122     *out_p = out;
123     return DW_DLV_OK;
124 }
125 static int
read_sword_de(Dwarf_Small ** lp,Dwarf_Signed * out_p,Dwarf_Debug dbg,Dwarf_Error * err,Dwarf_Small * lpend)126 read_sword_de(Dwarf_Small **lp,
127     Dwarf_Signed *out_p,
128     Dwarf_Debug dbg,
129     Dwarf_Error *err,
130     Dwarf_Small *lpend)
131 {
132     Dwarf_Small *inptr = *lp;
133     Dwarf_Signed out = 0;
134     DECODE_LEB128_SWORD_CK(inptr,
135         out,
136         dbg,err,lpend);
137     *lp = inptr;
138     *out_p = out;
139     return DW_DLV_OK;
140 }
141 
142 
143 /* Common line table header reading code.
144    Returns DW_DLV_OK, DW_DLV_ERROR.
145    DW_DLV_NO_ENTRY cannot be returned, but callers should
146    assume it is possible.
147 
148    The line_context area must be initialized properly before calling this.
149 
150    Has the side effect of allocating arrays which
151    must be freed (see the Line_Table_Context which
152    holds the pointers to space we allocate here).
153 
154    bogus_bytes_ptr and bogus_bytes are output values which
155    let a print-program notify the user of some surprising bytes
156    after a line table header and before the line table instructions.
157    These can be ignored unless one is printing.
158    And are ignored if NULL passed as the pointer.
159 
160    err_count_out may be NULL, in which case we
161    make no attempt to count checking-type errors.
162    Checking-type errors do not stop us, we just report them.
163 
164    See dw-linetableheader.txt for the ordering of text fields
165    across the various dwarf versions. The code
166    follows this ordering closely.
167 
168    Some of the arguments remaining are in line_context
169    so can be deleted from the
170    argument list (after a close look for correctness).
171 */
172 static int
_dwarf_read_line_table_header(Dwarf_Debug dbg,Dwarf_CU_Context cu_context,Dwarf_Small * section_start,Dwarf_Small * data_start,Dwarf_Unsigned section_length,Dwarf_Small ** updated_data_start_out,Dwarf_Line_Context line_context,Dwarf_Small ** bogus_bytes_ptr,Dwarf_Unsigned * bogus_bytes,Dwarf_Error * err,int * err_count_out)173 _dwarf_read_line_table_header(Dwarf_Debug dbg,
174     Dwarf_CU_Context cu_context,
175     Dwarf_Small * section_start,
176     Dwarf_Small * data_start,
177     Dwarf_Unsigned section_length,
178     Dwarf_Small ** updated_data_start_out,
179     Dwarf_Line_Context  line_context,
180     Dwarf_Small ** bogus_bytes_ptr,
181     Dwarf_Unsigned *bogus_bytes,
182     Dwarf_Error * err,
183     int *err_count_out)
184 {
185     Dwarf_Small *line_ptr = data_start;
186     Dwarf_Small *starting_line_ptr = data_start;
187     Dwarf_Unsigned total_length = 0;
188     int local_length_size = 0;
189     int local_extension_size = 0;
190     Dwarf_Unsigned prologue_length = 0;
191     Dwarf_Half version = 0;
192     Dwarf_Small *section_end = section_start + section_length;
193     Dwarf_Small *line_ptr_end = 0;
194     Dwarf_Small *lp_begin = 0;
195     int res = 0;
196     Dwarf_Unsigned htmp = 0;
197 
198     if (bogus_bytes_ptr) *bogus_bytes_ptr = 0;
199     if (bogus_bytes) *bogus_bytes= 0;
200 
201     line_context->lc_line_ptr_start = starting_line_ptr;
202     /* READ_AREA_LENGTH updates line_ptr for consumed bytes */
203     READ_AREA_LENGTH_CK(dbg, total_length, Dwarf_Unsigned,
204         line_ptr, local_length_size, local_extension_size,
205         err, section_length,section_end);
206     line_ptr_end = line_ptr + total_length;
207     line_context->lc_line_ptr_end = line_ptr_end;
208     line_context->lc_length_field_length = local_length_size +
209         local_extension_size;
210     line_context->lc_section_offset = starting_line_ptr -
211         dbg->de_debug_line.dss_data;
212     /*  ASSERT: line_context->lc_length_field_length == line_ptr
213         -line_context->lc_line_ptr_start; */
214     if (line_ptr_end > section_end) {
215         _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_LENGTH_BAD);
216         return (DW_DLV_ERROR);
217     }
218     line_context->lc_total_length = total_length;
219 
220     /* READ_UNALIGNED_CK(dbg, version, Dwarf_Half,
221         line_ptr, DWARF_HALF_SIZE,
222         err,line_ptr_end); */
223     res = _dwarf_read_unaligned_ck_wrapper(dbg,
224         &htmp,line_ptr,DWARF_HALF_SIZE,line_ptr_end,err);
225     if (res == DW_DLV_ERROR) {
226         return res;
227     }
228     version = htmp;
229 
230     line_context->lc_version_number = version;
231     line_ptr += DWARF_HALF_SIZE;
232     if (version != DW_LINE_VERSION2 &&
233         version != DW_LINE_VERSION3 &&
234         version != DW_LINE_VERSION4 &&
235         version != DW_LINE_VERSION5 &&
236         version != EXPERIMENTAL_LINE_TABLES_VERSION) {
237         _dwarf_error(dbg, err, DW_DLE_VERSION_STAMP_ERROR);
238         return (DW_DLV_ERROR);
239     }
240     if (version == DW_LINE_VERSION5) {
241         if (line_ptr >= line_ptr_end) {
242             _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_LENGTH_BAD);
243             return (DW_DLV_ERROR);
244         }
245         line_context->lc_address_size = *(unsigned char *) line_ptr;
246         line_ptr = line_ptr + sizeof(Dwarf_Small);
247         if (line_ptr >= line_ptr_end) {
248             _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_LENGTH_BAD);
249             return (DW_DLV_ERROR);
250         }
251         line_context->lc_segment_selector_size =
252             *(unsigned char *) line_ptr;
253         line_ptr = line_ptr + sizeof(Dwarf_Small);
254     } else {
255         line_context->lc_address_size = cu_context->cc_address_size;
256         line_context->lc_segment_selector_size =
257             cu_context->cc_segment_selector_size;
258     }
259 
260     READ_UNALIGNED_CK(dbg, prologue_length, Dwarf_Unsigned,
261         line_ptr, local_length_size,
262         err,line_ptr_end);
263     line_context->lc_prologue_length = prologue_length;
264     line_ptr += local_length_size;
265     line_context->lc_line_prologue_start = line_ptr;
266     if (line_ptr >= line_ptr_end) {
267         _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_LENGTH_BAD);
268         return (DW_DLV_ERROR);
269     }
270     line_context->lc_minimum_instruction_length =
271         *(unsigned char *) line_ptr;
272     line_ptr = line_ptr + sizeof(Dwarf_Small);
273 
274     if (version == DW_LINE_VERSION4 ||
275         version == DW_LINE_VERSION5 ||
276         version == EXPERIMENTAL_LINE_TABLES_VERSION) {
277         if (line_ptr >= line_ptr_end) {
278             _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_LENGTH_BAD);
279             return (DW_DLV_ERROR);
280         }
281         line_context->lc_maximum_ops_per_instruction =
282             *(unsigned char *) line_ptr;
283         line_ptr = line_ptr + sizeof(Dwarf_Small);
284     }
285     if (line_ptr >= line_ptr_end) {
286         _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_LENGTH_BAD);
287         return (DW_DLV_ERROR);
288     }
289     line_context->lc_default_is_stmt = *(unsigned char *) line_ptr;
290     line_ptr = line_ptr + sizeof(Dwarf_Small);
291 
292     if (line_ptr >= line_ptr_end) {
293         _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_LENGTH_BAD);
294         return (DW_DLV_ERROR);
295     }
296     line_context->lc_line_base = *(signed char *) line_ptr;
297     line_ptr = line_ptr + sizeof(Dwarf_Sbyte);
298     if(line_ptr >= line_ptr_end) {
299         _dwarf_error(dbg, err, DW_DLE_LINE_OFFSET_BAD);
300         return DW_DLV_ERROR;
301     }
302     line_context->lc_line_range = *(unsigned char *) line_ptr;
303     if (!line_context->lc_line_range) {
304         _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_RANGE_ZERO);
305         return DW_DLV_ERROR;
306     }
307     line_ptr = line_ptr + sizeof(Dwarf_Small);
308     if(line_ptr >= line_ptr_end) {
309         _dwarf_error(dbg, err, DW_DLE_LINE_OFFSET_BAD);
310         return DW_DLV_ERROR;
311     }
312     line_context->lc_opcode_base = *(unsigned char *) line_ptr;
313     line_ptr = line_ptr + sizeof(Dwarf_Small);
314     /*  Set up the array of standard opcode lengths. */
315     /*  We think this works ok even for cross-endian processing of
316         objects.  It might be wrong, we might need to specially process
317         the array of ubyte into host order.  */
318     line_context->lc_opcode_length_table = line_ptr;
319 
320     /*  lc_opcode_base is one greater than the size of the array. */
321     line_ptr += line_context->lc_opcode_base - 1;
322     line_context->lc_std_op_count = line_context->lc_opcode_base -1;
323     if(line_ptr >= line_ptr_end) {
324         _dwarf_error(dbg, err, DW_DLE_LINE_OFFSET_BAD);
325         return DW_DLV_ERROR;
326     }
327     {
328         /*  Determine (as best we can) whether the
329             lc_opcode_length_table holds 9 or 12 standard-conforming
330             entries.  gcc4 upped to DWARF3's 12 without updating the
331             version number.
332             EXPERIMENTAL_LINE_TABLES_VERSION upped to 15.  */
333         unsigned check_count = line_context->lc_std_op_count;
334         unsigned tab_count = sizeof(dwarf_standard_opcode_operand_count);
335 
336         int operand_ck_fail = true;
337         if (line_context->lc_std_op_count > tab_count) {
338             _dwarf_print_header_issue(dbg,
339                 "Too many standard operands in linetable header: ",
340                 data_start,
341                 line_context->lc_std_op_count,
342                 0,0,0,
343                 err_count_out);
344             check_count = tab_count;
345         }
346         {
347             unsigned entrynum = 0;
348             unsigned tabv     = 0;
349             unsigned linetabv     = 0;
350 
351             int mismatch = operandmismatch(
352                 dwarf_standard_opcode_operand_count,
353                 tab_count,
354                 line_context->lc_opcode_length_table,
355                 check_count,&entrynum,&tabv,&linetabv);
356             if (mismatch) {
357                 if (err_count_out) {
358                     _dwarf_print_header_issue(dbg,
359                         "standard-operands did not match, checked",
360                         data_start,
361                         check_count,
362                         entrynum,tabv,linetabv,err_count_out);
363                 }
364                 if (check_count >
365                     sizeof(dwarf_arm_standard_opcode_operand_count)) {
366                     check_count =
367                         sizeof(dwarf_arm_standard_opcode_operand_count);
368                 }
369                 mismatch = operandmismatch(
370                     dwarf_arm_standard_opcode_operand_count,
371                     sizeof(dwarf_arm_standard_opcode_operand_count),
372                     line_context->lc_opcode_length_table,
373                     check_count,&entrynum,&tabv,&linetabv);
374                 if (!mismatch && err_count_out) {
375                     _dwarf_print_header_issue(dbg,
376                         "arm (incorrect) operands in use: ",
377                         data_start,
378                         check_count,
379                         entrynum,tabv,linetabv,err_count_out);
380                 }
381             }
382             if (!mismatch) {
383                 if (version == 2) {
384                     if (line_context->lc_std_op_count ==
385                         STANDARD_OPERAND_COUNT_DWARF3) {
386                         _dwarf_print_header_issue(dbg,
387                             "standard DWARF3 operands matched,"
388                             " but is DWARF2 linetable: count",
389                             data_start,
390                             check_count,
391                             0,0,0, err_count_out);
392                     }
393                 }
394                 operand_ck_fail = false;
395             }
396         }
397         if (operand_ck_fail) {
398             /* Here we are not sure what the lc_std_op_count is. */
399             _dwarf_error(dbg, err, DW_DLE_LINE_NUM_OPERANDS_BAD);
400             return (DW_DLV_ERROR);
401         }
402     }
403     /*  At this point we no longer need to check operand counts. */
404     if(line_ptr >= line_ptr_end) {
405         _dwarf_error(dbg, err, DW_DLE_LINE_OFFSET_BAD);
406         return DW_DLV_ERROR;
407     }
408 
409     if (version < DW_LINE_VERSION5){
410         Dwarf_Unsigned directories_count = 0;
411         Dwarf_Unsigned directories_malloc = 5;
412         line_context->lc_include_directories =
413             malloc(sizeof(Dwarf_Small *) * directories_malloc);
414         if (line_context->lc_include_directories == NULL) {
415             _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
416             return (DW_DLV_ERROR);
417         }
418         memset(line_context->lc_include_directories, 0,
419             sizeof(Dwarf_Small *) * directories_malloc);
420 
421         if (line_ptr >= line_ptr_end) {
422             _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
423             return (DW_DLV_ERROR);
424         }
425         while ((*(char *) line_ptr) != '\0') {
426             if (directories_count >= directories_malloc) {
427                 Dwarf_Unsigned expand = 2 * directories_malloc;
428                 Dwarf_Unsigned bytesalloc = sizeof(Dwarf_Small *) * expand;
429                 Dwarf_Small **newdirs =
430                     realloc(line_context->lc_include_directories,
431                         bytesalloc);
432 
433                 if (!newdirs) {
434                     _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
435                     return (DW_DLV_ERROR);
436                 }
437                 /* Doubled size, zero out second half. */
438                 memset(newdirs + directories_malloc, 0,
439                     sizeof(Dwarf_Small *) * directories_malloc);
440                 directories_malloc = expand;
441                 line_context->lc_include_directories = newdirs;
442             }
443             line_context->lc_include_directories[directories_count] =
444                 line_ptr;
445             res = _dwarf_check_string_valid(dbg,
446                 data_start,line_ptr,line_ptr_end,
447                 DW_DLE_LINE_STRING_BAD,err);
448             if (res != DW_DLV_OK) {
449                 return res;
450             }
451             line_ptr = line_ptr + strlen((char *) line_ptr) + 1;
452             directories_count++;
453             if (line_ptr >= line_ptr_end) {
454                 _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
455                 return (DW_DLV_ERROR);
456             }
457         }
458         line_ptr++;
459         line_context->lc_include_directories_count = directories_count;
460     } else if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
461         /* Empty old style dir entry list. */
462         line_ptr++;
463     } else if (version == DW_LINE_VERSION5) {
464         /* handled below */
465     } else {
466         /* No old style directory entries. */
467     }
468     if(line_ptr > line_ptr_end) {
469         _dwarf_error(dbg, err, DW_DLE_LINE_OFFSET_BAD);
470         return DW_DLV_ERROR;
471     }
472     if (version < DW_LINE_VERSION5) {
473         if (line_ptr >= line_ptr_end) {
474             _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
475             return (DW_DLV_ERROR);
476         }
477         while (*(char *) line_ptr != '\0') {
478             Dwarf_Unsigned utmp;
479             Dwarf_Unsigned dir_index = 0;
480             Dwarf_Unsigned lastmod = 0;
481             Dwarf_Unsigned file_length = 0;
482             int resl = 0;
483             Dwarf_File_Entry currfile  = 0;
484 
485             currfile = (Dwarf_File_Entry)
486                 malloc(sizeof(struct Dwarf_File_Entry_s));
487             if (currfile == NULL) {
488                 _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
489                 return (DW_DLV_ERROR);
490             }
491             memset(currfile,0,sizeof(struct Dwarf_File_Entry_s));
492             /*  Insert early so in case of error we can find
493                 and free the record. */
494             _dwarf_add_to_files_list(line_context,currfile);
495 
496             currfile->fi_file_name = line_ptr;
497             resl = _dwarf_check_string_valid(dbg,
498                 data_start,line_ptr,line_ptr_end,
499                 DW_DLE_LINE_STRING_BAD,err);
500             if (resl != DW_DLV_OK) {
501                 return resl;
502             }
503             line_ptr = line_ptr + strlen((char *) line_ptr) + 1;
504             /*  DECODE_LEB128_UWORD_CK(line_ptr, utmp,dbg,
505                 err,line_ptr_end); */
506             res =  read_uword_de(&line_ptr,&utmp,
507                 dbg,err,line_ptr_end);
508             if (res == DW_DLV_ERROR) {
509                 return DW_DLV_ERROR;
510             }
511             dir_index = (Dwarf_Unsigned) utmp;
512             if (dir_index >
513                 line_context->lc_include_directories_count) {
514                 _dwarf_error(dbg, err, DW_DLE_DIR_INDEX_BAD);
515                 return (DW_DLV_ERROR);
516             }
517             currfile->fi_dir_index = dir_index;
518             currfile->fi_dir_index_present = TRUE;
519 
520             /*DECODE_LEB128_UWORD_CK(line_ptr,lastmod,
521                 dbg,err, line_ptr_end); */
522             res =  read_uword_de( &line_ptr,&lastmod,
523                 dbg,err,line_ptr_end);
524             if (res == DW_DLV_ERROR) {
525                 return DW_DLV_ERROR;
526             }
527 
528 
529             currfile->fi_time_last_mod = lastmod;
530             currfile->fi_time_last_mod_present = TRUE;
531 
532             DECODE_LEB128_UWORD_CK(line_ptr,file_length,
533                 dbg,err, line_ptr_end);
534             currfile->fi_file_length = file_length;
535             currfile->fi_file_length_present = TRUE;
536             if (line_ptr >= line_ptr_end) {
537                 _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
538                 return (DW_DLV_ERROR);
539             }
540         }
541         /* Skip trailing nul byte */
542         ++line_ptr;
543     } else if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
544         if (line_ptr >= line_ptr_end) {
545             _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
546             return (DW_DLV_ERROR);
547         }
548         if (*line_ptr != 0) {
549             _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
550             return (DW_DLV_ERROR);
551         }
552         line_ptr++;
553     } else if (version == 5) {
554         /* handled below */
555     } else {
556         /* No old style filenames entries. */
557     }
558     if(line_ptr > line_ptr_end) {
559         _dwarf_error(dbg, err, DW_DLE_LINE_OFFSET_BAD);
560         return DW_DLV_ERROR;
561     }
562 
563     if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
564         static unsigned char expbytes[5] = {0,0xff,0xff,0x7f, 0x7f };
565         Dwarf_Unsigned logicals_table_offset = 0;
566         Dwarf_Unsigned actuals_table_offset = 0;
567         unsigned i = 0;
568 
569         for ( ; i < 5; ++i) {
570             if (line_ptr >= line_ptr_end) {
571                 _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
572                 return (DW_DLV_ERROR);
573             }
574             if (*line_ptr != expbytes[i]) {
575                 _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
576                 return (DW_DLV_ERROR);
577             }
578             line_ptr++;
579         }
580         READ_UNALIGNED_CK(dbg, logicals_table_offset, Dwarf_Unsigned,
581             line_ptr, local_length_size,err,line_ptr_end);
582         line_context->lc_logicals_table_offset = logicals_table_offset;
583         line_ptr += local_length_size;
584         READ_UNALIGNED_CK(dbg, actuals_table_offset, Dwarf_Unsigned,
585             line_ptr, local_length_size,err,line_ptr_end);
586         line_context->lc_actuals_table_offset = actuals_table_offset;
587         line_ptr += local_length_size;
588         if(line_ptr > line_ptr_end) {
589             _dwarf_error(dbg, err, DW_DLE_LINE_OFFSET_BAD);
590             return DW_DLV_ERROR;
591         }
592     }
593 
594     if (version == DW_LINE_VERSION5 ||
595         version == EXPERIMENTAL_LINE_TABLES_VERSION) {
596         /* DWARF 5.  directory names.*/
597         Dwarf_Unsigned directory_format_count = 0;
598         struct Dwarf_Unsigned_Pair_s * format_values = 0;
599         Dwarf_Unsigned directories_count = 0;
600         Dwarf_Unsigned i = 0;
601         Dwarf_Unsigned j = 0;
602         int dres = 0;
603 
604         if (line_ptr >= line_ptr_end) {
605             _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
606             return (DW_DLV_ERROR);
607         }
608         directory_format_count = *(unsigned char *) line_ptr;
609         line_context->lc_directory_entry_format_count =
610             directory_format_count;
611         line_ptr = line_ptr + sizeof(Dwarf_Small);
612         if (directory_format_count > 0) {
613             format_values = malloc(sizeof(struct Dwarf_Unsigned_Pair_s) *
614                 directory_format_count);
615             if (format_values == NULL) {
616                 _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
617                 return (DW_DLV_ERROR);
618             }
619             for (i = 0; i < directory_format_count; i++) {
620                 dres=read_uword_de(&line_ptr,
621                     &format_values[i].up_first,
622                     dbg,err,line_ptr_end);
623                 if (dres != DW_DLV_OK) {
624                     free(format_values);
625                     format_values = 0;
626                     return dres;
627                 }
628                 dres=read_uword_de(&line_ptr,
629                     &format_values[i].up_second,
630                     dbg,err,line_ptr_end);
631                 if (dres != DW_DLV_OK) {
632                     free(format_values);
633                     format_values = 0;
634                     return dres;
635                 }
636             }
637         }
638         dres = read_uword_de(&line_ptr,&directories_count,
639             dbg,err,line_ptr_end);
640         if (dres != DW_DLV_OK) {
641             free(format_values);
642             format_values = 0;
643             return dres;
644         }
645         line_context->lc_include_directories =
646             malloc(sizeof(Dwarf_Small *) * directories_count);
647         if (line_context->lc_include_directories == NULL) {
648             free(format_values);
649             format_values = 0;
650             _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
651             return (DW_DLV_ERROR);
652         }
653         if (directory_format_count == 0 &&
654             directories_count > 0) {
655             free(format_values);
656             format_values = 0;
657             _dwarf_error_string(dbg, err,
658                 DW_DLE_DIRECTORY_FORMAT_COUNT_VS_DIRECTORIES_MISMATCH,
659                 "DW_DLE_DIRECTORY_FORMAT_COUNT_VS_DIRECTORIES_MISMATCH"
660                 ": format count is zero yet directories count > 0");
661             return (DW_DLV_ERROR);
662         }
663         memset(line_context->lc_include_directories, 0,
664             sizeof(Dwarf_Small *) * directories_count);
665 
666         for(i = 0; i < directories_count; i++) {
667             for (j = 0; j < directory_format_count; j++) {
668 
669                 switch (format_values[j].up_first) {
670                 case DW_LNCT_path: {
671                     char *inc_dir_ptr = 0;
672                     res = _dwarf_decode_line_string_form(dbg,
673                         format_values[j].up_second,
674                         local_length_size,
675                         &line_ptr,
676                         line_ptr_end,
677                         &inc_dir_ptr,
678                         err);
679                     if (res != DW_DLV_OK) {
680                         free(format_values);
681                         format_values = 0;
682                         return res;
683                     }
684                     line_context->lc_include_directories[i] =
685                         (unsigned char *)inc_dir_ptr;
686                     break;
687                 }
688                 default:
689                     free(format_values);
690                     format_values = 0;
691                     _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
692                     return (DW_DLV_ERROR);
693                 }
694             }
695             if (line_ptr > line_ptr_end) {
696                 free(format_values);
697                 format_values = 0;
698                 _dwarf_error(dbg, err,
699                     DW_DLE_LINE_NUMBER_HEADER_ERROR);
700                 return (DW_DLV_ERROR);
701             }
702         }
703         line_context->lc_directory_format_values = format_values;
704         format_values = 0;
705         line_context->lc_include_directories_count = directories_count;
706     }
707 
708     if (version == DW_LINE_VERSION5 ||
709         version == EXPERIMENTAL_LINE_TABLES_VERSION) {
710         /* DWARF 5.  file names.*/
711         struct Dwarf_Unsigned_Pair_s * filename_entry_pairs = 0;
712         Dwarf_Unsigned filename_format_count = 0;
713         Dwarf_Unsigned files_count = 0;
714         Dwarf_Unsigned i = 0;
715         Dwarf_Unsigned j = 0;
716         int dres = 0;
717 
718         if (line_ptr >= line_ptr_end) {
719             _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
720             return (DW_DLV_ERROR);
721         }
722         filename_format_count = *(unsigned char *) line_ptr;
723         line_context->lc_file_name_format_count =
724             filename_format_count;
725         line_ptr = line_ptr + sizeof(Dwarf_Small);
726         filename_entry_pairs = malloc(
727             sizeof(struct Dwarf_Unsigned_Pair_s) *
728             filename_format_count);
729         if (!filename_entry_pairs) {
730             _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
731             return DW_DLV_ERROR;
732         }
733         for (i = 0; i < filename_format_count; i++) {
734             dres=read_uword_de(&line_ptr,&filename_entry_pairs[i].up_first,
735                 dbg,err,line_ptr_end);
736             if (dres != DW_DLV_OK) {
737                 free(filename_entry_pairs);
738                 return dres;
739             }
740             dres=read_uword_de(&line_ptr,&filename_entry_pairs[i].up_second,
741                 dbg,err,line_ptr_end);
742             if (dres != DW_DLV_OK) {
743                 free(filename_entry_pairs);
744                 return dres;
745             }
746         }
747         /* DECODE_LEB128_UWORD_CK(line_ptr, files_count,
748             dbg,err,line_ptr_end); */
749         dres=read_uword_de(&line_ptr,&files_count,
750             dbg,err,line_ptr_end);
751         if (dres != DW_DLV_OK) {
752             free(filename_entry_pairs);
753             return dres;
754         }
755 
756         for (i = 0; i < files_count; i++) {
757             Dwarf_File_Entry curline = 0;
758             curline = (Dwarf_File_Entry)
759                 malloc(sizeof(struct Dwarf_File_Entry_s));
760             if (curline == NULL) {
761                 free(filename_entry_pairs);
762                 _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
763                 return (DW_DLV_ERROR);
764             }
765             memset(curline,0,sizeof(*curline));
766             _dwarf_add_to_files_list(line_context,curline);
767             for(j = 0; j < filename_format_count; j++) {
768                 Dwarf_Unsigned dirindex = 0;
769                 switch (filename_entry_pairs[j].up_first) {
770                 case DW_LNCT_path:
771                     res = _dwarf_decode_line_string_form(dbg,
772                         filename_entry_pairs[j].up_second,
773                         local_length_size,
774                         &line_ptr,
775                         line_ptr_end,
776                         (char **)&curline->fi_file_name,
777                         err);
778                     if (res != DW_DLV_OK) {
779                         free(filename_entry_pairs);
780                         return res;
781                     }
782                     break;
783                 case DW_LNCT_directory_index:
784                     res = _dwarf_decode_line_udata_form(dbg,
785                         filename_entry_pairs[j].up_second,
786                         &line_ptr,
787                         &dirindex,
788                         line_ptr_end,
789                         err);
790                     if (res != DW_DLV_OK) {
791                         free(filename_entry_pairs);
792                         return res;
793                     }
794                     curline->fi_dir_index = dirindex;
795                     curline->fi_dir_index_present = TRUE;
796                     break;
797                 case DW_LNCT_timestamp:
798                     res = _dwarf_decode_line_udata_form(dbg,
799                         filename_entry_pairs[j].up_second,
800                         &line_ptr,
801                         &curline->fi_time_last_mod,
802                         line_ptr_end,
803                         err);
804                     if (res != DW_DLV_OK) {
805                         free(filename_entry_pairs);
806                         return res;
807                     }
808                     curline->fi_time_last_mod_present = TRUE;
809                     break;
810                 case DW_LNCT_size:
811                     res = _dwarf_decode_line_udata_form(dbg,
812                         filename_entry_pairs[j].up_second,
813                         &line_ptr,
814                         &curline->fi_file_length,
815                         line_ptr_end,
816                         err);
817                     if (res != DW_DLV_OK) {
818                         free(filename_entry_pairs);
819                         return res;
820                     }
821                     curline->fi_file_length_present = TRUE;
822                     break;
823                 case DW_LNCT_MD5: { /* form DW_FORM_data16 */
824                     if (filename_entry_pairs[j].up_second !=
825                         DW_FORM_data16) {
826                         free(filename_entry_pairs);
827                         _dwarf_error(dbg, err,DW_DLE_LNCT_MD5_WRONG_FORM);
828                         return  DW_DLV_ERROR;
829                     }
830                     res = _dwarf_extract_data16(dbg,
831                         line_ptr,
832                         line_ptr,
833                         line_ptr_end,
834                         &curline->fi_md5_value,
835                         err);
836                     if (res != DW_DLV_OK) {
837                         free(filename_entry_pairs);
838                         return res;
839                     }
840                     curline->fi_md5_present = TRUE;
841                     line_ptr = line_ptr + sizeof(curline->fi_md5_value);
842                     }
843                     break;
844 
845                 default:
846                     free(filename_entry_pairs);
847                     _dwarf_error(dbg, err,DW_DLE_LINE_NUMBER_HEADER_ERROR);
848                     return (DW_DLV_ERROR);
849                 }
850                 if (line_ptr > line_ptr_end) {
851                     free(filename_entry_pairs);
852                     _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
853                     return (DW_DLV_ERROR);
854                 }
855             }
856         }
857         line_context->lc_file_format_values = filename_entry_pairs;
858         filename_entry_pairs = 0;
859     }
860     /* For two-level line tables, read the subprograms table. */
861     if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
862         Dwarf_Unsigned subprog_format_count = 0;
863         Dwarf_Unsigned *subprog_entry_types = 0;
864         Dwarf_Unsigned *subprog_entry_forms = 0;
865         Dwarf_Unsigned subprogs_count = 0;
866         Dwarf_Unsigned i = 0;
867         Dwarf_Unsigned j = 0;
868         int dres = 0;
869 
870         if (line_ptr > line_ptr_end) {
871             _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
872             return (DW_DLV_ERROR);
873         }
874         subprog_format_count = *(unsigned char *) line_ptr;
875         line_ptr = line_ptr + sizeof(Dwarf_Small);
876         subprog_entry_types = malloc(sizeof(Dwarf_Unsigned) *
877             subprog_format_count);
878         if (subprog_entry_types == NULL) {
879             _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
880             return (DW_DLV_ERROR);
881         }
882         subprog_entry_forms = malloc(sizeof(Dwarf_Unsigned) *
883             subprog_format_count);
884         if (subprog_entry_forms == NULL) {
885             free(subprog_entry_types);
886             _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
887             return (DW_DLV_ERROR);
888         }
889 
890         for (i = 0; i < subprog_format_count; i++) {
891 
892             dres=read_uword_de(&line_ptr,subprog_entry_types+i,
893                 dbg,err,line_ptr_end);
894             if (dres != DW_DLV_OK) {
895                 free(subprog_entry_types);
896                 free(subprog_entry_forms);
897                 return dres;
898             }
899             /* DECODE_LEB128_UWORD_CK(line_ptr, subprog_entry_types[i],
900                 dbg,err,line_ptr_end); */
901             dres=read_uword_de(&line_ptr,subprog_entry_forms+i,
902                 dbg,err,line_ptr_end);
903             if (dres != DW_DLV_OK) {
904                 free(subprog_entry_types);
905                 free(subprog_entry_forms);
906                 return dres;
907             }
908             /* DECODE_LEB128_UWORD_CK(line_ptr, subprog_entry_forms[i],
909                 dbg,err,line_ptr_end); */
910         }
911         /*  DECODE_LEB128_UWORD_CK(line_ptr, subprogs_count,
912             dbg,err,line_ptr_end); */
913         dres=read_uword_de(&line_ptr,&subprogs_count,
914             dbg,err,line_ptr_end);
915         if (dres != DW_DLV_OK) {
916             free(subprog_entry_types);
917             free(subprog_entry_forms);
918             return dres;
919         }
920         line_context->lc_subprogs =
921             malloc(sizeof(struct Dwarf_Subprog_Entry_s) * subprogs_count);
922         if (line_context->lc_subprogs == NULL) {
923             free(subprog_entry_types);
924             free(subprog_entry_forms);
925             _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
926             return (DW_DLV_ERROR);
927         }
928         memset(line_context->lc_subprogs, 0,
929             sizeof(struct Dwarf_Subprog_Entry_s) * subprogs_count);
930         for (i = 0; i < subprogs_count; i++) {
931             struct Dwarf_Subprog_Entry_s *curline =
932                 line_context->lc_subprogs + i;
933             for (j = 0; j < subprog_format_count; j++) {
934                 switch (subprog_entry_types[j]) {
935                 case DW_LNCT_GNU_subprogram_name:
936                     res = _dwarf_decode_line_string_form(dbg,
937                         subprog_entry_forms[j],
938                         local_length_size,
939                         &line_ptr,
940                         line_ptr_end,
941                         (char **)&curline->ds_subprog_name,
942                         err);
943                     if (res != DW_DLV_OK) {
944                         free(subprog_entry_types);
945                         free(subprog_entry_forms);
946                         return res;
947                     }
948                     break;
949                 case DW_LNCT_GNU_decl_file:
950                     res = _dwarf_decode_line_udata_form(dbg,
951                         subprog_entry_forms[j],
952                         &line_ptr,
953                         &curline->ds_decl_file,
954                         line_ptr_end,
955                         err);
956                     if (res != DW_DLV_OK) {
957                         free(subprog_entry_forms);
958                         free(subprog_entry_types);
959                         return res;
960                     }
961                     break;
962                 case DW_LNCT_GNU_decl_line:
963                     res = _dwarf_decode_line_udata_form(dbg,
964                         subprog_entry_forms[j],
965                         &line_ptr,
966                         &curline->ds_decl_line,
967                         line_ptr_end,
968                         err);
969                     if (res != DW_DLV_OK) {
970                         free(subprog_entry_forms);
971                         free(subprog_entry_types);
972                         return res;
973                     }
974                     break;
975                 default:
976                     free(subprog_entry_forms);
977                     free(subprog_entry_types);
978                     _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
979                     return (DW_DLV_ERROR);
980                 }
981                 if (line_ptr >= line_ptr_end) {
982                     free(subprog_entry_types);
983                     free(subprog_entry_forms);
984                     _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
985                     return (DW_DLV_ERROR);
986                 }
987             }
988         }
989 
990         free(subprog_entry_types);
991         free(subprog_entry_forms);
992         line_context->lc_subprogs_count = subprogs_count;
993     }
994     if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
995         lp_begin = line_context->lc_line_prologue_start +
996             line_context->lc_logicals_table_offset;
997     } else {
998         lp_begin = line_context->lc_line_prologue_start +
999             line_context->lc_prologue_length;
1000     }
1001     if(line_ptr > line_ptr_end) {
1002         _dwarf_error(dbg, err, DW_DLE_LINE_OFFSET_BAD);
1003         return DW_DLV_ERROR;
1004     }
1005     if (line_ptr != lp_begin) {
1006         if (line_ptr > lp_begin) {
1007             _dwarf_error(dbg, err, DW_DLE_LINE_PROLOG_LENGTH_BAD);
1008             return (DW_DLV_ERROR);
1009         } else {
1010             /*  Bug in compiler. These
1011                 bytes are really part of the instruction
1012                 stream.  The line_context->lc_prologue_length is
1013                 wrong (12 too high).  */
1014             if (bogus_bytes_ptr) {
1015                 *bogus_bytes_ptr = line_ptr;
1016             }
1017             if (bogus_bytes) {
1018                 /*  How far off things are. We expect the
1019                     value 12 ! */
1020                 *bogus_bytes = (lp_begin - line_ptr);
1021             }
1022         }
1023         /*  Ignore the lp_begin calc. Assume line_ptr right.
1024             Making up for compiler bug. */
1025         lp_begin = line_ptr;
1026     }
1027     line_context->lc_line_ptr_start = lp_begin;
1028     if (line_context->lc_actuals_table_offset) {
1029         /* This means two tables. */
1030         line_context->lc_table_count = 2;
1031     } else {
1032         if (line_context->lc_line_ptr_end > lp_begin) {
1033             line_context->lc_table_count = 1;
1034         } else {
1035             line_context->lc_table_count = 0;
1036         }
1037     }
1038     *updated_data_start_out = lp_begin;
1039     return DW_DLV_OK;
1040 }
1041 
1042 
1043 /*  Read one line table program. For two-level line tables, this
1044     function is called once for each table. */
1045 static int
read_line_table_program(Dwarf_Debug dbg,Dwarf_Small * line_ptr,Dwarf_Small * line_ptr_end,UNUSEDARG Dwarf_Small * orig_line_ptr,Dwarf_Small * section_start,Dwarf_Line_Context line_context,Dwarf_Half address_size,Dwarf_Bool doaddrs,Dwarf_Bool dolines,Dwarf_Bool is_single_table,Dwarf_Bool is_actuals_table,Dwarf_Error * error,UNUSEDARG int * err_count_out)1046 read_line_table_program(Dwarf_Debug dbg,
1047     Dwarf_Small *line_ptr,
1048     Dwarf_Small *line_ptr_end,
1049     UNUSEDARG Dwarf_Small *orig_line_ptr,
1050     Dwarf_Small *section_start,
1051     Dwarf_Line_Context line_context,
1052     Dwarf_Half address_size,
1053     Dwarf_Bool doaddrs, /* Only true if SGI IRIX rqs calling. */
1054     Dwarf_Bool dolines,
1055     Dwarf_Bool is_single_table,
1056     Dwarf_Bool is_actuals_table,
1057     Dwarf_Error *error,
1058     UNUSEDARG int *err_count_out)
1059 {
1060     Dwarf_Unsigned i = 0;
1061     Dwarf_File_Entry cur_file_entry = 0;
1062     Dwarf_Line *logicals = line_context->lc_linebuf_logicals;
1063     Dwarf_Unsigned logicals_count = line_context->lc_linecount_logicals;
1064 
1065     struct Dwarf_Line_Registers_s regs;
1066 
1067     /*  This is a pointer to the current line being added to the line
1068         matrix. */
1069     Dwarf_Line curr_line = 0;
1070 
1071     /*  These variables are used to decode leb128 numbers. Leb128_num
1072         holds the decoded number, and leb128_length is its length in
1073         bytes. */
1074     Dwarf_Unsigned leb128_num = 0;
1075     Dwarf_Signed advance_line = 0;
1076 
1077     /*  This is the operand of the latest fixed_advance_pc extended
1078         opcode. */
1079     Dwarf_Half fixed_advance_pc = 0;
1080 
1081     /*  Counts the number of lines in the line matrix. */
1082     Dwarf_Unsigned line_count = 0;
1083 
1084     /*  This is the length of an extended opcode instr.  */
1085     Dwarf_Unsigned instr_length = 0;
1086 
1087 
1088     /*  Used to chain together pointers to line table entries that are
1089         later used to create a block of Dwarf_Line entries. */
1090     Dwarf_Chain chain_line = NULL;
1091     Dwarf_Chain head_chain = NULL;
1092     Dwarf_Chain curr_chain = NULL;
1093 
1094     /*  This points to a block of Dwarf_Lines, a pointer to which is
1095         returned in linebuf. */
1096     Dwarf_Line *block_line = 0;
1097 
1098     /*  Mark a line record as being DW_LNS_set_address */
1099     Dwarf_Bool is_addr_set = false;
1100 
1101 
1102     /*  Initialize the one state machine variable that depends on the
1103         prefix.  */
1104     _dwarf_set_line_table_regs_default_values(&regs,
1105         line_context->lc_version_number,
1106         line_context->lc_default_is_stmt);
1107 
1108     /* Start of statement program.  */
1109     while (line_ptr < line_ptr_end) {
1110         int type = 0;
1111         Dwarf_Small opcode = 0;
1112 
1113 #ifdef PRINTING_DETAILS
1114         {
1115         dwarfstring m9a;
1116         dwarfstring_constructor(&m9a);
1117         dwarfstring_append_printf_u(&m9a,
1118             " [0x%06" DW_PR_DSx "] ",
1119             (line_ptr - section_start));
1120         _dwarf_printf(dbg,dwarfstring_string(&m9a));
1121         dwarfstring_destructor(&m9a);
1122         }
1123 #endif /* PRINTING_DETAILS */
1124         opcode = *(Dwarf_Small *) line_ptr;
1125         line_ptr++;
1126         /* 'type' is the output */
1127         WHAT_IS_OPCODE(type, opcode, line_context->lc_opcode_base,
1128             line_context->lc_opcode_length_table, line_ptr,
1129             line_context->lc_std_op_count);
1130 
1131         if (type == LOP_DISCARD) {
1132             int oc = 0;
1133             int opcnt = line_context->lc_opcode_length_table[opcode];
1134 #ifdef PRINTING_DETAILS
1135             {
1136             dwarfstring m9b;
1137             dwarfstring_constructor(&m9b);
1138             dwarfstring_append_printf_i(&m9b,
1139                 "*** DWARF CHECK: DISCARD standard opcode %d ",
1140                 opcode);
1141             dwarfstring_append_printf_i(&m9b,
1142                 "with %d operands: not understood.", opcnt);
1143             _dwarf_printf(dbg,dwarfstring_string(&m9b));
1144             *err_count_out += 1;
1145             dwarfstring_destructor(&m9b);
1146             }
1147 #endif /* PRINTING_DETAILS */
1148             for (oc = 0; oc < opcnt; oc++) {
1149                 int ocres = 0;
1150                 /*  Read and discard operands we don't
1151                     understand.
1152                     arbitrary choice of unsigned read.
1153                     signed read would work as well.    */
1154                 UNUSEDARG Dwarf_Unsigned utmp2 = 0;
1155 
1156                 /*  DECODE_LEB128_UWORD_CK(line_ptr, utmp2,
1157                     dbg,error,line_ptr_end); */
1158                 ocres =  read_uword_de( &line_ptr,&utmp2,
1159                     dbg,error,line_ptr_end);
1160                 if (ocres == DW_DLV_ERROR) {
1161                     _dwarf_free_chain_entries(dbg,head_chain,
1162                         line_count);
1163                     if(curr_line) {
1164                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1165                         curr_line = 0;
1166                     }
1167                     return DW_DLV_ERROR;
1168                 }
1169 
1170 
1171 #ifdef PRINTING_DETAILS
1172                 {
1173                 dwarfstring m9e;
1174                 dwarfstring_constructor(&m9e);
1175                 dwarfstring_append_printf_u(&m9e,
1176                     " %" DW_PR_DUu,
1177                     utmp2);
1178                 dwarfstring_append_printf_u(&m9e,
1179                     " (0x%" DW_PR_XZEROS DW_PR_DUx ")",
1180                     utmp2);
1181                 _dwarf_printf(dbg,dwarfstring_string(&m9e));
1182                 dwarfstring_destructor(&m9e);
1183                 }
1184 #endif /* PRINTING_DETAILS */
1185             }
1186 #ifdef PRINTING_DETAILS
1187             _dwarf_printf(dbg,"***\n");
1188 #endif /* PRINTING_DETAILS */
1189         } else if (type == LOP_SPECIAL) {
1190             /*  This op code is a special op in the object, no matter
1191                 that it might fall into the standard op range in this
1192                 compile. That is, these are special opcodes between
1193                 opcode_base and MAX_LINE_OP_CODE.  (including
1194                 opcode_base and MAX_LINE_OP_CODE) */
1195 #ifdef PRINTING_DETAILS
1196             unsigned origop = opcode;
1197 #endif /* PRINTING_DETAILS */
1198             Dwarf_Unsigned operation_advance = 0;
1199 
1200             opcode = opcode - line_context->lc_opcode_base;
1201             operation_advance = (opcode / line_context->lc_line_range);
1202 
1203             if (line_context->lc_maximum_ops_per_instruction < 2) {
1204                 regs.lr_address = regs.lr_address + (operation_advance *
1205                     line_context->lc_minimum_instruction_length);
1206             } else {
1207                 regs.lr_address = regs.lr_address +
1208                     (line_context->lc_minimum_instruction_length *
1209                     ((regs.lr_op_index + operation_advance)/
1210                     line_context->lc_maximum_ops_per_instruction));
1211                 regs.lr_op_index = (regs.lr_op_index +operation_advance)%
1212                     line_context->lc_maximum_ops_per_instruction;
1213             }
1214 
1215             regs.lr_line = regs.lr_line + line_context->lc_line_base +
1216                 opcode % line_context->lc_line_range;
1217             if ((Dwarf_Signed)regs.lr_line < 0) {
1218                 /* Something is badly wrong */
1219                 dwarfstring m;
1220 
1221                 dwarfstring_constructor(&m);
1222                 dwarfstring_append_printf_i(&m,
1223                     "\nERROR: DW_DLE_LINE_TABLE_LINENO_ERROR "
1224                     "The line number computes as %d "
1225                     "and negative line numbers "
1226                     "are not correct.",(Dwarf_Signed)regs.lr_line);
1227                 _dwarf_error_string(dbg, error,
1228                     DW_DLE_LINE_TABLE_LINENO_ERROR,
1229                     dwarfstring_string(&m));
1230                 dwarfstring_destructor(&m);
1231                 regs.lr_line = 0;
1232                 return DW_DLV_ERROR;
1233             }
1234 #ifdef PRINTING_DETAILS
1235             {
1236             dwarfstring ma;
1237             dwarfstring mb;
1238 
1239             dwarfstring_constructor(&ma);
1240             dwarfstring_constructor(&mb);
1241             dwarfstring_append_printf_u(&mb,"Specialop %3u", origop);
1242             _dwarf_printf(dbg,dwarfstring_string(&ma));
1243             dwarfstring_destructor(&ma);
1244             print_line_detail(dbg,dwarfstring_string(&mb),
1245                 opcode,line_count+1, &regs,is_single_table, is_actuals_table);
1246             dwarfstring_destructor(&mb);
1247             dwarfstring_destructor(&ma);
1248             }
1249 #endif /* PRINTING_DETAILS */
1250 
1251             if (dolines) {
1252                 curr_line =
1253                     (Dwarf_Line) _dwarf_get_alloc(dbg, DW_DLA_LINE, 1);
1254                 if (curr_line == NULL) {
1255                     _dwarf_free_chain_entries(dbg,head_chain,line_count);
1256                     _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1257                     return (DW_DLV_ERROR);
1258                 }
1259 
1260                 /* Mark a line record as being DW_LNS_set_address */
1261                 curr_line->li_addr_line.li_l_data.li_is_addr_set =
1262                     is_addr_set;
1263                 is_addr_set = false;
1264                 curr_line->li_address = regs.lr_address;
1265                 curr_line->li_addr_line.li_l_data.li_file =
1266                     (Dwarf_Signed) regs.lr_file;
1267                 curr_line->li_addr_line.li_l_data.li_line =
1268                     (Dwarf_Signed) regs.lr_line;
1269                 curr_line->li_addr_line.li_l_data.li_column =
1270                     (Dwarf_Half) regs.lr_column;
1271                 curr_line->li_addr_line.li_l_data.li_is_stmt =
1272                     regs.lr_is_stmt;
1273                 curr_line->li_addr_line.li_l_data.li_basic_block =
1274                     regs.lr_basic_block;
1275                 curr_line->li_addr_line.li_l_data.li_end_sequence =
1276                     curr_line->li_addr_line.li_l_data.
1277                     li_epilogue_begin = regs.lr_epilogue_begin;
1278                 curr_line->li_addr_line.li_l_data.li_prologue_end =
1279                     regs.lr_prologue_end;
1280                 curr_line->li_addr_line.li_l_data.li_isa = regs.lr_isa;
1281                 curr_line->li_addr_line.li_l_data.li_discriminator =
1282                     regs.lr_discriminator;
1283                 curr_line->li_addr_line.li_l_data.li_call_context =
1284                     regs.lr_call_context;
1285                 curr_line->li_addr_line.li_l_data.li_subprogram =
1286                     regs.lr_subprogram;
1287                 curr_line->li_context = line_context;
1288                 curr_line->li_is_actuals_table = is_actuals_table;
1289                 line_count++;
1290 
1291                 chain_line = (Dwarf_Chain)
1292                     _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
1293                 if (chain_line == NULL) {
1294                     if(curr_line) {
1295                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1296                     }
1297                     _dwarf_free_chain_entries(dbg,head_chain,line_count);
1298                     _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1299                     return (DW_DLV_ERROR);
1300                 }
1301                 chain_line->ch_itemtype = DW_DLA_LINE;
1302                 chain_line->ch_item = curr_line;
1303                 _dwarf_update_chain_list(chain_line,&head_chain,&curr_chain);
1304                 curr_line = 0;
1305             }
1306 
1307             regs.lr_basic_block = false;
1308             regs.lr_prologue_end = false;
1309             regs.lr_epilogue_begin = false;
1310             regs.lr_discriminator = 0;
1311 #ifdef PRINTING_DETAILS
1312 #endif /* PRINTING_DETAILS */
1313         } else if (type == LOP_STANDARD) {
1314 #ifdef PRINTING_DETAILS
1315             dwarfstring mb;
1316 #endif /* PRINTING_DETAILS */
1317 
1318             switch (opcode) {
1319 
1320             case DW_LNS_copy:{
1321 
1322 #ifdef PRINTING_DETAILS
1323                 print_line_detail(dbg,"DW_LNS_copy",
1324                     opcode,line_count+1, &regs,is_single_table, is_actuals_table);
1325 #endif /* PRINTING_DETAILS */
1326                 if (dolines) {
1327                     curr_line = (Dwarf_Line) _dwarf_get_alloc(dbg,
1328                         DW_DLA_LINE, 1);
1329                     if (curr_line == NULL) {
1330                         _dwarf_free_chain_entries(dbg,head_chain,line_count);
1331                         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1332                         return (DW_DLV_ERROR);
1333                     }
1334 
1335                     /* Mark a line record as DW_LNS_set_address */
1336                     curr_line->li_addr_line.li_l_data.li_is_addr_set =
1337                         is_addr_set;
1338                     is_addr_set = false;
1339 
1340                     curr_line->li_address = regs.lr_address;
1341                     curr_line->li_addr_line.li_l_data.li_file =
1342                         (Dwarf_Signed) regs.lr_file;
1343                     curr_line->li_addr_line.li_l_data.li_line =
1344                         (Dwarf_Signed) regs.lr_line;
1345                     curr_line->li_addr_line.li_l_data.li_column =
1346                         (Dwarf_Half) regs.lr_column;
1347                     curr_line->li_addr_line.li_l_data.li_is_stmt =
1348                         regs.lr_is_stmt;
1349                     curr_line->li_addr_line.li_l_data.
1350                         li_basic_block = regs.lr_basic_block;
1351                     curr_line->li_addr_line.li_l_data.
1352                         li_end_sequence = regs.lr_end_sequence;
1353                     curr_line->li_context = line_context;
1354                     curr_line->li_is_actuals_table = is_actuals_table;
1355                     curr_line->li_addr_line.li_l_data.
1356                         li_epilogue_begin = regs.lr_epilogue_begin;
1357                     curr_line->li_addr_line.li_l_data.
1358                         li_prologue_end = regs.lr_prologue_end;
1359                     curr_line->li_addr_line.li_l_data.li_isa = regs.lr_isa;
1360                     curr_line->li_addr_line.li_l_data.li_discriminator =
1361                         regs.lr_discriminator;
1362                     curr_line->li_addr_line.li_l_data.li_call_context =
1363                         regs.lr_call_context;
1364                     curr_line->li_addr_line.li_l_data.li_subprogram =
1365                         regs.lr_subprogram;
1366                     line_count++;
1367 
1368                     chain_line = (Dwarf_Chain)
1369                         _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
1370                     if (chain_line == NULL) {
1371                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1372                         _dwarf_free_chain_entries(dbg,head_chain,
1373                             line_count);
1374                         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1375                         return (DW_DLV_ERROR);
1376                     }
1377                     chain_line->ch_itemtype = DW_DLA_LINE;
1378                     chain_line->ch_item = curr_line;
1379                     _dwarf_update_chain_list(chain_line,&head_chain,
1380                         &curr_chain);
1381                     curr_line = 0;
1382                 }
1383 
1384                 regs.lr_basic_block = false;
1385                 regs.lr_prologue_end = false;
1386                 regs.lr_epilogue_begin = false;
1387                 regs.lr_discriminator = 0;
1388                 }
1389                 break;
1390             case DW_LNS_advance_pc:{
1391                 Dwarf_Unsigned utmp2 = 0;
1392                 int advres = 0;
1393 
1394                 /* DECODE_LEB128_UWORD_CK(line_ptr, utmp2,
1395                     dbg,error,line_ptr_end); */
1396                 advres =  read_uword_de( &line_ptr,&utmp2,
1397                     dbg,error,line_ptr_end);
1398                 if (advres == DW_DLV_ERROR) {
1399                     _dwarf_free_chain_entries(dbg,head_chain,
1400                         line_count);
1401                     if(curr_line) {
1402                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1403                     }
1404                     return DW_DLV_ERROR;
1405                 }
1406 
1407 
1408 
1409 #ifdef PRINTING_DETAILS
1410                 dwarfstring_constructor(&mb);
1411                 dwarfstring_append_printf_i(&mb,
1412                     "DW_LNS_advance_pc val %" DW_PR_DSd,
1413                     utmp2);
1414                 dwarfstring_append_printf_u(&mb,
1415                     " 0x%" DW_PR_XZEROS DW_PR_DUx "\n",
1416                     utmp2);
1417                 _dwarf_printf(dbg,dwarfstring_string(&mb));
1418                 dwarfstring_destructor(&mb);
1419 #endif /* PRINTING_DETAILS */
1420                 leb128_num = utmp2;
1421                 regs.lr_address = regs.lr_address +
1422                     line_context->lc_minimum_instruction_length *
1423                     leb128_num;
1424                 }
1425                 break;
1426             case DW_LNS_advance_line:{
1427                 Dwarf_Signed stmp = 0;
1428                 int alres = 0;
1429 
1430                 /*  DECODE_LEB128_SWORD_CK(line_ptr, stmp,
1431                     dbg,error,line_ptr_end); */
1432                 alres =  read_sword_de( &line_ptr,&stmp,
1433                     dbg,error,line_ptr_end);
1434                 if (alres == DW_DLV_ERROR) {
1435                     _dwarf_free_chain_entries(dbg,head_chain,
1436                         line_count);
1437                     if(curr_line) {
1438                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1439                     }
1440                     return DW_DLV_ERROR;
1441                 }
1442                 advance_line = (Dwarf_Signed) stmp;
1443 
1444 #ifdef PRINTING_DETAILS
1445                 dwarfstring_constructor(&mb);
1446                 dwarfstring_append_printf_i(&mb,
1447                     "DW_LNS_advance_line val %" DW_PR_DSd,
1448                     advance_line);
1449                 dwarfstring_append_printf_u(&mb,
1450                     " 0x%" DW_PR_XZEROS DW_PR_DSx "\n",
1451                     advance_line);
1452                 _dwarf_printf(dbg,dwarfstring_string(&mb));
1453                 dwarfstring_destructor(&mb);
1454 #endif /* PRINTING_DETAILS */
1455                 regs.lr_line = regs.lr_line + advance_line;
1456                 if ((Dwarf_Signed)regs.lr_line < 0) {
1457                     dwarfstring m;
1458 
1459                     dwarfstring_constructor(&m);
1460                     dwarfstring_append_printf_i(&m,
1461                         "\nERROR: DW_DLE_LINE_TABLE_LINENO_ERROR"
1462                         " The line number is %d "
1463                         "and negative line numbers after "
1464                         "DW_LNS_ADVANCE_LINE ",
1465                         (Dwarf_Signed)regs.lr_line);
1466                     dwarfstring_append_printf_i(&m,
1467                         " of %d "
1468                         "are not correct.",stmp);
1469                     _dwarf_error_string(dbg, error,
1470                         DW_DLE_LINE_TABLE_LINENO_ERROR,
1471                         dwarfstring_string(&m));
1472                     dwarfstring_destructor(&m);
1473                     regs.lr_line = 0;
1474                     if(curr_line) {
1475                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1476                     }
1477                     _dwarf_free_chain_entries(dbg,head_chain,line_count);
1478                     return DW_DLV_ERROR;
1479                 }
1480                 }
1481                 break;
1482             case DW_LNS_set_file:{
1483                 Dwarf_Unsigned utmp2 = 0;
1484                 int sfres = 0;
1485 
1486                 /*  DECODE_LEB128_UWORD_CK(line_ptr, utmp2,
1487                     dbg,error,line_ptr_end); */
1488                 sfres =  read_uword_de( &line_ptr,&utmp2,
1489                     dbg,error,line_ptr_end);
1490                 if (sfres == DW_DLV_ERROR) {
1491                     _dwarf_free_chain_entries(dbg,head_chain,
1492                         line_count);
1493                     if(curr_line) {
1494                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1495                     }
1496                     return DW_DLV_ERROR;
1497                 }
1498 
1499                 regs.lr_file = utmp2;
1500 #ifdef PRINTING_DETAILS
1501                 dwarfstring_constructor(&mb);
1502                 dwarfstring_append_printf_i(&mb,
1503                     "DW_LNS_set_file  %ld\n",
1504                     regs.lr_file);
1505                 _dwarf_printf(dbg,dwarfstring_string(&mb));
1506                 dwarfstring_destructor(&mb);
1507 #endif /* PRINTING_DETAILS */
1508                 }
1509                 break;
1510             case DW_LNS_set_column:{
1511                 Dwarf_Unsigned utmp2 = 0;
1512                 int scres = 0;
1513 
1514                 /*  DECODE_LEB128_UWORD_CK(line_ptr, utmp2,
1515                     dbg,error,line_ptr_end); */
1516                 scres =  read_uword_de( &line_ptr,&utmp2,
1517                     dbg,error,line_ptr_end);
1518                 if (scres == DW_DLV_ERROR) {
1519                     _dwarf_free_chain_entries(dbg,head_chain,
1520                         line_count);
1521                     if(curr_line) {
1522                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1523                     }
1524                     return DW_DLV_ERROR;
1525                 }
1526 
1527                 regs.lr_column = utmp2;
1528 #ifdef PRINTING_DETAILS
1529                 dwarfstring_constructor(&mb);
1530 
1531                 dwarfstring_append_printf_i(&mb,
1532                     "DW_LNS_set_column val %" DW_PR_DSd ,
1533                     regs.lr_column);
1534                 dwarfstring_append_printf_u(&mb,
1535                     " 0x%" DW_PR_XZEROS DW_PR_DSx "\n",
1536                     regs.lr_column);
1537                 _dwarf_printf(dbg,dwarfstring_string(&mb));
1538                 dwarfstring_destructor(&mb);
1539 #endif /* PRINTING_DETAILS */
1540                 }
1541                 break;
1542             case DW_LNS_negate_stmt:{
1543                 regs.lr_is_stmt = !regs.lr_is_stmt;
1544 #ifdef PRINTING_DETAILS
1545                 _dwarf_printf(dbg, "DW_LNS_negate_stmt\n");
1546 #endif /* PRINTING_DETAILS */
1547                 }
1548                 break;
1549             case DW_LNS_set_basic_block:{
1550                 regs.lr_basic_block = true;
1551 #ifdef PRINTING_DETAILS
1552                 _dwarf_printf(dbg,
1553                     "DW_LNS_set_basic_block\n");
1554 #endif /* PRINTING_DETAILS */
1555                 }
1556                 break;
1557 
1558             case DW_LNS_const_add_pc:{
1559                 opcode = MAX_LINE_OP_CODE -
1560                     line_context->lc_opcode_base;
1561                 if (line_context->lc_maximum_ops_per_instruction < 2) {
1562                     Dwarf_Unsigned operation_advance =
1563                         (opcode / line_context->lc_line_range);
1564                     regs.lr_address = regs.lr_address +
1565                         line_context->lc_minimum_instruction_length *
1566                             operation_advance;
1567                 } else {
1568                     Dwarf_Unsigned operation_advance =
1569                         (opcode / line_context->lc_line_range);
1570                     regs.lr_address = regs.lr_address +
1571                         line_context->lc_minimum_instruction_length *
1572                         ((regs.lr_op_index + operation_advance)/
1573                         line_context->lc_maximum_ops_per_instruction);
1574                     regs.lr_op_index = (regs.lr_op_index +operation_advance)%
1575                         line_context->lc_maximum_ops_per_instruction;
1576                 }
1577 #ifdef PRINTING_DETAILS
1578                 dwarfstring_constructor(&mb);
1579                 dwarfstring_append_printf_u(&mb,
1580                     "DW_LNS_const_add_pc new address 0x%"
1581                     DW_PR_XZEROS DW_PR_DSx "\n",
1582                     regs.lr_address);
1583                 _dwarf_printf(dbg,dwarfstring_string(&mb));
1584                 dwarfstring_destructor(&mb);
1585 #endif /* PRINTING_DETAILS */
1586                 }
1587                 break;
1588             case DW_LNS_fixed_advance_pc:{
1589                 Dwarf_Unsigned fpc = 0;
1590                 int apres = 0;
1591                 /*READ_UNALIGNED_CK(dbg, fixed_advance_pc,
1592                     Dwarf_Half, line_ptr,
1593                     DWARF_HALF_SIZE,error,line_ptr_end); */
1594                 apres = _dwarf_read_unaligned_ck_wrapper(dbg,
1595                     &fpc,line_ptr,DWARF_HALF_SIZE,line_ptr_end,
1596                     error);
1597                 fixed_advance_pc = fpc;
1598                 if (apres == DW_DLV_ERROR) {
1599                     if(curr_line) {
1600                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1601                     }
1602                     _dwarf_free_chain_entries(dbg,head_chain,
1603                         line_count);
1604                     return apres;
1605                 }
1606                 line_ptr += DWARF_HALF_SIZE;
1607                 if (line_ptr > line_ptr_end) {
1608                     dwarfstring g;
1609                     ptrdiff_t d = 0;
1610 
1611                     d = line_ptr - section_start;
1612                     dwarfstring_constructor(&g);
1613                     dwarfstring_append_printf_u(&g,
1614                         "DW_DLE_LINE_TABLE_BAD reading "
1615                         "DW_LNS_fixed_advance_pc we are "
1616                         "off this line table at section "
1617                         "offset. 0x%x .",
1618                         d);
1619                     _dwarf_error_string(dbg, error,
1620                         DW_DLE_LINE_TABLE_BAD,
1621                         dwarfstring_string(&g));
1622                     dwarfstring_destructor(&g);
1623                     if(curr_line) {
1624                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1625                     }
1626                     _dwarf_free_chain_entries(dbg,head_chain,line_count);
1627                     return DW_DLV_ERROR;
1628                 }
1629                 regs.lr_address = regs.lr_address + fixed_advance_pc;
1630                 regs.lr_op_index = 0;
1631 #ifdef PRINTING_DETAILS
1632                 dwarfstring_constructor(&mb);
1633                 dwarfstring_append_printf_i(&mb,
1634                     "DW_LNS_fixed_advance_pc val %"
1635                     DW_PR_DSd, fixed_advance_pc);
1636                 dwarfstring_append_printf_u(&mb,
1637                     " 0x%" DW_PR_XZEROS DW_PR_DSx,
1638                     fixed_advance_pc);
1639                 dwarfstring_append_printf_u(&mb,
1640                     " new address 0x%"
1641                     DW_PR_XZEROS DW_PR_DSx "\n",
1642                     regs.lr_address);
1643                 _dwarf_printf(dbg,
1644                     dwarfstring_string(&mb));
1645                 dwarfstring_destructor(&mb);
1646 #endif /* PRINTING_DETAILS */
1647                 }
1648                 break;
1649 
1650                 /* New in DWARF3 */
1651             case DW_LNS_set_prologue_end:{
1652                 regs.lr_prologue_end = true;
1653                 }
1654                 break;
1655                 /* New in DWARF3 */
1656             case DW_LNS_set_epilogue_begin:{
1657                 regs.lr_epilogue_begin = true;
1658 #ifdef PRINTING_DETAILS
1659                 _dwarf_printf(dbg,
1660                     "DW_LNS_set_prologue_end set true.\n");
1661 #endif /* PRINTING_DETAILS */
1662                 }
1663                 break;
1664 
1665                 /* New in DWARF3 */
1666             case DW_LNS_set_isa:{
1667                 Dwarf_Unsigned utmp2 = 0;
1668                 int sires = 0;
1669 
1670                 /*  DECODE_LEB128_UWORD_CK(line_ptr, utmp2,
1671                     dbg,error,line_ptr_end); */
1672                 sires =  read_uword_de( &line_ptr,&utmp2,
1673                     dbg,error,line_ptr_end);
1674                 if (sires == DW_DLV_ERROR) {
1675                     _dwarf_free_chain_entries(dbg,head_chain,
1676                         line_count);
1677                     if(curr_line) {
1678                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1679                     }
1680                     return DW_DLV_ERROR;
1681                 }
1682 
1683                 regs.lr_isa = utmp2;
1684 
1685 #ifdef PRINTING_DETAILS
1686                 dwarfstring_constructor(&mb);
1687                 dwarfstring_append_printf_u(&mb,
1688                     "DW_LNS_set_isa new value 0x%"
1689                     DW_PR_XZEROS DW_PR_DUx ".\n",
1690                     utmp2);
1691                 _dwarf_printf(dbg,dwarfstring_string(&mb));
1692                 dwarfstring_destructor(&mb);
1693 #endif /* PRINTING_DETAILS */
1694                 if (regs.lr_isa != utmp2) {
1695                     /*  The value of the isa did
1696                         not fit in our
1697                         local so we record it wrong.
1698                         declare an error. */
1699                     if(curr_line) {
1700                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1701                     }
1702                     _dwarf_free_chain_entries(dbg,head_chain,line_count);
1703                     _dwarf_error(dbg, error,
1704                         DW_DLE_LINE_NUM_OPERANDS_BAD);
1705                     return (DW_DLV_ERROR);
1706                 }
1707                 }
1708                 break;
1709 
1710                 /*  Experimental two-level line tables */
1711                 /*  DW_LNS_set_address_from_logical and
1712                     DW_LNS_set_subprogram
1713                     share the same opcode. Disambiguate by checking
1714                     is_actuals_table. */
1715             case DW_LNS_set_subprogram:
1716 
1717                 if (is_actuals_table) {
1718                     /* DW_LNS_set_address_from_logical */
1719                     Dwarf_Signed stmp = 0;
1720                     int atres = 0;
1721 
1722                     /*  DECODE_LEB128_SWORD_CK(line_ptr, stmp,
1723                         dbg,error,line_ptr_end); */
1724                     atres =  read_sword_de( &line_ptr,&stmp,
1725                         dbg,error,line_ptr_end);
1726                     if (atres == DW_DLV_ERROR) {
1727                         _dwarf_free_chain_entries(dbg,head_chain,
1728                             line_count);
1729                         if(curr_line) {
1730                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1731                         }
1732                         return DW_DLV_ERROR;
1733                     }
1734                     advance_line = (Dwarf_Signed) stmp;
1735                     regs.lr_line = regs.lr_line + advance_line;
1736                     if ((Dwarf_Signed)regs.lr_line < 0) {
1737                         dwarfstring m;
1738 
1739                         dwarfstring_constructor(&m);
1740                         dwarfstring_append_printf_i(&m,
1741                             "\nERROR: DW_DLE_LINE_TABLE_LINENO_ERROR"
1742                             " The line number is %d "
1743                             "and negative line numbers after "
1744                             "DW_LNS_set_subprogram ",
1745                             (Dwarf_Signed)regs.lr_line);
1746                         dwarfstring_append_printf_i(&m,
1747                             " of %d applied "
1748                             "are not correct.",stmp);
1749                         _dwarf_error_string(dbg, error,
1750                             DW_DLE_LINE_TABLE_LINENO_ERROR,
1751                             dwarfstring_string(&m));
1752                         dwarfstring_destructor(&m);
1753                         regs.lr_line = 0;
1754                         _dwarf_free_chain_entries(dbg,head_chain,line_count);
1755                         if(curr_line) {
1756                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1757                         }
1758                         return DW_DLV_ERROR;
1759 
1760                     }
1761                     if (regs.lr_line >= 1 &&
1762                         regs.lr_line - 1 < logicals_count) {
1763                         regs.lr_address =
1764                             logicals[regs.lr_line - 1]->li_address;
1765                         regs.lr_op_index = 0;
1766 #ifdef PRINTING_DETAILS /* block 1 print */
1767                         dwarfstring_constructor(&mb);
1768                         dwarfstring_append_printf_i(&mb,
1769                             "DW_LNS_set_address_from"
1770                             "_logical "
1771                             "%" DW_PR_DSd,
1772                             stmp);
1773                         dwarfstring_append_printf_u(&mb,
1774                             " 0x%" DW_PR_XZEROS DW_PR_DSx,
1775                             stmp);
1776                         dwarfstring_append_printf_u(&mb,
1777                             "  newaddr="
1778                             " 0x%" DW_PR_XZEROS DW_PR_DUx ".\n",
1779                             regs.lr_address);
1780                         _dwarf_printf(dbg,
1781                             dwarfstring_string(&mb));
1782                         dwarfstring_destructor(&mb);
1783 #endif /* PRINTING_DETAILS */
1784                     } else {
1785 #ifdef PRINTING_DETAILS /* block 2 print */
1786                         dwarfstring_constructor(&mb);
1787                         dwarfstring_append_printf_i(&mb,
1788                             "DW_LNS_set_address_from_logical line"
1789                             " is %" DW_PR_DSd ,
1790                             regs.lr_line);
1791                         dwarfstring_append_printf_u(&mb,
1792                             " 0x%" DW_PR_XZEROS DW_PR_DSx ".\n",
1793                             regs.lr_line);
1794                         _dwarf_printf(dbg,
1795                             dwarfstring_string(&mb));
1796                         dwarfstring_destructor(&mb);
1797 #endif /* PRINTING_DETAILS */
1798                     }
1799                 } else {
1800                     /*  DW_LNS_set_subprogram,
1801                         building logicals table.  */
1802                     Dwarf_Unsigned utmp2 = 0;
1803                     int spres = 0;
1804 
1805                     regs.lr_call_context = 0;
1806                     /*  DECODE_LEB128_UWORD_CK(line_ptr, utmp2,
1807                         dbg,error,line_ptr_end); */
1808                     spres =  read_uword_de( &line_ptr,&utmp2,
1809                         dbg,error,line_ptr_end);
1810                     if (spres == DW_DLV_ERROR) {
1811                         _dwarf_free_chain_entries(dbg,head_chain,
1812                             line_count);
1813                         if(curr_line) {
1814                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1815                         }
1816                         return DW_DLV_ERROR;
1817                     }
1818                     regs.lr_subprogram = utmp2;
1819 #ifdef PRINTING_DETAILS /* block 3 print */
1820                     dwarfstring_constructor(&mb);
1821                     dwarfstring_append_printf_i(&mb,
1822                         "DW_LNS_set_subprogram "
1823                         "%" DW_PR_DSd,
1824                         utmp2);
1825                     dwarfstring_append_printf_u(&mb,
1826                         " 0x%" DW_PR_XZEROS DW_PR_DSx "\n",
1827                         utmp2);
1828                     _dwarf_printf(dbg,
1829                         dwarfstring_string(&mb));
1830 #endif /* PRINTING_DETAILS */
1831                 }
1832                 break;
1833                 /* Experimental two-level line tables */
1834             case DW_LNS_inlined_call: {
1835                 Dwarf_Signed stmp = 0;
1836                 Dwarf_Unsigned ilcuw = 0;
1837                 int icres  = 0;
1838 
1839                 /*  DECODE_LEB128_SWORD_CK(line_ptr, stmp,
1840                     dbg,error,line_ptr_end); */
1841                 icres =  read_sword_de( &line_ptr,&stmp,
1842                     dbg,error,line_ptr_end);
1843                 if (icres == DW_DLV_ERROR) {
1844                     _dwarf_free_chain_entries(dbg,head_chain,
1845                         line_count);
1846                     if(curr_line) {
1847                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1848                     }
1849                     return DW_DLV_ERROR;
1850                 }
1851                 regs.lr_call_context = line_count + stmp;
1852                 /*  DECODE_LEB128_UWORD_CK(line_ptr,
1853                     regs.lr_subprogram,
1854                     dbg,error,line_ptr_end); */
1855                 icres =  read_uword_de(&line_ptr,&ilcuw,
1856                     dbg,error,line_ptr_end);
1857                 regs.lr_subprogram = ilcuw;
1858                 if (icres == DW_DLV_ERROR) {
1859                     _dwarf_free_chain_entries(dbg,head_chain,
1860                         line_count);
1861                     if(curr_line) {
1862                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1863                     }
1864                     return DW_DLV_ERROR;
1865                 }
1866 
1867 
1868 #ifdef PRINTING_DETAILS
1869                 dwarfstring_constructor(&mb);
1870                 dwarfstring_append_printf_i(&mb,
1871                     "DW_LNS_inlined_call "
1872                     "%" DW_PR_DSd ,stmp);
1873                 dwarfstring_append_printf_u(&mb,
1874                     " (0x%" DW_PR_XZEROS DW_PR_DSx "),",
1875                     stmp);
1876                 dwarfstring_append_printf_i(&mb,
1877                     "%" DW_PR_DSd,
1878                     regs.lr_subprogram);
1879                 dwarfstring_append_printf_u(&mb,
1880                     " (0x%" DW_PR_XZEROS DW_PR_DSx ")",
1881                     regs.lr_subprogram);
1882                 dwarfstring_append_printf_i(&mb,
1883                     "  callcontext=" "%" DW_PR_DSd ,
1884                     regs.lr_call_context);
1885                 dwarfstring_append_printf_u(&mb,
1886                     " (0x%" DW_PR_XZEROS DW_PR_DSx ")\n",
1887                     regs.lr_call_context);
1888                 _dwarf_printf(dbg,
1889                     dwarfstring_string(&mb));
1890                 dwarfstring_destructor(&mb);
1891 #endif /* PRINTING_DETAILS */
1892                 }
1893                 break;
1894 
1895                 /* Experimental two-level line tables */
1896             case DW_LNS_pop_context: {
1897                 Dwarf_Unsigned logical_num = regs.lr_call_context;
1898                 Dwarf_Chain logical_chain = head_chain;
1899                 Dwarf_Line logical_line = 0;
1900 
1901                 if (logical_num > 0 && logical_num <= line_count) {
1902                     for (i = 1; i < logical_num; i++) {
1903                         logical_chain = logical_chain->ch_next;
1904                     }
1905                     logical_line = (Dwarf_Line) logical_chain->ch_item;
1906                     regs.lr_file =
1907                         logical_line->li_addr_line.li_l_data.li_file;
1908                     regs.lr_line =
1909                         logical_line->li_addr_line.li_l_data.li_line;
1910                     regs.lr_column =
1911                         logical_line->li_addr_line.li_l_data.li_column;
1912                     regs.lr_discriminator =
1913                         logical_line->li_addr_line.li_l_data.li_discriminator;
1914                     regs.lr_is_stmt =
1915                         logical_line->li_addr_line.li_l_data.li_is_stmt;
1916                     regs.lr_call_context =
1917                         logical_line->li_addr_line.li_l_data.li_call_context;
1918                     regs.lr_subprogram =
1919                         logical_line->li_addr_line.li_l_data.li_subprogram;
1920 #ifdef PRINTING_DETAILS
1921                     {
1922                     dwarfstring pcon;
1923                     dwarfstring_constructor(&pcon);
1924                     dwarfstring_append_printf_u(&pcon,
1925                         "DW_LNS_pop_context set"
1926                         " from logical "
1927                         "%" DW_PR_DUu ,logical_num);
1928                     dwarfstring_append_printf_u(&pcon,
1929                         " (0x%" DW_PR_XZEROS DW_PR_DUx ")\n",
1930                         logical_num);
1931                     _dwarf_printf(dbg,
1932                         dwarfstring_string(&pcon));
1933                     dwarfstring_destructor(&pcon);
1934                     }
1935                 } else {
1936                     dwarfstring pcon;
1937                     dwarfstring_constructor(&pcon);
1938                     dwarfstring_append_printf_u(&pcon,
1939                         "DW_LNS_pop_context does nothing, logical"
1940                         "%" DW_PR_DUu ,
1941                         logical_num);
1942                     dwarfstring_append_printf_u(&pcon,
1943                         " (0x%" DW_PR_XZEROS DW_PR_DUx ")\n",
1944                         logical_num);
1945                     _dwarf_printf(dbg,
1946                         dwarfstring_string(&pcon));
1947                     dwarfstring_destructor(&pcon);
1948 #endif /* PRINTING_DETAILS */
1949                 }
1950                 }
1951                 break;
1952             } /* End switch (opcode) */
1953 
1954         } else if (type == LOP_EXTENDED) {
1955             Dwarf_Unsigned utmp3 = 0;
1956             Dwarf_Small ext_opcode = 0;
1957             int leres = 0;
1958 
1959             /*  DECODE_LEB128_UWORD_CK(line_ptr, utmp3,
1960                 dbg,error,line_ptr_end); */
1961             leres =  read_uword_de( &line_ptr,&utmp3,
1962                 dbg,error,line_ptr_end);
1963             if (leres == DW_DLV_ERROR) {
1964                 _dwarf_free_chain_entries(dbg,head_chain,
1965                     line_count);
1966                 if(curr_line) {
1967                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1968                 }
1969                 return DW_DLV_ERROR;
1970             }
1971 
1972             instr_length =  utmp3;
1973             /*  Dwarf_Small is a ubyte and the extended opcode is a
1974                 ubyte, though not stated as clearly in the
1975                 2.0.0 spec as one might hope. */
1976             if (line_ptr >= line_ptr_end) {
1977                 dwarfstring g;
1978                 ptrdiff_t d = 0;
1979 
1980                 d = line_ptr - section_start;
1981                 dwarfstring_constructor(&g);
1982                 dwarfstring_append_printf_u(&g,
1983                     "DW_DLE_LINE_TABLE_BAD reading "
1984                     "extended op we are "
1985                     "off this line table at section "
1986                     "offset 0x%x .",
1987                     d);
1988                 _dwarf_error_string(dbg, error,
1989                     DW_DLE_LINE_TABLE_BAD,
1990                     dwarfstring_string(&g));
1991                 dwarfstring_destructor(&g);
1992                 if(curr_line) {
1993                 dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
1994                 }
1995                 _dwarf_free_chain_entries(dbg,head_chain,line_count);
1996                 return DW_DLV_ERROR;
1997             }
1998             ext_opcode = *(Dwarf_Small *) line_ptr;
1999             line_ptr++;
2000             if (line_ptr > line_ptr_end) {
2001                 dwarfstring g;
2002                 ptrdiff_t d = 0;
2003 
2004                 d = line_ptr - section_start;
2005                 dwarfstring_constructor(&g);
2006                 dwarfstring_append_printf_u(&g,
2007                     "DW_DLE_LINE_TABLE_BAD reading "
2008                     "extended op opcode we are "
2009                     "off this line table at section "
2010                     "offset 0x%x .",
2011                     d);
2012                 _dwarf_error_string(dbg, error,
2013                     DW_DLE_LINE_TABLE_BAD,
2014                     dwarfstring_string(&g));
2015                 dwarfstring_destructor(&g);
2016                 _dwarf_free_chain_entries(dbg,head_chain,line_count);
2017                 if(curr_line) {
2018                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2019                 }
2020                 return DW_DLV_ERROR;
2021             }
2022             switch (ext_opcode) {
2023 
2024             case DW_LNE_end_sequence:{
2025                 regs.lr_end_sequence = true;
2026                 if (dolines) {
2027                     curr_line = (Dwarf_Line)
2028                         _dwarf_get_alloc(dbg, DW_DLA_LINE, 1);
2029                     if (!curr_line) {
2030                         _dwarf_free_chain_entries(dbg,head_chain,
2031                             line_count);
2032                         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
2033                         return (DW_DLV_ERROR);
2034                     }
2035 
2036 #ifdef PRINTING_DETAILS
2037                     print_line_detail(dbg,
2038                         "DW_LNE_end_sequence extended",
2039                         ext_opcode, line_count+1,&regs,
2040                         is_single_table, is_actuals_table);
2041 #endif /* PRINTING_DETAILS */
2042                     curr_line->li_address = regs.lr_address;
2043                     curr_line->li_addr_line.li_l_data.li_file =
2044                         (Dwarf_Signed) regs.lr_file;
2045                     curr_line->li_addr_line.li_l_data.li_line =
2046                         (Dwarf_Signed) regs.lr_line;
2047                     curr_line->li_addr_line.li_l_data.li_column =
2048                         (Dwarf_Half) regs.lr_column;
2049                     curr_line->li_addr_line.li_l_data.li_is_stmt =
2050                         regs.lr_is_stmt;
2051                     curr_line->li_addr_line.li_l_data.
2052                         li_basic_block = regs.lr_basic_block;
2053                     curr_line->li_addr_line.li_l_data.
2054                         li_end_sequence = regs.lr_end_sequence;
2055                     curr_line->li_context = line_context;
2056                     curr_line->li_is_actuals_table = is_actuals_table;
2057                     curr_line->li_addr_line.li_l_data.
2058                         li_epilogue_begin = regs.lr_epilogue_begin;
2059                     curr_line->li_addr_line.li_l_data.
2060                         li_prologue_end = regs.lr_prologue_end;
2061                     curr_line->li_addr_line.li_l_data.li_isa = regs.lr_isa;
2062                     curr_line->li_addr_line.li_l_data.li_discriminator =
2063                         regs.lr_discriminator;
2064                     curr_line->li_addr_line.li_l_data.li_call_context =
2065                         regs.lr_call_context;
2066                     curr_line->li_addr_line.li_l_data.li_subprogram =
2067                         regs.lr_subprogram;
2068                     line_count++;
2069                     chain_line = (Dwarf_Chain)
2070                         _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
2071                     if (chain_line == NULL) {
2072                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2073                         _dwarf_free_chain_entries(dbg,head_chain,line_count);
2074                         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
2075                         return (DW_DLV_ERROR);
2076                     }
2077                     chain_line->ch_itemtype = DW_DLA_LINE;
2078                     chain_line->ch_item = curr_line;
2079                     _dwarf_update_chain_list(chain_line,
2080                         &head_chain,&curr_chain);
2081                     curr_line = 0;
2082                 }
2083                 _dwarf_set_line_table_regs_default_values(&regs,
2084                     line_context->lc_version_number,
2085                     line_context->lc_default_is_stmt);
2086                 }
2087                 break;
2088 
2089             case DW_LNE_set_address:{
2090                 int sares = 0;
2091                 /*  READ_UNALIGNED_CK(dbg, regs.lr_address,
2092                     Dwarf_Addr,
2093                     line_ptr, address_size,error,line_ptr_end); */
2094                 sares = _dwarf_read_unaligned_ck_wrapper(dbg,
2095                     &regs.lr_address,line_ptr,
2096                     address_size,line_ptr_end,
2097                     error);
2098                 if (sares == DW_DLV_ERROR) {
2099                     if(curr_line) {
2100                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2101                     }
2102                     _dwarf_free_chain_entries(dbg,head_chain,
2103                         line_count);
2104                     return sares;
2105                 }
2106 
2107                 /* Mark a line record as being DW_LNS_set_address */
2108                 is_addr_set = true;
2109 #ifdef PRINTING_DETAILS
2110                 {
2111                 dwarfstring sadd;
2112                 dwarfstring_constructor(&sadd);
2113                 dwarfstring_append_printf_u(&sadd,
2114                     "DW_LNE_set_address address 0x%"
2115                     DW_PR_XZEROS DW_PR_DUx "\n",
2116                     regs.lr_address);
2117                 _dwarf_printf(dbg,dwarfstring_string(&sadd));
2118                 dwarfstring_destructor(&sadd);
2119                 }
2120 #endif /* PRINTING_DETAILS */
2121                 if (doaddrs) {
2122                     /* SGI IRIX rqs processing only. */
2123                     curr_line = (Dwarf_Line) _dwarf_get_alloc(dbg,
2124                         DW_DLA_LINE, 1);
2125                     if (!curr_line) {
2126                         _dwarf_free_chain_entries(dbg,head_chain,line_count);
2127                         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
2128                         return (DW_DLV_ERROR);
2129                     }
2130 
2131                     /* Mark a line record as being DW_LNS_set_address */
2132                     curr_line->li_addr_line.li_l_data.li_is_addr_set =
2133                         is_addr_set;
2134                     is_addr_set = false;
2135                     curr_line->li_address = regs.lr_address;
2136 #ifdef __sgi /* SGI IRIX ONLY */
2137                     curr_line->li_addr_line.li_offset =
2138                         line_ptr - dbg->de_debug_line.dss_data;
2139 #endif /* __sgi */
2140                     line_count++;
2141                     chain_line = (Dwarf_Chain)
2142                         _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
2143                     if (chain_line == NULL) {
2144                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2145                         _dwarf_free_chain_entries(dbg,head_chain,line_count);
2146                         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
2147                         return (DW_DLV_ERROR);
2148                     }
2149                     chain_line->ch_itemtype = DW_DLA_LINE;
2150                     chain_line->ch_item = curr_line;
2151                     _dwarf_update_chain_list(chain_line,&head_chain,&curr_chain);
2152                     curr_line = 0;
2153                 }
2154                 regs.lr_op_index = 0;
2155                 line_ptr += address_size;
2156                 if (line_ptr > line_ptr_end) {
2157                     dwarfstring g;
2158                     ptrdiff_t d = 0;
2159 
2160                     d = line_ptr - section_start;
2161                     dwarfstring_constructor(&g);
2162                     dwarfstring_append_printf_u(&g,
2163                         "DW_DLE_LINE_TABLE_BAD reading "
2164                         "DW_LNE_set_address we are "
2165                         "off this line table at section "
2166                         "offset 0x%x .",
2167                         d);
2168                     _dwarf_error_string(dbg, error,
2169                         DW_DLE_LINE_TABLE_BAD,
2170                         dwarfstring_string(&g));
2171                     dwarfstring_destructor(&g);
2172                     if(curr_line) {
2173                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2174                     }
2175                     _dwarf_free_chain_entries(dbg,head_chain,line_count);
2176                     return DW_DLV_ERROR;
2177                 }
2178                 }
2179                 break;
2180 
2181             case DW_LNE_define_file:
2182                 if (dolines) {
2183                     int dlres = 0;
2184                     Dwarf_Unsigned value = 0;
2185 
2186                     cur_file_entry = (Dwarf_File_Entry)
2187                         malloc(sizeof(struct Dwarf_File_Entry_s));
2188                     if (cur_file_entry == NULL) {
2189                         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
2190                         if(curr_line) {
2191                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2192                         }
2193                         _dwarf_free_chain_entries(dbg,head_chain,line_count);
2194                         return DW_DLV_ERROR;
2195                     }
2196                     memset(cur_file_entry,0,
2197                         sizeof(struct Dwarf_File_Entry_s));
2198                     _dwarf_add_to_files_list(line_context,
2199                         cur_file_entry);
2200                     cur_file_entry->fi_file_name =
2201                         (Dwarf_Small *) line_ptr;
2202                     dlres = _dwarf_check_string_valid(dbg,
2203                         line_ptr,line_ptr,line_ptr_end,
2204                         DW_DLE_DEFINE_FILE_STRING_BAD,error);
2205                     if (dlres != DW_DLV_OK) {
2206                         _dwarf_free_chain_entries(dbg,head_chain,
2207                             line_count);
2208                         if(curr_line) {
2209                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2210                         }
2211                         return dlres;
2212                     }
2213                     line_ptr = line_ptr + strlen((char *) line_ptr)
2214                         + 1;
2215                     /*DECODE_LEB128_UWORD_CK(line_ptr,value,
2216                         dbg,error,line_ptr_end); */
2217                     dlres =  read_uword_de( &line_ptr,&value,
2218                         dbg,error,line_ptr_end);
2219                     if (dlres == DW_DLV_ERROR) {
2220                         _dwarf_free_chain_entries(dbg,head_chain,
2221                             line_count);
2222                         if(curr_line) {
2223                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2224                         }
2225                         return DW_DLV_ERROR;
2226                     }
2227                     cur_file_entry->fi_dir_index = (Dwarf_Signed)value;
2228                     cur_file_entry->fi_dir_index_present = TRUE;
2229                     /* DECODE_LEB128_UWORD_CK(line_ptr,value,
2230                         dbg,error,line_ptr_end); */
2231                     dlres =  read_uword_de( &line_ptr,&value,
2232                         dbg,error,line_ptr_end);
2233                     if (dlres == DW_DLV_ERROR) {
2234                         _dwarf_free_chain_entries(dbg,head_chain,
2235                             line_count);
2236                         if(curr_line) {
2237                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2238                         }
2239                         return DW_DLV_ERROR;
2240                     }
2241                     cur_file_entry->fi_time_last_mod = value;
2242                     /*DECODE_LEB128_UWORD_CK(line_ptr,value,
2243                         dbg,error,line_ptr_end); */
2244                     dlres =  read_uword_de( &line_ptr,&value,
2245                         dbg,error,line_ptr_end);
2246                     if (dlres == DW_DLV_ERROR) {
2247                         _dwarf_free_chain_entries(dbg,head_chain,
2248                             line_count);
2249                         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2250                         return DW_DLV_ERROR;
2251                     }
2252                     cur_file_entry->fi_file_length = value;
2253                     cur_file_entry->fi_dir_index_present = TRUE;
2254                     cur_file_entry->fi_time_last_mod_present = TRUE;
2255                     cur_file_entry->fi_file_length_present = TRUE;
2256 #ifdef PRINTING_DETAILS
2257                     {
2258                     dwarfstring m9c;
2259                     dwarfstring_constructor(&m9c);
2260                     dwarfstring_append_printf_s(&m9c,
2261                         "DW_LNE_define_file %s \n",
2262                         (char *)cur_file_entry->fi_file_name);
2263                     dwarfstring_append_printf_i(&m9c,
2264                         "    dir index %d\n",
2265                         (int) cur_file_entry->fi_dir_index);
2266 
2267                     {
2268                         time_t tt3 = (time_t) cur_file_entry->
2269                             fi_time_last_mod;
2270 
2271                         /* ctime supplies newline */
2272                         dwarfstring_append_printf_u(&m9c,
2273                             "    last time 0x%x ",
2274                             (Dwarf_Unsigned)tt3);
2275                         dwarfstring_append_printf_s(&m9c,
2276                             "%s",
2277                             ctime(&tt3));
2278                     }
2279                     dwarfstring_append_printf_i(&m9c,
2280                         "    file length %ld ",
2281                         cur_file_entry->fi_file_length);
2282                     dwarfstring_append_printf_u(&m9c,
2283                         "0x%lx\n",
2284                         cur_file_entry->fi_file_length);
2285                     _dwarf_printf(dbg,dwarfstring_string(&m9c));
2286                     dwarfstring_destructor(&m9c);
2287                     }
2288 #endif /* PRINTING_DETAILS */
2289                 }
2290                 break;
2291             case DW_LNE_set_discriminator:{
2292                 /* New in DWARF4 */
2293                 int sdres = 0;
2294                 Dwarf_Unsigned utmp2 = 0;
2295 
2296                 /*DECODE_LEB128_UWORD_CK(line_ptr, utmp2,
2297                     dbg,error,line_ptr_end); */
2298                 sdres =  read_uword_de( &line_ptr,&utmp2,
2299                     dbg,error,line_ptr_end);
2300                 if (sdres == DW_DLV_ERROR) {
2301                     _dwarf_free_chain_entries(dbg,head_chain,
2302                         line_count);
2303                     if(curr_line) {
2304                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2305                     }
2306                     return DW_DLV_ERROR;
2307                 }
2308                 regs.lr_discriminator = utmp2;
2309 
2310 #ifdef PRINTING_DETAILS
2311                 {
2312                 dwarfstring mk;
2313                 dwarfstring_constructor(&mk);
2314                 dwarfstring_append_printf_u(&mk,
2315                     "DW_LNE_set_discriminator 0x%"
2316                     DW_PR_XZEROS DW_PR_DUx "\n",
2317                     utmp2);
2318                 _dwarf_printf(dbg,dwarfstring_string(&mk));
2319                 dwarfstring_destructor(&mk);
2320                 }
2321 #endif /* PRINTING_DETAILS */
2322                 }
2323                 break;
2324             default:{
2325                 /*  This is an extended op code we do not know about,
2326                     other than we know now many bytes it is
2327                     and the op code and the bytes of operand. */
2328                 Dwarf_Unsigned remaining_bytes = instr_length -1;
2329 
2330                 if (instr_length < 1 ||
2331                     remaining_bytes > DW_LNE_LEN_MAX) {
2332                     dwarfstring g;
2333                     ptrdiff_t d = 0;
2334 
2335                     _dwarf_free_chain_entries(dbg,head_chain,
2336                         line_count);
2337                     d = line_ptr - section_start;
2338                     dwarfstring_constructor(&g);
2339                     dwarfstring_append_printf_u(&g,
2340                         "DW_DLE_LINE_TABLE_BAD reading "
2341                         "unknown DW_LNE_extended op opcode 0x%x ",
2342                         ext_opcode);
2343                     dwarfstring_append_printf_u(&g,
2344                         "we are "
2345                         "off this line table at section "
2346                         "offset 0x%x and ",
2347                         d);
2348                     dwarfstring_append_printf_u(&g,"instruction length"
2349                         "%u.",instr_length);
2350                     _dwarf_error_string(dbg, error,
2351                         DW_DLE_LINE_TABLE_BAD,
2352                         dwarfstring_string(&g));
2353                     dwarfstring_destructor(&g);
2354                     if(curr_line) {
2355                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2356                     }
2357                     _dwarf_free_chain_entries(dbg,head_chain,line_count);
2358                     return DW_DLV_ERROR;
2359                 }
2360 
2361 #ifdef PRINTING_DETAILS
2362                 {
2363                 dwarfstring m9d;
2364                 dwarfstring_constructor(&m9d);
2365                 dwarfstring_append_printf_u(&m9d,
2366                     "DW_LNE extended op 0x%x ",
2367                     ext_opcode);
2368                 dwarfstring_append_printf_u(&m9d,
2369                     "Bytecount: %" DW_PR_DUu ,
2370                     (Dwarf_Unsigned)instr_length);
2371                 if (remaining_bytes > 0) {
2372                     dwarfstring_append(&m9d," linedata: 0x");
2373                     while (remaining_bytes > 0) {
2374                         dwarfstring_append_printf_u(&m9d,
2375                             "%02x",
2376                             (unsigned char)(*(line_ptr)));
2377                         line_ptr++;
2378                         if (line_ptr > line_ptr_end) {
2379                             dwarfstring g;
2380                             ptrdiff_t d = 0;
2381 
2382                             d = line_ptr - section_start;
2383                             dwarfstring_constructor(&g);
2384                             dwarfstring_append_printf_u(&g,
2385                                 "DW_DLE_LINE_TABLE_BAD reading "
2386                                 "DW_LNE extended op remaining bytes "
2387                                 "we are "
2388                                 "off this line table at section "
2389                                 "offset 0x%x .",
2390                                 d);
2391                             _dwarf_error_string(dbg, error,
2392                                 DW_DLE_LINE_TABLE_BAD,
2393                                 dwarfstring_string(&g));
2394                             dwarfstring_destructor(&g);
2395                             dwarfstring_destructor(&m9d);
2396                             if(curr_line) {
2397                             dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2398                             }
2399                             _dwarf_free_chain_entries(dbg,head_chain,line_count);
2400                             return DW_DLV_ERROR;
2401                         }
2402                         remaining_bytes--;
2403                     }
2404                 }
2405                 _dwarf_printf(dbg,dwarfstring_string(&m9d));
2406                 dwarfstring_destructor(&m9d);
2407                 }
2408 #else /* ! PRINTING_DETAILS */
2409                 line_ptr += remaining_bytes;
2410                 if (line_ptr > line_ptr_end) {
2411                     dwarfstring g;
2412                     ptrdiff_t d = 0;
2413 
2414                     d = line_ptr - section_start;
2415                     dwarfstring_constructor(&g);
2416                     dwarfstring_append_printf_u(&g,
2417                         "DW_DLE_LINE_TABLE_BAD reading "
2418                         "DW_LNE extended op remaining bytes "
2419                         "we are "
2420                         "off this line table at section "
2421                         "offset 0x%x .",
2422                         d);
2423                     _dwarf_error_string(dbg, error,
2424                         DW_DLE_LINE_TABLE_BAD,
2425                         dwarfstring_string(&g));
2426                     dwarfstring_destructor(&g);
2427                     if(curr_line) {
2428                     dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2429                     }
2430                     _dwarf_free_chain_entries(dbg,head_chain,line_count);
2431                     return DW_DLV_ERROR;
2432                 }
2433 #endif /* PRINTING_DETAILS */
2434                 _dwarf_printf(dbg,"\n");
2435                 }
2436                 break;
2437             } /* End switch. */
2438         }
2439     }
2440     block_line = (Dwarf_Line *)
2441         _dwarf_get_alloc(dbg, DW_DLA_LIST, line_count);
2442     if (block_line == NULL) {
2443         curr_chain = head_chain;
2444         _dwarf_free_chain_entries(dbg,head_chain,line_count);
2445         if(curr_line) {
2446         dwarf_dealloc(dbg,curr_line,DW_DLA_LINE);
2447         curr_line = 0;
2448         }
2449         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
2450         return (DW_DLV_ERROR);
2451     }
2452 
2453     curr_chain = head_chain;
2454     for (i = 0; i < line_count; i++) {
2455         Dwarf_Chain t = 0;
2456         *(block_line + i) = curr_chain->ch_item;
2457         curr_chain->ch_item = 0;
2458         curr_chain->ch_itemtype = 0;
2459         t = curr_chain;
2460         curr_chain = curr_chain->ch_next;
2461         dwarf_dealloc(dbg, t, DW_DLA_CHAIN);
2462     }
2463 
2464     if (is_single_table || !is_actuals_table) {
2465         line_context->lc_linebuf_logicals = block_line;
2466         line_context->lc_linecount_logicals = line_count;
2467     } else {
2468         line_context->lc_linebuf_actuals = block_line;
2469         line_context->lc_linecount_actuals = line_count;
2470     }
2471 #ifdef PRINTING_DETAILS
2472     {
2473     dwarfstring mc;
2474     dwarfstring_constructor(&mc);
2475     if (is_single_table) {
2476         if(!line_count) {
2477             dwarfstring_append_printf_u(&mc,
2478                 " Line table is present (offset 0x%"
2479                 DW_PR_XZEROS DW_PR_DUx
2480                 ") but no lines present\n",
2481                 line_context->lc_section_offset);
2482         }
2483     } else if (is_actuals_table) {
2484         if(!line_count) {
2485             dwarfstring_append_printf_u(&mc,
2486                 " Line table present (offset 0x%"
2487                 DW_PR_XZEROS DW_PR_DUx
2488                 ") but no actuals lines present\n",
2489                 line_context->lc_section_offset);
2490         }
2491     } else {
2492         if(!line_count) {
2493             dwarfstring_append_printf_u(&mc,
2494                 " Line table present (offset 0x%"
2495                 DW_PR_XZEROS DW_PR_DUx
2496                 ") but no logicals lines present\n",
2497                 line_context->lc_section_offset);
2498         }
2499     }
2500     if (dwarfstring_strlen(&mc)) {
2501         _dwarf_printf(dbg,dwarfstring_string(&mc));
2502     }
2503     dwarfstring_destructor(&mc);
2504     }
2505 #endif /* PRINTING_DETAILS */
2506     return DW_DLV_OK;
2507 }
2508