rdwarf 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,38 @@
1
+ /*
2
+ Copyright (C) 2000,2005 Silicon Graphics, Inc. All Rights Reserved.
3
+ Portions Copyright (C) 2008-2011 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
+ /* #define DWARF_SIMPLE_MALLOC 1 */
28
+
29
+ char * _dwarf_get_alloc(Dwarf_Debug, Dwarf_Small, Dwarf_Unsigned);
30
+ Dwarf_Debug _dwarf_get_debug(void);
31
+ int _dwarf_free_all_of_one_debug(Dwarf_Debug);
32
+ struct Dwarf_Error_s * _dwarf_special_no_dbg_error_malloc(void);
33
+
34
+
35
+ /* ALLOC_AREA_INDEX_TABLE_MAX is the size of the
36
+ struct ial_s index_into_allocated array in dwarf_alloc.c
37
+ */
38
+ #define ALLOC_AREA_INDEX_TABLE_MAX 60
@@ -0,0 +1,595 @@
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
+
8
+ This program is free software; you can redistribute it and/or modify it
9
+ under the terms of version 2.1 of the GNU Lesser General Public License
10
+ as published by the Free Software Foundation.
11
+
12
+ This program is distributed in the hope that it would be useful, but
13
+ WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+
16
+ Further, this software is distributed without any warranty that it is
17
+ free of the rightful claim of any third person regarding infringement
18
+ or the like. Any license provided herein, whether implied or
19
+ otherwise, applies only to this software file. Patent licenses, if
20
+ any, provided herein do not apply to combinations of this program with
21
+ other software, or any other product whatsoever.
22
+
23
+ You should have received a copy of the GNU Lesser General Public
24
+ License along with this program; if not, write the Free Software
25
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
26
+ USA.
27
+
28
+ */
29
+
30
+ #include "config.h"
31
+ #include "dwarf_incl.h"
32
+ #include <stdio.h>
33
+ #include "dwarf_arange.h"
34
+ #include "dwarf_global.h" /* for _dwarf_fixup_* */
35
+
36
+
37
+ /* Common code for two user-visible routines to share.
38
+ Errors here result in memory leaks, but errors here
39
+ are serious (making aranges unusable) so we assume
40
+ callers will not repeat the error often or mind the leaks.
41
+ */
42
+ static int
43
+ dwarf_get_aranges_list(Dwarf_Debug dbg,
44
+ Dwarf_Chain * chain_out,
45
+ Dwarf_Signed * chain_count_out,
46
+ Dwarf_Error * error)
47
+ {
48
+ /* Sweeps through the arange. */
49
+ Dwarf_Small *arange_ptr = 0;
50
+ Dwarf_Small *arange_ptr_start = 0;
51
+
52
+ /* Start of arange header. Used for rounding offset of arange_ptr
53
+ to twice the tuple size. Libdwarf requirement. */
54
+ Dwarf_Small *header_ptr = 0;
55
+
56
+ /* Version of .debug_aranges header. */
57
+ Dwarf_Half version = 0;
58
+
59
+ /* Offset of current set of aranges into .debug_info. */
60
+ Dwarf_Off info_offset = 0;
61
+
62
+ /* Size in bytes of addresses in target. */
63
+ Dwarf_Small address_size = 0;
64
+
65
+ /* Size in bytes of segment offsets in target. */
66
+ Dwarf_Small segment_size = 0;
67
+
68
+ /* Count of total number of aranges. */
69
+ Dwarf_Signed arange_count = 0;
70
+
71
+ Dwarf_Arange arange = 0;
72
+
73
+ /* Used to chain Dwarf_Aranges structs. */
74
+ Dwarf_Chain curr_chain = NULL;
75
+ Dwarf_Chain prev_chain = NULL;
76
+ Dwarf_Chain head_chain = NULL;
77
+ if (!dbg->de_debug_aranges.dss_size) {
78
+ return (DW_DLV_NO_ENTRY);
79
+ }
80
+
81
+
82
+ arange_ptr = dbg->de_debug_aranges.dss_data;
83
+ arange_ptr_start = arange_ptr;
84
+ do {
85
+ /* Length of current set of aranges.
86
+ This is local length, which begins just
87
+ after the length field itself. */
88
+ Dwarf_Unsigned area_length = 0;
89
+ Dwarf_Small remainder = 0;
90
+ Dwarf_Small *arange_ptr_past_end = 0;
91
+ Dwarf_Unsigned range_entry_size = 0;
92
+
93
+ int local_length_size;
94
+
95
+ /*REFERENCED*/ /* Not used in this instance of the macro */
96
+ int local_extension_size = 0;
97
+
98
+ header_ptr = arange_ptr;
99
+
100
+ /* READ_AREA_LENGTH updates arange_ptr for consumed bytes */
101
+ READ_AREA_LENGTH(dbg, area_length, Dwarf_Unsigned,
102
+ arange_ptr, local_length_size,
103
+ local_extension_size);
104
+ /* arange_ptr has been incremented appropriately past
105
+ the length field by READ_AREA_LENGTH. */
106
+ arange_ptr_past_end = arange_ptr + area_length;
107
+
108
+
109
+ READ_UNALIGNED(dbg, version, Dwarf_Half,
110
+ arange_ptr, sizeof(Dwarf_Half));
111
+ arange_ptr += sizeof(Dwarf_Half);
112
+ if (version != DW_ARANGES_VERSION2) {
113
+ _dwarf_error(dbg, error, DW_DLE_VERSION_STAMP_ERROR);
114
+ return (DW_DLV_ERROR);
115
+ }
116
+
117
+ READ_UNALIGNED(dbg, info_offset, Dwarf_Off,
118
+ arange_ptr, local_length_size);
119
+ arange_ptr += local_length_size;
120
+ /* This applies to debug_info only, not to debug_types. */
121
+ if (info_offset >= dbg->de_debug_info.dss_size) {
122
+ FIX_UP_OFFSET_IRIX_BUG(dbg, info_offset,
123
+ "arange info offset.a");
124
+ if (info_offset >= dbg->de_debug_info.dss_size) {
125
+ _dwarf_error(dbg, error, DW_DLE_ARANGE_OFFSET_BAD);
126
+ return (DW_DLV_ERROR);
127
+ }
128
+ }
129
+
130
+ address_size = *(Dwarf_Small *) arange_ptr;
131
+ if (address_size > sizeof(Dwarf_Addr)) {
132
+ _dwarf_error(dbg, error, DW_DLE_ADDRESS_SIZE_ERROR);
133
+ return DW_DLV_ERROR;
134
+ }
135
+ if (address_size == 0) {
136
+ _dwarf_error(dbg, error, DW_DLE_ADDRESS_SIZE_ERROR);
137
+ return DW_DLV_ERROR;
138
+ }
139
+ /* It is not an error if the sizes differ.
140
+ Unusual, but not an error. */
141
+ arange_ptr = arange_ptr + sizeof(Dwarf_Small);
142
+
143
+ /* Even DWARF2 had a segment_size field here, meaning
144
+ size in bytes of a segment descriptor on the target
145
+ system. */
146
+ segment_size = *(Dwarf_Small *) arange_ptr;
147
+ if (segment_size > sizeof(Dwarf_Addr)) {
148
+ _dwarf_error(dbg, error, DW_DLE_SEGMENT_SIZE_BAD);
149
+ return (DW_DLV_ERROR);
150
+ }
151
+ arange_ptr = arange_ptr + sizeof(Dwarf_Small);
152
+
153
+ range_entry_size = 2*address_size + segment_size;
154
+ /* Round arange_ptr offset to next multiple of address_size. */
155
+ remainder = (Dwarf_Unsigned) (arange_ptr - header_ptr) %
156
+ (range_entry_size);
157
+ if (remainder != 0) {
158
+ arange_ptr = arange_ptr + (2 * address_size) - remainder;
159
+ }
160
+ do {
161
+ Dwarf_Addr range_address = 0;
162
+ Dwarf_Unsigned segment_selector = 0;
163
+ Dwarf_Unsigned range_length = 0;
164
+ /* For segmented address spaces, the first field to
165
+ read is a segment selector (new in DWARF4).
166
+ Surprising since the segment_size was always there
167
+ in the table header! */
168
+ if ((version >= 4) && (segment_size != 0)) {
169
+ READ_UNALIGNED(dbg, segment_selector, Dwarf_Unsigned,
170
+ arange_ptr, segment_size);
171
+ arange_ptr += address_size;
172
+ }
173
+
174
+ READ_UNALIGNED(dbg, range_address, Dwarf_Addr,
175
+ arange_ptr, address_size);
176
+ arange_ptr += address_size;
177
+
178
+ READ_UNALIGNED(dbg, range_length, Dwarf_Unsigned,
179
+ arange_ptr, address_size);
180
+ arange_ptr += address_size;
181
+
182
+ {
183
+ /* We used to suppress all-zero entries, but
184
+ now we return all aranges entries so we show
185
+ the entire content. March 31, 2010. */
186
+
187
+ arange = (Dwarf_Arange)
188
+ _dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1);
189
+ if (arange == NULL) {
190
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
191
+ return (DW_DLV_ERROR);
192
+ }
193
+
194
+ arange->ar_segment_selector = segment_selector;
195
+ arange->ar_segment_selector_size = segment_size;
196
+ arange->ar_address = range_address;
197
+ arange->ar_length = range_length;
198
+ arange->ar_info_offset = info_offset;
199
+ arange->ar_dbg = dbg;
200
+ arange_count++;
201
+
202
+ curr_chain = (Dwarf_Chain)
203
+ _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1);
204
+ if (curr_chain == NULL) {
205
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
206
+ return (DW_DLV_ERROR);
207
+ }
208
+
209
+ curr_chain->ch_item = arange;
210
+ if (head_chain == NULL)
211
+ head_chain = prev_chain = curr_chain;
212
+ else {
213
+ prev_chain->ch_next = curr_chain;
214
+ prev_chain = curr_chain;
215
+ }
216
+ }
217
+ /* The current set of ranges is terminated by
218
+ range_address 0 and range_length 0, but that
219
+ does not necessarily terminate the ranges for this CU!
220
+ There can be multiple sets in that DWARF
221
+ does not explicitly forbid multiple sets.
222
+ DWARF2,3,4 section 7.20
223
+ We stop short to avoid overrun of the end of the CU. */
224
+
225
+ } while (arange_ptr_past_end >= (arange_ptr + range_entry_size));
226
+
227
+ /* A compiler could emit some padding bytes here. dwarf2/3
228
+ (dwarf4 sec 7.20) does not clearly make extra padding
229
+ bytes illegal. */
230
+ if (arange_ptr_past_end < arange_ptr) {
231
+ char buf[200];
232
+ Dwarf_Unsigned pad_count = arange_ptr - arange_ptr_past_end;
233
+ Dwarf_Unsigned offset = arange_ptr - arange_ptr_start;
234
+ snprintf(buf,sizeof(buf),"DW_DLE_ARANGE_LENGTH_BAD."
235
+ " 0x%" DW_PR_XZEROS DW_PR_DUx
236
+ " pad bytes at offset 0x%" DW_PR_XZEROS DW_PR_DUx
237
+ " in .debug_aranges",
238
+ pad_count, offset);
239
+ dwarf_insert_harmless_error(dbg,buf);
240
+ }
241
+ /* For most compilers, arange_ptr == arange_ptr_past_end at
242
+ this point. But not if there were padding bytes */
243
+ arange_ptr = arange_ptr_past_end;
244
+ } while (arange_ptr <
245
+ dbg->de_debug_aranges.dss_data + dbg->de_debug_aranges.dss_size);
246
+
247
+ if (arange_ptr !=
248
+ dbg->de_debug_aranges.dss_data + dbg->de_debug_aranges.dss_size) {
249
+ _dwarf_error(dbg, error, DW_DLE_ARANGE_DECODE_ERROR);
250
+ return (DW_DLV_ERROR);
251
+ }
252
+ *chain_out = head_chain;
253
+ *chain_count_out = arange_count;
254
+ return DW_DLV_OK;
255
+ }
256
+
257
+ /*
258
+ This function returns the count of the number of
259
+ aranges in the .debug_aranges section. It sets
260
+ aranges to point to a block of Dwarf_Arange's
261
+ describing the arange's. It returns DW_DLV_ERROR
262
+ on error.
263
+
264
+ Must be identical in most aspects to
265
+ dwarf_get_aranges_addr_offsets!
266
+
267
+ */
268
+ int
269
+ dwarf_get_aranges(Dwarf_Debug dbg,
270
+ Dwarf_Arange ** aranges,
271
+ Dwarf_Signed * returned_count, Dwarf_Error * error)
272
+ {
273
+ /* Count of total number of aranges. */
274
+ Dwarf_Signed arange_count = 0;
275
+
276
+ Dwarf_Arange *arange_block = 0;
277
+
278
+ /* Used to chain Dwarf_Aranges structs. */
279
+ Dwarf_Chain curr_chain = NULL;
280
+ Dwarf_Chain prev_chain = NULL;
281
+ Dwarf_Chain head_chain = NULL;
282
+ Dwarf_Signed i = 0;
283
+ int res = DW_DLV_ERROR;
284
+
285
+ /* ***** BEGIN CODE ***** */
286
+
287
+ if (dbg == NULL) {
288
+ _dwarf_error(NULL, error, DW_DLE_DBG_NULL);
289
+ return (DW_DLV_ERROR);
290
+ }
291
+
292
+ res = _dwarf_load_section(dbg, &dbg->de_debug_aranges, error);
293
+ if (res != DW_DLV_OK) {
294
+ return res;
295
+ }
296
+
297
+ res = dwarf_get_aranges_list(dbg,&head_chain,&arange_count,error);
298
+ if (res != DW_DLV_OK) {
299
+ return res;
300
+ }
301
+
302
+ arange_block = (Dwarf_Arange *)
303
+ _dwarf_get_alloc(dbg, DW_DLA_LIST, arange_count);
304
+ if (arange_block == NULL) {
305
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
306
+ return (DW_DLV_ERROR);
307
+ }
308
+
309
+ curr_chain = head_chain;
310
+ for (i = 0; i < arange_count; i++) {
311
+ *(arange_block + i) = curr_chain->ch_item;
312
+ prev_chain = curr_chain;
313
+ curr_chain = curr_chain->ch_next;
314
+ dwarf_dealloc(dbg, prev_chain, DW_DLA_CHAIN);
315
+ }
316
+
317
+ *aranges = arange_block;
318
+ *returned_count = (arange_count);
319
+ return DW_DLV_OK;
320
+ }
321
+
322
+ /*
323
+ This function returns DW_DLV_OK if it succeeds
324
+ and DW_DLV_ERR or DW_DLV_OK otherwise.
325
+ count is set to the number of addresses in the
326
+ .debug_aranges section.
327
+ For each address, the corresponding element in
328
+ an array is set to the address itself(aranges) and
329
+ the section offset (offsets).
330
+ Must be identical in most aspects to
331
+ dwarf_get_aranges!
332
+ */
333
+ int
334
+ _dwarf_get_aranges_addr_offsets(Dwarf_Debug dbg,
335
+ Dwarf_Addr ** addrs,
336
+ Dwarf_Off ** offsets,
337
+ Dwarf_Signed * count,
338
+ Dwarf_Error * error)
339
+ {
340
+ Dwarf_Signed i = 0;
341
+
342
+ /* Used to chain Dwarf_Aranges structs. */
343
+ Dwarf_Chain curr_chain = NULL;
344
+ Dwarf_Chain prev_chain = NULL;
345
+ Dwarf_Chain head_chain = NULL;
346
+
347
+ Dwarf_Signed arange_count = 0;
348
+ Dwarf_Addr *arange_addrs = 0;
349
+ Dwarf_Off *arange_offsets = 0;
350
+
351
+ int res = DW_DLV_ERROR;
352
+
353
+ /* ***** BEGIN CODE ***** */
354
+
355
+ if (error != NULL)
356
+ *error = NULL;
357
+
358
+ if (dbg == NULL) {
359
+ _dwarf_error(NULL, error, DW_DLE_DBG_NULL);
360
+ return (DW_DLV_ERROR);
361
+ }
362
+
363
+ res = _dwarf_load_section(dbg, &dbg->de_debug_aranges,error);
364
+ if (res != DW_DLV_OK) {
365
+ return res;
366
+ }
367
+
368
+ res = dwarf_get_aranges_list(dbg,&head_chain,&arange_count,error);
369
+ if (res != DW_DLV_OK) {
370
+ return res;
371
+ }
372
+
373
+ arange_addrs = (Dwarf_Addr *)
374
+ _dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count);
375
+ if (arange_addrs == NULL) {
376
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
377
+ return (DW_DLV_ERROR);
378
+ }
379
+ arange_offsets = (Dwarf_Off *)
380
+ _dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count);
381
+ if (arange_offsets == NULL) {
382
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
383
+ return (DW_DLV_ERROR);
384
+ }
385
+
386
+ curr_chain = head_chain;
387
+ for (i = 0; i < arange_count; i++) {
388
+ Dwarf_Arange ar = curr_chain->ch_item;
389
+
390
+ arange_addrs[i] = ar->ar_address;
391
+ arange_offsets[i] = ar->ar_info_offset;
392
+ prev_chain = curr_chain;
393
+ curr_chain = curr_chain->ch_next;
394
+ dwarf_dealloc(dbg, ar, DW_DLA_ARANGE);
395
+ dwarf_dealloc(dbg, prev_chain, DW_DLA_CHAIN);
396
+ }
397
+ *count = arange_count;
398
+ *offsets = arange_offsets;
399
+ *addrs = arange_addrs;
400
+ return (DW_DLV_OK);
401
+ }
402
+
403
+
404
+ /*
405
+ This function takes a pointer to a block
406
+ of Dwarf_Arange's, and a count of the
407
+ length of the block. It checks if the
408
+ given address is within the range of an
409
+ address range in the block. If yes, it
410
+ returns the appropriate Dwarf_Arange.
411
+ Otherwise, it returns DW_DLV_ERROR.
412
+ */
413
+ int
414
+ dwarf_get_arange(Dwarf_Arange * aranges,
415
+ Dwarf_Unsigned arange_count,
416
+ Dwarf_Addr address,
417
+ Dwarf_Arange * returned_arange, Dwarf_Error * error)
418
+ {
419
+ Dwarf_Arange curr_arange = 0;
420
+ Dwarf_Unsigned i = 0;
421
+
422
+ if (aranges == NULL) {
423
+ _dwarf_error(NULL, error, DW_DLE_ARANGES_NULL);
424
+ return (DW_DLV_ERROR);
425
+ }
426
+ for (i = 0; i < arange_count; i++) {
427
+ curr_arange = *(aranges + i);
428
+ if (address >= curr_arange->ar_address &&
429
+ address <
430
+ curr_arange->ar_address + curr_arange->ar_length) {
431
+ *returned_arange = curr_arange;
432
+ return (DW_DLV_OK);
433
+ }
434
+ }
435
+
436
+ return (DW_DLV_NO_ENTRY);
437
+ }
438
+
439
+
440
+ /*
441
+ This function takes an Dwarf_Arange,
442
+ and returns the offset of the first
443
+ die in the compilation-unit that the
444
+ arange belongs to. Returns DW_DLV_ERROR
445
+ on error.
446
+
447
+ For an arange, the cu_die can only be from debug_info,
448
+ not debug_types, it seems.
449
+ */
450
+ int
451
+ dwarf_get_cu_die_offset(Dwarf_Arange arange,
452
+ Dwarf_Off * returned_offset,
453
+ Dwarf_Error * error)
454
+ {
455
+ Dwarf_Debug dbg = 0;
456
+ Dwarf_Off offset = 0;
457
+
458
+ if (arange == NULL) {
459
+ _dwarf_error(NULL, error, DW_DLE_ARANGE_NULL);
460
+ return (DW_DLV_ERROR);
461
+ }
462
+ dbg = arange->ar_dbg;
463
+ offset = arange->ar_info_offset;
464
+ /* This applies to debug_info only, not to debug_types. */
465
+ if (!dbg->de_debug_info.dss_data) {
466
+ int res = _dwarf_load_debug_info(dbg, error);
467
+
468
+ if (res != DW_DLV_OK) {
469
+ return res;
470
+ }
471
+ }
472
+ *returned_offset = offset + _dwarf_length_of_cu_header(dbg, offset, true);
473
+ return DW_DLV_OK;
474
+ }
475
+
476
+ /* This function takes an Dwarf_Arange,
477
+ and returns the offset of the CU header
478
+ in the compilation-unit that the
479
+ arange belongs to. Returns DW_DLV_ERROR
480
+ on error.
481
+ Ensures .debug_info loaded so
482
+ the cu_offset is meaningful. */
483
+ int
484
+ dwarf_get_arange_cu_header_offset(Dwarf_Arange arange,
485
+ Dwarf_Off * cu_header_offset_returned,
486
+ Dwarf_Error * error)
487
+ {
488
+ Dwarf_Debug dbg = 0;
489
+ if (arange == NULL) {
490
+ _dwarf_error(NULL, error, DW_DLE_ARANGE_NULL);
491
+ return (DW_DLV_ERROR);
492
+ }
493
+ dbg = arange->ar_dbg;
494
+ /* This applies to debug_info only, not to debug_types. */
495
+ /* Like dwarf_get_arange_info this ensures debug_info loaded:
496
+ the cu_header is in debug_info and will be used else
497
+ we would not call dwarf_get_arange_cu_header_offset. */
498
+ if (!dbg->de_debug_info.dss_data) {
499
+ int res = _dwarf_load_debug_info(dbg, error);
500
+ if (res != DW_DLV_OK) {
501
+ return res;
502
+ }
503
+ }
504
+ *cu_header_offset_returned = arange->ar_info_offset;
505
+ return DW_DLV_OK;
506
+ }
507
+
508
+
509
+
510
+
511
+ /*
512
+ This function takes a Dwarf_Arange, and returns
513
+ true if it is not NULL. It also stores the start
514
+ address of the range in *start, the length of the
515
+ range in *length, and the offset of the first die
516
+ in the compilation-unit in *cu_die_offset. It
517
+ returns false on error.
518
+ If cu_die_offset returned ensures .debug_info loaded so
519
+ the cu_die_offset is meaningful.
520
+ */
521
+ int
522
+ dwarf_get_arange_info(Dwarf_Arange arange,
523
+ Dwarf_Addr * start,
524
+ Dwarf_Unsigned * length,
525
+ Dwarf_Off * cu_die_offset, Dwarf_Error * error)
526
+ {
527
+ if (arange == NULL) {
528
+ _dwarf_error(NULL, error, DW_DLE_ARANGE_NULL);
529
+ return (DW_DLV_ERROR);
530
+ }
531
+
532
+ if (start != NULL)
533
+ *start = arange->ar_address;
534
+ if (length != NULL)
535
+ *length = arange->ar_length;
536
+ if (cu_die_offset != NULL) {
537
+ Dwarf_Debug dbg = arange->ar_dbg;
538
+ Dwarf_Off offset = arange->ar_info_offset;
539
+
540
+ /* This applies to debug_info only, not to debug_types. */
541
+ if (!dbg->de_debug_info.dss_data) {
542
+ int res = _dwarf_load_debug_info(dbg, error);
543
+ if (res != DW_DLV_OK) {
544
+ return res;
545
+ }
546
+ }
547
+ *cu_die_offset =
548
+ offset + _dwarf_length_of_cu_header(dbg, offset,true);
549
+ }
550
+ return (DW_DLV_OK);
551
+ }
552
+
553
+
554
+ /* New for DWARF4, entries may have segment information.
555
+ *segment is only meaningful if *segment_entry_size is non-zero. */
556
+ int
557
+ dwarf_get_arange_info_b(Dwarf_Arange arange,
558
+ Dwarf_Unsigned* segment,
559
+ Dwarf_Unsigned* segment_entry_size,
560
+ Dwarf_Addr * start,
561
+ Dwarf_Unsigned* length,
562
+ Dwarf_Off * cu_die_offset,
563
+ Dwarf_Error * error)
564
+ {
565
+ if (arange == NULL) {
566
+ _dwarf_error(NULL, error, DW_DLE_ARANGE_NULL);
567
+ return (DW_DLV_ERROR);
568
+ }
569
+
570
+ if (segment != NULL) {
571
+ *segment = arange->ar_segment_selector;
572
+ }
573
+ if (segment_entry_size != NULL) {
574
+ *segment_entry_size = arange->ar_segment_selector_size;
575
+ }
576
+ if (start != NULL)
577
+ *start = arange->ar_address;
578
+ if (length != NULL)
579
+ *length = arange->ar_length;
580
+ if (cu_die_offset != NULL) {
581
+ Dwarf_Debug dbg = arange->ar_dbg;
582
+ Dwarf_Off offset = arange->ar_info_offset;
583
+
584
+ /* This applies to debug_info only, not to debug_types. */
585
+ if (!dbg->de_debug_info.dss_data) {
586
+ int res = _dwarf_load_debug_info(dbg, error);
587
+ if (res != DW_DLV_OK) {
588
+ return res;
589
+ }
590
+ }
591
+ *cu_die_offset =
592
+ offset + _dwarf_length_of_cu_header(dbg, offset,true);
593
+ }
594
+ return (DW_DLV_OK);
595
+ }