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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [dstread.c] - Blame information for rev 1774

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

Line No. Rev Author Line
1 104 markom
/* Read apollo DST symbol tables and convert to internal format, for GDB.
2
   Contributed by Troy Rollo, University of NSW (troy@cbme.unsw.edu.au).
3
   Copyright 1993 Free Software Foundation, Inc.
4
 
5
   This file is part of GDB.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 59 Temple Place - Suite 330,
20
   Boston, MA 02111-1307, USA.  */
21
 
22
#include "defs.h"
23
#include "symtab.h"
24
#include "gdbtypes.h"
25
#include "breakpoint.h"
26
#include "bfd.h"
27
#include "symfile.h"
28
#include "objfiles.h"
29
#include "buildsym.h"
30
#include "obstack.h"
31
 
32
#include "gdb_string.h"
33
 
34
#include "dst.h"
35
 
36
CORE_ADDR cur_src_start_addr, cur_src_end_addr;
37
dst_sec blocks_info, lines_info, symbols_info;
38
 
39
/* Vector of line number information.  */
40
 
41
static struct linetable *line_vector;
42
 
43
/* Index of next entry to go in line_vector_index.  */
44
 
45
static int line_vector_index;
46
 
47
/* Last line number recorded in the line vector.  */
48
 
49
static int prev_line_number;
50
 
51
/* Number of elements allocated for line_vector currently.  */
52
 
53
static int line_vector_length;
54
 
55
static int
56
init_dst_sections PARAMS ((int));
57
 
58
static void
59
read_dst_symtab PARAMS ((struct objfile *));
60
 
61
static void
62
find_dst_sections PARAMS ((bfd *, sec_ptr, PTR));
63
 
64
static void
65
dst_symfile_init PARAMS ((struct objfile *));
66
 
67
static void
68
dst_new_init PARAMS ((struct objfile *));
69
 
70
static void
71
dst_symfile_read PARAMS ((struct objfile *, int));
72
 
73
static void
74
dst_symfile_finish PARAMS ((struct objfile *));
75
 
76
static void
77
dst_end_symtab PARAMS ((struct objfile *));
78
 
79
static void
80
complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
81
 
82
static void
83
dst_start_symtab PARAMS ((void));
84
 
85
static void
86
dst_record_line PARAMS ((int, CORE_ADDR));
87
 
88
/* Manage the vector of line numbers.  */
89
/* FIXME: Use record_line instead.  */
90
 
91
static void
92
dst_record_line (line, pc)
93
     int line;
94
     CORE_ADDR pc;
95
{
96
  struct linetable_entry *e;
97
  /* Make sure line vector is big enough.  */
98
 
99
  if (line_vector_index + 2 >= line_vector_length)
100
    {
101
      line_vector_length *= 2;
102
      line_vector = (struct linetable *)
103
        xrealloc ((char *) line_vector, sizeof (struct linetable)
104
                  + (line_vector_length
105
                     * sizeof (struct linetable_entry)));
106
    }
107
 
108
  e = line_vector->item + line_vector_index++;
109
  e->line = line;
110
  e->pc = pc;
111
}
112
 
113
/* Start a new symtab for a new source file.
114
   It indicates the start of data for one original source file.  */
115
/* FIXME: use start_symtab, like coffread.c now does.  */
116
 
117
static void
118
dst_start_symtab ()
119
{
120
  /* Initialize the source file line number information for this file.  */
121
 
122
  if (line_vector)              /* Unlikely, but maybe possible? */
123
    free ((PTR) line_vector);
124
  line_vector_index = 0;
125
  line_vector_length = 1000;
126
  prev_line_number = -2;        /* Force first line number to be explicit */
127
  line_vector = (struct linetable *)
128
    xmalloc (sizeof (struct linetable)
129
             + line_vector_length * sizeof (struct linetable_entry));
130
}
131
 
132
/* Save the vital information from when starting to read a file,
133
   for use when closing off the current file.
134
   NAME is the file name the symbols came from, START_ADDR is the first
135
   text address for the file, and SIZE is the number of bytes of text.  */
136
 
137
static void
138
complete_symtab (name, start_addr, size)
139
     char *name;
140
     CORE_ADDR start_addr;
141
     unsigned int size;
142
{
143
  last_source_file = savestring (name, strlen (name));
144
  cur_src_start_addr = start_addr;
145
  cur_src_end_addr = start_addr + size;
146
 
147
  if (current_objfile->ei.entry_point >= cur_src_start_addr &&
148
      current_objfile->ei.entry_point < cur_src_end_addr)
149
    {
150
      current_objfile->ei.entry_file_lowpc = cur_src_start_addr;
151
      current_objfile->ei.entry_file_highpc = cur_src_end_addr;
152
    }
153
}
154
 
155
/* Finish the symbol definitions for one main source file,
156
   close off all the lexical contexts for that file
157
   (creating struct block's for them), then make the
158
   struct symtab for that file and put it in the list of all such. */
159
/* FIXME: Use end_symtab, like coffread.c now does.  */
160
 
161
static void
162
dst_end_symtab (objfile)
163
     struct objfile *objfile;
164
{
165
  register struct symtab *symtab;
166
  register struct blockvector *blockvector;
167
  register struct linetable *lv;
168
 
169
  /* Create the blockvector that points to all the file's blocks.  */
170
 
171
  blockvector = make_blockvector (objfile);
172
 
173
  /* Now create the symtab object for this source file.  */
174
  symtab = allocate_symtab (last_source_file, objfile);
175
 
176
  /* Fill in its components.  */
177
  symtab->blockvector = blockvector;
178
  symtab->free_code = free_linetable;
179
  symtab->free_ptr = 0;
180
  symtab->filename = last_source_file;
181
  symtab->dirname = NULL;
182
  symtab->debugformat = obsavestring ("Apollo DST", 10,
183
                                      &objfile->symbol_obstack);
184
  lv = line_vector;
185
  lv->nitems = line_vector_index;
186
  symtab->linetable = (struct linetable *)
187
    xrealloc ((char *) lv, (sizeof (struct linetable)
188
                            + lv->nitems * sizeof (struct linetable_entry)));
189
 
190
  free_named_symtabs (symtab->filename);
191
 
192
  /* Reinitialize for beginning of new file. */
193
  line_vector = 0;
194
  line_vector_length = -1;
195
  last_source_file = NULL;
196
}
197
 
198
/* dst_symfile_init ()
199
   is the dst-specific initialization routine for reading symbols.
200
 
201
   We will only be called if this is a DST or DST-like file.
202
   BFD handles figuring out the format of the file, and code in symtab.c
203
   uses BFD's determination to vector to us.
204
 
205
   The ultimate result is a new symtab (or, FIXME, eventually a psymtab).  */
206
 
207
static void
208
dst_symfile_init (objfile)
209
     struct objfile *objfile;
210
{
211
  asection *section;
212
  bfd *abfd = objfile->obfd;
213
 
214
  init_entry_point_info (objfile);
215
 
216
}
217
 
218
/* This function is called for every section; it finds the outer limits
219
   of the line table (minimum and maximum file offset) so that the
220
   mainline code can read the whole thing for efficiency.  */
221
 
222
/* ARGSUSED */
223
static void
224
find_dst_sections (abfd, asect, vpinfo)
225
     bfd *abfd;
226
     sec_ptr asect;
227
     PTR vpinfo;
