PR23652, Use symbols from debug bfd for _bfd_elf_find_function
[deliverable/binutils-gdb.git] / bfd / xsym.c
1 /* xSYM symbol-file support for BFD.
2 Copyright (C) 1999-2019 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21 /* xSYM is the debugging format used by CodeWarrior on Mac OS classic. */
22
23 #include "sysdep.h"
24 #include "alloca-conf.h"
25 #include "xsym.h"
26 #include "bfd.h"
27 #include "libbfd.h"
28
29 #define bfd_sym_close_and_cleanup _bfd_generic_close_and_cleanup
30 #define bfd_sym_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
31 #define bfd_sym_new_section_hook _bfd_generic_new_section_hook
32 #define bfd_sym_bfd_is_local_label_name bfd_generic_is_local_label_name
33 #define bfd_sym_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
34 #define bfd_sym_get_lineno _bfd_nosymbols_get_lineno
35 #define bfd_sym_find_nearest_line _bfd_nosymbols_find_nearest_line
36 #define bfd_sym_find_line _bfd_nosymbols_find_line
37 #define bfd_sym_find_inliner_info _bfd_nosymbols_find_inliner_info
38 #define bfd_sym_get_symbol_version_string _bfd_nosymbols_get_symbol_version_string
39 #define bfd_sym_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
40 #define bfd_sym_read_minisymbols _bfd_generic_read_minisymbols
41 #define bfd_sym_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
42 #define bfd_sym_set_arch_mach _bfd_generic_set_arch_mach
43 #define bfd_sym_get_section_contents _bfd_generic_get_section_contents
44 #define bfd_sym_set_section_contents _bfd_generic_set_section_contents
45 #define bfd_sym_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
46 #define bfd_sym_bfd_relax_section bfd_generic_relax_section
47 #define bfd_sym_bfd_gc_sections bfd_generic_gc_sections
48 #define bfd_sym_bfd_lookup_section_flags bfd_generic_lookup_section_flags
49 #define bfd_sym_bfd_merge_sections bfd_generic_merge_sections
50 #define bfd_sym_bfd_is_group_section bfd_generic_is_group_section
51 #define bfd_sym_bfd_group_name bfd_generic_group_name
52 #define bfd_sym_bfd_discard_group bfd_generic_discard_group
53 #define bfd_sym_section_already_linked _bfd_generic_section_already_linked
54 #define bfd_sym_bfd_define_common_symbol bfd_generic_define_common_symbol
55 #define bfd_sym_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
56 #define bfd_sym_bfd_define_start_stop bfd_generic_define_start_stop
57 #define bfd_sym_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
58 #define bfd_sym_bfd_link_add_symbols _bfd_generic_link_add_symbols
59 #define bfd_sym_bfd_link_just_syms _bfd_generic_link_just_syms
60 #define bfd_sym_bfd_copy_link_hash_symbol_type \
61 _bfd_generic_copy_link_hash_symbol_type
62 #define bfd_sym_bfd_final_link _bfd_generic_final_link
63 #define bfd_sym_bfd_link_split_section _bfd_generic_link_split_section
64 #define bfd_sym_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
65 #define bfd_sym_bfd_link_check_relocs _bfd_generic_link_check_relocs
66
67 extern const bfd_target sym_vec;
68
69 static int
70 pstrcmp (const char *as, const char *bs)
71 {
72 const unsigned char *a = (const unsigned char *) as;
73 const unsigned char *b = (const unsigned char *) bs;
74 unsigned char clen;
75 int ret;
76
77 clen = (a[0] > b[0]) ? b[0] : a[0];
78 ret = memcmp (a + 1, b + 1, clen);
79 if (ret != 0)
80 return ret;
81
82 if (a[0] == b[0])
83 return 0;
84 else if (a[0] < b[0])
85 return -1;
86 else
87 return 1;
88 }
89
90 static unsigned long
91 compute_offset (unsigned long first_page,
92 unsigned long page_size,
93 unsigned long entry_size,
94 unsigned long sym_index)
95 {
96 unsigned long entries_per_page = page_size / entry_size;
97 unsigned long page_number = first_page + (sym_index / entries_per_page);
98 unsigned long page_offset = (sym_index % entries_per_page) * entry_size;
99
100 return (page_number * page_size) + page_offset;
101 }
102
103 bfd_boolean
104 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
105 {
106 return 1;
107 }
108
109 void
110 bfd_sym_print_symbol (bfd *abfd ATTRIBUTE_UNUSED,
111 void * afile ATTRIBUTE_UNUSED,
112 asymbol *symbol ATTRIBUTE_UNUSED,
113 bfd_print_symbol_type how ATTRIBUTE_UNUSED)
114 {
115 return;
116 }
117
118 bfd_boolean
119 bfd_sym_valid (bfd *abfd)
120 {
121 if (abfd == NULL || abfd->xvec == NULL)
122 return 0;
123
124 return abfd->xvec == &sym_vec;
125 }
126
127 unsigned char *
128 bfd_sym_read_name_table (bfd *abfd, bfd_sym_header_block *dshb)
129 {
130 unsigned char *rstr;
131 long ret;
132 size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size;
133 size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size;
134
135 rstr = bfd_alloc (abfd, table_size);
136 if (rstr == NULL)
137 return rstr;
138
139 bfd_seek (abfd, table_offset, SEEK_SET);
140 ret = bfd_bread (rstr, table_size, abfd);
141 if (ret < 0 || (unsigned long) ret != table_size)
142 {
143 bfd_release (abfd, rstr);
144 return NULL;
145 }
146
147 return rstr;
148 }
149
150 void
151 bfd_sym_parse_file_reference_v32 (unsigned char *buf,
152 size_t len,
153 bfd_sym_file_reference *entry)
154 {
155 BFD_ASSERT (len == 6);
156
157 entry->fref_frte_index = bfd_getb16 (buf);
158 entry->fref_offset = bfd_getb32 (buf + 2);
159 }
160
161 void
162 bfd_sym_parse_disk_table_v32 (unsigned char *buf,
163 size_t len,
164 bfd_sym_table_info *table)
165 {
166 BFD_ASSERT (len == 8);
167
168 table->dti_first_page = bfd_getb16 (buf);
169 table->dti_page_count = bfd_getb16 (buf + 2);
170 table->dti_object_count = bfd_getb32 (buf + 4);
171 }
172
173 void
174 bfd_sym_parse_header_v32 (unsigned char *buf,
175 size_t len,
176 bfd_sym_header_block *header)
177 {
178 BFD_ASSERT (len == 154);
179
180 memcpy (header->dshb_id, buf, 32);
181 header->dshb_page_size = bfd_getb16 (buf + 32);
182 header->dshb_hash_page = bfd_getb16 (buf + 34);
183 header->dshb_root_mte = bfd_getb16 (buf + 36);
184 header->dshb_mod_date = bfd_getb32 (buf + 38);
185
186 bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte);
187 bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte);
188 bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte);
189 bfd_sym_parse_disk_table_v32 (buf + 66, 8, &header->dshb_cmte);
190 bfd_sym_parse_disk_table_v32 (buf + 74, 8, &header->dshb_cvte);
191 bfd_sym_parse_disk_table_v32 (buf + 82, 8, &header->dshb_csnte);
192 bfd_sym_parse_disk_table_v32 (buf + 90, 8, &header->dshb_clte);
193 bfd_sym_parse_disk_table_v32 (buf + 98, 8, &header->dshb_ctte);
194 bfd_sym_parse_disk_table_v32 (buf + 106, 8, &header->dshb_tte);
195 bfd_sym_parse_disk_table_v32 (buf + 114, 8, &header->dshb_nte);
196 bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo);
197 bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite);
198 bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const);
199
200 memcpy (&header->dshb_file_creator, buf + 146, 4);
201 memcpy (&header->dshb_file_type, buf + 150, 4);
202 }
203
204 int
205 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header)
206 {
207 unsigned char buf[154];
208 long ret;
209
210 ret = bfd_bread (buf, 154, abfd);
211 if (ret != 154)
212 return -1;
213
214 bfd_sym_parse_header_v32 (buf, 154, header);
215
216 return 0;
217 }
218
219 int
220 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED,
221 bfd_sym_header_block *header ATTRIBUTE_UNUSED)
222 {
223 abort ();
224 }
225
226 int
227 bfd_sym_read_header (bfd *abfd,
228 bfd_sym_header_block *header,
229 bfd_sym_version version)
230 {
231 switch (version)
232 {
233 case BFD_SYM_VERSION_3_5:
234 case BFD_SYM_VERSION_3_4:
235 return bfd_sym_read_header_v34 (abfd, header);
236 case BFD_SYM_VERSION_3_3:
237 case BFD_SYM_VERSION_3_2:
238 return bfd_sym_read_header_v32 (abfd, header);
239 case BFD_SYM_VERSION_3_1:
240 default:
241 return 0;
242 }
243 }
244
245 int
246 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version)
247 {
248 char version_string[32];
249 long ret;
250
251 ret = bfd_bread (version_string, sizeof (version_string), abfd);
252 if (ret != sizeof (version_string))
253 return -1;
254
255 if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0)
256 *version = BFD_SYM_VERSION_3_1;
257 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0)
258 *version = BFD_SYM_VERSION_3_2;
259 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0)
260 *version = BFD_SYM_VERSION_3_3;
261 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0)
262 *version = BFD_SYM_VERSION_3_4;
263 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0)
264 *version = BFD_SYM_VERSION_3_5;
265 else
266 return -1;
267
268 return 0;
269 }
270
271 void
272 bfd_sym_display_table_summary (FILE *f,
273 bfd_sym_table_info *dti,
274 const char *name)
275 {
276 fprintf (f, "%-6s %13ld %13ld %13ld\n",
277 name,
278 dti->dti_first_page,
279 dti->dti_page_count,
280 dti->dti_object_count);
281 }
282
283 void
284 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb)
285 {
286 fprintf (f, " Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1);
287 fprintf (f, " Page Size: 0x%x\n", dshb->dshb_page_size);
288 fprintf (f, " Hash Page: %lu\n", dshb->dshb_hash_page);
289 fprintf (f, " Root MTE: %lu\n", dshb->dshb_root_mte);
290 fprintf (f, " Modification Date: ");
291 fprintf (f, "[unimplemented]");
292 fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date);
293
294 fprintf (f, " File Creator: %.4s Type: %.4s\n\n",
295 dshb->dshb_file_creator, dshb->dshb_file_type);
296
297 fprintf (f, "Table Name First Page Page Count Object Count\n");
298 fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
299
300 bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE");
301 bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE");
302 bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE");
303 bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE");
304 bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE");
305 bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE");
306 bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE");
307 bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE");
308 bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE");
309 bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE");
310 bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO");
311 bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE");
312 bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST");
313
314 fprintf (f, "\n");
315 }
316
317 void
318 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf,
319 size_t len,
320 bfd_sym_resources_table_entry *entry)
321 {
322 BFD_ASSERT (len == 18);
323
324 memcpy (&entry->rte_res_type, buf, 4);
325 entry->rte_res_number = bfd_getb16 (buf + 4);
326 entry->rte_nte_index = bfd_getb32 (buf + 6);
327 entry->rte_mte_first = bfd_getb16 (buf + 10);
328 entry->rte_mte_last = bfd_getb16 (buf + 12);
329 entry->rte_res_size = bfd_getb32 (buf + 14);
330 }
331
332 void
333 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf,
334 size_t len,
335 bfd_sym_modules_table_entry *entry)
336 {
337 BFD_ASSERT (len == 46);
338
339 entry->mte_rte_index = bfd_getb16 (buf);
340 entry->mte_res_offset = bfd_getb32 (buf + 2);
341 entry->mte_size = bfd_getb32 (buf + 6);
342 entry->mte_kind = buf[10];
343 entry->mte_scope = buf[11];
344 entry->mte_parent = bfd_getb16 (buf + 12);
345 bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref);
346 entry->mte_imp_end = bfd_getb32 (buf + 20);
347 entry->mte_nte_index = bfd_getb32 (buf + 24);
348 entry->mte_cmte_index = bfd_getb16 (buf + 28);
349 entry->mte_cvte_index = bfd_getb32 (buf + 30);
350 entry->mte_clte_index = bfd_getb16 (buf + 34);
351 entry->mte_ctte_index = bfd_getb16 (buf + 36);
352 entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38);
353 entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42);
354 }
355
356 void
357 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf,
358 size_t len,
359 bfd_sym_file_references_table_entry *entry)
360 {
361 unsigned int type;
362
363 BFD_ASSERT (len == 10);
364
365 memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
366 type = bfd_getb16 (buf);
367
368 switch (type)
369 {
370 case BFD_SYM_END_OF_LIST_3_2:
371 entry->generic.type = BFD_SYM_END_OF_LIST;
372 break;
373
374 case BFD_SYM_FILE_NAME_INDEX_3_2:
375 entry->filename.type = BFD_SYM_FILE_NAME_INDEX;
376 entry->filename.nte_index = bfd_getb32 (buf + 2);
377 entry->filename.mod_date = bfd_getb32 (buf + 6);
378 break;
379
380 default:
381 entry->entry.mte_index = type;
382 entry->entry.file_offset = bfd_getb32 (buf + 2);
383 }
384 }
385
386 void
387 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf,
388 size_t len,
389 bfd_sym_contained_modules_table_entry *entry)
390 {
391 unsigned int type;
392
393 BFD_ASSERT (len == 6);
394
395 memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
396 type = bfd_getb16 (buf);
397
398 switch (type)
399 {
400 case BFD_SYM_END_OF_LIST_3_2:
401 entry->generic.type = BFD_SYM_END_OF_LIST;
402 break;
403
404 default:
405 entry->entry.mte_index = type;
406 entry->entry.nte_index = bfd_getb32 (buf + 2);
407 break;
408 }
409 }
410
411 void
412 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf,
413 size_t len,
414 bfd_sym_contained_variables_table_entry *entry)
415 {
416 unsigned int type;
417
418 BFD_ASSERT (len == 26);
419
420 memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
421 type = bfd_getb16 (buf);
422
423 switch (type)
424 {
425 case BFD_SYM_END_OF_LIST_3_2:
426 entry->generic.type = BFD_SYM_END_OF_LIST;
427 break;
428
429 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
430 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
431 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
432 break;
433
434 default:
435 entry->entry.tte_index = type;
436 entry->entry.nte_index = bfd_getb32 (buf + 2);
437 entry->entry.file_delta = bfd_getb16 (buf + 6);
438 entry->entry.scope = buf[8];
439 entry->entry.la_size = buf[9];
440
441 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
442 {
443 entry->entry.address.scstruct.sca_kind = buf[10];
444 entry->entry.address.scstruct.sca_class = buf[11];
445 entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12);
446 }
447 else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
448 {
449 #if BFD_SYM_CVTE_SCA > 0
450 memcpy (&entry->entry.address.lastruct.la, buf + 10,
451 BFD_SYM_CVTE_SCA);
452 #endif
453 entry->entry.address.lastruct.la_kind = buf[23];
454 }
455 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
456 {
457 entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
458 entry->entry.address.biglastruct.big_la_kind = buf[12];
459 }
460 }
461 }
462
463 void
464 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf,
465 size_t len,
466 bfd_sym_contained_statements_table_entry *entry)
467 {
468 unsigned int type;
469
470 BFD_ASSERT (len == 8);
471
472 memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
473 type = bfd_getb16 (buf);
474
475 switch (type)
476 {
477 case BFD_SYM_END_OF_LIST_3_2:
478 entry->generic.type = BFD_SYM_END_OF_LIST;
479 break;
480
481 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
482 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
483 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
484 break;
485
486 default:
487 entry->entry.mte_index = type;
488 entry->entry.mte_offset = bfd_getb16 (buf + 2);
489 entry->entry.file_delta = bfd_getb32 (buf + 4);
490 break;
491 }
492 }
493
494 void
495 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf,
496 size_t len,
497 bfd_sym_contained_labels_table_entry *entry)
498 {
499 unsigned int type;
500
501 BFD_ASSERT (len == 12);
502
503 memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
504 type = bfd_getb16 (buf);
505
506 switch (type)
507 {
508 case BFD_SYM_END_OF_LIST_3_2:
509 entry->generic.type = BFD_SYM_END_OF_LIST;
510 break;
511
512 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
513 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
514 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
515 break;
516
517 default:
518 entry->entry.mte_index = type;
519 entry->entry.mte_offset = bfd_getb16 (buf + 2);
520 entry->entry.nte_index = bfd_getb32 (buf + 4);
521 entry->entry.file_delta = bfd_getb16 (buf + 8);
522 entry->entry.scope = bfd_getb16 (buf + 10);
523 break;
524 }
525 }
526
527 void
528 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
529 size_t len,
530 bfd_sym_type_table_entry *entry)
531 {
532 BFD_ASSERT (len == 4);
533
534 *entry = bfd_getb32 (buf);
535 }
536
537 int
538 bfd_sym_fetch_resources_table_entry (bfd *abfd,
539 bfd_sym_resources_table_entry *entry,
540 unsigned long sym_index)
541 {
542 void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *);
543 unsigned long offset;
544 unsigned long entry_size;
545 unsigned char buf[18];
546 bfd_sym_data_struct *sdata = NULL;
547
548 parser = NULL;
549 BFD_ASSERT (bfd_sym_valid (abfd));
550 sdata = abfd->tdata.sym_data;
551
552 if (sym_index == 0)
553 return -1;
554
555 switch (sdata->version)
556 {
557 case BFD_SYM_VERSION_3_5:
558 case BFD_SYM_VERSION_3_4:
559 return -1;
560
561 case BFD_SYM_VERSION_3_3:
562 case BFD_SYM_VERSION_3_2:
563 entry_size = 18;
564 parser = bfd_sym_parse_resources_table_entry_v32;
565 break;
566
567 case BFD_SYM_VERSION_3_1:
568 default:
569 return -1;
570 }
571 if (parser == NULL)
572 return -1;
573
574 offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
575 sdata->header.dshb_page_size,
576 entry_size, sym_index);
577
578 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
579 return -1;
580 if (bfd_bread (buf, entry_size, abfd) != entry_size)
581 return -1;
582
583 (*parser) (buf, entry_size, entry);
584
585 return 0;
586 }
587
588 int
589 bfd_sym_fetch_modules_table_entry (bfd *abfd,
590 bfd_sym_modules_table_entry *entry,
591 unsigned long sym_index)
592 {
593 void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *);
594 unsigned long offset;
595 unsigned long entry_size;
596 unsigned char buf[46];
597 bfd_sym_data_struct *sdata = NULL;
598
599 parser = NULL;
600 BFD_ASSERT (bfd_sym_valid (abfd));
601 sdata = abfd->tdata.sym_data;
602
603 if (sym_index == 0)
604 return -1;
605
606 switch (sdata->version)
607 {
608 case BFD_SYM_VERSION_3_5:
609 case BFD_SYM_VERSION_3_4:
610 return -1;
611
612 case BFD_SYM_VERSION_3_3:
613 entry_size = 46;
614 parser = bfd_sym_parse_modules_table_entry_v33;
615 break;
616
617 case BFD_SYM_VERSION_3_2:
618 case BFD_SYM_VERSION_3_1:
619 default:
620 return -1;
621 }
622 if (parser == NULL)
623 return -1;
624
625 offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
626 sdata->header.dshb_page_size,
627 entry_size, sym_index);
628
629 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
630 return -1;
631 if (bfd_bread (buf, entry_size, abfd) != entry_size)
632 return -1;
633
634 (*parser) (buf, entry_size, entry);
635
636 return 0;
637 }
638
639 int
640 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
641 bfd_sym_file_references_table_entry *entry,
642 unsigned long sym_index)
643 {
644 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *);
645 unsigned long offset;
646 unsigned long entry_size = 0;
647 unsigned char buf[8];
648 bfd_sym_data_struct *sdata = NULL;
649
650 parser = NULL;
651 BFD_ASSERT (bfd_sym_valid (abfd));
652 sdata = abfd->tdata.sym_data;
653
654 if (sym_index == 0)
655 return -1;
656
657 switch (sdata->version)
658 {
659 case BFD_SYM_VERSION_3_3:
660 case BFD_SYM_VERSION_3_2:
661 entry_size = 10;
662 parser = bfd_sym_parse_file_references_table_entry_v32;
663 break;
664
665 case BFD_SYM_VERSION_3_5:
666 case BFD_SYM_VERSION_3_4:
667 case BFD_SYM_VERSION_3_1:
668 default:
669 break;
670 }
671
672 if (parser == NULL)
673 return -1;
674
675 offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
676 sdata->header.dshb_page_size,
677 entry_size, sym_index);
678
679 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
680 return -1;
681 if (bfd_bread (buf, entry_size, abfd) != entry_size)
682 return -1;
683
684 (*parser) (buf, entry_size, entry);
685
686 return 0;
687 }
688
689 int
690 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
691 bfd_sym_contained_modules_table_entry *entry,
692 unsigned long sym_index)
693 {
694 void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *);
695 unsigned long offset;
696 unsigned long entry_size = 0;
697 unsigned char buf[6];
698 bfd_sym_data_struct *sdata = NULL;
699
700 parser = NULL;
701 BFD_ASSERT (bfd_sym_valid (abfd));
702 sdata = abfd->tdata.sym_data;
703
704 if (sym_index == 0)
705 return -1;
706
707 switch (sdata->version)
708 {
709 case BFD_SYM_VERSION_3_3:
710 case BFD_SYM_VERSION_3_2:
711 entry_size = 6;
712 parser = bfd_sym_parse_contained_modules_table_entry_v32;
713 break;
714
715 case BFD_SYM_VERSION_3_5:
716 case BFD_SYM_VERSION_3_4:
717 case BFD_SYM_VERSION_3_1:
718 default:
719 break;
720 }
721
722 if (parser == NULL)
723 return -1;
724
725 offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
726 sdata->header.dshb_page_size,
727 entry_size, sym_index);
728
729 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
730 return -1;
731 if (bfd_bread (buf, entry_size, abfd) != entry_size)
732 return -1;
733
734 (*parser) (buf, entry_size, entry);
735
736 return 0;
737 }
738
739 int
740 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
741 bfd_sym_contained_variables_table_entry *entry,
742 unsigned long sym_index)
743 {
744 void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *);
745 unsigned long offset;
746 unsigned long entry_size = 0;
747 unsigned char buf[26];
748 bfd_sym_data_struct *sdata = NULL;
749
750 parser = NULL;
751 BFD_ASSERT (bfd_sym_valid (abfd));
752 sdata = abfd->tdata.sym_data;
753
754 if (sym_index == 0)
755 return -1;
756
757 switch (sdata->version)
758 {
759 case BFD_SYM_VERSION_3_3:
760 case BFD_SYM_VERSION_3_2:
761 entry_size = 26;
762 parser = bfd_sym_parse_contained_variables_table_entry_v32;
763 break;
764
765 case BFD_SYM_VERSION_3_5:
766 case BFD_SYM_VERSION_3_4:
767 case BFD_SYM_VERSION_3_1:
768 default:
769 break;
770 }
771
772 if (parser == NULL)
773 return -1;
774
775 offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
776 sdata->header.dshb_page_size,
777 entry_size, sym_index);
778
779 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
780 return -1;
781 if (bfd_bread (buf, entry_size, abfd) != entry_size)
782 return -1;
783
784 (*parser) (buf, entry_size, entry);
785
786 return 0;
787 }
788
789 int
790 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
791 bfd_sym_contained_statements_table_entry *entry,
792 unsigned long sym_index)
793 {
794 void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *);
795 unsigned long offset;
796 unsigned long entry_size = 0;
797 unsigned char buf[8];
798 bfd_sym_data_struct *sdata = NULL;
799
800 parser = NULL;
801 BFD_ASSERT (bfd_sym_valid (abfd));
802 sdata = abfd->tdata.sym_data;
803
804 if (sym_index == 0)
805 return -1;
806
807 switch (sdata->version)
808 {
809 case BFD_SYM_VERSION_3_3:
810 case BFD_SYM_VERSION_3_2:
811 entry_size = 8;
812 parser = bfd_sym_parse_contained_statements_table_entry_v32;
813 break;
814
815 case BFD_SYM_VERSION_3_5:
816 case BFD_SYM_VERSION_3_4:
817 case BFD_SYM_VERSION_3_1:
818 default:
819 break;
820 }
821
822 if (parser == NULL)
823 return -1;
824
825 offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
826 sdata->header.dshb_page_size,
827 entry_size, sym_index);
828
829 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
830 return -1;
831 if (bfd_bread (buf, entry_size, abfd) != entry_size)
832 return -1;
833
834 (*parser) (buf, entry_size, entry);
835
836 return 0;
837 }
838
839 int
840 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
841 bfd_sym_contained_labels_table_entry *entry,
842 unsigned long sym_index)
843 {
844 void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *);
845 unsigned long offset;
846 unsigned long entry_size = 0;
847 unsigned char buf[12];
848 bfd_sym_data_struct *sdata = NULL;
849
850 parser = NULL;
851 BFD_ASSERT (bfd_sym_valid (abfd));
852 sdata = abfd->tdata.sym_data;
853
854 if (sym_index == 0)
855 return -1;
856
857 switch (sdata->version)
858 {
859 case BFD_SYM_VERSION_3_3:
860 case BFD_SYM_VERSION_3_2:
861 entry_size = 12;
862 parser = bfd_sym_parse_contained_labels_table_entry_v32;
863 break;
864
865 case BFD_SYM_VERSION_3_5:
866 case BFD_SYM_VERSION_3_4:
867 case BFD_SYM_VERSION_3_1:
868 default:
869 break;
870 }
871
872 if (parser == NULL)
873 return -1;
874
875 offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
876 sdata->header.dshb_page_size,
877 entry_size, sym_index);
878
879 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
880 return -1;
881 if (bfd_bread (buf, entry_size, abfd) != entry_size)
882 return -1;
883
884 (*parser) (buf, entry_size, entry);
885
886 return 0;
887 }
888
889 int
890 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
891 bfd_sym_contained_types_table_entry *entry,
892 unsigned long sym_index)
893 {
894 void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *);
895 unsigned long offset;
896 unsigned long entry_size = 0;
897 unsigned char buf[0];
898 bfd_sym_data_struct *sdata = NULL;
899
900 parser = NULL;
901 BFD_ASSERT (bfd_sym_valid (abfd));
902 sdata = abfd->tdata.sym_data;
903
904 if (sym_index == 0)
905 return -1;
906
907 switch (sdata->version)
908 {
909 case BFD_SYM_VERSION_3_3:
910 case BFD_SYM_VERSION_3_2:
911 entry_size = 0;
912 parser = NULL;
913 break;
914
915 case BFD_SYM_VERSION_3_5:
916 case BFD_SYM_VERSION_3_4:
917 case BFD_SYM_VERSION_3_1:
918 default:
919 break;
920 }
921
922 if (parser == NULL)
923 return -1;
924
925 offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
926 sdata->header.dshb_page_size,
927 entry_size, sym_index);
928
929 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
930 return -1;
931 if (bfd_bread (buf, entry_size, abfd) != entry_size)
932 return -1;
933
934 (*parser) (buf, entry_size, entry);
935
936 return 0;
937 }
938
939 int
940 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
941 bfd_sym_file_references_index_table_entry *entry,
942 unsigned long sym_index)
943 {
944 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *);
945 unsigned long offset;
946 unsigned long entry_size = 0;
947 unsigned char buf[0];
948 bfd_sym_data_struct *sdata = NULL;
949
950 parser = NULL;
951 BFD_ASSERT (bfd_sym_valid (abfd));
952 sdata = abfd->tdata.sym_data;
953
954 if (sym_index == 0)
955 return -1;
956
957 switch (sdata->version)
958 {
959 case BFD_SYM_VERSION_3_3:
960 case BFD_SYM_VERSION_3_2:
961 entry_size = 0;
962 parser = NULL;
963 break;
964
965 case BFD_SYM_VERSION_3_5:
966 case BFD_SYM_VERSION_3_4:
967 case BFD_SYM_VERSION_3_1:
968 default:
969 break;
970 }
971
972 if (parser == NULL)
973 return -1;
974
975 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
976 sdata->header.dshb_page_size,
977 entry_size, sym_index);
978
979 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
980 return -1;
981 if (bfd_bread (buf, entry_size, abfd) != entry_size)
982 return -1;
983
984 (*parser) (buf, entry_size, entry);
985
986 return 0;
987 }
988
989 int
990 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
991 bfd_sym_constant_pool_entry *entry,
992 unsigned long sym_index)
993 {
994 void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *);
995 unsigned long offset;
996 unsigned long entry_size = 0;
997 unsigned char buf[0];
998 bfd_sym_data_struct *sdata = NULL;
999
1000 parser = NULL;
1001 BFD_ASSERT (bfd_sym_valid (abfd));
1002 sdata = abfd->tdata.sym_data;
1003
1004 if (sym_index == 0)
1005 return -1;
1006
1007 switch (sdata->version)
1008 {
1009 case BFD_SYM_VERSION_3_3:
1010 case BFD_SYM_VERSION_3_2:
1011 entry_size = 0;
1012 parser = NULL;
1013 break;
1014
1015 case BFD_SYM_VERSION_3_5:
1016 case BFD_SYM_VERSION_3_4:
1017 case BFD_SYM_VERSION_3_1:
1018 default:
1019 break;
1020 }
1021
1022 if (parser == NULL)
1023 return -1;
1024
1025 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1026 sdata->header.dshb_page_size,
1027 entry_size, sym_index);
1028
1029 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1030 return -1;
1031 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1032 return -1;
1033
1034 (*parser) (buf, entry_size, entry);
1035
1036 return 0;
1037 }
1038
1039 int
1040 bfd_sym_fetch_type_table_entry (bfd *abfd,
1041 bfd_sym_type_table_entry *entry,
1042 unsigned long sym_index)
1043 {
1044 void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *);
1045 unsigned long offset;
1046 unsigned long entry_size = 0;
1047 unsigned char buf[4];
1048 bfd_sym_data_struct *sdata = NULL;
1049
1050 parser = NULL;
1051 BFD_ASSERT (bfd_sym_valid (abfd));
1052 sdata = abfd->tdata.sym_data;
1053
1054 switch (sdata->version)
1055 {
1056 case BFD_SYM_VERSION_3_3:
1057 case BFD_SYM_VERSION_3_2:
1058 entry_size = 4;
1059 parser = bfd_sym_parse_type_table_entry_v32;
1060 break;
1061
1062 case BFD_SYM_VERSION_3_5:
1063 case BFD_SYM_VERSION_3_4:
1064 case BFD_SYM_VERSION_3_1:
1065 default:
1066 break;
1067 }
1068
1069 if (parser == NULL)
1070 return -1;
1071
1072 offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
1073 sdata->header.dshb_page_size,
1074 entry_size, sym_index);
1075
1076 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1077 return -1;
1078 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1079 return -1;
1080
1081 (*parser) (buf, entry_size, entry);
1082
1083 return 0;
1084 }
1085
1086 int
1087 bfd_sym_fetch_type_information_table_entry (bfd *abfd,
1088 bfd_sym_type_information_table_entry *entry,
1089 unsigned long offset)
1090 {
1091 unsigned char buf[4];
1092
1093 BFD_ASSERT (bfd_sym_valid (abfd));
1094
1095 if (offset == 0)
1096 return -1;
1097
1098 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1099 return -1;
1100
1101 if (bfd_bread (buf, 4, abfd) != 4)
1102 return -1;
1103 entry->nte_index = bfd_getb32 (buf);
1104
1105 if (bfd_bread (buf, 2, abfd) != 2)
1106 return -1;
1107 entry->physical_size = bfd_getb16 (buf);
1108
1109 if (entry->physical_size & 0x8000)
1110 {
1111 if (bfd_bread (buf, 4, abfd) != 4)
1112 return -1;
1113 entry->physical_size &= 0x7fff;
1114 entry->logical_size = bfd_getb32 (buf);
1115 entry->offset = offset + 10;
1116 }
1117 else
1118 {
1119 if (bfd_bread (buf, 2, abfd) != 2)
1120 return -1;
1121 entry->physical_size &= 0x7fff;
1122 entry->logical_size = bfd_getb16 (buf);
1123 entry->offset = offset + 8;
1124 }
1125
1126 return 0;
1127 }
1128
1129 int
1130 bfd_sym_fetch_type_table_information (bfd *abfd,
1131 bfd_sym_type_information_table_entry *entry,
1132 unsigned long sym_index)
1133 {
1134 bfd_sym_type_table_entry tindex;
1135 bfd_sym_data_struct *sdata = NULL;
1136
1137 BFD_ASSERT (bfd_sym_valid (abfd));
1138 sdata = abfd->tdata.sym_data;
1139
1140 if (sdata->header.dshb_tte.dti_object_count <= 99)
1141 return -1;
1142 if (sym_index < 100)
1143 return -1;
1144
1145 if (bfd_sym_fetch_type_table_entry (abfd, &tindex, sym_index - 100) < 0)
1146 return -1;
1147 if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
1148 return -1;
1149
1150 return 0;
1151 }
1152
1153 const unsigned char *
1154 bfd_sym_symbol_name (bfd *abfd, unsigned long sym_index)
1155 {
1156 bfd_sym_data_struct *sdata = NULL;
1157
1158 BFD_ASSERT (bfd_sym_valid (abfd));
1159 sdata = abfd->tdata.sym_data;
1160
1161 if (sym_index == 0)
1162 return (const unsigned char *) "";
1163
1164 sym_index *= 2;
1165 if ((sym_index / sdata->header.dshb_page_size)
1166 > sdata->header.dshb_nte.dti_page_count)
1167 return (const unsigned char *) "\09[INVALID]";
1168
1169 return (const unsigned char *) sdata->name_table + sym_index;
1170 }
1171
1172 const unsigned char *
1173 bfd_sym_module_name (bfd *abfd, unsigned long sym_index)
1174 {
1175 bfd_sym_modules_table_entry entry;
1176
1177 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, sym_index) < 0)
1178 return (const unsigned char *) "\09[INVALID]";
1179
1180 return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
1181 }
1182
1183 const char *
1184 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind)
1185 {
1186 switch (kind)
1187 {
1188 case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL";
1189 case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE";
1190 case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE";
1191 case BFD_SYM_STORAGE_KIND_WITH: return "WITH";
1192 default: return "[UNKNOWN]";
1193 }
1194 }
1195
1196 const char *
1197 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind)
1198 {
1199 switch (kind)
1200 {
1201 case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER";
1202 case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL";
1203 case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE";
1204 case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE";
1205 case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE";
1206 case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT";
1207 case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE";
1208 case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT";
1209 default: return "[UNKNOWN]";
1210 }
1211 }
1212
1213 const char *
1214 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind)
1215 {
1216 switch (kind)
1217 {
1218 case BFD_SYM_MODULE_KIND_NONE: return "NONE";
1219 case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM";
1220 case BFD_SYM_MODULE_KIND_UNIT: return "UNIT";
1221 case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE";
1222 case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION";
1223 case BFD_SYM_MODULE_KIND_DATA: return "DATA";
1224 case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK";
1225 default: return "[UNKNOWN]";
1226 }
1227 }
1228
1229 const char *
1230 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope)
1231 {
1232 switch (scope)
1233 {
1234 case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
1235 case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
1236 default:
1237 return "[UNKNOWN]";
1238 }
1239 }
1240
1241 void
1242 bfd_sym_print_file_reference (bfd *abfd,
1243 FILE *f,
1244 bfd_sym_file_reference *entry)
1245 {
1246 bfd_sym_file_references_table_entry frtentry;
1247 int ret;
1248
1249 ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
1250 entry->fref_frte_index);
1251 fprintf (f, "FILE ");
1252
1253 if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
1254 fprintf (f, "[INVALID]");
1255 else
1256 fprintf (f, "\"%.*s\"",
1257 bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0],
1258 &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]);
1259
1260 fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
1261 }
1262
1263 void
1264 bfd_sym_print_resources_table_entry (bfd *abfd,
1265 FILE *f,
1266 bfd_sym_resources_table_entry *entry)
1267 {
1268 fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu",
1269 bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0],
1270 &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1],
1271 entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number,
1272 entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last);
1273 }
1274
1275 void
1276 bfd_sym_print_modules_table_entry (bfd *abfd,
1277 FILE *f,
1278 bfd_sym_modules_table_entry *entry)
1279 {
1280 fprintf (f, "\"%.*s\" (NTE %lu)",
1281 bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0],
1282 &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1],
1283 entry->mte_nte_index);
1284
1285 fprintf (f, "\n ");
1286
1287 bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref);
1288 fprintf (f, " range %lu -- %lu",
1289 entry->mte_imp_fref.fref_offset, entry->mte_imp_end);
1290
1291 fprintf (f, "\n ");
1292
1293 fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind));
1294 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope));
1295
1296 fprintf (f, ", RTE %lu, offset %lu, size %lu",
1297 entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
1298
1299 fprintf (f, "\n ");
1300
1301 fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu",
1302 entry->mte_cmte_index, entry->mte_cvte_index,
1303 entry->mte_clte_index, entry->mte_ctte_index,
1304 entry->mte_csnte_idx_1, entry->mte_csnte_idx_2);
1305
1306 if (entry->mte_parent != 0)
1307 fprintf (f, ", parent %lu", entry->mte_parent);
1308 else
1309 fprintf (f, ", no parent");
1310
1311 if (entry->mte_cmte_index != 0)
1312 fprintf (f, ", child %lu", entry->mte_cmte_index);
1313 else
1314 fprintf (f, ", no child");
1315 }
1316
1317 void
1318 bfd_sym_print_file_references_table_entry (bfd *abfd,
1319 FILE *f,
1320 bfd_sym_file_references_table_entry *entry)
1321 {
1322 switch (entry->generic.type)
1323 {
1324 case BFD_SYM_FILE_NAME_INDEX:
1325 fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ",
1326 bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0],
1327 &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1],
1328 entry->filename.nte_index);
1329
1330 fprintf (f, "[UNIMPLEMENTED]");
1331 /* printModDate (entry->filename.mod_date); */
1332 fprintf (f, " (0x%lx)", entry->filename.mod_date);
1333 break;
1334
1335 case BFD_SYM_END_OF_LIST:
1336 fprintf (f, "END");
1337 break;
1338
1339 default:
1340 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu",
1341 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1342 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1343 entry->entry.mte_index,
1344 entry->entry.file_offset);
1345 break;
1346 }
1347 }
1348
1349 void
1350 bfd_sym_print_contained_modules_table_entry (bfd *abfd,
1351 FILE *f,
1352 bfd_sym_contained_modules_table_entry *entry)
1353 {
1354 switch (entry->generic.type)
1355 {
1356 case BFD_SYM_END_OF_LIST:
1357 fprintf (f, "END");
1358 break;
1359
1360 default:
1361 fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)",
1362 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1363 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1364 entry->entry.mte_index,
1365 entry->entry.nte_index);
1366 break;
1367 }
1368 }
1369
1370 void
1371 bfd_sym_print_contained_variables_table_entry (bfd *abfd,
1372 FILE *f,
1373 bfd_sym_contained_variables_table_entry *entry)
1374 {
1375 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1376 {
1377 fprintf (f, "END");
1378 return;
1379 }
1380
1381 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1382 {
1383 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1384 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1385 return;
1386 }
1387
1388 fprintf (f, "\"%.*s\" (NTE %lu)",
1389 bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0],
1390 &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1],
1391 entry->entry.nte_index);
1392
1393 fprintf (f, ", TTE %lu", entry->entry.tte_index);
1394 fprintf (f, ", offset %lu", entry->entry.file_delta);
1395 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope));
1396
1397 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
1398 fprintf (f, ", latype %s, laclass %s, laoffset %lu",
1399 bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind),
1400 bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class),
1401 entry->entry.address.scstruct.sca_offset);
1402 else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE)
1403 {
1404 unsigned long i;
1405
1406 fprintf (f, ", la [");
1407 for (i = 0; i < entry->entry.la_size; i++)
1408 fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]);
1409 fprintf (f, "]");
1410 }
1411 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
1412 fprintf (f, ", bigla %lu, biglakind %u",
1413 entry->entry.address.biglastruct.big_la,
1414 entry->entry.address.biglastruct.big_la_kind);
1415
1416 else
1417 fprintf (f, ", la [INVALID]");
1418 }
1419
1420 void
1421 bfd_sym_print_contained_statements_table_entry (bfd *abfd,
1422 FILE *f,
1423 bfd_sym_contained_statements_table_entry *entry)
1424 {
1425 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1426 {
1427 fprintf (f, "END");
1428 return;
1429 }
1430
1431 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1432 {
1433 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1434 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1435 return;
1436 }
1437
1438 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu",
1439 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1440 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1441 entry->entry.mte_index,
1442 entry->entry.mte_offset,
1443 entry->entry.file_delta);
1444 }
1445
1446 void
1447 bfd_sym_print_contained_labels_table_entry (bfd *abfd,
1448 FILE *f,
1449 bfd_sym_contained_labels_table_entry *entry)
1450 {
1451 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1452 {
1453 fprintf (f, "END");
1454 return;
1455 }
1456
1457 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1458 {
1459 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1460 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1461 return;
1462 }
1463
1464 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s",
1465 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1466 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1467 entry->entry.mte_index,
1468 entry->entry.mte_offset,
1469 entry->entry.file_delta,
1470 bfd_sym_unparse_symbol_scope (entry->entry.scope));
1471 }
1472
1473 void
1474 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1475 FILE *f,
1476 bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED)
1477 {
1478 fprintf (f, "[UNIMPLEMENTED]");
1479 }
1480
1481 const char *
1482 bfd_sym_type_operator_name (unsigned char num)
1483 {
1484 switch (num)
1485 {
1486 case 1: return "TTE";
1487 case 2: return "PointerTo";
1488 case 3: return "ScalarOf";
1489 case 4: return "ConstantOf";
1490 case 5: return "EnumerationOf";
1491 case 6: return "VectorOf";
1492 case 7: return "RecordOf";
1493 case 8: return "UnionOf";
1494 case 9: return "SubRangeOf";
1495 case 10: return "SetOf";
1496 case 11: return "NamedTypeOf";
1497 case 12: return "ProcOf";
1498 case 13: return "ValueOf";
1499 case 14: return "ArrayOf";
1500 default: return "[UNKNOWN OPERATOR]";
1501 }
1502 }
1503
1504 const char *
1505 bfd_sym_type_basic_name (unsigned char num)
1506 {
1507 switch (num)
1508 {
1509 case 0: return "void";
1510 case 1: return "pascal string";
1511 case 2: return "unsigned long";
1512 case 3: return "signed long";
1513 case 4: return "extended (10 bytes)";
1514 case 5: return "pascal boolean (1 byte)";
1515 case 6: return "unsigned byte";
1516 case 7: return "signed byte";
1517 case 8: return "character (1 byte)";
1518 case 9: return "wide character (2 bytes)";
1519 case 10: return "unsigned short";
1520 case 11: return "signed short";
1521 case 12: return "singled";
1522 case 13: return "double";
1523 case 14: return "extended (12 bytes)";
1524 case 15: return "computational (8 bytes)";
1525 case 16: return "c string";
1526 case 17: return "as-is string";
1527 default: return "[UNKNOWN BASIC TYPE]";
1528 }
1529 }
1530
1531 int
1532 bfd_sym_fetch_long (unsigned char *buf,
1533 unsigned long len,
1534 unsigned long offset,
1535 unsigned long *offsetptr,
1536 long *value)
1537 {
1538 int ret;
1539
1540 if (offset >= len)
1541 {
1542 *value = 0;
1543 offset += 0;
1544 ret = -1;
1545 }
1546 else if (! (buf[offset] & 0x80))
1547 {
1548 *value = buf[offset];
1549 offset += 1;
1550 ret = 0;
1551 }
1552 else if (buf[offset] == 0xc0)
1553 {
1554 if ((offset + 5) > len)
1555 {
1556 *value = 0;
1557 offset = len;
1558 ret = -1;
1559 }
1560 else
1561 {
1562 *value = bfd_getb32 (buf + offset + 1);
1563 offset += 5;
1564 ret = 0;
1565 }
1566 }
1567 else if ((buf[offset] & 0xc0) == 0xc0)
1568 {
1569 *value = -(buf[offset] & 0x3f);
1570 offset += 1;
1571 ret = 0;
1572 }
1573 else if ((buf[offset] & 0xc0) == 0x80)
1574 {
1575 if ((offset + 2) > len)
1576 {
1577 *value = 0;
1578 offset = len;
1579 ret = -1;
1580 }
1581 else
1582 {
1583 *value = bfd_getb16 (buf + offset) & 0x3fff;
1584 offset += 2;
1585 ret = 0;
1586 }
1587 }
1588 else
1589 abort ();
1590
1591 if (offsetptr != NULL)
1592 *offsetptr = offset;
1593
1594 return ret;
1595 }
1596
1597 void
1598 bfd_sym_print_type_information (bfd *abfd,
1599 FILE *f,
1600 unsigned char *buf,
1601 unsigned long len,
1602 unsigned long offset,
1603 unsigned long *offsetptr)
1604 {
1605 unsigned int type;
1606
1607 if (offset >= len)
1608 {
1609 fprintf (f, "[NULL]");
1610
1611 if (offsetptr != NULL)
1612 *offsetptr = offset;
1613 return;
1614 }
1615
1616 type = buf[offset];
1617 offset++;
1618
1619 if (! (type & 0x80))
1620 {
1621 fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
1622
1623 if (offsetptr != NULL)
1624 *offsetptr = offset;
1625 return;
1626 }
1627
1628 if (type & 0x40)
1629 fprintf (f, "[packed ");
1630 else
1631 fprintf (f, "[");
1632
1633 switch (type & 0x3f)
1634 {
1635 case 1:
1636 {
1637 long value;
1638 bfd_sym_type_information_table_entry tinfo;
1639
1640 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1641 if (value <= 0)
1642 fprintf (f, "[INVALID]");
1643 else
1644 {
1645 if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
1646 fprintf (f, "[INVALID]");
1647 else
1648 fprintf (f, "\"%.*s\"",
1649 bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
1650 &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
1651 }
1652 fprintf (f, " (TTE %lu)", (unsigned long) value);
1653 break;
1654 }
1655
1656 case 2:
1657 fprintf (f, "pointer (0x%x) to ", type);
1658 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1659 break;
1660
1661 case 3:
1662 {
1663 long value;
1664
1665 fprintf (f, "scalar (0x%x) of ", type);
1666 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1667 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1668 fprintf (f, " (%lu)", (unsigned long) value);
1669 break;
1670 }
1671
1672 case 5:
1673 {
1674 long lower, upper, nelem;
1675 int i;
1676
1677 fprintf (f, "enumeration (0x%x) of ", type);
1678 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1679 bfd_sym_fetch_long (buf, len, offset, &offset, &lower);
1680 bfd_sym_fetch_long (buf, len, offset, &offset, &upper);
1681 bfd_sym_fetch_long (buf, len, offset, &offset, &nelem);
1682 fprintf (f, " from %lu to %lu with %lu elements: ",
1683 (unsigned long) lower, (unsigned long) upper,
1684 (unsigned long) nelem);
1685
1686 for (i = 0; i < nelem; i++)
1687 {
1688 fprintf (f, "\n ");
1689 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1690 }
1691 break;
1692 }
1693
1694 case 6:
1695 fprintf (f, "vector (0x%x)", type);
1696 fprintf (f, "\n index ");
1697 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1698 fprintf (f, "\n target ");
1699 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1700 break;
1701
1702 case 7:
1703 case 8:
1704 {
1705 long nrec, eloff, i;
1706
1707 if ((type & 0x3f) == 7)
1708 fprintf (f, "record (0x%x) of ", type);
1709 else
1710 fprintf (f, "union (0x%x) of ", type);
1711
1712 bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
1713 fprintf (f, "%lu elements: ", (unsigned long) nrec);
1714
1715 for (i = 0; i < nrec; i++)
1716 {
1717 bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
1718 fprintf (f, "\n ");
1719 fprintf (f, "offset %lu: ", (unsigned long) eloff);
1720 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1721 }
1722 break;
1723 }
1724
1725 case 9:
1726 fprintf (f, "subrange (0x%x) of ", type);
1727 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1728 fprintf (f, " lower ");
1729 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1730 fprintf (f, " upper ");
1731 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1732 break;
1733
1734 case 11:
1735 {
1736 long value;
1737
1738 fprintf (f, "named type (0x%x) ", type);
1739 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1740 if (value <= 0)
1741 fprintf (f, "[INVALID]");
1742 else
1743 fprintf (f, "\"%.*s\"",
1744 bfd_sym_symbol_name (abfd, value)[0],
1745 &bfd_sym_symbol_name (abfd, value)[1]);
1746
1747 fprintf (f, " (NTE %lu) with type ", (unsigned long) value);
1748 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1749 break;
1750 }
1751
1752 default:
1753 fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
1754 break;
1755 }
1756
1757 if (type == (0x40 | 0x6))
1758 {
1759 /* Vector. */
1760 long n, width, m;
1761 long l;
1762 long i;
1763
1764 bfd_sym_fetch_long (buf, len, offset, &offset, &n);
1765 bfd_sym_fetch_long (buf, len, offset, &offset, &width);
1766 bfd_sym_fetch_long (buf, len, offset, &offset, &m);
1767 /* fprintf (f, "\n "); */
1768 fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m);
1769 for (i = 0; i < m; i++)
1770 {
1771 bfd_sym_fetch_long (buf, len, offset, &offset, &l);
1772 if (i != 0)
1773 fprintf (f, " ");
1774 fprintf (f, "%ld", l);
1775 }
1776 }
1777 else if (type & 0x40)
1778 {
1779 /* Other packed type. */
1780 long msb, lsb;
1781
1782 bfd_sym_fetch_long (buf, len, offset, &offset, &msb);
1783 bfd_sym_fetch_long (buf, len, offset, &offset, &lsb);
1784 /* fprintf (f, "\n "); */
1785 fprintf (f, " msb %ld, lsb %ld", msb, lsb);
1786 }
1787
1788 fprintf (f, "]");
1789
1790 if (offsetptr != NULL)
1791 *offsetptr = offset;
1792 }
1793
1794 void
1795 bfd_sym_print_type_information_table_entry (bfd *abfd,
1796 FILE *f,
1797 bfd_sym_type_information_table_entry *entry)
1798 {
1799 unsigned char *buf;
1800 unsigned long offset;
1801 unsigned int i;
1802
1803 fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu",
1804 bfd_sym_symbol_name (abfd, entry->nte_index)[0],
1805 &bfd_sym_symbol_name (abfd, entry->nte_index)[1],
1806 entry->nte_index,
1807 entry->physical_size, entry->offset, entry->logical_size);
1808
1809 fprintf (f, "\n ");
1810
1811 buf = malloc (entry->physical_size);
1812 if (buf == NULL)
1813 {
1814 fprintf (f, "[ERROR]\n");
1815 return;
1816 }
1817 if (bfd_seek (abfd, entry->offset, SEEK_SET) < 0)
1818 {
1819 fprintf (f, "[ERROR]\n");
1820 free (buf);
1821 return;
1822 }
1823 if (bfd_bread (buf, entry->physical_size, abfd) != entry->physical_size)
1824 {
1825 fprintf (f, "[ERROR]\n");
1826 free (buf);
1827 return;
1828 }
1829
1830 fprintf (f, "[");
1831 for (i = 0; i < entry->physical_size; i++)
1832 {
1833 if (i == 0)
1834 fprintf (f, "0x%02x", buf[i]);
1835 else
1836 fprintf (f, " 0x%02x", buf[i]);
1837 }
1838
1839 fprintf (f, "]");
1840 fprintf (f, "\n ");
1841
1842 bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
1843
1844 if (offset != entry->physical_size)
1845 fprintf (f, "\n [parser used %lu bytes instead of %lu]", offset, entry->physical_size);
1846 free (buf);
1847 }
1848
1849 void
1850 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1851 FILE *f,
1852 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED)
1853 {
1854 fprintf (f, "[UNIMPLEMENTED]");
1855 }
1856
1857 void
1858 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED,
1859 FILE *f,
1860 bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED)
1861 {
1862 fprintf (f, "[UNIMPLEMENTED]");
1863 }
1864
1865 unsigned char *
1866 bfd_sym_display_name_table_entry (bfd *abfd,
1867 FILE *f,
1868 unsigned char *entry)
1869 {
1870 unsigned long sym_index;
1871 unsigned long offset;
1872 bfd_sym_data_struct *sdata = NULL;
1873
1874 BFD_ASSERT (bfd_sym_valid (abfd));
1875 sdata = abfd->tdata.sym_data;
1876 sym_index = (entry - sdata->name_table) / 2;
1877
1878 if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
1879 {
1880 unsigned short length = bfd_getb16 (entry + 2);
1881 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, length, entry + 4);
1882 offset = 2 + length + 1;
1883 }
1884 else
1885 {
1886 if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
1887 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, entry[0], entry + 1);
1888
1889 if (sdata->version >= BFD_SYM_VERSION_3_4)
1890 offset = entry[0] + 2;
1891 else
1892 offset = entry[0] + 1;
1893 }
1894
1895 return (entry + offset + (offset % 2));
1896 }
1897
1898 void
1899 bfd_sym_display_name_table (bfd *abfd, FILE *f)
1900 {
1901 unsigned long name_table_len;
1902 unsigned char *name_table, *name_table_end, *cur;
1903 bfd_sym_data_struct *sdata = NULL;
1904
1905 BFD_ASSERT (bfd_sym_valid (abfd));
1906 sdata = abfd->tdata.sym_data;
1907
1908 name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size;
1909 name_table = sdata->name_table;
1910 name_table_end = name_table + name_table_len;
1911
1912 fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
1913
1914 cur = name_table;
1915 for (;;)
1916 {
1917 cur = bfd_sym_display_name_table_entry (abfd, f, cur);
1918 if (cur >= name_table_end)
1919 break;
1920 }
1921 }
1922
1923 void
1924 bfd_sym_display_resources_table (bfd *abfd, FILE *f)
1925 {
1926 unsigned long i;
1927 bfd_sym_resources_table_entry entry;
1928 bfd_sym_data_struct *sdata = NULL;
1929
1930 BFD_ASSERT (bfd_sym_valid (abfd));
1931 sdata = abfd->tdata.sym_data;
1932
1933 fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
1934 sdata->header.dshb_rte.dti_object_count);
1935
1936 for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
1937 {
1938 if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
1939 fprintf (f, " [%8lu] [INVALID]\n", i);
1940 else
1941 {
1942 fprintf (f, " [%8lu] ", i);
1943 bfd_sym_print_resources_table_entry (abfd, f, &entry);
1944 fprintf (f, "\n");
1945 }
1946 }
1947 }
1948
1949 void
1950 bfd_sym_display_modules_table (bfd *abfd, FILE *f)
1951 {
1952 unsigned long i;
1953 bfd_sym_modules_table_entry entry;
1954 bfd_sym_data_struct *sdata = NULL;
1955
1956 BFD_ASSERT (bfd_sym_valid (abfd));
1957 sdata = abfd->tdata.sym_data;
1958
1959 fprintf (f, "module table (MTE) contains %lu objects:\n\n",
1960 sdata->header.dshb_mte.dti_object_count);
1961
1962 for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
1963 {
1964 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
1965 fprintf (f, " [%8lu] [INVALID]\n", i);
1966 else
1967 {
1968 fprintf (f, " [%8lu] ", i);
1969 bfd_sym_print_modules_table_entry (abfd, f, &entry);
1970 fprintf (f, "\n");
1971 }
1972 }
1973 }
1974
1975 void
1976 bfd_sym_display_file_references_table (bfd *abfd, FILE *f)
1977 {
1978 unsigned long i;
1979 bfd_sym_file_references_table_entry entry;
1980 bfd_sym_data_struct *sdata = NULL;
1981
1982 BFD_ASSERT (bfd_sym_valid (abfd));
1983 sdata = abfd->tdata.sym_data;
1984
1985 fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
1986 sdata->header.dshb_frte.dti_object_count);
1987
1988 for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
1989 {
1990 if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
1991 fprintf (f, " [%8lu] [INVALID]\n", i);
1992 else
1993 {
1994 fprintf (f, " [%8lu] ", i);
1995 bfd_sym_print_file_references_table_entry (abfd, f, &entry);
1996 fprintf (f, "\n");
1997 }
1998 }
1999 }
2000
2001 void
2002 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f)
2003 {
2004 unsigned long i;
2005 bfd_sym_contained_modules_table_entry entry;
2006 bfd_sym_data_struct *sdata = NULL;
2007
2008 BFD_ASSERT (bfd_sym_valid (abfd));
2009 sdata = abfd->tdata.sym_data;
2010
2011 fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
2012 sdata->header.dshb_cmte.dti_object_count);
2013
2014 for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
2015 {
2016 if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
2017 fprintf (f, " [%8lu] [INVALID]\n", i);
2018 else
2019 {
2020 fprintf (f, " [%8lu] ", i);
2021 bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
2022 fprintf (f, "\n");
2023 }
2024 }
2025 }
2026
2027 void
2028 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f)
2029 {
2030 unsigned long i;
2031 bfd_sym_contained_variables_table_entry entry;
2032 bfd_sym_data_struct *sdata = NULL;
2033
2034 BFD_ASSERT (bfd_sym_valid (abfd));
2035 sdata = abfd->tdata.sym_data;
2036
2037 fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
2038 sdata->header.dshb_cvte.dti_object_count);
2039
2040 for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
2041 {
2042 if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
2043 fprintf (f, " [%8lu] [INVALID]\n", i);
2044 else
2045 {
2046 fprintf (f, " [%8lu] ", i);
2047 bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
2048 fprintf (f, "\n");
2049 }
2050 }
2051
2052 fprintf (f, "\n");
2053 }
2054
2055 void
2056 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f)
2057 {
2058 unsigned long i;
2059 bfd_sym_contained_statements_table_entry entry;
2060 bfd_sym_data_struct *sdata = NULL;
2061
2062 BFD_ASSERT (bfd_sym_valid (abfd));
2063 sdata = abfd->tdata.sym_data;
2064
2065 fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
2066 sdata->header.dshb_csnte.dti_object_count);
2067
2068 for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
2069 {
2070 if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
2071 fprintf (f, " [%8lu] [INVALID]\n", i);
2072 else
2073 {
2074 fprintf (f, " [%8lu] ", i);
2075 bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
2076 fprintf (f, "\n");
2077 }
2078 }
2079 }
2080
2081 void
2082 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f)
2083 {
2084 unsigned long i;
2085 bfd_sym_contained_labels_table_entry entry;
2086 bfd_sym_data_struct *sdata = NULL;
2087
2088 BFD_ASSERT (bfd_sym_valid (abfd));
2089 sdata = abfd->tdata.sym_data;
2090
2091 fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
2092 sdata->header.dshb_clte.dti_object_count);
2093
2094 for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
2095 {
2096 if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
2097 fprintf (f, " [%8lu] [INVALID]\n", i);
2098 else
2099 {
2100 fprintf (f, " [%8lu] ", i);
2101 bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
2102 fprintf (f, "\n");
2103 }
2104 }
2105 }
2106
2107 void
2108 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f)
2109 {
2110 unsigned long i;
2111 bfd_sym_contained_types_table_entry entry;
2112 bfd_sym_data_struct *sdata = NULL;
2113
2114 BFD_ASSERT (bfd_sym_valid (abfd));
2115 sdata = abfd->tdata.sym_data;
2116
2117 fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
2118 sdata->header.dshb_ctte.dti_object_count);
2119
2120 for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
2121 {
2122 if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
2123 fprintf (f, " [%8lu] [INVALID]\n", i);
2124 else
2125 {
2126 fprintf (f, " [%8lu] ", i);
2127 bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
2128 fprintf (f, "\n");
2129 }
2130 }
2131 }
2132
2133 void
2134 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f)
2135 {
2136 unsigned long i;
2137 bfd_sym_file_references_index_table_entry entry;
2138 bfd_sym_data_struct *sdata = NULL;
2139
2140 BFD_ASSERT (bfd_sym_valid (abfd));
2141 sdata = abfd->tdata.sym_data;
2142
2143 fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
2144 sdata->header.dshb_fite.dti_object_count);
2145
2146 for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
2147 {
2148 if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
2149 fprintf (f, " [%8lu] [INVALID]\n", i);
2150 else
2151 {
2152 fprintf (f, " [%8lu] ", i);
2153 bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
2154 fprintf (f, "\n");
2155 }
2156 }
2157 }
2158
2159 void
2160 bfd_sym_display_constant_pool (bfd *abfd, FILE *f)
2161 {
2162 unsigned long i;
2163 bfd_sym_constant_pool_entry entry;
2164 bfd_sym_data_struct *sdata = NULL;
2165
2166 BFD_ASSERT (bfd_sym_valid (abfd));
2167 sdata = abfd->tdata.sym_data;
2168
2169 fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
2170 sdata->header.dshb_const.dti_object_count);
2171
2172 for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
2173 {
2174 if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
2175 fprintf (f, " [%8lu] [INVALID]\n", i);
2176 else
2177 {
2178 fprintf (f, " [%8lu] ", i);
2179 bfd_sym_print_constant_pool_entry (abfd, f, &entry);
2180 fprintf (f, "\n");
2181 }
2182 }
2183 }
2184
2185 void
2186 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
2187 {
2188 unsigned long i;
2189 bfd_sym_type_table_entry sym_index;
2190 bfd_sym_type_information_table_entry entry;
2191 bfd_sym_data_struct *sdata = NULL;
2192
2193 BFD_ASSERT (bfd_sym_valid (abfd));
2194 sdata = abfd->tdata.sym_data;
2195
2196 if (sdata->header.dshb_tte.dti_object_count > 99)
2197 fprintf (f, "type table (TINFO) contains %lu objects:\n\n",
2198 sdata->header.dshb_tte.dti_object_count - 99);
2199 else
2200 {
2201 fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
2202 return;
2203 }
2204
2205 for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
2206 {
2207 if (bfd_sym_fetch_type_table_entry (abfd, &sym_index, i - 100) < 0)
2208 fprintf (f, " [%8lu] [INVALID]\n", i);
2209 else
2210 {
2211 fprintf (f, " [%8lu] (TINFO %lu) ", i, sym_index);
2212
2213 if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, sym_index) < 0)
2214 fprintf (f, "[INVALID]");
2215 else
2216 bfd_sym_print_type_information_table_entry (abfd, f, &entry);
2217
2218 fprintf (f, "\n");
2219 }
2220 }
2221 }
2222
2223 int
2224 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
2225 {
2226 asection *bfdsec;
2227 const char *name = "symbols";
2228
2229 mdata->name_table = 0;
2230 mdata->sbfd = abfd;
2231 mdata->version = version;
2232
2233 bfd_seek (abfd, 0, SEEK_SET);
2234 if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
2235 return -1;
2236
2237 mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
2238 if (mdata->name_table == NULL)
2239 return -1;
2240
2241 bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS);
2242 if (bfdsec == NULL)
2243 return -1;
2244
2245 bfdsec->vma = 0;
2246 bfdsec->lma = 0;
2247 bfdsec->size = 0;
2248 bfdsec->filepos = 0;
2249 bfdsec->alignment_power = 0;
2250
2251 abfd->tdata.sym_data = mdata;
2252
2253 return 0;
2254 }
2255
2256 const bfd_target *
2257 bfd_sym_object_p (bfd *abfd)
2258 {
2259 bfd_sym_version version = -1;
2260 bfd_sym_data_struct *mdata;
2261
2262 bfd_seek (abfd, 0, SEEK_SET);
2263 if (bfd_sym_read_version (abfd, &version) != 0)
2264 goto wrong;
2265
2266 mdata = (bfd_sym_data_struct *) bfd_alloc (abfd, sizeof (*mdata));
2267 if (mdata == NULL)
2268 goto fail;
2269
2270 if (bfd_sym_scan (abfd, version, mdata) != 0)
2271 goto wrong;
2272
2273 return abfd->xvec;
2274
2275 wrong:
2276 bfd_set_error (bfd_error_wrong_format);
2277
2278 fail:
2279 return NULL;
2280 }
2281
2282 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol
2283
2284 void
2285 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret)
2286 {
2287 bfd_symbol_info (symbol, ret);
2288 }
2289
2290 long
2291 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED)
2292 {
2293 return 0;
2294 }
2295
2296 long
2297 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED)
2298 {
2299 return 0;
2300 }
2301
2302 int
2303 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
2304 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2305 {
2306 return 0;
2307 }
2308
2309 const bfd_target sym_vec =
2310 {
2311 "sym", /* Name. */
2312 bfd_target_sym_flavour, /* Flavour. */
2313 BFD_ENDIAN_BIG, /* Byteorder. */
2314 BFD_ENDIAN_BIG, /* Header byteorder. */
2315 (HAS_RELOC | EXEC_P | /* Object flags. */
2316 HAS_LINENO | HAS_DEBUG |
2317 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2318 (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
2319 | SEC_ROM | SEC_HAS_CONTENTS), /* Section_flags. */
2320 0, /* Symbol_leading_char. */
2321 ' ', /* AR_pad_char. */
2322 16, /* AR_max_namelen. */
2323 0, /* match priority. */
2324 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2325 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2326 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
2327 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2328 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2329 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Hdrs. */
2330 { /* bfd_check_format. */
2331 _bfd_dummy_target,
2332 bfd_sym_object_p, /* bfd_check_format. */
2333 _bfd_dummy_target,
2334 _bfd_dummy_target,
2335 },
2336 { /* bfd_set_format. */
2337 _bfd_bool_bfd_false_error,
2338 bfd_sym_mkobject,
2339 _bfd_bool_bfd_false_error,
2340 _bfd_bool_bfd_false_error,
2341 },
2342 { /* bfd_write_contents. */
2343 _bfd_bool_bfd_false_error,
2344 _bfd_bool_bfd_true,
2345 _bfd_bool_bfd_false_error,
2346 _bfd_bool_bfd_false_error,
2347 },
2348
2349 BFD_JUMP_TABLE_GENERIC (bfd_sym),
2350 BFD_JUMP_TABLE_COPY (_bfd_generic),
2351 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2352 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
2353 BFD_JUMP_TABLE_SYMBOLS (bfd_sym),
2354 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
2355 BFD_JUMP_TABLE_WRITE (bfd_sym),
2356 BFD_JUMP_TABLE_LINK (bfd_sym),
2357 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2358
2359 NULL,
2360
2361 NULL
2362 };
This page took 0.07713 seconds and 4 git commands to generate.