OSDN Git Service

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