OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [bfd/] [xsym.c] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.