228
{
229
  int size, count;
230
  long base;
231
  file_ptr offset, maxoff;
232
  dst_sec *section;
233
 
234
/* WARNING WILL ROBINSON!  ACCESSING BFD-PRIVATE DATA HERE!  FIXME!  */
235
  size = asect->_raw_size;
236
  offset = asect->filepos;
237
  base = asect->vma;
238
/* End of warning */
239
 
240
  section = NULL;
241
  if (!strcmp (asect->name, ".blocks"))
242
    section = &blocks_info;
243
  else if (!strcmp (asect->name, ".lines"))
244
    section = &lines_info;
245
  else if (!strcmp (asect->name, ".symbols"))
246
    section = &symbols_info;
247
  if (!section)
248
    return;
249
  section->size = size;
250
  section->position = offset;
251
  section->base = base;
252
}
253
 
254
 
255
/* The BFD for this file -- only good while we're actively reading
256
   symbols into a psymtab or a symtab.  */
257
 
258
static bfd *symfile_bfd;
259
 
260
/* Read a symbol file, after initialization by dst_symfile_init.  */
261
/* FIXME!  Addr and Mainline are not used yet -- this will not work for
262
   shared libraries or add_file!  */
263
 
264
/* ARGSUSED */
265
static void
266
dst_symfile_read (objfile, mainline)
267
     struct objfile *objfile;
268
     int mainline;
269
{
270
  bfd *abfd = objfile->obfd;
271
  char *name = bfd_get_filename (abfd);
272
  int desc;
273
  register int val;
274
  int num_symbols;
275
  int symtab_offset;
276
  int stringtab_offset;
277
 
278
  symfile_bfd = abfd;           /* Kludge for swap routines */
279
 
280
/* WARNING WILL ROBINSON!  ACCESSING BFD-PRIVATE DATA HERE!  FIXME!  */
281
  desc = fileno ((FILE *) (abfd->iostream));    /* File descriptor */
282
 
283
  /* Read the line number table, all at once.  */
284
  bfd_map_over_sections (abfd, find_dst_sections, (PTR) NULL);
285
 
286
  val = init_dst_sections (desc);
287
  if (val < 0)
288
    error ("\"%s\": error reading debugging symbol tables\n", name);
289
 
290
  init_minimal_symbol_collection ();
291
  make_cleanup (discard_minimal_symbols, 0);
292
 
293
  /* Now that the executable file is positioned at symbol table,
294
     process it and define symbols accordingly.  */
295
 
296
  read_dst_symtab (objfile);
297
 
298
  /* Sort symbols alphabetically within each block.  */
299
 
300
  {
301
    struct symtab *s;
302
    for (s = objfile->symtabs; s != NULL; s = s->next)
303
      {
304
        sort_symtab_syms (s);
305
      }
306
  }
307
 
308
  /* Install any minimal symbols that have been collected as the current
309
     minimal symbols for this objfile. */
310
 
311
  install_minimal_symbols (objfile);
312
}
313
 
314
static void
315
dst_new_init (ignore)
316
     struct objfile *ignore;
317
{
318
  /* Nothin' to do */
319
}
320
 
321
/* Perform any local cleanups required when we are done with a particular
322
   objfile.  I.E, we are in the process of discarding all symbol information
323
   for an objfile, freeing up all memory held for it, and unlinking the
324
   objfile struct from the global list of known objfiles. */
325
 
326
static void
327
dst_symfile_finish (objfile)
328
     struct objfile *objfile;
329
{
330
  /* Nothing to do */
331
}
332
 
333
 
334
/* Get the next line number from the DST. Returns 0 when we hit an
335
 * end directive or cannot continue for any other reason.
336
 *
337
 * Note that ordinary pc deltas are multiplied by two. Apparently
338
 * this is what was really intended.
339
 */
340
static int
341
get_dst_line (buffer, pc)
342
     signed char **buffer;
343
     long *pc;
344
{
345
  static last_pc = 0;
346
  static long last_line = 0;
347
  static int last_file = 0;
348
  dst_ln_entry_ptr_t entry;
349
  int size;
350
  dst_src_loc_t *src_loc;
351
 
352
  if (*pc != -1)
353
    {
354
      last_pc = *pc;
355
      *pc = -1;
356
    }
357
  entry = (dst_ln_entry_ptr_t) * buffer;
358
 
359
  while (dst_ln_ln_delta (*entry) == dst_ln_escape_flag)
360
    {
361
      switch (entry->esc.esc_code)
362
        {
363
        case dst_ln_pad:
364
          size = 1;             /* pad byte */
365
          break;
366
        case dst_ln_file:
367
          /* file escape.  Next 4 bytes are a dst_src_loc_t */
368
          size = 5;
369
          src_loc = (dst_src_loc_t *) (*buffer + 1);
370
          last_line = src_loc->line_number;
371
          last_file = src_loc->file_index;
372
          break;
373
        case dst_ln_dln1_dpc1:
374
          /* 1 byte line delta, 1 byte pc delta */
375
          last_line += (*buffer)[1];
376
          last_pc += 2 * (unsigned char) (*buffer)[2];
377
          dst_record_line (last_line, last_pc);
378
          size = 3;
379
          break;
380
        case dst_ln_dln2_dpc2:
381
          /* 2 bytes line delta, 2 bytes pc delta */
382
          last_line += *(short *) (*buffer + 1);
383
          last_pc += 2 * (*(short *) (*buffer + 3));
384
          size = 5;
385
          dst_record_line (last_line, last_pc);
386
          break;
387
        case dst_ln_ln4_pc4:
388
          /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
389
          last_line = *(unsigned long *) (*buffer + 1);
390
          last_pc = *(unsigned long *) (*buffer + 5);
391
          size = 9;
392
          dst_record_line (last_line, last_pc);
393
          break;
394
        case dst_ln_dln1_dpc0:
395
          /* 1 byte line delta, pc delta = 0 */
396
          size = 2;
397
          last_line += (*buffer)[1];
398
          break;
399
        case dst_ln_ln_off_1:
400
          /* statement escape, stmt # = 1 (2nd stmt on line) */
401
          size = 1;
402
          break;
403
        case dst_ln_ln_off:
404
          /* statement escape, stmt # = next byte */
405
          size = 2;
406
          break;
407
        case dst_ln_entry:
408
          /* entry escape, next byte is entry number */
409
          size = 2;
410
          break;
411
        case dst_ln_exit:
412
          /* exit escape */
413
          size = 1;
414
          break;
415
        case dst_ln_stmt_end:
416
          /* gap escape, 4 bytes pc delta */
417
          size = 5;
418
          /* last_pc += 2 * (*(long *) (*buffer + 1)); */
419
          /* Apparently this isn't supposed to actually modify
420
           * the pc value. Totally weird.
421
           */
422
          break;
423
        case dst_ln_escape_11:
424
        case dst_ln_escape_12:
425
        case dst_ln_escape_13:
426
          size = 1;
427
          break;
428
        case dst_ln_nxt_byte:
429
          /* This shouldn't happen. If it does, we're SOL */
430
          return 0;
431
          break;
432
        case dst_ln_end:
433
          /* end escape, final entry follows */
434
          return 0;
435
        }
436
      *buffer += (size < 0) ? -size : size;
437
      entry = (dst_ln_entry_ptr_t) * buffer;
438
    }
439
  last_line += dst_ln_ln_delta (*entry);
440
  last_pc += entry->delta.pc_delta * 2;
441
  (*buffer)++;
442
  dst_record_line (last_line, last_pc);
443
  return 1;
444
}
445
 
446
static void
447
enter_all_lines (buffer, address)
448
     char *buffer;
449
     long address;
450
{
451
  if (buffer)
452
    while (get_dst_line (&buffer, &address));
453
}
454
 
