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