rdwarf 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +28 -0
  6. data/README.md +39 -0
  7. data/Rakefile +8 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +7 -0
  10. data/ext/rdwarf/depend +5 -0
  11. data/ext/rdwarf/extconf.rb +29 -0
  12. data/ext/rdwarf/libdwarf/CHANGES +102 -0
  13. data/ext/rdwarf/libdwarf/CODINGSTYLE +71 -0
  14. data/ext/rdwarf/libdwarf/COPYING +28 -0
  15. data/ext/rdwarf/libdwarf/ChangeLog +619 -0
  16. data/ext/rdwarf/libdwarf/ChangeLog2006 +835 -0
  17. data/ext/rdwarf/libdwarf/ChangeLog2007 +217 -0
  18. data/ext/rdwarf/libdwarf/ChangeLog2008 +263 -0
  19. data/ext/rdwarf/libdwarf/ChangeLog2009 +348 -0
  20. data/ext/rdwarf/libdwarf/ChangeLog2010 +175 -0
  21. data/ext/rdwarf/libdwarf/ChangeLog2011 +297 -0
  22. data/ext/rdwarf/libdwarf/ChangeLog2012 +131 -0
  23. data/ext/rdwarf/libdwarf/ChangeLog2013 +238 -0
  24. data/ext/rdwarf/libdwarf/ChangeLog2014 +399 -0
  25. data/ext/rdwarf/libdwarf/LGPL.txt +504 -0
  26. data/ext/rdwarf/libdwarf/LIBDWARFCOPYRIGHT +40 -0
  27. data/ext/rdwarf/libdwarf/Makefile.in +220 -0
  28. data/ext/rdwarf/libdwarf/NEWS +535 -0
  29. data/ext/rdwarf/libdwarf/README +235 -0
  30. data/ext/rdwarf/libdwarf/checkexamples.c +1179 -0
  31. data/ext/rdwarf/libdwarf/cmplrs/dwarf_addr_finder.h +55 -0
  32. data/ext/rdwarf/libdwarf/common.c +62 -0
  33. data/ext/rdwarf/libdwarf/common.h +38 -0
  34. data/ext/rdwarf/libdwarf/config.h.in +146 -0
  35. data/ext/rdwarf/libdwarf/configure +5581 -0
  36. data/ext/rdwarf/libdwarf/configure.in +167 -0
  37. data/ext/rdwarf/libdwarf/dw-linetableheader.txt +39 -0
  38. data/ext/rdwarf/libdwarf/dwarf.h +1342 -0
  39. data/ext/rdwarf/libdwarf/dwarf_abbrev.c +291 -0
  40. data/ext/rdwarf/libdwarf/dwarf_abbrev.h +45 -0
  41. data/ext/rdwarf/libdwarf/dwarf_addr_finder.c +676 -0
  42. data/ext/rdwarf/libdwarf/dwarf_alloc.c +685 -0
  43. data/ext/rdwarf/libdwarf/dwarf_alloc.h +38 -0
  44. data/ext/rdwarf/libdwarf/dwarf_arange.c +595 -0
  45. data/ext/rdwarf/libdwarf/dwarf_arange.h +62 -0
  46. data/ext/rdwarf/libdwarf/dwarf_base_types.h +157 -0
  47. data/ext/rdwarf/libdwarf/dwarf_die_deliv.c +1802 -0
  48. data/ext/rdwarf/libdwarf/dwarf_die_deliv.h +46 -0
  49. data/ext/rdwarf/libdwarf/dwarf_elf_access.c +1348 -0
  50. data/ext/rdwarf/libdwarf/dwarf_elf_access.h +46 -0
  51. data/ext/rdwarf/libdwarf/dwarf_error.c +492 -0
  52. data/ext/rdwarf/libdwarf/dwarf_error.h +53 -0
  53. data/ext/rdwarf/libdwarf/dwarf_form.c +1302 -0
  54. data/ext/rdwarf/libdwarf/dwarf_frame.c +2454 -0
  55. data/ext/rdwarf/libdwarf/dwarf_frame.h +418 -0
  56. data/ext/rdwarf/libdwarf/dwarf_frame2.c +1533 -0
  57. data/ext/rdwarf/libdwarf/dwarf_frame3.c +282 -0
  58. data/ext/rdwarf/libdwarf/dwarf_funcs.c +123 -0
  59. data/ext/rdwarf/libdwarf/dwarf_funcs.h +33 -0
  60. data/ext/rdwarf/libdwarf/dwarf_gdbindex.c +520 -0
  61. data/ext/rdwarf/libdwarf/dwarf_gdbindex.h +97 -0
  62. data/ext/rdwarf/libdwarf/dwarf_global.c +612 -0
  63. data/ext/rdwarf/libdwarf/dwarf_global.h +117 -0
  64. data/ext/rdwarf/libdwarf/dwarf_harmless.c +228 -0
  65. data/ext/rdwarf/libdwarf/dwarf_harmless.h +31 -0
  66. data/ext/rdwarf/libdwarf/dwarf_incl.h +61 -0
  67. data/ext/rdwarf/libdwarf/dwarf_init_finish.c +1263 -0
  68. data/ext/rdwarf/libdwarf/dwarf_leb.c +159 -0
  69. data/ext/rdwarf/libdwarf/dwarf_line.c +1822 -0
  70. data/ext/rdwarf/libdwarf/dwarf_line.h +446 -0
  71. data/ext/rdwarf/libdwarf/dwarf_line2.c +98 -0
  72. data/ext/rdwarf/libdwarf/dwarf_line_table_reader_common.c +1583 -0
  73. data/ext/rdwarf/libdwarf/dwarf_loc.c +1525 -0
  74. data/ext/rdwarf/libdwarf/dwarf_loc.h +149 -0
  75. data/ext/rdwarf/libdwarf/dwarf_loc2.c +833 -0
  76. data/ext/rdwarf/libdwarf/dwarf_macro.c +479 -0
  77. data/ext/rdwarf/libdwarf/dwarf_macro.h +35 -0
  78. data/ext/rdwarf/libdwarf/dwarf_opaque.h +778 -0
  79. data/ext/rdwarf/libdwarf/dwarf_original_elf_init.c +219 -0
  80. data/ext/rdwarf/libdwarf/dwarf_print_lines.c +631 -0
  81. data/ext/rdwarf/libdwarf/dwarf_pubtypes.c +132 -0
  82. data/ext/rdwarf/libdwarf/dwarf_query.c +1594 -0
  83. data/ext/rdwarf/libdwarf/dwarf_ranges.c +194 -0
  84. data/ext/rdwarf/libdwarf/dwarf_reloc_arm.h +308 -0
  85. data/ext/rdwarf/libdwarf/dwarf_reloc_mips.h +117 -0
  86. data/ext/rdwarf/libdwarf/dwarf_reloc_ppc.h +242 -0
  87. data/ext/rdwarf/libdwarf/dwarf_reloc_ppc64.h +272 -0
  88. data/ext/rdwarf/libdwarf/dwarf_reloc_x86_64.h +127 -0
  89. data/ext/rdwarf/libdwarf/dwarf_sort_line.c +665 -0
  90. data/ext/rdwarf/libdwarf/dwarf_string.c +82 -0
  91. data/ext/rdwarf/libdwarf/dwarf_stubs.c +38 -0
  92. data/ext/rdwarf/libdwarf/dwarf_tied.c +423 -0
  93. data/ext/rdwarf/libdwarf/dwarf_tsearch.h +125 -0
  94. data/ext/rdwarf/libdwarf/dwarf_tsearchhash.c +675 -0
  95. data/ext/rdwarf/libdwarf/dwarf_types.c +121 -0
  96. data/ext/rdwarf/libdwarf/dwarf_types.h +32 -0
  97. data/ext/rdwarf/libdwarf/dwarf_util.c +913 -0
  98. data/ext/rdwarf/libdwarf/dwarf_util.h +324 -0
  99. data/ext/rdwarf/libdwarf/dwarf_vars.c +125 -0
  100. data/ext/rdwarf/libdwarf/dwarf_vars.h +29 -0
  101. data/ext/rdwarf/libdwarf/dwarf_weaks.c +123 -0
  102. data/ext/rdwarf/libdwarf/dwarf_weaks.h +29 -0
  103. data/ext/rdwarf/libdwarf/dwarf_xu_index.c +579 -0
  104. data/ext/rdwarf/libdwarf/dwarf_xu_index.h +68 -0
  105. data/ext/rdwarf/libdwarf/dwgetopt.c +181 -0
  106. data/ext/rdwarf/libdwarf/dwgetopt.h +51 -0
  107. data/ext/rdwarf/libdwarf/gennames.c +531 -0
  108. data/ext/rdwarf/libdwarf/install.sh +119 -0
  109. data/ext/rdwarf/libdwarf/libdwarf.h.in +3746 -0
  110. data/ext/rdwarf/libdwarf/libdwarf2.1.mm +9805 -0
  111. data/ext/rdwarf/libdwarf/libdwarf2.1.pdf +0 -0
  112. data/ext/rdwarf/libdwarf/libdwarf2p.1.mm +2807 -0
  113. data/ext/rdwarf/libdwarf/libdwarf2p.1.pdf +0 -0
  114. data/ext/rdwarf/libdwarf/libdwarfdefs.h +81 -0
  115. data/ext/rdwarf/libdwarf/malloc_check.c +327 -0
  116. data/ext/rdwarf/libdwarf/malloc_check.h +52 -0
  117. data/ext/rdwarf/libdwarf/mips_extensions.mm +1266 -0
  118. data/ext/rdwarf/libdwarf/mips_extensions.pdf +0 -0
  119. data/ext/rdwarf/libdwarf/pro_alloc.c +179 -0
  120. data/ext/rdwarf/libdwarf/pro_alloc.h +33 -0
  121. data/ext/rdwarf/libdwarf/pro_arange.c +310 -0
  122. data/ext/rdwarf/libdwarf/pro_arange.h +51 -0
  123. data/ext/rdwarf/libdwarf/pro_die.c +431 -0
  124. data/ext/rdwarf/libdwarf/pro_die.h +59 -0
  125. data/ext/rdwarf/libdwarf/pro_encode_nm.c +108 -0
  126. data/ext/rdwarf/libdwarf/pro_encode_nm.h +39 -0
  127. data/ext/rdwarf/libdwarf/pro_error.c +96 -0
  128. data/ext/rdwarf/libdwarf/pro_error.h +43 -0
  129. data/ext/rdwarf/libdwarf/pro_expr.c +575 -0
  130. data/ext/rdwarf/libdwarf/pro_expr.h +36 -0
  131. data/ext/rdwarf/libdwarf/pro_finish.c +45 -0
  132. data/ext/rdwarf/libdwarf/pro_forms.c +1271 -0
  133. data/ext/rdwarf/libdwarf/pro_frame.c +572 -0
  134. data/ext/rdwarf/libdwarf/pro_frame.h +120 -0
  135. data/ext/rdwarf/libdwarf/pro_funcs.c +50 -0
  136. data/ext/rdwarf/libdwarf/pro_incl.h +91 -0
  137. data/ext/rdwarf/libdwarf/pro_init.c +327 -0
  138. data/ext/rdwarf/libdwarf/pro_line.c +373 -0
  139. data/ext/rdwarf/libdwarf/pro_line.h +112 -0
  140. data/ext/rdwarf/libdwarf/pro_macinfo.c +457 -0
  141. data/ext/rdwarf/libdwarf/pro_macinfo.h +31 -0
  142. data/ext/rdwarf/libdwarf/pro_opaque.h +513 -0
  143. data/ext/rdwarf/libdwarf/pro_pubnames.c +60 -0
  144. data/ext/rdwarf/libdwarf/pro_reloc.c +253 -0
  145. data/ext/rdwarf/libdwarf/pro_reloc.h +38 -0
  146. data/ext/rdwarf/libdwarf/pro_reloc_stream.c +256 -0
  147. data/ext/rdwarf/libdwarf/pro_reloc_stream.h +52 -0
  148. data/ext/rdwarf/libdwarf/pro_reloc_symbolic.c +245 -0
  149. data/ext/rdwarf/libdwarf/pro_reloc_symbolic.h +45 -0
  150. data/ext/rdwarf/libdwarf/pro_section.c +2233 -0
  151. data/ext/rdwarf/libdwarf/pro_section.h +100 -0
  152. data/ext/rdwarf/libdwarf/pro_types.c +274 -0
  153. data/ext/rdwarf/libdwarf/pro_types.h +34 -0
  154. data/ext/rdwarf/libdwarf/pro_util.h +38 -0
  155. data/ext/rdwarf/libdwarf/pro_vars.c +52 -0
  156. data/ext/rdwarf/libdwarf/pro_weaks.c +51 -0
  157. data/ext/rdwarf/rdwarf.c +765 -0
  158. data/ext/rdwarf/rdwarf.h +52 -0
  159. data/ext/rdwarf/rdwarf_names_gen.rb +109 -0
  160. data/lib/rdwarf.rb +181 -0
  161. data/lib/rdwarf/version.rb +3 -0
  162. data/rdwarf.gemspec +30 -0
  163. metadata +251 -0