455
static int
456
get_dst_entry (buffer, ret_entry)
457
     char *buffer;
458
     dst_rec_ptr_t *ret_entry;
459
{
460
  int size;
461
  dst_rec_ptr_t entry;
462
  static int last_type;
463
  int ar_size;
464
  static unsigned lu3;
465
 
466
  entry = (dst_rec_ptr_t) buffer;
467
  switch (entry->rec_type)
468
    {
469
    case dst_typ_pad:
470
      size = 0;
471
      break;
472
    case dst_typ_comp_unit:
473
      size = sizeof (DST_comp_unit (entry));
474
      break;
475
    case dst_typ_section_tab:
476
      size = sizeof (DST_section_tab (entry))
477
        + ((int) DST_section_tab (entry).number_of_sections
478
           - dst_dummy_array_size) * sizeof (long);
479
      break;
480
    case dst_typ_file_tab:
481
      size = sizeof (DST_file_tab (entry))
482
        + ((int) DST_file_tab (entry).number_of_files
483
           - dst_dummy_array_size) * sizeof (dst_file_desc_t);
484
      break;
485
    case dst_typ_block:
486
      size = sizeof (DST_block (entry))
487
        + ((int) DST_block (entry).n_of_code_ranges
488
           - dst_dummy_array_size) * sizeof (dst_code_range_t);
489
      break;
490
    case dst_typ_5:
491
      size = -1;
492
      break;
493
    case dst_typ_var:
494
      size = sizeof (DST_var (entry)) -
495
        sizeof (dst_var_loc_long_t) * dst_dummy_array_size +
496
        DST_var (entry).no_of_locs *
497
        (DST_var (entry).short_locs ?
498
         sizeof (dst_var_loc_short_t) :
499
         sizeof (dst_var_loc_long_t));
500
      break;
501
    case dst_typ_pointer:
502
      size = sizeof (DST_pointer (entry));
503
      break;
504
    case dst_typ_array:
505
      size = sizeof (DST_array (entry));
506
      break;
507
    case dst_typ_subrange:
508
      size = sizeof (DST_subrange (entry));
509
      break;
510
    case dst_typ_set:
511
      size = sizeof (DST_set (entry));
512
      break;
513
    case dst_typ_implicit_enum:
514
      size = sizeof (DST_implicit_enum (entry))
515
        + ((int) DST_implicit_enum (entry).nelems
516
           - dst_dummy_array_size) * sizeof (dst_rel_offset_t);
517
      break;
518
    case dst_typ_explicit_enum:
519
      size = sizeof (DST_explicit_enum (entry))
520
        + ((int) DST_explicit_enum (entry).nelems
521
           - dst_dummy_array_size) * sizeof (dst_enum_elem_t);
522
      break;
523
    case dst_typ_short_rec:
524
      size = sizeof (DST_short_rec (entry))
525
        + DST_short_rec (entry).nfields * sizeof (dst_short_field_t)
526
        - dst_dummy_array_size * sizeof (dst_field_t);
527
      break;
528
    case dst_typ_short_union:
529
      size = sizeof (DST_short_union (entry))
530
        + DST_short_union (entry).nfields * sizeof (dst_short_field_t)
531
        - dst_dummy_array_size * sizeof (dst_field_t);
532
      break;
533
    case dst_typ_file:
534
      size = sizeof (DST_file (entry));
535
      break;
536
    case dst_typ_offset:
537
      size = sizeof (DST_offset (entry));
538
      break;
539
    case dst_typ_alias:
540
      size = sizeof (DST_alias (entry));
541
      break;
542
    case dst_typ_signature:
543
      size = sizeof (DST_signature (entry)) +
544
        ((int) DST_signature (entry).nargs -
545
         dst_dummy_array_size) * sizeof (dst_arg_t);
546
      break;
547
    case dst_typ_21:
548
      size = -1;
549
      break;
550
    case dst_typ_old_label:
551
      size = sizeof (DST_old_label (entry));
552
      break;
553
    case dst_typ_scope:
554
      size = sizeof (DST_scope (entry));
555
      break;
556
    case dst_typ_end_scope:
557
      size = 0;
558
      break;
559
    case dst_typ_25:
560
    case dst_typ_26:
561
      size = -1;
562
      break;
563
    case dst_typ_string_tab:
564
    case dst_typ_global_name_tab:
565
      size = sizeof (DST_string_tab (entry))
566
        + DST_string_tab (entry).length
567
        - dst_dummy_array_size;
568
      break;
569
    case dst_typ_forward:
570
      size = sizeof (DST_forward (entry));
571
      get_dst_entry ((char *) entry + DST_forward (entry).rec_off, &entry);
572
      break;
573
    case dst_typ_aux_size:
574
      size = sizeof (DST_aux_size (entry));
575
      break;
576
    case dst_typ_aux_align:
577
      size = sizeof (DST_aux_align (entry));
578
      break;
579
    case dst_typ_aux_field_size:
580
      size = sizeof (DST_aux_field_size (entry));
581
      break;
582
    case dst_typ_aux_field_off:
583
      size = sizeof (DST_aux_field_off (entry));
584
      break;
585
    case dst_typ_aux_field_align:
586
      size = sizeof (DST_aux_field_align (entry));
587
      break;
588
    case dst_typ_aux_qual:
589
      size = sizeof (DST_aux_qual (entry));
590
      break;
591
    case dst_typ_aux_var_bound:
592
      size = sizeof (DST_aux_var_bound (entry));
593
      break;
594
    case dst_typ_extension:
595
      size = DST_extension (entry).rec_size;
596
      break;
597
    case dst_typ_string:
598
      size = sizeof (DST_string (entry));
599
      break;
600
    case dst_typ_old_entry:
601
      size = 48;                /* Obsolete entry type */
602
      break;
603
    case dst_typ_const:
604
      size = sizeof (DST_const (entry))
605
        + DST_const (entry).value.length
606
        - sizeof (DST_const (entry).value.val);
607
      break;
608
    case dst_typ_reference:
609
      size = sizeof (DST_reference (entry));
610
      break;
611
    case dst_typ_old_record:
612
    case dst_typ_old_union:
613
    case dst_typ_record:
614
    case dst_typ_union:
615
      size = sizeof (DST_record (entry))
616
        + ((int) DST_record (entry).nfields
617
           - dst_dummy_array_size) * sizeof (dst_field_t);
618
      break;
619
    case dst_typ_aux_type_deriv:
620
      size = sizeof (DST_aux_type_deriv (entry));
621
      break;
622
    case dst_typ_locpool:
623
      size = sizeof (DST_locpool (entry))
624
        + ((int) DST_locpool (entry).length -
625
           dst_dummy_array_size);
626
      break;
627
    case dst_typ_variable:
628
      size = sizeof (DST_variable (entry));
629
      break;
630
    case dst_typ_label:
631
      size = sizeof (DST_label (entry));
632
      break;
633
    case dst_typ_entry:
634
      size = sizeof (DST_entry (entry));
635
      break;
636
    case dst_typ_aux_lifetime:
637
      size = sizeof (DST_aux_lifetime (entry));
638
      break;
639
    case dst_typ_aux_ptr_base:
640
      size = sizeof (DST_aux_ptr_base (entry));
641
      break;
642
    case dst_typ_aux_src_range:
643
      size = sizeof (DST_aux_src_range (entry));
644
      break;
645
    case dst_typ_aux_reg_val:
646
      size = sizeof (DST_aux_reg_val (entry));
647
      break;
648
    case dst_typ_aux_unit_names:
649
      size = sizeof (DST_aux_unit_names (entry))
650
        + ((int) DST_aux_unit_names (entry).number_of_names
651
           - dst_dummy_array_size) * sizeof (dst_rel_offset_t);
652
      break;
653
    case dst_typ_aux_sect_info:
654
      size = sizeof (DST_aux_sect_info (entry))
655
        + ((int) DST_aux_sect_info (entry).number_of_refs
656
           - dst_dummy_array_size) * sizeof (dst_sect_ref_t);
657
      break;
658
    default:
659
      size = -1;
660
      break;
661
    }
662
  if (size == -1)
663
    {
664
      fprintf_unfiltered (gdb_stderr, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
665
                          (int) entry->rec_type,
666
                          last_type);
667
      fprintf_unfiltered (gdb_stderr, "Last unknown_3 value: %d\n", lu3);
668
      size = 0;
669
    }
670
  else
671
    last_type = entry->rec_type;
672
  if (size & 1)                 /* Align on a word boundary */
673
    size++;
674
  size += 2;
675
  *ret_entry = entry;
676
  return size;
677
}
678
 
