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