Back to index

cell-binutils  2.17cvs20070401
xsym.c
Go to the documentation of this file.
00001 /* xSYM symbol-file support for BFD.
00002    Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
00003    Free Software Foundation, Inc.
00004 
00005    This file is part of BFD, the Binary File Descriptor library.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 #include "xsym.h"
00022 #include "bfd.h"
00023 #include "sysdep.h"
00024 #include "libbfd.h"
00025 
00026 #define bfd_sym_close_and_cleanup                   _bfd_generic_close_and_cleanup
00027 #define bfd_sym_bfd_free_cached_info                _bfd_generic_bfd_free_cached_info
00028 #define bfd_sym_new_section_hook                    _bfd_generic_new_section_hook
00029 #define bfd_sym_bfd_is_local_label_name             bfd_generic_is_local_label_name
00030 #define bfd_sym_bfd_is_target_special_symbol       ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
00031 #define bfd_sym_get_lineno                          _bfd_nosymbols_get_lineno
00032 #define bfd_sym_find_nearest_line                   _bfd_nosymbols_find_nearest_line
00033 #define bfd_sym_find_inliner_info                   _bfd_nosymbols_find_inliner_info
00034 #define bfd_sym_bfd_make_debug_symbol               _bfd_nosymbols_bfd_make_debug_symbol
00035 #define bfd_sym_read_minisymbols                    _bfd_generic_read_minisymbols
00036 #define bfd_sym_minisymbol_to_symbol                _bfd_generic_minisymbol_to_symbol
00037 #define bfd_sym_set_arch_mach                       _bfd_generic_set_arch_mach
00038 #define bfd_sym_get_section_contents                _bfd_generic_get_section_contents
00039 #define bfd_sym_set_section_contents                _bfd_generic_set_section_contents
00040 #define bfd_sym_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
00041 #define bfd_sym_bfd_relax_section                   bfd_generic_relax_section
00042 #define bfd_sym_bfd_gc_sections                     bfd_generic_gc_sections
00043 #define bfd_sym_bfd_merge_sections                  bfd_generic_merge_sections
00044 #define bfd_sym_bfd_is_group_section                bfd_generic_is_group_section
00045 #define bfd_sym_bfd_discard_group                   bfd_generic_discard_group
00046 #define bfd_sym_section_already_linked              _bfd_generic_section_already_linked
00047 #define bfd_sym_bfd_link_hash_table_create          _bfd_generic_link_hash_table_create
00048 #define bfd_sym_bfd_link_hash_table_free            _bfd_generic_link_hash_table_free
00049 #define bfd_sym_bfd_link_add_symbols                _bfd_generic_link_add_symbols
00050 #define bfd_sym_bfd_link_just_syms                  _bfd_generic_link_just_syms
00051 #define bfd_sym_bfd_final_link                      _bfd_generic_final_link
00052 #define bfd_sym_bfd_link_split_section              _bfd_generic_link_split_section
00053 #define bfd_sym_get_section_contents_in_window      _bfd_generic_get_section_contents_in_window
00054 
00055 extern const bfd_target sym_vec;
00056 
00057 static int
00058 pstrcmp (const char *as, const char *bs)
00059 {
00060   const unsigned char *a = (const unsigned char *) as;
00061   const unsigned char *b = (const unsigned char *) bs;
00062   unsigned char clen;
00063   int ret;
00064 
00065   clen = (a[0] > b[0]) ? b[0] : a[0];
00066   ret = memcmp (a + 1, b + 1, clen);
00067   if (ret != 0)
00068     return ret;
00069 
00070   if (a[0] == b[0])
00071     return 0;
00072   else if (a[0] < b[0])
00073     return -1;
00074   else
00075     return 1;
00076 }
00077 
00078 static unsigned long
00079 compute_offset (unsigned long first_page,
00080               unsigned long page_size,
00081               unsigned long entry_size,
00082               unsigned long index)
00083 {
00084   unsigned long entries_per_page = page_size / entry_size;
00085   unsigned long page_number = first_page + (index / entries_per_page);
00086   unsigned long page_offset = (index % entries_per_page) * entry_size;
00087 
00088   return (page_number * page_size) + page_offset;
00089 }
00090 
00091 bfd_boolean
00092 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
00093 {
00094   return 1;
00095 }
00096 
00097 void
00098 bfd_sym_print_symbol (bfd *abfd ATTRIBUTE_UNUSED,
00099                     void * afile ATTRIBUTE_UNUSED,
00100                     asymbol *symbol ATTRIBUTE_UNUSED,
00101                     bfd_print_symbol_type how ATTRIBUTE_UNUSED)
00102 {
00103   return;
00104 }
00105 
00106 bfd_boolean
00107 bfd_sym_valid (bfd *abfd)
00108 {
00109   if (abfd == NULL || abfd->xvec == NULL)
00110     return 0;
00111 
00112   return abfd->xvec == &sym_vec;
00113 }
00114 
00115 unsigned char *
00116 bfd_sym_read_name_table (bfd *abfd, bfd_sym_header_block *dshb)
00117 {
00118   unsigned char *rstr;
00119   long ret;
00120   size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size;
00121   size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size;
00122 
00123   rstr = bfd_alloc (abfd, table_size);
00124   if (rstr == NULL)
00125     return rstr;
00126 
00127   bfd_seek (abfd, table_offset, SEEK_SET);
00128   ret = bfd_bread (rstr, table_size, abfd);
00129   if (ret < 0 || (unsigned long) ret != table_size)
00130     {
00131       bfd_release (abfd, rstr);
00132       return NULL;
00133     }
00134 
00135   return rstr;
00136 }
00137 
00138 void
00139 bfd_sym_parse_file_reference_v32 (unsigned char *buf,
00140                               size_t len,
00141                               bfd_sym_file_reference *entry)
00142 {
00143   BFD_ASSERT (len == 6);
00144 
00145   entry->fref_frte_index = bfd_getb16 (buf);
00146   entry->fref_offset = bfd_getb32 (buf + 2);
00147 }
00148 
00149 void
00150 bfd_sym_parse_disk_table_v32 (unsigned char *buf,
00151                            size_t len,
00152                            bfd_sym_table_info *table)
00153 {
00154   BFD_ASSERT (len == 8);
00155 
00156   table->dti_first_page = bfd_getb16 (buf);
00157   table->dti_page_count = bfd_getb16 (buf + 2);
00158   table->dti_object_count = bfd_getb32 (buf + 4);
00159 }
00160 
00161 void
00162 bfd_sym_parse_header_v32 (unsigned char *buf,
00163                        size_t len,
00164                        bfd_sym_header_block *header)
00165 {
00166   BFD_ASSERT (len == 154);
00167 
00168   memcpy (header->dshb_id, buf, 32);
00169   header->dshb_page_size = bfd_getb16 (buf + 32);
00170   header->dshb_hash_page = bfd_getb16 (buf + 34);
00171   header->dshb_root_mte = bfd_getb16 (buf + 36);
00172   header->dshb_mod_date = bfd_getb32 (buf + 38);
00173 
00174   bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte);
00175   bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte);
00176   bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte);
00177   bfd_sym_parse_disk_table_v32 (buf + 66, 8, &header->dshb_cmte);
00178   bfd_sym_parse_disk_table_v32 (buf + 74, 8, &header->dshb_cvte);
00179   bfd_sym_parse_disk_table_v32 (buf + 82, 8, &header->dshb_csnte);
00180   bfd_sym_parse_disk_table_v32 (buf + 90, 8, &header->dshb_clte);
00181   bfd_sym_parse_disk_table_v32 (buf + 98, 8, &header->dshb_ctte);
00182   bfd_sym_parse_disk_table_v32 (buf + 106, 8, &header->dshb_tte);
00183   bfd_sym_parse_disk_table_v32 (buf + 114, 8, &header->dshb_nte);
00184   bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo);
00185   bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite);
00186   bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const);
00187 
00188   memcpy (&header->dshb_file_creator, buf + 146, 4);
00189   memcpy (&header->dshb_file_type, buf + 150, 4);
00190 }
00191 
00192 int
00193 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header)
00194 {
00195   unsigned char buf[154];
00196   long ret;
00197 
00198   ret = bfd_bread (buf, 154, abfd);
00199   if (ret != 154)
00200     return -1;
00201 
00202   bfd_sym_parse_header_v32 (buf, 154, header);
00203 
00204   return 0;
00205 }
00206 
00207 int
00208 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED,
00209                       bfd_sym_header_block *header ATTRIBUTE_UNUSED)
00210 {
00211   abort ();
00212 }
00213 
00214 int
00215 bfd_sym_read_header (bfd *abfd,
00216                    bfd_sym_header_block *header,
00217                    bfd_sym_version version)
00218 {
00219   switch (version)
00220     {
00221     case BFD_SYM_VERSION_3_5:
00222     case BFD_SYM_VERSION_3_4:
00223       return bfd_sym_read_header_v34 (abfd, header);
00224     case BFD_SYM_VERSION_3_3:
00225     case BFD_SYM_VERSION_3_2:
00226       return bfd_sym_read_header_v32 (abfd, header);
00227     case BFD_SYM_VERSION_3_1:
00228     default:
00229       return 0;
00230     }
00231 }
00232 
00233 int
00234 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version)
00235 {
00236   char version_string[32];
00237   long ret;
00238 
00239   ret = bfd_bread (version_string, sizeof (version_string), abfd);
00240   if (ret != sizeof (version_string))
00241     return -1;
00242 
00243   if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0)
00244     *version = BFD_SYM_VERSION_3_1;
00245   else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0)
00246     *version = BFD_SYM_VERSION_3_2;
00247   else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0)
00248     *version = BFD_SYM_VERSION_3_3;
00249   else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0)
00250     *version = BFD_SYM_VERSION_3_4;
00251   else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0)
00252     *version = BFD_SYM_VERSION_3_5;
00253   else
00254     return -1;
00255 
00256   return 0;
00257 }
00258 
00259 void
00260 bfd_sym_display_table_summary (FILE *f,
00261                             bfd_sym_table_info *dti,
00262                             const char *name)
00263 {
00264   fprintf (f, "%-6s %13ld %13ld %13ld\n",
00265           name,
00266           dti->dti_first_page,
00267           dti->dti_page_count,
00268           dti->dti_object_count);
00269 }
00270 
00271 void
00272 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb)
00273 {
00274   fprintf (f, "            Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1);
00275   fprintf (f, "          Page Size: 0x%x\n", dshb->dshb_page_size);
00276   fprintf (f, "          Hash Page: %lu\n", dshb->dshb_hash_page);
00277   fprintf (f, "           Root MTE: %lu\n", dshb->dshb_root_mte);
00278   fprintf (f, "  Modification Date: ");
00279   fprintf (f, "[unimplemented]");
00280   fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date);
00281 
00282   fprintf (f, "       File Creator:  %.4s  Type: %.4s\n\n",
00283           dshb->dshb_file_creator, dshb->dshb_file_type);
00284 
00285   fprintf (f, "Table Name   First Page    Page Count   Object Count\n");
00286   fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
00287 
00288   bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE");
00289   bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE");
00290   bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE");
00291   bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE");
00292   bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE");
00293   bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE");
00294   bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE");
00295   bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE");
00296   bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE");
00297   bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE");
00298   bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO");
00299   bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE");
00300   bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST");
00301 
00302   fprintf (f, "\n");
00303 }
00304 
00305 void
00306 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf,
00307                                     size_t len,
00308                                     bfd_sym_resources_table_entry *entry)
00309 {
00310   BFD_ASSERT (len == 18);
00311 
00312   memcpy (&entry->rte_res_type, buf, 4);
00313   entry->rte_res_number = bfd_getb16 (buf + 4);
00314   entry->rte_nte_index = bfd_getb32 (buf + 6);
00315   entry->rte_mte_first = bfd_getb16 (buf + 10);
00316   entry->rte_mte_last = bfd_getb16 (buf + 12);
00317   entry->rte_res_size = bfd_getb32 (buf + 14);
00318 }
00319 
00320 void
00321 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf,
00322                                    size_t len,
00323                                    bfd_sym_modules_table_entry *entry)
00324 {
00325   BFD_ASSERT (len == 46);
00326 
00327   entry->mte_rte_index = bfd_getb16 (buf);
00328   entry->mte_res_offset = bfd_getb32 (buf + 2);
00329   entry->mte_size = bfd_getb32 (buf + 6);
00330   entry->mte_kind = buf[10];
00331   entry->mte_scope = buf[11];
00332   entry->mte_parent = bfd_getb16 (buf + 12);
00333   bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref);
00334   entry->mte_imp_end = bfd_getb32 (buf + 20);
00335   entry->mte_nte_index = bfd_getb32 (buf + 24);
00336   entry->mte_cmte_index = bfd_getb16 (buf + 28);
00337   entry->mte_cvte_index = bfd_getb32 (buf + 30);
00338   entry->mte_clte_index = bfd_getb16 (buf + 34);
00339   entry->mte_ctte_index = bfd_getb16 (buf + 36);
00340   entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38);
00341   entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42);
00342 }
00343 
00344 void
00345 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf,
00346                                           size_t len,
00347                                           bfd_sym_file_references_table_entry *entry)
00348 {
00349   unsigned int type;
00350 
00351   BFD_ASSERT (len == 10);
00352 
00353   memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
00354   type = bfd_getb16 (buf);
00355 
00356   switch (type)
00357     {
00358     case BFD_SYM_END_OF_LIST_3_2:
00359       entry->generic.type = BFD_SYM_END_OF_LIST;
00360       break;
00361 
00362     case BFD_SYM_FILE_NAME_INDEX_3_2:
00363       entry->filename.type = BFD_SYM_FILE_NAME_INDEX;
00364       entry->filename.nte_index = bfd_getb32 (buf + 2);
00365       entry->filename.mod_date = bfd_getb32 (buf + 6);
00366       break;
00367 
00368     default:
00369       entry->entry.mte_index = type;
00370       entry->entry.file_offset = bfd_getb32 (buf + 2);
00371     }
00372 }
00373 
00374 void
00375 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf,
00376                                            size_t len,
00377                                            bfd_sym_contained_modules_table_entry *entry)
00378 {
00379   unsigned int type;
00380 
00381   BFD_ASSERT (len == 6);
00382 
00383   memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
00384   type = bfd_getb16 (buf);
00385 
00386   switch (type)
00387     {
00388     case BFD_SYM_END_OF_LIST_3_2:
00389       entry->generic.type = BFD_SYM_END_OF_LIST;
00390       break;
00391 
00392     default:
00393       entry->entry.mte_index = type;
00394       entry->entry.nte_index = bfd_getb32 (buf + 2);
00395       break;
00396     }
00397 }
00398 
00399 void
00400 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf,
00401                                              size_t len,
00402                                              bfd_sym_contained_variables_table_entry *entry)
00403 {
00404   unsigned int type;
00405 
00406   BFD_ASSERT (len == 26);
00407 
00408   memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
00409   type = bfd_getb16 (buf);
00410 
00411   switch (type)
00412     {
00413     case BFD_SYM_END_OF_LIST_3_2:
00414       entry->generic.type = BFD_SYM_END_OF_LIST;
00415       break;
00416 
00417     case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
00418       entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
00419       bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
00420       break;
00421 
00422     default:
00423       entry->entry.tte_index = type;
00424       entry->entry.nte_index = bfd_getb32 (buf + 2);
00425       entry->entry.file_delta = bfd_getb16 (buf + 6);
00426       entry->entry.scope = buf[8];
00427       entry->entry.la_size = buf[9];
00428 
00429       if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
00430        {
00431          entry->entry.address.scstruct.sca_kind = buf[10];
00432          entry->entry.address.scstruct.sca_class = buf[11];
00433          entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12);
00434        }
00435       else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
00436        {
00437 #if BFD_SYM_CVTE_SCA > 0
00438          memcpy (&entry->entry.address.lastruct.la, buf + 10,
00439                 BFD_SYM_CVTE_SCA);
00440 #endif
00441          entry->entry.address.lastruct.la_kind = buf[23];
00442        }
00443       else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
00444        {
00445          entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
00446          entry->entry.address.biglastruct.big_la_kind = buf[12];
00447        }
00448     }
00449 }
00450 
00451 void
00452 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf,
00453                                               size_t len,
00454                                               bfd_sym_contained_statements_table_entry *entry)
00455 {
00456   unsigned int type;
00457 
00458   BFD_ASSERT (len == 8);
00459 
00460   memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
00461   type = bfd_getb16 (buf);
00462 
00463   switch (type)
00464     {
00465     case BFD_SYM_END_OF_LIST_3_2:
00466       entry->generic.type = BFD_SYM_END_OF_LIST;
00467       break;
00468 
00469     case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
00470       entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
00471       bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
00472       break;
00473 
00474     default:
00475       entry->entry.mte_index = type;
00476       entry->entry.mte_offset = bfd_getb16 (buf + 2);
00477       entry->entry.file_delta = bfd_getb32 (buf + 4);
00478       break;
00479     }
00480 }
00481 
00482 void
00483 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf,
00484                                           size_t len,
00485                                           bfd_sym_contained_labels_table_entry *entry)
00486 {
00487   unsigned int type;
00488 
00489   BFD_ASSERT (len == 12);
00490 
00491   memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
00492   type = bfd_getb16 (buf);
00493 
00494   switch (type)
00495     {
00496     case BFD_SYM_END_OF_LIST_3_2:
00497       entry->generic.type = BFD_SYM_END_OF_LIST;
00498       break;
00499 
00500     case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
00501       entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
00502       bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
00503       break;
00504 
00505     default:
00506       entry->entry.mte_index = type;
00507       entry->entry.mte_offset = bfd_getb16 (buf + 2);
00508       entry->entry.nte_index = bfd_getb32 (buf + 4);
00509       entry->entry.file_delta = bfd_getb16 (buf + 8);
00510       entry->entry.scope = bfd_getb16 (buf + 10);
00511       break;
00512     }
00513 }
00514 
00515 void
00516 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
00517                                 size_t len,
00518                                 bfd_sym_type_table_entry *entry)
00519 {
00520   BFD_ASSERT (len == 4);
00521 
00522   *entry = bfd_getb32 (buf);
00523 }
00524 
00525 int
00526 bfd_sym_fetch_resources_table_entry (bfd *abfd,
00527                                  bfd_sym_resources_table_entry *entry,
00528                                  unsigned long index)
00529 {
00530   void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *);
00531   unsigned long offset;
00532   unsigned long entry_size;
00533   unsigned char buf[18];
00534   bfd_sym_data_struct *sdata = NULL;
00535 
00536   parser = NULL;
00537   BFD_ASSERT (bfd_sym_valid (abfd));
00538   sdata = abfd->tdata.sym_data;
00539 
00540   if (index == 0)
00541     return -1;
00542 
00543   switch (sdata->version)
00544     {
00545     case BFD_SYM_VERSION_3_5:
00546     case BFD_SYM_VERSION_3_4:
00547       return -1;
00548 
00549     case BFD_SYM_VERSION_3_3:
00550     case BFD_SYM_VERSION_3_2:
00551       entry_size = 18;
00552       parser = bfd_sym_parse_resources_table_entry_v32;
00553       break;
00554 
00555     case BFD_SYM_VERSION_3_1:
00556     default:
00557       return -1;
00558     }
00559   if (parser == NULL)
00560     return -1;
00561 
00562   offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
00563                         sdata->header.dshb_page_size,
00564                         entry_size, index);
00565 
00566   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
00567     return -1;
00568   if (bfd_bread (buf, entry_size, abfd) != entry_size)
00569     return -1;
00570 
00571   (*parser) (buf, entry_size, entry);
00572 
00573   return 0;
00574 }
00575 
00576 int
00577 bfd_sym_fetch_modules_table_entry (bfd *abfd,
00578                                bfd_sym_modules_table_entry *entry,
00579                                unsigned long index)
00580 {
00581   void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *);
00582   unsigned long offset;
00583   unsigned long entry_size;
00584   unsigned char buf[46];
00585   bfd_sym_data_struct *sdata = NULL;
00586 
00587   parser = NULL;
00588   BFD_ASSERT (bfd_sym_valid (abfd));
00589   sdata = abfd->tdata.sym_data;
00590 
00591   if (index == 0)
00592     return -1;
00593 
00594   switch (sdata->version)
00595     {
00596     case BFD_SYM_VERSION_3_5:
00597     case BFD_SYM_VERSION_3_4:
00598       return -1;
00599 
00600     case BFD_SYM_VERSION_3_3:
00601       entry_size = 46;
00602       parser = bfd_sym_parse_modules_table_entry_v33;
00603       break;
00604 
00605     case BFD_SYM_VERSION_3_2:
00606     case BFD_SYM_VERSION_3_1:
00607     default:
00608       return -1;
00609     }
00610   if (parser == NULL)
00611     return -1;
00612 
00613   offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
00614                         sdata->header.dshb_page_size,
00615                         entry_size, index);
00616 
00617   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
00618     return -1;
00619   if (bfd_bread (buf, entry_size, abfd) != entry_size)
00620     return -1;
00621 
00622   (*parser) (buf, entry_size, entry);
00623 
00624   return 0;
00625 }
00626 
00627 int
00628 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
00629                                       bfd_sym_file_references_table_entry *entry,
00630                                       unsigned long index)
00631 {
00632   void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *);
00633   unsigned long offset;
00634   unsigned long entry_size = 0;
00635   unsigned char buf[8];
00636   bfd_sym_data_struct *sdata = NULL;
00637 
00638   parser = NULL;
00639   BFD_ASSERT (bfd_sym_valid (abfd));
00640   sdata = abfd->tdata.sym_data;
00641 
00642   if (index == 0)
00643     return -1;
00644 
00645   switch (sdata->version)
00646     {
00647     case BFD_SYM_VERSION_3_3:
00648     case BFD_SYM_VERSION_3_2:
00649       entry_size = 10;
00650       parser = bfd_sym_parse_file_references_table_entry_v32;
00651       break;
00652 
00653     case BFD_SYM_VERSION_3_5:
00654     case BFD_SYM_VERSION_3_4:
00655     case BFD_SYM_VERSION_3_1:
00656     default:
00657       break;
00658     }
00659 
00660   if (parser == NULL)
00661     return -1;
00662 
00663   offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
00664                         sdata->header.dshb_page_size,
00665                         entry_size, index);
00666 
00667   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
00668     return -1;
00669   if (bfd_bread (buf, entry_size, abfd) != entry_size)
00670     return -1;
00671 
00672   (*parser) (buf, entry_size, entry);
00673 
00674   return 0;
00675 }
00676 
00677 int
00678 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
00679                                         bfd_sym_contained_modules_table_entry *entry,
00680                                         unsigned long index)
00681 {
00682   void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *);
00683   unsigned long offset;
00684   unsigned long entry_size = 0;
00685   unsigned char buf[6];
00686   bfd_sym_data_struct *sdata = NULL;
00687 
00688   parser = NULL;
00689   BFD_ASSERT (bfd_sym_valid (abfd));
00690   sdata = abfd->tdata.sym_data;
00691 
00692   if (index == 0)
00693     return -1;
00694 
00695   switch (sdata->version)
00696     {
00697     case BFD_SYM_VERSION_3_3:
00698     case BFD_SYM_VERSION_3_2:
00699       entry_size = 6;
00700       parser = bfd_sym_parse_contained_modules_table_entry_v32;
00701       break;
00702 
00703     case BFD_SYM_VERSION_3_5:
00704     case BFD_SYM_VERSION_3_4:
00705     case BFD_SYM_VERSION_3_1:
00706     default:
00707       break;
00708     }
00709 
00710   if (parser == NULL)
00711     return -1;
00712 
00713   offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
00714                         sdata->header.dshb_page_size,
00715                         entry_size, index);
00716 
00717   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
00718     return -1;
00719   if (bfd_bread (buf, entry_size, abfd) != entry_size)
00720     return -1;
00721 
00722   (*parser) (buf, entry_size, entry);
00723 
00724   return 0;
00725 }
00726 
00727 int
00728 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
00729                                           bfd_sym_contained_variables_table_entry *entry,
00730                                           unsigned long index)
00731 {
00732   void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *);
00733   unsigned long offset;
00734   unsigned long entry_size = 0;
00735   unsigned char buf[26];
00736   bfd_sym_data_struct *sdata = NULL;
00737 
00738   parser = NULL;
00739   BFD_ASSERT (bfd_sym_valid (abfd));
00740   sdata = abfd->tdata.sym_data;
00741 
00742   if (index == 0)
00743     return -1;
00744 
00745   switch (sdata->version)
00746     {
00747     case BFD_SYM_VERSION_3_3:
00748     case BFD_SYM_VERSION_3_2:
00749       entry_size = 26;
00750       parser = bfd_sym_parse_contained_variables_table_entry_v32;
00751       break;
00752 
00753     case BFD_SYM_VERSION_3_5:
00754     case BFD_SYM_VERSION_3_4:
00755     case BFD_SYM_VERSION_3_1:
00756     default:
00757       break;
00758     }
00759 
00760   if (parser == NULL)
00761     return -1;
00762 
00763   offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
00764                         sdata->header.dshb_page_size,
00765                         entry_size, index);
00766 
00767   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
00768     return -1;
00769   if (bfd_bread (buf, entry_size, abfd) != entry_size)
00770     return -1;
00771 
00772   (*parser) (buf, entry_size, entry);
00773 
00774   return 0;
00775 }
00776 
00777 int
00778 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
00779                                           bfd_sym_contained_statements_table_entry *entry,
00780                                           unsigned long index)
00781 {
00782   void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *);
00783   unsigned long offset;
00784   unsigned long entry_size = 0;
00785   unsigned char buf[8];
00786   bfd_sym_data_struct *sdata = NULL;
00787 
00788   parser = NULL;
00789   BFD_ASSERT (bfd_sym_valid (abfd));
00790   sdata = abfd->tdata.sym_data;
00791 
00792   if (index == 0)
00793     return -1;
00794 
00795   switch (sdata->version)
00796     {
00797     case BFD_SYM_VERSION_3_3:
00798     case BFD_SYM_VERSION_3_2:
00799       entry_size = 8;
00800       parser = bfd_sym_parse_contained_statements_table_entry_v32;
00801       break;
00802 
00803     case BFD_SYM_VERSION_3_5:
00804     case BFD_SYM_VERSION_3_4:
00805     case BFD_SYM_VERSION_3_1:
00806     default:
00807       break;
00808     }
00809 
00810   if (parser == NULL)
00811     return -1;
00812 
00813   offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
00814                         sdata->header.dshb_page_size,
00815                         entry_size, index);
00816 
00817   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
00818     return -1;
00819   if (bfd_bread (buf, entry_size, abfd) != entry_size)
00820     return -1;
00821 
00822   (*parser) (buf, entry_size, entry);
00823 
00824   return 0;
00825 }
00826 
00827 int
00828 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
00829                                        bfd_sym_contained_labels_table_entry *entry,
00830                                        unsigned long index)
00831 {
00832   void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *);
00833   unsigned long offset;
00834   unsigned long entry_size = 0;
00835   unsigned char buf[12];
00836   bfd_sym_data_struct *sdata = NULL;
00837 
00838   parser = NULL;
00839   BFD_ASSERT (bfd_sym_valid (abfd));
00840   sdata = abfd->tdata.sym_data;
00841 
00842   if (index == 0)
00843     return -1;
00844 
00845   switch (sdata->version)
00846     {
00847     case BFD_SYM_VERSION_3_3:
00848     case BFD_SYM_VERSION_3_2:
00849       entry_size = 12;
00850       parser = bfd_sym_parse_contained_labels_table_entry_v32;
00851       break;
00852 
00853     case BFD_SYM_VERSION_3_5:
00854     case BFD_SYM_VERSION_3_4:
00855     case BFD_SYM_VERSION_3_1:
00856     default:
00857       break;
00858     }
00859 
00860   if (parser == NULL)
00861     return -1;
00862 
00863   offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
00864                         sdata->header.dshb_page_size,
00865                         entry_size, index);
00866 
00867   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
00868     return -1;
00869   if (bfd_bread (buf, entry_size, abfd) != entry_size)
00870     return -1;
00871 
00872   (*parser) (buf, entry_size, entry);
00873 
00874   return 0;
00875 }
00876 
00877 int
00878 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
00879                                       bfd_sym_contained_types_table_entry *entry,
00880                                       unsigned long index)
00881 {
00882   void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *);
00883   unsigned long offset;
00884   unsigned long entry_size = 0;
00885   unsigned char buf[0];
00886   bfd_sym_data_struct *sdata = NULL;
00887 
00888   parser = NULL;
00889   BFD_ASSERT (bfd_sym_valid (abfd));
00890   sdata = abfd->tdata.sym_data;
00891 
00892   if (index == 0)
00893     return -1;
00894 
00895   switch (sdata->version)
00896     {
00897     case BFD_SYM_VERSION_3_3:
00898     case BFD_SYM_VERSION_3_2:
00899       entry_size = 0;
00900       parser = NULL;
00901       break;
00902 
00903     case BFD_SYM_VERSION_3_5:
00904     case BFD_SYM_VERSION_3_4:
00905     case BFD_SYM_VERSION_3_1:
00906     default:
00907       break;
00908     }
00909 
00910   if (parser == NULL)
00911     return -1;
00912 
00913   offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
00914                         sdata->header.dshb_page_size,
00915                         entry_size, index);
00916 
00917   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
00918     return -1;
00919   if (bfd_bread (buf, entry_size, abfd) != entry_size)
00920     return -1;
00921 
00922   (*parser) (buf, entry_size, entry);
00923 
00924   return 0;
00925 }
00926 
00927 int
00928 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
00929                                            bfd_sym_file_references_index_table_entry *entry,
00930                                            unsigned long index)
00931 {
00932   void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *);
00933   unsigned long offset;
00934   unsigned long entry_size = 0;
00935   unsigned char buf[0];
00936   bfd_sym_data_struct *sdata = NULL;
00937 
00938   parser = NULL;
00939   BFD_ASSERT (bfd_sym_valid (abfd));
00940   sdata = abfd->tdata.sym_data;
00941 
00942   if (index == 0)
00943     return -1;
00944 
00945   switch (sdata->version)
00946     {
00947     case BFD_SYM_VERSION_3_3:
00948     case BFD_SYM_VERSION_3_2:
00949       entry_size = 0;
00950       parser = NULL;
00951       break;
00952 
00953     case BFD_SYM_VERSION_3_5:
00954     case BFD_SYM_VERSION_3_4:
00955     case BFD_SYM_VERSION_3_1:
00956     default:
00957       break;
00958     }
00959 
00960   if (parser == NULL)
00961     return -1;
00962 
00963   offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
00964                         sdata->header.dshb_page_size,
00965                         entry_size, index);
00966 
00967   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
00968     return -1;
00969   if (bfd_bread (buf, entry_size, abfd) != entry_size)
00970     return -1;
00971 
00972   (*parser) (buf, entry_size, entry);
00973 
00974   return 0;
00975 }
00976 
00977 int
00978 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
00979                                bfd_sym_constant_pool_entry *entry,
00980                                unsigned long index)
00981 {
00982   void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *);
00983   unsigned long offset;
00984   unsigned long entry_size = 0;
00985   unsigned char buf[0];
00986   bfd_sym_data_struct *sdata = NULL;
00987 
00988   parser = NULL;
00989   BFD_ASSERT (bfd_sym_valid (abfd));
00990   sdata = abfd->tdata.sym_data;
00991 
00992   if (index == 0)
00993     return -1;
00994 
00995   switch (sdata->version)
00996     {
00997     case BFD_SYM_VERSION_3_3:
00998     case BFD_SYM_VERSION_3_2:
00999       entry_size = 0;
01000       parser = NULL;
01001       break;
01002 
01003     case BFD_SYM_VERSION_3_5:
01004     case BFD_SYM_VERSION_3_4:
01005     case BFD_SYM_VERSION_3_1:
01006     default:
01007       break;
01008     }
01009 
01010   if (parser == NULL)
01011     return -1;
01012 
01013   offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
01014                         sdata->header.dshb_page_size,
01015                         entry_size, index);
01016 
01017   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
01018     return -1;
01019   if (bfd_bread (buf, entry_size, abfd) != entry_size)
01020     return -1;
01021 
01022   (*parser) (buf, entry_size, entry);
01023 
01024   return 0;
01025 }
01026 
01027 int
01028 bfd_sym_fetch_type_table_entry (bfd *abfd,
01029                             bfd_sym_type_table_entry *entry,
01030                             unsigned long index)
01031 {
01032   void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *);
01033   unsigned long offset;
01034   unsigned long entry_size = 0;
01035   unsigned char buf[4];
01036   bfd_sym_data_struct *sdata = NULL;
01037 
01038   parser = NULL;
01039   BFD_ASSERT (bfd_sym_valid (abfd));
01040   sdata = abfd->tdata.sym_data;
01041 
01042   switch (sdata->version)
01043     {
01044     case BFD_SYM_VERSION_3_3:
01045     case BFD_SYM_VERSION_3_2:
01046       entry_size = 4;
01047       parser = bfd_sym_parse_type_table_entry_v32;
01048       break;
01049 
01050     case BFD_SYM_VERSION_3_5:
01051     case BFD_SYM_VERSION_3_4:
01052     case BFD_SYM_VERSION_3_1:
01053     default:
01054       break;
01055     }
01056 
01057   if (parser == NULL)
01058     return -1;
01059 
01060   offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
01061                         sdata->header.dshb_page_size,
01062                         entry_size, index);
01063 
01064   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
01065     return -1;
01066   if (bfd_bread (buf, entry_size, abfd) != entry_size)
01067     return -1;
01068 
01069   (*parser) (buf, entry_size, entry);
01070 
01071   return 0;
01072 }
01073 
01074 int
01075 bfd_sym_fetch_type_information_table_entry (bfd *abfd,
01076                                        bfd_sym_type_information_table_entry *entry,
01077                                        unsigned long offset)
01078 {
01079   unsigned char buf[4];
01080   bfd_sym_data_struct *sdata = NULL;
01081 
01082   BFD_ASSERT (bfd_sym_valid (abfd));
01083   sdata = abfd->tdata.sym_data;
01084 
01085   if (offset == 0)
01086     return -1;
01087 
01088   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
01089     return -1;
01090 
01091   if (bfd_bread (buf, 4, abfd) != 4)
01092     return -1;
01093   entry->nte_index = bfd_getb32 (buf);
01094 
01095   if (bfd_bread (buf, 2, abfd) != 2)
01096     return -1;
01097   entry->physical_size = bfd_getb16 (buf);
01098 
01099   if (entry->physical_size & 0x8000)
01100     {
01101       if (bfd_bread (buf, 4, abfd) != 4)
01102        return -1;
01103       entry->physical_size &= 0x7fff;
01104       entry->logical_size = bfd_getb32 (buf);
01105       entry->offset = offset + 10;
01106     }
01107   else
01108     {
01109       if (bfd_bread (buf, 2, abfd) != 2)
01110        return -1;
01111       entry->physical_size &= 0x7fff;
01112       entry->logical_size = bfd_getb16 (buf);
01113       entry->offset = offset + 8;
01114     }
01115 
01116   return 0;
01117 }
01118 
01119 int
01120 bfd_sym_fetch_type_table_information (bfd *abfd,
01121                                   bfd_sym_type_information_table_entry *entry,
01122                                   unsigned long index)
01123 {
01124   bfd_sym_type_table_entry tindex;
01125   bfd_sym_data_struct *sdata = NULL;
01126 
01127   BFD_ASSERT (bfd_sym_valid (abfd));
01128   sdata = abfd->tdata.sym_data;
01129 
01130   if (sdata->header.dshb_tte.dti_object_count <= 99)
01131     return -1;
01132   if (index < 100)
01133     return -1;
01134 
01135   if (bfd_sym_fetch_type_table_entry (abfd, &tindex, index - 100) < 0)
01136     return -1;
01137   if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
01138     return -1;
01139 
01140   return 0;
01141 }
01142 
01143 const unsigned char *
01144 bfd_sym_symbol_name (bfd *abfd, unsigned long index)
01145 {
01146   bfd_sym_data_struct *sdata = NULL;
01147 
01148   BFD_ASSERT (bfd_sym_valid (abfd));
01149   sdata = abfd->tdata.sym_data;
01150 
01151   if (index == 0)
01152     return (const unsigned char *) "";
01153 
01154   index *= 2;
01155   if ((index / sdata->header.dshb_page_size)
01156       > sdata->header.dshb_nte.dti_page_count)
01157     return (const unsigned char *) "\09[INVALID]";
01158 
01159   return (const unsigned char *) sdata->name_table + index;
01160 }
01161 
01162 const unsigned char *
01163 bfd_sym_module_name (bfd *abfd, unsigned long index)
01164 {
01165   bfd_sym_modules_table_entry entry;
01166 
01167   if (bfd_sym_fetch_modules_table_entry (abfd, &entry, index) < 0)
01168     return (const unsigned char *) "\09[INVALID]";
01169 
01170   return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
01171 }
01172 
01173 const char *
01174 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind)
01175 {
01176   switch (kind)
01177     {
01178     case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL";
01179     case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE";
01180     case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE";
01181     case BFD_SYM_STORAGE_KIND_WITH: return "WITH";
01182     default: return "[UNKNOWN]";
01183     }
01184 }
01185 
01186 const char *
01187 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind)
01188 {
01189   switch (kind)
01190     {
01191     case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER";
01192     case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL";
01193     case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE";
01194     case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE";
01195     case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE";
01196     case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT";
01197     case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE";
01198     case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT";
01199     default: return "[UNKNOWN]";
01200     }
01201 }
01202 
01203 const char *
01204 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind)
01205 {
01206   switch (kind)
01207     {
01208     case BFD_SYM_MODULE_KIND_NONE: return "NONE";
01209     case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM";
01210     case BFD_SYM_MODULE_KIND_UNIT: return "UNIT";
01211     case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE";
01212     case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION";
01213     case BFD_SYM_MODULE_KIND_DATA: return "DATA";
01214     case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK";
01215     default: return "[UNKNOWN]";
01216     }
01217 }
01218 
01219 const char *
01220 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope)
01221 {
01222   switch (scope)
01223     {
01224     case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
01225     case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
01226     default:
01227       return "[UNKNOWN]";
01228     }
01229 }
01230 
01231 void
01232 bfd_sym_print_file_reference (bfd *abfd,
01233                            FILE *f,
01234                            bfd_sym_file_reference *entry)
01235 {
01236   bfd_sym_file_references_table_entry frtentry;
01237   int ret;
01238 
01239   ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
01240                                              entry->fref_frte_index);
01241   fprintf (f, "FILE ");
01242 
01243   if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
01244     fprintf (f, "[INVALID]");
01245   else
01246     fprintf (f, "\"%.*s\"",
01247             bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0],
01248             &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]);
01249 
01250   fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
01251 }
01252 
01253 void
01254 bfd_sym_print_resources_table_entry (bfd *abfd,
01255                                  FILE *f,
01256                                  bfd_sym_resources_table_entry *entry)
01257 {
01258   fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu",
01259           bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0],
01260           &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1],
01261           entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number,
01262           entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last);
01263 }
01264 
01265 void
01266 bfd_sym_print_modules_table_entry (bfd *abfd,
01267                                FILE *f,
01268                                bfd_sym_modules_table_entry *entry)
01269 {
01270   fprintf (f, "\"%.*s\" (NTE %lu)",
01271           bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0],
01272           &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1],
01273           entry->mte_nte_index);
01274 
01275   fprintf (f, "\n            ");
01276 
01277   bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref);
01278   fprintf (f, " range %lu -- %lu",
01279           entry->mte_imp_fref.fref_offset, entry->mte_imp_end);
01280 
01281   fprintf (f, "\n            ");
01282 
01283   fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind));
01284   fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope));
01285 
01286   fprintf (f, ", RTE %lu, offset %lu, size %lu",
01287           entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
01288 
01289   fprintf (f, "\n            ");
01290 
01291   fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu",
01292           entry->mte_cmte_index, entry->mte_cvte_index,
01293           entry->mte_clte_index, entry->mte_ctte_index,
01294           entry->mte_csnte_idx_1, entry->mte_csnte_idx_2);
01295 
01296   if (entry->mte_parent != 0)
01297     fprintf (f, ", parent %lu", entry->mte_parent);
01298   else
01299     fprintf (f, ", no parent");
01300 
01301   if (entry->mte_cmte_index != 0)
01302     fprintf (f, ", child %lu", entry->mte_cmte_index);
01303   else
01304     fprintf (f, ", no child");
01305 }
01306 
01307 void
01308 bfd_sym_print_file_references_table_entry (bfd *abfd,
01309                                       FILE *f,
01310                                       bfd_sym_file_references_table_entry *entry)
01311 {
01312   switch (entry->generic.type)
01313     {
01314     case BFD_SYM_FILE_NAME_INDEX:
01315       fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ",
01316               bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0],
01317               &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1],
01318               entry->filename.nte_index);
01319 
01320       fprintf (f, "[UNIMPLEMENTED]");
01321       /* printModDate (entry->filename.mod_date); */
01322       fprintf (f, " (0x%lx)", entry->filename.mod_date);
01323       break;
01324 
01325     case BFD_SYM_END_OF_LIST:
01326       fprintf (f, "END");
01327       break;
01328 
01329     default:
01330       fprintf (f, "\"%.*s\" (MTE %lu), offset %lu",
01331               bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
01332               &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
01333               entry->entry.mte_index,
01334               entry->entry.file_offset);
01335       break;
01336     }
01337 }
01338 
01339 void
01340 bfd_sym_print_contained_modules_table_entry (bfd *abfd,
01341                                         FILE *f,
01342                                         bfd_sym_contained_modules_table_entry *entry)
01343 {
01344   switch (entry->generic.type)
01345     {
01346     case BFD_SYM_END_OF_LIST:
01347       fprintf (f, "END");
01348       break;
01349 
01350     default:
01351       fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)",
01352               bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
01353               &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
01354               entry->entry.mte_index,
01355               entry->entry.nte_index);
01356       break;
01357     }
01358 }
01359 
01360 void
01361 bfd_sym_print_contained_variables_table_entry (bfd *abfd,
01362                                           FILE *f,
01363                                           bfd_sym_contained_variables_table_entry *entry)
01364 {
01365   if (entry->generic.type == BFD_SYM_END_OF_LIST)
01366     {
01367       fprintf (f, "END");
01368       return;
01369     }
01370 
01371   if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
01372     {
01373       bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
01374       fprintf (f, " offset %lu", entry->file.fref.fref_offset);
01375       return;
01376     }
01377 
01378   fprintf (f, "\"%.*s\" (NTE %lu)",
01379           bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0],
01380           &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1],
01381           entry->entry.nte_index);
01382 
01383   fprintf (f, ", TTE %lu", entry->entry.tte_index);
01384   fprintf (f, ", offset %lu", entry->entry.file_delta);
01385   fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope));
01386 
01387   if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
01388     fprintf (f, ", latype %s, laclass %s, laoffset %lu",
01389             bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind),
01390             bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class),
01391             entry->entry.address.scstruct.sca_offset);
01392   else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE)
01393     {
01394       unsigned long i;
01395 
01396       fprintf (f, ", la [");
01397       for (i = 0; i < entry->entry.la_size; i++)
01398        fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]);
01399       fprintf (f, "]");
01400     }
01401   else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
01402     fprintf (f, ", bigla %lu, biglakind %u",
01403             entry->entry.address.biglastruct.big_la,
01404             entry->entry.address.biglastruct.big_la_kind);
01405 
01406   else
01407     fprintf (f, ", la [INVALID]");
01408 }
01409 
01410 void
01411 bfd_sym_print_contained_statements_table_entry (bfd *abfd,
01412                                           FILE *f,
01413                                           bfd_sym_contained_statements_table_entry *entry)
01414 {
01415   if (entry->generic.type == BFD_SYM_END_OF_LIST)
01416     {
01417       fprintf (f, "END");
01418       return;
01419     }
01420 
01421   if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
01422     {
01423       bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
01424       fprintf (f, " offset %lu", entry->file.fref.fref_offset);
01425       return;
01426     }
01427 
01428   fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu",
01429           bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
01430           &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
01431           entry->entry.mte_index,
01432           entry->entry.mte_offset,
01433           entry->entry.file_delta);
01434 }
01435 
01436 void
01437 bfd_sym_print_contained_labels_table_entry (bfd *abfd,
01438                                        FILE *f,
01439                                        bfd_sym_contained_labels_table_entry *entry)
01440 {
01441   if (entry->generic.type == BFD_SYM_END_OF_LIST)
01442     {
01443       fprintf (f, "END");
01444       return;
01445     }
01446 
01447   if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
01448     {
01449       bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
01450       fprintf (f, " offset %lu", entry->file.fref.fref_offset);
01451       return;
01452     }
01453 
01454   fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s",
01455           bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
01456           &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
01457           entry->entry.mte_index,
01458           entry->entry.mte_offset,
01459           entry->entry.file_delta,
01460           bfd_sym_unparse_symbol_scope (entry->entry.scope));
01461 }
01462 
01463 void
01464 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
01465                                       FILE *f,
01466                                       bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED)
01467 {
01468   fprintf (f, "[UNIMPLEMENTED]");
01469 }
01470 
01471 const char *
01472 bfd_sym_type_operator_name (unsigned char num)
01473 {
01474   switch (num)
01475     {
01476     case 1: return "TTE";
01477     case 2: return "PointerTo";
01478     case 3: return "ScalarOf";
01479     case 4: return "ConstantOf";
01480     case 5: return "EnumerationOf";
01481     case 6: return "VectorOf";
01482     case 7: return "RecordOf";
01483     case 8: return "UnionOf";
01484     case 9: return "SubRangeOf";
01485     case 10: return "SetOf";
01486     case 11: return "NamedTypeOf";
01487     case 12: return "ProcOf";
01488     case 13: return "ValueOf";
01489     case 14: return "ArrayOf";
01490     default: return "[UNKNOWN OPERATOR]";
01491     }
01492 }
01493 
01494 const char *
01495 bfd_sym_type_basic_name (unsigned char num)
01496 {
01497   switch (num)
01498     {
01499     case 0: return "void";
01500     case 1: return "pascal string";
01501     case 2: return "unsigned long";
01502     case 3: return "signed long";
01503     case 4: return "extended (10 bytes)";
01504     case 5: return "pascal boolean (1 byte)";
01505     case 6: return "unsigned byte";
01506     case 7: return "signed byte";
01507     case 8: return "character (1 byte)";
01508     case 9: return "wide character (2 bytes)";
01509     case 10: return "unsigned short";
01510     case 11: return "signed short";
01511     case 12: return "singled";
01512     case 13: return "double";
01513     case 14: return "extended (12 bytes)";
01514     case 15: return "computational (8 bytes)";
01515     case 16: return "c string";
01516     case 17: return "as-is string";
01517     default: return "[UNKNOWN BASIC TYPE]";
01518     }
01519 }
01520 
01521 int
01522 bfd_sym_fetch_long (unsigned char *buf,
01523                   unsigned long len,
01524                   unsigned long offset,
01525                   unsigned long *offsetptr,
01526                   long *value)
01527 {
01528   int ret;
01529 
01530   if (offset >= len)
01531     {
01532       *value = 0;
01533       offset += 0;
01534       ret = -1;
01535     }
01536   else if (! (buf[offset] & 0x80))
01537     {
01538       *value = buf[offset];
01539       offset += 1;
01540       ret = 0;
01541     }
01542   else if (buf[offset] == 0xc0)
01543     {
01544       if ((offset + 5) > len)
01545        {
01546          *value = 0;
01547          offset = len;
01548          ret = -1;
01549        }
01550       else
01551        {
01552          *value = bfd_getb32 (buf + offset + 1);
01553          offset += 5;
01554          ret = 0;
01555        }
01556     }
01557   else if ((buf[offset] & 0xc0) == 0xc0)
01558     {
01559       *value =  -(buf[offset] & 0x3f);
01560       offset += 1;
01561       ret = 0;
01562     }
01563   else if ((buf[offset] & 0xc0) == 0x80)
01564     {
01565       if ((offset + 2) > len)
01566        {
01567          *value = 0;
01568          offset = len;
01569          ret = -1;
01570        }
01571       else
01572        {
01573          *value = bfd_getb16 (buf + offset) & 0x3fff;
01574          offset += 2;
01575          ret = 0;
01576        }
01577     }
01578   else
01579     abort ();
01580 
01581   if (offsetptr != NULL)
01582     *offsetptr = offset;
01583 
01584   return ret;
01585 }
01586 
01587 void
01588 bfd_sym_print_type_information (bfd *abfd,
01589                             FILE *f,
01590                             unsigned char *buf,
01591                             unsigned long len,
01592                             unsigned long offset,
01593                             unsigned long *offsetptr)
01594 {
01595   unsigned int type;
01596 
01597   if (offset >= len)
01598     {
01599       fprintf (f, "[NULL]");
01600 
01601       if (offsetptr != NULL)
01602        *offsetptr = offset;
01603       return;
01604   }
01605 
01606   type = buf[offset];
01607   offset++;
01608 
01609   if (! (type & 0x80))
01610     {
01611       fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
01612 
01613       if (offsetptr != NULL)
01614        *offsetptr = offset;
01615       return;
01616     }
01617 
01618   if (type & 0x40)
01619     fprintf (f, "[packed ");
01620   else
01621     fprintf (f, "[");
01622 
01623   switch (type & 0x3f)
01624     {
01625     case 1:
01626       {
01627        long value;
01628        bfd_sym_type_information_table_entry tinfo;
01629 
01630        bfd_sym_fetch_long (buf, len, offset, &offset, &value);
01631        if (value <= 0)
01632          fprintf (f, "[INVALID]");
01633        else
01634          {
01635            if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
01636              fprintf (f, "[INVALID]");
01637            else
01638              fprintf (f, "\"%.*s\"",
01639                      bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
01640                      &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
01641          }
01642        fprintf (f, " (TTE %lu)", value);
01643        break;
01644       }
01645 
01646     case 2:
01647       fprintf (f, "pointer (0x%x) to ", type);
01648       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01649       break;
01650 
01651     case 3:
01652       {
01653        long value;
01654 
01655        fprintf (f, "scalar (0x%x) of ", type);
01656        bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01657        bfd_sym_fetch_long (buf, len, offset, &offset, &value);
01658        fprintf (f, " (%lu)", (unsigned long) value);
01659        break;
01660       }
01661 
01662     case 5:
01663       {
01664        long lower, upper, nelem;
01665        int i;
01666 
01667        fprintf (f, "enumeration (0x%x) of ", type);
01668        bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01669        bfd_sym_fetch_long (buf, len, offset, &offset, &lower);
01670        bfd_sym_fetch_long (buf, len, offset, &offset, &upper);
01671        bfd_sym_fetch_long (buf, len, offset, &offset, &nelem);
01672        fprintf (f, " from %lu to %lu with %lu elements: ",
01673                (unsigned long) lower, (unsigned long) upper,
01674                (unsigned long) nelem);
01675 
01676        for (i = 0; i < nelem; i++)
01677          {
01678            fprintf (f, "\n                    ");
01679            bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01680          }
01681        break;
01682       }
01683 
01684     case 6:
01685       fprintf (f, "vector (0x%x)", type);
01686       fprintf (f, "\n                index ");
01687       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01688       fprintf (f, "\n                target ");
01689       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01690       break;
01691 
01692     case 7:
01693     case 8:
01694       {
01695        long nrec, eloff, i;
01696 
01697        if ((type & 0x3f) == 7)
01698          fprintf (f, "record (0x%x) of ", type);
01699        else
01700          fprintf (f, "union (0x%x) of ", type);
01701 
01702        bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
01703        fprintf (f, "%lu elements: ", nrec);
01704 
01705        for (i = 0; i < nrec; i++)
01706          {
01707            bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
01708            fprintf (f, "\n                ");
01709            fprintf (f, "offset %lu: ", eloff);
01710            bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01711          }
01712        break;
01713       }
01714 
01715     case 9:
01716       fprintf (f, "subrange (0x%x) of ", type);
01717       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01718       fprintf (f, " lower ");
01719       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01720       fprintf (f, " upper ");
01721       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01722       break;
01723 
01724   case 11:
01725     {
01726       long value;
01727 
01728       fprintf (f, "named type (0x%x) ", type);
01729       bfd_sym_fetch_long (buf, len, offset, &offset, &value);
01730       if (value <= 0)
01731        fprintf (f, "[INVALID]");
01732       else
01733        fprintf (f, "\"%.*s\"",
01734                bfd_sym_symbol_name (abfd, value)[0],
01735                &bfd_sym_symbol_name (abfd, value)[1]);
01736 
01737       fprintf (f, " (NTE %lu) with type ", value);
01738       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
01739       break;
01740     }
01741 
01742   default:
01743     fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
01744     break;
01745     }
01746 
01747   if (type == (0x40 | 0x6))
01748     {
01749       /* Vector.  */
01750       long n, width, m;
01751       long l;
01752       long i;
01753 
01754       bfd_sym_fetch_long (buf, len, offset, &offset, &n);
01755       bfd_sym_fetch_long (buf, len, offset, &offset, &width);
01756       bfd_sym_fetch_long (buf, len, offset, &offset, &m);
01757       /* fprintf (f, "\n                "); */
01758       fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m);
01759       for (i = 0; i < m; i++)
01760        {
01761          bfd_sym_fetch_long (buf, len, offset, &offset, &l);
01762          if (i != 0)
01763            fprintf (f, " ");
01764          fprintf (f, "%ld", l);
01765        }
01766     }
01767   else  if (type & 0x40)
01768     {
01769       /* Other packed type.  */
01770       long msb, lsb;
01771 
01772       bfd_sym_fetch_long (buf, len, offset, &offset, &msb);
01773       bfd_sym_fetch_long (buf, len, offset, &offset, &lsb);
01774       /* fprintf (f, "\n                "); */
01775       fprintf (f, " msb %ld, lsb %ld", msb, lsb);
01776     }
01777 
01778   fprintf (f, "]");
01779 
01780   if (offsetptr != NULL)
01781     *offsetptr = offset;
01782 }
01783 
01784 void
01785 bfd_sym_print_type_information_table_entry (bfd *abfd,
01786                                        FILE *f,
01787                                        bfd_sym_type_information_table_entry *entry)
01788 {
01789   unsigned char *buf;
01790   unsigned long offset;
01791   unsigned int i;
01792 
01793   fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu",
01794           bfd_sym_symbol_name (abfd, entry->nte_index)[0],
01795           &bfd_sym_symbol_name (abfd, entry->nte_index)[1],
01796           entry->nte_index,
01797           entry->physical_size, entry->offset, entry->logical_size);
01798 
01799   fprintf (f, "\n            ");
01800 
01801   buf = alloca (entry->physical_size);
01802   if (buf == NULL)
01803     {
01804       fprintf (f, "[ERROR]\n");
01805       return;
01806     }
01807   if (bfd_seek (abfd, entry->offset, SEEK_SET) < 0)
01808     {
01809       fprintf (f, "[ERROR]\n");
01810       return;
01811     }
01812   if (bfd_bread (buf, entry->physical_size, abfd) != entry->physical_size)
01813     {
01814       fprintf (f, "[ERROR]\n");
01815       return;
01816     }
01817 
01818   fprintf (f, "[");
01819   for (i = 0; i < entry->physical_size; i++)
01820     {
01821       if (i == 0)
01822        fprintf (f, "0x%02x", buf[i]);
01823       else
01824        fprintf (f, " 0x%02x", buf[i]);
01825     }
01826 
01827   fprintf (f, "]");
01828   fprintf (f, "\n            ");
01829 
01830   bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
01831 
01832   if (offset != entry->physical_size)
01833     fprintf (f, "\n            [parser used %lu bytes instead of %lu]", offset, entry->physical_size);
01834 }
01835 
01836 void
01837 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
01838                                            FILE *f,
01839                                            bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED)
01840 {
01841   fprintf (f, "[UNIMPLEMENTED]");
01842 }
01843 
01844 void
01845 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED,
01846                                FILE *f,
01847                                bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED)
01848 {
01849   fprintf (f, "[UNIMPLEMENTED]");
01850 }
01851 
01852 unsigned char *
01853 bfd_sym_display_name_table_entry (bfd *abfd,
01854                               FILE *f,
01855                               unsigned char *entry)
01856 {
01857   unsigned long index;
01858   unsigned long offset;
01859   bfd_sym_data_struct *sdata = NULL;
01860 
01861   BFD_ASSERT (bfd_sym_valid (abfd));
01862   sdata = abfd->tdata.sym_data;
01863   index = (entry - sdata->name_table) / 2;
01864 
01865   if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
01866     {
01867       unsigned short length = bfd_getb16 (entry + 2);
01868       fprintf (f, "[%8lu] \"%.*s\"\n", index, length, entry + 4);
01869       offset = 2 + length + 1;
01870     }
01871   else
01872     {
01873       if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
01874        fprintf (f, "[%8lu] \"%.*s\"\n", index, entry[0], entry + 1);
01875 
01876       if (sdata->version >= BFD_SYM_VERSION_3_4)
01877        offset = entry[0] + 2;
01878       else
01879        offset = entry[0] + 1;
01880     }
01881 
01882   return (entry + offset + (offset % 2));
01883 }
01884 
01885 void
01886 bfd_sym_display_name_table (bfd *abfd, FILE *f)
01887 {
01888   unsigned long name_table_len;
01889   unsigned char *name_table, *name_table_end, *cur;
01890   bfd_sym_data_struct *sdata = NULL;
01891 
01892   BFD_ASSERT (bfd_sym_valid (abfd));
01893   sdata = abfd->tdata.sym_data;
01894 
01895   name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size;
01896   name_table = sdata->name_table;
01897   name_table_end = name_table + name_table_len;
01898 
01899   fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
01900 
01901   cur = name_table;
01902   for (;;)
01903     {
01904       cur = bfd_sym_display_name_table_entry (abfd, f, cur);
01905       if (cur >= name_table_end)
01906        break;
01907     }
01908 }
01909 
01910 void
01911 bfd_sym_display_resources_table (bfd *abfd, FILE *f)
01912 {
01913   unsigned long i;
01914   bfd_sym_resources_table_entry entry;
01915   bfd_sym_data_struct *sdata = NULL;
01916 
01917   BFD_ASSERT (bfd_sym_valid (abfd));
01918   sdata = abfd->tdata.sym_data;
01919 
01920   fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
01921           sdata->header.dshb_rte.dti_object_count);
01922 
01923   for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
01924     {
01925       if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
01926        fprintf (f, " [%8lu] [INVALID]\n", i);
01927       else
01928        {
01929          fprintf (f, " [%8lu] ", i);
01930          bfd_sym_print_resources_table_entry (abfd, f, &entry);
01931          fprintf (f, "\n");
01932        }
01933     }
01934 }
01935 
01936 void
01937 bfd_sym_display_modules_table (bfd *abfd, FILE *f)
01938 {
01939   unsigned long i;
01940   bfd_sym_modules_table_entry entry;
01941   bfd_sym_data_struct *sdata = NULL;
01942 
01943   BFD_ASSERT (bfd_sym_valid (abfd));
01944   sdata = abfd->tdata.sym_data;
01945 
01946   fprintf (f, "module table (MTE) contains %lu objects:\n\n",
01947           sdata->header.dshb_mte.dti_object_count);
01948 
01949   for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
01950     {
01951       if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
01952        fprintf (f, " [%8lu] [INVALID]\n", i);
01953       else
01954        {
01955          fprintf (f, " [%8lu] ", i);
01956          bfd_sym_print_modules_table_entry (abfd, f, &entry);
01957          fprintf (f, "\n");
01958        }
01959     }
01960 }
01961 
01962 void
01963 bfd_sym_display_file_references_table (bfd *abfd, FILE *f)
01964 {
01965   unsigned long i;
01966   bfd_sym_file_references_table_entry entry;
01967   bfd_sym_data_struct *sdata = NULL;
01968 
01969   BFD_ASSERT (bfd_sym_valid (abfd));
01970   sdata = abfd->tdata.sym_data;
01971 
01972   fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
01973           sdata->header.dshb_frte.dti_object_count);
01974 
01975   for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
01976     {
01977       if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
01978        fprintf (f, " [%8lu] [INVALID]\n", i);
01979       else
01980        {
01981          fprintf (f, " [%8lu] ", i);
01982          bfd_sym_print_file_references_table_entry (abfd, f, &entry);
01983          fprintf (f, "\n");
01984        }
01985     }
01986 }
01987 
01988 void
01989 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f)
01990 {
01991   unsigned long i;
01992   bfd_sym_contained_modules_table_entry entry;
01993   bfd_sym_data_struct *sdata = NULL;
01994 
01995   BFD_ASSERT (bfd_sym_valid (abfd));
01996   sdata = abfd->tdata.sym_data;
01997 
01998   fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
01999           sdata->header.dshb_cmte.dti_object_count);
02000 
02001   for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
02002     {
02003       if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
02004        fprintf (f, " [%8lu] [INVALID]\n", i);
02005       else
02006        {
02007          fprintf (f, " [%8lu] ", i);
02008          bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
02009          fprintf (f, "\n");
02010        }
02011     }
02012 }
02013 
02014 void
02015 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f)
02016 {
02017   unsigned long i;
02018   bfd_sym_contained_variables_table_entry entry;
02019   bfd_sym_data_struct *sdata = NULL;
02020 
02021   BFD_ASSERT (bfd_sym_valid (abfd));
02022   sdata = abfd->tdata.sym_data;
02023 
02024   fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
02025           sdata->header.dshb_cvte.dti_object_count);
02026 
02027   for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
02028     {
02029       if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
02030        fprintf (f, " [%8lu] [INVALID]\n", i);
02031       else
02032        {
02033          fprintf (f, " [%8lu] ", i);
02034          bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
02035          fprintf (f, "\n");
02036        }
02037     }
02038 
02039   fprintf (f, "\n");
02040 }
02041 
02042 void
02043 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f)
02044 {
02045   unsigned long i;
02046   bfd_sym_contained_statements_table_entry entry;
02047   bfd_sym_data_struct *sdata = NULL;
02048 
02049   BFD_ASSERT (bfd_sym_valid (abfd));
02050   sdata = abfd->tdata.sym_data;
02051 
02052   fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
02053           sdata->header.dshb_csnte.dti_object_count);
02054 
02055   for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
02056     {
02057       if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
02058        fprintf (f, " [%8lu] [INVALID]\n", i);
02059       else
02060        {
02061          fprintf (f, " [%8lu] ", i);
02062          bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
02063          fprintf (f, "\n");
02064        }
02065     }
02066 }
02067 
02068 void
02069 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f)
02070 {
02071   unsigned long i;
02072   bfd_sym_contained_labels_table_entry entry;
02073   bfd_sym_data_struct *sdata = NULL;
02074 
02075   BFD_ASSERT (bfd_sym_valid (abfd));
02076   sdata = abfd->tdata.sym_data;
02077 
02078   fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
02079           sdata->header.dshb_clte.dti_object_count);
02080 
02081   for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
02082     {
02083       if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
02084        fprintf (f, " [%8lu] [INVALID]\n", i);
02085       else
02086        {
02087          fprintf (f, " [%8lu] ", i);
02088          bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
02089          fprintf (f, "\n");
02090        }
02091     }
02092 }
02093 
02094 void
02095 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f)
02096 {
02097   unsigned long i;
02098   bfd_sym_contained_types_table_entry entry;
02099   bfd_sym_data_struct *sdata = NULL;
02100 
02101   BFD_ASSERT (bfd_sym_valid (abfd));
02102   sdata = abfd->tdata.sym_data;
02103 
02104   fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
02105           sdata->header.dshb_ctte.dti_object_count);
02106 
02107   for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
02108     {
02109       if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
02110        fprintf (f, " [%8lu] [INVALID]\n", i);
02111       else
02112        {
02113          fprintf (f, " [%8lu] ", i);
02114          bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
02115          fprintf (f, "\n");
02116        }
02117     }
02118 }
02119 
02120 void
02121 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f)
02122 {
02123   unsigned long i;
02124   bfd_sym_file_references_index_table_entry entry;
02125   bfd_sym_data_struct *sdata = NULL;
02126 
02127   BFD_ASSERT (bfd_sym_valid (abfd));
02128   sdata = abfd->tdata.sym_data;
02129 
02130   fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
02131           sdata->header.dshb_fite.dti_object_count);
02132 
02133   for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
02134     {
02135       if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
02136        fprintf (f, " [%8lu] [INVALID]\n", i);
02137       else
02138        {
02139          fprintf (f, " [%8lu] ", i);
02140          bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
02141          fprintf (f, "\n");
02142        }
02143     }
02144 }
02145 
02146 void
02147 bfd_sym_display_constant_pool (bfd *abfd, FILE *f)
02148 {
02149   unsigned long i;
02150   bfd_sym_constant_pool_entry entry;
02151   bfd_sym_data_struct *sdata = NULL;
02152 
02153   BFD_ASSERT (bfd_sym_valid (abfd));
02154   sdata = abfd->tdata.sym_data;
02155 
02156   fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
02157           sdata->header.dshb_const.dti_object_count);
02158 
02159   for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
02160     {
02161       if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
02162        fprintf (f, " [%8lu] [INVALID]\n", i);
02163       else
02164        {
02165          fprintf (f, " [%8lu] ", i);
02166          bfd_sym_print_constant_pool_entry (abfd, f, &entry);
02167          fprintf (f, "\n");
02168        }
02169     }
02170 }
02171 
02172 void
02173 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
02174 {
02175   unsigned long i;
02176   bfd_sym_type_table_entry index;
02177   bfd_sym_type_information_table_entry entry;
02178   bfd_sym_data_struct *sdata = NULL;
02179 
02180   BFD_ASSERT (bfd_sym_valid (abfd));
02181   sdata = abfd->tdata.sym_data;
02182 
02183   if (sdata->header.dshb_tte.dti_object_count > 99)
02184     fprintf (f, "type table (TINFO) contains %lu objects:\n\n",
02185             sdata->header.dshb_tte.dti_object_count - 99);
02186   else
02187     {
02188       fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
02189       return;
02190     }
02191 
02192   for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
02193     {
02194       if (bfd_sym_fetch_type_table_entry (abfd, &index, i - 100) < 0)
02195        fprintf (f, " [%8lu] [INVALID]\n", i);
02196       else
02197        {
02198          fprintf (f, " [%8lu] (TINFO %lu) ", i, index);
02199 
02200          if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, index) < 0)
02201            fprintf (f, "[INVALID]");
02202          else
02203            bfd_sym_print_type_information_table_entry (abfd, f, &entry);
02204 
02205          fprintf (f, "\n");
02206        }
02207     }
02208 }
02209 
02210 int
02211 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
02212 {
02213   asection *bfdsec;
02214   const char *name = "symbols";
02215 
02216   mdata->name_table = 0;
02217   mdata->sbfd = abfd;
02218   mdata->version = version;
02219 
02220   bfd_seek (abfd, 0, SEEK_SET);
02221   if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
02222     return -1;
02223 
02224   mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
02225   if (mdata->name_table == NULL)
02226     return -1;
02227 
02228   bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS);
02229   if (bfdsec == NULL)
02230     return -1;
02231 
02232   bfdsec->vma = 0;
02233   bfdsec->lma = 0;
02234   bfdsec->size = 0;
02235   bfdsec->filepos = 0;
02236   bfdsec->alignment_power = 0;
02237 
02238   abfd->tdata.sym_data = mdata;
02239 
02240   return 0;
02241 }
02242 
02243 const bfd_target *
02244 bfd_sym_object_p (bfd *abfd)
02245 {
02246   struct bfd_preserve preserve;
02247   bfd_sym_version version = -1;
02248 
02249   preserve.marker = NULL;
02250   bfd_seek (abfd, 0, SEEK_SET);
02251   if (bfd_sym_read_version (abfd, &version) != 0)
02252     goto wrong;
02253 
02254   preserve.marker = bfd_alloc (abfd, sizeof (bfd_sym_data_struct));
02255   if (preserve.marker == NULL
02256       || ! bfd_preserve_save (abfd, &preserve))
02257     goto fail;
02258 
02259   if (bfd_sym_scan (abfd, version,
02260                   (bfd_sym_data_struct *) preserve.marker) != 0)
02261     goto wrong;
02262 
02263   bfd_preserve_finish (abfd, &preserve);
02264   return abfd->xvec;
02265 
02266  wrong:
02267   bfd_set_error (bfd_error_wrong_format);
02268 
02269  fail:
02270   if (preserve.marker != NULL)
02271     bfd_preserve_restore (abfd, &preserve);
02272   return NULL;
02273 }
02274 
02275 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol
02276 
02277 void
02278 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret)
02279 {
02280   bfd_symbol_info (symbol, ret);
02281 }
02282 
02283 long
02284 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED)
02285 {
02286   return 0;
02287 }
02288 
02289 long
02290 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED)
02291 {
02292   return 0;
02293 }
02294 
02295 int
02296 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
02297                      struct bfd_link_info *info ATTRIBUTE_UNUSED)
02298 {
02299   return 0;
02300 }
02301 
02302 const bfd_target sym_vec =
02303 {
02304   "sym",                    /* Name.  */
02305   bfd_target_sym_flavour,   /* Flavour.  */
02306   BFD_ENDIAN_BIG,           /* Byteorder.  */
02307   BFD_ENDIAN_BIG,           /* Header byteorder.  */
02308   (HAS_RELOC | EXEC_P |            /* Object flags.  */
02309    HAS_LINENO | HAS_DEBUG |
02310    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
02311   (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
02312    | SEC_ROM | SEC_HAS_CONTENTS), /* Section_flags.  */
02313   0,                        /* Symbol_leading_char.  */
02314   ' ',                      /* AR_pad_char.  */
02315   16,                       /* AR_max_namelen.  */
02316   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
02317   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
02318   bfd_getb16, bfd_getb_signed_16, bfd_putb16,    /* Data.  */
02319   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
02320   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
02321   bfd_getb16, bfd_getb_signed_16, bfd_putb16,    /* Hdrs.  */
02322   {                         /* bfd_check_format.  */
02323     _bfd_dummy_target,
02324     bfd_sym_object_p,              /* bfd_check_format.  */
02325     _bfd_dummy_target,
02326     _bfd_dummy_target,
02327   },
02328   {                         /* bfd_set_format.  */
02329     bfd_false,
02330     bfd_sym_mkobject,
02331     bfd_false,
02332     bfd_false,
02333   },
02334   {                         /* bfd_write_contents.  */
02335     bfd_false,
02336     bfd_true,
02337     bfd_false,
02338     bfd_false,
02339   },
02340 
02341   BFD_JUMP_TABLE_GENERIC (bfd_sym),
02342   BFD_JUMP_TABLE_COPY (_bfd_generic),
02343   BFD_JUMP_TABLE_CORE (_bfd_nocore),
02344   BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
02345   BFD_JUMP_TABLE_SYMBOLS (bfd_sym),
02346   BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
02347   BFD_JUMP_TABLE_WRITE (bfd_sym),
02348   BFD_JUMP_TABLE_LINK (bfd_sym),
02349   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
02350 
02351   NULL,
02352 
02353   NULL
02354 };