OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 Google Inc. All Rights Reserved. | |
2 // | |
3 // Redistribution and use in source and binary forms, with or without | |
4 // modification, are permitted provided that the following conditions are | |
5 // met: | |
6 // | |
7 // * Redistributions of source code must retain the above copyright | |
8 // notice, this list of conditions and the following disclaimer. | |
9 // * Redistributions in binary form must reproduce the above | |
10 // copyright notice, this list of conditions and the following disclaimer | |
11 // in the documentation and/or other materials provided with the | |
12 // distribution. | |
13 // * Neither the name of Google Inc. nor the names of its | |
14 // contributors may be used to endorse or promote products derived from | |
15 // this software without specific prior written permission. | |
16 // | |
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | |
29 #include <assert.h> | |
30 | |
31 #include <map> | |
32 | |
33 #include "common/dwarf/dwarf2enums.h" | |
34 #include "common/dwarf/types.h" | |
35 | |
36 #include "dwarf_reader/dwarf_strings.h" | |
37 | |
38 | |
39 static int32 s_DwarfStringsInit = 0; | |
40 | |
41 static std::map<uint32,const char *> s_FormMap; | |
42 static std::map<uint32,const char *> s_TagMap; | |
43 static std::map<uint32,const char *> s_AttributeMap; | |
44 | |
45 #define SET_TAG(x) s_TagMap[DW_TAG_##x] = #x; | |
46 #define SET_ATTR(x) s_AttributeMap[DW_AT_##x] = #x; | |
47 #define SET_FORM(x) s_FormMap[DW_FORM_##x] = #x; | |
48 | |
49 | |
50 using namespace dwarf2reader; | |
51 | |
52 namespace dwarf_reader { | |
53 | |
54 static void BuildTagLookup() { | |
55 SET_TAG(padding) | |
56 SET_TAG(array_type) | |
57 SET_TAG(class_type) | |
58 SET_TAG(entry_point) | |
59 SET_TAG(enumeration_type) | |
60 SET_TAG(formal_parameter) | |
61 SET_TAG(imported_declaration) | |
62 SET_TAG(label) | |
63 SET_TAG(lexical_block) | |
64 SET_TAG(member) | |
65 SET_TAG(pointer_type) | |
66 SET_TAG(reference_type) | |
67 SET_TAG(compile_unit) | |
68 SET_TAG(string_type) | |
69 SET_TAG(structure_type) | |
70 SET_TAG(subroutine_type) | |
71 SET_TAG(typedef) | |
72 SET_TAG(union_type) | |
73 SET_TAG(unspecified_parameters) | |
74 SET_TAG(variant) | |
75 SET_TAG(common_block) | |
76 SET_TAG(common_inclusion) | |
77 SET_TAG(inheritance) | |
78 SET_TAG(inlined_subroutine) | |
79 SET_TAG(module) | |
80 SET_TAG(ptr_to_member_type) | |
81 SET_TAG(set_type) | |
82 SET_TAG(subrange_type) | |
83 SET_TAG(with_stmt) | |
84 SET_TAG(access_declaration) | |
85 SET_TAG(base_type) | |
86 SET_TAG(catch_block) | |
87 SET_TAG(const_type) | |
88 SET_TAG(constant) | |
89 SET_TAG(enumerator) | |
90 SET_TAG(file_type) | |
91 SET_TAG(friend) | |
92 SET_TAG(namelist) | |
93 SET_TAG(namelist_item) | |
94 SET_TAG(packed_type) | |
95 SET_TAG(subprogram) | |
96 SET_TAG(template_type_param) | |
97 SET_TAG(template_value_param) | |
98 SET_TAG(thrown_type) | |
99 SET_TAG(try_block) | |
100 SET_TAG(variant_part) | |
101 SET_TAG(variable) | |
102 SET_TAG(volatile_type) | |
103 // DWARF 3. | |
104 SET_TAG(dwarf_procedure) | |
105 SET_TAG(restrict_type) | |
106 SET_TAG(interface_type) | |
107 SET_TAG(namespace) | |
108 SET_TAG(imported_module) | |
109 SET_TAG(unspecified_type) | |
110 SET_TAG(partial_unit) | |
111 SET_TAG(imported_unit) | |
112 // SGI/MIPS Extensions. | |
113 SET_TAG(MIPS_loop) | |
114 // HP extensions. See: | |
115 // ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz | |
116 SET_TAG(HP_array_descriptor) | |
117 // GNU extensions. | |
118 SET_TAG(format_label) | |
119 SET_TAG(function_template) | |
120 SET_TAG(class_template) | |
121 SET_TAG(GNU_BINCL) | |
122 SET_TAG(GNU_EINCL) | |
123 // Extensions for UPC. See: http://upc.gwu.edu/~upc. | |
124 SET_TAG(upc_shared_type) | |
125 SET_TAG(upc_strict_type) | |
126 SET_TAG(upc_relaxed_type) | |
127 // PGI (STMicroelectronics) extensions. No documentation available. | |
128 SET_TAG(PGI_kanji_type) | |
129 SET_TAG(PGI_interface_block) | |
130 } | |
131 | |
132 static void BuildAttributeLookup() { | |
133 SET_ATTR(sibling) | |
134 SET_ATTR(location) | |
135 SET_ATTR(name) | |
136 SET_ATTR(ordering) | |
137 SET_ATTR(subscr_data) | |
138 SET_ATTR(byte_size) | |
139 SET_ATTR(bit_offset) | |
140 SET_ATTR(bit_size) | |
141 SET_ATTR(element_list) | |
142 SET_ATTR(stmt_list) | |
143 SET_ATTR(low_pc) | |
144 SET_ATTR(high_pc) | |
145 SET_ATTR(language) | |
146 SET_ATTR(member) | |
147 SET_ATTR(discr) | |
148 SET_ATTR(discr_value) | |
149 SET_ATTR(visibility) | |
150 SET_ATTR(import) | |
151 SET_ATTR(string_length) | |
152 SET_ATTR(common_reference) | |
153 SET_ATTR(comp_dir) | |
154 SET_ATTR(const_value) | |
155 SET_ATTR(containing_type) | |
156 SET_ATTR(default_value) | |
157 SET_ATTR(inline) | |
158 SET_ATTR(is_optional) | |
159 SET_ATTR(lower_bound) | |
160 SET_ATTR(producer) | |
161 SET_ATTR(prototyped) | |
162 SET_ATTR(return_addr) | |
163 SET_ATTR(start_scope) | |
164 SET_ATTR(stride_size) | |
165 SET_ATTR(upper_bound) | |
166 SET_ATTR(abstract_origin) | |
167 SET_ATTR(accessibility) | |
168 SET_ATTR(address_class) | |
169 SET_ATTR(artificial) | |
170 SET_ATTR(base_types) | |
171 SET_ATTR(calling_convention) | |
172 SET_ATTR(count) | |
173 SET_ATTR(data_member_location) | |
174 SET_ATTR(decl_column) | |
175 SET_ATTR(decl_file) | |
176 SET_ATTR(decl_line) | |
177 SET_ATTR(declaration) | |
178 SET_ATTR(discr_list) | |
179 SET_ATTR(encoding) | |
180 SET_ATTR(external) | |
181 SET_ATTR(frame_base) | |
182 SET_ATTR(friend) | |
183 SET_ATTR(identifier_case) | |
184 SET_ATTR(macro_info) | |
185 SET_ATTR(namelist_items) | |
186 SET_ATTR(priority) | |
187 SET_ATTR(segment) | |
188 SET_ATTR(specification) | |
189 SET_ATTR(static_link) | |
190 SET_ATTR(type) | |
191 SET_ATTR(use_location) | |
192 SET_ATTR(variable_parameter) | |
193 SET_ATTR(virtuality) | |
194 SET_ATTR(vtable_elem_location) | |
195 // DWARF 3 values. | |
196 SET_ATTR(allocated) | |
197 SET_ATTR(associated) | |
198 SET_ATTR(data_location) | |
199 SET_ATTR(stride) | |
200 SET_ATTR(entry_pc) | |
201 SET_ATTR(use_UTF8) | |
202 SET_ATTR(extension) | |
203 SET_ATTR(ranges) | |
204 SET_ATTR(trampoline) | |
205 SET_ATTR(call_column) | |
206 SET_ATTR(call_file) | |
207 SET_ATTR(call_line) | |
208 // SGI/MIPS extensions. | |
209 SET_ATTR(MIPS_fde) | |
210 SET_ATTR(MIPS_loop_begin) | |
211 SET_ATTR(MIPS_tail_loop_begin) | |
212 SET_ATTR(MIPS_epilog_begin) | |
213 SET_ATTR(MIPS_loop_unroll_factor) | |
214 SET_ATTR(MIPS_software_pipeline_depth) | |
215 SET_ATTR(MIPS_linkage_name) | |
216 SET_ATTR(MIPS_stride) | |
217 SET_ATTR(MIPS_abstract_name) | |
218 SET_ATTR(MIPS_clone_origin) | |
219 SET_ATTR(MIPS_has_inlines) | |
220 // HP extensions. | |
221 SET_ATTR(HP_block_index) | |
222 SET_ATTR(HP_unmodifiable) | |
223 SET_ATTR(HP_actuals_stmt_list) | |
224 SET_ATTR(HP_proc_per_section) | |
225 SET_ATTR(HP_raw_data_ptr) | |
226 SET_ATTR(HP_pass_by_reference) | |
227 SET_ATTR(HP_opt_level) | |
228 SET_ATTR(HP_prof_version_id) | |
229 SET_ATTR(HP_opt_flags) | |
230 SET_ATTR(HP_cold_region_low_pc ) | |
231 SET_ATTR(HP_cold_region_high_pc) | |
232 SET_ATTR(HP_all_variables_modifiable) | |
233 SET_ATTR(HP_linkage_name) | |
234 SET_ATTR(HP_prof_flags) | |
235 // GNU extensions. | |
236 SET_ATTR(sf_names) | |
237 SET_ATTR(src_info) | |
238 SET_ATTR(mac_info) | |
239 SET_ATTR(src_coords) | |
240 SET_ATTR(body_begin) | |
241 SET_ATTR(body_end) | |
242 SET_ATTR(GNU_vector) | |
243 // VMS extensions. | |
244 SET_ATTR(VMS_rtnbeg_pd_address) | |
245 // UPC extension. | |
246 SET_ATTR(upc_threads_scaled) | |
247 // PGI (STMicroelectronics) extensions. | |
248 SET_ATTR(PGI_lbase) | |
249 SET_ATTR(PGI_soffset) | |
250 SET_ATTR(PGI_lstride) | |
251 } | |
252 | |
253 static void BuildFormLookup() { | |
254 // Form names and codes. | |
255 SET_FORM(addr) | |
256 SET_FORM(block2) | |
257 SET_FORM(block4) | |
258 SET_FORM(data2) | |
259 SET_FORM(data4) | |
260 SET_FORM(data8) | |
261 SET_FORM(string) | |
262 SET_FORM(block) | |
263 SET_FORM(block1) | |
264 SET_FORM(data1) | |
265 SET_FORM(flag) | |
266 SET_FORM(sdata) | |
267 SET_FORM(strp) | |
268 SET_FORM(udata) | |
269 SET_FORM(ref_addr) | |
270 SET_FORM(ref1) | |
271 SET_FORM(ref2) | |
272 SET_FORM(ref4) | |
273 SET_FORM(ref8) | |
274 SET_FORM(ref_udata) | |
275 SET_FORM(indirect) | |
276 } | |
277 | |
278 | |
279 static inline void BuildLookups() { | |
280 if (!s_DwarfStringsInit) { | |
281 s_DwarfStringsInit = 1; | |
282 BuildTagLookup(); | |
283 BuildFormLookup(); | |
284 BuildAttributeLookup(); | |
285 } | |
286 } | |
287 | |
288 | |
289 const char *DwarfAttributeName(enum DwarfAttribute attr) { | |
290 const char *out; | |
291 | |
292 BuildLookups(); | |
293 | |
294 if (attr == DW_AT_data_member_location) | |
295 out = 0; | |
296 | |
297 out = s_AttributeMap[attr]; | |
298 assert(NULL != out); | |
299 return out; | |
300 } | |
301 | |
302 const char *DwarfTagName(enum DwarfTag tag) { | |
303 const char *out; | |
304 | |
305 BuildLookups(); | |
306 | |
307 out = s_TagMap[tag]; | |
308 assert(NULL != out); | |
309 return out; | |
310 } | |
311 | |
312 | |
313 const char *DwarfFormName(enum DwarfForm form) { | |
314 const char *out; | |
315 | |
316 BuildLookups(); | |
317 | |
318 out = s_FormMap[form]; | |
319 assert(NULL != out); | |
320 return out; | |
321 } | |
322 | |
323 | |
324 } // namespace dwarf2reader | |
325 | |
OLD | NEW |