Bug 439685 compiler warning in callgrind/main.c
[valgrind.git] / coregrind / m_debuginfo / d3basics.c
blobe9e8944af8d62f8a553c758ab91f77187f1f3f78
2 /*--------------------------------------------------------------------*/
3 /*--- Basic definitions and helper functions for DWARF3. ---*/
4 /*--- d3basics.c ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
11 Copyright (C) 2008-2017 OpenWorks LLP
12 info@open-works.co.uk
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
29 Neither the names of the U.S. Department of Energy nor the
30 University of California nor the names of its contributors may be
31 used to endorse or promote products derived from this software
32 without prior written permission.
35 #include "pub_core_basics.h"
36 #include "pub_core_debuginfo.h"
37 #include "pub_core_libcassert.h"
38 #include "pub_core_libcprint.h"
39 #include "pub_core_libcbase.h"
40 #include "pub_core_options.h"
41 #include "pub_core_xarray.h"
43 #include "pub_core_vki.h" /* VKI_PROT_READ */
44 #include "pub_core_aspacemgr.h" /* VG_(is_valid_for_client) */
46 #include "priv_misc.h"
47 #include "priv_image.h"
48 #include "priv_d3basics.h" /* self */
49 #include "priv_storage.h"
51 const HChar* ML_(pp_DW_children) ( DW_children hashch )
53 switch (hashch) {
54 case DW_children_no: return "no children";
55 case DW_children_yes: return "has children";
57 return "DW_children_???";
60 const HChar* ML_(pp_DW_TAG) ( DW_TAG tag )
62 switch (tag) {
63 case DW_TAG_padding: return "DW_TAG_padding";
64 case DW_TAG_array_type: return "DW_TAG_array_type";
65 case DW_TAG_class_type: return "DW_TAG_class_type";
66 case DW_TAG_entry_point: return "DW_TAG_entry_point";
67 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
68 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
69 case DW_TAG_imported_declaration:
70 return "DW_TAG_imported_declaration";
71 case DW_TAG_label: return "DW_TAG_label";
72 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
73 case DW_TAG_member: return "DW_TAG_member";
74 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
75 case DW_TAG_reference_type: return "DW_TAG_reference_type";
76 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
77 case DW_TAG_string_type: return "DW_TAG_string_type";
78 case DW_TAG_structure_type: return "DW_TAG_structure_type";
79 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
80 case DW_TAG_typedef: return "DW_TAG_typedef";
81 case DW_TAG_union_type: return "DW_TAG_union_type";
82 case DW_TAG_unspecified_parameters:
83 return "DW_TAG_unspecified_parameters";
84 case DW_TAG_variant: return "DW_TAG_variant";
85 case DW_TAG_common_block: return "DW_TAG_common_block";
86 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
87 case DW_TAG_inheritance: return "DW_TAG_inheritance";
88 case DW_TAG_inlined_subroutine:
89 return "DW_TAG_inlined_subroutine";
90 case DW_TAG_module: return "DW_TAG_module";
91 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
92 case DW_TAG_set_type: return "DW_TAG_set_type";
93 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
94 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
95 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
96 case DW_TAG_base_type: return "DW_TAG_base_type";
97 case DW_TAG_catch_block: return "DW_TAG_catch_block";
98 case DW_TAG_const_type: return "DW_TAG_const_type";
99 case DW_TAG_constant: return "DW_TAG_constant";
100 case DW_TAG_enumerator: return "DW_TAG_enumerator";
101 case DW_TAG_file_type: return "DW_TAG_file_type";
102 case DW_TAG_friend: return "DW_TAG_friend";
103 case DW_TAG_namelist: return "DW_TAG_namelist";
104 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
105 case DW_TAG_packed_type: return "DW_TAG_packed_type";
106 case DW_TAG_subprogram: return "DW_TAG_subprogram";
107 case DW_TAG_template_type_param:
108 return "DW_TAG_template_type_param";
109 case DW_TAG_template_value_param:
110 return "DW_TAG_template_value_param";
111 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
112 case DW_TAG_try_block: return "DW_TAG_try_block";
113 case DW_TAG_variant_part: return "DW_TAG_variant_part";
114 case DW_TAG_variable: return "DW_TAG_variable";
115 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
116 /* DWARF 3. */
117 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
118 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
119 case DW_TAG_interface_type: return "DW_TAG_interface_type";
120 case DW_TAG_namespace: return "DW_TAG_namespace";
121 case DW_TAG_imported_module: return "DW_TAG_imported_module";
122 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
123 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
124 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
125 case DW_TAG_condition: return "DW_TAG_condition";
126 case DW_TAG_shared_type: return "DW_TAG_shared_type";
127 /* DWARF 4. */
128 case DW_TAG_type_unit: return "DW_TAG_type_unit";
129 case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type";
130 case DW_TAG_template_alias: return "DW_TAG_template_alias";
131 /* DWARF 5. */
132 case DW_TAG_coarray_type: return "DW_TAG_coarray_type";
133 case DW_TAG_generic_subrange: return "DW_TAG_generic_subrange";
134 case DW_TAG_dynamic_type: return "DW_TAG_dynamic_type";
135 case DW_TAG_atomic_type: return "DW_TAG_atomic_type";
136 case DW_TAG_call_site: return "DW_TAG_call_site";
137 case DW_TAG_call_site_parameter:
138 return "DW_TAG_call_site_parameter";
139 case DW_TAG_skeleton_unit: return "DW_TAG_skeleton_unit";
140 case DW_TAG_immutable_type: return "DW_TAG_immutable_type";
141 /* SGI/MIPS Extensions. */
142 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
143 /* HP extensions. See:
144 ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz . */
145 case DW_TAG_HP_array_descriptor:
146 return "DW_TAG_HP_array_descriptor";
147 /* GNU extensions. */
148 case DW_TAG_format_label: return "DW_TAG_format_label";
149 case DW_TAG_function_template: return "DW_TAG_function_template";
150 case DW_TAG_class_template: return "DW_TAG_class_template";
151 case DW_TAG_GNU_BINCL: return "DW_TAG_GNU_BINCL";
152 case DW_TAG_GNU_EINCL: return "DW_TAG_GNU_EINCL";
153 case DW_TAG_GNU_template_template_param:
154 return "DW_TAG_GNU_template_template_param";
155 case DW_TAG_GNU_template_parameter_pack:
156 return"DW_TAG_GNU_template_parameter_pack";
157 case DW_TAG_GNU_formal_parameter_pack:
158 return "DW_TAG_GNU_formal_parameter_pack";
159 case DW_TAG_GNU_call_site:
160 return "DW_TAG_GNU_call_site";
161 case DW_TAG_GNU_call_site_parameter:
162 return "DW_TAG_GNU_call_site_parameter";
163 /* Extensions for UPC. See: http://upc.gwu.edu/~upc. */
164 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
165 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
166 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
167 /* PGI (STMicroelectronics) extensions. No documentation available. */
168 case DW_TAG_PGI_kanji_type: return "DW_TAG_PGI_kanji_type";
169 case DW_TAG_PGI_interface_block:
170 return "DW_TAG_PGI_interface_block";
172 return "DW_TAG_???";
175 const HChar* ML_(pp_DW_FORM) ( DW_FORM form )
177 switch (form) {
178 case DW_FORM_addr: return "DW_FORM_addr";
179 case DW_FORM_block2: return "DW_FORM_block2";
180 case DW_FORM_block4: return "DW_FORM_block4";
181 case DW_FORM_data2: return "DW_FORM_data2";
182 case DW_FORM_data4: return "DW_FORM_data4";
183 case DW_FORM_data8: return "DW_FORM_data8";
184 case DW_FORM_string: return "DW_FORM_string";
185 case DW_FORM_block: return "DW_FORM_block";
186 case DW_FORM_block1: return "DW_FORM_block1";
187 case DW_FORM_data1: return "DW_FORM_data1";
188 case DW_FORM_flag: return "DW_FORM_flag";
189 case DW_FORM_sdata: return "DW_FORM_sdata";
190 case DW_FORM_strp: return "DW_FORM_strp";
191 case DW_FORM_udata: return "DW_FORM_udata";
192 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
193 case DW_FORM_ref1: return "DW_FORM_ref1";
194 case DW_FORM_ref2: return "DW_FORM_ref2";
195 case DW_FORM_ref4: return "DW_FORM_ref4";
196 case DW_FORM_ref8: return "DW_FORM_ref8";
197 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
198 case DW_FORM_indirect: return "DW_FORM_indirect";
199 case DW_FORM_sec_offset:return "DW_FORM_sec_offset";
200 case DW_FORM_exprloc: return "DW_FORM_exprloc";
201 case DW_FORM_flag_present:return "DW_FORM_flag_present";
202 case DW_FORM_ref_sig8: return "DW_FORM_ref_sig8";
203 case DW_FORM_strx: return "DW_FORM_strx";
204 case DW_FORM_addrx: return "DW_FORM_addrx";
205 case DW_FORM_ref_sup4: return "DW_FORM_ref_sup4";
206 case DW_FORM_strp_sup: return "DW_FORM_strp_sup";
207 case DW_FORM_data16: return "DW_FORM_data16";
208 case DW_FORM_line_strp: return "DW_FORM_line_strp";
209 case DW_FORM_implicit_const:return "DW_FORM_implicit_const";
210 case DW_FORM_loclistx: return "DW_FORM_loclistx";
211 case DW_FORM_rnglistx: return "DW_FORM_rnglistx";
212 case DW_FORM_ref_sup8: return "DW_FORM_ref_sup8";
213 case DW_FORM_strx1: return "DW_FORM_strx1";
214 case DW_FORM_strx2: return "DW_FORM_strx2";
215 case DW_FORM_strx3: return "DW_FORM_strx3";
216 case DW_FORM_strx4: return "DW_FORM_strx4";
217 case DW_FORM_addrx1: return "DW_FORM_addrx1";
218 case DW_FORM_addrx2: return "DW_FORM_addrx2";
219 case DW_FORM_addrx3: return "DW_FORM_addrx3";
220 case DW_FORM_addrx4: return "DW_FORM_addrx4";
221 /* GNU Debug Fission extensions. */
222 case DW_FORM_GNU_addr_index:return "DW_FORM_GNU_addr_index";
223 case DW_FORM_GNU_str_index:return "DW_FORM_GNU_str_index";
224 case DW_FORM_GNU_ref_alt:return "DW_FORM_GNU_ref_alt";
225 case DW_FORM_GNU_strp_alt:return "DW_FORM_GNU_strp_alt";
227 return "DW_FORM_???";
230 const HChar* ML_(pp_DW_AT) ( DW_AT attr )
232 switch (attr) {
233 case DW_AT_sibling: return "DW_AT_sibling";
234 case DW_AT_location: return "DW_AT_location";
235 case DW_AT_name: return "DW_AT_name";
236 case DW_AT_ordering: return "DW_AT_ordering";
237 case DW_AT_subscr_data: return "DW_AT_subscr_data";
238 case DW_AT_byte_size: return "DW_AT_byte_size";
239 case DW_AT_bit_offset: return "DW_AT_bit_offset";
240 case DW_AT_bit_size: return "DW_AT_bit_size";
241 case DW_AT_element_list: return "DW_AT_element_list";
242 case DW_AT_stmt_list: return "DW_AT_stmt_list";
243 case DW_AT_low_pc: return "DW_AT_low_pc";
244 case DW_AT_high_pc: return "DW_AT_high_pc";
245 case DW_AT_language: return "DW_AT_language";
246 case DW_AT_member: return "DW_AT_member";
247 case DW_AT_discr: return "DW_AT_discr";
248 case DW_AT_discr_value: return "DW_AT_discr_value";
249 case DW_AT_visibility: return "DW_AT_visibility";
250 case DW_AT_import: return "DW_AT_import";
251 case DW_AT_string_length: return "DW_AT_string_length";
252 case DW_AT_common_reference: return "DW_AT_common_reference";
253 case DW_AT_comp_dir: return "DW_AT_comp_dir";
254 case DW_AT_const_value: return "DW_AT_const_value";
255 case DW_AT_containing_type: return "DW_AT_containing_type";
256 case DW_AT_default_value: return "DW_AT_default_value";
257 case DW_AT_inline: return "DW_AT_inline";
258 case DW_AT_is_optional: return "DW_AT_is_optional";
259 case DW_AT_lower_bound: return "DW_AT_lower_bound";
260 case DW_AT_producer: return "DW_AT_producer";
261 case DW_AT_prototyped: return "DW_AT_prototyped";
262 case DW_AT_return_addr: return "DW_AT_return_addr";
263 case DW_AT_start_scope: return "DW_AT_start_scope";
264 case DW_AT_stride_size: return "DW_AT_stride_size";
265 case DW_AT_upper_bound: return "DW_AT_upper_bound";
266 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
267 case DW_AT_accessibility: return "DW_AT_accessibility";
268 case DW_AT_address_class: return "DW_AT_address_class";
269 case DW_AT_artificial: return "DW_AT_artificial";
270 case DW_AT_base_types: return "DW_AT_base_types";
271 case DW_AT_calling_convention: return "DW_AT_calling_convention";
272 case DW_AT_count: return "DW_AT_count";
273 case DW_AT_data_member_location: return "DW_AT_data_member_location";
274 case DW_AT_decl_column: return "DW_AT_decl_column";
275 case DW_AT_decl_file: return "DW_AT_decl_file";
276 case DW_AT_decl_line: return "DW_AT_decl_line";
277 case DW_AT_declaration: return "DW_AT_declaration";
278 case DW_AT_discr_list: return "DW_AT_discr_list";
279 case DW_AT_encoding: return "DW_AT_encoding";
280 case DW_AT_external: return "DW_AT_external";
281 case DW_AT_frame_base: return "DW_AT_frame_base";
282 case DW_AT_friend: return "DW_AT_friend";
283 case DW_AT_identifier_case: return "DW_AT_identifier_case";
284 case DW_AT_macro_info: return "DW_AT_macro_info";
285 case DW_AT_namelist_items: return "DW_AT_namelist_items";
286 case DW_AT_priority: return "DW_AT_priority";
287 case DW_AT_segment: return "DW_AT_segment";
288 case DW_AT_specification: return "DW_AT_specification";
289 case DW_AT_static_link: return "DW_AT_static_link";
290 case DW_AT_type: return "DW_AT_type";
291 case DW_AT_use_location: return "DW_AT_use_location";
292 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
293 case DW_AT_virtuality: return "DW_AT_virtuality";
294 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
295 /* DWARF 3 values. */
296 case DW_AT_allocated: return "DW_AT_allocated";
297 case DW_AT_associated: return "DW_AT_associated";
298 case DW_AT_data_location: return "DW_AT_data_location";
299 case DW_AT_stride: return "DW_AT_stride";
300 case DW_AT_entry_pc: return "DW_AT_entry_pc";
301 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
302 case DW_AT_extension: return "DW_AT_extension";
303 case DW_AT_ranges: return "DW_AT_ranges";
304 case DW_AT_trampoline: return "DW_AT_trampoline";
305 case DW_AT_call_column: return "DW_AT_call_column";
306 case DW_AT_call_file: return "DW_AT_call_file";
307 case DW_AT_call_line: return "DW_AT_call_line";
308 case DW_AT_description: return "DW_AT_description";
309 case DW_AT_binary_scale: return "DW_AT_binary_scale";
310 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
311 case DW_AT_small: return "DW_AT_small";
312 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
313 case DW_AT_digit_count: return "DW_AT_digit_count";
314 case DW_AT_picture_string: return "DW_AT_picture_string";
315 case DW_AT_mutable: return "DW_AT_mutable";
316 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
317 case DW_AT_explicit: return "DW_AT_explicit";
318 case DW_AT_object_pointer: return "DW_AT_object_pointer";
319 case DW_AT_endianity: return "DW_AT_endianity";
320 case DW_AT_elemental: return "DW_AT_elemental";
321 case DW_AT_pure: return "DW_AT_pure";
322 case DW_AT_recursive: return "DW_AT_recursive";
323 /* DWARF 4 values. */
324 case DW_AT_signature: return "DW_AT_signature";
325 case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
326 case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
327 case DW_AT_const_expr: return "DW_AT_const_expr";
328 case DW_AT_enum_class: return "DW_AT_enum_class";
329 case DW_AT_linkage_name: return "DW_AT_linkage_name";
330 /* DWARF 5 values. */
331 case DW_AT_string_length_bit_size: return "DW_AT_string_length_bit_size";
332 case DW_AT_string_length_byte_size: return "DW_AT_string_length_byte_size";
333 case DW_AT_rank: return "DW_AT_rank";
334 case DW_AT_str_offsets_base: return "DW_AT_str_offsets_base";
335 case DW_AT_addr_base: return "DW_AT_addr_base";
336 case DW_AT_rnglists_base: return "DW_AT_rnglists_base";
337 case DW_AT_dwo_name: return "DW_AT_dwo_name";
338 case DW_AT_reference: return "DW_AT_reference";
339 case DW_AT_rvalue_reference: return "DW_AT_rvalue_reference";
340 case DW_AT_macros: return "DW_AT_macros";
341 case DW_AT_call_all_calls: return "DW_AT_call_all_calls";
342 case DW_AT_call_all_source_calls: return "DW_AT_call_all_source_calls";
343 case DW_AT_call_all_tail_calls: return "DW_AT_call_all_tail_calls";
344 case DW_AT_call_return_pc: return "DW_AT_call_return_pc";
345 case DW_AT_call_value: return "DW_AT_call_value";
346 case DW_AT_call_origin: return "DW_AT_call_origin";
347 case DW_AT_call_parameter: return "DW_AT_call_parameter";
348 case DW_AT_call_pc: return "DW_AT_call_pc";
349 case DW_AT_call_tail_call: return "DW_AT_call_tail_call";
350 case DW_AT_call_target: return "DW_AT_call_target";
351 case DW_AT_call_target_clobbered: return "DW_AT_call_target_clobbered";
352 case DW_AT_call_data_location: return "DW_AT_call_data_location";
353 case DW_AT_call_data_value: return "DW_AT_call_data_value";
354 case DW_AT_noreturn: return "DW_AT_noreturn";
355 case DW_AT_alignment: return "DW_AT_alignment";
356 case DW_AT_export_symbols: return "DW_AT_export_symbols";
357 case DW_AT_deleted: return "DW_AT_deleted";
358 case DW_AT_defaulted: return "DW_AT_defaulted";
359 case DW_AT_loclists_base: return "DW_AT_loclists_base";
360 /* SGI/MIPS extensions. */
361 /* case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde"; */
362 /* DW_AT_MIPS_fde == DW_AT_HP_unmodifiable */
363 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
364 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
365 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
366 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
367 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
368 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
369 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
370 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
371 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
372 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
373 /* HP extensions. */
374 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
375 case DW_AT_HP_unmodifiable: return "DW_AT_HP_unmodifiable";
376 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
377 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
378 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
379 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
380 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
381 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
382 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
383 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
384 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
385 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
386 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
387 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
388 /* GNU extensions. */
389 case DW_AT_sf_names: return "DW_AT_sf_names";
390 case DW_AT_src_info: return "DW_AT_src_info";
391 case DW_AT_mac_info: return "DW_AT_mac_info";
392 case DW_AT_src_coords: return "DW_AT_src_coords";
393 case DW_AT_body_begin: return "DW_AT_body_begin";
394 case DW_AT_body_end: return "DW_AT_body_end";
395 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
396 case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by";
397 case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by";
398 case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded";
399 case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded";
400 case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded";
401 case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required";
402 case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required";
403 case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature";
404 case DW_AT_GNU_template_name: return "DW_AT_GNU_template_name";
405 case DW_AT_GNU_call_site_value: return "DW_AT_GNU_call_site_value";
406 case DW_AT_GNU_call_site_data_value: return "DW_AT_GNU_call_site_data_value";
407 case DW_AT_GNU_call_site_target: return "DW_AT_GNU_call_site_target";
408 case DW_AT_GNU_call_site_target_clobbered: return "DW_AT_GNU_call_site_target_clobbered";
409 case DW_AT_GNU_tail_call: return "DW_AT_GNU_tail_call";
410 case DW_AT_GNU_all_tail_call_sites: return "DW_AT_GNU_all_tail_call_sites";
411 case DW_AT_GNU_all_call_sites: return "DW_AT_GNU_all_call_sites";
412 case DW_AT_GNU_all_source_call_sites: return "DW_AT_GNU_all_source_call_sites";
413 case DW_AT_GNU_locviews: return "DW_AT_GNU_locviews";
414 case DW_AT_GNU_entry_view: return "DW_AT_GNU_entry_view";
415 case DW_AT_GNU_macros: return "DW_AT_GNU_macros";
416 case DW_AT_GNU_deleted: return "DW_AT_GNU_deleted";
417 case DW_AT_GNU_dwo_name: return "DW_AT_GNU_dwo_name";
418 case DW_AT_GNU_dwo_id: return "DW_AT_GNU_dwo_id";
419 case DW_AT_GNU_ranges_base: return "DW_AT_GNU_ranges_base";
420 case DW_AT_GNU_addr_base: return "DW_AT_GNU_addr_base";
421 case DW_AT_GNU_pubnames: return "DW_AT_GNU_pubnames";
422 case DW_AT_GNU_pubtypes: return "DW_AT_GNU_pubtypes";
423 case DW_AT_GNU_numerator: return "DW_AT_GNU_numerator";
424 case DW_AT_GNU_denominator: return "DW_AT_GNU_denominator";
425 case DW_AT_GNU_bias: return "DW_AT_GNU_bias";
426 /* VMS extensions. */
427 case DW_AT_VMS_rtnbeg_pd_address: return "DW_AT_VMS_rtnbeg_pd_address";
428 /* UPC extension. */
429 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
430 /* PGI (STMicroelectronics) extensions. */
431 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
432 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
433 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
435 return "DW_AT_???";
438 const HChar* ML_(pp_DW_LLE) ( DW_LLE entry )
440 switch (entry) {
441 case DW_LLE_end_of_list: return "DW_LLE_end_of_list";
442 case DW_LLE_base_addressx: return "DW_LLE_base_addressx";
443 case DW_LLE_startx_endx: return "DW_LLE_startx_endx";
444 case DW_LLE_startx_length: return "DW_LLE_startx_length";
445 case DW_LLE_offset_pair: return "DW_LLE_offset_pair";
446 case DW_LLE_default_location: return "DW_LLE_default_location";
447 case DW_LLE_base_address: return "DW_LLE_base_address";
448 case DW_LLE_start_end: return "DW_LLE_start_end";
449 case DW_LLE_start_length: return "DW_LLE_start_length";
450 case DW_LLE_GNU_view_pair: return "DW_LLE_GNU_view_pair";
452 return "DW_LLE_???";
455 const HChar* ML_(pp_DW_RLE) ( DW_RLE entry )
457 switch (entry) {
458 case DW_RLE_end_of_list: return "DW_RLE_end_of_list";
459 case DW_RLE_base_addressx: return "DW_RLE_base_addressx";
460 case DW_RLE_startx_endx: return "DW_RLE_startx_endx";
461 case DW_RLE_startx_length: return "DW_RLE_startx_length";
462 case DW_RLE_offset_pair: return "DW_RLE_offset_pair";
463 case DW_RLE_base_address: return "DW_RLE_base_address";
464 case DW_RLE_start_end: return "DW_RLE_start_end";
465 case DW_RLE_start_length: return "DW_RLE_start_length";
467 return "DW_RLE_???";
470 /* ------ To do with evaluation of Dwarf expressions ------ */
472 /* FIXME: duplicated in readdwarf.c */
473 static
474 ULong read_leb128 ( const UChar* data, Int* length_return, Int sign )
476 ULong result = 0;
477 UInt num_read = 0;
478 Int shift = 0;
479 UChar byte;
481 vg_assert(sign == 0 || sign == 1);
485 byte = * data ++;
486 num_read ++;
488 result |= ((ULong)(byte & 0x7f)) << shift;
490 shift += 7;
493 while (byte & 0x80);
495 if (length_return != NULL)
496 * length_return = num_read;
498 if (sign && (shift < 64) && (byte & 0x40))
499 result |= -(1ULL << shift);
501 return result;
504 /* Small helper functions easier to use
505 * value is returned and the given pointer is
506 * moved past end of leb128 data */
507 /* FIXME: duplicated in readdwarf.c */
508 static ULong read_leb128U( const UChar **data )
510 Int len;
511 ULong val = read_leb128( *data, &len, 0 );
512 *data += len;
513 return val;
516 /* Same for signed data */
517 /* FIXME: duplicated in readdwarf.c */
518 static Long read_leb128S( const UChar **data )
520 Int len;
521 ULong val = read_leb128( *data, &len, 1 );
522 *data += len;
523 return (Long)val;
526 /* FIXME: duplicates logic in readdwarf.c: copy_convert_CfiExpr_tree
527 and {FP,SP}_REG decls */
528 static Bool get_Dwarf_Reg( /*OUT*/Addr* a, Word regno, const RegSummary* regs )
530 vg_assert(regs);
531 # if defined(VGP_x86_linux) || defined(VGP_x86_darwin) \
532 || defined(VGP_x86_solaris) || defined(VGP_x86_freebsd)
533 if (regno == 5/*EBP*/) { *a = regs->fp; return True; }
534 if (regno == 4/*ESP*/) { *a = regs->sp; return True; }
535 # elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin) \
536 || defined(VGP_amd64_solaris) || defined(VGP_amd64_freebsd)
537 if (regno == 6/*RBP*/) { *a = regs->fp; return True; }
538 if (regno == 7/*RSP*/) { *a = regs->sp; return True; }
539 # elif defined(VGP_ppc32_linux)
540 if (regno == 1/*SP*/) { *a = regs->sp; return True; }
541 # elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
542 if (regno == 1/*SP*/) { *a = regs->sp; return True; }
543 # elif defined(VGP_arm_linux)
544 if (regno == 13) { *a = regs->sp; return True; }
545 if (regno == 11) { *a = regs->fp; return True; }
546 # elif defined(VGP_s390x_linux)
547 if (regno == 15) { *a = regs->sp; return True; }
548 if (regno == 11) { *a = regs->fp; return True; }
549 # elif defined(VGP_mips32_linux) || defined(VGP_nanomips_linux)
550 if (regno == 29) { *a = regs->sp; return True; }
551 if (regno == 30) { *a = regs->fp; return True; }
552 # elif defined(VGP_mips64_linux)
553 if (regno == 29) { *a = regs->sp; return True; }
554 if (regno == 30) { *a = regs->fp; return True; }
555 # elif defined(VGP_arm64_linux)
556 if (regno == 31) { *a = regs->sp; return True; }
557 if (regno == 29) { *a = regs->fp; return True; }
558 # else
559 # error "Unknown platform"
560 # endif
561 return False;
564 /* Convert a stated address to an actual address */
565 static Bool bias_address( Addr* a, const DebugInfo* di )
567 if (di->text_present
568 && di->text_size > 0
569 && *a >= di->text_debug_svma && *a < di->text_debug_svma + di->text_size) {
570 *a += di->text_debug_bias;
572 else if (di->data_present
573 && di->data_size > 0
574 && *a >= di->data_debug_svma && *a < di->data_debug_svma + di->data_size) {
575 *a += di->data_debug_bias;
577 else if (di->sdata_present
578 && di->sdata_size > 0
579 && *a >= di->sdata_debug_svma && *a < di->sdata_debug_svma + di->sdata_size) {
580 *a += di->sdata_debug_bias;
582 else if (di->rodata_present
583 && di->rodata_size > 0
584 && *a >= di->rodata_debug_svma && *a < di->rodata_debug_svma + di->rodata_size) {
585 *a += di->rodata_debug_bias;
587 else if (di->bss_present
588 && di->bss_size > 0
589 && *a >= di->bss_debug_svma && *a < di->bss_debug_svma + di->bss_size) {
590 *a += di->bss_debug_bias;
592 else if (di->sbss_present
593 && di->sbss_size > 0
594 && *a >= di->sbss_debug_svma && *a < di->sbss_debug_svma + di->sbss_size) {
595 *a += di->sbss_debug_bias;
597 else {
598 return False;
601 return True;
605 /* Evaluate a standard DWARF3 expression. See detailed description in
606 priv_d3basics.h. Doesn't handle DW_OP_piece/DW_OP_bit_piece yet. */
607 GXResult ML_(evaluate_Dwarf3_Expr) ( const UChar* expr, UWord exprszB,
608 const GExpr* fbGX, const RegSummary* regs,
609 const DebugInfo* di,
610 Bool push_initial_zero )
612 # define N_EXPR_STACK 20
614 # define FAIL(_str) \
615 do { \
616 res.kind = GXR_Failure; \
617 res.word = (UWord)(_str); \
618 return res; \
619 } while (0)
621 # define PUSH(_arg) \
622 do { \
623 vg_assert(sp >= -1 && sp < N_EXPR_STACK); \
624 if (sp == N_EXPR_STACK-1) \
625 FAIL("evaluate_Dwarf3_Expr: stack overflow(1)"); \
626 sp++; \
627 stack[sp] = (_arg); \
628 } while (0)
630 # define POP(_lval) \
631 do { \
632 vg_assert(sp >= -1 && sp < N_EXPR_STACK); \
633 if (sp == -1) \
634 FAIL("evaluate_Dwarf3_Expr: stack underflow(1)"); \
635 _lval = stack[sp]; \
636 sp--; \
637 } while (0)
639 UChar opcode;
640 const UChar* limit;
641 Int sp; /* # of top element: valid is -1 .. N_EXPR_STACK-1 */
642 Addr stack[N_EXPR_STACK]; /* stack of addresses, as per D3 spec */
643 GXResult fbval, res;
644 Addr a1;
645 Word sw1, sw2;
646 UWord uw1, uw2;
647 Bool ok;
649 sp = -1;
650 vg_assert(expr);
651 vg_assert(exprszB >= 0);
652 limit = expr + exprszB;
654 /* Deal with the case where the entire expression is a single
655 Register Name Operation (D3 spec sec 2.6.1). Then the
656 denotation of the expression as a whole is a register name. */
657 if (exprszB == 1
658 && expr[0] >= DW_OP_reg0 && expr[0] <= DW_OP_reg31) {
659 res.kind = GXR_RegNo;
660 res.word = (UWord)(expr[0] - DW_OP_reg0);
661 return res;
663 if (exprszB > 1
664 && expr[0] == DW_OP_regx) {
665 /* JRS: 2008Feb20: I believe the following is correct, but would
666 like to see a test case show up before enabling it. */
667 expr++;
668 res.kind = GXR_RegNo;
669 res.word = (UWord)read_leb128U( &expr );
670 if (expr != limit)
671 FAIL("evaluate_Dwarf3_Expr: DW_OP_regx*: invalid expr size");
672 else
673 return res;
674 /*NOTREACHED*/
677 /* Evidently this expression denotes a value, not a register name.
678 So evaluate it accordingly. */
680 if (push_initial_zero)
681 PUSH(0);
683 while (True) {
685 vg_assert(sp >= -1 && sp < N_EXPR_STACK);
687 if (expr > limit)
688 /* overrun - something's wrong */
689 FAIL("evaluate_Dwarf3_Expr: ran off end of expr");
691 if (expr == limit) {
692 /* end of expr - return expr on the top of stack. */
693 if (sp == -1)
694 /* stack empty. Bad. */
695 FAIL("evaluate_Dwarf3_Expr: stack empty at end of expr");
696 else
697 break;
700 opcode = *expr++;
701 switch (opcode) {
702 case DW_OP_addr:
703 /* Presumably what is given in the Dwarf3 is a SVMA (how
704 could it be otherwise?) So we add the appropriate bias
705 on before pushing the result. */
706 a1 = ML_(read_Addr)(expr);
707 if (bias_address(&a1, di)) {
708 PUSH( a1 );
709 expr += sizeof(Addr);
711 else {
712 FAIL("evaluate_Dwarf3_Expr: DW_OP_addr with address "
713 "in unknown section");
715 break;
716 case DW_OP_fbreg:
717 if (!fbGX)
718 FAIL("evaluate_Dwarf3_Expr: DW_OP_fbreg with "
719 "no expr for fbreg present");
720 fbval = ML_(evaluate_GX)(fbGX, NULL, regs, di);
721 /* Convert fbval into something we can use. If we got a
722 Value, no problem. However, as per D3 spec sec 3.3.5
723 (Low Level Information) sec 2, we could also get a
724 RegNo, and that is taken to mean the value in the
725 indicated register. So we have to manually
726 "dereference" it. */
727 a1 = 0;
728 switch (fbval.kind) {
729 case GXR_Failure:
730 return fbval; /* propagate failure */
731 case GXR_Addr:
732 a1 = fbval.word; break; /* use as-is */
733 case GXR_RegNo:
734 ok = get_Dwarf_Reg( &a1, fbval.word, regs );
735 if (!ok) return fbval; /* propagate failure */
736 break;
737 case GXR_Value:
738 FAIL("evaluate_Dwarf3_Expr: DW_OP_{implicit,stack}_value "
739 "in DW_AT_frame_base");
740 default:
741 vg_assert(0);
743 sw1 = (Word)read_leb128S( &expr );
744 PUSH( a1 + sw1 );
745 break;
746 /* DW_OP_breg* denotes 'contents of specified register, plus
747 constant offset'. So provided we know what the register's
748 value is, we can evaluate this. Contrast DW_OP_reg*,
749 which indicates that denoted location is in a register
750 itself. If DW_OP_reg* shows up here the expression is
751 malformed, since we are evaluating for value now, and
752 DW_OP_reg* denotes a register location, not a value. See
753 D3 Spec sec 2.6.1 ("Register Name Operations") for
754 details. */
755 case DW_OP_breg0 ... DW_OP_breg31:
756 if (!regs)
757 FAIL("evaluate_Dwarf3_Expr: DW_OP_breg* but no reg info");
758 a1 = 0;
759 if (!get_Dwarf_Reg( &a1, opcode - DW_OP_breg0, regs ))
760 FAIL("evaluate_Dwarf3_Expr: unhandled DW_OP_breg*");
761 sw1 = (Word)read_leb128S( &expr );
762 a1 += sw1;
763 PUSH( a1 );
764 break;
765 case DW_OP_bregx:
766 if (!regs)
767 FAIL("evaluate_Dwarf3_Expr: DW_OP_bregx but no reg info");
768 a1 = 0;
769 uw1 = (UWord)read_leb128U( &expr );
770 if (!get_Dwarf_Reg( &a1, uw1, regs ))
771 FAIL("evaluate_Dwarf3_Expr: unhandled DW_OP_bregx reg value");
772 sw1 = (Word)read_leb128S( &expr );
773 a1 += sw1;
774 PUSH( a1 );
775 break;
776 /* As per comment on DW_OP_breg*, the following denote that
777 the value in question is in a register, not in memory. So
778 we simply return failure. (iow, the expression is
779 malformed). */
780 case DW_OP_reg0 ... DW_OP_reg31:
781 case DW_OP_regx:
782 FAIL("evaluate_Dwarf3_Expr: DW_OP_reg* "
783 "whilst evaluating for a value");
784 break;
785 case DW_OP_plus_uconst:
786 POP(uw1);
787 uw1 += (UWord)read_leb128U( &expr );
788 PUSH(uw1);
789 break;
790 case DW_OP_GNU_push_tls_address:
791 /* GDB contains the following cryptic comment: */
792 /* Variable is at a constant offset in the thread-local
793 storage block into the objfile for the current thread and
794 the dynamic linker module containing this expression. Here
795 we return returns the offset from that base. The top of the
796 stack has the offset from the beginning of the thread
797 control block at which the variable is located. Nothing
798 should follow this operator, so the top of stack would be
799 returned. */
800 /* But no spec resulting from Googling. Punt for now. */
801 FAIL("warning: evaluate_Dwarf3_Expr: unhandled "
802 "DW_OP_GNU_push_tls_address");
803 /*NOTREACHED*/
804 case DW_OP_deref:
805 POP(uw1);
806 if (VG_(am_is_valid_for_client)( (Addr)uw1, sizeof(Addr),
807 VKI_PROT_READ )) {
808 uw1 = ML_(read_UWord)((void *)uw1);
809 PUSH(uw1);
810 } else {
811 FAIL("warning: evaluate_Dwarf3_Expr: DW_OP_deref: "
812 "address not valid for client");
814 break;
815 case DW_OP_deref_size:
816 POP(uw1);
817 uw2 = *expr++;
818 if (VG_(am_is_valid_for_client)( (Addr)uw1, uw2,
819 VKI_PROT_READ )) {
820 switch (uw2) {
821 case 1: uw1 = ML_(read_UChar)((void*)uw1); break;
822 case 2: uw1 = ML_(read_UShort)((void*)uw1); break;
823 case 4: uw1 = ML_(read_UInt)((void*)uw1); break;
824 case 8: uw1 = ML_(read_ULong)((void*)uw1); break;
825 default:
826 FAIL("warning: evaluate_Dwarf3_Expr: unhandled "
827 "DW_OP_deref_size size");
829 PUSH(uw1);
830 } else {
831 FAIL("warning: evaluate_Dwarf3_Expr: DW_OP_deref_size: "
832 "address not valid for client");
834 break;
835 case DW_OP_lit0 ... DW_OP_lit31:
836 PUSH(opcode - DW_OP_lit0);
837 break;
838 case DW_OP_const1u:
839 uw1 = *expr++;
840 PUSH(uw1);
841 break;
842 case DW_OP_const2u:
843 uw1 = ML_(read_UShort)(expr);
844 expr += 2;
845 PUSH(uw1);
846 break;
847 case DW_OP_const4u:
848 uw1 = ML_(read_UInt)(expr);
849 expr += 4;
850 PUSH(uw1);
851 break;
852 case DW_OP_const8u:
853 uw1 = ML_(read_ULong)(expr);
854 expr += 8;
855 PUSH(uw1);
856 break;
857 case DW_OP_constu:
858 uw1 = read_leb128U( &expr );
859 PUSH(uw1);
860 break;
861 case DW_OP_const1s:
862 uw1 = *(const Char *)expr;
863 expr++;
864 PUSH(uw1);
865 break;
866 case DW_OP_const2s:
867 uw1 = ML_(read_Short)(expr);
868 expr += 2;
869 PUSH(uw1);
870 break;
871 case DW_OP_const4s:
872 uw1 = ML_(read_Int)(expr);
873 expr += 4;
874 PUSH(uw1);
875 break;
876 case DW_OP_const8s:
877 uw1 = ML_(read_Long)(expr);
878 expr += 8;
879 PUSH(uw1);
880 break;
881 case DW_OP_consts:
882 uw1 = read_leb128S( &expr );
883 PUSH(uw1);
884 break;
885 case DW_OP_dup:
886 POP(uw1);
887 PUSH(uw1);
888 PUSH(uw1);
889 break;
890 case DW_OP_drop:
891 POP(uw1);
892 break;
893 case DW_OP_over:
894 uw1 = 1;
895 goto do_pick;
896 case DW_OP_pick:
897 uw1 = *expr++;
898 do_pick:
899 if (sp < (Int)uw1)
900 FAIL("evaluate_Dwarf3_Expr: stack underflow");
901 uw1 = stack[sp - uw1];
902 PUSH(uw1);
903 break;
904 case DW_OP_swap:
905 if (sp < 1)
906 FAIL("evaluate_Dwarf3_Expr: stack underflow");
907 uw1 = stack[sp];
908 stack[sp] = stack[sp - 1];
909 stack[sp - 1] = uw1;
910 break;
911 case DW_OP_rot:
912 if (sp < 2)
913 FAIL("evaluate_Dwarf3_Expr: stack underflow");
914 uw1 = stack[sp];
915 stack[sp] = stack[sp - 1];
916 stack[sp - 1] = stack[sp - 2];
917 stack[sp - 2] = uw1;
918 break;
919 case DW_OP_abs:
920 POP(sw1);
921 if (sw1 < 0)
922 sw1 = -sw1;
923 PUSH(sw1);
924 break;
925 case DW_OP_div:
926 POP(sw2);
927 if (sw2 == 0)
928 FAIL("evaluate_Dwarf3_Expr: division by zero");
929 POP(sw1);
930 sw1 /= sw2;
931 PUSH(sw1);
932 break;
933 case DW_OP_mod:
934 POP(uw2);
935 if (uw2 == 0)
936 FAIL("evaluate_Dwarf3_Expr: division by zero");
937 POP(uw1);
938 uw1 %= uw2;
939 PUSH(uw1);
940 break;
941 #define BINARY(name, op, s) \
942 case DW_OP_##name: \
943 POP(s##w2); \
944 POP(s##w1); \
945 s##w1 = s##w1 op s##w2; \
946 PUSH(s##w1); \
947 break
948 #define UNARY(name, op, s) \
949 case DW_OP_##name: \
950 POP(s##w1); \
951 s##w1 = op s##w1; \
952 PUSH(s##w1); \
953 break
954 BINARY (and, &, u);
955 BINARY (minus, -, u);
956 BINARY (mul, *, u);
957 UNARY (neg, -, u);
958 UNARY (not, ~, u);
959 BINARY (or, |, u);
960 BINARY (plus, +, u);
961 BINARY (shl, <<, u);
962 BINARY (shr, >>, u);
963 BINARY (shra, >>, s);
964 BINARY (xor, ^, u);
965 BINARY (le, <=, s);
966 BINARY (lt, <, s);
967 BINARY (ge, >=, s);
968 BINARY (gt, >, s);
969 BINARY (ne, !=, u);
970 BINARY (eq, ==, u);
971 #undef UNARY
972 #undef BINARY
973 case DW_OP_skip:
974 sw1 = ML_(read_Short)(expr);
975 expr += 2;
976 if (expr + sw1 < limit - exprszB)
977 FAIL("evaluate_Dwarf3_Expr: DW_OP_skip before start of expr");
978 if (expr + sw1 >= limit)
979 FAIL("evaluate_Dwarf3_Expr: DW_OP_skip after end of expr");
980 expr += sw1;
981 break;
982 case DW_OP_bra:
983 sw1 = ML_(read_Short)(expr);
984 expr += 2;
985 if (expr + sw1 < limit - exprszB)
986 FAIL("evaluate_Dwarf3_Expr: DW_OP_bra before start of expr");
987 if (expr + sw1 >= limit)
988 FAIL("evaluate_Dwarf3_Expr: DW_OP_bra after end of expr");
989 POP(uw1);
990 if (uw1)
991 expr += sw1;
992 break;
993 case DW_OP_nop:
994 break;
995 case DW_OP_call_frame_cfa:
996 if (!regs)
997 FAIL("evaluate_Dwarf3_Expr: "
998 "DW_OP_call_frame_cfa but no reg info");
999 #if defined(VGP_ppc32_linux) || defined(VGP_ppc64be_linux) \
1000 || defined(VGP_ppc64le_linux)
1001 /* Valgrind on ppc32/ppc64 currently doesn't use unwind info. */
1002 uw1 = ML_(read_Addr)((UChar*)regs->sp);
1003 #else
1004 uw1 = ML_(get_CFA)(regs->ip, regs->sp, regs->fp, 0, ~(UWord) 0);
1005 #endif
1006 /* we expect this to fail on arm-linux, since ML_(get_CFA)
1007 always returns zero at present. */
1008 if (!uw1)
1009 FAIL("evaluate_Dwarf3_Expr: Could not resolve "
1010 "DW_OP_call_frame_cfa");
1011 PUSH(uw1);
1012 break;
1013 case DW_OP_implicit_value:
1014 sw1 = (Word)read_leb128S( &expr );
1015 uw1 = 0;
1016 switch (sw1) {
1017 case 1:
1018 uw1 = ML_(read_UChar)(expr);
1019 expr += 1;
1020 break;
1021 case 2:
1022 uw1 = ML_(read_UShort)(expr);
1023 expr += 2;
1024 break;
1025 case 4:
1026 uw1 = ML_(read_UInt)(expr);
1027 expr += 4;
1028 break;
1029 case 8:
1030 uw1 = ML_(read_ULong)(expr);
1031 expr += 8;
1032 break;
1033 default:
1034 FAIL("evaluate_Dwarf3_Expr: Unhandled "
1035 "DW_OP_implicit_value size");
1037 if (expr != limit)
1038 FAIL("evaluate_Dwarf3_Expr: DW_OP_implicit_value "
1039 "does not terminate expression");
1040 res.word = uw1;
1041 res.kind = GXR_Value;
1042 return res;
1043 case DW_OP_stack_value:
1044 POP (uw1);
1045 res.word = uw1;
1046 res.kind = GXR_Value;
1047 if (expr != limit)
1048 FAIL("evaluate_Dwarf3_Expr: DW_OP_stack_value "
1049 "does not terminate expression");
1050 break;
1051 case DW_OP_entry_value:
1052 case DW_OP_GNU_entry_value:
1053 /* This provides a DWARF expression where any register op
1054 needs tobe evaluated as if the value that register had
1055 upon entering the function. Which is non-trivial to
1056 implement. */
1057 FAIL("evaluate_Dwarf3_Expr: Unhandled DW_OP entry_value");
1058 return res;
1059 default:
1060 if (!VG_(clo_xml))
1061 VG_(message)(Vg_DebugMsg,
1062 "warning: evaluate_Dwarf3_Expr: unhandled "
1063 "DW_OP_ 0x%x\n", (Int)opcode);
1064 FAIL("evaluate_Dwarf3_Expr: unhandled DW_OP_");
1065 /*NOTREACHED*/
1070 vg_assert(sp >= 0 && sp < N_EXPR_STACK);
1071 res.word = stack[sp];
1072 res.kind = GXR_Addr;
1073 return res;
1075 # undef POP
1076 # undef PUSH
1077 # undef FAIL
1078 # undef N_EXPR_STACK
1082 /* Evaluate a so-called Guarded (DWARF3) expression. See detailed
1083 description in priv_d3basics.h. */
1084 GXResult ML_(evaluate_GX)( const GExpr* gx, const GExpr* fbGX,
1085 const RegSummary* regs, const DebugInfo* di )
1087 GXResult res;
1088 Addr aMin, aMax;
1089 UChar uc;
1090 UShort nbytes;
1091 UWord nGuards = 0;
1092 const UChar* p = &gx->payload[0];
1093 uc = *p++; /*biasMe*/
1094 vg_assert(uc == 0 || uc == 1);
1095 /* in fact it's senseless to evaluate if the guards need biasing.
1096 So don't. */
1097 vg_assert(uc == 0);
1098 while (True) {
1099 uc = *p++;
1100 if (uc == 1) { /*isEnd*/
1101 /* didn't find any matching range. */
1102 res.kind = GXR_Failure;
1103 res.word = (UWord)"no matching range";
1104 return res;
1106 vg_assert(uc == 0);
1107 aMin = ML_(read_Addr)(p); p += sizeof(Addr);
1108 aMax = ML_(read_Addr)(p); p += sizeof(Addr);
1109 nbytes = ML_(read_UShort)(p); p += sizeof(UShort);
1110 nGuards++;
1111 if (0) VG_(printf)(" guard %lu: %#lx %#lx\n",
1112 nGuards, aMin,aMax);
1113 if (regs == NULL) {
1114 vg_assert(aMin == (Addr)0);
1115 vg_assert(aMax == ~(Addr)0);
1116 /* Assert this is the first guard. */
1117 vg_assert(nGuards == 1);
1118 res = ML_(evaluate_Dwarf3_Expr)(
1119 p, (UWord)nbytes, fbGX, regs, di,
1120 False/*push_initial_zero*/ );
1121 /* Now check there are no more guards. */
1122 p += (UWord)nbytes;
1123 vg_assert(*p == 1); /*isEnd*/
1124 return res;
1125 } else {
1126 if (aMin <= regs->ip && regs->ip <= aMax) {
1127 /* found a matching range. Evaluate the expression. */
1128 return ML_(evaluate_Dwarf3_Expr)(
1129 p, (UWord)nbytes, fbGX, regs, di,
1130 False/*push_initial_zero*/ );
1133 /* else keep searching */
1134 p += (UWord)nbytes;
1139 /* Evaluate a very simple Guarded (DWARF3) expression. The expression
1140 is expected to denote a constant, with no reference to any
1141 registers nor to any frame base expression. The expression is
1142 expected to have at least one guard. If there is more than one
1143 guard, all the sub-expressions are evaluated and compared. The
1144 address ranges on the guards are ignored. GXR_Failure is returned
1145 in the following circumstances:
1146 * no guards
1147 * any of the subexpressions require a frame base expression
1148 * any of the subexpressions denote a register location
1149 * any of the subexpressions do not produce a manifest constant
1150 * there's more than one subexpression, all of which successfully
1151 evaluate to a constant, but they don't all produce the same constant.
1152 JRS 23Jan09: the special-casing in this function is a nasty kludge.
1153 Really it ought to be pulled out and turned into a general
1154 constant- expression evaluator.
1156 GXResult ML_(evaluate_trivial_GX)( const GExpr* gx, const DebugInfo* di )
1158 GXResult res;
1159 Addr aMin, aMax;
1160 UChar uc;
1161 UShort nbytes;
1162 Word i, nGuards;
1163 MaybeULong *mul, *mul2;
1165 const HChar* badness = NULL;
1166 const UChar* p = &gx->payload[0]; /* must remain unsigned */
1167 XArray* results = VG_(newXA)( ML_(dinfo_zalloc), "di.d3basics.etG.1",
1168 ML_(dinfo_free),
1169 sizeof(MaybeULong) );
1171 uc = *p++; /*biasMe*/
1172 vg_assert(uc == 0 || uc == 1);
1173 /* in fact it's senseless to evaluate if the guards need biasing.
1174 So don't. */
1175 vg_assert(uc == 0);
1177 nGuards = 0;
1178 while (True) {
1179 MaybeULong thisResult;
1180 uc = *p++;
1181 if (uc == 1) /*isEnd*/
1182 break;
1183 vg_assert(uc == 0);
1184 aMin = ML_(read_Addr)(p); p += sizeof(Addr);
1185 aMax = ML_(read_Addr)(p); p += sizeof(Addr);
1186 nbytes = ML_(read_UShort)(p); p += sizeof(UShort);
1187 nGuards++;
1188 if (0) VG_(printf)(" guard %ld: %#lx %#lx\n",
1189 nGuards, aMin,aMax);
1191 thisResult.b = False;
1192 thisResult.ul = 0;
1194 /* Peer at this particular subexpression, to see if it's
1195 obviously a constant. */
1196 if (nbytes == 1 + sizeof(Addr) && *p == DW_OP_addr) {
1197 /* DW_OP_addr a */
1198 Addr a = ML_(read_Addr)((p+1));
1199 if (bias_address(&a, di)) {
1200 thisResult.b = True;
1201 thisResult.ul = (ULong)a;
1202 } else {
1203 if (!badness)
1204 badness = "trivial GExpr denotes constant address "
1205 "in unknown section (1)";
1208 else
1209 if (nbytes == 1 + sizeof(Addr) + 1 + 1
1210 /* 11 byte block: 3 c0 b6 2b 0 0 0 0 0 23 4
1211 (DW_OP_addr: 2bb6c0; DW_OP_plus_uconst: 4)
1212 This is really a nasty kludge - only matches if the
1213 trailing ULEB denotes a number in the range 0 .. 127
1214 inclusive. */
1215 && p[0] == DW_OP_addr
1216 && p[1 + sizeof(Addr)] == DW_OP_plus_uconst
1217 && p[1 + sizeof(Addr) + 1] < 0x80 /*1-byte ULEB*/) {
1218 Addr a = ML_(read_Addr)(&p[1]);
1219 if (bias_address(&a, di)) {
1220 thisResult.b = True;
1221 thisResult.ul = (ULong)a + (ULong)p[1 + sizeof(Addr) + 1];
1222 } else {
1223 if (!badness)
1224 badness = "trivial GExpr denotes constant address "
1225 "in unknown section (2)";
1228 else
1229 if (nbytes == 2 + sizeof(Addr)
1230 && *p == DW_OP_addr
1231 && *(p + 1 + sizeof(Addr)) == DW_OP_GNU_push_tls_address) {
1232 if (!badness)
1233 badness = "trivial GExpr is DW_OP_addr plus trailing junk";
1235 else if (nbytes >= 1 && *p >= DW_OP_reg0 && *p <= DW_OP_reg31) {
1236 if (!badness)
1237 badness = "trivial GExpr denotes register (1)";
1239 else if (nbytes >= 1 && *p == DW_OP_fbreg) {
1240 if (!badness)
1241 badness = "trivial GExpr requires fbGX";
1243 else if (nbytes >= 1 && *p >= DW_OP_breg0 && *p <= DW_OP_breg31) {
1244 if (!badness)
1245 badness = "trivial GExpr requires register value";
1247 else if (nbytes >= 1 && *p == DW_OP_regx) {
1248 if (!badness)
1249 badness = "trivial GExpr denotes register (2)";
1251 else if (0) {
1252 VG_(printf)(" ML_(evaluate_trivial_GX): unhandled:\n ");
1253 ML_(pp_GX)( gx );
1254 VG_(printf)("\n");
1255 vg_assert(0);
1257 else
1258 if (!badness)
1259 badness = "non-trivial GExpr";
1261 VG_(addToXA)( results, &thisResult );
1263 p += (UWord)nbytes;
1266 res.kind = GXR_Failure;
1268 vg_assert(nGuards == VG_(sizeXA)( results ));
1269 vg_assert(nGuards >= 0);
1270 if (nGuards == 0) {
1271 vg_assert(!badness);
1272 res.word = (UWord)"trivial GExpr has no guards (!)";
1273 VG_(deleteXA)( results );
1274 return res;
1277 for (i = 0; i < nGuards; i++) {
1278 mul = VG_(indexXA)( results, i );
1279 if (mul->b == False)
1280 break;
1283 vg_assert(i >= 0 && i <= nGuards);
1284 if (i < nGuards) {
1285 /* at least one subexpression failed to produce a manifest constant. */
1286 vg_assert(badness);
1287 res.word = (UWord)badness;
1288 VG_(deleteXA)( results );
1289 return res;
1292 /* All the subexpressions produced a constant, but did they all produce
1293 the same one? */
1294 mul = VG_(indexXA)( results, 0 );
1295 vg_assert(mul->b == True); /* we just established that all exprs are ok */
1297 for (i = 1; i < nGuards; i++) {
1298 mul2 = VG_(indexXA)( results, i );
1299 vg_assert(mul2->b == True);
1300 if (mul2->ul != mul->ul) {
1301 res.word = (UWord)"trivial GExpr: subexpressions disagree";
1302 VG_(deleteXA)( results );
1303 return res;
1307 /* Well, we have success. All subexpressions evaluated, and
1308 they all agree. Hurrah. */
1309 res.kind = GXR_Addr;
1310 res.word = (UWord)mul->ul; /* NB: narrowing from ULong */
1311 VG_(deleteXA)( results );
1312 return res;
1316 void ML_(pp_GXResult) ( GXResult res )
1318 switch (res.kind) {
1319 case GXR_Failure:
1320 VG_(printf)("GXR_Failure(%s)", (HChar*)res.word); break;
1321 case GXR_Addr:
1322 VG_(printf)("GXR_Addr(0x%lx)", res.word); break;
1323 case GXR_Value:
1324 VG_(printf)("GXR_Value(0x%lx)", res.word); break;
1325 case GXR_RegNo:
1326 VG_(printf)("GXR_RegNo(%lu)", res.word); break;
1327 default:
1328 VG_(printf)("GXR_???"); break;
1333 void ML_(pp_GX) ( const GExpr* gx )
1335 Addr aMin, aMax;
1336 UChar uc;
1337 UShort nbytes;
1338 const UChar* p = &gx->payload[0];
1339 uc = *p++;
1340 VG_(printf)("GX(%s){", uc == 0 ? "final" : "Breqd" );
1341 vg_assert(uc == 0 || uc == 1);
1342 while (True) {
1343 uc = *p++;
1344 if (uc == 1)
1345 break; /*isEnd*/
1346 vg_assert(uc == 0);
1347 aMin = ML_(read_Addr)(p); p += sizeof(Addr);
1348 aMax = ML_(read_Addr)(p); p += sizeof(Addr);
1349 nbytes = ML_(read_UShort)(p); p += sizeof(UShort);
1350 VG_(printf)("[%#lx,%#lx]=", aMin, aMax);
1351 while (nbytes > 0) {
1352 VG_(printf)("%02x", (UInt)*p++);
1353 nbytes--;
1355 if (*p == 0)
1356 VG_(printf)(",");
1358 VG_(printf)("}");
1362 /*--------------------------------------------------------------------*/
1363 /*--- end d3basics.c ---*/
1364 /*--------------------------------------------------------------------*/