bfd/
[binutils.git] / bfd / xsym.c
bloba4058dd3954813895072d9193d3c4f9cc4045f29
1 /* xSYM symbol-file support for BFD.
2 Copyright 1999, 2000, 2001, 2002, 2003
3 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include "xsym.h"
22 #include "bfd.h"
23 #include "sysdep.h"
24 #include "libbfd.h"
26 #define bfd_sym_close_and_cleanup _bfd_generic_close_and_cleanup
27 #define bfd_sym_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
28 #define bfd_sym_new_section_hook _bfd_generic_new_section_hook
29 #define bfd_sym_bfd_is_local_label_name bfd_generic_is_local_label_name
30 #define bfd_sym_get_lineno _bfd_nosymbols_get_lineno
31 #define bfd_sym_find_nearest_line _bfd_nosymbols_find_nearest_line
32 #define bfd_sym_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
33 #define bfd_sym_read_minisymbols _bfd_generic_read_minisymbols
34 #define bfd_sym_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
35 #define bfd_sym_get_reloc_upper_bound _bfd_norelocs_get_reloc_upper_bound
36 #define bfd_sym_canonicalize_reloc _bfd_norelocs_canonicalize_reloc
37 #define bfd_sym_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
38 #define bfd_sym_set_arch_mach _bfd_generic_set_arch_mach
39 #define bfd_sym_get_section_contents _bfd_generic_get_section_contents
40 #define bfd_sym_set_section_contents _bfd_generic_set_section_contents
41 #define bfd_sym_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
42 #define bfd_sym_bfd_relax_section bfd_generic_relax_section
43 #define bfd_sym_bfd_gc_sections bfd_generic_gc_sections
44 #define bfd_sym_bfd_merge_sections bfd_generic_merge_sections
45 #define bfd_sym_bfd_discard_group bfd_generic_discard_group
46 #define bfd_sym_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
47 #define bfd_sym_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
48 #define bfd_sym_bfd_link_add_symbols _bfd_generic_link_add_symbols
49 #define bfd_sym_bfd_link_just_syms _bfd_generic_link_just_syms
50 #define bfd_sym_bfd_final_link _bfd_generic_final_link
51 #define bfd_sym_bfd_link_split_section _bfd_generic_link_split_section
52 #define bfd_sym_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
54 static int pstrcmp PARAMS ((unsigned char *, unsigned char *));
55 static unsigned long compute_offset
56 PARAMS ((unsigned long, unsigned long, unsigned long, unsigned long));
58 extern const bfd_target sym_vec;
60 static int
61 pstrcmp (a, b)
62 unsigned char *a;
63 unsigned char *b;
65 unsigned char clen;
66 int ret;
68 clen = (a[0] > b[0]) ? a[0] : b[0];
69 ret = memcmp (a + 1, b + 1, clen);
70 if (ret != 0)
71 return ret;
73 if (a[0] == b[0])
74 return 0;
75 else if (a[0] < b[0])
76 return -1;
77 else
78 return 0;
81 static unsigned long
82 compute_offset (first_page, page_size, entry_size, index)
83 unsigned long first_page;
84 unsigned long page_size;
85 unsigned long entry_size;
86 unsigned long index;
88 unsigned long entries_per_page = page_size / entry_size;
89 unsigned long page_number = first_page + (index / entries_per_page);
90 unsigned long page_offset = (index % entries_per_page) * entry_size;
92 return (page_number * page_size) + page_offset;
95 bfd_boolean
96 bfd_sym_mkobject (abfd)
97 bfd *abfd ATTRIBUTE_UNUSED;
99 return 1;
102 void
103 bfd_sym_print_symbol (abfd, afile, symbol, how)
104 bfd *abfd ATTRIBUTE_UNUSED;
105 PTR afile ATTRIBUTE_UNUSED;
106 asymbol *symbol ATTRIBUTE_UNUSED;
107 bfd_print_symbol_type how ATTRIBUTE_UNUSED;
109 return;
112 bfd_boolean
113 bfd_sym_valid (abfd)
114 bfd *abfd;
116 if (abfd == NULL || abfd->xvec == NULL)
117 return 0;
119 return abfd->xvec == &sym_vec;
122 unsigned char *
123 bfd_sym_read_name_table (abfd, dshb)
124 bfd *abfd;
125 bfd_sym_header_block *dshb;
127 unsigned char *rstr;
128 long ret;
129 size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size;
130 size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size;
132 rstr = (unsigned char *) bfd_alloc (abfd, table_size);
133 if (rstr == NULL)
134 return rstr;
136 bfd_seek (abfd, table_offset, SEEK_SET);
137 ret = bfd_bread (rstr, table_size, abfd);
138 if (ret < 0 || (unsigned long) ret != table_size)
140 bfd_release (abfd, rstr);
141 return NULL;
144 return rstr;
147 void
148 bfd_sym_parse_file_reference_v32 (buf, len, entry)
149 unsigned char *buf;
150 size_t len;
151 bfd_sym_file_reference *entry;
153 BFD_ASSERT (len == 6);
155 entry->fref_frte_index = bfd_getb16 (buf);
156 entry->fref_offset = bfd_getb32 (buf + 2);
159 void
160 bfd_sym_parse_disk_table_v32 (buf, len, table)
161 unsigned char *buf;
162 size_t len;
163 bfd_sym_table_info *table;
165 BFD_ASSERT (len == 8);
167 table->dti_first_page = bfd_getb16 (buf);
168 table->dti_page_count = bfd_getb16 (buf + 2);
169 table->dti_object_count = bfd_getb32 (buf + 4);
172 void
173 bfd_sym_parse_header_v32 (buf, len, header)
174 unsigned char *buf;
175 size_t len;
176 bfd_sym_header_block *header;
178 BFD_ASSERT (len == 154);
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);
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);
200 memcpy (&header->dshb_file_creator, buf + 146, 4);
201 memcpy (&header->dshb_file_type, buf + 150, 4);
205 bfd_sym_read_header_v32 (abfd, header)
206 bfd *abfd;
207 bfd_sym_header_block *header;
209 unsigned char buf[154];
210 long ret;
212 ret = bfd_bread (buf, 154, abfd);
213 if (ret != 154)
214 return -1;
216 bfd_sym_parse_header_v32 (buf, 154, header);
218 return 0;
222 bfd_sym_read_header_v34 (abfd, header)
223 bfd *abfd ATTRIBUTE_UNUSED;
224 bfd_sym_header_block *header ATTRIBUTE_UNUSED;
226 abort ();
230 bfd_sym_read_header (abfd, header, version)
231 bfd *abfd;
232 bfd_sym_header_block *header;
233 bfd_sym_version version;
235 switch (version)
237 case BFD_SYM_VERSION_3_5:
238 case BFD_SYM_VERSION_3_4:
239 return bfd_sym_read_header_v34 (abfd, header);
240 case BFD_SYM_VERSION_3_3:
241 case BFD_SYM_VERSION_3_2:
242 return bfd_sym_read_header_v32 (abfd, header);
243 case BFD_SYM_VERSION_3_1:
244 default:
245 return FALSE;
250 bfd_sym_read_version (abfd, version)
251 bfd *abfd;
252 bfd_sym_version *version;
254 unsigned char version_string[32];
255 long ret;
257 ret = bfd_bread (version_string, sizeof (version_string), abfd);
258 if (ret != sizeof (version_string))
259 return -1;
261 if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0)
262 *version = BFD_SYM_VERSION_3_1;
263 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0)
264 *version = BFD_SYM_VERSION_3_2;
265 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0)
266 *version = BFD_SYM_VERSION_3_3;
267 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0)
268 *version = BFD_SYM_VERSION_3_4;
269 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0)
270 *version = BFD_SYM_VERSION_3_5;
271 else
272 return -1;
274 return 0;
277 void
278 bfd_sym_display_table_summary (f, dti, name)
279 FILE *f;
280 bfd_sym_table_info *dti;
281 const char *name;
283 fprintf (f, "%-6s %13ld %13ld %13ld\n",
284 name,
285 dti->dti_first_page,
286 dti->dti_page_count,
287 dti->dti_object_count);
290 void
291 bfd_sym_display_header (f, dshb)
292 FILE *f;
293 bfd_sym_header_block *dshb;
295 fprintf (f, " Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1);
296 fprintf (f, " Page Size: 0x%x\n", dshb->dshb_page_size);
297 fprintf (f, " Hash Page: %lu\n", dshb->dshb_hash_page);
298 fprintf (f, " Root MTE: %lu\n", dshb->dshb_root_mte);
299 fprintf (f, " Modification Date: ");
300 fprintf (f, "[unimplemented]");
301 fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date);
303 fprintf (f, " File Creator: %.4s Type: %.4s\n\n",
304 dshb->dshb_file_creator, dshb->dshb_file_type);
306 fprintf (f, "Table Name First Page Page Count Object Count\n");
307 fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
309 bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE");
310 bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE");
311 bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE");
312 bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE");
313 bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE");
314 bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE");
315 bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE");
316 bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE");
317 bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE");
318 bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE");
319 bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO");
320 bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE");
321 bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST");
323 fprintf (f, "\n");
326 void
327 bfd_sym_parse_resources_table_entry_v32 (buf, len, entry)
328 unsigned char *buf;
329 size_t len;
330 bfd_sym_resources_table_entry *entry;
332 BFD_ASSERT (len == 18);
334 memcpy (&entry->rte_res_type, buf, 4);
335 entry->rte_res_number = bfd_getb16 (buf + 4);
336 entry->rte_nte_index = bfd_getb32 (buf + 6);
337 entry->rte_mte_first = bfd_getb16 (buf + 10);
338 entry->rte_mte_last = bfd_getb16 (buf + 12);
339 entry->rte_res_size = bfd_getb32 (buf + 14);
342 void
343 bfd_sym_parse_modules_table_entry_v33 (buf, len, entry)
344 unsigned char *buf;
345 size_t len;
346 bfd_sym_modules_table_entry *entry;
348 BFD_ASSERT (len == 46);
350 entry->mte_rte_index = bfd_getb16 (buf);
351 entry->mte_res_offset = bfd_getb32 (buf + 2);
352 entry->mte_size = bfd_getb32 (buf + 6);
353 entry->mte_kind = buf[10];
354 entry->mte_scope = buf[11];
355 entry->mte_parent = bfd_getb16 (buf + 12);
356 bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref);
357 entry->mte_imp_end = bfd_getb32 (buf + 20);
358 entry->mte_nte_index = bfd_getb32 (buf + 24);
359 entry->mte_cmte_index = bfd_getb16 (buf + 28);
360 entry->mte_cvte_index = bfd_getb32 (buf + 30);
361 entry->mte_clte_index = bfd_getb16 (buf + 34);
362 entry->mte_ctte_index = bfd_getb16 (buf + 36);
363 entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38);
364 entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42);
367 void
368 bfd_sym_parse_file_references_table_entry_v32 (buf, len, entry)
369 unsigned char *buf;
370 size_t len;
371 bfd_sym_file_references_table_entry *entry;
373 unsigned int type;
375 BFD_ASSERT (len == 10);
377 memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
378 type = bfd_getb16 (buf);
380 switch (type)
382 case BFD_SYM_END_OF_LIST_3_2:
383 entry->generic.type = BFD_SYM_END_OF_LIST;
384 break;
386 case BFD_SYM_FILE_NAME_INDEX_3_2:
387 entry->filename.type = BFD_SYM_FILE_NAME_INDEX;
388 entry->filename.nte_index = bfd_getb32 (buf + 2);
389 entry->filename.mod_date = bfd_getb32 (buf + 6);
390 break;
392 default:
393 entry->entry.mte_index = type;
394 entry->entry.file_offset = bfd_getb32 (buf + 2);
398 void
399 bfd_sym_parse_contained_modules_table_entry_v32 (buf, len, entry)
400 unsigned char *buf;
401 size_t len;
402 bfd_sym_contained_modules_table_entry *entry;
404 unsigned int type;
406 BFD_ASSERT (len == 6);
408 memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
409 type = bfd_getb16 (buf);
411 switch (type)
413 case BFD_SYM_END_OF_LIST_3_2:
414 entry->generic.type = BFD_SYM_END_OF_LIST;
415 break;
417 default:
418 entry->entry.mte_index = type;
419 entry->entry.nte_index = bfd_getb32 (buf + 2);
420 break;
424 void
425 bfd_sym_parse_contained_variables_table_entry_v32 (buf, len, entry)
426 unsigned char *buf;
427 size_t len;
428 bfd_sym_contained_variables_table_entry *entry;
430 unsigned int type;
432 BFD_ASSERT (len == 26);
434 memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
435 type = bfd_getb16 (buf);
437 switch (type)
439 case BFD_SYM_END_OF_LIST_3_2:
440 entry->generic.type = BFD_SYM_END_OF_LIST;
441 break;
443 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
444 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
445 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
446 break;
448 default:
449 entry->entry.tte_index = type;
450 entry->entry.nte_index = bfd_getb32 (buf + 2);
451 entry->entry.file_delta = bfd_getb16 (buf + 6);
452 entry->entry.scope = buf[8];
453 entry->entry.la_size = buf[9];
455 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
457 entry->entry.address.scstruct.sca_kind = buf[10];
458 entry->entry.address.scstruct.sca_class = buf[11];
459 entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12);
461 else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
463 memcpy (&entry->entry.address.lastruct.la, buf + 10, BFD_SYM_CVTE_SCA);
464 entry->entry.address.lastruct.la_kind = buf[23];
466 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
468 entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
469 entry->entry.address.biglastruct.big_la_kind = buf[12];
474 void
475 bfd_sym_parse_contained_statements_table_entry_v32 (buf, len, entry)
476 unsigned char *buf;
477 size_t len;
478 bfd_sym_contained_statements_table_entry *entry;
480 unsigned int type;
482 BFD_ASSERT (len == 8);
484 memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
485 type = bfd_getb16 (buf);
487 switch (type)
489 case BFD_SYM_END_OF_LIST_3_2:
490 entry->generic.type = BFD_SYM_END_OF_LIST;
491 break;
493 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
494 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
495 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
496 break;
498 default:
499 entry->entry.mte_index = type;
500 entry->entry.mte_offset = bfd_getb16 (buf + 2);
501 entry->entry.file_delta = bfd_getb32 (buf + 4);
502 break;
506 void
507 bfd_sym_parse_contained_labels_table_entry_v32 (buf, len, entry)
508 unsigned char *buf;
509 size_t len;
510 bfd_sym_contained_labels_table_entry *entry;
512 unsigned int type;
514 BFD_ASSERT (len == 12);
516 memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
517 type = bfd_getb16 (buf);
519 switch (type)
521 case BFD_SYM_END_OF_LIST_3_2:
522 entry->generic.type = BFD_SYM_END_OF_LIST;
523 break;
525 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
526 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
527 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
528 break;
530 default:
531 entry->entry.mte_index = type;
532 entry->entry.mte_offset = bfd_getb16 (buf + 2);
533 entry->entry.nte_index = bfd_getb32 (buf + 4);
534 entry->entry.file_delta = bfd_getb16 (buf + 8);
535 entry->entry.scope = bfd_getb16 (buf + 10);
536 break;
540 void
541 bfd_sym_parse_type_table_entry_v32 (buf, len, entry)
542 unsigned char *buf;
543 size_t len;
544 bfd_sym_type_table_entry *entry;
546 BFD_ASSERT (len == 4);
548 *entry = bfd_getb32 (buf);
552 bfd_sym_fetch_resources_table_entry (abfd, entry, index)
553 bfd *abfd;
554 bfd_sym_resources_table_entry *entry;
555 unsigned long index;
557 void (*parser) PARAMS ((unsigned char *, size_t,
558 bfd_sym_resources_table_entry *));
559 unsigned long offset;
560 unsigned long entry_size;
561 unsigned char buf[18];
562 bfd_sym_data_struct *sdata = NULL;
564 parser = NULL;
565 BFD_ASSERT (bfd_sym_valid (abfd));
566 sdata = abfd->tdata.sym_data;
568 if (index == 0)
569 return -1;
571 switch (sdata->version)
573 case BFD_SYM_VERSION_3_5:
574 case BFD_SYM_VERSION_3_4:
575 return -1;
577 case BFD_SYM_VERSION_3_3:
578 case BFD_SYM_VERSION_3_2:
579 entry_size = 18;
580 parser = bfd_sym_parse_resources_table_entry_v32;
581 break;
583 case BFD_SYM_VERSION_3_1:
584 default:
585 return -1;
587 if (parser == NULL)
588 return -1;
590 offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
591 sdata->header.dshb_page_size,
592 entry_size, index);
594 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
595 return -1;
596 if (bfd_bread (buf, entry_size, abfd) != entry_size)
597 return -1;
599 (*parser) (buf, entry_size, entry);
601 return 0;
605 bfd_sym_fetch_modules_table_entry (abfd, entry, index)
606 bfd *abfd;
607 bfd_sym_modules_table_entry *entry;
608 unsigned long index;
610 void (*parser) PARAMS ((unsigned char *, size_t,
611 bfd_sym_modules_table_entry *));
612 unsigned long offset;
613 unsigned long entry_size;
614 unsigned char buf[46];
615 bfd_sym_data_struct *sdata = NULL;
617 parser = NULL;
618 BFD_ASSERT (bfd_sym_valid (abfd));
619 sdata = abfd->tdata.sym_data;
621 if (index == 0)
622 return -1;
624 switch (sdata->version)
626 case BFD_SYM_VERSION_3_5:
627 case BFD_SYM_VERSION_3_4:
628 return -1;
630 case BFD_SYM_VERSION_3_3:
631 entry_size = 46;
632 parser = bfd_sym_parse_modules_table_entry_v33;
633 break;
635 case BFD_SYM_VERSION_3_2:
636 case BFD_SYM_VERSION_3_1:
637 default:
638 return -1;
640 if (parser == NULL)
641 return -1;
643 offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
644 sdata->header.dshb_page_size,
645 entry_size, index);
647 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
648 return -1;
649 if (bfd_bread (buf, entry_size, abfd) != entry_size)
650 return -1;
652 (*parser) (buf, entry_size, entry);
654 return 0;
658 bfd_sym_fetch_file_references_table_entry (abfd, entry, index)
659 bfd *abfd;
660 bfd_sym_file_references_table_entry *entry;
661 unsigned long index;
663 void (*parser) PARAMS ((unsigned char *, size_t,
664 bfd_sym_file_references_table_entry *));
665 unsigned long offset;
666 unsigned long entry_size = 0;
667 unsigned char buf[8];
668 bfd_sym_data_struct *sdata = NULL;
670 parser = NULL;
671 BFD_ASSERT (bfd_sym_valid (abfd));
672 sdata = abfd->tdata.sym_data;
674 if (index == 0)
675 return -1;
677 switch (sdata->version)
679 case BFD_SYM_VERSION_3_3:
680 case BFD_SYM_VERSION_3_2:
681 entry_size = 10;
682 parser = bfd_sym_parse_file_references_table_entry_v32;
683 break;
685 case BFD_SYM_VERSION_3_5:
686 case BFD_SYM_VERSION_3_4:
687 case BFD_SYM_VERSION_3_1:
688 default:
689 break;
692 if (parser == NULL)
693 return -1;
695 offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
696 sdata->header.dshb_page_size,
697 entry_size, index);
699 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
700 return -1;
701 if (bfd_bread (buf, entry_size, abfd) != entry_size)
702 return -1;
704 (*parser) (buf, entry_size, entry);
706 return 0;
710 bfd_sym_fetch_contained_modules_table_entry (abfd, entry, index)
711 bfd *abfd;
712 bfd_sym_contained_modules_table_entry *entry;
713 unsigned long index;
715 void (*parser) PARAMS ((unsigned char *, size_t,
716 bfd_sym_contained_modules_table_entry *));
717 unsigned long offset;
718 unsigned long entry_size = 0;
719 unsigned char buf[6];
720 bfd_sym_data_struct *sdata = NULL;
722 parser = NULL;
723 BFD_ASSERT (bfd_sym_valid (abfd));
724 sdata = abfd->tdata.sym_data;
726 if (index == 0)
727 return -1;
729 switch (sdata->version)
731 case BFD_SYM_VERSION_3_3:
732 case BFD_SYM_VERSION_3_2:
733 entry_size = 6;
734 parser = bfd_sym_parse_contained_modules_table_entry_v32;
735 break;
737 case BFD_SYM_VERSION_3_5:
738 case BFD_SYM_VERSION_3_4:
739 case BFD_SYM_VERSION_3_1:
740 default:
741 break;
744 if (parser == NULL)
745 return -1;
747 offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
748 sdata->header.dshb_page_size,
749 entry_size, index);
751 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
752 return -1;
753 if (bfd_bread (buf, entry_size, abfd) != entry_size)
754 return -1;
756 (*parser) (buf, entry_size, entry);
758 return 0;
762 bfd_sym_fetch_contained_variables_table_entry (abfd, entry, index)
763 bfd *abfd;
764 bfd_sym_contained_variables_table_entry *entry;
765 unsigned long index;
767 void (*parser) PARAMS ((unsigned char *, size_t,
768 bfd_sym_contained_variables_table_entry *));
769 unsigned long offset;
770 unsigned long entry_size = 0;
771 unsigned char buf[26];
772 bfd_sym_data_struct *sdata = NULL;
774 parser = NULL;
775 BFD_ASSERT (bfd_sym_valid (abfd));
776 sdata = abfd->tdata.sym_data;
778 if (index == 0)
779 return -1;
781 switch (sdata->version)
783 case BFD_SYM_VERSION_3_3:
784 case BFD_SYM_VERSION_3_2:
785 entry_size = 26;
786 parser = bfd_sym_parse_contained_variables_table_entry_v32;
787 break;
789 case BFD_SYM_VERSION_3_5:
790 case BFD_SYM_VERSION_3_4:
791 case BFD_SYM_VERSION_3_1:
792 default:
793 break;
796 if (parser == NULL)
797 return -1;
799 offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
800 sdata->header.dshb_page_size,
801 entry_size, index);
803 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
804 return -1;
805 if (bfd_bread (buf, entry_size, abfd) != entry_size)
806 return -1;
808 (*parser) (buf, entry_size, entry);
810 return 0;
814 bfd_sym_fetch_contained_statements_table_entry (abfd, entry, index)
815 bfd *abfd;
816 bfd_sym_contained_statements_table_entry *entry;
817 unsigned long index;
819 void (*parser) PARAMS ((unsigned char *, size_t,
820 bfd_sym_contained_statements_table_entry *));
821 unsigned long offset;
822 unsigned long entry_size = 0;
823 unsigned char buf[8];
824 bfd_sym_data_struct *sdata = NULL;
826 parser = NULL;
827 BFD_ASSERT (bfd_sym_valid (abfd));
828 sdata = abfd->tdata.sym_data;
830 if (index == 0)
831 return -1;
833 switch (sdata->version)
835 case BFD_SYM_VERSION_3_3:
836 case BFD_SYM_VERSION_3_2:
837 entry_size = 8;
838 parser = bfd_sym_parse_contained_statements_table_entry_v32;
839 break;
841 case BFD_SYM_VERSION_3_5:
842 case BFD_SYM_VERSION_3_4:
843 case BFD_SYM_VERSION_3_1:
844 default:
845 break;
848 if (parser == NULL)
849 return -1;
851 offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
852 sdata->header.dshb_page_size,
853 entry_size, index);
855 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
856 return -1;
857 if (bfd_bread (buf, entry_size, abfd) != entry_size)
858 return -1;
860 (*parser) (buf, entry_size, entry);
862 return 0;
866 bfd_sym_fetch_contained_labels_table_entry (abfd, entry, index)
867 bfd *abfd;
868 bfd_sym_contained_labels_table_entry *entry;
869 unsigned long index;
871 void (*parser) PARAMS ((unsigned char *, size_t,
872 bfd_sym_contained_labels_table_entry *));
873 unsigned long offset;
874 unsigned long entry_size = 0;
875 unsigned char buf[12];
876 bfd_sym_data_struct *sdata = NULL;
878 parser = NULL;
879 BFD_ASSERT (bfd_sym_valid (abfd));
880 sdata = abfd->tdata.sym_data;
882 if (index == 0)
883 return -1;
885 switch (sdata->version)
887 case BFD_SYM_VERSION_3_3:
888 case BFD_SYM_VERSION_3_2:
889 entry_size = 12;
890 parser = bfd_sym_parse_contained_labels_table_entry_v32;
891 break;
893 case BFD_SYM_VERSION_3_5:
894 case BFD_SYM_VERSION_3_4:
895 case BFD_SYM_VERSION_3_1:
896 default:
897 break;
900 if (parser == NULL)
901 return -1;
903 offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
904 sdata->header.dshb_page_size,
905 entry_size, index);
907 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
908 return -1;
909 if (bfd_bread (buf, entry_size, abfd) != entry_size)
910 return -1;
912 (*parser) (buf, entry_size, entry);
914 return 0;
918 bfd_sym_fetch_contained_types_table_entry (abfd, entry, index)
919 bfd *abfd;
920 bfd_sym_contained_types_table_entry *entry;
921 unsigned long index;
923 void (*parser) PARAMS ((unsigned char *, size_t,
924 bfd_sym_contained_types_table_entry *));
925 unsigned long offset;
926 unsigned long entry_size = 0;
927 unsigned char buf[0];
928 bfd_sym_data_struct *sdata = NULL;
930 parser = NULL;
931 BFD_ASSERT (bfd_sym_valid (abfd));
932 sdata = abfd->tdata.sym_data;
934 if (index == 0)
935 return -1;
937 switch (sdata->version)
939 case BFD_SYM_VERSION_3_3:
940 case BFD_SYM_VERSION_3_2:
941 entry_size = 0;
942 parser = NULL;
943 break;
945 case BFD_SYM_VERSION_3_5:
946 case BFD_SYM_VERSION_3_4:
947 case BFD_SYM_VERSION_3_1:
948 default:
949 break;
952 if (parser == NULL)
953 return -1;
955 offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
956 sdata->header.dshb_page_size,
957 entry_size, index);
959 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
960 return -1;
961 if (bfd_bread (buf, entry_size, abfd) != entry_size)
962 return -1;
964 (*parser) (buf, entry_size, entry);
966 return 0;
970 bfd_sym_fetch_file_references_index_table_entry (abfd, entry, index)
971 bfd *abfd;
972 bfd_sym_file_references_index_table_entry *entry;
973 unsigned long index;
975 void (*parser) PARAMS ((unsigned char *, size_t,
976 bfd_sym_file_references_index_table_entry *));
977 unsigned long offset;
978 unsigned long entry_size = 0;
979 unsigned char buf[0];
980 bfd_sym_data_struct *sdata = NULL;
982 parser = NULL;
983 BFD_ASSERT (bfd_sym_valid (abfd));
984 sdata = abfd->tdata.sym_data;
986 if (index == 0)
987 return -1;
989 switch (sdata->version)
991 case BFD_SYM_VERSION_3_3:
992 case BFD_SYM_VERSION_3_2:
993 entry_size = 0;
994 parser = NULL;
995 break;
997 case BFD_SYM_VERSION_3_5:
998 case BFD_SYM_VERSION_3_4:
999 case BFD_SYM_VERSION_3_1:
1000 default:
1001 break;
1004 if (parser == NULL)
1005 return -1;
1007 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1008 sdata->header.dshb_page_size,
1009 entry_size, index);
1011 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1012 return -1;
1013 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1014 return -1;
1016 (*parser) (buf, entry_size, entry);
1018 return 0;
1022 bfd_sym_fetch_constant_pool_entry (abfd, entry, index)
1023 bfd *abfd;
1024 bfd_sym_constant_pool_entry *entry;
1025 unsigned long index;
1027 void (*parser) PARAMS ((unsigned char *, size_t,
1028 bfd_sym_constant_pool_entry *));
1029 unsigned long offset;
1030 unsigned long entry_size = 0;
1031 unsigned char buf[0];
1032 bfd_sym_data_struct *sdata = NULL;
1034 parser = NULL;
1035 BFD_ASSERT (bfd_sym_valid (abfd));
1036 sdata = abfd->tdata.sym_data;
1038 if (index == 0)
1039 return -1;
1041 switch (sdata->version)
1043 case BFD_SYM_VERSION_3_3:
1044 case BFD_SYM_VERSION_3_2:
1045 entry_size = 0;
1046 parser = NULL;
1047 break;
1049 case BFD_SYM_VERSION_3_5:
1050 case BFD_SYM_VERSION_3_4:
1051 case BFD_SYM_VERSION_3_1:
1052 default:
1053 break;
1056 if (parser == NULL)
1057 return -1;
1059 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1060 sdata->header.dshb_page_size,
1061 entry_size, index);
1063 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1064 return -1;
1065 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1066 return -1;
1068 (*parser) (buf, entry_size, entry);
1070 return 0;
1074 bfd_sym_fetch_type_table_entry (abfd, entry, index)
1075 bfd *abfd;
1076 bfd_sym_type_table_entry *entry;
1077 unsigned long index;
1079 void (*parser) PARAMS ((unsigned char *, size_t,
1080 bfd_sym_type_table_entry *));
1081 unsigned long offset;
1082 unsigned long entry_size = 0;
1083 unsigned char buf[4];
1084 bfd_sym_data_struct *sdata = NULL;
1086 parser = NULL;
1087 BFD_ASSERT (bfd_sym_valid (abfd));
1088 sdata = abfd->tdata.sym_data;
1090 switch (sdata->version)
1092 case BFD_SYM_VERSION_3_3:
1093 case BFD_SYM_VERSION_3_2:
1094 entry_size = 4;
1095 parser = bfd_sym_parse_type_table_entry_v32;
1096 break;
1098 case BFD_SYM_VERSION_3_5:
1099 case BFD_SYM_VERSION_3_4:
1100 case BFD_SYM_VERSION_3_1:
1101 default:
1102 break;
1105 if (parser == NULL)
1106 return -1;
1108 offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
1109 sdata->header.dshb_page_size,
1110 entry_size, index);
1112 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1113 return -1;
1114 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1115 return -1;
1117 (*parser) (buf, entry_size, entry);
1119 return 0;
1123 bfd_sym_fetch_type_information_table_entry (abfd, entry, offset)
1124 bfd *abfd;
1125 bfd_sym_type_information_table_entry *entry;
1126 unsigned long offset;
1128 unsigned char buf[4];
1129 bfd_sym_data_struct *sdata = NULL;
1131 BFD_ASSERT (bfd_sym_valid (abfd));
1132 sdata = abfd->tdata.sym_data;
1134 if (offset == 0)
1135 return -1;
1137 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1138 return -1;
1140 if (bfd_bread (buf, 4, abfd) != 4)
1141 return -1;
1142 entry->nte_index = bfd_getb32 (buf);
1144 if (bfd_bread (buf, 2, abfd) != 2)
1145 return -1;
1146 entry->physical_size = bfd_getb16 (buf);
1148 if (entry->physical_size & 0x8000)
1150 if (bfd_bread (buf, 4, abfd) != 4)
1151 return -1;
1152 entry->physical_size &= 0x7fff;
1153 entry->logical_size = bfd_getb32 (buf);
1154 entry->offset = offset + 10;
1156 else
1158 if (bfd_bread (buf, 2, abfd) != 2)
1159 return -1;
1160 entry->physical_size &= 0x7fff;
1161 entry->logical_size = bfd_getb16 (buf);
1162 entry->offset = offset + 8;
1165 return 0;
1169 bfd_sym_fetch_type_table_information (abfd, entry, index)
1170 bfd *abfd;
1171 bfd_sym_type_information_table_entry *entry;
1172 unsigned long index;
1174 bfd_sym_type_table_entry tindex;
1175 bfd_sym_data_struct *sdata = NULL;
1177 BFD_ASSERT (bfd_sym_valid (abfd));
1178 sdata = abfd->tdata.sym_data;
1180 if (sdata->header.dshb_tte.dti_object_count <= 99)
1181 return -1;
1182 if (index < 100)
1183 return -1;
1185 if (bfd_sym_fetch_type_table_entry (abfd, &tindex, index - 100) < 0)
1186 return -1;
1187 if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
1188 return -1;
1190 return 0;
1193 const unsigned char *
1194 bfd_sym_symbol_name (abfd, index)
1195 bfd *abfd;
1196 unsigned long index;
1198 bfd_sym_data_struct *sdata = NULL;
1200 BFD_ASSERT (bfd_sym_valid (abfd));
1201 sdata = abfd->tdata.sym_data;
1203 if (index == 0)
1204 return "";
1206 index *= 2;
1207 if ((index / sdata->header.dshb_page_size)
1208 > sdata->header.dshb_nte.dti_page_count)
1209 return "\009[INVALID]";
1211 return (const unsigned char *) sdata->name_table + index;
1214 const unsigned char *
1215 bfd_sym_module_name (abfd, index)
1216 bfd *abfd;
1217 unsigned long index;
1219 bfd_sym_modules_table_entry entry;
1221 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, index) < 0)
1222 return "\011[INVALID]";
1224 return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
1227 const char *
1228 bfd_sym_unparse_storage_kind (kind)
1229 enum bfd_sym_storage_kind kind;
1231 switch (kind)
1233 case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL";
1234 case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE";
1235 case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE";
1236 case BFD_SYM_STORAGE_KIND_WITH: return "WITH";
1237 default: return "[UNKNOWN]";
1241 const char *
1242 bfd_sym_unparse_storage_class (kind)
1243 enum bfd_sym_storage_class kind;
1245 switch (kind)
1247 case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER";
1248 case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL";
1249 case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE";
1250 case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE";
1251 case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE";
1252 case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT";
1253 case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE";
1254 case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT";
1255 default: return "[UNKNOWN]";
1259 const char *
1260 bfd_sym_unparse_module_kind (kind)
1261 enum bfd_sym_module_kind kind;
1263 switch (kind)
1265 case BFD_SYM_MODULE_KIND_NONE: return "NONE";
1266 case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM";
1267 case BFD_SYM_MODULE_KIND_UNIT: return "UNIT";
1268 case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE";
1269 case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION";
1270 case BFD_SYM_MODULE_KIND_DATA: return "DATA";
1271 case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK";
1272 default: return "[UNKNOWN]";
1276 const char *
1277 bfd_sym_unparse_symbol_scope (scope)
1278 enum bfd_sym_symbol_scope scope;
1280 switch (scope)
1282 case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
1283 case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
1284 default:
1285 return "[UNKNOWN]";
1289 void
1290 bfd_sym_print_file_reference (abfd, f, entry)
1291 bfd *abfd;
1292 FILE *f;
1293 bfd_sym_file_reference *entry;
1295 bfd_sym_file_references_table_entry frtentry;
1296 int ret;
1298 ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
1299 entry->fref_frte_index);
1300 fprintf (f, "FILE ");
1302 if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
1303 fprintf (f, "[INVALID]");
1304 else
1305 fprintf (f, "\"%.*s\"",
1306 bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0],
1307 &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]);
1309 fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
1312 void
1313 bfd_sym_print_resources_table_entry (abfd, f, entry)
1314 bfd *abfd;
1315 FILE *f;
1316 bfd_sym_resources_table_entry *entry;
1318 fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu",
1319 bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0],
1320 &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1],
1321 entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number,
1322 entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last);
1325 void
1326 bfd_sym_print_modules_table_entry (abfd, f, entry)
1327 bfd *abfd;
1328 FILE *f;
1329 bfd_sym_modules_table_entry *entry;
1331 fprintf (f, "\"%.*s\" (NTE %lu)",
1332 bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0],
1333 &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1],
1334 entry->mte_nte_index);
1336 fprintf (f, "\n ");
1338 bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref);
1339 fprintf (f, " range %lu -- %lu",
1340 entry->mte_imp_fref.fref_offset, entry->mte_imp_end);
1342 fprintf (f, "\n ");
1344 fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind));
1345 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope));
1347 fprintf (f, ", RTE %lu, offset %lu, size %lu",
1348 entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
1350 fprintf (f, "\n ");
1352 fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu",
1353 entry->mte_cmte_index, entry->mte_cvte_index,
1354 entry->mte_clte_index, entry->mte_ctte_index,
1355 entry->mte_csnte_idx_1, entry->mte_csnte_idx_2);
1357 if (entry->mte_parent != 0)
1358 fprintf (f, ", parent %lu", entry->mte_parent);
1359 else
1360 fprintf (f, ", no parent");
1362 if (entry->mte_cmte_index != 0)
1363 fprintf (f, ", child %lu", entry->mte_cmte_index);
1364 else
1365 fprintf (f, ", no child");
1367 #if 0
1369 MTE bfd_sym_modules_table_entry pentry;
1371 ret = bfd_sym_fetch_modules_table_entry (abfd, &pentry, entry->mte_parent);
1372 if (ret < 0)
1373 fprintf (f, " parent MTE %lu [INVALID]\n", entry->mte_parent);
1374 else
1375 fprintf (f, " parent MTE %lu \"%.*s\"\n",
1376 entry->mte_parent,
1377 bfd_sym_symbol_name (abfd, pentry.mte_nte_index)[0],
1378 &bfd_sym_symbol_name (abfd, pentry.mte_nte_index)[1]);
1380 #endif
1383 void
1384 bfd_sym_print_file_references_table_entry (abfd, f, entry)
1385 bfd *abfd;
1386 FILE *f;
1387 bfd_sym_file_references_table_entry *entry;
1389 switch (entry->generic.type)
1391 case BFD_SYM_FILE_NAME_INDEX:
1392 fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ",
1393 bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0],
1394 &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1],
1395 entry->filename.nte_index);
1397 fprintf (f, "[UNIMPLEMENTED]");
1398 /* printModDate (entry->filename.mod_date); */
1399 fprintf (f, " (0x%lx)", entry->filename.mod_date);
1400 break;
1402 case BFD_SYM_END_OF_LIST:
1403 fprintf (f, "END");
1404 break;
1406 default:
1407 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu",
1408 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1409 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1410 entry->entry.mte_index,
1411 entry->entry.file_offset);
1412 break;
1416 void
1417 bfd_sym_print_contained_modules_table_entry (abfd, f, entry)
1418 bfd *abfd;
1419 FILE *f;
1420 bfd_sym_contained_modules_table_entry *entry;
1422 switch (entry->generic.type)
1424 case BFD_SYM_END_OF_LIST:
1425 fprintf (f, "END");
1426 break;
1428 default:
1429 fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)",
1430 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1431 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1432 entry->entry.mte_index,
1433 entry->entry.nte_index);
1434 break;
1438 void
1439 bfd_sym_print_contained_variables_table_entry (abfd, f, entry)
1440 bfd *abfd;
1441 FILE *f;
1442 bfd_sym_contained_variables_table_entry *entry;
1444 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1446 fprintf (f, "END");
1447 return;
1450 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1452 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1453 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1454 return;
1457 fprintf (f, "\"%.*s\" (NTE %lu)",
1458 bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0],
1459 &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1],
1460 entry->entry.nte_index);
1462 fprintf (f, ", TTE %lu", entry->entry.tte_index);
1463 fprintf (f, ", offset %lu", entry->entry.file_delta);
1464 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope));
1466 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
1467 fprintf (f, ", latype %s, laclass %s, laoffset %lu",
1468 bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind),
1469 bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class),
1470 entry->entry.address.scstruct.sca_offset);
1471 else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE)
1473 unsigned long i;
1475 fprintf (f, ", la [");
1476 for (i = 0; i < entry->entry.la_size; i++)
1477 fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]);
1478 fprintf (f, "]");
1480 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
1481 fprintf (f, ", bigla %lu, biglakind %u",
1482 entry->entry.address.biglastruct.big_la,
1483 entry->entry.address.biglastruct.big_la_kind);
1485 else
1486 fprintf (f, ", la [INVALID]");
1489 void
1490 bfd_sym_print_contained_statements_table_entry (abfd, f, entry)
1491 bfd *abfd;
1492 FILE *f;
1493 bfd_sym_contained_statements_table_entry *entry;
1495 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1497 fprintf (f, "END");
1498 return;
1501 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1503 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1504 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1505 return;
1508 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu",
1509 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1510 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1511 entry->entry.mte_index,
1512 entry->entry.mte_offset,
1513 entry->entry.file_delta);
1516 void
1517 bfd_sym_print_contained_labels_table_entry (abfd, f, entry)
1518 bfd *abfd;
1519 FILE *f;
1520 bfd_sym_contained_labels_table_entry *entry;
1522 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1524 fprintf (f, "END");
1525 return;
1528 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1530 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1531 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1532 return;
1535 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s",
1536 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1537 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1538 entry->entry.mte_index,
1539 entry->entry.mte_offset,
1540 entry->entry.file_delta,
1541 bfd_sym_unparse_symbol_scope (entry->entry.scope));
1544 void
1545 bfd_sym_print_contained_types_table_entry (abfd, f, entry)
1546 bfd *abfd ATTRIBUTE_UNUSED;
1547 FILE *f;
1548 bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED;
1550 fprintf (f, "[UNIMPLEMENTED]");
1553 const char *
1554 bfd_sym_type_operator_name (num)
1555 unsigned char num;
1557 switch (num)
1559 case 1: return "TTE";
1560 case 2: return "PointerTo";
1561 case 3: return "ScalarOf";
1562 case 4: return "ConstantOf";
1563 case 5: return "EnumerationOf";
1564 case 6: return "VectorOf";
1565 case 7: return "RecordOf";
1566 case 8: return "UnionOf";
1567 case 9: return "SubRangeOf";
1568 case 10: return "SetOf";
1569 case 11: return "NamedTypeOf";
1570 case 12: return "ProcOf";
1571 case 13: return "ValueOf";
1572 case 14: return "ArrayOf";
1573 default: return "[UNKNOWN OPERATOR]";
1577 const char *
1578 bfd_sym_type_basic_name (num)
1579 unsigned char num;
1581 switch (num)
1583 case 0: return "void";
1584 case 1: return "pascal string";
1585 case 2: return "unsigned long";
1586 case 3: return "signed long";
1587 case 4: return "extended (10 bytes)";
1588 case 5: return "pascal boolean (1 byte)";
1589 case 6: return "unsigned byte";
1590 case 7: return "signed byte";
1591 case 8: return "character (1 byte)";
1592 case 9: return "wide character (2 bytes)";
1593 case 10: return "unsigned short";
1594 case 11: return "signed short";
1595 case 12: return "singled";
1596 case 13: return "double";
1597 case 14: return "extended (12 bytes)";
1598 case 15: return "computational (8 bytes)";
1599 case 16: return "c string";
1600 case 17: return "as-is string";
1601 default: return "[UNKNOWN BASIC TYPE]";
1606 bfd_sym_fetch_long (buf, len, offset, offsetptr, value)
1607 unsigned char *buf;
1608 unsigned long len;
1609 unsigned long offset;
1610 unsigned long *offsetptr;
1611 long *value;
1613 int ret;
1615 if (offset >= len)
1617 *value = 0;
1618 offset += 0;
1619 ret = -1;
1621 else if (! (buf[offset] & 0x80))
1623 *value = buf[offset];
1624 offset += 1;
1625 ret = 0;
1627 else if (buf[offset] == 0xc0)
1629 if ((offset + 5) > len)
1631 *value = 0;
1632 offset = len;
1633 ret = -1;
1635 else
1637 *value = bfd_getb32 (buf + offset + 1);
1638 offset += 5;
1639 ret = 0;
1642 else if ((buf[offset] & 0xc0) == 0xc0)
1644 *value = -(buf[offset] & 0x3f);
1645 offset += 1;
1646 ret = 0;
1648 else if ((buf[offset] & 0xc0) == 0x80)
1650 if ((offset + 2) > len)
1652 *value = 0;
1653 offset = len;
1654 ret = -1;
1656 else
1658 *value = bfd_getb16 (buf + offset) & 0x3fff;
1659 offset += 2;
1660 ret = 0;
1663 else
1664 abort ();
1666 if (offsetptr != NULL)
1667 *offsetptr = offset;
1669 return ret;
1672 void
1673 bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr)
1674 bfd *abfd;
1675 FILE *f;
1676 unsigned char *buf;
1677 unsigned long len;
1678 unsigned long offset;
1679 unsigned long *offsetptr;
1681 unsigned int type;
1683 if (offset >= len)
1685 fprintf (f, "[NULL]");
1687 if (offsetptr != NULL)
1688 *offsetptr = offset;
1689 return;
1692 type = buf[offset];
1693 offset++;
1695 if (! (type & 0x80))
1697 fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
1699 if (offsetptr != NULL)
1700 *offsetptr = offset;
1701 return;
1704 if (type & 0x40)
1705 fprintf (f, "[packed ");
1706 else
1707 fprintf (f, "[");
1709 switch (type & 0x3f)
1711 case 1:
1713 long value;
1714 bfd_sym_type_information_table_entry tinfo;
1716 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1717 if (value <= 0)
1718 fprintf (f, "[INVALID]");
1719 else
1721 if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
1722 fprintf (f, "[INVALID]");
1723 else
1724 fprintf (f, "\"%.*s\"",
1725 bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
1726 &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
1728 fprintf (f, " (TTE %lu)", value);
1729 break;
1732 case 2:
1733 fprintf (f, "pointer (0x%x) to ", type);
1734 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1735 break;
1737 case 3:
1739 unsigned long value;
1741 fprintf (f, "scalar (0x%x) of ", type);
1742 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1743 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1744 fprintf (f, " (%lu)", value);
1745 break;
1748 case 5:
1750 unsigned long lower, upper, nelem;
1751 unsigned long i;
1753 fprintf (f, "enumeration (0x%x) of ", type);
1754 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1755 bfd_sym_fetch_long (buf, len, offset, &offset, &lower);
1756 bfd_sym_fetch_long (buf, len, offset, &offset, &upper);
1757 bfd_sym_fetch_long (buf, len, offset, &offset, &nelem);
1758 fprintf (f, " from %lu to %lu with %lu elements: ", lower, upper, nelem);
1760 for (i = 0; i < nelem; i++)
1762 fprintf (f, "\n ");
1763 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1765 break;
1768 case 6:
1769 fprintf (f, "vector (0x%x)", type);
1770 fprintf (f, "\n index ");
1771 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1772 fprintf (f, "\n target ");
1773 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1774 break;
1776 case 7:
1777 case 8:
1779 long nrec, eloff, i;
1781 if ((type & 0x3f) == 7)
1782 fprintf (f, "record (0x%x) of ", type);
1783 else
1784 fprintf (f, "union (0x%x) of ", type);
1786 bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
1787 fprintf (f, "%lu elements: ", nrec);
1789 for (i = 0; i < nrec; i++)
1791 bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
1792 fprintf (f, "\n ");
1793 fprintf (f, "offset %lu: ", eloff);
1794 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1796 break;
1799 case 9:
1800 fprintf (f, "subrange (0x%x) of ", type);
1801 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1802 fprintf (f, " lower ");
1803 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1804 fprintf (f, " upper ");
1805 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1806 break;
1808 case 11:
1810 long value;
1812 fprintf (f, "named type (0x%x) ", type);
1813 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1814 if (value <= 0)
1815 fprintf (f, "[INVALID]");
1816 else
1817 fprintf (f, "\"%.*s\"",
1818 bfd_sym_symbol_name (abfd, value)[0],
1819 &bfd_sym_symbol_name (abfd, value)[1]);
1821 fprintf (f, " (NTE %lu) with type ", value);
1822 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1823 break;
1826 default:
1827 fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
1828 break;
1831 if (type == (0x40 | 0x6))
1833 /* Vector. */
1834 long n, width, m;
1835 long l;
1836 long i;
1838 bfd_sym_fetch_long (buf, len, offset, &offset, &n);
1839 bfd_sym_fetch_long (buf, len, offset, &offset, &width);
1840 bfd_sym_fetch_long (buf, len, offset, &offset, &m);
1841 /* fprintf (f, "\n "); */
1842 fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m);
1843 for (i = 0; i < m; i++)
1845 bfd_sym_fetch_long (buf, len, offset, &offset, &l);
1846 if (i != 0)
1847 fprintf (f, " ");
1848 fprintf (f, "%ld", l);
1851 else if (type & 0x40)
1853 /* Other packed type. */
1854 long msb, lsb;
1856 bfd_sym_fetch_long (buf, len, offset, &offset, &msb);
1857 bfd_sym_fetch_long (buf, len, offset, &offset, &lsb);
1858 /* fprintf (f, "\n "); */
1859 fprintf (f, " msb %ld, lsb %ld", msb, lsb);
1862 fprintf (f, "]");
1864 if (offsetptr != NULL)
1865 *offsetptr = offset;
1868 void
1869 bfd_sym_print_type_information_table_entry (abfd, f, entry)
1870 bfd *abfd;
1871 FILE *f;
1872 bfd_sym_type_information_table_entry *entry;
1874 unsigned char *buf;
1875 unsigned long offset;
1876 unsigned int i;
1878 fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu",
1879 bfd_sym_symbol_name (abfd, entry->nte_index)[0],
1880 &bfd_sym_symbol_name (abfd, entry->nte_index)[1],
1881 entry->nte_index,
1882 entry->physical_size, entry->offset, entry->logical_size);
1884 fprintf (f, "\n ");
1886 buf = alloca (entry->physical_size);
1887 if (buf == NULL)
1889 fprintf (f, "[ERROR]\n");
1890 return;
1892 if (bfd_seek (abfd, entry->offset, SEEK_SET) < 0)
1894 fprintf (f, "[ERROR]\n");
1895 return;
1897 if (bfd_bread (buf, entry->physical_size, abfd) != entry->physical_size)
1899 fprintf (f, "[ERROR]\n");
1900 return;
1903 fprintf (f, "[");
1904 for (i = 0; i < entry->physical_size; i++)
1906 if (i == 0)
1907 fprintf (f, "0x%02x", buf[i]);
1908 else
1909 fprintf (f, " 0x%02x", buf[i]);
1912 fprintf (f, "]");
1913 fprintf (f, "\n ");
1915 bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
1917 if (offset != entry->physical_size)
1918 fprintf (f, "\n [parser used %lu bytes instead of %lu]", offset, entry->physical_size); }
1920 void
1921 bfd_sym_print_file_references_index_table_entry (abfd, f, entry)
1922 bfd *abfd ATTRIBUTE_UNUSED;
1923 FILE *f;
1924 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED;
1926 fprintf (f, "[UNIMPLEMENTED]");
1929 void
1930 bfd_sym_print_constant_pool_entry (abfd, f, entry)
1931 bfd *abfd ATTRIBUTE_UNUSED;
1932 FILE *f;
1933 bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED;
1935 fprintf (f, "[UNIMPLEMENTED]");
1938 unsigned char *
1939 bfd_sym_display_name_table_entry (abfd, f, entry)
1940 bfd *abfd;
1941 FILE *f;
1942 unsigned char *entry;
1944 unsigned long index;
1945 unsigned long offset;
1946 bfd_sym_data_struct *sdata = NULL;
1948 BFD_ASSERT (bfd_sym_valid (abfd));
1949 sdata = abfd->tdata.sym_data;
1950 index = (entry - sdata->name_table) / 2;
1952 if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
1954 unsigned short length = bfd_getb16 (entry + 2);
1955 fprintf (f, "[%8lu] \"%.*s\"\n", index, length, entry + 4);
1956 offset = 2 + length + 1;
1958 else
1960 if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
1961 fprintf (f, "[%8lu] \"%.*s\"\n", index, entry[0], entry + 1);
1963 if (sdata->version >= BFD_SYM_VERSION_3_4)
1964 offset = entry[0] + 2;
1965 else
1966 offset = entry[0] + 1;
1969 return (entry + offset + (offset % 2));
1972 void
1973 bfd_sym_display_name_table (abfd, f)
1974 bfd *abfd;
1975 FILE *f;
1977 unsigned long name_table_len;
1978 unsigned char *name_table, *name_table_end, *cur;
1979 bfd_sym_data_struct *sdata = NULL;
1981 BFD_ASSERT (bfd_sym_valid (abfd));
1982 sdata = abfd->tdata.sym_data;
1984 name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size;
1985 name_table = sdata->name_table;
1986 name_table_end = name_table + name_table_len;
1988 fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
1990 cur = name_table;
1991 for (;;)
1993 cur = bfd_sym_display_name_table_entry (abfd, f, cur);
1994 if (cur >= name_table_end)
1995 break;
1999 void
2000 bfd_sym_display_resources_table (abfd, f)
2001 bfd *abfd;
2002 FILE *f;
2004 unsigned long i;
2005 bfd_sym_resources_table_entry entry;
2006 bfd_sym_data_struct *sdata = NULL;
2008 BFD_ASSERT (bfd_sym_valid (abfd));
2009 sdata = abfd->tdata.sym_data;
2011 fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
2012 sdata->header.dshb_rte.dti_object_count);
2014 for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
2016 if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
2017 fprintf (f, " [%8lu] [INVALID]\n", i);
2018 else
2020 fprintf (f, " [%8lu] ", i);
2021 bfd_sym_print_resources_table_entry (abfd, f, &entry);
2022 fprintf (f, "\n");
2027 void
2028 bfd_sym_display_modules_table (abfd, f)
2029 bfd *abfd;
2030 FILE *f;
2032 unsigned long i;
2033 bfd_sym_modules_table_entry entry;
2034 bfd_sym_data_struct *sdata = NULL;
2036 BFD_ASSERT (bfd_sym_valid (abfd));
2037 sdata = abfd->tdata.sym_data;
2039 fprintf (f, "module table (MTE) contains %lu objects:\n\n",
2040 sdata->header.dshb_mte.dti_object_count);
2042 for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
2044 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
2045 fprintf (f, " [%8lu] [INVALID]\n", i);
2046 else
2048 fprintf (f, " [%8lu] ", i);
2049 bfd_sym_print_modules_table_entry (abfd, f, &entry);
2050 fprintf (f, "\n");
2055 void
2056 bfd_sym_display_file_references_table (abfd, f)
2057 bfd *abfd;
2058 FILE *f;
2060 unsigned long i;
2061 bfd_sym_file_references_table_entry entry;
2062 bfd_sym_data_struct *sdata = NULL;
2064 BFD_ASSERT (bfd_sym_valid (abfd));
2065 sdata = abfd->tdata.sym_data;
2067 fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
2068 sdata->header.dshb_frte.dti_object_count);
2070 for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
2072 if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
2073 fprintf (f, " [%8lu] [INVALID]\n", i);
2074 else
2076 fprintf (f, " [%8lu] ", i);
2077 bfd_sym_print_file_references_table_entry (abfd, f, &entry);
2078 fprintf (f, "\n");
2083 void
2084 bfd_sym_display_contained_modules_table (abfd, f)
2085 bfd *abfd;
2086 FILE *f;
2088 unsigned long i;
2089 bfd_sym_contained_modules_table_entry entry;
2090 bfd_sym_data_struct *sdata = NULL;
2092 BFD_ASSERT (bfd_sym_valid (abfd));
2093 sdata = abfd->tdata.sym_data;
2095 fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
2096 sdata->header.dshb_cmte.dti_object_count);
2098 for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
2100 if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
2101 fprintf (f, " [%8lu] [INVALID]\n", i);
2102 else
2104 fprintf (f, " [%8lu] ", i);
2105 bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
2106 fprintf (f, "\n");
2111 void
2112 bfd_sym_display_contained_variables_table (abfd, f)
2113 bfd *abfd;
2114 FILE *f;
2116 unsigned long i;
2117 bfd_sym_contained_variables_table_entry entry;
2118 bfd_sym_data_struct *sdata = NULL;
2120 BFD_ASSERT (bfd_sym_valid (abfd));
2121 sdata = abfd->tdata.sym_data;
2123 fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
2124 sdata->header.dshb_cvte.dti_object_count);
2126 for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
2128 if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
2129 fprintf (f, " [%8lu] [INVALID]\n", i);
2130 else
2132 fprintf (f, " [%8lu] ", i);
2133 bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
2134 fprintf (f, "\n");
2138 fprintf (f, "\n");
2141 void
2142 bfd_sym_display_contained_statements_table (abfd, f)
2143 bfd *abfd;
2144 FILE *f;
2146 unsigned long i;
2147 bfd_sym_contained_statements_table_entry entry;
2148 bfd_sym_data_struct *sdata = NULL;
2150 BFD_ASSERT (bfd_sym_valid (abfd));
2151 sdata = abfd->tdata.sym_data;
2153 fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
2154 sdata->header.dshb_csnte.dti_object_count);
2156 for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
2158 if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
2159 fprintf (f, " [%8lu] [INVALID]\n", i);
2160 else
2162 fprintf (f, " [%8lu] ", i);
2163 bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
2164 fprintf (f, "\n");
2169 void
2170 bfd_sym_display_contained_labels_table (abfd, f)
2171 bfd *abfd;
2172 FILE *f;
2174 unsigned long i;
2175 bfd_sym_contained_labels_table_entry entry;
2176 bfd_sym_data_struct *sdata = NULL;
2178 BFD_ASSERT (bfd_sym_valid (abfd));
2179 sdata = abfd->tdata.sym_data;
2181 fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
2182 sdata->header.dshb_clte.dti_object_count);
2184 for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
2186 if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
2187 fprintf (f, " [%8lu] [INVALID]\n", i);
2188 else
2190 fprintf (f, " [%8lu] ", i);
2191 bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
2192 fprintf (f, "\n");
2197 void
2198 bfd_sym_display_contained_types_table (abfd, f)
2199 bfd *abfd;
2200 FILE *f;
2202 unsigned long i;
2203 bfd_sym_contained_types_table_entry entry;
2204 bfd_sym_data_struct *sdata = NULL;
2206 BFD_ASSERT (bfd_sym_valid (abfd));
2207 sdata = abfd->tdata.sym_data;
2209 fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
2210 sdata->header.dshb_ctte.dti_object_count);
2212 for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
2214 if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
2215 fprintf (f, " [%8lu] [INVALID]\n", i);
2216 else
2218 fprintf (f, " [%8lu] ", i);
2219 bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
2220 fprintf (f, "\n");
2225 void
2226 bfd_sym_display_file_references_index_table (abfd, f)
2227 bfd *abfd;
2228 FILE *f;
2230 unsigned long i;
2231 bfd_sym_file_references_index_table_entry entry;
2232 bfd_sym_data_struct *sdata = NULL;
2234 BFD_ASSERT (bfd_sym_valid (abfd));
2235 sdata = abfd->tdata.sym_data;
2237 fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
2238 sdata->header.dshb_fite.dti_object_count);
2240 for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
2242 if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
2243 fprintf (f, " [%8lu] [INVALID]\n", i);
2244 else
2246 fprintf (f, " [%8lu] ", i);
2247 bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
2248 fprintf (f, "\n");
2253 void
2254 bfd_sym_display_constant_pool (abfd, f)
2255 bfd *abfd;
2256 FILE *f;
2258 unsigned long i;
2259 bfd_sym_constant_pool_entry entry;
2260 bfd_sym_data_struct *sdata = NULL;
2262 BFD_ASSERT (bfd_sym_valid (abfd));
2263 sdata = abfd->tdata.sym_data;
2265 fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
2266 sdata->header.dshb_const.dti_object_count);
2268 for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
2270 if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
2271 fprintf (f, " [%8lu] [INVALID]\n", i);
2272 else
2274 fprintf (f, " [%8lu] ", i);
2275 bfd_sym_print_constant_pool_entry (abfd, f, &entry);
2276 fprintf (f, "\n");
2281 void
2282 bfd_sym_display_type_information_table (abfd, f)
2283 bfd *abfd;
2284 FILE *f;
2286 unsigned long i;
2287 bfd_sym_type_table_entry index;
2288 bfd_sym_type_information_table_entry entry;
2289 bfd_sym_data_struct *sdata = NULL;
2291 BFD_ASSERT (bfd_sym_valid (abfd));
2292 sdata = abfd->tdata.sym_data;
2294 if (sdata->header.dshb_tte.dti_object_count > 99)
2295 fprintf (f, "type table (TINFO) contains %lu objects:\n\n",
2296 sdata->header.dshb_tte.dti_object_count - 99);
2297 else
2299 fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
2300 return;
2303 for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
2305 if (bfd_sym_fetch_type_table_entry (abfd, &index, i - 100) < 0)
2306 fprintf (f, " [%8lu] [INVALID]\n", i);
2307 else
2309 fprintf (f, " [%8lu] (TINFO %lu) ", i, index);
2311 if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, index) < 0)
2312 fprintf (f, "[INVALID]");
2313 else
2314 bfd_sym_print_type_information_table_entry (abfd, f, &entry);
2316 fprintf (f, "\n");
2322 bfd_sym_scan (abfd, version, mdata)
2323 bfd *abfd;
2324 bfd_sym_version version;
2325 bfd_sym_data_struct *mdata;
2327 asection *bfdsec;
2328 const char *name = "symbols";
2330 mdata->name_table = 0;
2331 mdata->sbfd = abfd;
2332 mdata->version = version;
2334 bfd_seek (abfd, 0, SEEK_SET);
2335 if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
2336 return -1;
2338 mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
2339 if (mdata->name_table == NULL)
2340 return -1;
2342 bfdsec = bfd_make_section_anyway (abfd, name);
2343 if (bfdsec == NULL)
2344 return -1;
2346 bfdsec->vma = 0;
2347 bfdsec->lma = 0;
2348 bfdsec->_raw_size = 0;
2349 bfdsec->filepos = 0;
2350 bfdsec->alignment_power = 0;
2352 bfdsec->flags = SEC_HAS_CONTENTS;
2354 abfd->tdata.sym_data = mdata;
2356 return 0;
2359 const bfd_target *
2360 bfd_sym_object_p (abfd)
2361 bfd *abfd;
2363 struct bfd_preserve preserve;
2364 bfd_sym_version version = -1;
2366 preserve.marker = NULL;
2367 bfd_seek (abfd, 0, SEEK_SET);
2368 if (bfd_sym_read_version (abfd, &version) != 0)
2369 goto wrong;
2371 preserve.marker = bfd_alloc (abfd, sizeof (bfd_sym_data_struct));
2372 if (preserve.marker == NULL
2373 || ! bfd_preserve_save (abfd, &preserve))
2374 goto fail;
2376 if (bfd_sym_scan (abfd, version,
2377 (bfd_sym_data_struct *) preserve.marker) != 0)
2378 goto wrong;
2380 bfd_preserve_finish (abfd, &preserve);
2381 return abfd->xvec;
2383 wrong:
2384 bfd_set_error (bfd_error_wrong_format);
2386 fail:
2387 if (preserve.marker != NULL)
2388 bfd_preserve_restore (abfd, &preserve);
2389 return NULL;
2392 asymbol *
2393 bfd_sym_make_empty_symbol (abfd)
2394 bfd *abfd;
2396 return (asymbol *) bfd_alloc (abfd, sizeof (asymbol));
2399 void
2400 bfd_sym_get_symbol_info (abfd, symbol, ret)
2401 bfd *abfd ATTRIBUTE_UNUSED;
2402 asymbol *symbol;
2403 symbol_info *ret;
2405 bfd_symbol_info (symbol, ret);
2408 long
2409 bfd_sym_get_symtab_upper_bound (abfd)
2410 bfd *abfd ATTRIBUTE_UNUSED;
2412 return 0;
2415 long
2416 bfd_sym_canonicalize_symtab (abfd, sym)
2417 bfd *abfd ATTRIBUTE_UNUSED;
2418 asymbol **sym ATTRIBUTE_UNUSED;
2420 return 0;
2424 bfd_sym_sizeof_headers (abfd, exec)
2425 bfd *abfd ATTRIBUTE_UNUSED;
2426 bfd_boolean exec ATTRIBUTE_UNUSED;
2428 return 0;
2431 const bfd_target sym_vec =
2433 "sym", /* name */
2434 bfd_target_sym_flavour, /* flavour */
2435 BFD_ENDIAN_BIG, /* byteorder */
2436 BFD_ENDIAN_BIG, /* header_byteorder */
2437 (HAS_RELOC | EXEC_P | /* object flags */
2438 HAS_LINENO | HAS_DEBUG |
2439 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2440 (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
2441 | SEC_ROM | SEC_HAS_CONTENTS), /* section_flags */
2442 0, /* symbol_leading_char */
2443 ' ', /* ar_pad_char */
2444 16, /* ar_max_namelen */
2445 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2446 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2447 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
2448 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2449 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2450 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
2451 { /* bfd_check_format */
2452 _bfd_dummy_target,
2453 bfd_sym_object_p, /* bfd_check_format */
2454 _bfd_dummy_target,
2455 _bfd_dummy_target,
2457 { /* bfd_set_format */
2458 bfd_false,
2459 bfd_sym_mkobject,
2460 bfd_false,
2461 bfd_false,
2463 { /* bfd_write_contents */
2464 bfd_false,
2465 bfd_true,
2466 bfd_false,
2467 bfd_false,
2470 BFD_JUMP_TABLE_GENERIC (bfd_sym),
2471 BFD_JUMP_TABLE_COPY (_bfd_generic),
2472 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2473 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
2474 BFD_JUMP_TABLE_SYMBOLS (bfd_sym),
2475 BFD_JUMP_TABLE_RELOCS (bfd_sym),
2476 BFD_JUMP_TABLE_WRITE (bfd_sym),
2477 BFD_JUMP_TABLE_LINK (bfd_sym),
2478 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2480 NULL,
2482 NULL