* elf32-spu.c (build_stub): Fix malloc under-allocation.
[binutils.git] / bfd / xsym.c
blob0926297e059510562de8c0e1bdeb028ac3e49388
1 /* xSYM symbol-file support for BFD.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009, 2010, 2011 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 /* xSYM is the debugging format used by CodeWarrior on Mac OS classic. */
24 #include "alloca-conf.h"
25 #include "sysdep.h"
26 #include "xsym.h"
27 #include "bfd.h"
28 #include "libbfd.h"
30 #define bfd_sym_close_and_cleanup _bfd_generic_close_and_cleanup
31 #define bfd_sym_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
32 #define bfd_sym_new_section_hook _bfd_generic_new_section_hook
33 #define bfd_sym_bfd_is_local_label_name bfd_generic_is_local_label_name
34 #define bfd_sym_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
35 #define bfd_sym_get_lineno _bfd_nosymbols_get_lineno
36 #define bfd_sym_find_nearest_line _bfd_nosymbols_find_nearest_line
37 #define bfd_sym_find_inliner_info _bfd_nosymbols_find_inliner_info
38 #define bfd_sym_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
39 #define bfd_sym_read_minisymbols _bfd_generic_read_minisymbols
40 #define bfd_sym_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
41 #define bfd_sym_set_arch_mach _bfd_generic_set_arch_mach
42 #define bfd_sym_get_section_contents _bfd_generic_get_section_contents
43 #define bfd_sym_set_section_contents _bfd_generic_set_section_contents
44 #define bfd_sym_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
45 #define bfd_sym_bfd_relax_section bfd_generic_relax_section
46 #define bfd_sym_bfd_gc_sections bfd_generic_gc_sections
47 #define bfd_sym_bfd_lookup_section_flags bfd_generic_lookup_section_flags
48 #define bfd_sym_bfd_merge_sections bfd_generic_merge_sections
49 #define bfd_sym_bfd_is_group_section bfd_generic_is_group_section
50 #define bfd_sym_bfd_discard_group bfd_generic_discard_group
51 #define bfd_sym_section_already_linked _bfd_generic_section_already_linked
52 #define bfd_sym_bfd_define_common_symbol bfd_generic_define_common_symbol
53 #define bfd_sym_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
54 #define bfd_sym_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
55 #define bfd_sym_bfd_link_add_symbols _bfd_generic_link_add_symbols
56 #define bfd_sym_bfd_link_just_syms _bfd_generic_link_just_syms
57 #define bfd_sym_bfd_copy_link_hash_symbol_type \
58 _bfd_generic_copy_link_hash_symbol_type
59 #define bfd_sym_bfd_final_link _bfd_generic_final_link
60 #define bfd_sym_bfd_link_split_section _bfd_generic_link_split_section
61 #define bfd_sym_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
63 extern const bfd_target sym_vec;
65 static int
66 pstrcmp (const char *as, const char *bs)
68 const unsigned char *a = (const unsigned char *) as;
69 const unsigned char *b = (const unsigned char *) bs;
70 unsigned char clen;
71 int ret;
73 clen = (a[0] > b[0]) ? b[0] : a[0];
74 ret = memcmp (a + 1, b + 1, clen);
75 if (ret != 0)
76 return ret;
78 if (a[0] == b[0])
79 return 0;
80 else if (a[0] < b[0])
81 return -1;
82 else
83 return 1;
86 static unsigned long
87 compute_offset (unsigned long first_page,
88 unsigned long page_size,
89 unsigned long entry_size,
90 unsigned long sym_index)
92 unsigned long entries_per_page = page_size / entry_size;
93 unsigned long page_number = first_page + (sym_index / entries_per_page);
94 unsigned long page_offset = (sym_index % entries_per_page) * entry_size;
96 return (page_number * page_size) + page_offset;
99 bfd_boolean
100 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
102 return 1;
105 void
106 bfd_sym_print_symbol (bfd *abfd ATTRIBUTE_UNUSED,
107 void * afile ATTRIBUTE_UNUSED,
108 asymbol *symbol ATTRIBUTE_UNUSED,
109 bfd_print_symbol_type how ATTRIBUTE_UNUSED)
111 return;
114 bfd_boolean
115 bfd_sym_valid (bfd *abfd)
117 if (abfd == NULL || abfd->xvec == NULL)
118 return 0;
120 return abfd->xvec == &sym_vec;
123 unsigned char *
124 bfd_sym_read_name_table (bfd *abfd, bfd_sym_header_block *dshb)
126 unsigned char *rstr;
127 long ret;
128 size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size;
129 size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size;
131 rstr = bfd_alloc (abfd, table_size);
132 if (rstr == NULL)
133 return rstr;
135 bfd_seek (abfd, table_offset, SEEK_SET);
136 ret = bfd_bread (rstr, table_size, abfd);
137 if (ret < 0 || (unsigned long) ret != table_size)
139 bfd_release (abfd, rstr);
140 return NULL;
143 return rstr;
146 void
147 bfd_sym_parse_file_reference_v32 (unsigned char *buf,
148 size_t len,
149 bfd_sym_file_reference *entry)
151 BFD_ASSERT (len == 6);
153 entry->fref_frte_index = bfd_getb16 (buf);
154 entry->fref_offset = bfd_getb32 (buf + 2);
157 void
158 bfd_sym_parse_disk_table_v32 (unsigned char *buf,
159 size_t len,
160 bfd_sym_table_info *table)
162 BFD_ASSERT (len == 8);
164 table->dti_first_page = bfd_getb16 (buf);
165 table->dti_page_count = bfd_getb16 (buf + 2);
166 table->dti_object_count = bfd_getb32 (buf + 4);
169 void
170 bfd_sym_parse_header_v32 (unsigned char *buf,
171 size_t len,
172 bfd_sym_header_block *header)
174 BFD_ASSERT (len == 154);
176 memcpy (header->dshb_id, buf, 32);
177 header->dshb_page_size = bfd_getb16 (buf + 32);
178 header->dshb_hash_page = bfd_getb16 (buf + 34);
179 header->dshb_root_mte = bfd_getb16 (buf + 36);
180 header->dshb_mod_date = bfd_getb32 (buf + 38);
182 bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte);
183 bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte);
184 bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte);
185 bfd_sym_parse_disk_table_v32 (buf + 66, 8, &header->dshb_cmte);
186 bfd_sym_parse_disk_table_v32 (buf + 74, 8, &header->dshb_cvte);
187 bfd_sym_parse_disk_table_v32 (buf + 82, 8, &header->dshb_csnte);
188 bfd_sym_parse_disk_table_v32 (buf + 90, 8, &header->dshb_clte);
189 bfd_sym_parse_disk_table_v32 (buf + 98, 8, &header->dshb_ctte);
190 bfd_sym_parse_disk_table_v32 (buf + 106, 8, &header->dshb_tte);
191 bfd_sym_parse_disk_table_v32 (buf + 114, 8, &header->dshb_nte);
192 bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo);
193 bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite);
194 bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const);
196 memcpy (&header->dshb_file_creator, buf + 146, 4);
197 memcpy (&header->dshb_file_type, buf + 150, 4);
201 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header)
203 unsigned char buf[154];
204 long ret;
206 ret = bfd_bread (buf, 154, abfd);
207 if (ret != 154)
208 return -1;
210 bfd_sym_parse_header_v32 (buf, 154, header);
212 return 0;
216 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED,
217 bfd_sym_header_block *header ATTRIBUTE_UNUSED)
219 abort ();
223 bfd_sym_read_header (bfd *abfd,
224 bfd_sym_header_block *header,
225 bfd_sym_version version)
227 switch (version)
229 case BFD_SYM_VERSION_3_5:
230 case BFD_SYM_VERSION_3_4:
231 return bfd_sym_read_header_v34 (abfd, header);
232 case BFD_SYM_VERSION_3_3:
233 case BFD_SYM_VERSION_3_2:
234 return bfd_sym_read_header_v32 (abfd, header);
235 case BFD_SYM_VERSION_3_1:
236 default:
237 return 0;
242 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version)
244 char version_string[32];
245 long ret;
247 ret = bfd_bread (version_string, sizeof (version_string), abfd);
248 if (ret != sizeof (version_string))
249 return -1;
251 if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0)
252 *version = BFD_SYM_VERSION_3_1;
253 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0)
254 *version = BFD_SYM_VERSION_3_2;
255 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0)
256 *version = BFD_SYM_VERSION_3_3;
257 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0)
258 *version = BFD_SYM_VERSION_3_4;
259 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0)
260 *version = BFD_SYM_VERSION_3_5;
261 else
262 return -1;
264 return 0;
267 void
268 bfd_sym_display_table_summary (FILE *f,
269 bfd_sym_table_info *dti,
270 const char *name)
272 fprintf (f, "%-6s %13ld %13ld %13ld\n",
273 name,
274 dti->dti_first_page,
275 dti->dti_page_count,
276 dti->dti_object_count);
279 void
280 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb)
282 fprintf (f, " Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1);
283 fprintf (f, " Page Size: 0x%x\n", dshb->dshb_page_size);
284 fprintf (f, " Hash Page: %lu\n", dshb->dshb_hash_page);
285 fprintf (f, " Root MTE: %lu\n", dshb->dshb_root_mte);
286 fprintf (f, " Modification Date: ");
287 fprintf (f, "[unimplemented]");
288 fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date);
290 fprintf (f, " File Creator: %.4s Type: %.4s\n\n",
291 dshb->dshb_file_creator, dshb->dshb_file_type);
293 fprintf (f, "Table Name First Page Page Count Object Count\n");
294 fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
296 bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE");
297 bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE");
298 bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE");
299 bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE");
300 bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE");
301 bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE");
302 bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE");
303 bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE");
304 bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE");
305 bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE");
306 bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO");
307 bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE");
308 bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST");
310 fprintf (f, "\n");
313 void
314 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf,
315 size_t len,
316 bfd_sym_resources_table_entry *entry)
318 BFD_ASSERT (len == 18);
320 memcpy (&entry->rte_res_type, buf, 4);
321 entry->rte_res_number = bfd_getb16 (buf + 4);
322 entry->rte_nte_index = bfd_getb32 (buf + 6);
323 entry->rte_mte_first = bfd_getb16 (buf + 10);
324 entry->rte_mte_last = bfd_getb16 (buf + 12);
325 entry->rte_res_size = bfd_getb32 (buf + 14);
328 void
329 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf,
330 size_t len,
331 bfd_sym_modules_table_entry *entry)
333 BFD_ASSERT (len == 46);
335 entry->mte_rte_index = bfd_getb16 (buf);
336 entry->mte_res_offset = bfd_getb32 (buf + 2);
337 entry->mte_size = bfd_getb32 (buf + 6);
338 entry->mte_kind = buf[10];
339 entry->mte_scope = buf[11];
340 entry->mte_parent = bfd_getb16 (buf + 12);
341 bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref);
342 entry->mte_imp_end = bfd_getb32 (buf + 20);
343 entry->mte_nte_index = bfd_getb32 (buf + 24);
344 entry->mte_cmte_index = bfd_getb16 (buf + 28);
345 entry->mte_cvte_index = bfd_getb32 (buf + 30);
346 entry->mte_clte_index = bfd_getb16 (buf + 34);
347 entry->mte_ctte_index = bfd_getb16 (buf + 36);
348 entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38);
349 entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42);
352 void
353 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf,
354 size_t len,
355 bfd_sym_file_references_table_entry *entry)
357 unsigned int type;
359 BFD_ASSERT (len == 10);
361 memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
362 type = bfd_getb16 (buf);
364 switch (type)
366 case BFD_SYM_END_OF_LIST_3_2:
367 entry->generic.type = BFD_SYM_END_OF_LIST;
368 break;
370 case BFD_SYM_FILE_NAME_INDEX_3_2:
371 entry->filename.type = BFD_SYM_FILE_NAME_INDEX;
372 entry->filename.nte_index = bfd_getb32 (buf + 2);
373 entry->filename.mod_date = bfd_getb32 (buf + 6);
374 break;
376 default:
377 entry->entry.mte_index = type;
378 entry->entry.file_offset = bfd_getb32 (buf + 2);
382 void
383 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf,
384 size_t len,
385 bfd_sym_contained_modules_table_entry *entry)
387 unsigned int type;
389 BFD_ASSERT (len == 6);
391 memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
392 type = bfd_getb16 (buf);
394 switch (type)
396 case BFD_SYM_END_OF_LIST_3_2:
397 entry->generic.type = BFD_SYM_END_OF_LIST;
398 break;
400 default:
401 entry->entry.mte_index = type;
402 entry->entry.nte_index = bfd_getb32 (buf + 2);
403 break;
407 void
408 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf,
409 size_t len,
410 bfd_sym_contained_variables_table_entry *entry)
412 unsigned int type;
414 BFD_ASSERT (len == 26);
416 memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
417 type = bfd_getb16 (buf);
419 switch (type)
421 case BFD_SYM_END_OF_LIST_3_2:
422 entry->generic.type = BFD_SYM_END_OF_LIST;
423 break;
425 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
426 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
427 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
428 break;
430 default:
431 entry->entry.tte_index = type;
432 entry->entry.nte_index = bfd_getb32 (buf + 2);
433 entry->entry.file_delta = bfd_getb16 (buf + 6);
434 entry->entry.scope = buf[8];
435 entry->entry.la_size = buf[9];
437 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
439 entry->entry.address.scstruct.sca_kind = buf[10];
440 entry->entry.address.scstruct.sca_class = buf[11];
441 entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12);
443 else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
445 #if BFD_SYM_CVTE_SCA > 0
446 memcpy (&entry->entry.address.lastruct.la, buf + 10,
447 BFD_SYM_CVTE_SCA);
448 #endif
449 entry->entry.address.lastruct.la_kind = buf[23];
451 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
453 entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
454 entry->entry.address.biglastruct.big_la_kind = buf[12];
459 void
460 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf,
461 size_t len,
462 bfd_sym_contained_statements_table_entry *entry)
464 unsigned int type;
466 BFD_ASSERT (len == 8);
468 memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
469 type = bfd_getb16 (buf);
471 switch (type)
473 case BFD_SYM_END_OF_LIST_3_2:
474 entry->generic.type = BFD_SYM_END_OF_LIST;
475 break;
477 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
478 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
479 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
480 break;
482 default:
483 entry->entry.mte_index = type;
484 entry->entry.mte_offset = bfd_getb16 (buf + 2);
485 entry->entry.file_delta = bfd_getb32 (buf + 4);
486 break;
490 void
491 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf,
492 size_t len,
493 bfd_sym_contained_labels_table_entry *entry)
495 unsigned int type;
497 BFD_ASSERT (len == 12);
499 memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
500 type = bfd_getb16 (buf);
502 switch (type)
504 case BFD_SYM_END_OF_LIST_3_2:
505 entry->generic.type = BFD_SYM_END_OF_LIST;
506 break;
508 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
509 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
510 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
511 break;
513 default:
514 entry->entry.mte_index = type;
515 entry->entry.mte_offset = bfd_getb16 (buf + 2);
516 entry->entry.nte_index = bfd_getb32 (buf + 4);
517 entry->entry.file_delta = bfd_getb16 (buf + 8);
518 entry->entry.scope = bfd_getb16 (buf + 10);
519 break;
523 void
524 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
525 size_t len,
526 bfd_sym_type_table_entry *entry)
528 BFD_ASSERT (len == 4);
530 *entry = bfd_getb32 (buf);
534 bfd_sym_fetch_resources_table_entry (bfd *abfd,
535 bfd_sym_resources_table_entry *entry,
536 unsigned long sym_index)
538 void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *);
539 unsigned long offset;
540 unsigned long entry_size;
541 unsigned char buf[18];
542 bfd_sym_data_struct *sdata = NULL;
544 parser = NULL;
545 BFD_ASSERT (bfd_sym_valid (abfd));
546 sdata = abfd->tdata.sym_data;
548 if (sym_index == 0)
549 return -1;
551 switch (sdata->version)
553 case BFD_SYM_VERSION_3_5:
554 case BFD_SYM_VERSION_3_4:
555 return -1;
557 case BFD_SYM_VERSION_3_3:
558 case BFD_SYM_VERSION_3_2:
559 entry_size = 18;
560 parser = bfd_sym_parse_resources_table_entry_v32;
561 break;
563 case BFD_SYM_VERSION_3_1:
564 default:
565 return -1;
567 if (parser == NULL)
568 return -1;
570 offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
571 sdata->header.dshb_page_size,
572 entry_size, sym_index);
574 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
575 return -1;
576 if (bfd_bread (buf, entry_size, abfd) != entry_size)
577 return -1;
579 (*parser) (buf, entry_size, entry);
581 return 0;
585 bfd_sym_fetch_modules_table_entry (bfd *abfd,
586 bfd_sym_modules_table_entry *entry,
587 unsigned long sym_index)
589 void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *);
590 unsigned long offset;
591 unsigned long entry_size;
592 unsigned char buf[46];
593 bfd_sym_data_struct *sdata = NULL;
595 parser = NULL;
596 BFD_ASSERT (bfd_sym_valid (abfd));
597 sdata = abfd->tdata.sym_data;
599 if (sym_index == 0)
600 return -1;
602 switch (sdata->version)
604 case BFD_SYM_VERSION_3_5:
605 case BFD_SYM_VERSION_3_4:
606 return -1;
608 case BFD_SYM_VERSION_3_3:
609 entry_size = 46;
610 parser = bfd_sym_parse_modules_table_entry_v33;
611 break;
613 case BFD_SYM_VERSION_3_2:
614 case BFD_SYM_VERSION_3_1:
615 default:
616 return -1;
618 if (parser == NULL)
619 return -1;
621 offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
622 sdata->header.dshb_page_size,
623 entry_size, sym_index);
625 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
626 return -1;
627 if (bfd_bread (buf, entry_size, abfd) != entry_size)
628 return -1;
630 (*parser) (buf, entry_size, entry);
632 return 0;
636 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
637 bfd_sym_file_references_table_entry *entry,
638 unsigned long sym_index)
640 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *);
641 unsigned long offset;
642 unsigned long entry_size = 0;
643 unsigned char buf[8];
644 bfd_sym_data_struct *sdata = NULL;
646 parser = NULL;
647 BFD_ASSERT (bfd_sym_valid (abfd));
648 sdata = abfd->tdata.sym_data;
650 if (sym_index == 0)
651 return -1;
653 switch (sdata->version)
655 case BFD_SYM_VERSION_3_3:
656 case BFD_SYM_VERSION_3_2:
657 entry_size = 10;
658 parser = bfd_sym_parse_file_references_table_entry_v32;
659 break;
661 case BFD_SYM_VERSION_3_5:
662 case BFD_SYM_VERSION_3_4:
663 case BFD_SYM_VERSION_3_1:
664 default:
665 break;
668 if (parser == NULL)
669 return -1;
671 offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
672 sdata->header.dshb_page_size,
673 entry_size, sym_index);
675 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
676 return -1;
677 if (bfd_bread (buf, entry_size, abfd) != entry_size)
678 return -1;
680 (*parser) (buf, entry_size, entry);
682 return 0;
686 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
687 bfd_sym_contained_modules_table_entry *entry,
688 unsigned long sym_index)
690 void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *);
691 unsigned long offset;
692 unsigned long entry_size = 0;
693 unsigned char buf[6];
694 bfd_sym_data_struct *sdata = NULL;
696 parser = NULL;
697 BFD_ASSERT (bfd_sym_valid (abfd));
698 sdata = abfd->tdata.sym_data;
700 if (sym_index == 0)
701 return -1;
703 switch (sdata->version)
705 case BFD_SYM_VERSION_3_3:
706 case BFD_SYM_VERSION_3_2:
707 entry_size = 6;
708 parser = bfd_sym_parse_contained_modules_table_entry_v32;
709 break;
711 case BFD_SYM_VERSION_3_5:
712 case BFD_SYM_VERSION_3_4:
713 case BFD_SYM_VERSION_3_1:
714 default:
715 break;
718 if (parser == NULL)
719 return -1;
721 offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
722 sdata->header.dshb_page_size,
723 entry_size, sym_index);
725 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
726 return -1;
727 if (bfd_bread (buf, entry_size, abfd) != entry_size)
728 return -1;
730 (*parser) (buf, entry_size, entry);
732 return 0;
736 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
737 bfd_sym_contained_variables_table_entry *entry,
738 unsigned long sym_index)
740 void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *);
741 unsigned long offset;
742 unsigned long entry_size = 0;
743 unsigned char buf[26];
744 bfd_sym_data_struct *sdata = NULL;
746 parser = NULL;
747 BFD_ASSERT (bfd_sym_valid (abfd));
748 sdata = abfd->tdata.sym_data;
750 if (sym_index == 0)
751 return -1;
753 switch (sdata->version)
755 case BFD_SYM_VERSION_3_3:
756 case BFD_SYM_VERSION_3_2:
757 entry_size = 26;
758 parser = bfd_sym_parse_contained_variables_table_entry_v32;
759 break;
761 case BFD_SYM_VERSION_3_5:
762 case BFD_SYM_VERSION_3_4:
763 case BFD_SYM_VERSION_3_1:
764 default:
765 break;
768 if (parser == NULL)
769 return -1;
771 offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
772 sdata->header.dshb_page_size,
773 entry_size, sym_index);
775 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
776 return -1;
777 if (bfd_bread (buf, entry_size, abfd) != entry_size)
778 return -1;
780 (*parser) (buf, entry_size, entry);
782 return 0;
786 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
787 bfd_sym_contained_statements_table_entry *entry,
788 unsigned long sym_index)
790 void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *);
791 unsigned long offset;
792 unsigned long entry_size = 0;
793 unsigned char buf[8];
794 bfd_sym_data_struct *sdata = NULL;
796 parser = NULL;
797 BFD_ASSERT (bfd_sym_valid (abfd));
798 sdata = abfd->tdata.sym_data;
800 if (sym_index == 0)
801 return -1;
803 switch (sdata->version)
805 case BFD_SYM_VERSION_3_3:
806 case BFD_SYM_VERSION_3_2:
807 entry_size = 8;
808 parser = bfd_sym_parse_contained_statements_table_entry_v32;
809 break;
811 case BFD_SYM_VERSION_3_5:
812 case BFD_SYM_VERSION_3_4:
813 case BFD_SYM_VERSION_3_1:
814 default:
815 break;
818 if (parser == NULL)
819 return -1;
821 offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
822 sdata->header.dshb_page_size,
823 entry_size, sym_index);
825 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
826 return -1;
827 if (bfd_bread (buf, entry_size, abfd) != entry_size)
828 return -1;
830 (*parser) (buf, entry_size, entry);
832 return 0;
836 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
837 bfd_sym_contained_labels_table_entry *entry,
838 unsigned long sym_index)
840 void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *);
841 unsigned long offset;
842 unsigned long entry_size = 0;
843 unsigned char buf[12];
844 bfd_sym_data_struct *sdata = NULL;
846 parser = NULL;
847 BFD_ASSERT (bfd_sym_valid (abfd));
848 sdata = abfd->tdata.sym_data;
850 if (sym_index == 0)
851 return -1;
853 switch (sdata->version)
855 case BFD_SYM_VERSION_3_3:
856 case BFD_SYM_VERSION_3_2:
857 entry_size = 12;
858 parser = bfd_sym_parse_contained_labels_table_entry_v32;
859 break;
861 case BFD_SYM_VERSION_3_5:
862 case BFD_SYM_VERSION_3_4:
863 case BFD_SYM_VERSION_3_1:
864 default:
865 break;
868 if (parser == NULL)
869 return -1;
871 offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
872 sdata->header.dshb_page_size,
873 entry_size, sym_index);
875 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
876 return -1;
877 if (bfd_bread (buf, entry_size, abfd) != entry_size)
878 return -1;
880 (*parser) (buf, entry_size, entry);
882 return 0;
886 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
887 bfd_sym_contained_types_table_entry *entry,
888 unsigned long sym_index)
890 void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *);
891 unsigned long offset;
892 unsigned long entry_size = 0;
893 unsigned char buf[0];
894 bfd_sym_data_struct *sdata = NULL;
896 parser = NULL;
897 BFD_ASSERT (bfd_sym_valid (abfd));
898 sdata = abfd->tdata.sym_data;
900 if (sym_index == 0)
901 return -1;
903 switch (sdata->version)
905 case BFD_SYM_VERSION_3_3:
906 case BFD_SYM_VERSION_3_2:
907 entry_size = 0;
908 parser = NULL;
909 break;
911 case BFD_SYM_VERSION_3_5:
912 case BFD_SYM_VERSION_3_4:
913 case BFD_SYM_VERSION_3_1:
914 default:
915 break;
918 if (parser == NULL)
919 return -1;
921 offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
922 sdata->header.dshb_page_size,
923 entry_size, sym_index);
925 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
926 return -1;
927 if (bfd_bread (buf, entry_size, abfd) != entry_size)
928 return -1;
930 (*parser) (buf, entry_size, entry);
932 return 0;
936 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
937 bfd_sym_file_references_index_table_entry *entry,
938 unsigned long sym_index)
940 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *);
941 unsigned long offset;
942 unsigned long entry_size = 0;
943 unsigned char buf[0];
944 bfd_sym_data_struct *sdata = NULL;
946 parser = NULL;
947 BFD_ASSERT (bfd_sym_valid (abfd));
948 sdata = abfd->tdata.sym_data;
950 if (sym_index == 0)
951 return -1;
953 switch (sdata->version)
955 case BFD_SYM_VERSION_3_3:
956 case BFD_SYM_VERSION_3_2:
957 entry_size = 0;
958 parser = NULL;
959 break;
961 case BFD_SYM_VERSION_3_5:
962 case BFD_SYM_VERSION_3_4:
963 case BFD_SYM_VERSION_3_1:
964 default:
965 break;
968 if (parser == NULL)
969 return -1;
971 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
972 sdata->header.dshb_page_size,
973 entry_size, sym_index);
975 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
976 return -1;
977 if (bfd_bread (buf, entry_size, abfd) != entry_size)
978 return -1;
980 (*parser) (buf, entry_size, entry);
982 return 0;
986 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
987 bfd_sym_constant_pool_entry *entry,
988 unsigned long sym_index)
990 void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *);
991 unsigned long offset;
992 unsigned long entry_size = 0;
993 unsigned char buf[0];
994 bfd_sym_data_struct *sdata = NULL;
996 parser = NULL;
997 BFD_ASSERT (bfd_sym_valid (abfd));
998 sdata = abfd->tdata.sym_data;
1000 if (sym_index == 0)
1001 return -1;
1003 switch (sdata->version)
1005 case BFD_SYM_VERSION_3_3:
1006 case BFD_SYM_VERSION_3_2:
1007 entry_size = 0;
1008 parser = NULL;
1009 break;
1011 case BFD_SYM_VERSION_3_5:
1012 case BFD_SYM_VERSION_3_4:
1013 case BFD_SYM_VERSION_3_1:
1014 default:
1015 break;
1018 if (parser == NULL)
1019 return -1;
1021 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1022 sdata->header.dshb_page_size,
1023 entry_size, sym_index);
1025 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1026 return -1;
1027 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1028 return -1;
1030 (*parser) (buf, entry_size, entry);
1032 return 0;
1036 bfd_sym_fetch_type_table_entry (bfd *abfd,
1037 bfd_sym_type_table_entry *entry,
1038 unsigned long sym_index)
1040 void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *);
1041 unsigned long offset;
1042 unsigned long entry_size = 0;
1043 unsigned char buf[4];
1044 bfd_sym_data_struct *sdata = NULL;
1046 parser = NULL;
1047 BFD_ASSERT (bfd_sym_valid (abfd));
1048 sdata = abfd->tdata.sym_data;
1050 switch (sdata->version)
1052 case BFD_SYM_VERSION_3_3:
1053 case BFD_SYM_VERSION_3_2:
1054 entry_size = 4;
1055 parser = bfd_sym_parse_type_table_entry_v32;
1056 break;
1058 case BFD_SYM_VERSION_3_5:
1059 case BFD_SYM_VERSION_3_4:
1060 case BFD_SYM_VERSION_3_1:
1061 default:
1062 break;
1065 if (parser == NULL)
1066 return -1;
1068 offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
1069 sdata->header.dshb_page_size,
1070 entry_size, sym_index);
1072 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1073 return -1;
1074 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1075 return -1;
1077 (*parser) (buf, entry_size, entry);
1079 return 0;
1083 bfd_sym_fetch_type_information_table_entry (bfd *abfd,
1084 bfd_sym_type_information_table_entry *entry,
1085 unsigned long offset)
1087 unsigned char buf[4];
1089 BFD_ASSERT (bfd_sym_valid (abfd));
1091 if (offset == 0)
1092 return -1;
1094 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1095 return -1;
1097 if (bfd_bread (buf, 4, abfd) != 4)
1098 return -1;
1099 entry->nte_index = bfd_getb32 (buf);
1101 if (bfd_bread (buf, 2, abfd) != 2)
1102 return -1;
1103 entry->physical_size = bfd_getb16 (buf);
1105 if (entry->physical_size & 0x8000)
1107 if (bfd_bread (buf, 4, abfd) != 4)
1108 return -1;
1109 entry->physical_size &= 0x7fff;
1110 entry->logical_size = bfd_getb32 (buf);
1111 entry->offset = offset + 10;
1113 else
1115 if (bfd_bread (buf, 2, abfd) != 2)
1116 return -1;
1117 entry->physical_size &= 0x7fff;
1118 entry->logical_size = bfd_getb16 (buf);
1119 entry->offset = offset + 8;
1122 return 0;
1126 bfd_sym_fetch_type_table_information (bfd *abfd,
1127 bfd_sym_type_information_table_entry *entry,
1128 unsigned long sym_index)
1130 bfd_sym_type_table_entry tindex;
1131 bfd_sym_data_struct *sdata = NULL;
1133 BFD_ASSERT (bfd_sym_valid (abfd));
1134 sdata = abfd->tdata.sym_data;
1136 if (sdata->header.dshb_tte.dti_object_count <= 99)
1137 return -1;
1138 if (sym_index < 100)
1139 return -1;
1141 if (bfd_sym_fetch_type_table_entry (abfd, &tindex, sym_index - 100) < 0)
1142 return -1;
1143 if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
1144 return -1;
1146 return 0;
1149 const unsigned char *
1150 bfd_sym_symbol_name (bfd *abfd, unsigned long sym_index)
1152 bfd_sym_data_struct *sdata = NULL;
1154 BFD_ASSERT (bfd_sym_valid (abfd));
1155 sdata = abfd->tdata.sym_data;
1157 if (sym_index == 0)
1158 return (const unsigned char *) "";
1160 sym_index *= 2;
1161 if ((sym_index / sdata->header.dshb_page_size)
1162 > sdata->header.dshb_nte.dti_page_count)
1163 return (const unsigned char *) "\09[INVALID]";
1165 return (const unsigned char *) sdata->name_table + sym_index;
1168 const unsigned char *
1169 bfd_sym_module_name (bfd *abfd, unsigned long sym_index)
1171 bfd_sym_modules_table_entry entry;
1173 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, sym_index) < 0)
1174 return (const unsigned char *) "\09[INVALID]";
1176 return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
1179 const char *
1180 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind)
1182 switch (kind)
1184 case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL";
1185 case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE";
1186 case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE";
1187 case BFD_SYM_STORAGE_KIND_WITH: return "WITH";
1188 default: return "[UNKNOWN]";
1192 const char *
1193 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind)
1195 switch (kind)
1197 case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER";
1198 case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL";
1199 case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE";
1200 case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE";
1201 case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE";
1202 case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT";
1203 case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE";
1204 case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT";
1205 default: return "[UNKNOWN]";
1209 const char *
1210 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind)
1212 switch (kind)
1214 case BFD_SYM_MODULE_KIND_NONE: return "NONE";
1215 case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM";
1216 case BFD_SYM_MODULE_KIND_UNIT: return "UNIT";
1217 case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE";
1218 case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION";
1219 case BFD_SYM_MODULE_KIND_DATA: return "DATA";
1220 case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK";
1221 default: return "[UNKNOWN]";
1225 const char *
1226 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope)
1228 switch (scope)
1230 case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
1231 case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
1232 default:
1233 return "[UNKNOWN]";
1237 void
1238 bfd_sym_print_file_reference (bfd *abfd,
1239 FILE *f,
1240 bfd_sym_file_reference *entry)
1242 bfd_sym_file_references_table_entry frtentry;
1243 int ret;
1245 ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
1246 entry->fref_frte_index);
1247 fprintf (f, "FILE ");
1249 if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
1250 fprintf (f, "[INVALID]");
1251 else
1252 fprintf (f, "\"%.*s\"",
1253 bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0],
1254 &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]);
1256 fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
1259 void
1260 bfd_sym_print_resources_table_entry (bfd *abfd,
1261 FILE *f,
1262 bfd_sym_resources_table_entry *entry)
1264 fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu",
1265 bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0],
1266 &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1],
1267 entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number,
1268 entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last);
1271 void
1272 bfd_sym_print_modules_table_entry (bfd *abfd,
1273 FILE *f,
1274 bfd_sym_modules_table_entry *entry)
1276 fprintf (f, "\"%.*s\" (NTE %lu)",
1277 bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0],
1278 &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1],
1279 entry->mte_nte_index);
1281 fprintf (f, "\n ");
1283 bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref);
1284 fprintf (f, " range %lu -- %lu",
1285 entry->mte_imp_fref.fref_offset, entry->mte_imp_end);
1287 fprintf (f, "\n ");
1289 fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind));
1290 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope));
1292 fprintf (f, ", RTE %lu, offset %lu, size %lu",
1293 entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
1295 fprintf (f, "\n ");
1297 fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu",
1298 entry->mte_cmte_index, entry->mte_cvte_index,
1299 entry->mte_clte_index, entry->mte_ctte_index,
1300 entry->mte_csnte_idx_1, entry->mte_csnte_idx_2);
1302 if (entry->mte_parent != 0)
1303 fprintf (f, ", parent %lu", entry->mte_parent);
1304 else
1305 fprintf (f, ", no parent");
1307 if (entry->mte_cmte_index != 0)
1308 fprintf (f, ", child %lu", entry->mte_cmte_index);
1309 else
1310 fprintf (f, ", no child");
1313 void
1314 bfd_sym_print_file_references_table_entry (bfd *abfd,
1315 FILE *f,
1316 bfd_sym_file_references_table_entry *entry)
1318 switch (entry->generic.type)
1320 case BFD_SYM_FILE_NAME_INDEX:
1321 fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ",
1322 bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0],
1323 &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1],
1324 entry->filename.nte_index);
1326 fprintf (f, "[UNIMPLEMENTED]");
1327 /* printModDate (entry->filename.mod_date); */
1328 fprintf (f, " (0x%lx)", entry->filename.mod_date);
1329 break;
1331 case BFD_SYM_END_OF_LIST:
1332 fprintf (f, "END");
1333 break;
1335 default:
1336 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu",
1337 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1338 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1339 entry->entry.mte_index,
1340 entry->entry.file_offset);
1341 break;
1345 void
1346 bfd_sym_print_contained_modules_table_entry (bfd *abfd,
1347 FILE *f,
1348 bfd_sym_contained_modules_table_entry *entry)
1350 switch (entry->generic.type)
1352 case BFD_SYM_END_OF_LIST:
1353 fprintf (f, "END");
1354 break;
1356 default:
1357 fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)",
1358 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1359 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1360 entry->entry.mte_index,
1361 entry->entry.nte_index);
1362 break;
1366 void
1367 bfd_sym_print_contained_variables_table_entry (bfd *abfd,
1368 FILE *f,
1369 bfd_sym_contained_variables_table_entry *entry)
1371 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1373 fprintf (f, "END");
1374 return;
1377 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1379 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1380 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1381 return;
1384 fprintf (f, "\"%.*s\" (NTE %lu)",
1385 bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0],
1386 &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1],
1387 entry->entry.nte_index);
1389 fprintf (f, ", TTE %lu", entry->entry.tte_index);
1390 fprintf (f, ", offset %lu", entry->entry.file_delta);
1391 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope));
1393 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
1394 fprintf (f, ", latype %s, laclass %s, laoffset %lu",
1395 bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind),
1396 bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class),
1397 entry->entry.address.scstruct.sca_offset);
1398 else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE)
1400 unsigned long i;
1402 fprintf (f, ", la [");
1403 for (i = 0; i < entry->entry.la_size; i++)
1404 fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]);
1405 fprintf (f, "]");
1407 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
1408 fprintf (f, ", bigla %lu, biglakind %u",
1409 entry->entry.address.biglastruct.big_la,
1410 entry->entry.address.biglastruct.big_la_kind);
1412 else
1413 fprintf (f, ", la [INVALID]");
1416 void
1417 bfd_sym_print_contained_statements_table_entry (bfd *abfd,
1418 FILE *f,
1419 bfd_sym_contained_statements_table_entry *entry)
1421 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1423 fprintf (f, "END");
1424 return;
1427 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1429 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1430 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1431 return;
1434 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu",
1435 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1436 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1437 entry->entry.mte_index,
1438 entry->entry.mte_offset,
1439 entry->entry.file_delta);
1442 void
1443 bfd_sym_print_contained_labels_table_entry (bfd *abfd,
1444 FILE *f,
1445 bfd_sym_contained_labels_table_entry *entry)
1447 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1449 fprintf (f, "END");
1450 return;
1453 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1455 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1456 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1457 return;
1460 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s",
1461 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1462 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1463 entry->entry.mte_index,
1464 entry->entry.mte_offset,
1465 entry->entry.file_delta,
1466 bfd_sym_unparse_symbol_scope (entry->entry.scope));
1469 void
1470 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1471 FILE *f,
1472 bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED)
1474 fprintf (f, "[UNIMPLEMENTED]");
1477 const char *
1478 bfd_sym_type_operator_name (unsigned char num)
1480 switch (num)
1482 case 1: return "TTE";
1483 case 2: return "PointerTo";
1484 case 3: return "ScalarOf";
1485 case 4: return "ConstantOf";
1486 case 5: return "EnumerationOf";
1487 case 6: return "VectorOf";
1488 case 7: return "RecordOf";
1489 case 8: return "UnionOf";
1490 case 9: return "SubRangeOf";
1491 case 10: return "SetOf";
1492 case 11: return "NamedTypeOf";
1493 case 12: return "ProcOf";
1494 case 13: return "ValueOf";
1495 case 14: return "ArrayOf";
1496 default: return "[UNKNOWN OPERATOR]";
1500 const char *
1501 bfd_sym_type_basic_name (unsigned char num)
1503 switch (num)
1505 case 0: return "void";
1506 case 1: return "pascal string";
1507 case 2: return "unsigned long";
1508 case 3: return "signed long";
1509 case 4: return "extended (10 bytes)";
1510 case 5: return "pascal boolean (1 byte)";
1511 case 6: return "unsigned byte";
1512 case 7: return "signed byte";
1513 case 8: return "character (1 byte)";
1514 case 9: return "wide character (2 bytes)";
1515 case 10: return "unsigned short";
1516 case 11: return "signed short";
1517 case 12: return "singled";
1518 case 13: return "double";
1519 case 14: return "extended (12 bytes)";
1520 case 15: return "computational (8 bytes)";
1521 case 16: return "c string";
1522 case 17: return "as-is string";
1523 default: return "[UNKNOWN BASIC TYPE]";
1528 bfd_sym_fetch_long (unsigned char *buf,
1529 unsigned long len,
1530 unsigned long offset,
1531 unsigned long *offsetptr,
1532 long *value)
1534 int ret;
1536 if (offset >= len)
1538 *value = 0;
1539 offset += 0;
1540 ret = -1;
1542 else if (! (buf[offset] & 0x80))
1544 *value = buf[offset];
1545 offset += 1;
1546 ret = 0;
1548 else if (buf[offset] == 0xc0)
1550 if ((offset + 5) > len)
1552 *value = 0;
1553 offset = len;
1554 ret = -1;
1556 else
1558 *value = bfd_getb32 (buf + offset + 1);
1559 offset += 5;
1560 ret = 0;
1563 else if ((buf[offset] & 0xc0) == 0xc0)
1565 *value = -(buf[offset] & 0x3f);
1566 offset += 1;
1567 ret = 0;
1569 else if ((buf[offset] & 0xc0) == 0x80)
1571 if ((offset + 2) > len)
1573 *value = 0;
1574 offset = len;
1575 ret = -1;
1577 else
1579 *value = bfd_getb16 (buf + offset) & 0x3fff;
1580 offset += 2;
1581 ret = 0;
1584 else
1585 abort ();
1587 if (offsetptr != NULL)
1588 *offsetptr = offset;
1590 return ret;
1593 void
1594 bfd_sym_print_type_information (bfd *abfd,
1595 FILE *f,
1596 unsigned char *buf,
1597 unsigned long len,
1598 unsigned long offset,
1599 unsigned long *offsetptr)
1601 unsigned int type;
1603 if (offset >= len)
1605 fprintf (f, "[NULL]");
1607 if (offsetptr != NULL)
1608 *offsetptr = offset;
1609 return;
1612 type = buf[offset];
1613 offset++;
1615 if (! (type & 0x80))
1617 fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
1619 if (offsetptr != NULL)
1620 *offsetptr = offset;
1621 return;
1624 if (type & 0x40)
1625 fprintf (f, "[packed ");
1626 else
1627 fprintf (f, "[");
1629 switch (type & 0x3f)
1631 case 1:
1633 long value;
1634 bfd_sym_type_information_table_entry tinfo;
1636 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1637 if (value <= 0)
1638 fprintf (f, "[INVALID]");
1639 else
1641 if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
1642 fprintf (f, "[INVALID]");
1643 else
1644 fprintf (f, "\"%.*s\"",
1645 bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
1646 &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
1648 fprintf (f, " (TTE %lu)", (unsigned long) value);
1649 break;
1652 case 2:
1653 fprintf (f, "pointer (0x%x) to ", type);
1654 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1655 break;
1657 case 3:
1659 long value;
1661 fprintf (f, "scalar (0x%x) of ", type);
1662 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1663 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1664 fprintf (f, " (%lu)", (unsigned long) value);
1665 break;
1668 case 5:
1670 long lower, upper, nelem;
1671 int i;
1673 fprintf (f, "enumeration (0x%x) of ", type);
1674 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1675 bfd_sym_fetch_long (buf, len, offset, &offset, &lower);
1676 bfd_sym_fetch_long (buf, len, offset, &offset, &upper);
1677 bfd_sym_fetch_long (buf, len, offset, &offset, &nelem);
1678 fprintf (f, " from %lu to %lu with %lu elements: ",
1679 (unsigned long) lower, (unsigned long) upper,
1680 (unsigned long) nelem);
1682 for (i = 0; i < nelem; i++)
1684 fprintf (f, "\n ");
1685 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1687 break;
1690 case 6:
1691 fprintf (f, "vector (0x%x)", type);
1692 fprintf (f, "\n index ");
1693 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1694 fprintf (f, "\n target ");
1695 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1696 break;
1698 case 7:
1699 case 8:
1701 long nrec, eloff, i;
1703 if ((type & 0x3f) == 7)
1704 fprintf (f, "record (0x%x) of ", type);
1705 else
1706 fprintf (f, "union (0x%x) of ", type);
1708 bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
1709 fprintf (f, "%lu elements: ", (unsigned long) nrec);
1711 for (i = 0; i < nrec; i++)
1713 bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
1714 fprintf (f, "\n ");
1715 fprintf (f, "offset %lu: ", (unsigned long) eloff);
1716 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1718 break;
1721 case 9:
1722 fprintf (f, "subrange (0x%x) of ", type);
1723 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1724 fprintf (f, " lower ");
1725 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1726 fprintf (f, " upper ");
1727 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1728 break;
1730 case 11:
1732 long value;
1734 fprintf (f, "named type (0x%x) ", type);
1735 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1736 if (value <= 0)
1737 fprintf (f, "[INVALID]");
1738 else
1739 fprintf (f, "\"%.*s\"",
1740 bfd_sym_symbol_name (abfd, value)[0],
1741 &bfd_sym_symbol_name (abfd, value)[1]);
1743 fprintf (f, " (NTE %lu) with type ", (unsigned long) value);
1744 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1745 break;
1748 default:
1749 fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
1750 break;
1753 if (type == (0x40 | 0x6))
1755 /* Vector. */
1756 long n, width, m;
1757 long l;
1758 long i;
1760 bfd_sym_fetch_long (buf, len, offset, &offset, &n);
1761 bfd_sym_fetch_long (buf, len, offset, &offset, &width);
1762 bfd_sym_fetch_long (buf, len, offset, &offset, &m);
1763 /* fprintf (f, "\n "); */
1764 fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m);
1765 for (i = 0; i < m; i++)
1767 bfd_sym_fetch_long (buf, len, offset, &offset, &l);
1768 if (i != 0)
1769 fprintf (f, " ");
1770 fprintf (f, "%ld", l);
1773 else if (type & 0x40)
1775 /* Other packed type. */
1776 long msb, lsb;
1778 bfd_sym_fetch_long (buf, len, offset, &offset, &msb);
1779 bfd_sym_fetch_long (buf, len, offset, &offset, &lsb);
1780 /* fprintf (f, "\n "); */
1781 fprintf (f, " msb %ld, lsb %ld", msb, lsb);
1784 fprintf (f, "]");
1786 if (offsetptr != NULL)
1787 *offsetptr = offset;
1790 void
1791 bfd_sym_print_type_information_table_entry (bfd *abfd,
1792 FILE *f,
1793 bfd_sym_type_information_table_entry *entry)
1795 unsigned char *buf;
1796 unsigned long offset;
1797 unsigned int i;
1799 fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu",
1800 bfd_sym_symbol_name (abfd, entry->nte_index)[0],
1801 &bfd_sym_symbol_name (abfd, entry->nte_index)[1],
1802 entry->nte_index,
1803 entry->physical_size, entry->offset, entry->logical_size);
1805 fprintf (f, "\n ");
1807 buf = alloca (entry->physical_size);
1808 if (buf == NULL)
1810 fprintf (f, "[ERROR]\n");
1811 return;
1813 if (bfd_seek (abfd, entry->offset, SEEK_SET) < 0)
1815 fprintf (f, "[ERROR]\n");
1816 return;
1818 if (bfd_bread (buf, entry->physical_size, abfd) != entry->physical_size)
1820 fprintf (f, "[ERROR]\n");
1821 return;
1824 fprintf (f, "[");
1825 for (i = 0; i < entry->physical_size; i++)
1827 if (i == 0)
1828 fprintf (f, "0x%02x", buf[i]);
1829 else
1830 fprintf (f, " 0x%02x", buf[i]);
1833 fprintf (f, "]");
1834 fprintf (f, "\n ");
1836 bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
1838 if (offset != entry->physical_size)
1839 fprintf (f, "\n [parser used %lu bytes instead of %lu]", offset, entry->physical_size);
1842 void
1843 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1844 FILE *f,
1845 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED)
1847 fprintf (f, "[UNIMPLEMENTED]");
1850 void
1851 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED,
1852 FILE *f,
1853 bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED)
1855 fprintf (f, "[UNIMPLEMENTED]");
1858 unsigned char *
1859 bfd_sym_display_name_table_entry (bfd *abfd,
1860 FILE *f,
1861 unsigned char *entry)
1863 unsigned long sym_index;
1864 unsigned long offset;
1865 bfd_sym_data_struct *sdata = NULL;
1867 BFD_ASSERT (bfd_sym_valid (abfd));
1868 sdata = abfd->tdata.sym_data;
1869 sym_index = (entry - sdata->name_table) / 2;
1871 if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
1873 unsigned short length = bfd_getb16 (entry + 2);
1874 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, length, entry + 4);
1875 offset = 2 + length + 1;
1877 else
1879 if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
1880 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, entry[0], entry + 1);
1882 if (sdata->version >= BFD_SYM_VERSION_3_4)
1883 offset = entry[0] + 2;
1884 else
1885 offset = entry[0] + 1;
1888 return (entry + offset + (offset % 2));
1891 void
1892 bfd_sym_display_name_table (bfd *abfd, FILE *f)
1894 unsigned long name_table_len;
1895 unsigned char *name_table, *name_table_end, *cur;
1896 bfd_sym_data_struct *sdata = NULL;
1898 BFD_ASSERT (bfd_sym_valid (abfd));
1899 sdata = abfd->tdata.sym_data;
1901 name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size;
1902 name_table = sdata->name_table;
1903 name_table_end = name_table + name_table_len;
1905 fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
1907 cur = name_table;
1908 for (;;)
1910 cur = bfd_sym_display_name_table_entry (abfd, f, cur);
1911 if (cur >= name_table_end)
1912 break;
1916 void
1917 bfd_sym_display_resources_table (bfd *abfd, FILE *f)
1919 unsigned long i;
1920 bfd_sym_resources_table_entry entry;
1921 bfd_sym_data_struct *sdata = NULL;
1923 BFD_ASSERT (bfd_sym_valid (abfd));
1924 sdata = abfd->tdata.sym_data;
1926 fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
1927 sdata->header.dshb_rte.dti_object_count);
1929 for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
1931 if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
1932 fprintf (f, " [%8lu] [INVALID]\n", i);
1933 else
1935 fprintf (f, " [%8lu] ", i);
1936 bfd_sym_print_resources_table_entry (abfd, f, &entry);
1937 fprintf (f, "\n");
1942 void
1943 bfd_sym_display_modules_table (bfd *abfd, FILE *f)
1945 unsigned long i;
1946 bfd_sym_modules_table_entry entry;
1947 bfd_sym_data_struct *sdata = NULL;
1949 BFD_ASSERT (bfd_sym_valid (abfd));
1950 sdata = abfd->tdata.sym_data;
1952 fprintf (f, "module table (MTE) contains %lu objects:\n\n",
1953 sdata->header.dshb_mte.dti_object_count);
1955 for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
1957 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
1958 fprintf (f, " [%8lu] [INVALID]\n", i);
1959 else
1961 fprintf (f, " [%8lu] ", i);
1962 bfd_sym_print_modules_table_entry (abfd, f, &entry);
1963 fprintf (f, "\n");
1968 void
1969 bfd_sym_display_file_references_table (bfd *abfd, FILE *f)
1971 unsigned long i;
1972 bfd_sym_file_references_table_entry entry;
1973 bfd_sym_data_struct *sdata = NULL;
1975 BFD_ASSERT (bfd_sym_valid (abfd));
1976 sdata = abfd->tdata.sym_data;
1978 fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
1979 sdata->header.dshb_frte.dti_object_count);
1981 for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
1983 if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
1984 fprintf (f, " [%8lu] [INVALID]\n", i);
1985 else
1987 fprintf (f, " [%8lu] ", i);
1988 bfd_sym_print_file_references_table_entry (abfd, f, &entry);
1989 fprintf (f, "\n");
1994 void
1995 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f)
1997 unsigned long i;
1998 bfd_sym_contained_modules_table_entry entry;
1999 bfd_sym_data_struct *sdata = NULL;
2001 BFD_ASSERT (bfd_sym_valid (abfd));
2002 sdata = abfd->tdata.sym_data;
2004 fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
2005 sdata->header.dshb_cmte.dti_object_count);
2007 for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
2009 if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
2010 fprintf (f, " [%8lu] [INVALID]\n", i);
2011 else
2013 fprintf (f, " [%8lu] ", i);
2014 bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
2015 fprintf (f, "\n");
2020 void
2021 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f)
2023 unsigned long i;
2024 bfd_sym_contained_variables_table_entry entry;
2025 bfd_sym_data_struct *sdata = NULL;
2027 BFD_ASSERT (bfd_sym_valid (abfd));
2028 sdata = abfd->tdata.sym_data;
2030 fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
2031 sdata->header.dshb_cvte.dti_object_count);
2033 for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
2035 if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
2036 fprintf (f, " [%8lu] [INVALID]\n", i);
2037 else
2039 fprintf (f, " [%8lu] ", i);
2040 bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
2041 fprintf (f, "\n");
2045 fprintf (f, "\n");
2048 void
2049 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f)
2051 unsigned long i;
2052 bfd_sym_contained_statements_table_entry entry;
2053 bfd_sym_data_struct *sdata = NULL;
2055 BFD_ASSERT (bfd_sym_valid (abfd));
2056 sdata = abfd->tdata.sym_data;
2058 fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
2059 sdata->header.dshb_csnte.dti_object_count);
2061 for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
2063 if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
2064 fprintf (f, " [%8lu] [INVALID]\n", i);
2065 else
2067 fprintf (f, " [%8lu] ", i);
2068 bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
2069 fprintf (f, "\n");
2074 void
2075 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f)
2077 unsigned long i;
2078 bfd_sym_contained_labels_table_entry entry;
2079 bfd_sym_data_struct *sdata = NULL;
2081 BFD_ASSERT (bfd_sym_valid (abfd));
2082 sdata = abfd->tdata.sym_data;
2084 fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
2085 sdata->header.dshb_clte.dti_object_count);
2087 for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
2089 if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
2090 fprintf (f, " [%8lu] [INVALID]\n", i);
2091 else
2093 fprintf (f, " [%8lu] ", i);
2094 bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
2095 fprintf (f, "\n");
2100 void
2101 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f)
2103 unsigned long i;
2104 bfd_sym_contained_types_table_entry entry;
2105 bfd_sym_data_struct *sdata = NULL;
2107 BFD_ASSERT (bfd_sym_valid (abfd));
2108 sdata = abfd->tdata.sym_data;
2110 fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
2111 sdata->header.dshb_ctte.dti_object_count);
2113 for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
2115 if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
2116 fprintf (f, " [%8lu] [INVALID]\n", i);
2117 else
2119 fprintf (f, " [%8lu] ", i);
2120 bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
2121 fprintf (f, "\n");
2126 void
2127 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f)
2129 unsigned long i;
2130 bfd_sym_file_references_index_table_entry entry;
2131 bfd_sym_data_struct *sdata = NULL;
2133 BFD_ASSERT (bfd_sym_valid (abfd));
2134 sdata = abfd->tdata.sym_data;
2136 fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
2137 sdata->header.dshb_fite.dti_object_count);
2139 for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
2141 if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
2142 fprintf (f, " [%8lu] [INVALID]\n", i);
2143 else
2145 fprintf (f, " [%8lu] ", i);
2146 bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
2147 fprintf (f, "\n");
2152 void
2153 bfd_sym_display_constant_pool (bfd *abfd, FILE *f)
2155 unsigned long i;
2156 bfd_sym_constant_pool_entry entry;
2157 bfd_sym_data_struct *sdata = NULL;
2159 BFD_ASSERT (bfd_sym_valid (abfd));
2160 sdata = abfd->tdata.sym_data;
2162 fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
2163 sdata->header.dshb_const.dti_object_count);
2165 for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
2167 if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
2168 fprintf (f, " [%8lu] [INVALID]\n", i);
2169 else
2171 fprintf (f, " [%8lu] ", i);
2172 bfd_sym_print_constant_pool_entry (abfd, f, &entry);
2173 fprintf (f, "\n");
2178 void
2179 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
2181 unsigned long i;
2182 bfd_sym_type_table_entry sym_index;
2183 bfd_sym_type_information_table_entry entry;
2184 bfd_sym_data_struct *sdata = NULL;
2186 BFD_ASSERT (bfd_sym_valid (abfd));
2187 sdata = abfd->tdata.sym_data;
2189 if (sdata->header.dshb_tte.dti_object_count > 99)
2190 fprintf (f, "type table (TINFO) contains %lu objects:\n\n",
2191 sdata->header.dshb_tte.dti_object_count - 99);
2192 else
2194 fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
2195 return;
2198 for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
2200 if (bfd_sym_fetch_type_table_entry (abfd, &sym_index, i - 100) < 0)
2201 fprintf (f, " [%8lu] [INVALID]\n", i);
2202 else
2204 fprintf (f, " [%8lu] (TINFO %lu) ", i, sym_index);
2206 if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, sym_index) < 0)
2207 fprintf (f, "[INVALID]");
2208 else
2209 bfd_sym_print_type_information_table_entry (abfd, f, &entry);
2211 fprintf (f, "\n");
2217 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
2219 asection *bfdsec;
2220 const char *name = "symbols";
2222 mdata->name_table = 0;
2223 mdata->sbfd = abfd;
2224 mdata->version = version;
2226 bfd_seek (abfd, 0, SEEK_SET);
2227 if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
2228 return -1;
2230 mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
2231 if (mdata->name_table == NULL)
2232 return -1;
2234 bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS);
2235 if (bfdsec == NULL)
2236 return -1;
2238 bfdsec->vma = 0;
2239 bfdsec->lma = 0;
2240 bfdsec->size = 0;
2241 bfdsec->filepos = 0;
2242 bfdsec->alignment_power = 0;
2244 abfd->tdata.sym_data = mdata;
2246 return 0;
2249 const bfd_target *
2250 bfd_sym_object_p (bfd *abfd)
2252 struct bfd_preserve preserve;
2253 bfd_sym_version version = -1;
2255 preserve.marker = NULL;
2256 bfd_seek (abfd, 0, SEEK_SET);
2257 if (bfd_sym_read_version (abfd, &version) != 0)
2258 goto wrong;
2260 preserve.marker = bfd_alloc (abfd, sizeof (bfd_sym_data_struct));
2261 if (preserve.marker == NULL
2262 || ! bfd_preserve_save (abfd, &preserve))
2263 goto fail;
2265 if (bfd_sym_scan (abfd, version,
2266 (bfd_sym_data_struct *) preserve.marker) != 0)
2267 goto wrong;
2269 bfd_preserve_finish (abfd, &preserve);
2270 return abfd->xvec;
2272 wrong:
2273 bfd_set_error (bfd_error_wrong_format);
2275 fail:
2276 if (preserve.marker != NULL)
2277 bfd_preserve_restore (abfd, &preserve);
2278 return NULL;
2281 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol
2283 void
2284 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret)
2286 bfd_symbol_info (symbol, ret);
2289 long
2290 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED)
2292 return 0;
2295 long
2296 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED)
2298 return 0;
2302 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
2303 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2305 return 0;
2308 const bfd_target sym_vec =
2310 "sym", /* Name. */
2311 bfd_target_sym_flavour, /* Flavour. */
2312 BFD_ENDIAN_BIG, /* Byteorder. */
2313 BFD_ENDIAN_BIG, /* Header byteorder. */
2314 (HAS_RELOC | EXEC_P | /* Object flags. */
2315 HAS_LINENO | HAS_DEBUG |
2316 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2317 (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
2318 | SEC_ROM | SEC_HAS_CONTENTS), /* Section_flags. */
2319 0, /* Symbol_leading_char. */
2320 ' ', /* AR_pad_char. */
2321 16, /* AR_max_namelen. */
2322 0, /* match priority. */
2323 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2324 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2325 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
2326 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2327 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2328 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Hdrs. */
2329 { /* bfd_check_format. */
2330 _bfd_dummy_target,
2331 bfd_sym_object_p, /* bfd_check_format. */
2332 _bfd_dummy_target,
2333 _bfd_dummy_target,
2335 { /* bfd_set_format. */
2336 bfd_false,
2337 bfd_sym_mkobject,
2338 bfd_false,
2339 bfd_false,
2341 { /* bfd_write_contents. */
2342 bfd_false,
2343 bfd_true,
2344 bfd_false,
2345 bfd_false,
2348 BFD_JUMP_TABLE_GENERIC (bfd_sym),
2349 BFD_JUMP_TABLE_COPY (_bfd_generic),
2350 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2351 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
2352 BFD_JUMP_TABLE_SYMBOLS (bfd_sym),
2353 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
2354 BFD_JUMP_TABLE_WRITE (bfd_sym),
2355 BFD_JUMP_TABLE_LINK (bfd_sym),
2356 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2358 NULL,
2360 NULL