Debian Codegraph @

src/lib/libdwarf/dwarf_line_table_reader_common.h

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