679
static int
680
next_dst_entry (buffer, entry, table)
681
     char **buffer;
682
     dst_rec_ptr_t *entry;
683
     dst_sec *table;
684
{
685
  if (*buffer - table->buffer >= table->size)
686
    {
687
      *entry = NULL;
688
      return 0;
689
    }
690
  *buffer += get_dst_entry (*buffer, entry);
691
  return 1;
692
}
693
 
694
#define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
695
#define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
696
#define DST_OFFSET(a, b) ((char *) (a) + (b))
697
 
698
static dst_rec_ptr_t section_table = NULL;
699
 
700
char *
701
get_sec_ref (ref)
702
     dst_sect_ref_t *ref;
703
{
704
  dst_sec *section = NULL;
705
  long offset;
706
 
707
  if (!section_table || !ref->sect_index)
708
    return NULL;
709
  offset = DST_section_tab (section_table).section_base[ref->sect_index - 1]
710
    + ref->sect_offset;
711
  if (offset >= blocks_info.base &&
712
      offset < blocks_info.base + blocks_info.size)
713
    section = &blocks_info;
714
  else if (offset >= symbols_info.base &&
715
           offset < symbols_info.base + symbols_info.size)
716
    section = &symbols_info;
717
  else if (offset >= lines_info.base &&
718
           offset < lines_info.base + lines_info.size)
719
    section = &lines_info;
720
  if (!section)
721
    return NULL;
722
  return section->buffer + (offset - section->base);
723
}
724
 
725
CORE_ADDR
726
dst_get_addr (int section, long offset)
727
{
728
  if (!section_table || !section)
729
    return 0;
730
  return DST_section_tab (section_table).section_base[section - 1] + offset;
731
}
732
 
733
CORE_ADDR
734
dst_sym_addr (ref)
735
     dst_sect_ref_t *ref;
736
{
737
  if (!section_table || !ref->sect_index)
738
    return 0;
739
  return DST_section_tab (section_table).section_base[ref->sect_index - 1]
740
    + ref->sect_offset;
741
}
742
 
743
static struct type *
744
create_new_type (objfile)
745
     struct objfile *objfile;
746
{
747
  struct type *type;
748
 
749
  type = (struct type *)
750
    obstack_alloc (&objfile->symbol_obstack, sizeof (struct type));
751
  memset (type, 0, sizeof (struct type));
752
  return type;
753
}
754
 
755
static struct symbol *
756
create_new_symbol (objfile, name)
757
     struct objfile *objfile;
758
     char *name;
759
{
760
  struct symbol *sym = (struct symbol *)
761
  obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
762
  memset (sym, 0, sizeof (struct symbol));
763
  SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
764
                                    &objfile->symbol_obstack);
765
  SYMBOL_VALUE (sym) = 0;
766
  SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
767
 
768
  SYMBOL_CLASS (sym) = LOC_BLOCK;
769
  return sym;
770
};
771
 
772
static struct type *
773
  decode_dst_type PARAMS ((struct objfile *, dst_rec_ptr_t));
774
 
775
static struct type *
776
decode_type_desc (objfile, type_desc, base)
777
     struct objfile *objfile;
778
     dst_type_t *type_desc;
779
     dst_rec_ptr_t base;
780
{
781
  struct type *type;
782
  dst_rec_ptr_t entry;
783
  if (type_desc->std_type.user_defined_type)
784
    {
785
      entry = (dst_rec_ptr_t) DST_OFFSET (base,
786
                                          dst_user_type_offset (*type_desc));
787
      type = decode_dst_type (objfile, entry);
788
    }
789
  else
790
    {
791
      switch (type_desc->std_type.dtc)
792
        {
793
        case dst_int8_type:
794
          type = builtin_type_signed_char;
795
          break;
796
        case dst_int16_type:
797
          type = builtin_type_short;
798
          break;
799
        case dst_int32_type:
800
          type = builtin_type_long;
801
          break;
802
        case dst_uint8_type:
803
          type = builtin_type_unsigned_char;
804
          break;
805
        case dst_uint16_type:
806
          type = builtin_type_unsigned_short;
807
          break;
808
        case dst_uint32_type:
809
          type = builtin_type_unsigned_long;
810
          break;
811
        case dst_real32_type:
812
          type = builtin_type_float;
813
          break;
814
        case dst_real64_type:
815
          type = builtin_type_double;
816
          break;
817
        case dst_complex_type:
818
          type = builtin_type_complex;
819
          break;
820
        case dst_dcomplex_type:
821
          type = builtin_type_double_complex;
822
          break;
823
        case dst_bool8_type:
824
          type = builtin_type_char;
825
          break;
826
        case dst_bool16_type:
827
          type = builtin_type_short;
828
          break;
829
        case dst_bool32_type:
830
          type = builtin_type_long;
831
          break;
832
        case dst_char_type:
833
          type = builtin_type_char;
834
          break;
835
          /* The next few are more complex. I will take care
836
           * of them properly at a later point.
837
           */
838
        case dst_string_type:
839
          type = builtin_type_void;
840
          break;
841
        case dst_ptr_type:
842
          type = builtin_type_void;
843
          break;
844
        case dst_set_type:
845
          type = builtin_type_void;
846
          break;
847
        case dst_proc_type:
848
          type = builtin_type_void;
849
          break;
850
        case dst_func_type:
851
          type = builtin_type_void;
852
          break;
853
          /* Back tto some ordinary ones */
854
        case dst_void_type:
855
          type = builtin_type_void;
856
          break;
857
        case dst_uchar_type:
858
          type = builtin_type_unsigned_char;
859
          break;
860
        default:
861
          type = builtin_type_void;
862
          break;
863
        }
864
    }
865
  return type;
866
}
867
 
868
struct structure_list
869
{
870
  struct structure_list *next;
871
  struct type *type;
872
};
873
 
874
static struct structure_list *struct_list = NULL;
875
 
876
static struct type *
877
find_dst_structure (name)
878
     char *name;
879
{
880
  struct structure_list *element;
881
 
882
  for (element = struct_list; element; element = element->next)
883
    if (!strcmp (name, TYPE_NAME (element->type)))
884
      return element->type;
885
  return NULL;
886
}
887
 
888
 
889
static struct type *
890
decode_dst_structure (objfile, entry, code, version)
891
     struct objfile *objfile;
892
     dst_rec_ptr_t entry;
893
     int code;
894
     int version;
