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,572 @@
1
+ /*
2
+
3
+ Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved.
4
+ Portions Copyright 2011-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 "libdwarfdefs.h"
31
+ #include <stdio.h>
32
+ #include <string.h>
33
+ #include <limits.h>
34
+ #include "pro_incl.h"
35
+ #include "pro_frame.h"
36
+
37
+ static void _dwarf_pro_add_to_fde(Dwarf_P_Fde fde,
38
+ Dwarf_P_Frame_Pgm inst);
39
+
40
+ /* This function adds a cie struct to the debug pointer. Its in the
41
+ form of a linked list.
42
+ augmenter: string reps augmentation (implementation defined)
43
+ code_align: alignment of code
44
+ data_align: alignment of data
45
+ init_bytes: byts having initial instructions
46
+ init_n_bytes: number of bytes of initial instructions */
47
+ Dwarf_Unsigned
48
+ dwarf_add_frame_cie(Dwarf_P_Debug dbg,
49
+ char *augmenter,
50
+ Dwarf_Small code_align,
51
+ Dwarf_Small data_align,
52
+ Dwarf_Small return_reg,
53
+ Dwarf_Ptr init_bytes,
54
+ Dwarf_Unsigned init_n_bytes, Dwarf_Error * error)
55
+ {
56
+ Dwarf_P_Cie curcie;
57
+
58
+ if (dbg->de_frame_cies == NULL) {
59
+ dbg->de_frame_cies = (Dwarf_P_Cie)
60
+ _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Cie_s));
61
+ if (dbg->de_frame_cies == NULL) {
62
+ DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_ALLOC, DW_DLV_NOCOUNT);
63
+ }
64
+ curcie = dbg->de_frame_cies;
65
+ dbg->de_n_cie = 1;
66
+ dbg->de_last_cie = curcie;
67
+ } else {
68
+ curcie = dbg->de_last_cie;
69
+ curcie->cie_next = (Dwarf_P_Cie)
70
+ _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Cie_s));
71
+ if (curcie->cie_next == NULL) {
72
+ DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_ALLOC, DW_DLV_NOCOUNT);
73
+ }
74
+ curcie = curcie->cie_next;
75
+ dbg->de_n_cie++;
76
+ dbg->de_last_cie = curcie;
77
+ }
78
+ curcie->cie_version = DW_CIE_VERSION;
79
+ curcie->cie_aug = augmenter;
80
+ curcie->cie_code_align = code_align;
81
+ curcie->cie_data_align = data_align;
82
+ curcie->cie_ret_reg = return_reg;
83
+ curcie->cie_inst = (char *) init_bytes;
84
+ curcie->cie_inst_bytes = (long) init_n_bytes;
85
+ curcie->cie_next = NULL;
86
+ return dbg->de_n_cie;
87
+ }
88
+
89
+
90
+ /* This functions adds a fde struct to the debug pointer. Its in the
91
+ form of a linked list.
92
+ die: subprogram/function die corresponding to this fde
93
+ cie: cie referred to by this fde, obtained from call to
94
+ add_frame_cie() routine.
95
+ virt_addr: beginning address
96
+ code_len: length of code reps by the fde */
97
+ /*ARGSUSED*/ /* pretend all args used */
98
+ Dwarf_Unsigned
99
+ dwarf_add_frame_fde(Dwarf_P_Debug dbg,
100
+ Dwarf_P_Fde fde,
101
+ Dwarf_P_Die die,
102
+ Dwarf_Unsigned cie,
103
+ Dwarf_Unsigned virt_addr,
104
+ Dwarf_Unsigned code_len,
105
+ Dwarf_Unsigned symidx, Dwarf_Error * error)
106
+ {
107
+ return dwarf_add_frame_fde_b(dbg, fde, die, cie, virt_addr,
108
+ code_len, symidx, 0, 0, error);
109
+ }
110
+
111
+ /*ARGSUSED10*/
112
+ Dwarf_Unsigned
113
+ dwarf_add_frame_fde_b(Dwarf_P_Debug dbg,
114
+ Dwarf_P_Fde fde,
115
+ Dwarf_P_Die die,
116
+ Dwarf_Unsigned cie,
117
+ Dwarf_Unsigned virt_addr,
118
+ Dwarf_Unsigned code_len,
119
+ Dwarf_Unsigned symidx,
120
+ Dwarf_Unsigned symidx_of_end,
121
+ Dwarf_Addr offset_from_end_sym,
122
+ Dwarf_Error * error)
123
+ {
124
+ Dwarf_P_Fde curfde;
125
+
126
+ fde->fde_die = die;
127
+ fde->fde_cie = (long) cie;
128
+ fde->fde_initloc = virt_addr;
129
+ fde->fde_r_symidx = symidx;
130
+ fde->fde_addr_range = code_len;
131
+ fde->fde_offset_into_exception_tables = DW_DLX_NO_EH_OFFSET;
132
+ fde->fde_exception_table_symbol = 0;
133
+ fde->fde_end_symbol_offset = offset_from_end_sym;
134
+ fde->fde_end_symbol = symidx_of_end;
135
+ fde->fde_dbg = dbg;
136
+
137
+ curfde = dbg->de_last_fde;
138
+ if (curfde == NULL) {
139
+ dbg->de_frame_fdes = fde;
140
+ dbg->de_last_fde = fde;
141
+ dbg->de_n_fde = 1;
142
+ } else {
143
+ curfde->fde_next = fde;
144
+ dbg->de_last_fde = fde;
145
+ dbg->de_n_fde++;
146
+ }
147
+ return dbg->de_n_fde;
148
+ }
149
+
150
+ /* This function adds information to an fde. The fde is
151
+ linked into the linked list of fde's maintained in the Dwarf_P_Debug
152
+ structure.
153
+ dbg: The debug descriptor.
154
+ fde: The fde to be added.
155
+ die: subprogram/function die corresponding to this fde
156
+ cie: cie referred to by this fde, obtained from call to
157
+ add_frame_cie() routine.
158
+ virt_addr: beginning address
159
+ code_len: length of code reps by the fde
160
+ symidx: The symbol id of the symbol wrt to which relocation needs
161
+ to be performed for 'virt_addr'.
162
+ offset_into_exception_tables: The start of exception tables for
163
+ this function (indicated as an offset into the exception
164
+ tables). A value of -1 indicates that there is no exception
165
+ table entries associated with this function.
166
+ exception_table_symbol: The symbol id of the section for exception
167
+ tables wrt to which the offset_into_exception_tables will
168
+ be relocated. */
169
+ Dwarf_Unsigned
170
+ dwarf_add_frame_info(Dwarf_P_Debug dbg,
171
+ Dwarf_P_Fde fde,
172
+ Dwarf_P_Die die,
173
+ Dwarf_Unsigned cie,
174
+ Dwarf_Unsigned virt_addr,
175
+ Dwarf_Unsigned code_len,
176
+ Dwarf_Unsigned symidx,
177
+ Dwarf_Signed offset_into_exception_tables,
178
+ Dwarf_Unsigned exception_table_symbol,
179
+ Dwarf_Error * error)
180
+ {
181
+
182
+ return dwarf_add_frame_info_b(dbg, fde, die, cie, virt_addr,
183
+ code_len, symidx,
184
+ /* end_symbol */ 0,
185
+ /* offset_from_end */ 0,
186
+ offset_into_exception_tables,
187
+ exception_table_symbol, error);
188
+
189
+ }
190
+
191
+ /*ARGSUSED*/ /* pretend all args used */
192
+ Dwarf_Unsigned
193
+ dwarf_add_frame_info_b(Dwarf_P_Debug dbg,
194
+ Dwarf_P_Fde fde,
195
+ Dwarf_P_Die die,
196
+ Dwarf_Unsigned cie,
197
+ Dwarf_Unsigned virt_addr,
198
+ Dwarf_Unsigned code_len,
199
+ Dwarf_Unsigned symidx,
200
+ Dwarf_Unsigned end_symidx,
201
+ Dwarf_Unsigned offset_from_end_symbol,
202
+ Dwarf_Signed offset_into_exception_tables,
203
+ Dwarf_Unsigned exception_table_symbol,
204
+ Dwarf_Error * error)
205
+ {
206
+ Dwarf_P_Fde curfde;
207
+
208
+ fde->fde_die = die;
209
+ fde->fde_cie = (long) cie;
210
+ fde->fde_initloc = virt_addr;
211
+ fde->fde_r_symidx = symidx;
212
+ fde->fde_addr_range = code_len;
213
+ fde->fde_offset_into_exception_tables =
214
+ offset_into_exception_tables;
215
+ fde->fde_exception_table_symbol = exception_table_symbol;
216
+ fde->fde_end_symbol_offset = offset_from_end_symbol;
217
+ fde->fde_end_symbol = end_symidx;
218
+ fde->fde_dbg = dbg;
219
+
220
+ curfde = dbg->de_last_fde;
221
+ if (curfde == NULL) {
222
+ dbg->de_frame_fdes = fde;
223
+ dbg->de_last_fde = fde;
224
+ dbg->de_n_fde = 1;
225
+ } else {
226
+ curfde->fde_next = fde;
227
+ dbg->de_last_fde = fde;
228
+ dbg->de_n_fde++;
229
+ }
230
+ return dbg->de_n_fde;
231
+ }
232
+
233
+ /* This is an alternate to inserting frame instructions
234
+ one instruction at a time. But use either this
235
+ or instruction level, not both in one fde. */
236
+ int
237
+ dwarf_insert_fde_inst_bytes(Dwarf_P_Debug dbg,
238
+ Dwarf_P_Fde fde,Dwarf_Unsigned len, Dwarf_Ptr ibytes,
239
+ Dwarf_Error *error)
240
+ {
241
+ if (len == 0) {
242
+ return DW_DLV_OK;
243
+ }
244
+ if (fde->fde_block || fde->fde_inst) {
245
+ DWARF_P_DBG_ERROR(dbg, DW_DLE_DUPLICATE_INST_BLOCK,
246
+ (int)DW_DLV_BADADDR);
247
+ }
248
+ fde->fde_block = (Dwarf_Ptr)_dwarf_p_get_alloc(dbg, len);
249
+ memcpy(fde->fde_block,ibytes,len);
250
+ fde->fde_inst_block_size = len;
251
+ fde->fde_n_bytes += len;
252
+ return DW_DLV_OK;
253
+ }
254
+
255
+
256
+
257
+ /* Create a new fde. */
258
+ Dwarf_P_Fde
259
+ dwarf_new_fde(Dwarf_P_Debug dbg, Dwarf_Error * error)
260
+ {
261
+ Dwarf_P_Fde fde;
262
+
263
+ fde = (Dwarf_P_Fde)
264
+ _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Fde_s));
265
+ if (fde == NULL) {
266
+ DWARF_P_DBG_ERROR(dbg, DW_DLE_FDE_ALLOC,
267
+ (Dwarf_P_Fde) DW_DLV_BADADDR);
268
+ }
269
+ fde->fde_uwordb_size = dbg->de_offset_size;
270
+ return fde;
271
+ }
272
+
273
+
274
+ /* Add a cfe_offset instruction to the fde passed in. */
275
+ Dwarf_P_Fde
276
+ dwarf_fde_cfa_offset(Dwarf_P_Fde fde,
277
+ Dwarf_Unsigned reg,
278
+ Dwarf_Signed offset, Dwarf_Error * error)
279
+ {
280
+ Dwarf_Ubyte opc, regno;
281
+ char *ptr = 0;
282
+ Dwarf_P_Frame_Pgm curinst;
283
+ int nbytes = 0;
284
+ int res = 0;
285
+ char buff1[ENCODE_SPACE_NEEDED];
286
+ Dwarf_P_Debug dbg = fde->fde_dbg;
287
+
288
+ curinst = (Dwarf_P_Frame_Pgm)
289
+ _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Frame_Pgm_s));
290
+ if (curinst == NULL) {
291
+ DWARF_P_DBG_ERROR(dbg, DW_DLE_FPGM_ALLOC,
292
+ (Dwarf_P_Fde) DW_DLV_BADADDR);
293
+ }
294
+ opc = DW_CFA_offset;
295
+ regno = reg;
296
+ if (regno & 0xc0) {
297
+ DWARF_P_DBG_ERROR(dbg, DW_DLE_REGNO_OVFL,
298
+ (Dwarf_P_Fde) DW_DLV_BADADDR);
299
+ }
300
+ opc = opc | regno; /* lower 6 bits are register number */
301
+ curinst->dfp_opcode = opc;
302
+ res = _dwarf_pro_encode_leb128_nm(offset, &nbytes,
303
+ buff1, sizeof(buff1));
304
+ if (res != DW_DLV_OK) {
305
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
306
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
307
+ }
308
+ ptr = (char *) _dwarf_p_get_alloc(dbg, nbytes);
309
+ if (ptr == NULL) {
310
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
311
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
312
+ }
313
+ memcpy(ptr, buff1, nbytes);
314
+
315
+ curinst->dfp_args = ptr;
316
+ curinst->dfp_nbytes = nbytes;
317
+ curinst->dfp_next = NULL;
318
+
319
+ _dwarf_pro_add_to_fde(fde, curinst);
320
+ return fde;
321
+ }
322
+
323
+ /* Generic routine to add opcode to fde instructions. val1 and
324
+ val2 are parameters whose interpretation depends on the 'op'.
325
+
326
+ This does not work properly for DW_DLC_SYMBOLIC_RELOCATIONS
327
+ for DW_CFA_set_loc or DW_DVA_advance_loc* 'op', as
328
+ these ops normally are addresses or (DW_CFA_set_loc)
329
+ or code lengths (DW_DVA_advance_loc*) and such must be
330
+ represented with relocations and symbol indices for
331
+ DW_DLC_SYMBOLIC_RELOCATIONS.
332
+
333
+ This does not treat all DW_CFA instructions yet.
334
+
335
+ For certain operations a val? value must be
336
+ signed (though passed in as unsigned here).
337
+
338
+ Currently this does not check that the frame
339
+ version is 3(for dwarf3) or 4 (for dwarf4)
340
+ when applying operations that are only valid for
341
+ dwarf3 or dwarf4. */
342
+ Dwarf_P_Fde
343
+ dwarf_add_fde_inst(Dwarf_P_Fde fde,
344
+ Dwarf_Small op,
345
+ Dwarf_Unsigned val1,
346
+ Dwarf_Unsigned val2, Dwarf_Error * error)
347
+ {
348
+ Dwarf_P_Frame_Pgm curinst;
349
+ int nbytes, nbytes1, nbytes2;
350
+ Dwarf_Ubyte db;
351
+ Dwarf_Half dh;
352
+ Dwarf_Word dw;
353
+ Dwarf_Unsigned du;
354
+ char *ptr;
355
+ int res;
356
+ char buff1[ENCODE_SPACE_NEEDED];
357
+ char buff2[ENCODE_SPACE_NEEDED];
358
+ Dwarf_P_Debug dbg = fde->fde_dbg;
359
+ /* This is a hack telling the code when to transform
360
+ a value to a signed leb number. */
361
+ int signed_second = 0;
362
+ int signed_first = 0;
363
+
364
+
365
+ nbytes = 0;
366
+ ptr = NULL;
367
+ curinst = (Dwarf_P_Frame_Pgm)
368
+ _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Frame_Pgm_s));
369
+ if (curinst == NULL) {
370
+ _dwarf_p_error(dbg, error, DW_DLE_FPGM_ALLOC);
371
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
372
+ }
373
+
374
+ switch (op) {
375
+
376
+ case DW_CFA_advance_loc:
377
+ if (val1 <= 0x3f) {
378
+ db = val1;
379
+ op |= db;
380
+ }
381
+ /* test not portable FIX */
382
+ else if (val1 <= UCHAR_MAX) {
383
+ op = DW_CFA_advance_loc1;
384
+ db = val1;
385
+ ptr = (char *) _dwarf_p_get_alloc(dbg, 1);
386
+ if (ptr == NULL) {
387
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
388
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
389
+ }
390
+ memcpy((void *) ptr, (const void *) &db, 1);
391
+ nbytes = 1;
392
+ }
393
+ /* test not portable FIX */
394
+ else if (val1 <= USHRT_MAX) {
395
+ op = DW_CFA_advance_loc2;
396
+ dh = val1;
397
+ ptr = (char *) _dwarf_p_get_alloc(dbg, 2);
398
+ if (ptr == NULL) {
399
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
400
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
401
+ }
402
+ memcpy((void *) ptr, (const void *) &dh, 2);
403
+ nbytes = 2;
404
+ }
405
+ /* test not portable FIX */
406
+ else if (val1 <= ULONG_MAX) {
407
+ op = DW_CFA_advance_loc4;
408
+ dw = (Dwarf_Word) val1;
409
+ ptr = (char *) _dwarf_p_get_alloc(dbg, 4);
410
+ if (ptr == NULL) {
411
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
412
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
413
+ }
414
+ memcpy((void *) ptr, (const void *) &dw, 4);
415
+ nbytes = 4;
416
+ } else {
417
+ op = DW_CFA_MIPS_advance_loc8;
418
+ du = val1;
419
+ ptr =
420
+ (char *) _dwarf_p_get_alloc(dbg,
421
+ sizeof(Dwarf_Unsigned));
422
+ if (ptr == NULL) {
423
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
424
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
425
+ }
426
+ memcpy((void *) ptr, (const void *) &du, 8);
427
+ nbytes = 8;
428
+ }
429
+ break;
430
+
431
+ case DW_CFA_offset:
432
+ if (val1 <= MAX_6_BIT_VALUE) {
433
+ db = val1;
434
+ op |= db;
435
+ res = _dwarf_pro_encode_leb128_nm(val2, &nbytes,
436
+ buff1, sizeof(buff1));
437
+ if (res != DW_DLV_OK) {
438
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
439
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
440
+ }
441
+ ptr = (char *) _dwarf_p_get_alloc(dbg, nbytes);
442
+ if (ptr == NULL) {
443
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
444
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
445
+ }
446
+ memcpy(ptr, buff1, nbytes);
447
+
448
+ } else {
449
+ op = DW_CFA_offset_extended;
450
+ goto two_leb;
451
+ }
452
+ break;
453
+ case DW_CFA_offset_extended_sf: /* DWARF3 */
454
+ signed_second = 1;
455
+ goto two_leb;
456
+ case DW_CFA_offset_extended:
457
+ goto two_leb;
458
+
459
+ case DW_CFA_undefined:
460
+ case DW_CFA_same_value:
461
+ goto one_leb;
462
+
463
+ case DW_CFA_val_offset:
464
+ goto two_leb;
465
+ case DW_CFA_val_offset_sf:
466
+ signed_second = 1;
467
+ goto two_leb;
468
+ case DW_CFA_def_cfa_sf:
469
+ signed_second = 1;
470
+ goto two_leb;
471
+ case DW_CFA_register:
472
+ case DW_CFA_def_cfa:
473
+ two_leb:
474
+ res = _dwarf_pro_encode_leb128_nm(val1, &nbytes1,
475
+ buff1, sizeof(buff1));
476
+ if (res != DW_DLV_OK) {
477
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
478
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
479
+ }
480
+ if (!signed_second) {
481
+ res = _dwarf_pro_encode_leb128_nm(val2, &nbytes2,
482
+ buff2, sizeof(buff2));
483
+ } else {
484
+ Dwarf_Signed val2s = val2;
485
+ res = _dwarf_pro_encode_signed_leb128_nm(val2s, &nbytes2,
486
+ buff2, sizeof(buff2));
487
+ }
488
+
489
+ res = _dwarf_pro_encode_leb128_nm(val2, &nbytes2,
490
+ buff2, sizeof(buff2));
491
+ if (res != DW_DLV_OK) {
492
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
493
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
494
+ }
495
+
496
+ ptr = (char *) _dwarf_p_get_alloc(dbg, nbytes1 + nbytes2);
497
+ if (ptr == NULL) {
498
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
499
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
500
+ }
501
+ memcpy(ptr, buff1, nbytes1);
502
+ memcpy(ptr + nbytes1, buff2, nbytes2);
503
+ nbytes = nbytes1 + nbytes2;
504
+ break;
505
+
506
+ case DW_CFA_def_cfa_offset_sf: /* DWARF3 */
507
+ signed_first = 1;
508
+ goto one_leb;
509
+ case DW_CFA_def_cfa_register:
510
+ case DW_CFA_def_cfa_offset:
511
+ one_leb:
512
+ if (!signed_first) {
513
+ res = _dwarf_pro_encode_leb128_nm(val1, &nbytes,
514
+ buff1, sizeof(buff1));
515
+ } else {
516
+ Dwarf_Signed val1s = val1;
517
+ res = _dwarf_pro_encode_signed_leb128_nm(val1s, &nbytes,
518
+ buff1, sizeof(buff1));
519
+ }
520
+ if (res != DW_DLV_OK) {
521
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
522
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
523
+ }
524
+ ptr = (char *) _dwarf_p_get_alloc(dbg, nbytes);
525
+ if (ptr == NULL) {
526
+ _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
527
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
528
+ }
529
+ memcpy(ptr, buff1, nbytes);
530
+ break;
531
+ case DW_CFA_def_cfa_expression: /* DWARF3 */
532
+ /* FIXME: argument is dwarf expr, not handled yet. */
533
+ case DW_CFA_expression: /* DWARF3 */
534
+ /* First arg: ULEB reg num. 2nd arg dwarf expr in form block.
535
+ FIXME: not handled yet. */
536
+ case DW_CFA_val_expression: /* DWARF3f */
537
+ /* First arg: ULEB reg num. 2nd arg dwarf expr in form block.
538
+ FIXME: not handled yet. */
539
+ default:
540
+ _dwarf_p_error(dbg, error, DW_DLE_DEBUGFRAME_ERROR);
541
+ return ((Dwarf_P_Fde) DW_DLV_BADADDR);
542
+ }
543
+
544
+ curinst->dfp_opcode = op;
545
+ curinst->dfp_args = ptr;
546
+ curinst->dfp_nbytes = nbytes;
547
+ curinst->dfp_next = NULL;
548
+
549
+ _dwarf_pro_add_to_fde(fde, curinst);
550
+ return fde;
551
+ }
552
+
553
+
554
+ /* Instructions are added to an fde in the form of a linked
555
+ list. This function manages the linked list. */
556
+ void
557
+ _dwarf_pro_add_to_fde(Dwarf_P_Fde fde, Dwarf_P_Frame_Pgm curinst)
558
+ {
559
+ if (fde->fde_last_inst) {
560
+ fde->fde_last_inst->dfp_next = curinst;
561
+ fde->fde_last_inst = curinst;
562
+ fde->fde_n_inst++;
563
+ fde->fde_n_bytes +=
564
+ (long) (curinst->dfp_nbytes + sizeof(Dwarf_Ubyte));
565
+ } else {
566
+ fde->fde_last_inst = curinst;
567
+ fde->fde_inst = curinst;
568
+ fde->fde_n_inst = 1;
569
+ fde->fde_n_bytes =
570
+ (long) (curinst->dfp_nbytes + sizeof(Dwarf_Ubyte));
571
+ }
572
+ }