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,479 @@
1
+ /*
2
+
3
+ Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4
+ Portions Copyright (C) 2007-2012 David Anderson. All Rights Reserved.
5
+ Portions Copyright 2012 SN Systems Ltd. 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
+ #include "config.h"
30
+ #include "dwarf_incl.h"
31
+ #include <stdio.h>
32
+ #include <limits.h>
33
+ #ifdef HAVE_STDLIB_H
34
+ #include <stdlib.h>
35
+ #endif /* HAVE_STDLIB_H */
36
+ #include "dwarf_macro.h"
37
+
38
+
39
+ #define LEFTPAREN '('
40
+ #define RIGHTPAREN ')'
41
+ #define SPACE ' '
42
+
43
+ /* Given the dwarf macro string, return a pointer to
44
+ the value. Returns pointer to 0 byte at end of string
45
+ if no value found (meaning the value is the empty string).
46
+
47
+ Only understands well-formed dwarf macinfo strings.
48
+ */
49
+ char *
50
+ dwarf_find_macro_value_start(char *str)
51
+ {
52
+ char *lcp;
53
+ int funclike = 0;
54
+
55
+ for (lcp = str; *lcp; ++lcp) {
56
+ switch (*lcp) {
57
+ case LEFTPAREN:
58
+ funclike = 1;
59
+ break;
60
+ case RIGHTPAREN:
61
+ /* lcp+1 must be a space, and following char is the value */
62
+ return lcp + 2;
63
+ case SPACE:
64
+ /* We allow extraneous spaces inside macro parameter **
65
+ list, just in case... This is not really needed. */
66
+ if (!funclike) {
67
+ return lcp + 1;
68
+ }
69
+ break;
70
+ }
71
+ }
72
+ /* Never found value: returns pointer to the 0 byte at end of
73
+ string. */
74
+ return lcp;
75
+
76
+ }
77
+
78
+
79
+ /*
80
+ Try to keep fileindex correct in every Macro_Details
81
+ record by tracking file starts and ends.
82
+ Uses high water mark: space reused, not freed.
83
+ Presumption is that this makes sense for most uses.
84
+ STARTERMAX is set so that the array need not be expanded for
85
+ most files: it is the initial include file depth.
86
+ */
87
+ struct macro_stack_s {
88
+ Dwarf_Signed *st_base;
89
+ long max;
90
+ long next_to_use;
91
+ int was_fault;
92
+ };
93
+
94
+ static void _dwarf_reset_index_macro_stack(struct macro_stack_s *ms);
95
+ static void
96
+ free_macro_stack(Dwarf_Debug dbg, struct macro_stack_s *ms)
97
+ {
98
+ dwarf_dealloc(dbg,ms->st_base,DW_DLA_STRING);
99
+ _dwarf_reset_index_macro_stack(ms);
100
+ }
101
+
102
+ #define STARTERMAX 10
103
+ static void
104
+ _dwarf_reset_index_macro_stack(struct macro_stack_s *ms)
105
+ {
106
+ ms->st_base = 0;
107
+ ms->max = 0;
108
+ ms->next_to_use = 0;
109
+ ms->was_fault = 0;
110
+ }
111
+ static int
112
+ _dwarf_macro_stack_push_index(Dwarf_Debug dbg, Dwarf_Signed indx,
113
+ struct macro_stack_s *ms)
114
+ {
115
+ Dwarf_Signed *newbase;
116
+
117
+ if (ms->next_to_use >= ms->max) {
118
+ long new_size;
119
+
120
+ if (ms->max == 0) {
121
+ ms->max = STARTERMAX;
122
+ }
123
+ new_size = ms->max * 2;
124
+ newbase =
125
+ (Dwarf_Signed *)_dwarf_get_alloc(dbg, DW_DLA_STRING,
126
+ new_size * sizeof(Dwarf_Signed));
127
+ if (newbase == 0) {
128
+ /* just leave the old array in place */
129
+ ms->was_fault = 1;
130
+ return DW_DLV_ERROR;
131
+ }
132
+ if (ms->st_base) {
133
+ memcpy(newbase, ms->st_base,
134
+ ms->next_to_use * sizeof(Dwarf_Signed));
135
+ dwarf_dealloc(dbg, ms->st_base, DW_DLA_STRING);
136
+ }
137
+ ms->st_base = newbase;
138
+ ms->max = new_size;
139
+ }
140
+ ms->st_base[ms->next_to_use] = indx;
141
+ ++ms->next_to_use;
142
+ return DW_DLV_OK;
143
+ }
144
+
145
+ static Dwarf_Signed
146
+ _dwarf_macro_stack_pop_index(struct macro_stack_s *ms)
147
+ {
148
+ if (ms->was_fault) {
149
+ return -1;
150
+ }
151
+ if (ms->next_to_use > 0) {
152
+ ms->next_to_use--;
153
+ return (ms->st_base[ms->next_to_use]);
154
+ } else {
155
+ ms->was_fault = 1;
156
+ }
157
+ return -1;
158
+ }
159
+
160
+ /* Starting at macro_offset in .debug_macinfo,
161
+ if maximum_count is 0, treat as if it is infinite.
162
+ get macro data up thru
163
+ maximum_count entries or the end of a compilation
164
+ unit's entries (whichever comes first).
165
+
166
+ .debug_macinfo never appears in a .dwp Package File.
167
+ So offset adjustment for such is not needed.
168
+ */
169
+
170
+ int
171
+ dwarf_get_macro_details(Dwarf_Debug dbg,
172
+ Dwarf_Off macro_offset,
173
+ Dwarf_Unsigned maximum_count,
174
+ Dwarf_Signed * entry_count,
175
+ Dwarf_Macro_Details ** details,
176
+ Dwarf_Error * error)
177
+ {
178
+ Dwarf_Small *macro_base = 0;
179
+ Dwarf_Small *macro_end = 0;
180
+ Dwarf_Small *pnext = 0;
181
+ Dwarf_Unsigned endloc = 0;
182
+ unsigned char uc = 0;
183
+ unsigned long depth = 0;
184
+ /* By section 6.3.2 Dwarf3 draft 8/9,
185
+ the base file should appear as
186
+ DW_MACINFO_start_file. See
187
+ http://gcc.gnu.org/ml/gcc-bugs/2005-02/msg03442.html
188
+ on "[Bug debug/20253] New: [3.4/4.0 regression]:
189
+ Macro debug info broken due to lexer change" for how
190
+ gcc is broken in some versions. We no longer use
191
+ depth as a stopping point, it's not needed as a
192
+ stopping point anyway. */
193
+ int res = 0;
194
+ /* count space used by strings */
195
+ unsigned long str_space = 0;
196
+ int done = 0;
197
+ unsigned long space_needed = 0;
198
+ unsigned long string_offset = 0;
199
+ Dwarf_Small *return_data = 0;
200
+ Dwarf_Small *pdata = 0;
201
+ unsigned long final_count = 0;
202
+ Dwarf_Signed fileindex = -1;
203
+ Dwarf_Small *latest_str_loc = 0;
204
+ struct macro_stack_s msdata;
205
+
206
+ unsigned long count = 0;
207
+ unsigned long max_count = (unsigned long) maximum_count;
208
+
209
+ _dwarf_reset_index_macro_stack(&msdata);
210
+ if (dbg == NULL) {
211
+ _dwarf_error(NULL, error, DW_DLE_DBG_NULL);
212
+ free_macro_stack(dbg,&msdata);
213
+ return (DW_DLV_ERROR);
214
+ }
215
+
216
+ res = _dwarf_load_section(dbg, &dbg->de_debug_macinfo,error);
217
+ if (res != DW_DLV_OK) {
218
+ free_macro_stack(dbg,&msdata);
219
+ return res;
220
+ }
221
+ if (!dbg->de_debug_abbrev.dss_size) {
222
+ free_macro_stack(dbg,&msdata);
223
+ return (DW_DLV_NO_ENTRY);
224
+ }
225
+
226
+ macro_base = dbg->de_debug_macinfo.dss_data;
227
+ if (macro_base == NULL) {
228
+ free_macro_stack(dbg,&msdata);
229
+ return (DW_DLV_NO_ENTRY);
230
+ }
231
+ if (macro_offset >= dbg->de_debug_macinfo.dss_size) {
232
+ free_macro_stack(dbg,&msdata);
233
+ return (DW_DLV_NO_ENTRY);
234
+ }
235
+ macro_end = macro_base + dbg->de_debug_macinfo.dss_size;
236
+ /* FIXME debugfission is NOT handled here. */
237
+
238
+ pnext = macro_base + macro_offset;
239
+ if (maximum_count == 0) {
240
+ max_count = ULONG_MAX;
241
+ }
242
+
243
+
244
+ /* how many entries and how much space will they take? */
245
+
246
+ endloc = (pnext - macro_base);
247
+ if (endloc >= dbg->de_debug_macinfo.dss_size) {
248
+ if (endloc == dbg->de_debug_macinfo.dss_size) {
249
+ /* normal: found last entry */
250
+ free_macro_stack(dbg,&msdata);
251
+ return DW_DLV_NO_ENTRY;
252
+ }
253
+ _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_LENGTH_BAD);
254
+ free_macro_stack(dbg,&msdata);
255
+ return (DW_DLV_ERROR);
256
+ }
257
+ for (count = 0; !done && count < max_count; ++count) {
258
+ unsigned long slen;
259
+ Dwarf_Word len;
260
+
261
+ uc = *pnext;
262
+ ++pnext; /* get past the type code */
263
+ switch (uc) {
264
+ case DW_MACINFO_define:
265
+ case DW_MACINFO_undef:
266
+ /* line, string */
267
+ case DW_MACINFO_vendor_ext:
268
+ /* number, string */
269
+ (void) _dwarf_decode_u_leb128(pnext, &len);
270
+
271
+ pnext += len;
272
+ if (((Dwarf_Unsigned)(pnext - macro_base)) >=
273
+ dbg->de_debug_macinfo.dss_size) {
274
+ free_macro_stack(dbg,&msdata);
275
+ _dwarf_error(dbg, error,
276
+ DW_DLE_DEBUG_MACRO_INCONSISTENT);
277
+ return (DW_DLV_ERROR);
278
+ }
279
+ res = _dwarf_check_string_valid(dbg,
280
+ macro_base,pnext,macro_end,error);
281
+ if (res != DW_DLV_OK) {
282
+ return res;
283
+ }
284
+ slen = strlen((char *) pnext) + 1;
285
+ pnext += slen;
286
+ if (((Dwarf_Unsigned)(pnext - macro_base)) >=
287
+ dbg->de_debug_macinfo.dss_size) {
288
+ free_macro_stack(dbg,&msdata);
289
+ _dwarf_error(dbg, error,
290
+ DW_DLE_DEBUG_MACRO_INCONSISTENT);
291
+ return (DW_DLV_ERROR);
292
+ }
293
+ str_space += slen;
294
+ break;
295
+ case DW_MACINFO_start_file:
296
+ /* line, file index */
297
+ (void) _dwarf_decode_u_leb128(pnext, &len);
298
+ pnext += len;
299
+ if (((Dwarf_Unsigned)(pnext - macro_base)) >=
300
+ dbg->de_debug_macinfo.dss_size) {
301
+ free_macro_stack(dbg,&msdata);
302
+ _dwarf_error(dbg, error,
303
+ DW_DLE_DEBUG_MACRO_INCONSISTENT);
304
+ return (DW_DLV_ERROR);
305
+ }
306
+ (void) _dwarf_decode_u_leb128(pnext, &len);
307
+ pnext += len;
308
+ if (((Dwarf_Unsigned)(pnext - macro_base)) >=
309
+ dbg->de_debug_macinfo.dss_size) {
310
+ free_macro_stack(dbg,&msdata);
311
+ _dwarf_error(dbg, error,
312
+ DW_DLE_DEBUG_MACRO_INCONSISTENT);
313
+ return (DW_DLV_ERROR);
314
+ }
315
+ ++depth;
316
+ break;
317
+
318
+ case DW_MACINFO_end_file:
319
+ if (--depth == 0) {
320
+ /* done = 1; no, do not stop here, at least one gcc had
321
+ the wrong depth settings in the gcc 3.4 timeframe. */
322
+ }
323
+ /* no string or number here */
324
+ break;
325
+ case 0:
326
+ /* end of cu's entries */
327
+ done = 1;
328
+ break;
329
+ default:
330
+ free_macro_stack(dbg,&msdata);
331
+ _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_INCONSISTENT);
332
+ return (DW_DLV_ERROR);
333
+ /* bogus macinfo! */
334
+ }
335
+
336
+ endloc = (pnext - macro_base);
337
+ if (endloc == dbg->de_debug_macinfo.dss_size) {
338
+ done = 1;
339
+ } else if (endloc > dbg->de_debug_macinfo.dss_size) {
340
+ _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_LENGTH_BAD);
341
+ free_macro_stack(dbg,&msdata);
342
+ return (DW_DLV_ERROR);
343
+ }
344
+ }
345
+ if (count == 0) {
346
+ free_macro_stack(dbg,&msdata);
347
+ _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_INTERNAL_ERR);
348
+ return (DW_DLV_ERROR);
349
+ }
350
+
351
+ /* We have 'count' array entries to allocate and str_space bytes of
352
+ string space to provide for. */
353
+
354
+ string_offset = count * sizeof(Dwarf_Macro_Details);
355
+
356
+ /* extra 2 not really needed */
357
+ space_needed = string_offset + str_space + 2;
358
+ return_data = pdata =
359
+ (Dwarf_Small *)_dwarf_get_alloc(dbg, DW_DLA_STRING, space_needed);
360
+ latest_str_loc = pdata + string_offset;
361
+ if (pdata == 0) {
362
+ free_macro_stack(dbg,&msdata);
363
+ _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_MALLOC_SPACE);
364
+ return (DW_DLV_ERROR);
365
+ }
366
+ pnext = macro_base + macro_offset;
367
+
368
+ done = 0;
369
+
370
+ /* A series ends with a type code of 0. */
371
+
372
+ for (final_count = 0; !done && final_count < count; ++final_count) {
373
+ unsigned long slen;
374
+ Dwarf_Word len;
375
+ Dwarf_Unsigned v1;
376
+ Dwarf_Macro_Details *pdmd = (Dwarf_Macro_Details *) (pdata +
377
+ (final_count * sizeof (Dwarf_Macro_Details)));
378
+
379
+ endloc = (pnext - macro_base);
380
+ if (endloc > dbg->de_debug_macinfo.dss_size) {
381
+ free_macro_stack(dbg,&msdata);
382
+ _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_LENGTH_BAD);
383
+ return (DW_DLV_ERROR);
384
+ }
385
+ uc = *pnext;
386
+ pdmd->dmd_offset = (pnext - macro_base);
387
+ pdmd->dmd_type = uc;
388
+ pdmd->dmd_fileindex = fileindex;
389
+ pdmd->dmd_lineno = 0;
390
+ pdmd->dmd_macro = 0;
391
+ ++pnext; /* get past the type code */
392
+ switch (uc) {
393
+ case DW_MACINFO_define:
394
+ case DW_MACINFO_undef:
395
+ /* line, string */
396
+ case DW_MACINFO_vendor_ext:
397
+ /* number, string */
398
+ v1 = _dwarf_decode_u_leb128(pnext, &len);
399
+ pdmd->dmd_lineno = v1;
400
+
401
+ pnext += len;
402
+ if (((Dwarf_Unsigned)(pnext - macro_base)) >=
403
+ dbg->de_debug_macinfo.dss_size) {
404
+ free_macro_stack(dbg,&msdata);
405
+ dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
406
+ _dwarf_error(dbg, error,
407
+ DW_DLE_DEBUG_MACRO_INCONSISTENT);
408
+ return (DW_DLV_ERROR);
409
+ }
410
+ res = _dwarf_check_string_valid(dbg,
411
+ macro_base,pnext,macro_end,error);
412
+ if (res != DW_DLV_OK) {
413
+ return res;
414
+ }
415
+ slen = strlen((char *) pnext) + 1;
416
+ strcpy((char *) latest_str_loc, (char *) pnext);
417
+ pdmd->dmd_macro = (char *) latest_str_loc;
418
+ latest_str_loc += slen;
419
+ pnext += slen;
420
+ if (((Dwarf_Unsigned)(pnext - macro_base)) >=
421
+ dbg->de_debug_macinfo.dss_size) {
422
+ free_macro_stack(dbg,&msdata);
423
+ dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
424
+ _dwarf_error(dbg, error,
425
+ DW_DLE_DEBUG_MACRO_INCONSISTENT);
426
+ return (DW_DLV_ERROR);
427
+ }
428
+ break;
429
+ case DW_MACINFO_start_file:
430
+ /* Line, file index */
431
+ v1 = _dwarf_decode_u_leb128(pnext, &len);
432
+ pdmd->dmd_lineno = v1;
433
+ pnext += len;
434
+ if (((Dwarf_Unsigned)(pnext - macro_base)) >=
435
+ dbg->de_debug_macinfo.dss_size) {
436
+ free_macro_stack(dbg,&msdata);
437
+ dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
438
+ _dwarf_error(dbg, error,
439
+ DW_DLE_DEBUG_MACRO_INCONSISTENT);
440
+ return (DW_DLV_ERROR);
441
+ }
442
+ v1 = _dwarf_decode_u_leb128(pnext, &len);
443
+ pdmd->dmd_fileindex = v1;
444
+ (void) _dwarf_macro_stack_push_index(dbg, fileindex,
445
+ &msdata);
446
+ /* We ignore the error, we just let fileindex ** be -1 when
447
+ we pop this one. */
448
+ fileindex = v1;
449
+ pnext += len;
450
+ if (((Dwarf_Unsigned)(pnext - macro_base)) >=
451
+ dbg->de_debug_macinfo.dss_size) {
452
+ free_macro_stack(dbg,&msdata);
453
+ dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
454
+ _dwarf_error(dbg, error,
455
+ DW_DLE_DEBUG_MACRO_INCONSISTENT);
456
+ return (DW_DLV_ERROR);
457
+ }
458
+ break;
459
+
460
+ case DW_MACINFO_end_file:
461
+ fileindex = _dwarf_macro_stack_pop_index(&msdata);
462
+ break; /* no string or number here */
463
+ case 0:
464
+ /* Type code of 0 means the end of cu's entries. */
465
+ done = 1;
466
+ break;
467
+ default:
468
+ /* Bogus macinfo! */
469
+ dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
470
+ free_macro_stack(dbg,&msdata);
471
+ _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_INCONSISTENT);
472
+ return (DW_DLV_ERROR);
473
+ }
474
+ }
475
+ *entry_count = count;
476
+ *details = (Dwarf_Macro_Details *) return_data;
477
+ free_macro_stack(dbg,&msdata);
478
+ return DW_DLV_OK;
479
+ }