895
{
896
  struct type *type, *child_type;
897
  char *struct_name;
898
  char *name, *field_name;
899
  int i;
900
  int fieldoffset, fieldsize;
901
  dst_type_t type_desc;
902
  struct structure_list *element;
903
 
904
  struct_name = DST_OFFSET (entry, DST_record (entry).noffset);
905
  name = concat ((code == TYPE_CODE_UNION) ? "union " : "struct ",
906
                 struct_name, NULL);
907
  type = find_dst_structure (name);
908
  if (type)
909
    {
910
      free ((PTR) name);
911
      return type;
912
    }
913
  type = create_new_type (objfile);
914
  TYPE_NAME (type) = obstack_copy0 (&objfile->symbol_obstack,
915
                                    name, strlen (name));
916
  free ((PTR) name);
917
  TYPE_CODE (type) = code;
918
  TYPE_LENGTH (type) = DST_record (entry).size;
919
  TYPE_NFIELDS (type) = DST_record (entry).nfields;
920
  TYPE_FIELDS (type) = (struct field *)
921
    obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) *
922
                   DST_record (entry).nfields);
923
  fieldoffset = fieldsize = 0;
924
  INIT_CPLUS_SPECIFIC (type);
925
  element = (struct structure_list *)
926
    xmalloc (sizeof (struct structure_list));
927
  element->type = type;
928
  element->next = struct_list;
929
  struct_list = element;
930
  for (i = 0; i < DST_record (entry).nfields; i++)
931
    {
932
      switch (version)
933
        {
934
        case 2:
935
          field_name = DST_OFFSET (entry,
936
                                   DST_record (entry).f.ofields[i].noffset);
937
          fieldoffset = DST_record (entry).f.ofields[i].foffset * 8 +
938
            DST_record (entry).f.ofields[i].bit_offset;
939
          fieldsize = DST_record (entry).f.ofields[i].size;
940
          type_desc = DST_record (entry).f.ofields[i].type_desc;
941
          break;
942
        case 1:
943
          field_name = DST_OFFSET (entry,
944
                                   DST_record (entry).f.fields[i].noffset);
945
          type_desc = DST_record (entry).f.fields[i].type_desc;
946
          switch (DST_record (entry).f.fields[i].f.field_loc.format_tag)
947
            {
948
            case dst_field_byte:
949
              fieldoffset = DST_record (entry).f.
950
                fields[i].f.field_byte.offset * 8;
951
              fieldsize = -1;
952
              break;
953
            case dst_field_bit:
954
              fieldoffset = DST_record (entry).f.
955
                fields[i].f.field_bit.byte_offset * 8 +
956
                DST_record (entry).f.
957
                fields[i].f.field_bit.bit_offset;
958
              fieldsize = DST_record (entry).f.
959
                fields[i].f.field_bit.nbits;
960
              break;
961
            case dst_field_loc:
962
              fieldoffset += fieldsize;
963
              fieldsize = -1;
964
              break;
965
            }
966
          break;
967
        case 0:
968
          field_name = DST_OFFSET (entry,
969
                                   DST_record (entry).f.sfields[i].noffset);
970
          fieldoffset = DST_record (entry).f.sfields[i].foffset;
971
          type_desc = DST_record (entry).f.sfields[i].type_desc;
972
          if (i < DST_record (entry).nfields - 1)
973
            fieldsize = DST_record (entry).f.sfields[i + 1].foffset;
974
          else
975
            fieldsize = DST_record (entry).size;
976
          fieldsize -= fieldoffset;
977
          fieldoffset *= 8;
978
          fieldsize *= 8;
979
        }
980
      TYPE_FIELDS (type)[i].name =
981
        obstack_copy0 (&objfile->symbol_obstack,
982
                       field_name, strlen (field_name));
983
      TYPE_FIELDS (type)[i].type = decode_type_desc (objfile,
984
                                                     &type_desc,
985
                                                     entry);
986
      if (fieldsize == -1)
987
        fieldsize = TYPE_LENGTH (TYPE_FIELDS (type)[i].type) *
988
          8;
989
      TYPE_FIELDS (type)[i].bitsize = fieldsize;
990
      TYPE_FIELDS (type)[i].bitpos = fieldoffset;
991
    }
992
  return type;
993
}
994
 
995
static struct type *
996
decode_dst_type (objfile, entry)
997
     struct objfile *objfile;
998
     dst_rec_ptr_t entry;
999
{
1000
  struct type *child_type, *type, *range_type, *index_type;
1001
 
1002
  switch (entry->rec_type)
1003
    {
1004
    case dst_typ_var:
1005
      return decode_type_desc (objfile,
1006
                               &DST_var (entry).type_desc,
1007
                               entry);
1008
      break;
1009
    case dst_typ_variable:
1010
      return decode_type_desc (objfile,
1011
                               &DST_variable (entry).type_desc,
1012
                               entry);
1013
      break;
1014
    case dst_typ_short_rec:
1015
      return decode_dst_structure (objfile, entry, TYPE_CODE_STRUCT, 0);
1016
    case dst_typ_short_union:
1017
      return decode_dst_structure (objfile, entry, TYPE_CODE_UNION, 0);
1018
    case dst_typ_union:
1019
      return decode_dst_structure (objfile, entry, TYPE_CODE_UNION, 1);
1020
    case dst_typ_record:
1021
      return decode_dst_structure (objfile, entry, TYPE_CODE_STRUCT, 1);
1022
    case dst_typ_old_union:
1023
      return decode_dst_structure (objfile, entry, TYPE_CODE_UNION, 2);
1024
    case dst_typ_old_record:
1025
      return decode_dst_structure (objfile, entry, TYPE_CODE_STRUCT, 2);
1026
    case dst_typ_pointer:
1027
      return make_pointer_type (
1028
                                 decode_type_desc (objfile,
1029
                                             &DST_pointer (entry).type_desc,
1030
                                                   entry),
1031
                                 NULL);
1032
    case dst_typ_array:
1033
      child_type = decode_type_desc (objfile,
1034
                                     &DST_pointer (entry).type_desc,
1035
                                     entry);
1036
      index_type = lookup_fundamental_type (objfile,
1037
                                            FT_INTEGER);
1038
      range_type = create_range_type ((struct type *) NULL,
1039
                                      index_type, DST_array (entry).lo_bound,
1040
                                      DST_array (entry).hi_bound);
1041
      return create_array_type ((struct type *) NULL, child_type,
1042
                                range_type);
1043
    case dst_typ_alias:
1044
      return decode_type_desc (objfile,
1045
                               &DST_alias (entry).type_desc,
1046
                               entry);
1047
    default:
1048
      return builtin_type_int;
1049
    }
1050
}
1051
 
1052
struct symbol_list
1053
{
1054
  struct symbol_list *next;
1055
  struct symbol *symbol;
1056
};
1057
 
1058
static struct symbol_list *dst_global_symbols = NULL;
1059
static int total_globals = 0;
1060
 
1061
static void
1062
decode_dst_locstring (locstr, sym)
1063
     char *locstr;
1064
     struct symbol *sym;
