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