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,282 @@
1
+ /*
2
+
3
+ Copyright (C) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
4
+ Portions Copyright (C) 2009-2011 David Anderson. All Rights Reserved.
5
+
6
+ This program is free software; you can redistribute it and/or modify it
7
+ under the terms of version 2.1 of the GNU Lesser General Public License
8
+ as published by the Free Software Foundation.
9
+
10
+ This program is distributed in the hope that it would be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+
14
+ Further, this software is distributed without any warranty that it is
15
+ free of the rightful claim of any third person regarding infringement
16
+ or the like. Any license provided herein, whether implied or
17
+ otherwise, applies only to this software file. Patent licenses, if
18
+ any, provided herein do not apply to combinations of this program with
19
+ other software, or any other product whatsoever.
20
+
21
+ You should have received a copy of the GNU Lesser General Public
22
+ License along with this program; if not, write the Free Software
23
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
24
+ USA.
25
+
26
+ */
27
+
28
+ #include "config.h"
29
+ #include "dwarf_incl.h"
30
+ #include <stdio.h>
31
+ #include <stdlib.h>
32
+ #include "dwarf_frame.h"
33
+ #include "dwarf_arange.h" /* using Arange as a way to build a list */
34
+
35
+ /* Used by rqs (an IRIX application).
36
+ Not needed except for that one application.
37
+ Should be moved to its own source file since
38
+ it is so rarely needed.
39
+ Returns DW_DLV_OK if returns the arrays.
40
+ Returns DW_DLV_NO_ENTRY if no section. ?? (How do I tell?)
41
+ Returns DW_DLV_ERROR if there is an error.
42
+
43
+ Uses DW_FRAME_CFA_COL because IRIX is only DWARF2
44
+ and that is what IRIX compilers and compatible
45
+ compilers support on IRIX.
46
+ */
47
+ int
48
+ _dwarf_frame_address_offsets(Dwarf_Debug dbg, Dwarf_Addr ** addrlist,
49
+ Dwarf_Off ** offsetlist,
50
+ Dwarf_Signed * returncount,
51
+ Dwarf_Error * err)
52
+ {
53
+ int retval = DW_DLV_OK;
54
+ int res = DW_DLV_ERROR;
55
+ Dwarf_Cie *cie_data = 0;
56
+ Dwarf_Signed cie_count = 0;
57
+ Dwarf_Fde *fde_data = 0;
58
+ Dwarf_Signed fde_count = 0;
59
+ Dwarf_Signed i = 0;
60
+ Dwarf_Unsigned u = 0;
61
+ Dwarf_Frame_Op *frame_inst = 0;
62
+ Dwarf_Fde fdep = 0;
63
+ Dwarf_Cie ciep = 0;
64
+ Dwarf_Chain curr_chain = 0;
65
+ Dwarf_Chain head_chain = 0;
66
+ Dwarf_Chain prev_chain = 0;
67
+ Dwarf_Arange arange = 0;
68
+ Dwarf_Unsigned arange_count = 0;
69
+ Dwarf_Addr *arange_addrs = 0;
70
+ Dwarf_Off *arange_offsets = 0;
71
+
72
+ res = dwarf_get_fde_list(dbg, &cie_data, &cie_count,
73
+ &fde_data, &fde_count, err);
74
+ if (res != DW_DLV_OK) {
75
+ return res;
76
+ }
77
+
78
+ res = _dwarf_load_section(dbg, &dbg->de_debug_frame, err);
79
+ if (res != DW_DLV_OK) {
80
+ return res;
81
+ }
82
+ if (!dbg->de_debug_frame.dss_size) {
83
+ return (DW_DLV_NO_ENTRY);
84
+ }
85
+
86
+ for (i = 0; i < cie_count; i++) {
87
+ Dwarf_Off instoff = 0;
88
+ Dwarf_Signed initial_instructions_length = 0;
89
+ Dwarf_Small *instr_end = 0;
90
+ Dwarf_Sword icount = 0;
91
+ int j = 0;
92
+ int dw_err;
93
+
94
+ ciep = cie_data[i];
95
+ instoff = ciep->ci_cie_instr_start - dbg->de_debug_frame.dss_data;
96
+ initial_instructions_length = ciep->ci_length +
97
+ ciep->ci_length_size + ciep->ci_extension_size -
98
+ (ciep->ci_cie_instr_start - ciep->ci_cie_start);
99
+ instr_end = ciep->ci_cie_instr_start +
100
+ initial_instructions_length;
101
+ res = _dwarf_exec_frame_instr( /* make_instr */ true,
102
+ &frame_inst,
103
+ /* search_pc= */ false,
104
+ /* search_pc_val= */ 0,
105
+ /* location */ 0,
106
+ ciep->ci_cie_instr_start,
107
+ instr_end,
108
+ /* Dwarf_frame= */ 0,
109
+ /* cie= */ 0,
110
+ dbg,
111
+ DW_FRAME_CFA_COL,
112
+ &icount, &dw_err);
113
+ if (res == DW_DLV_ERROR) {
114
+ _dwarf_error(dbg, err, dw_err);
115
+ return (res);
116
+ } else if (res == DW_DLV_NO_ENTRY) {
117
+ continue;
118
+ }
119
+
120
+ for (j = 0; j < icount; ++j) {
121
+ Dwarf_Frame_Op *finst = frame_inst + j;
122
+
123
+ if (finst->fp_base_op == 0 && finst->fp_extended_op == 1) {
124
+ /* is DW_CFA_set_loc */
125
+ Dwarf_Addr add = (Dwarf_Addr) finst->fp_offset;
126
+ Dwarf_Off off = finst->fp_instr_offset + instoff;
127
+
128
+ arange = (Dwarf_Arange)
129
+ _dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1);
130
+ if (arange == NULL) {
131
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
132
+ return (DW_DLV_ERROR);
133
+ }
134
+ arange->ar_address = add;
135
+ arange->ar_info_offset = off;
136
+ arange_count++;
137
+ curr_chain = (Dwarf_Chain)
138
+ _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
139
+ if (curr_chain == NULL) {
140
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
141
+ return (DW_DLV_ERROR);
142
+ }
143
+ curr_chain->ch_item = arange;
144
+ if (head_chain == NULL)
145
+ head_chain = prev_chain = curr_chain;
146
+ else {
147
+ prev_chain->ch_next = curr_chain;
148
+ prev_chain = curr_chain;
149
+ }
150
+ }
151
+ }
152
+ dwarf_dealloc(dbg, frame_inst, DW_DLA_FRAME_BLOCK);
153
+
154
+ }
155
+ for (i = 0; i < fde_count; i++) {
156
+ Dwarf_Small *instr_end = 0;
157
+ Dwarf_Sword icount = 0;
158
+ Dwarf_Signed instructions_length = 0;
159
+ Dwarf_Off instoff = 0;
160
+ Dwarf_Off off = 0;
161
+ Dwarf_Addr addr = 0;
162
+ int j = 0;
163
+ int dw_err;
164
+
165
+ fdep = fde_data[i];
166
+ off = fdep->fd_initial_loc_pos - dbg->de_debug_frame.dss_data;
167
+ addr = fdep->fd_initial_location;
168
+ arange = (Dwarf_Arange)
169
+ _dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1);
170
+ if (arange == NULL) {
171
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
172
+ return (DW_DLV_ERROR);
173
+ }
174
+ arange->ar_address = addr;
175
+ arange->ar_info_offset = off;
176
+ arange_count++;
177
+ curr_chain = (Dwarf_Chain)
178
+ _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
179
+ if (curr_chain == NULL) {
180
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
181
+ return (DW_DLV_ERROR);
182
+ }
183
+ curr_chain->ch_item = arange;
184
+ if (head_chain == NULL)
185
+ head_chain = prev_chain = curr_chain;
186
+ else {
187
+ prev_chain->ch_next = curr_chain;
188
+ prev_chain = curr_chain;
189
+ }
190
+
191
+
192
+ instoff = fdep->fd_fde_instr_start - dbg->de_debug_frame.dss_data;
193
+ instructions_length = fdep->fd_length +
194
+ fdep->fd_length_size + fdep->fd_extension_size -
195
+ (fdep->fd_fde_instr_start - fdep->fd_fde_start);
196
+ instr_end = fdep->fd_fde_instr_start + instructions_length;
197
+ res = _dwarf_exec_frame_instr( /* make_instr */ true,
198
+ &frame_inst,
199
+ /* search_pc= */ false,
200
+ /* search_pc_val= */ 0,
201
+ /* location */ 0,
202
+ fdep->fd_fde_instr_start,
203
+ instr_end,
204
+ /* Dwarf_frame= */ 0,
205
+ /* cie= */ 0,
206
+ dbg,
207
+ DW_FRAME_CFA_COL,
208
+ &icount, &dw_err);
209
+ if (res == DW_DLV_ERROR) {
210
+ _dwarf_error(dbg, err, dw_err);
211
+ return (res);
212
+ } else if (res == DW_DLV_NO_ENTRY) {
213
+ continue;
214
+ }
215
+
216
+ for (j = 0; j < icount; ++j) {
217
+ Dwarf_Frame_Op *finst2 = frame_inst + j;
218
+
219
+ if (finst2->fp_base_op == 0 && finst2->fp_extended_op == 1) {
220
+ /* is DW_CFA_set_loc */
221
+ Dwarf_Addr add = (Dwarf_Addr) finst2->fp_offset;
222
+ Dwarf_Off off2 = finst2->fp_instr_offset + instoff;
223
+
224
+ arange = (Dwarf_Arange)
225
+ _dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1);
226
+ if (arange == NULL) {
227
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
228
+ return (DW_DLV_ERROR);
229
+ }
230
+ arange->ar_address = add;
231
+ arange->ar_info_offset = off2;
232
+ arange_count++;
233
+ curr_chain = (Dwarf_Chain)
234
+ _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
235
+ if (curr_chain == NULL) {
236
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
237
+ return (DW_DLV_ERROR);
238
+ }
239
+ curr_chain->ch_item = arange;
240
+ if (head_chain == NULL)
241
+ head_chain = prev_chain = curr_chain;
242
+ else {
243
+ prev_chain->ch_next = curr_chain;
244
+ prev_chain = curr_chain;
245
+ }
246
+
247
+ }
248
+ }
249
+ dwarf_dealloc(dbg, frame_inst, DW_DLA_FRAME_BLOCK);
250
+
251
+ }
252
+ dwarf_dealloc(dbg, fde_data, DW_DLA_LIST);
253
+ dwarf_dealloc(dbg, cie_data, DW_DLA_LIST);
254
+ arange_addrs = (Dwarf_Addr *)
255
+ _dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count);
256
+ if (arange_addrs == NULL) {
257
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
258
+ return (DW_DLV_ERROR);
259
+ }
260
+ arange_offsets = (Dwarf_Off *)
261
+ _dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count);
262
+ if (arange_offsets == NULL) {
263
+ _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
264
+ return (DW_DLV_ERROR);
265
+ }
266
+
267
+ curr_chain = head_chain;
268
+ for (u = 0; u < arange_count; u++) {
269
+ Dwarf_Arange ar = curr_chain->ch_item;
270
+
271
+ arange_addrs[u] = ar->ar_address;
272
+ arange_offsets[u] = ar->ar_info_offset;
273
+ prev_chain = curr_chain;
274
+ curr_chain = curr_chain->ch_next;
275
+ dwarf_dealloc(dbg, ar, DW_DLA_ARANGE);
276
+ dwarf_dealloc(dbg, prev_chain, DW_DLA_CHAIN);
277
+ }
278
+ *returncount = arange_count;
279
+ *offsetlist = arange_offsets;
280
+ *addrlist = arange_addrs;
281
+ return retval;
282
+ }
@@ -0,0 +1,123 @@
1
+ /*
2
+
3
+ Copyright (C) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
4
+ Portions Copyright (C) 2009-2010 David Anderson. All Rights Reserved.
5
+
6
+ This program is free software; you can redistribute it and/or modify it
7
+ under the terms of version 2.1 of the GNU Lesser General Public License
8
+ as published by the Free Software Foundation.
9
+
10
+ This program is distributed in the hope that it would be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+
14
+ Further, this software is distributed without any warranty that it is
15
+ free of the rightful claim of any third person regarding infringement
16
+ or the like. Any license provided herein, whether implied or
17
+ otherwise, applies only to this software file. Patent licenses, if
18
+ any, provided herein do not apply to combinations of this program with
19
+ other software, or any other product whatsoever.
20
+
21
+ You should have received a copy of the GNU Lesser General Public
22
+ License along with this program; if not, write the Free Software
23
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
24
+ USA.
25
+
26
+ */
27
+
28
+ #include "config.h"
29
+ #include "dwarf_incl.h"
30
+ #include <stdio.h>
31
+ #include "dwarf_funcs.h"
32
+ #include "dwarf_global.h"
33
+
34
+ int
35
+ dwarf_get_funcs(Dwarf_Debug dbg,
36
+ Dwarf_Func ** funcs,
37
+ Dwarf_Signed * ret_func_count, Dwarf_Error * error)
38
+ {
39
+ int res = _dwarf_load_section(dbg, &dbg->de_debug_funcnames,error);
40
+ if (res != DW_DLV_OK) {
41
+ return res;
42
+ }
43
+ if (!dbg->de_debug_funcnames.dss_size) {
44
+ return (DW_DLV_NO_ENTRY);
45
+ }
46
+
47
+
48
+ return _dwarf_internal_get_pubnames_like_data(dbg,
49
+ dbg->de_debug_funcnames.dss_data,
50
+ dbg->de_debug_funcnames.dss_size,
51
+ (Dwarf_Global **) funcs, /* Type punning for sections with identical format. */
52
+ ret_func_count,
53
+ error,
54
+ DW_DLA_FUNC_CONTEXT,
55
+ DW_DLA_FUNC,
56
+ DW_DLE_DEBUG_FUNCNAMES_LENGTH_BAD,
57
+ DW_DLE_DEBUG_FUNCNAMES_VERSION_ERROR);
58
+ }
59
+
60
+ /* Deallocating fully requires deallocating the list
61
+ and all entries. But some internal data is
62
+ not exposed, so we need a function with internal knowledge.
63
+ */
64
+
65
+ void
66
+ dwarf_funcs_dealloc(Dwarf_Debug dbg, Dwarf_Func * dwgl,
67
+ Dwarf_Signed count)
68
+ {
69
+ _dwarf_internal_globals_dealloc(dbg, (Dwarf_Global *) dwgl,
70
+ count,
71
+ DW_DLA_FUNC_CONTEXT,
72
+ DW_DLA_FUNC, DW_DLA_LIST);
73
+ return;
74
+ }
75
+
76
+
77
+
78
+ int
79
+ dwarf_funcname(Dwarf_Func func_in, char **ret_name, Dwarf_Error * error)
80
+ {
81
+ Dwarf_Global func = (Dwarf_Global) func_in;
82
+
83
+ if (func == NULL) {
84
+ _dwarf_error(NULL, error, DW_DLE_FUNC_NULL);
85
+ return (DW_DLV_ERROR);
86
+ }
87
+
88
+ *ret_name = (char *) (func->gl_name);
89
+ return DW_DLV_OK;
90
+ }
91
+
92
+ int
93
+ dwarf_func_die_offset(Dwarf_Func func_in,
94
+ Dwarf_Off * return_offset, Dwarf_Error * error)
95
+ {
96
+ Dwarf_Global func = (Dwarf_Global) func_in;
97
+
98
+ return dwarf_global_die_offset(func, return_offset, error);
99
+ }
100
+
101
+
102
+ int
103
+ dwarf_func_cu_offset(Dwarf_Func func_in,
104
+ Dwarf_Off * return_offset, Dwarf_Error * error)
105
+ {
106
+ Dwarf_Global func = (Dwarf_Global) func_in;
107
+
108
+ return dwarf_global_cu_offset(func, return_offset, error);
109
+ }
110
+
111
+
112
+ int
113
+ dwarf_func_name_offsets(Dwarf_Func func_in,
114
+ char **ret_func_name,
115
+ Dwarf_Off * die_offset,
116
+ Dwarf_Off * cu_die_offset, Dwarf_Error * error)
117
+ {
118
+ Dwarf_Global func = (Dwarf_Global) func_in;
119
+
120
+ return dwarf_global_name_offsets(func,
121
+ ret_func_name,
122
+ die_offset, cu_die_offset, error);
123
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+
3
+ Copyright (C) 2000, 2004 Silicon Graphics, Inc. All Rights Reserved.
4
+
5
+ This program is free software; you can redistribute it and/or modify it
6
+ under the terms of version 2.1 of the GNU Lesser General Public License
7
+ as published by the Free Software Foundation.
8
+
9
+ This program is distributed in the hope that it would be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+
13
+ Further, this software is distributed without any warranty that it is
14
+ free of the rightful claim of any third person regarding infringement
15
+ or the like. Any license provided herein, whether implied or
16
+ otherwise, applies only to this software file. Patent licenses, if
17
+ any, provided herein do not apply to combinations of this program with
18
+ other software, or any other product whatsoever.
19
+
20
+ You should have received a copy of the GNU Lesser General Public
21
+ License along with this program; if not, write the Free Software
22
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
23
+ USA.
24
+
25
+ */
26
+
27
+
28
+
29
+
30
+ typedef struct Dwarf_Func_Context_s *Dwarf_Func_Context;
31
+
32
+
33
+ /* struct never completed: see dwarf_global.h */
@@ -0,0 +1,520 @@
1
+ /*
2
+
3
+ Copyright (C) 2014-2014 David Anderson. All Rights Reserved.
4
+
5
+ This program is free software; you can redistribute it and/or modify it
6
+ under the terms of version 2.1 of the GNU Lesser General Public License
7
+ as published by the Free Software Foundation.
8
+
9
+ This program is distributed in the hope that it would be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+
13
+ Further, this software is distributed without any warranty that it is
14
+ free of the rightful claim of any third person regarding infringement
15
+ or the like. Any license provided herein, whether implied or
16
+ otherwise, applies only to this software file. Patent licenses, if
17
+ any, provided herein do not apply to combinations of this program with
18
+ other software, or any other product whatsoever.
19
+
20
+ You should have received a copy of the GNU Lesser General Public
21
+ License along with this program; if not, write the Free Software
22
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
23
+ USA.
24
+
25
+ */
26
+
27
+ #include "config.h"
28
+ #include "dwarf_incl.h"
29
+ #include <stdio.h>
30
+ #include <stdlib.h>
31
+ #include "dwarf_gdbindex.h"
32
+
33
+ #define TRUE 1
34
+ #define FALSE 0
35
+
36
+ /* The dwarf_util macro READ_UNALIGNED
37
+ cannot be directly used because
38
+ gdb defines the section contents of
39
+ .gdb_index as little-endian always.
40
+ */
41
+
42
+ #if WORDS_BIGENDIAN /* meaning on this host */
43
+ #define READ_GDBINDEX(dest,desttype, source, length) \
44
+ do { \
45
+ BIGGEST_UINT _ltmp = 0; \
46
+ _dwarf_memcpy_swap_bytes((((char *)(&_ltmp)) + sizeof(_ltmp) - length), \
47
+ source, length) ; \
48
+ dest = (desttype)_ltmp; \
49
+ } while (0)
50
+ #else /* little-endian on this host */
51
+ #define READ_GDBINDEX(dest,desttype, source, length) \
52
+ do { \
53
+ BIGGEST_UINT _ltmp = 0; \
54
+ memcpy(((char *)(&_ltmp)) , \
55
+ source, length) ; \
56
+ dest = (desttype)_ltmp; \
57
+ } while (0)
58
+
59
+ #endif
60
+
61
+
62
+ struct gi_fileheader_s {
63
+ gdbindex_offset_type headerval[6];
64
+ };
65
+
66
+ struct dwarf_64bitpair {
67
+ gdbindex_64 offset;
68
+ gdbindex_64 length;
69
+ };
70
+
71
+ static int
72
+ set_base(Dwarf_Debug dbg,
73
+ struct Dwarf_Gdbindex_array_instance_s * hdr,
74
+ Dwarf_Small *start,
75
+ Dwarf_Small *end,
76
+ /* entrylen is the length of a single struct as seen in the object. */
77
+ Dwarf_Unsigned entrylen,
78
+ /* The size of each field in the struct in the object. */
79
+ Dwarf_Unsigned fieldlen,
80
+ enum gdbindex_type_e type,
81
+ Dwarf_Error * err)
82
+ {
83
+
84
+ if (type == git_std || type == git_cuvec) {
85
+ /* cuvec is sort of a fake as a simple
86
+ section, but a useful one. */
87
+ Dwarf_Unsigned count = 0;
88
+ if( end < start) {
89
+ _dwarf_error(dbg, err,DW_DLE_GDB_INDEX_COUNT_ERROR);
90
+ return DW_DLV_ERROR;
91
+ }
92
+ count = end - start;
93
+ count = count / entrylen;
94
+ hdr->dg_type = type;
95
+ hdr->dg_base = start;
96
+ hdr->dg_count = count;
97
+ hdr->dg_entry_length = entrylen;
98
+ hdr->dg_fieldlen = fieldlen;
99
+ } else {
100
+ /* address area. */
101
+ /* 64bit, 64bit, offset. Then 32bit pad. */
102
+ Dwarf_Unsigned count = 0;
103
+ hdr->dg_base = start;
104
+ if( end < start) {
105
+ _dwarf_error(dbg, err,DW_DLE_GDB_INDEX_COUNT_ADDR_ERROR);
106
+ return DW_DLV_ERROR;
107
+ }
108
+ /* entry length includes pad. */
109
+ hdr->dg_entry_length = 2*sizeof(gdbindex_64) +
110
+ sizeof(gdbindex_offset_type);
111
+ count = end - start;
112
+ count = count / hdr->dg_entry_length;
113
+ hdr->dg_count = count;
114
+ /* The dg_fieldlen is a fake, the fields are not
115
+ all the same length. */
116
+ hdr->dg_fieldlen = sizeof(gdbindex_offset_type);
117
+ hdr->dg_type = type;
118
+ }
119
+ return DW_DLV_OK;
120
+ }
121
+
122
+ int
123
+ dwarf_gdbindex_header(Dwarf_Debug dbg,
124
+ Dwarf_Gdbindex * gdbindexptr,
125
+ Dwarf_Unsigned * version,
126
+ Dwarf_Unsigned * cu_list_offset,
127
+ Dwarf_Unsigned * types_cu_list_offset,
128
+ Dwarf_Unsigned * address_area_offset,
129
+ Dwarf_Unsigned * symbol_table_offset,
130
+ Dwarf_Unsigned * constant_pool_offset,
131
+ Dwarf_Unsigned * section_size,
132
+ Dwarf_Unsigned * unused_reserved,
133
+ const char ** section_name,
134
+ Dwarf_Error * error)
135
+ {
136
+
137
+ struct gi_fileheader_s header;
138
+ Dwarf_Gdbindex indexptr = 0;
139
+ int res = DW_DLV_ERROR;
140
+
141
+ if (!dbg->de_debug_gdbindex.dss_size) {
142
+ return DW_DLV_NO_ENTRY;
143
+ }
144
+ if (!dbg->de_debug_gdbindex.dss_data) {
145
+ res = _dwarf_load_section(dbg, &dbg->de_debug_gdbindex,error);
146
+ if (res != DW_DLV_OK) {
147
+ return res;
148
+ }
149
+ }
150
+
151
+ if (dbg->de_debug_gdbindex.dss_size < sizeof(struct gi_fileheader_s) ) {
152
+ _dwarf_error(dbg, error, DW_DLE_ERRONEOUS_GDB_INDEX_SECTION);
153
+ return (DW_DLV_ERROR);
154
+ }
155
+ memcpy(&header,dbg->de_debug_gdbindex.dss_data,
156
+ sizeof(struct gi_fileheader_s));
157
+ indexptr = (Dwarf_Gdbindex)_dwarf_get_alloc(dbg,DW_DLA_GDBINDEX,1);
158
+ if (indexptr == NULL) {
159
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
160
+ return (DW_DLV_ERROR);
161
+ }
162
+
163
+ indexptr->gi_dbg = dbg;
164
+ indexptr->gi_section_data = dbg->de_debug_gdbindex.dss_data;
165
+ indexptr->gi_section_length = dbg->de_debug_gdbindex.dss_size;
166
+ READ_GDBINDEX(indexptr->gi_version ,Dwarf_Unsigned,
167
+ dbg->de_debug_gdbindex.dss_data,
168
+ sizeof(gdbindex_offset_type));
169
+ READ_GDBINDEX(indexptr->gi_cu_list_offset ,Dwarf_Unsigned,
170
+ dbg->de_debug_gdbindex.dss_data + sizeof(gdbindex_offset_type),
171
+ sizeof(gdbindex_offset_type));
172
+ READ_GDBINDEX(indexptr->gi_types_cu_list_offset ,Dwarf_Unsigned,
173
+ dbg->de_debug_gdbindex.dss_data + 2*sizeof(gdbindex_offset_type),
174
+ sizeof(gdbindex_offset_type));
175
+ READ_GDBINDEX(indexptr->gi_address_area_offset ,Dwarf_Unsigned,
176
+ dbg->de_debug_gdbindex.dss_data + 3*sizeof(gdbindex_offset_type),
177
+ sizeof(gdbindex_offset_type));
178
+ READ_GDBINDEX(indexptr->gi_symbol_table_offset ,Dwarf_Unsigned,
179
+ dbg->de_debug_gdbindex.dss_data + 4*sizeof(gdbindex_offset_type),
180
+ sizeof(gdbindex_offset_type));
181
+ READ_GDBINDEX(indexptr->gi_constant_pool_offset ,Dwarf_Unsigned,
182
+ dbg->de_debug_gdbindex.dss_data + 5*sizeof(gdbindex_offset_type),
183
+ sizeof(gdbindex_offset_type));
184
+
185
+ res = set_base(dbg,&indexptr->gi_culisthdr,
186
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_cu_list_offset,
187
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_types_cu_list_offset,
188
+ 2*sizeof(gdbindex_64),
189
+ sizeof(gdbindex_64),
190
+ git_std,error);
191
+ res = set_base(dbg,&indexptr->gi_typesculisthdr,
192
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_types_cu_list_offset,
193
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_address_area_offset,
194
+ 3*sizeof(gdbindex_64),
195
+ sizeof(gdbindex_64),
196
+ git_std,error);
197
+ res = set_base(dbg,&indexptr->gi_addressareahdr,
198
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_address_area_offset,
199
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_symbol_table_offset,
200
+ 3*sizeof(gdbindex_64),
201
+ sizeof(gdbindex_64),
202
+ git_address,error);
203
+ res = set_base(dbg,&indexptr->gi_symboltablehdr,
204
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_symbol_table_offset,
205
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_constant_pool_offset,
206
+ 2*sizeof(gdbindex_offset_type),
207
+ sizeof(gdbindex_offset_type),
208
+ git_std,error);
209
+ res = set_base(dbg,&indexptr->gi_cuvectorhdr,
210
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_constant_pool_offset,
211
+ /* There is no real single vector size.
212
+ but we'll use the entire rest as if there was. */
213
+ dbg->de_debug_gdbindex.dss_data + indexptr->gi_section_length,
214
+ sizeof(gdbindex_offset_type),
215
+ sizeof(gdbindex_offset_type),
216
+ git_cuvec,error);
217
+
218
+ /* Really just pointing to constant pool area. */
219
+ indexptr->gi_string_pool = dbg->de_debug_gdbindex.dss_data +
220
+ indexptr->gi_constant_pool_offset;
221
+
222
+ *gdbindexptr = indexptr;
223
+ *version = indexptr->gi_version;
224
+ *cu_list_offset = indexptr->gi_cu_list_offset;
225
+ *types_cu_list_offset = indexptr->gi_types_cu_list_offset;
226
+ *address_area_offset = indexptr->gi_address_area_offset;
227
+ *symbol_table_offset = indexptr->gi_symbol_table_offset;
228
+ *constant_pool_offset = indexptr->gi_constant_pool_offset;
229
+ *section_size = indexptr->gi_section_length;
230
+ *unused_reserved = 0;
231
+ *section_name = dbg->de_debug_gdbindex.dss_name;
232
+
233
+ return DW_DLV_OK;
234
+
235
+
236
+ }
237
+
238
+
239
+ int
240
+ dwarf_gdbindex_culist_array(Dwarf_Gdbindex gdbindexptr,
241
+ Dwarf_Unsigned * list_length,
242
+ Dwarf_Error * error)
243
+ {
244
+ *list_length = gdbindexptr->gi_culisthdr.dg_count;
245
+ return DW_DLV_OK;
246
+ }
247
+
248
+ /* entryindex: 0 to list_length-1 */
249
+ int
250
+ dwarf_gdbindex_culist_entry(Dwarf_Gdbindex gdbindexptr,
251
+ Dwarf_Unsigned entryindex,
252
+ Dwarf_Unsigned * cu_offset,
253
+ Dwarf_Unsigned * cu_length,
254
+ Dwarf_Error * error)
255
+ {
256
+ Dwarf_Unsigned max = gdbindexptr->gi_culisthdr.dg_count;
257
+ Dwarf_Small * base = 0;
258
+ Dwarf_Unsigned offset = 0;
259
+ Dwarf_Unsigned length = 0;
260
+ unsigned fieldlen = gdbindexptr->gi_culisthdr.dg_fieldlen;
261
+
262
+ if (entryindex >= max) {
263
+ _dwarf_error(gdbindexptr->gi_dbg, error,DW_DLE_GDB_INDEX_INDEX_ERROR);
264
+ return DW_DLV_ERROR;
265
+ }
266
+ base = gdbindexptr->gi_culisthdr.dg_base;
267
+ base += entryindex*gdbindexptr->gi_culisthdr.dg_entry_length;
268
+
269
+ READ_GDBINDEX(offset ,Dwarf_Unsigned,
270
+ base,
271
+ fieldlen);
272
+ READ_GDBINDEX(length ,Dwarf_Unsigned,
273
+ base+ fieldlen,
274
+ fieldlen);
275
+ *cu_offset = offset;
276
+ *cu_length = length;
277
+ return DW_DLV_OK;
278
+ }
279
+
280
+ int
281
+ dwarf_gdbindex_types_culist_array(Dwarf_Gdbindex gdbindexptr,
282
+ Dwarf_Unsigned * list_length,
283
+ Dwarf_Error * error)
284
+ {
285
+ *list_length = gdbindexptr->gi_typesculisthdr.dg_count;
286
+ return DW_DLV_OK;
287
+ }
288
+
289
+ /* entryindex: 0 to list_length-1 */
290
+ int
291
+ dwarf_gdbindex_types_culist_entry(Dwarf_Gdbindex gdbindexptr,
292
+ Dwarf_Unsigned entryindex,
293
+ Dwarf_Unsigned * t_offset,
294
+ Dwarf_Unsigned * t_length,
295
+ Dwarf_Unsigned * t_signature,
296
+ Dwarf_Error * error)
297
+ {
298
+ Dwarf_Unsigned max = gdbindexptr->gi_typesculisthdr.dg_count;
299
+ Dwarf_Small * base = 0;
300
+ Dwarf_Unsigned offset = 0;
301
+ Dwarf_Unsigned length = 0;
302
+ Dwarf_Unsigned signature = 0;
303
+ unsigned fieldlen = gdbindexptr->gi_typesculisthdr.dg_fieldlen;
304
+
305
+ if (entryindex >= max) {
306
+ _dwarf_error(gdbindexptr->gi_dbg, error,DW_DLE_GDB_INDEX_INDEX_ERROR);
307
+ return DW_DLV_ERROR;
308
+ }
309
+ base = gdbindexptr->gi_typesculisthdr.dg_base;
310
+ base += entryindex*gdbindexptr->gi_typesculisthdr.dg_entry_length;
311
+
312
+ READ_GDBINDEX(offset ,Dwarf_Unsigned,
313
+ base,
314
+ fieldlen);
315
+ READ_GDBINDEX(length ,Dwarf_Unsigned,
316
+ base+ (1*fieldlen),
317
+ fieldlen);
318
+ READ_GDBINDEX(signature ,Dwarf_Unsigned,
319
+ base+ (2*fieldlen),
320
+ fieldlen);
321
+ *t_offset = offset;
322
+ *t_length = length;
323
+ *t_signature = signature;
324
+ return DW_DLV_OK;
325
+ }
326
+
327
+ int
328
+ dwarf_gdbindex_addressarea(Dwarf_Gdbindex gdbindexptr,
329
+ Dwarf_Unsigned * list_length,
330
+ Dwarf_Error * error)
331
+ {
332
+ *list_length = gdbindexptr->gi_addressareahdr.dg_count;
333
+ return DW_DLV_OK;
334
+ }
335
+
336
+ /* entryindex: 0 to addressarea_list_length-1 */
337
+ int
338
+ dwarf_gdbindex_addressarea_entry(
339
+ Dwarf_Gdbindex gdbindexptr,
340
+ Dwarf_Unsigned entryindex,
341
+ Dwarf_Unsigned * low_address,
342
+ Dwarf_Unsigned * high_address,
343
+ Dwarf_Unsigned * cu_index,
344
+ Dwarf_Error * error)
345
+ {
346
+ Dwarf_Unsigned max = gdbindexptr->gi_addressareahdr.dg_count;
347
+ Dwarf_Small * base = 0;
348
+ Dwarf_Unsigned lowaddr = 0;
349
+ Dwarf_Unsigned highaddr = 0;
350
+ Dwarf_Unsigned cuindex = 0;
351
+
352
+ if (entryindex >= max) {
353
+ _dwarf_error(gdbindexptr->gi_dbg, error,DW_DLE_GDB_INDEX_INDEX_ERROR);
354
+ return DW_DLV_ERROR;
355
+ }
356
+ base = gdbindexptr->gi_addressareahdr.dg_base;
357
+ base += entryindex*gdbindexptr->gi_addressareahdr.dg_entry_length;
358
+
359
+ READ_GDBINDEX(lowaddr ,Dwarf_Unsigned,
360
+ base,
361
+ sizeof(gdbindex_64));
362
+ READ_GDBINDEX(highaddr ,Dwarf_Unsigned,
363
+ base+ (1*sizeof(gdbindex_64)),
364
+ sizeof(gdbindex_64));
365
+ READ_GDBINDEX(cuindex ,Dwarf_Unsigned,
366
+ base+ (2*sizeof(gdbindex_64)),
367
+ sizeof(gdbindex_offset_type));
368
+ *low_address = lowaddr;
369
+ *high_address = highaddr;
370
+ *cu_index = cuindex;
371
+ return DW_DLV_OK;
372
+ }
373
+
374
+ int
375
+ dwarf_gdbindex_symboltable_array(Dwarf_Gdbindex gdbindexptr,
376
+ Dwarf_Unsigned * list_length,
377
+ Dwarf_Error * error)
378
+ {
379
+ *list_length = gdbindexptr->gi_symboltablehdr.dg_count;
380
+ return DW_DLV_OK;
381
+ }
382
+
383
+ /* entryindex: 0 to symtab_list_length-1 */
384
+ int
385
+ dwarf_gdbindex_symboltable_entry(
386
+ Dwarf_Gdbindex gdbindexptr,
387
+ Dwarf_Unsigned entryindex,
388
+ Dwarf_Unsigned * string_offset,
389
+ Dwarf_Unsigned * cu_vector_offset,
390
+ Dwarf_Error * error)
391
+ {
392
+ Dwarf_Unsigned max = gdbindexptr->gi_symboltablehdr.dg_count;
393
+ Dwarf_Small * base = 0;
394
+ Dwarf_Unsigned symoffset = 0;
395
+ Dwarf_Unsigned cuoffset = 0;
396
+ unsigned fieldlen = gdbindexptr->gi_symboltablehdr.dg_fieldlen;
397
+
398
+ if (entryindex >= max) {
399
+ _dwarf_error(gdbindexptr->gi_dbg, error,DW_DLE_GDB_INDEX_INDEX_ERROR);
400
+ return DW_DLV_ERROR;
401
+ }
402
+ base = gdbindexptr->gi_symboltablehdr.dg_base;
403
+ base += entryindex*gdbindexptr->gi_symboltablehdr.dg_entry_length;
404
+
405
+ READ_GDBINDEX(symoffset ,Dwarf_Unsigned,
406
+ base,
407
+ fieldlen);
408
+ READ_GDBINDEX(cuoffset ,Dwarf_Unsigned,
409
+ base + fieldlen,
410
+ fieldlen);
411
+ *string_offset = symoffset;
412
+ *cu_vector_offset = cuoffset;
413
+ return DW_DLV_OK;
414
+ }
415
+
416
+ int
417
+ dwarf_gdbindex_cuvector_length(Dwarf_Gdbindex gdbindex,
418
+ Dwarf_Unsigned cuvector_offset,
419
+ Dwarf_Unsigned * innercount,
420
+ Dwarf_Error * error)
421
+ {
422
+ Dwarf_Small *base = gdbindex->gi_cuvectorhdr.dg_base;
423
+ Dwarf_Small *end = gdbindex->gi_section_data + gdbindex->gi_section_length;
424
+ Dwarf_Unsigned val = 0;
425
+ unsigned fieldlen = gdbindex->gi_cuvectorhdr.dg_entry_length;
426
+
427
+ base += cuvector_offset;
428
+ if ((base + fieldlen) >= end) {
429
+ _dwarf_error(gdbindex->gi_dbg, error,DW_DLE_GDB_INDEX_INDEX_ERROR);
430
+ return DW_DLV_ERROR;
431
+ }
432
+
433
+ READ_GDBINDEX(val,Dwarf_Unsigned,
434
+ base,
435
+ fieldlen);
436
+ *innercount = val;
437
+ return DW_DLV_OK;
438
+ }
439
+
440
+ int
441
+ dwarf_gdbindex_cuvector_inner_attributes(Dwarf_Gdbindex gdbindexptr,
442
+ Dwarf_Unsigned cuvector_offset,
443
+ Dwarf_Unsigned innerindex,
444
+ /* The attr_value is a field of bits. For expanded version
445
+ use dwarf_gdbindex_instance_expand_value() */
446
+ Dwarf_Unsigned * attributes,
447
+ Dwarf_Error * error)
448
+ {
449
+ Dwarf_Small *base = gdbindexptr->gi_cuvectorhdr.dg_base;
450
+ Dwarf_Small *end = gdbindexptr->gi_section_data +
451
+ gdbindexptr->gi_section_length;
452
+ Dwarf_Unsigned val = 0;
453
+ unsigned fieldlen = gdbindexptr->gi_cuvectorhdr.dg_entry_length;
454
+
455
+ base += cuvector_offset;
456
+ if ((base+fieldlen) >= end) {
457
+ _dwarf_error(gdbindexptr->gi_dbg, error,DW_DLE_GDB_INDEX_INDEX_ERROR);
458
+ return DW_DLV_ERROR;
459
+ }
460
+ base += fieldlen;
461
+ base += innerindex*fieldlen;
462
+
463
+ READ_GDBINDEX(val ,Dwarf_Unsigned,
464
+ base,
465
+ fieldlen);
466
+ *attributes = val;
467
+ return DW_DLV_OK;
468
+ }
469
+
470
+
471
+ int
472
+ dwarf_gdbindex_cuvector_instance_expand_value(Dwarf_Gdbindex gdbindexptr,
473
+ Dwarf_Unsigned value,
474
+ Dwarf_Unsigned * cu_index,
475
+ Dwarf_Unsigned * reserved1,
476
+ Dwarf_Unsigned * symbol_kind,
477
+ Dwarf_Unsigned * is_static,
478
+ Dwarf_Error * error)
479
+ {
480
+ *cu_index = value & 0xffffff;
481
+ *reserved1 = (value >> 24) & 0xf;
482
+ *symbol_kind = (value >> 28) & 0x7;
483
+ *is_static = (value >> 31) & 1;
484
+ return DW_DLV_OK;
485
+ }
486
+
487
+
488
+ /* The strings in the pool follow (in memory) the cu index
489
+ set and are NUL terminated. */
490
+ int
491
+ dwarf_gdbindex_string_by_offset(Dwarf_Gdbindex gdbindexptr,
492
+ Dwarf_Unsigned stringoffsetinpool,
493
+ const char ** string_ptr,
494
+ Dwarf_Error * error)
495
+ {
496
+ Dwarf_Small *pooldata = gdbindexptr->gi_section_data +
497
+ gdbindexptr->gi_constant_pool_offset;
498
+ Dwarf_Small *section_end = gdbindexptr->gi_section_data +
499
+ gdbindexptr->gi_section_length;
500
+
501
+ Dwarf_Small *stringitself = pooldata + stringoffsetinpool;
502
+ if (stringitself > section_end) {
503
+ _dwarf_error(gdbindexptr->gi_dbg, error,DW_DLE_GDB_INDEX_INDEX_ERROR);
504
+ return DW_DLV_ERROR;
505
+ }
506
+ *string_ptr = (const char *)stringitself;
507
+ return DW_DLV_OK;
508
+ }
509
+
510
+
511
+
512
+
513
+ void
514
+ dwarf_gdbindex_free(Dwarf_Gdbindex indexptr)
515
+ {
516
+ if(indexptr) {
517
+ Dwarf_Debug dbg = indexptr->gi_dbg;
518
+ dwarf_dealloc(dbg,indexptr,DW_DLA_GDBINDEX);
519
+ }
520
+ }