1065
{
1066
  dst_loc_entry_t *entry, *next_entry;
1067
  CORE_ADDR temp;
1068
  int count = 0;
1069
 
1070
  while (1)
1071
    {
1072
      if (count++ == 100)
1073
        {
1074
          fprintf_unfiltered (gdb_stderr, "Error reading locstring\n");
1075
          break;
1076
        }
1077
      entry = (dst_loc_entry_t *) locstr;
1078
      next_entry = (dst_loc_entry_t *) (locstr + 1);
1079
      switch (entry->header.code)
1080
        {
1081
        case dst_lsc_end:       /* End of string */
1082
          return;
1083
        case dst_lsc_indirect:  /* Indirect through previous. Arg == 6 */
1084
          /* Or register ax x == arg */
1085
          if (entry->header.arg < 6)
1086
            {
1087
              SYMBOL_CLASS (sym) = LOC_REGISTER;
1088
              SYMBOL_VALUE (sym) = entry->header.arg + 8;
1089
            }
1090
          /* We predict indirects */
1091
          locstr++;
1092
          break;
1093
        case dst_lsc_dreg:
1094
          SYMBOL_CLASS (sym) = LOC_REGISTER;
1095
          SYMBOL_VALUE (sym) = entry->header.arg;
1096
          locstr++;
1097
          break;
1098
        case dst_lsc_section:   /* Section (arg+1) */
1099
          SYMBOL_VALUE (sym) = dst_get_addr (entry->header.arg + 1, 0);
1100
          locstr++;
1101
          break;
1102
        case dst_lsc_sec_byte:  /* Section (next_byte+1) */
1103
          SYMBOL_VALUE (sym) = dst_get_addr (locstr[1] + 1, 0);
1104
          locstr += 2;
1105
          break;
1106
        case dst_lsc_add:       /* Add (arg+1)*2 */
1107
        case dst_lsc_sub:       /* Subtract (arg+1)*2 */
1108
          temp = (entry->header.arg + 1) * 2;
1109
          locstr++;
1110
          if (*locstr == dst_multiply_256)
1111
            {
1112
              temp <<= 8;
1113
              locstr++;
1114
            }
1115
          switch (entry->header.code)
1116
            {
1117
            case dst_lsc_add:
1118
              if (SYMBOL_CLASS (sym) == LOC_LOCAL)
1119
                SYMBOL_CLASS (sym) = LOC_ARG;
1120
              SYMBOL_VALUE (sym) += temp;
1121
              break;
1122
            case dst_lsc_sub:
1123
              SYMBOL_VALUE (sym) -= temp;
1124
              break;
1125
            }
1126
          break;
1127
        case dst_lsc_add_byte:
1128
        case dst_lsc_sub_byte:
1129
          switch (entry->header.arg & 0x03)
1130
            {
1131
            case 1:
1132
              temp = (unsigned char) locstr[1];
1133
              locstr += 2;
1134
              break;
1135
            case 2:
1136
              temp = *(unsigned short *) (locstr + 1);
1137
              locstr += 3;
1138
              break;
1139
            case 3:
1140
              temp = *(unsigned long *) (locstr + 1);
1141
              locstr += 5;
1142
              break;
1143
            }
1144
          if (*locstr == dst_multiply_256)
1145
            {
1146
              temp <<= 8;
1147
              locstr++;
1148
            }
1149
          switch (entry->header.code)
1150
            {
1151
            case dst_lsc_add_byte:
1152
              if (SYMBOL_CLASS (sym) == LOC_LOCAL)
1153
                SYMBOL_CLASS (sym) = LOC_ARG;
1154
              SYMBOL_VALUE (sym) += temp;
1155
              break;
1156
            case dst_lsc_sub_byte:
1157
              SYMBOL_VALUE (sym) -= temp;
1158
              break;
1159
            }
1160
          break;
1161
        case dst_lsc_sbreg:     /* Stack base register (frame pointer). Arg==0 */
1162
          if (next_entry->header.code != dst_lsc_indirect)
1163
            {
1164
              SYMBOL_VALUE (sym) = 0;
1165
              SYMBOL_CLASS (sym) = LOC_STATIC;
1166
              return;
1167
            }
1168
          SYMBOL_VALUE (sym) = 0;
1169
          SYMBOL_CLASS (sym) = LOC_LOCAL;
1170
          locstr++;
1171
          break;
1172
        default:
1173
          SYMBOL_VALUE (sym) = 0;
1174
          SYMBOL_CLASS (sym) = LOC_STATIC;
1175
          return;
1176
        }
1177
    }
1178
}
1179
 
1180
static struct symbol_list *
1181
process_dst_symbols (objfile, entry, name, nsyms_ret)
1182
     struct objfile *objfile;
1183
     dst_rec_ptr_t entry;
1184
     char *name;
1185
     int *nsyms_ret;
1186
{
1187
  struct symbol_list *list = NULL, *element;
1188
  struct symbol *sym;
1189
  char *symname;
1190
  int nsyms = 0;
1191
  char *location;
1192
  long line;
1193
  dst_type_t symtype;
1194
  struct type *type;
1195
  dst_var_attr_t attr;
1196
  dst_var_loc_t loc_type;
1197
  unsigned loc_index;
1198
  long loc_value;
1199
 
1200
  if (!entry)
1201
    {
1202
      *nsyms_ret = 0;
1203
      return NULL;
1204
    }
1205
  location = (char *) entry;
1206
  while (NEXT_SYM (&location, &entry) &&
1207
         entry->rec_type != dst_typ_end_scope)
1208
    {
1209
      if (entry->rec_type == dst_typ_var)
1210
        {
1211
          if (DST_var (entry).short_locs)
1212
            {
1213
              loc_type = DST_var (entry).locs.shorts[0].loc_type;
1214
              loc_index = DST_var (entry).locs.shorts[0].loc_index;
1215
              loc_value = DST_var (entry).locs.shorts[0].location;
1216
            }
1217
          else
1218
            {
1219
              loc_type = DST_var (entry).locs.longs[0].loc_type;
1220
              loc_index = DST_var (entry).locs.longs[0].loc_index;
1221
              loc_value = DST_var (entry).locs.longs[0].location;
1222
            }
1223
          if (loc_type == dst_var_loc_external)
1224
            continue;
1225
          symname = DST_OFFSET (entry, DST_var (entry).noffset);
1226
          line = DST_var (entry).src_loc.line_number;
1227
          symtype = DST_var (entry).type_desc;
1228
          attr = DST_var (entry).attributes;
1229
        }
1230
      else if (entry->rec_type == dst_typ_variable)
1231
        {
1232
          symname = DST_OFFSET (entry,
1233
                                DST_variable (entry).noffset);
1234
          line = DST_variable (entry).src_loc.line_number;
1235
          symtype = DST_variable (entry).type_desc;
1236
          attr = DST_variable (entry).attributes;
1237
        }
1238
      else
1239
        {
1240
          continue;
1241
        }
1242
      if (symname && name && !strcmp (symname, name))
1243
        /* It's the function return value */
1244
        continue;
1245
      sym = create_new_symbol (objfile, symname);
1246
 
1247
      if ((attr & (1 << dst_var_attr_global)) ||
1248
          (attr & (1 << dst_var_attr_static)))
1249
        SYMBOL_CLASS (sym) = LOC_STATIC;
1250
      else
1251
        SYMBOL_CLASS (sym) = LOC_LOCAL;
1252
      SYMBOL_LINE (sym) = line;
1253
      SYMBOL_TYPE (sym) = decode_type_desc (objfile, &symtype,
1254
                                            entry);
1255
      SYMBOL_VALUE (sym) = 0;
1256
      switch (entry->rec_type)
1257
        {
1258
        case dst_typ_var:
1259
          switch (loc_type)
1260
            {
1261
            case dst_var_loc_abs:
1262
              SYMBOL_VALUE_ADDRESS (sym) = loc_value;
1263
              break;
1264
            case dst_var_loc_sect_off:
1265
            case dst_var_loc_ind_sect_off:      /* What is this? */
1266
              SYMBOL_VALUE_ADDRESS (sym) = dst_get_addr (
1267
                                                          loc_index,
1268
                                                          loc_value);
1269
              break;
1270
            case dst_var_loc_ind_reg_rel:       /* What is this? */
1271
            case dst_var_loc_reg_rel:
1272
              /* If it isn't fp relative, specify the
1273
               * register it's relative to.
1274
               */
1275
              if (loc_index)
1276
                {
1277
                  sym->aux_value.basereg = loc_index;
1278
                }
1279
              SYMBOL_VALUE (sym) = loc_value;
1280
              if (loc_value > 0 &&
1281
                  SYMBOL_CLASS (sym) == LOC_BASEREG)
1282
                SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
1283
              break;
1284
            case dst_var_loc_reg:
1285
              SYMBOL_VALUE (sym) = loc_index;
1286
              SYMBOL_CLASS (sym) = LOC_REGISTER;
1287
              break;
1288
            }
1289
          break;
1290
        case dst_typ_variable:
1291
          /* External variable..... don't try to interpret
1292
           * its nonexistant locstring.
1293
           */
1294
          if (DST_variable (entry).loffset == -1)
1295
            continue;
1296
          decode_dst_locstring (DST_OFFSET (entry,
1297
                                            DST_variable (entry).loffset),
1298
                                sym);
1299
        }
1300
      element = (struct symbol_list *)
1301
        xmalloc (sizeof (struct symbol_list));
1302
 
1303
      if (attr & (1 << dst_var_attr_global))
1304
        {
1305
          element->next = dst_global_symbols;
1306
          dst_global_symbols = element;
1307
          total_globals++;
1308
        }
1309
      else
1310
        {
1311
          element->next = list;
1312
          list = element;
1313
          nsyms++;
1314
        }
1315
      element->symbol = sym;
1316
    }
1317
  *nsyms_ret = nsyms;
1318
  return list;
1319
}
1320
 
