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