@@ -0,0 +1,1583 @@
1
+ /*
2
+ Copyright (C) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
3
+ Portions Copyright (C) 2007-2013 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 and/or modify it
8
+ under the terms of version 2.1 of the GNU Lesser General Public License
9
+ as published by the Free Software Foundation.
10
+
11
+ This program is distributed in the hope that it would be useful, but
12
+ WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+
15
+ Further, this software is distributed without any warranty that it is
16
+ free of the rightful claim of any third person regarding infringement
17
+ or the like. Any license provided herein, whether implied or
18
+ otherwise, applies only to this software file. Patent licenses, if
19
+ any, provided herein do not apply to combinations of this program with
20
+ other software, or any other product whatsoever.
21
+
22
+ You should have received a copy of the GNU Lesser General Public
23
+ License along with this program; if not, write the Free Software
24
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
25
+ USA.
26
+
27
+ */
28
+
29
+ /* This is #included twice. Once for
30
+ libdwarf callers and one for dwarfdump which prints
31
+ the internals.
32
+
33
+ This way we have just one blob of code that reads
34
+ the table operations. */
35
+
36
+ static unsigned char
37
+ dwarf_standard_opcode_operand_count[STANDARD_OPERAND_COUNT_TWO_LEVEL] = {
38
+ /* DWARF2 */
39
+ 0,
40
+ 1, 1, 1, 1,
41
+ 0, 0, 0,
42
+ 1,
43
+ /* Following are new for DWARF3. */
44
+ 0, 0, 1,
45
+ /* Experimental opcodes. */
46
+ 1, 2, 0,
47
+ };
48
+
49
+ /* We have a normal standard opcode base, but
50
+ an arm compiler emitted a non-standard table!
51
+ This could lead to problems...
52
+ ARM C/C++ Compiler, RVCT4.0 [Build 4
53
+ 00] seems to get the table wrong . */
54
+ static unsigned char
55
+ dwarf_arm_standard_opcode_operand_count[STANDARD_OPERAND_COUNT_DWARF3] = {
56
+ /* DWARF2 */
57
+ 0,
58
+ 1, 1, 1, 1,
59
+ 0, 0, 0,
60
+ 0, /* <<< --- this is wrong */
61
+ /* Following are new for DWARF3. */
62
+ 0, 0, 1
63
+ };
64
+
65
+
66
+ /* Common line table header reading code.
67
+ Returns DW_DLV_OK, DW_DLV_ERROR.
68
+ DW_DLV_NO_ENTRY cannot be returned, but callers should
69
+ assume it is possible.
70
+
71
+ The line_context area must be initialized properly before calling this.
72
+
73
+ Has the side effect of allocating arrays which
74
+ must be freed (see the Line_Table_Context which
75
+ holds the pointers to space we allocate here).
76
+
77
+ bogus_bytes_ptr and bogus_bytes are output values which
78
+ let a print-program notify the user of some surprising bytes
79
+ after a line table header and before the line table instructions.
80
+ These can be ignored unless one is printing.
81
+ And are ignored if NULL passed as the pointer.
82
+
83
+ err_count_out may be NULL, in which case we
84
+ make no attempt to count checking-type errors.
85
+ Checking-type errors do not stop us, we just report them.
86
+
87
+ See dw-linetableheader.txt for the ordering of text fields
88
+ across the various dwarf versions. The code
89
+ follows this ordering closely.
90
+
91
+ Some of the arguments remaining are in line_context
92
+ so can be deleted from the
93
+ argument list (after a close look for correctness).
94
+ */
95
+ static int
96
+ _dwarf_read_line_table_header(Dwarf_Debug dbg,
97
+ Dwarf_CU_Context cu_context,
98
+ Dwarf_Small * data_start,
99
+ Dwarf_Unsigned data_length,
100
+ Dwarf_Small ** updated_data_start_out,
101
+ Dwarf_Line_Context line_context,
102
+ Dwarf_Small ** bogus_bytes_ptr,
103
+ Dwarf_Unsigned *bogus_bytes,
104
+ Dwarf_Error * err,
105
+ int *err_count_out)
106
+ {
107
+ Dwarf_Small *line_ptr = data_start;
108
+ Dwarf_Small *starting_line_ptr = data_start;
109
+ Dwarf_Unsigned total_length = 0;
110
+ int local_length_size = 0;
111
+ int local_extension_size = 0;
112
+ Dwarf_Unsigned prologue_length = 0;
113
+
114
+ Dwarf_Half version = 0;
115
+ Dwarf_Small *line_ptr_end = 0;
116
+ Dwarf_Small *lp_begin = 0;
117
+ int res = 0;
118
+
119
+ if (bogus_bytes_ptr) *bogus_bytes_ptr = 0;
120
+ if (bogus_bytes) *bogus_bytes= 0;
121
+
122
+ line_context->lc_line_ptr_start = starting_line_ptr;
123
+ /* READ_AREA_LENGTH updates line_ptr for consumed bytes */
124
+ READ_AREA_LENGTH(dbg, total_length, Dwarf_Unsigned,
125
+ line_ptr, local_length_size, local_extension_size);
126
+
127
+ line_ptr_end = line_ptr + total_length;
128
+ line_context->lc_line_ptr_end = line_ptr_end;
129
+ line_context->lc_length_field_length = local_length_size +
130
+ local_extension_size;
131
+ line_context->lc_section_offset = starting_line_ptr - dbg->de_debug_line.dss_data;
132
+ /* ASSERT: line_context->lc_length_field_length == line_ptr
133
+ -line_context->lc_line_ptr_start; */
134
+ if (line_ptr_end > dbg->de_debug_line.dss_data +
135
+ dbg->de_debug_line.dss_size) {
136
+ _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_LENGTH_BAD);
137
+ return (DW_DLV_ERROR);
138
+ }
139
+ if (line_ptr_end > starting_line_ptr + data_length) {
140
+ _dwarf_error(dbg, err, DW_DLE_DEBUG_LINE_LENGTH_BAD);
141
+ return (DW_DLV_ERROR);
142
+ }
143
+ line_context->lc_total_length = total_length;
144
+
145
+ READ_UNALIGNED(dbg, version, Dwarf_Half,
146
+ line_ptr, sizeof(Dwarf_Half));
147
+ line_context->lc_version_number = version;
148
+ line_ptr += sizeof(Dwarf_Half);
149
+ if (version != DW_LINE_VERSION2 &&
150
+ version != DW_LINE_VERSION3 &&
151
+ version != DW_LINE_VERSION4 &&
152
+ version != DW_LINE_VERSION5 &&
153
+ version != EXPERIMENTAL_LINE_TABLES_VERSION) {
154
+ _dwarf_error(dbg, err, DW_DLE_VERSION_STAMP_ERROR);
155
+ return (DW_DLV_ERROR);
156
+ }
157
+ if (version == DW_LINE_VERSION5) {
158
+ line_context->lc_address_size = *(unsigned char *) line_ptr;
159
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
160
+ line_context->lc_segment_selector_size =
161
+ *(unsigned char *) line_ptr;
162
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
163
+ } else {
164
+ line_context->lc_address_size = cu_context->cc_address_size;
165
+ line_context->lc_segment_selector_size =
166
+ cu_context->cc_segment_selector_size;
167
+ }
168
+
169
+ READ_UNALIGNED(dbg, prologue_length, Dwarf_Unsigned,
170
+ line_ptr, local_length_size);
171
+ line_context->lc_prologue_length = prologue_length;
172
+ line_ptr += local_length_size;
173
+ line_context->lc_line_prologue_start = line_ptr;
174
+
175
+
176
+ line_context->lc_minimum_instruction_length =
177
+ *(unsigned char *) line_ptr;
178
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
179
+
180
+ if (version == DW_LINE_VERSION4 ||
181
+ version == DW_LINE_VERSION5 ||
182
+ version == EXPERIMENTAL_LINE_TABLES_VERSION) {
183
+ line_context->lc_maximum_ops_per_instruction =
184
+ *(unsigned char *) line_ptr;
185
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
186
+ }
187
+ line_context->lc_default_is_stmt = *(unsigned char *) line_ptr;
188
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
189
+
190
+ line_context->lc_line_base = *(signed char *) line_ptr;
191
+ line_ptr = line_ptr + sizeof(Dwarf_Sbyte);
192
+
193
+ line_context->lc_line_range = *(unsigned char *) line_ptr;
194
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
195
+ line_context->lc_opcode_base = *(unsigned char *) line_ptr;
196
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
197
+ /* Set up the array of standard opcode lengths. */
198
+ /* We think this works ok even for cross-endian processing of
199
+ objects. It might be wrong, we might need to specially process
200
+ the array of ubyte into host order. */
201
+ line_context->lc_opcode_length_table = line_ptr;
202
+
203
+ /* lc_opcode_base is one greater than the size of the array. */
204
+ line_ptr += line_context->lc_opcode_base - 1;
205
+ {
206
+ /* Determine (as best we can) whether the
207
+ lc_opcode_length_table holds 9 or 12 standard-conforming
208
+ entries. gcc4 upped to DWARF3's 12 without updating the
209
+ version number.
210
+ EXPERIMENTAL_LINE_TABLES_VERSION upped to 15. */
211
+ int operand_ck_fail = true;
212
+
213
+ if (line_context->lc_opcode_base >= STANDARD_OPERAND_COUNT_DWARF3) {
214
+ int mismatch = memcmp(dwarf_standard_opcode_operand_count,
215
+ line_context->lc_opcode_length_table,
216
+ STANDARD_OPERAND_COUNT_DWARF3);
217
+ if (mismatch) {
218
+ if (err_count_out) {
219
+ _dwarf_print_header_issue(dbg,
220
+ "standard-operands did not match",
221
+ data_start,err_count_out);
222
+ }
223
+ mismatch = memcmp(dwarf_arm_standard_opcode_operand_count,
224
+ line_context->lc_opcode_length_table,
225
+ STANDARD_OPERAND_COUNT_DWARF3);
226
+ if (!mismatch && err_count_out) {
227
+ _dwarf_print_header_issue(dbg,
228
+ "arm (incorrect) operands in use",
229
+ data_start,err_count_out);
230
+ }
231
+ }
232
+ if (!mismatch) {
233
+ if (version == 2) {
234
+ if (err_count_out) {
235
+ _dwarf_print_header_issue(dbg,
236
+ "standard DWARF3 operands matched,"
237
+ " but is DWARF2 linetable",
238
+ data_start,err_count_out);
239
+ }
240
+ }
241
+ operand_ck_fail = false;
242
+ if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
243
+ line_context->lc_std_op_count =
244
+ STANDARD_OPERAND_COUNT_TWO_LEVEL;
245
+ } else {
246
+ line_context->lc_std_op_count =
247
+ STANDARD_OPERAND_COUNT_DWARF3;
248
+ }
249
+ }
250
+ }
251
+ if (operand_ck_fail) {
252
+ if (line_context->lc_opcode_base >=
253
+ STANDARD_OPERAND_COUNT_DWARF2) {
254
+ int mismatch = memcmp(dwarf_standard_opcode_operand_count,
255
+ line_context->lc_opcode_length_table,
256
+ STANDARD_OPERAND_COUNT_DWARF2);
257
+
258
+ if (mismatch) {
259
+ if (err_count_out) {
260
+ _dwarf_print_header_issue(dbg,
261
+ "standard-operands-lengths did not match",
262
+ data_start,err_count_out);
263
+ }
264
+ mismatch = memcmp(dwarf_arm_standard_opcode_operand_count,
265
+ line_context->lc_opcode_length_table,
266
+ STANDARD_OPERAND_COUNT_DWARF2);
267
+ if (!mismatch && err_count_out) {
268
+ _dwarf_print_header_issue(dbg,
269
+ "arm (incorrect) operand in use",
270
+ data_start,err_count_out);
271
+ }
272
+ }
273
+
274
+ if (!mismatch) {
275
+ operand_ck_fail = false;
276
+ line_context->lc_std_op_count =
277
+ STANDARD_OPERAND_COUNT_DWARF2;
278
+ }
279
+ }
280
+ }
281
+ if (operand_ck_fail) {
282
+ /* Here we are not sure what the lc_std_op_count is. */
283
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUM_OPERANDS_BAD);
284
+ return (DW_DLV_ERROR);
285
+ }
286
+ }
287
+ /* At this point we no longer need to check operand counts. */
288
+
289
+ if (version < DW_LINE_VERSION5){
290
+ Dwarf_Unsigned directories_count = 0;
291
+ Dwarf_Unsigned directories_malloc = 5;
292
+ line_context->lc_include_directories = malloc(sizeof(Dwarf_Small *) *
293
+ directories_malloc);
294
+ if (line_context->lc_include_directories == NULL) {
295
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
296
+ return (DW_DLV_ERROR);
297
+ }
298
+ memset(line_context->lc_include_directories, 0,
299
+ sizeof(Dwarf_Small *) * directories_malloc);
300
+
301
+ if (line_ptr >= line_ptr_end) {
302
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
303
+ return (DW_DLV_ERROR);
304
+ }
305
+ while ((*(char *) line_ptr) != '\0') {
306
+ if (directories_count >= directories_malloc) {
307
+ Dwarf_Unsigned expand = 2 * directories_malloc;
308
+ Dwarf_Unsigned bytesalloc = sizeof(Dwarf_Small *) * expand;
309
+ Dwarf_Small **newdirs =
310
+ realloc(line_context->lc_include_directories,
311
+ bytesalloc);
312
+
313
+ if (!newdirs) {
314
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
315
+ return (DW_DLV_ERROR);
316
+ }
317
+ /* Doubled size, zero out second half. */
318
+ memset(newdirs + directories_malloc, 0,
319
+ sizeof(Dwarf_Small *) * directories_malloc);
320
+ directories_malloc = expand;
321
+ line_context->lc_include_directories = newdirs;
322
+ }
323
+ line_context->lc_include_directories[directories_count] =
324
+ line_ptr;
325
+ res = _dwarf_check_string_valid(dbg,
326
+ data_start,line_ptr,line_ptr_end,err);
327
+ if (res != DW_DLV_OK) {
328
+ return res;
329
+ }
330
+ line_ptr = line_ptr + strlen((char *) line_ptr) + 1;
331
+ directories_count++;
332
+ if (line_ptr >= line_ptr_end) {
333
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
334
+ return (DW_DLV_ERROR);
335
+ }
336
+ }
337
+ line_ptr++;
338
+ line_context->lc_include_directories_count = directories_count;
339
+ } else if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
340
+ /* Empty old style dir entry list. */
341
+ line_ptr++;
342
+ } else {
343
+ /* No old style directory entries. */
344
+ }
345
+ if (version < DW_LINE_VERSION5) {
346
+ if (line_ptr >= line_ptr_end) {
347
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
348
+ return (DW_DLV_ERROR);
349
+ }
350
+ while (*(char *) line_ptr != '\0') {
351
+ Dwarf_Unsigned utmp;
352
+ Dwarf_Unsigned dir_index = 0;
353
+ Dwarf_Unsigned lastmod = 0;
354
+ Dwarf_Unsigned file_length = 0;
355
+ Dwarf_Word leb128_length = 0;
356
+ int res = 0;
357
+ Dwarf_File_Entry currfile = 0;
358
+
359
+ currfile = (Dwarf_File_Entry)
360
+ malloc(sizeof(struct Dwarf_File_Entry_s));
361
+ if (currfile == NULL) {
362
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
363
+ return (DW_DLV_ERROR);
364
+ }
365
+ memset(currfile,0,sizeof(struct Dwarf_File_Entry_s));
366
+ /* Insert early so in case of error we can find
367
+ and free the record. */
368
+ _dwarf_add_to_files_list(line_context,currfile);
369
+
370
+ currfile->fi_file_name = line_ptr;
371
+ res = _dwarf_check_string_valid(dbg,
372
+ data_start,line_ptr,line_ptr_end,err);
373
+ if (res != DW_DLV_OK) {
374
+ return res;
375
+ }
376
+ line_ptr = line_ptr + strlen((char *) line_ptr) + 1;
377
+ DECODE_LEB128_UWORD(line_ptr, utmp);
378
+ dir_index = (Dwarf_Sword) utmp;
379
+ if (dir_index > line_context->lc_include_directories_count) {
380
+ _dwarf_error(dbg, err, DW_DLE_DIR_INDEX_BAD);
381
+ return (DW_DLV_ERROR);
382
+ }
383
+ currfile->fi_dir_index = dir_index;
384
+
385
+ lastmod = _dwarf_decode_u_leb128(line_ptr, &leb128_length);
386
+ line_ptr = line_ptr + leb128_length;
387
+ currfile->fi_time_last_mod = lastmod;
388
+
389
+ /* Skip over file length. */
390
+ file_length = _dwarf_decode_u_leb128(line_ptr, &leb128_length);
391
+ line_ptr = line_ptr + leb128_length;
392
+ currfile->fi_file_length = file_length;
393
+ if (line_ptr >= line_ptr_end) {
394
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
395
+ return (DW_DLV_ERROR);
396
+ }
397
+ }
398
+ /* Skip trailing nul byte */
399
+ ++line_ptr;
400
+ } else if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
401
+ if (*line_ptr != 0) {
402
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
403
+ return (DW_DLV_ERROR);
404
+ }
405
+ line_ptr++;
406
+ } else {
407
+ /* No old style filenames entries. */
408
+ }
409
+
410
+ if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
411
+ static unsigned char expbytes[5] = {0,0xff,0xff,0x7f, 0x7f };
412
+ Dwarf_Unsigned logicals_table_offset = 0;
413
+ Dwarf_Unsigned actuals_table_offset = 0;
414
+ unsigned i = 0;
415
+
416
+ for ( ; i < 5; ++i) {
417
+ if (*line_ptr != expbytes[i]) {
418
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
419
+ return (DW_DLV_ERROR);
420
+ }
421
+ line_ptr++;
422
+ }
423
+ READ_UNALIGNED(dbg, logicals_table_offset, Dwarf_Unsigned,
424
+ line_ptr, local_length_size);
425
+ line_context->lc_logicals_table_offset = logicals_table_offset;
426
+ line_ptr += local_length_size;
427
+ READ_UNALIGNED(dbg, actuals_table_offset, Dwarf_Unsigned,
428
+ line_ptr, local_length_size);
429
+ line_context->lc_actuals_table_offset = actuals_table_offset;
430
+ line_ptr += local_length_size;
431
+ }
432
+
433
+ if (version == DW_LINE_VERSION5 ||
434
+ version == EXPERIMENTAL_LINE_TABLES_VERSION) {
435
+ /* DWARF 5. */
436
+ Dwarf_Unsigned directory_format_count = 0;
437
+ Dwarf_Unsigned *directory_entry_types = 0;
438
+ Dwarf_Unsigned *directory_entry_forms = 0;
439
+ Dwarf_Unsigned directories_count = 0;
440
+ Dwarf_Signed i = 0;
441
+ Dwarf_Signed j = 0;
442
+ directory_format_count = *(unsigned char *) line_ptr;
443
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
444
+ directory_entry_types = malloc(sizeof(Dwarf_Unsigned) *
445
+ directory_format_count);
446
+ if (directory_entry_types == NULL) {
447
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
448
+ return (DW_DLV_ERROR);
449
+ }
450
+ directory_entry_forms = malloc(sizeof(Dwarf_Unsigned) *
451
+ directory_format_count);
452
+ if (directory_entry_forms == NULL) {
453
+ free(directory_entry_types);
454
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
455
+ return (DW_DLV_ERROR);
456
+ }
457
+ for (i = 0; i < directory_format_count; i++) {
458
+ DECODE_LEB128_UWORD(line_ptr, directory_entry_types[i]);
459
+ DECODE_LEB128_UWORD(line_ptr, directory_entry_forms[i]);
460
+ }
461
+ DECODE_LEB128_UWORD(line_ptr, directories_count);
462
+ line_context->lc_include_directories =
463
+ malloc(sizeof(Dwarf_Small *) * directories_count);
464
+ if (line_context->lc_include_directories == NULL) {
465
+ free(directory_entry_types);
466
+ free(directory_entry_forms);
467
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
468
+ return (DW_DLV_ERROR);
469
+ }
470
+ memset(line_context->lc_include_directories, 0,
471
+ sizeof(Dwarf_Small *) * directories_count);
472
+
473
+ for(i = 0; i < directories_count; i++) {
474
+ for (j = 0; j < directory_format_count; j++) {
475
+
476
+ switch (directory_entry_types[j]) {
477
+ case DW_LNCT_path:
478
+ res = _dwarf_decode_line_string_form(dbg,
479
+ directory_entry_forms[j],
480
+ local_length_size,
481
+ &line_ptr,
482
+ line_ptr_end,
483
+ (char **)&line_context->lc_include_directories[i],
484
+ err);
485
+ if (res != DW_DLV_OK) {
486
+ free(directory_entry_types);
487
+ free(directory_entry_forms);
488
+ return res;
489
+ }
490
+ break;
491
+ default:
492
+ free(directory_entry_types);
493
+ free(directory_entry_forms);
494
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
495
+ return (DW_DLV_ERROR);
496
+ }
497
+ }
498
+ if (line_ptr >= line_ptr_end) {
499
+ free(directory_entry_types);
500
+ free(directory_entry_forms);
501
+ _dwarf_error(dbg, err,
502
+ DW_DLE_LINE_NUMBER_HEADER_ERROR);
503
+ return (DW_DLV_ERROR);
504
+ }
505
+ }
506
+ free(directory_entry_types);
507
+ free(directory_entry_forms);
508
+ line_context->lc_include_directories_count = directories_count;
509
+ }
510
+
511
+ if (version == DW_LINE_VERSION5 ||
512
+ version == EXPERIMENTAL_LINE_TABLES_VERSION) {
513
+ /* DWARF 5. */
514
+ Dwarf_Unsigned filename_format_count = 0;
515
+ Dwarf_Unsigned *filename_entry_types = 0;
516
+ Dwarf_Unsigned *filename_entry_forms = 0;
517
+ Dwarf_Unsigned files_count = 0;
518
+ Dwarf_Signed i = 0;
519
+ Dwarf_Signed j = 0;
520
+
521
+ filename_format_count = *(unsigned char *) line_ptr;
522
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
523
+ filename_entry_types = malloc(sizeof(Dwarf_Unsigned) *
524
+ filename_format_count);
525
+ if (filename_entry_types == NULL) {
526
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
527
+ return (DW_DLV_ERROR);
528
+ }
529
+ filename_entry_forms = malloc(sizeof(Dwarf_Unsigned) *
530
+ filename_format_count);
531
+ if (filename_entry_forms == NULL) {
532
+ free(filename_entry_types);
533
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
534
+ return (DW_DLV_ERROR);
535
+ }
536
+ for (i = 0; i < filename_format_count; i++) {
537
+ DECODE_LEB128_UWORD(line_ptr, filename_entry_types[i]);
538
+ DECODE_LEB128_UWORD(line_ptr, filename_entry_forms[i]);
539
+ }
540
+ DECODE_LEB128_UWORD(line_ptr, files_count);
541
+
542
+
543
+ for (i = 0; i < files_count; i++) {
544
+ Dwarf_File_Entry curline = 0;
545
+ curline = (Dwarf_File_Entry)
546
+ malloc(sizeof(struct Dwarf_File_Entry_s));
547
+ if (curline == NULL) {
548
+ free(filename_entry_types);
549
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
550
+ return (DW_DLV_ERROR);
551
+ }
552
+ memset(curline,0,sizeof(*curline));
553
+ _dwarf_add_to_files_list(line_context,curline);
554
+ for(j = 0; j < filename_format_count; j++) {
555
+ Dwarf_Unsigned dirindex = 0;
556
+ switch (filename_entry_types[j]) {
557
+ case DW_LNCT_path:
558
+ res = _dwarf_decode_line_string_form(dbg,
559
+ filename_entry_forms[j],
560
+ local_length_size,
561
+ &line_ptr,
562
+ line_ptr_end,
563
+ (char **)&curline->fi_file_name,
564
+ err);
565
+ if (res != DW_DLV_OK) {
566
+ free(filename_entry_types);
567
+ free(filename_entry_forms);
568
+ return res;
569
+ }
570
+ break;
571
+ case DW_LNCT_directory_index:
572
+ res = _dwarf_decode_line_udata_form(dbg,
573
+ filename_entry_forms[j],
574
+ &line_ptr,
575
+ &dirindex,
576
+ err);
577
+ if (res != DW_DLV_OK) {
578
+ free(filename_entry_types);
579
+ free(filename_entry_forms);
580
+ return res;
581
+ }
582
+ curline->fi_dir_index = dirindex;
583
+ break;
584
+ case DW_LNCT_timestamp:
585
+ res = _dwarf_decode_line_udata_form(dbg,
586
+ filename_entry_forms[j],
587
+ &line_ptr,
588
+ &curline->fi_time_last_mod,
589
+ err);
590
+ if (res != DW_DLV_OK) {
591
+ free(filename_entry_types);
592
+ free(filename_entry_forms);
593
+ return res;
594
+ }
595
+ break;
596
+ case DW_LNCT_size:
597
+ res = _dwarf_decode_line_udata_form(dbg,
598
+ filename_entry_forms[j],
599
+ &line_ptr,
600
+ &curline->fi_file_length,
601
+ err);
602
+ if (res != DW_DLV_OK) {
603
+ free(filename_entry_types);
604
+ free(filename_entry_forms);
605
+ return res;
606
+ }
607
+ break;
608
+ case DW_LNCT_MD5: /* Not yet implemented */
609
+ default:
610
+ free(filename_entry_types);
611
+ free(filename_entry_forms);
612
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
613
+ return (DW_DLV_ERROR);
614
+ }
615
+ /* Should this be just > ??? */
616
+ if (line_ptr >= line_ptr_end) {
617
+ free(filename_entry_types);
618
+ free(filename_entry_forms);
619
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
620
+ return (DW_DLV_ERROR);
621
+ }
622
+ }
623
+ }
624
+ free(filename_entry_types);
625
+ free(filename_entry_forms);
626
+ }
627
+ /* For two-level line tables, read the subprograms table. */
628
+ if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
629
+ Dwarf_Unsigned subprog_format_count = 0;
630
+ Dwarf_Unsigned *subprog_entry_types = 0;
631
+ Dwarf_Unsigned *subprog_entry_forms = 0;
632
+ Dwarf_Unsigned subprogs_count = 0;
633
+ Dwarf_Signed i = 0;
634
+ Dwarf_Signed j = 0;
635
+
636
+ subprog_format_count = *(unsigned char *) line_ptr;
637
+ line_ptr = line_ptr + sizeof(Dwarf_Small);
638
+ subprog_entry_types = malloc(sizeof(Dwarf_Unsigned) *
639
+ subprog_format_count);
640
+ if (subprog_entry_types == NULL) {
641
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
642
+ return (DW_DLV_ERROR);
643
+ }
644
+ subprog_entry_forms = malloc(sizeof(Dwarf_Unsigned) *
645
+ subprog_format_count);
646
+ if (subprog_entry_forms == NULL) {
647
+ free(subprog_entry_types);
648
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
649
+ return (DW_DLV_ERROR);
650
+ }
651
+
652
+ for (i = 0; i < subprog_format_count; i++) {
653
+ DECODE_LEB128_UWORD(line_ptr, subprog_entry_types[i]);
654
+ DECODE_LEB128_UWORD(line_ptr, subprog_entry_forms[i]);
655
+ }
656
+ DECODE_LEB128_UWORD(line_ptr, subprogs_count);
657
+ line_context->lc_subprogs =
658
+ malloc(sizeof(struct Dwarf_Subprog_Entry_s) * subprogs_count);
659
+ if (line_context->lc_subprogs == NULL) {
660
+ free(subprog_entry_types);
661
+ free(subprog_entry_forms);
662
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
663
+ return (DW_DLV_ERROR);
664
+ }
665
+ memset(line_context->lc_subprogs, 0,
666
+ sizeof(struct Dwarf_Subprog_Entry_s) * subprogs_count);
667
+ for (i = 0; i < subprogs_count; i++) {
668
+ struct Dwarf_Subprog_Entry_s *curline =
669
+ line_context->lc_subprogs + i;
670
+ for (j = 0; j < subprog_format_count; j++) {
671
+ switch (subprog_entry_types[j]) {
672
+ case DW_LNCT_subprogram_name:
673
+ res = _dwarf_decode_line_string_form(dbg,
674
+ subprog_entry_forms[j],
675
+ local_length_size,
676
+ &line_ptr,
677
+ line_ptr_end,
678
+ (char **)&curline->ds_subprog_name,
679
+ err);
680
+ if (res != DW_DLV_OK) {
681
+ free(subprog_entry_types);
682
+ free(subprog_entry_forms);
683
+ return res;
684
+ }
685
+ break;
686
+ case DW_LNCT_decl_file:
687
+ res = _dwarf_decode_line_udata_form(dbg,
688
+ subprog_entry_forms[j],
689
+ &line_ptr,
690
+ &curline->ds_decl_file,
691
+ err);
692
+ if (res != DW_DLV_OK) {
693
+ free(subprog_entry_forms);
694
+ free(subprog_entry_types);
695
+ return res;
696
+ }
697
+ break;
698
+ case DW_LNCT_decl_line:
699
+ res = _dwarf_decode_line_udata_form(dbg,
700
+ subprog_entry_forms[j],
701
+ &line_ptr,
702
+ &curline->ds_decl_line,
703
+ err);
704
+ if (res != DW_DLV_OK) {
705
+ free(subprog_entry_forms);
706
+ free(subprog_entry_types);
707
+ return res;
708
+ }
709
+ break;
710
+ default:
711
+ free(subprog_entry_forms);
712
+ free(subprog_entry_types);
713
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
714
+ return (DW_DLV_ERROR);
715
+ }
716
+ if (line_ptr >= line_ptr_end) {
717
+ free(subprog_entry_types);
718
+ free(subprog_entry_forms);
719
+ _dwarf_error(dbg, err, DW_DLE_LINE_NUMBER_HEADER_ERROR);
720
+ return (DW_DLV_ERROR);
721
+ }
722
+ }
723
+ }
724
+
725
+ free(subprog_entry_types);
726
+ free(subprog_entry_forms);
727
+ line_context->lc_subprogs_count = subprogs_count;
728
+ }
729
+ if (version == EXPERIMENTAL_LINE_TABLES_VERSION) {
730
+ lp_begin = line_context->lc_line_prologue_start +
731
+ line_context->lc_logicals_table_offset;
732
+ } else {
733
+ lp_begin = line_context->lc_line_prologue_start +
734
+ line_context->lc_prologue_length;
735
+ }
736
+ if (line_ptr != lp_begin) {
737
+ if (line_ptr > lp_begin) {
738
+ _dwarf_error(dbg, err, DW_DLE_LINE_PROLOG_LENGTH_BAD);
739
+ return (DW_DLV_ERROR);
740
+ } else {
741
+ /* Bug in compiler. These
742
+ bytes are really part of the instruction
743
+ stream. The line_context->lc_prologue_length is
744
+ wrong (12 too high). */
745
+ if (bogus_bytes_ptr) {
746
+ *bogus_bytes_ptr = line_ptr;
747
+ }
748
+ if (bogus_bytes) {
749
+ /* How far off things are. We expect the
750
+ value 12 ! */
751
+ *bogus_bytes = (lp_begin - line_ptr);
752
+ }
753
+ }
754
+ /* Ignore the lp_begin calc. Assume line_ptr right.
755
+ Making up for compiler bug. */
756
+ lp_begin = line_ptr;
757
+ }
758
+ line_context->lc_line_ptr_start = lp_begin;
759
+ if (line_context->lc_actuals_table_offset) {
760
+ /* This means two tables. */
761
+ line_context->lc_table_count = 2;
762
+ } else {
763
+ if (line_context->lc_line_ptr_end > lp_begin) {
764
+ line_context->lc_table_count = 1;
765
+ } else {
766
+ line_context->lc_table_count = 0;
767
+ }
768
+ }
769
+ *updated_data_start_out = lp_begin;
770
+ return DW_DLV_OK;
771
+ }
772
+
773
+
774
+ /* Read one line table program. For two-level line tables, this
775
+ function is called once for each table. */
776
+ static int
777
+ read_line_table_program(Dwarf_Debug dbg,
778
+ Dwarf_Small *line_ptr,
779
+ Dwarf_Small *line_ptr_end,
780
+ Dwarf_Small *orig_line_ptr,
781
+ Dwarf_Small *section_start,
782
+ Dwarf_Line_Context line_context,
783
+ Dwarf_Half address_size,
784
+ Dwarf_Bool doaddrs, /* Only true if SGI IRIX rqs calling. */
785
+ Dwarf_Bool dolines,
786
+ Dwarf_Bool is_single_table,
787
+ Dwarf_Bool is_actuals_table,
788
+ Dwarf_Error *error,
789
+ int *err_count_out)
790
+ {
791
+ Dwarf_Sword i = 0;
792
+ Dwarf_File_Entry cur_file_entry = 0;
793
+ Dwarf_Line *logicals = line_context->lc_linebuf_logicals;
794
+ Dwarf_Signed logicals_count = line_context->lc_linecount_logicals;;
795
+
796
+ struct Dwarf_Line_Registers_s regs;
797
+
798
+ /* This is a pointer to the current line being added to the line
799
+ matrix. */
800
+ Dwarf_Line curr_line = 0;
801
+
802
+ /* These variables are used to decode leb128 numbers. Leb128_num
803
+ holds the decoded number, and leb128_length is its length in
804
+ bytes. */
805
+ Dwarf_Word leb128_num = 0;
806
+ Dwarf_Word leb128_length = 0;
807
+ Dwarf_Sword advance_line = 0;
808
+
809
+ /* This is the operand of the latest fixed_advance_pc extended
810
+ opcode. */
811
+ Dwarf_Half fixed_advance_pc = 0;
812
+
813
+ /* Counts the number of lines in the line matrix. */
814
+ Dwarf_Sword line_count = 0;
815
+
816
+ /* This is the length of an extended opcode instr. */
817
+ Dwarf_Word instr_length = 0;
818
+
819
+
820
+ /* Used to chain together pointers to line table entries that are
821
+ later used to create a block of Dwarf_Line entries. */
822
+ Dwarf_Chain chain_line = NULL;
823
+ Dwarf_Chain head_chain = NULL;
824
+ Dwarf_Chain curr_chain = NULL;
825
+
826
+ /* This points to a block of Dwarf_Lines, a pointer to which is
827
+ returned in linebuf. */
828
+ Dwarf_Line *block_line = 0;
829
+
830
+ /* Mark a line record as being DW_LNS_set_address */
831
+ Dwarf_Bool is_addr_set = false;
832
+
833
+ /* Initialize the one state machine variable that depends on the
834
+ prefix. */
835
+ _dwarf_set_line_table_regs_default_values(&regs,
836
+ line_context->lc_default_is_stmt);
837
+
838
+ /* Start of statement program. */
839
+ while (line_ptr < line_ptr_end) {
840
+ int type = 0;
841
+ Dwarf_Small opcode = 0;
842
+
843
+ #ifdef PRINTING_DETAILS
844
+ dwarf_printf(dbg,
845
+ " [0x%06" DW_PR_DSx "] ",
846
+ (Dwarf_Signed) (line_ptr - section_start));
847
+ #endif /* PRINTING_DETAILS */
848
+ opcode = *(Dwarf_Small *) line_ptr;
849
+ line_ptr++;
850
+ /* 'type' is the output */
851
+ WHAT_IS_OPCODE(type, opcode, line_context->lc_opcode_base,
852
+ line_context->lc_opcode_length_table, line_ptr,
853
+ line_context->lc_std_op_count);
854
+
855
+ if (type == LOP_DISCARD) {
856
+ int oc = 0;
857
+ int opcnt = line_context->lc_opcode_length_table[opcode];
858
+
859
+ #ifdef PRINTING_DETAILS
860
+ dwarf_printf(dbg,
861
+ "*** DWARF CHECK: DISCARD standard opcode %d "
862
+ "with %d operands: "
863
+ "not understood.", opcode, opcnt);
864
+ *err_count_out += 1;
865
+ #endif /* PRINTING_DETAILS */
866
+ for (oc = 0; oc < opcnt; oc++) {
867
+ /* Read and discard operands we don't
868
+ understand.
869
+ arbitrary choice of unsigned read.
870
+ signed read would work as well. */
871
+ Dwarf_Unsigned utmp2 = 0;
872
+
873
+ DECODE_LEB128_UWORD(line_ptr, utmp2);
874
+ #ifdef PRINTING_DETAILS
875
+ dwarf_printf(dbg,
876
+ " %" DW_PR_DUu
877
+ " (0x%" DW_PR_XZEROS DW_PR_DUx ")",
878
+ (Dwarf_Unsigned) utmp2,
879
+ (Dwarf_Unsigned) utmp2);
880
+ #endif /* PRINTING_DETAILS */
881
+ }
882
+ #ifdef PRINTING_DETAILS
883
+ dwarf_printf(dbg,"***\n");
884
+ #endif /* PRINTING_DETAILS */
885
+ } else if (type == LOP_SPECIAL) {
886
+ /* This op code is a special op in the object, no matter
887
+ that it might fall into the standard op range in this
888
+ compile. That is, these are special opcodes between
889
+ opcode_base and MAX_LINE_OP_CODE. (including
890
+ opcode_base and MAX_LINE_OP_CODE) */
891
+ #ifdef PRINTING_DETAILS
892
+ char special[50];
893
+ unsigned origop = opcode;
894
+ #endif /* PRINTING_DETAILS */
895
+ Dwarf_Unsigned operation_advance = 0;
896
+
897
+ opcode = opcode - line_context->lc_opcode_base;
898
+ operation_advance = (opcode / line_context->lc_line_range);
899
+
900
+ if (line_context->lc_maximum_ops_per_instruction < 2) {
901
+ regs.lr_address = regs.lr_address + (operation_advance *
902
+ line_context->lc_minimum_instruction_length);
903
+ } else {
904
+ regs.lr_address = regs.lr_address +
905
+ (line_context->lc_minimum_instruction_length *
906
+ ((regs.lr_op_index + operation_advance)/
907
+ line_context->lc_maximum_ops_per_instruction));
908
+ regs.lr_op_index = (regs.lr_op_index +operation_advance)%
909
+ line_context->lc_maximum_ops_per_instruction;
910
+ }
911
+
912
+ regs.lr_line = regs.lr_line + line_context->lc_line_base +
913
+ opcode % line_context->lc_line_range;
914
+ #ifdef PRINTING_DETAILS
915
+ sprintf(special, "Specialop %3u", origop);
916
+ print_line_detail(dbg,special,
917
+ opcode,line_count+1, &regs,is_single_table, is_actuals_table);
918
+ #endif /* PRINTING_DETAILS */
919
+
920
+ if (dolines) {
921
+ curr_line =
922
+ (Dwarf_Line) _dwarf_get_alloc(dbg, DW_DLA_LINE, 1);
923
+ if (curr_line == NULL) {
924
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
925
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
926
+ return (DW_DLV_ERROR);
927
+ }
928
+
929
+ /* Mark a line record as being DW_LNS_set_address */
930
+ curr_line->li_addr_line.li_l_data.li_is_addr_set = is_addr_set;
931
+ is_addr_set = false;
932
+
933
+ curr_line->li_address = regs.lr_address;
934
+ curr_line->li_addr_line.li_l_data.li_file =
935
+ (Dwarf_Sword) regs.lr_file;
936
+ curr_line->li_addr_line.li_l_data.li_line =
937
+ (Dwarf_Sword) regs.lr_line;
938
+ curr_line->li_addr_line.li_l_data.li_column =
939
+ (Dwarf_Half) regs.lr_column;
940
+ curr_line->li_addr_line.li_l_data.li_is_stmt =
941
+ regs.lr_is_stmt;
942
+ curr_line->li_addr_line.li_l_data.li_basic_block =
943
+ regs.lr_basic_block;
944
+ curr_line->li_addr_line.li_l_data.li_end_sequence =
945
+ curr_line->li_addr_line.li_l_data.
946
+ li_epilogue_begin = regs.lr_epilogue_begin;
947
+ curr_line->li_addr_line.li_l_data.li_prologue_end =
948
+ regs.lr_prologue_end;
949
+ curr_line->li_addr_line.li_l_data.li_isa = regs.lr_isa;
950
+ curr_line->li_addr_line.li_l_data.li_discriminator =
951
+ regs.lr_discriminator;
952
+ curr_line->li_addr_line.li_l_data.li_call_context =
953
+ regs.lr_call_context;
954
+ curr_line->li_addr_line.li_l_data.li_subprogram =
955
+ regs.lr_subprogram;
956
+ curr_line->li_context = line_context;
957
+ curr_line->li_is_actuals_table = is_actuals_table;
958
+ line_count++;
959
+
960
+ chain_line = (Dwarf_Chain)
961
+ _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
962
+ if (chain_line == NULL) {
963
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
964
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
965
+ return (DW_DLV_ERROR);
966
+ }
967
+ chain_line->ch_item = curr_line;
968
+ _dwarf_update_chain_list(chain_line,&head_chain,&curr_chain);
969
+ }
970
+
971
+ regs.lr_basic_block = false;
972
+ regs.lr_prologue_end = false;
973
+ regs.lr_epilogue_begin = false;
974
+ regs.lr_discriminator = 0;
975
+ } else if (type == LOP_STANDARD) {
976
+ switch (opcode) {
977
+
978
+ case DW_LNS_copy:{
979
+
980
+ #ifdef PRINTING_DETAILS
981
+ print_line_detail(dbg,"DW_LNS_copy",
982
+ opcode,line_count+1, &regs,is_single_table, is_actuals_table);
983
+ #endif /* PRINTING_DETAILS */
984
+ if (dolines) {
985
+ curr_line = (Dwarf_Line) _dwarf_get_alloc(dbg,
986
+ DW_DLA_LINE, 1);
987
+ if (curr_line == NULL) {
988
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
989
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
990
+ return (DW_DLV_ERROR);
991
+ }
992
+
993
+ /* Mark a line record as being DW_LNS_set_address */
994
+ curr_line->li_addr_line.li_l_data.li_is_addr_set =
995
+ is_addr_set;
996
+ is_addr_set = false;
997
+
998
+ curr_line->li_address = regs.lr_address;
999
+ curr_line->li_addr_line.li_l_data.li_file =
1000
+ (Dwarf_Sword) regs.lr_file;
1001
+ curr_line->li_addr_line.li_l_data.li_line =
1002
+ (Dwarf_Sword) regs.lr_line;
1003
+ curr_line->li_addr_line.li_l_data.li_column =
1004
+ (Dwarf_Half) regs.lr_column;
1005
+ curr_line->li_addr_line.li_l_data.li_is_stmt =
1006
+ regs.lr_is_stmt;
1007
+ curr_line->li_addr_line.li_l_data.
1008
+ li_basic_block = regs.lr_basic_block;
1009
+ curr_line->li_addr_line.li_l_data.
1010
+ li_end_sequence = regs.lr_end_sequence;
1011
+ curr_line->li_context = line_context;
1012
+ curr_line->li_is_actuals_table = is_actuals_table;
1013
+ curr_line->li_addr_line.li_l_data.
1014
+ li_epilogue_begin = regs.lr_epilogue_begin;
1015
+ curr_line->li_addr_line.li_l_data.
1016
+ li_prologue_end = regs.lr_prologue_end;
1017
+ curr_line->li_addr_line.li_l_data.li_isa = regs.lr_isa;
1018
+ curr_line->li_addr_line.li_l_data.li_discriminator =
1019
+ regs.lr_discriminator;
1020
+ curr_line->li_addr_line.li_l_data.li_call_context =
1021
+ regs.lr_call_context;
1022
+ curr_line->li_addr_line.li_l_data.li_subprogram =
1023
+ regs.lr_subprogram;
1024
+ line_count++;
1025
+
1026
+ chain_line = (Dwarf_Chain)
1027
+ _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
1028
+ if (chain_line == NULL) {
1029
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
1030
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1031
+ return (DW_DLV_ERROR);
1032
+ }
1033
+ chain_line->ch_item = curr_line;
1034
+ _dwarf_update_chain_list(chain_line,&head_chain,&curr_chain);
1035
+ }
1036
+
1037
+ regs.lr_basic_block = false;
1038
+ regs.lr_prologue_end = false;
1039
+ regs.lr_epilogue_begin = false;
1040
+ regs.lr_discriminator = 0;
1041
+ }
1042
+ break;
1043
+ case DW_LNS_advance_pc:{
1044
+ Dwarf_Unsigned utmp2 = 0;
1045
+
1046
+ DECODE_LEB128_UWORD(line_ptr, utmp2);
1047
+
1048
+ #ifdef PRINTING_DETAILS
1049
+ dwarf_printf(dbg,
1050
+ "DW_LNS_advance_pc val %"
1051
+ DW_PR_DSd " 0x%"
1052
+ DW_PR_XZEROS DW_PR_DUx "\n",
1053
+ (Dwarf_Signed) (Dwarf_Word) utmp2,
1054
+ (Dwarf_Unsigned) (Dwarf_Word) utmp2);
1055
+ #endif /* PRINTING_DETAILS */
1056
+ leb128_num = (Dwarf_Word) utmp2;
1057
+ regs.lr_address = regs.lr_address +
1058
+ line_context->lc_minimum_instruction_length *
1059
+ leb128_num;
1060
+ }
1061
+ break;
1062
+ case DW_LNS_advance_line:{
1063
+ Dwarf_Signed stmp = 0;
1064
+
1065
+ DECODE_LEB128_SWORD(line_ptr, stmp);
1066
+ advance_line = (Dwarf_Sword) stmp;
1067
+
1068
+ #ifdef PRINTING_DETAILS
1069
+ dwarf_printf(dbg,
1070
+ "DW_LNS_advance_line val %" DW_PR_DSd " 0x%"
1071
+ DW_PR_XZEROS DW_PR_DSx "\n",
1072
+ (Dwarf_Signed) advance_line,
1073
+ (Dwarf_Signed) advance_line);
1074
+ #endif /* PRINTING_DETAILS */
1075
+ regs.lr_line = regs.lr_line + advance_line;
1076
+ }
1077
+ break;
1078
+ case DW_LNS_set_file:{
1079
+ Dwarf_Unsigned utmp2 = 0;
1080
+
1081
+ DECODE_LEB128_UWORD(line_ptr, utmp2);
1082
+ regs.lr_file = (Dwarf_Word) utmp2;
1083
+ #ifdef PRINTING_DETAILS
1084
+ dwarf_printf(dbg,
1085
+ "DW_LNS_set_file %ld\n", (long) regs.lr_file);
1086
+ #endif /* PRINTING_DETAILS */
1087
+ }
1088
+ break;
1089
+ case DW_LNS_set_column:{
1090
+ Dwarf_Unsigned utmp2 = 0;
1091
+
1092
+ DECODE_LEB128_UWORD(line_ptr, utmp2);
1093
+ regs.lr_column = (Dwarf_Word) utmp2;
1094
+ #ifdef PRINTING_DETAILS
1095
+ dwarf_printf(dbg,
1096
+ "DW_LNS_set_column val %" DW_PR_DSd " 0x%"
1097
+ DW_PR_XZEROS DW_PR_DSx "\n",
1098
+ (Dwarf_Signed) regs.lr_column,
1099
+ (Dwarf_Signed) regs.lr_column);
1100
+ #endif /* PRINTING_DETAILS */
1101
+ }
1102
+ break;
1103
+ case DW_LNS_negate_stmt:{
1104
+ regs.lr_is_stmt = !regs.lr_is_stmt;
1105
+ #ifdef PRINTING_DETAILS
1106
+ dwarf_printf(dbg,
1107
+ "DW_LNS_negate_stmt\n");
1108
+ #endif /* PRINTING_DETAILS */
1109
+ }
1110
+ break;
1111
+ case DW_LNS_set_basic_block:{
1112
+ regs.lr_basic_block = true;
1113
+ #ifdef PRINTING_DETAILS
1114
+ dwarf_printf(dbg,
1115
+ "DW_LNS_set_basic_block\n");
1116
+ #endif /* PRINTING_DETAILS */
1117
+ }
1118
+ break;
1119
+
1120
+ case DW_LNS_const_add_pc:{
1121
+ opcode = MAX_LINE_OP_CODE - line_context->lc_opcode_base;
1122
+ if (line_context->lc_maximum_ops_per_instruction < 2) {
1123
+ Dwarf_Unsigned operation_advance =
1124
+ (opcode / line_context->lc_line_range);
1125
+ regs.lr_address = regs.lr_address +
1126
+ line_context->lc_minimum_instruction_length *
1127
+ operation_advance;
1128
+ } else {
1129
+ Dwarf_Unsigned operation_advance =
1130
+ (opcode / line_context->lc_line_range);
1131
+ regs.lr_address = regs.lr_address +
1132
+ line_context->lc_minimum_instruction_length *
1133
+ ((regs.lr_op_index + operation_advance)/
1134
+ line_context->lc_maximum_ops_per_instruction);
1135
+ regs.lr_op_index = (regs.lr_op_index +operation_advance)%
1136
+ line_context->lc_maximum_ops_per_instruction;
1137
+ }
1138
+ #ifdef PRINTING_DETAILS
1139
+ dwarf_printf(dbg,
1140
+ "DW_LNS_const_add_pc new address 0x%"
1141
+ DW_PR_XZEROS DW_PR_DSx "\n",
1142
+ (Dwarf_Signed) regs.lr_address);
1143
+ #endif /* PRINTING_DETAILS */
1144
+ }
1145
+ break;
1146
+ case DW_LNS_fixed_advance_pc:{
1147
+ READ_UNALIGNED(dbg, fixed_advance_pc, Dwarf_Half,
1148
+ line_ptr, sizeof(Dwarf_Half));
1149
+ line_ptr += sizeof(Dwarf_Half);
1150
+ regs.lr_address = regs.lr_address + fixed_advance_pc;
1151
+ regs.lr_op_index = 0;
1152
+ #ifdef PRINTING_DETAILS
1153
+ dwarf_printf(dbg,
1154
+ "DW_LNS_fixed_advance_pc val %" DW_PR_DSd
1155
+ " 0x%" DW_PR_XZEROS DW_PR_DSx
1156
+ " new address 0x%" DW_PR_XZEROS DW_PR_DSx "\n",
1157
+ (Dwarf_Signed) fixed_advance_pc,
1158
+ (Dwarf_Signed) fixed_advance_pc,
1159
+ (Dwarf_Signed) regs.lr_address);
1160
+ #endif /* PRINTING_DETAILS */
1161
+ }
1162
+ break;
1163
+
1164
+ /* New in DWARF3 */
1165
+ case DW_LNS_set_prologue_end:{
1166
+ regs.lr_prologue_end = true;
1167
+ }
1168
+ break;
1169
+ /* New in DWARF3 */
1170
+ case DW_LNS_set_epilogue_begin:{
1171
+ regs.lr_epilogue_begin = true;
1172
+ #ifdef PRINTING_DETAILS
1173
+ dwarf_printf(dbg,
1174
+ "DW_LNS_set_prologue_end set true.\n");
1175
+ #endif /* PRINTING_DETAILS */
1176
+ }
1177
+ break;
1178
+
1179
+ /* New in DWARF3 */
1180
+ case DW_LNS_set_isa:{
1181
+ Dwarf_Unsigned utmp2 = 0;
1182
+
1183
+ DECODE_LEB128_UWORD(line_ptr, utmp2);
1184
+ regs.lr_isa = utmp2;
1185
+
1186
+ #ifdef PRINTING_DETAILS
1187
+ dwarf_printf(dbg,
1188
+ "DW_LNS_set_isa new value 0x%"
1189
+ DW_PR_XZEROS DW_PR_DUx ".\n",
1190
+ (Dwarf_Unsigned) utmp2);
1191
+ #endif /* PRINTING_DETAILS */
1192
+ if (regs.lr_isa != utmp2) {
1193
+ /* The value of the isa did not fit in our
1194
+ local so we record it wrong. declare an
1195
+ error. */
1196
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
1197
+ _dwarf_error(dbg, error,
1198
+ DW_DLE_LINE_NUM_OPERANDS_BAD);
1199
+ return (DW_DLV_ERROR);
1200
+ }
1201
+ }
1202
+ break;
1203
+
1204
+ /* Experimental two-level line tables */
1205
+ /* DW_LNS_set_address_from_logical and
1206
+ DW_LNS_set_subprogram
1207
+ share the same opcode. Disambiguate by checking
1208
+ is_actuals_table. */
1209
+ case DW_LNS_set_subprogram:
1210
+ if (is_actuals_table) {
1211
+ /* DW_LNS_set_address_from_logical */
1212
+ Dwarf_Signed stmp = 0;
1213
+
1214
+ DECODE_LEB128_SWORD(line_ptr, stmp);
1215
+ advance_line = (Dwarf_Sword) stmp;
1216
+ regs.lr_line = regs.lr_line + advance_line;
1217
+ if (regs.lr_line >= 1 &&
1218
+ regs.lr_line - 1 < logicals_count) {
1219
+ regs.lr_address =
1220
+ logicals[regs.lr_line - 1]->li_address;
1221
+ regs.lr_op_index = 0;
1222
+ #ifdef PRINTING_DETAILS
1223
+ dwarf_printf(dbg,"DW_LNS_set_address_from_logical "
1224
+ "%" DW_PR_DSd " 0x%" DW_PR_XZEROS DW_PR_DSx,
1225
+ stmp,stmp);
1226
+ dwarf_printf(dbg," newaddr="
1227
+ " 0x%" DW_PR_XZEROS DW_PR_DUx ".\n",
1228
+ regs.lr_address);
1229
+ #endif /* PRINTING_DETAILS */
1230
+ } else {
1231
+ #ifdef PRINTING_DETAILS
1232
+ dwarf_printf(dbg,"DW_LNS_set_address_from_logical line is "
1233
+ "%" DW_PR_DSd " 0x%" DW_PR_XZEROS DW_PR_DSx ".\n",
1234
+ (Dwarf_Signed)regs.lr_line,
1235
+ (Dwarf_Signed)regs.lr_line);
1236
+ #endif /* PRINTING_DETAILS */
1237
+ }
1238
+ } else {
1239
+ /* DW_LNS_set_subprogram, building logicals table. */
1240
+ Dwarf_Unsigned utmp2 = 0;
1241
+
1242
+ regs.lr_call_context = 0;
1243
+ DECODE_LEB128_UWORD(line_ptr, utmp2);
1244
+ regs.lr_subprogram = (Dwarf_Word) utmp2;
1245
+ #ifdef PRINTING_DETAILS
1246
+ dwarf_printf(dbg,"DW_LNS_set_subprogram "
1247
+ "%" DW_PR_DSd " 0x%" DW_PR_XZEROS DW_PR_DSx "\n",
1248
+ (Dwarf_Signed)utmp2,(Dwarf_Signed)utmp2);
1249
+ #endif /* PRINTING_DETAILS */
1250
+ }
1251
+ break;
1252
+
1253
+ /* Experimental two-level line tables */
1254
+ case DW_LNS_inlined_call: {
1255
+ Dwarf_Signed stmp = 0;
1256
+
1257
+ DECODE_LEB128_SWORD(line_ptr, stmp);
1258
+ regs.lr_call_context = line_count + stmp;
1259
+ DECODE_LEB128_UWORD(line_ptr, regs.lr_subprogram);
1260
+
1261
+ #ifdef PRINTING_DETAILS
1262
+ dwarf_printf(dbg,"DW_LNS_inlined_call "
1263
+ "%" DW_PR_DSd " (0x%" DW_PR_XZEROS DW_PR_DSx "),"
1264
+ "%" DW_PR_DSd " (0x%" DW_PR_XZEROS DW_PR_DSx ")",
1265
+ stmp,stmp,
1266
+ (Dwarf_Signed)regs.lr_subprogram,
1267
+ (Dwarf_Signed)regs.lr_subprogram);
1268
+ dwarf_printf(dbg," callcontext="
1269
+ "%" DW_PR_DSd " (0x%" DW_PR_XZEROS DW_PR_DSx ")\n",
1270
+ (Dwarf_Signed)regs.lr_call_context,
1271
+ (Dwarf_Signed)regs.lr_call_context);
1272
+ #endif /* PRINTING_DETAILS */
1273
+ }
1274
+ break;
1275
+
1276
+ /* Experimental two-level line tables */
1277
+ case DW_LNS_pop_context: {
1278
+ Dwarf_Unsigned logical_num = regs.lr_call_context;
1279
+ Dwarf_Chain logical_chain = head_chain;
1280
+ Dwarf_Line logical_line = 0;
1281
+
1282
+ if (logical_num > 0 && logical_num <= line_count) {
1283
+ for (i = 1; i < logical_num; i++) {
1284
+ logical_chain = logical_chain->ch_next;
1285
+ }
1286
+ logical_line = (Dwarf_Line) logical_chain->ch_item;
1287
+ regs.lr_file =
1288
+ logical_line->li_addr_line.li_l_data.li_file;
1289
+ regs.lr_line =
1290
+ logical_line->li_addr_line.li_l_data.li_line;
1291
+ regs.lr_column =
1292
+ logical_line->li_addr_line.li_l_data.li_column;
1293
+ regs.lr_discriminator =
1294
+ logical_line->li_addr_line.li_l_data.li_discriminator;
1295
+ regs.lr_is_stmt =
1296
+ logical_line->li_addr_line.li_l_data.li_is_stmt;
1297
+ regs.lr_call_context =
1298
+ logical_line->li_addr_line.li_l_data.li_call_context;
1299
+ regs.lr_subprogram =
1300
+ logical_line->li_addr_line.li_l_data.li_subprogram;
1301
+ #ifdef PRINTING_DETAILS
1302
+ dwarf_printf(dbg,"DW_LNS_pop_context set from logical "
1303
+ "%" DW_PR_DUu " (0x%" DW_PR_XZEROS DW_PR_DUx ")\n",
1304
+ logical_num,logical_num);
1305
+ } else {
1306
+ dwarf_printf(dbg,"DW_LNS_pop_context does nothing, logical"
1307
+ "%" DW_PR_DUu " (0x%" DW_PR_XZEROS DW_PR_DUx ")\n",
1308
+ logical_num,logical_num);
1309
+ #endif /* PRINTING_DETAILS */
1310
+ }
1311
+ }
1312
+ break;
1313
+ } /* End switch (opcode) */
1314
+
1315
+ } else if (type == LOP_EXTENDED) {
1316
+ Dwarf_Unsigned utmp3 = 0;
1317
+ Dwarf_Small ext_opcode = 0;
1318
+
1319
+ DECODE_LEB128_UWORD(line_ptr, utmp3);
1320
+ instr_length = (Dwarf_Word) utmp3;
1321
+ /* Dwarf_Small is a ubyte and the extended opcode is a
1322
+ ubyte, though not stated as clearly in the 2.0.0 spec as
1323
+ one might hope. */
1324
+ ext_opcode = *(Dwarf_Small *) line_ptr;
1325
+ line_ptr++;
1326
+ switch (ext_opcode) {
1327
+
1328
+ case DW_LNE_end_sequence:{
1329
+ regs.lr_end_sequence = true;
1330
+ if (dolines) {
1331
+ curr_line = (Dwarf_Line)
1332
+ _dwarf_get_alloc(dbg, DW_DLA_LINE, 1);
1333
+ if (curr_line == NULL) {
1334
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
1335
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1336
+ return (DW_DLV_ERROR);
1337
+ }
1338
+
1339
+ #ifdef PRINTING_DETAILS
1340
+ print_line_detail(dbg,"DW_LNE_end_sequence extended",
1341
+ ext_opcode, line_count+1,&regs,
1342
+ is_single_table, is_actuals_table);
1343
+ #endif /* PRINTING_DETAILS */
1344
+ curr_line->li_address = regs.lr_address;
1345
+ curr_line->li_addr_line.li_l_data.li_file =
1346
+ (Dwarf_Sword) regs.lr_file;
1347
+ curr_line->li_addr_line.li_l_data.li_line =
1348
+ (Dwarf_Sword) regs.lr_line;
1349
+ curr_line->li_addr_line.li_l_data.li_column =
1350
+ (Dwarf_Half) regs.lr_column;
1351
+ curr_line->li_addr_line.li_l_data.li_is_stmt =
1352
+ regs.lr_is_stmt;
1353
+ curr_line->li_addr_line.li_l_data.
1354
+ li_basic_block = regs.lr_basic_block;
1355
+ curr_line->li_addr_line.li_l_data.
1356
+ li_end_sequence = regs.lr_end_sequence;
1357
+ curr_line->li_context = line_context;
1358
+ curr_line->li_is_actuals_table = is_actuals_table;
1359
+ curr_line->li_addr_line.li_l_data.
1360
+ li_epilogue_begin = regs.lr_epilogue_begin;
1361
+ curr_line->li_addr_line.li_l_data.
1362
+ li_prologue_end = regs.lr_prologue_end;
1363
+ curr_line->li_addr_line.li_l_data.li_isa = regs.lr_isa;
1364
+ curr_line->li_addr_line.li_l_data.li_discriminator =
1365
+ regs.lr_discriminator;
1366
+ curr_line->li_addr_line.li_l_data.li_call_context =
1367
+ regs.lr_call_context;
1368
+ curr_line->li_addr_line.li_l_data.li_subprogram =
1369
+ regs.lr_subprogram;
1370
+ line_count++;
1371
+ chain_line = (Dwarf_Chain)
1372
+ _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
1373
+ if (chain_line == NULL) {
1374
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
1375
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1376
+ return (DW_DLV_ERROR);
1377
+ }
1378
+ chain_line->ch_item = curr_line;
1379
+ _dwarf_update_chain_list(chain_line,&head_chain,&curr_chain);
1380
+ }
1381
+ _dwarf_set_line_table_regs_default_values(&regs,
1382
+ line_context->lc_default_is_stmt);
1383
+ }
1384
+ break;
1385
+
1386
+ case DW_LNE_set_address:{
1387
+ READ_UNALIGNED(dbg, regs.lr_address, Dwarf_Addr,
1388
+ line_ptr, address_size);
1389
+ /* Mark a line record as being DW_LNS_set_address */
1390
+ is_addr_set = true;
1391
+ #ifdef PRINTING_DETAILS
1392
+ dwarf_printf(dbg,
1393
+ "DW_LNE_set_address address 0x%"
1394
+ DW_PR_XZEROS DW_PR_DUx "\n",
1395
+ (Dwarf_Unsigned) regs.lr_address);
1396
+ #endif /* PRINTING_DETAILS */
1397
+ if (doaddrs) {
1398
+ /* SGI IRIX rqs processing only. */
1399
+ curr_line = (Dwarf_Line) _dwarf_get_alloc(dbg,
1400
+ DW_DLA_LINE, 1);
1401
+ if (curr_line == NULL) {
1402
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
1403
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1404
+ return (DW_DLV_ERROR);
1405
+ }
1406
+
1407
+ /* Mark a line record as being DW_LNS_set_address */
1408
+ curr_line->li_addr_line.li_l_data.li_is_addr_set =
1409
+ is_addr_set;
1410
+ is_addr_set = false;
1411
+ curr_line->li_address = regs.lr_address;
1412
+ #ifdef __sgi /* SGI IRIX ONLY */
1413
+ curr_line->li_addr_line.li_offset =
1414
+ line_ptr - dbg->de_debug_line.dss_data;
1415
+ #endif /* __sgi */
1416
+ line_count++;
1417
+ chain_line = (Dwarf_Chain)
1418
+ _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
1419
+ if (chain_line == NULL) {
1420
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
1421
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1422
+ return (DW_DLV_ERROR);
1423
+ }
1424
+ chain_line->ch_item = curr_line;
1425
+
1426
+ _dwarf_update_chain_list(chain_line,&head_chain,&curr_chain);
1427
+ }
1428
+ regs.lr_op_index = 0;
1429
+ line_ptr += address_size;
1430
+ }
1431
+ break;
1432
+
1433
+ case DW_LNE_define_file:
1434
+ if (dolines) {
1435
+ int res = 0;
1436
+ cur_file_entry = (Dwarf_File_Entry)
1437
+ malloc(sizeof(struct Dwarf_File_Entry_s));
1438
+ if (cur_file_entry == NULL) {
1439
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1440
+ return (DW_DLV_ERROR);
1441
+ }
1442
+ memset(cur_file_entry,0,sizeof(struct Dwarf_File_Entry_s));
1443
+ _dwarf_add_to_files_list(line_context,cur_file_entry);
1444
+ cur_file_entry->fi_file_name = (Dwarf_Small *) line_ptr;
1445
+ res = _dwarf_check_string_valid(dbg,
1446
+ line_ptr,line_ptr,line_ptr_end,error);
1447
+ if (res != DW_DLV_OK) {
1448
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
1449
+ return res;
1450
+ }
1451
+ line_ptr = line_ptr + strlen((char *) line_ptr) + 1;
1452
+ cur_file_entry->fi_dir_index = (Dwarf_Sword)
1453
+ _dwarf_decode_u_leb128(line_ptr, &leb128_length);
1454
+ line_ptr = line_ptr + leb128_length;
1455
+ cur_file_entry->fi_time_last_mod =
1456
+ _dwarf_decode_u_leb128(line_ptr, &leb128_length);
1457
+ line_ptr = line_ptr + leb128_length;
1458
+ cur_file_entry->fi_file_length =
1459
+ _dwarf_decode_u_leb128(line_ptr, &leb128_length);
1460
+ line_ptr = line_ptr + leb128_length;
1461
+ #ifdef PRINTING_DETAILS
1462
+ dwarf_printf(dbg,
1463
+ "DW_LNE_define_file %s \n", cur_file_entry->fi_file_name);
1464
+ dwarf_printf(dbg,
1465
+ " dir index %d\n", (int) cur_file_entry->fi_dir_index);
1466
+ {
1467
+ time_t tt3 = (time_t) cur_file_entry->fi_time_last_mod;
1468
+
1469
+ /* ctime supplies newline */
1470
+ dwarf_printf(dbg,
1471
+ " last time 0x%x %s",
1472
+ (unsigned)tt3, ctime(&tt3));
1473
+ }
1474
+ dwarf_printf(dbg,
1475
+ " file length %ld 0x%lx\n",
1476
+ (long) cur_file_entry->fi_file_length,
1477
+ (unsigned long) cur_file_entry->fi_file_length);
1478
+ #endif /* PRINTING_DETAILS */
1479
+ }
1480
+ break;
1481
+ case DW_LNE_set_discriminator:{
1482
+ /* New in DWARF4 */
1483
+ Dwarf_Unsigned utmp2 = 0;
1484
+
1485
+ DECODE_LEB128_UWORD(line_ptr, utmp2);
1486
+ regs.lr_discriminator = (Dwarf_Word) utmp2;
1487
+
1488
+ #ifdef PRINTING_DETAILS
1489
+ dwarf_printf(dbg,
1490
+ "DW_LNE_set_discriminator 0x%"
1491
+ DW_PR_XZEROS DW_PR_DUx "\n",utmp2);
1492
+ #endif /* PRINTING_DETAILS */
1493
+ }
1494
+ break;
1495
+ default:{
1496
+ /* This is an extended op code we do not know about,
1497
+ other than we know now many bytes it is
1498
+ and the op code and the bytes of operand. */
1499
+ Dwarf_Unsigned remaining_bytes = instr_length -1;
1500
+ if (instr_length < 1 || remaining_bytes > DW_LNE_LEN_MAX) {
1501
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
1502
+ _dwarf_error(dbg, error,
1503
+ DW_DLE_LINE_EXT_OPCODE_BAD);
1504
+ return (DW_DLV_ERROR);
1505
+ }
1506
+
1507
+ #ifdef PRINTING_DETAILS
1508
+ dwarf_printf(dbg,
1509
+ "DW_LNE extended op 0x%x ",ext_opcode);
1510
+ dwarf_printf(dbg,
1511
+ "Bytecount: %" DW_PR_DUu , (Dwarf_Unsigned)instr_length);
1512
+ if (remaining_bytes > 0) {
1513
+ dwarf_printf(dbg,
1514
+ " linedata: 0x");
1515
+ while (remaining_bytes > 0) {
1516
+ dwarf_printf(dbg,
1517
+ "%02x",(unsigned char)(*(line_ptr)));
1518
+ line_ptr++;
1519
+ remaining_bytes--;
1520
+ }
1521
+ }
1522
+ #else /* ! PRINTING_DETAILS */
1523
+ line_ptr += remaining_bytes;
1524
+ #endif /* PRINTING_DETAILS */
1525
+ dwarf_printf(dbg,"\n");
1526
+ }
1527
+ break;
1528
+ } /* End switch. */
1529
+ }
1530
+ }
1531
+ block_line = (Dwarf_Line *)
1532
+ _dwarf_get_alloc(dbg, DW_DLA_LIST, line_count);
1533
+ if (block_line == NULL) {
1534
+ curr_chain = head_chain;
1535
+ /* FIXME: chain cleanup should be a function and called at
1536
+ more places in this function. */
1537
+ _dwarf_free_chain_entries(dbg,head_chain,line_count);
1538
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1539
+ return (DW_DLV_ERROR);
1540
+ }
1541
+
1542
+ curr_chain = head_chain;
1543
+ for (i = 0; i < line_count; i++) {
1544
+ Dwarf_Chain t = 0;
1545
+ *(block_line + i) = curr_chain->ch_item;
1546
+ t = curr_chain;
1547
+ curr_chain = curr_chain->ch_next;
1548
+ dwarf_dealloc(dbg, t, DW_DLA_CHAIN);
1549
+ }
1550
+
1551
+ if (is_single_table || !is_actuals_table) {
1552
+ line_context->lc_linebuf_logicals = block_line;
1553
+ line_context->lc_linecount_logicals = line_count;
1554
+ } else {
1555
+ line_context->lc_linebuf_actuals = block_line;
1556
+ line_context->lc_linecount_actuals = line_count;
1557
+ }
1558
+ #ifdef PRINTING_DETAILS
1559
+ if (is_single_table) {
1560
+ if(!line_count) {
1561
+ dwarf_printf(dbg," Line table is present (offset 0x%"
1562
+ DW_PR_XZEROS DW_PR_DUx
1563
+ ") but no lines present\n",
1564
+ line_context->lc_section_offset);
1565
+ }
1566
+ } else if (is_actuals_table) {
1567
+ if(!line_count) {
1568
+ dwarf_printf(dbg," Line table present (offset 0x%"
1569
+ DW_PR_XZEROS DW_PR_DUx
1570
+ ") but no actuals lines present\n",
1571
+ line_context->lc_section_offset);
1572
+ }
1573
+ } else {
1574
+ if(!line_count) {
1575
+ dwarf_printf(dbg," Line table present (offset 0x%"
1576
+ DW_PR_XZEROS DW_PR_DUx
1577
+ ") but no logicals lines present\n",
1578
+ line_context->lc_section_offset);
1579
+ }
1580
+ }
1581
+ #endif /* PRINTING_DETAILS */
1582
+ return DW_DLV_OK;
1583
+ }