1321
 
1322
static struct symbol *
1323
process_dst_function (objfile, entry, name, address)
1324
     struct objfile *objfile;
1325
     dst_rec_ptr_t entry;
1326
     char *name;
1327
     CORE_ADDR address;
1328
{
1329
  struct symbol *sym;
1330
  struct type *type, *ftype;
1331
  dst_rec_ptr_t sym_entry, typ_entry;
1332
  char *location;
1333
  struct symbol_list *element;
1334
 
1335
  type = builtin_type_int;
1336
  sym = create_new_symbol (objfile, name);
1337
  SYMBOL_CLASS (sym) = LOC_BLOCK;
1338
 
1339
  if (entry)
1340
    {
1341
      location = (char *) entry;
1342
      do
1343
        {
1344
          NEXT_SYM (&location, &sym_entry);
1345
        }
1346
      while (sym_entry && sym_entry->rec_type != dst_typ_signature);
1347
 
1348
      if (sym_entry)
1349
        {
1350
          SYMBOL_LINE (sym) =
1351
            DST_signature (sym_entry).src_loc.line_number;
1352
          if (DST_signature (sym_entry).result)
1353
            {
1354
              typ_entry = (dst_rec_ptr_t)
1355
                DST_OFFSET (sym_entry,
1356
                            DST_signature (sym_entry).result);
1357
              type = decode_dst_type (objfile, typ_entry);
1358
            }
1359
        }
1360
    }
1361
 
1362
  if (!type->function_type)
1363
    {
1364
      ftype = create_new_type (objfile);
1365
      type->function_type = ftype;
1366
      ftype->target_type = type;
1367
      ftype->code = TYPE_CODE_FUNC;
1368
    }
1369
  SYMBOL_TYPE (sym) = type->function_type;
1370
 
1371
  /* Now add ourselves to the global symbols list */
1372
  element = (struct symbol_list *)
1373
    xmalloc (sizeof (struct symbol_list));
1374
 
1375
  element->next = dst_global_symbols;
1376
  dst_global_symbols = element;
1377
  total_globals++;
1378
  element->symbol = sym;
1379
 
1380
  return sym;
1381
}
1382
 
1383
static struct block *
1384
process_dst_block (objfile, entry)
1385
     struct objfile *objfile;
1386
     dst_rec_ptr_t entry;
1387
{
1388
  struct block *block;
1389
  struct symbol *function = NULL;
1390
  CORE_ADDR address;
1391
  long size;
1392
  char *name;
1393
  dst_rec_ptr_t child_entry, symbol_entry;
1394
  struct block *child_block;
1395
  int total_symbols = 0;
1396
  char fake_name[20];
1397
  static long fake_seq = 0;
1398
  struct symbol_list *symlist, *nextsym;
1399
  int symnum;
1400
 
1401
  if (DST_block (entry).noffset)
1402
    name = DST_OFFSET (entry, DST_block (entry).noffset);
1403
  else
1404
    name = NULL;
1405
  if (DST_block (entry).n_of_code_ranges)
1406
    {
1407
      address = dst_sym_addr (
1408
                               &DST_block (entry).code_ranges[0].code_start);
1409
      size = DST_block (entry).code_ranges[0].code_size;
1410
    }
1411
  else
1412
    {
1413
      address = -1;
1414
      size = 0;
1415
    }
1416
  symbol_entry = (dst_rec_ptr_t) get_sec_ref (&DST_block (entry).symbols_start);
1417
  switch (DST_block (entry).block_type)
1418
    {
1419
      /* These are all really functions. Even the "program" type.
1420
       * This is because the Apollo OS was written in Pascal, and
1421
       * in Pascal, the main procedure is described as the Program.
1422
       * Cute, huh?
1423
       */
1424
    case dst_block_procedure:
1425
    case dst_block_function:
1426
    case dst_block_subroutine:
1427
    case dst_block_program:
1428
      prim_record_minimal_symbol (name, address, mst_text, objfile);
1429
      function = process_dst_function (
1430
                                        objfile,
1431
                                        symbol_entry,
1432
                                        name,
1433
                                        address);
1434
      enter_all_lines (get_sec_ref (&DST_block (entry).code_ranges[0].lines_start), address);
1435
      break;
1436
    case dst_block_block_data:
1437
      break;
1438
 
1439
    default:
1440
      /* GDB has to call it something, and the module name
1441
       * won't cut it
1442
       */
1443
      sprintf (fake_name, "block_%08lx", fake_seq++);
1444
      function = process_dst_function (
1445
                                        objfile, NULL, fake_name, address);
1446
      break;
1447
    }
1448
  symlist = process_dst_symbols (objfile, symbol_entry,
1449
                                 name, &total_symbols);
1450
  block = (struct block *)
1451
    obstack_alloc (&objfile->symbol_obstack,
1452
                   sizeof (struct block) +
1453
                     (total_symbols - 1) * sizeof (struct symbol *));
1454
 
1455
  symnum = 0;
1456
  while (symlist)
1457
    {
1458
      nextsym = symlist->next;
1459
 
1460
      block->sym[symnum] = symlist->symbol;
1461
 
1462
      free ((PTR) symlist);
1463
      symlist = nextsym;
1464
      symnum++;
1465
    }
1466
  BLOCK_NSYMS (block) = total_symbols;
1467
  BLOCK_START (block) = address;
1468
  BLOCK_END (block) = address + size;
1469
  BLOCK_SUPERBLOCK (block) = 0;
1470
  if (function)
1471
    {
1472
      SYMBOL_BLOCK_VALUE (function) = block;
1473
      BLOCK_FUNCTION (block) = function;
1474
    }
1475
  else
1476
    BLOCK_FUNCTION (block) = 0;
1477
 
1478
  if (DST_block (entry).child_block_off)
1479
    {
1480
      child_entry = (dst_rec_ptr_t) DST_OFFSET (entry,
1481
                                         DST_block (entry).child_block_off);
1482
      while (child_entry)
1483
        {
1484
          child_block = process_dst_block (objfile, child_entry);
1485
          if (child_block)
1486
            {
1487
              if (BLOCK_START (child_block) <
1488
                  BLOCK_START (block) ||
1489
                  BLOCK_START (block) == -1)
1490
                BLOCK_START (block) =
1491
                  BLOCK_START (child_block);
1492
              if (BLOCK_END (child_block) >
1493
                  BLOCK_END (block) ||
1494
                  BLOCK_END (block) == -1)
1495
                BLOCK_END (block) =
1496
                  BLOCK_END (child_block);
1497
              BLOCK_SUPERBLOCK (child_block) = block;
1498
            }
1499
          if (DST_block (child_entry).sibling_block_off)
1500
            child_entry = (dst_rec_ptr_t) DST_OFFSET (
1501
                                                       child_entry,
1502
                                 DST_block (child_entry).sibling_block_off);
1503
          else
1504
            child_entry = NULL;
1505
        }
1506
    }
1507
  record_pending_block (objfile, block, NULL);
1508
  return block;
1509
}
1510
 
