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