1511
 
1512
static void
1513
read_dst_symtab (objfile)
1514
     struct objfile *objfile;
1515
{
1516
  char *buffer;
1517
  dst_rec_ptr_t entry, file_table, root_block;
1518
  char *source_file;
1519
  struct block *block, *global_block;
1520
  int symnum;
1521
  struct symbol_list *nextsym;
1522
  int module_num = 0;
1523
  struct structure_list *element;
1524
 
1525
  current_objfile = objfile;
1526
  buffer = blocks_info.buffer;
1527
  while (NEXT_BLK (&buffer, &entry))
1528
    {
1529
      if (entry->rec_type == dst_typ_comp_unit)
1530
        {
1531
          file_table = (dst_rec_ptr_t) DST_OFFSET (entry,
1532
                                          DST_comp_unit (entry).file_table);
1533
          section_table = (dst_rec_ptr_t) DST_OFFSET (entry,
1534
                                       DST_comp_unit (entry).section_table);
1535
          root_block = (dst_rec_ptr_t) DST_OFFSET (entry,
1536
                                   DST_comp_unit (entry).root_block_offset);
1537
          source_file = DST_OFFSET (file_table,
1538
                                DST_file_tab (file_table).files[0].noffset);
1539
          /* Point buffer to the start of the next comp_unit */
1540
          buffer = DST_OFFSET (entry,
1541
                               DST_comp_unit (entry).data_size);
1542
          dst_start_symtab ();
1543
 
1544
          block = process_dst_block (objfile, root_block);
1545
 
1546
          global_block = (struct block *)
1547
            obstack_alloc (&objfile->symbol_obstack,
1548
                           sizeof (struct block) +
1549
                             (total_globals - 1) *
1550
                           sizeof (struct symbol *));
1551
          BLOCK_NSYMS (global_block) = total_globals;
1552
          for (symnum = 0; symnum < total_globals; symnum++)
1553
            {
1554
              nextsym = dst_global_symbols->next;
1555
 
1556
              global_block->sym[symnum] =
1557
                dst_global_symbols->symbol;
1558
 
1559
              free ((PTR) dst_global_symbols);
1560
              dst_global_symbols = nextsym;
1561
            }
1562
          dst_global_symbols = NULL;
1563
          total_globals = 0;
1564
          BLOCK_FUNCTION (global_block) = 0;
1565
          BLOCK_START (global_block) = BLOCK_START (block);
1566
          BLOCK_END (global_block) = BLOCK_END (block);
1567
          BLOCK_SUPERBLOCK (global_block) = 0;
1568
          BLOCK_SUPERBLOCK (block) = global_block;
1569
          record_pending_block (objfile, global_block, NULL);
1570
 
1571
          complete_symtab (source_file,
1572
                           BLOCK_START (block),
1573
                           BLOCK_END (block) - BLOCK_START (block));
1574
          module_num++;
1575
          dst_end_symtab (objfile);
1576
        }
1577
    }
1578
  if (module_num)
1579
    prim_record_minimal_symbol ("<end_of_program>",
1580
                                BLOCK_END (block), mst_text, objfile);
1581
  /* One more faked symbol to make sure nothing can ever run off the
1582
   * end of the symbol table. This one represents the end of the
1583
   * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1584
   * int possible), but some parts of gdb treated it as a signed
1585
   * number and failed comparisons. We could equally use 7fffffff,
1586
   * but no functions are ever mapped to an address higher than
1587
   * 40000000
1588
   */
1589
  prim_record_minimal_symbol ("<end_of_text>",
1590
                              (CORE_ADDR) 0x40000000,
1591
                              mst_text, objfile);
1592
  while (struct_list)
1593
    {
1594
      element = struct_list;
1595
      struct_list = element->next;
1596
      free ((PTR) element);
1597
    }
1598
}
1599
 
1600
 
1601
/* Support for line number handling */
1602
static char *linetab = NULL;
1603
static long linetab_offset;
1604
static unsigned long linetab_size;
1605
 
1606
/* Read in all the line numbers for fast lookups later.  Leave them in
1607
   external (unswapped) format in memory; we'll swap them as we enter
1608
   them into GDB's data structures.  */
1609
static int
1610
init_one_section (chan, secinfo)
1611
     int chan;
1612
     dst_sec *secinfo;
1613
{
1614
  if (secinfo->size == 0
1615
      || lseek (chan, secinfo->position, 0) == -1
1616
      || (secinfo->buffer = xmalloc (secinfo->size)) == NULL
1617
      || myread (chan, secinfo->buffer, secinfo->size) == -1)
1618
    return 0;
1619
  else
1620
    return 1;
1621
}
1622
 
1623
static int
1624
init_dst_sections (chan)
1625
     int chan;
1626
{
1627
 
1628
  if (!init_one_section (chan, &blocks_info) ||
1629
      !init_one_section (chan, &lines_info) ||
1630
      !init_one_section (chan, &symbols_info))
1631
    return -1;
1632
  else
1633
    return 0;
1634
}
1635
 
1636
/* Fake up support for relocating symbol addresses.  FIXME.  */
1637
 
1638
struct section_offsets dst_symfile_faker =
1639
{0};
1640
 
1641
void
1642
dst_symfile_offsets (objfile, addr)
1643
     struct objfile *objfile;
1644
     struct section_addr_info *addrs;
1645
{
1646
  objfile->num_sections = 1;
1647
  objfile->section_offsets = &dst_symfile_faker;
1648
}
1649
 
1650
/* Register our ability to parse symbols for DST BFD files */
1651
 
1652
static struct sym_fns dst_sym_fns =
1653
{
1654
  /* FIXME: Can this be integrated with coffread.c?  If not, should it be
1655
     a separate flavour like ecoff?  */
1656
  (enum bfd_flavour) -2,
1657
 
1658
  dst_new_init,                 /* sym_new_init: init anything gbl to entire symtab */
1659
  dst_symfile_init,             /* sym_init: read initial info, setup for sym_read() */
1660
  dst_symfile_read,             /* sym_read: read a symbol file into symtab */
1661
  dst_symfile_finish,           /* sym_finish: finished with file, cleanup */
1662
  dst_symfile_offsets,          /* sym_offsets:  xlate external to internal form */
1663
  NULL                          /* next: pointer to next struct sym_fns */
1664
};
1665
 
1666
void
1667
_initialize_dstread ()
1668
{
1669
  add_symtab_fns (&dst_sym_fns);
1670
}

powered by: WebSVN 2.1.0

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