1 /* 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.
5 This file is part of GDB.
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.
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.
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. */
25 #include "breakpoint.h"
32 #include "gdb_string.h"
36 CORE_ADDR cur_src_start_addr, cur_src_end_addr;
37 dst_sec blocks_info, lines_info, symbols_info;
39 /* Vector of line number information. */
41 static struct linetable *line_vector;
43 /* Index of next entry to go in line_vector_index. */
45 static int line_vector_index;
47 /* Last line number recorded in the line vector. */
49 static int prev_line_number;
51 /* Number of elements allocated for line_vector currently. */
53 static int line_vector_length;
55 static int init_dst_sections (int);
57 static void read_dst_symtab (struct objfile *);
59 static void find_dst_sections (bfd *, sec_ptr, PTR);
61 static void dst_symfile_init (struct objfile *);
63 static void dst_new_init (struct objfile *);
65 static void dst_symfile_read (struct objfile *, int);
67 static void dst_symfile_finish (struct objfile *);
69 static void dst_end_symtab (struct objfile *);
71 static void complete_symtab (char *, CORE_ADDR, unsigned int);
73 static void dst_start_symtab (void);
75 static void dst_record_line (int, CORE_ADDR);
77 /* Manage the vector of line numbers. */
78 /* FIXME: Use record_line instead. */
81 dst_record_line (int line, CORE_ADDR pc)
83 struct linetable_entry *e;
84 /* Make sure line vector is big enough. */
86 if (line_vector_index + 2 >= line_vector_length)
88 line_vector_length *= 2;
89 line_vector = (struct linetable *)
90 xrealloc ((char *) line_vector, sizeof (struct linetable)
92 * sizeof (struct linetable_entry)));
95 e = line_vector->item + line_vector_index++;
100 /* Start a new symtab for a new source file.
101 It indicates the start of data for one original source file. */
102 /* FIXME: use start_symtab, like coffread.c now does. */
105 dst_start_symtab (void)
107 /* Initialize the source file line number information for this file. */
109 if (line_vector) /* Unlikely, but maybe possible? */
111 line_vector_index = 0;
112 line_vector_length = 1000;
113 prev_line_number = -2; /* Force first line number to be explicit */
114 line_vector = (struct linetable *)
115 xmalloc (sizeof (struct linetable)
116 + line_vector_length * sizeof (struct linetable_entry));
119 /* Save the vital information from when starting to read a file,
120 for use when closing off the current file.
121 NAME is the file name the symbols came from, START_ADDR is the first
122 text address for the file, and SIZE is the number of bytes of text. */
125 complete_symtab (char *name, CORE_ADDR start_addr, unsigned int size)
127 last_source_file = savestring (name, strlen (name));
128 cur_src_start_addr = start_addr;
129 cur_src_end_addr = start_addr + size;
131 if (current_objfile->ei.entry_point >= cur_src_start_addr &&
132 current_objfile->ei.entry_point < cur_src_end_addr)
134 current_objfile->ei.entry_file_lowpc = cur_src_start_addr;
135 current_objfile->ei.entry_file_highpc = cur_src_end_addr;
139 /* Finish the symbol definitions for one main source file,
140 close off all the lexical contexts for that file
141 (creating struct block's for them), then make the
142 struct symtab for that file and put it in the list of all such. */
143 /* FIXME: Use end_symtab, like coffread.c now does. */
146 dst_end_symtab (struct objfile *objfile)
148 register struct symtab *symtab;
149 register struct blockvector *blockvector;
150 register struct linetable *lv;
152 /* Create the blockvector that points to all the file's blocks. */
154 blockvector = make_blockvector (objfile);
156 /* Now create the symtab object for this source file. */
157 symtab = allocate_symtab (last_source_file, objfile);
159 /* Fill in its components. */
160 symtab->blockvector = blockvector;
161 symtab->free_code = free_linetable;
162 symtab->free_ptr = 0;
163 symtab->filename = last_source_file;
164 symtab->dirname = NULL;
165 symtab->debugformat = obsavestring ("Apollo DST", 10,
166 &objfile->symbol_obstack);
168 lv->nitems = line_vector_index;
169 symtab->linetable = (struct linetable *)
170 xrealloc ((char *) lv, (sizeof (struct linetable)
171 + lv->nitems * sizeof (struct linetable_entry)));
173 free_named_symtabs (symtab->filename);
175 /* Reinitialize for beginning of new file. */
177 line_vector_length = -1;
178 last_source_file = NULL;
181 /* dst_symfile_init ()
182 is the dst-specific initialization routine for reading symbols.
184 We will only be called if this is a DST or DST-like file.
185 BFD handles figuring out the format of the file, and code in symtab.c
186 uses BFD's determination to vector to us.
188 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
191 dst_symfile_init (struct objfile *objfile)
194 bfd *abfd = objfile->obfd;
196 init_entry_point_info (objfile);
200 /* This function is called for every section; it finds the outer limits
201 of the line table (minimum and maximum file offset) so that the
202 mainline code can read the whole thing for efficiency. */
206 find_dst_sections (bfd *abfd, sec_ptr asect, PTR vpinfo)
210 file_ptr offset, maxoff;
213 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
214 size = asect->_raw_size;
215 offset = asect->filepos;
220 if (!strcmp (asect->name, ".blocks"))
221 section = &blocks_info;
222 else if (!strcmp (asect->name, ".lines"))
223 section = &lines_info;
224 else if (!strcmp (asect->name, ".symbols"))
225 section = &symbols_info;
228 section->size = size;
229 section->position = offset;
230 section->base = base;
234 /* The BFD for this file -- only good while we're actively reading
235 symbols into a psymtab or a symtab. */
237 static bfd *symfile_bfd;
239 /* Read a symbol file, after initialization by dst_symfile_init. */
240 /* FIXME! Addr and Mainline are not used yet -- this will not work for
241 shared libraries or add_file! */
245 dst_symfile_read (struct objfile *objfile, int mainline)
247 bfd *abfd = objfile->obfd;
248 char *name = bfd_get_filename (abfd);
253 int stringtab_offset;
255 symfile_bfd = abfd; /* Kludge for swap routines */
257 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
258 desc = fileno ((FILE *) (abfd->iostream)); /* File descriptor */
260 /* Read the line number table, all at once. */
261 bfd_map_over_sections (abfd, find_dst_sections, (PTR) NULL);
263 val = init_dst_sections (desc);
265 error ("\"%s\": error reading debugging symbol tables\n", name);
267 init_minimal_symbol_collection ();
268 make_cleanup_discard_minimal_symbols ();
270 /* Now that the executable file is positioned at symbol table,
271 process it and define symbols accordingly. */
273 read_dst_symtab (objfile);
275 /* Sort symbols alphabetically within each block. */
279 for (s = objfile->symtabs; s != NULL; s = s->next)
281 sort_symtab_syms (s);
285 /* Install any minimal symbols that have been collected as the current
286 minimal symbols for this objfile. */
288 install_minimal_symbols (objfile);
292 dst_new_init (struct objfile *ignore)
297 /* Perform any local cleanups required when we are done with a particular
298 objfile. I.E, we are in the process of discarding all symbol information
299 for an objfile, freeing up all memory held for it, and unlinking the
300 objfile struct from the global list of known objfiles. */
303 dst_symfile_finish (struct objfile *objfile)
309 /* Get the next line number from the DST. Returns 0 when we hit an
310 * end directive or cannot continue for any other reason.
312 * Note that ordinary pc deltas are multiplied by two. Apparently
313 * this is what was really intended.
316 get_dst_line (signed char **buffer, long *pc)
319 static long last_line = 0;
320 static int last_file = 0;
321 dst_ln_entry_ptr_t entry;
323 dst_src_loc_t *src_loc;
330 entry = (dst_ln_entry_ptr_t) * buffer;
332 while (dst_ln_ln_delta (*entry) == dst_ln_escape_flag)
334 switch (entry->esc.esc_code)
337 size = 1; /* pad byte */
340 /* file escape. Next 4 bytes are a dst_src_loc_t */
342 src_loc = (dst_src_loc_t *) (*buffer + 1);
343 last_line = src_loc->line_number;
344 last_file = src_loc->file_index;
346 case dst_ln_dln1_dpc1:
347 /* 1 byte line delta, 1 byte pc delta */
348 last_line += (*buffer)[1];
349 last_pc += 2 * (unsigned char) (*buffer)[2];
350 dst_record_line (last_line, last_pc);
353 case dst_ln_dln2_dpc2:
354 /* 2 bytes line delta, 2 bytes pc delta */
355 last_line += *(short *) (*buffer + 1);
356 last_pc += 2 * (*(short *) (*buffer + 3));
358 dst_record_line (last_line, last_pc);
361 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
362 last_line = *(unsigned long *) (*buffer + 1);
363 last_pc = *(unsigned long *) (*buffer + 5);
365 dst_record_line (last_line, last_pc);
367 case dst_ln_dln1_dpc0:
368 /* 1 byte line delta, pc delta = 0 */
370 last_line += (*buffer)[1];
372 case dst_ln_ln_off_1:
373 /* statement escape, stmt # = 1 (2nd stmt on line) */
377 /* statement escape, stmt # = next byte */
381 /* entry escape, next byte is entry number */
388 case dst_ln_stmt_end:
389 /* gap escape, 4 bytes pc delta */
391 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
392 /* Apparently this isn't supposed to actually modify
393 * the pc value. Totally weird.
396 case dst_ln_escape_11:
397 case dst_ln_escape_12:
398 case dst_ln_escape_13:
401 case dst_ln_nxt_byte:
402 /* This shouldn't happen. If it does, we're SOL */
406 /* end escape, final entry follows */
409 *buffer += (size < 0) ? -size : size;
410 entry = (dst_ln_entry_ptr_t) * buffer;
412 last_line += dst_ln_ln_delta (*entry);
413 last_pc += entry->delta.pc_delta * 2;
415 dst_record_line (last_line, last_pc);
420 enter_all_lines (char *buffer, long address)
423 while (get_dst_line (&buffer, &address));
427 get_dst_entry (char *buffer, dst_rec_ptr_t *ret_entry)
431 static int last_type;
435 entry = (dst_rec_ptr_t) buffer;
436 switch (entry->rec_type)
441 case dst_typ_comp_unit:
442 size = sizeof (DST_comp_unit (entry));
444 case dst_typ_section_tab:
445 size = sizeof (DST_section_tab (entry))
446 + ((int) DST_section_tab (entry).number_of_sections
447 - dst_dummy_array_size) * sizeof (long);
449 case dst_typ_file_tab:
450 size = sizeof (DST_file_tab (entry))
451 + ((int) DST_file_tab (entry).number_of_files
452 - dst_dummy_array_size) * sizeof (dst_file_desc_t);
455 size = sizeof (DST_block (entry))
456 + ((int) DST_block (entry).n_of_code_ranges
457 - dst_dummy_array_size) * sizeof (dst_code_range_t);
463 size = sizeof (DST_var (entry)) -
464 sizeof (dst_var_loc_long_t) * dst_dummy_array_size +
465 DST_var (entry).no_of_locs *
466 (DST_var (entry).short_locs ?
467 sizeof (dst_var_loc_short_t) :
468 sizeof (dst_var_loc_long_t));
470 case dst_typ_pointer:
471 size = sizeof (DST_pointer (entry));
474 size = sizeof (DST_array (entry));
476 case dst_typ_subrange:
477 size = sizeof (DST_subrange (entry));
480 size = sizeof (DST_set (entry));
482 case dst_typ_implicit_enum:
483 size = sizeof (DST_implicit_enum (entry))
484 + ((int) DST_implicit_enum (entry).nelems
485 - dst_dummy_array_size) * sizeof (dst_rel_offset_t);
487 case dst_typ_explicit_enum:
488 size = sizeof (DST_explicit_enum (entry))
489 + ((int) DST_explicit_enum (entry).nelems
490 - dst_dummy_array_size) * sizeof (dst_enum_elem_t);
492 case dst_typ_short_rec:
493 size = sizeof (DST_short_rec (entry))
494 + DST_short_rec (entry).nfields * sizeof (dst_short_field_t)
495 - dst_dummy_array_size * sizeof (dst_field_t);
497 case dst_typ_short_union:
498 size = sizeof (DST_short_union (entry))
499 + DST_short_union (entry).nfields * sizeof (dst_short_field_t)
500 - dst_dummy_array_size * sizeof (dst_field_t);
503 size = sizeof (DST_file (entry));
506 size = sizeof (DST_offset (entry));
509 size = sizeof (DST_alias (entry));
511 case dst_typ_signature:
512 size = sizeof (DST_signature (entry)) +
513 ((int) DST_signature (entry).nargs -
514 dst_dummy_array_size) * sizeof (dst_arg_t);
519 case dst_typ_old_label:
520 size = sizeof (DST_old_label (entry));
523 size = sizeof (DST_scope (entry));
525 case dst_typ_end_scope:
532 case dst_typ_string_tab:
533 case dst_typ_global_name_tab:
534 size = sizeof (DST_string_tab (entry))
535 + DST_string_tab (entry).length
536 - dst_dummy_array_size;
538 case dst_typ_forward:
539 size = sizeof (DST_forward (entry));
540 get_dst_entry ((char *) entry + DST_forward (entry).rec_off, &entry);
542 case dst_typ_aux_size:
543 size = sizeof (DST_aux_size (entry));
545 case dst_typ_aux_align:
546 size = sizeof (DST_aux_align (entry));
548 case dst_typ_aux_field_size:
549 size = sizeof (DST_aux_field_size (entry));
551 case dst_typ_aux_field_off:
552 size = sizeof (DST_aux_field_off (entry));
554 case dst_typ_aux_field_align:
555 size = sizeof (DST_aux_field_align (entry));
557 case dst_typ_aux_qual:
558 size = sizeof (DST_aux_qual (entry));
560 case dst_typ_aux_var_bound:
561 size = sizeof (DST_aux_var_bound (entry));
563 case dst_typ_extension:
564 size = DST_extension (entry).rec_size;
567 size = sizeof (DST_string (entry));
569 case dst_typ_old_entry:
570 size = 48; /* Obsolete entry type */
573 size = sizeof (DST_const (entry))
574 + DST_const (entry).value.length
575 - sizeof (DST_const (entry).value.val);
577 case dst_typ_reference:
578 size = sizeof (DST_reference (entry));
580 case dst_typ_old_record:
581 case dst_typ_old_union:
584 size = sizeof (DST_record (entry))
585 + ((int) DST_record (entry).nfields
586 - dst_dummy_array_size) * sizeof (dst_field_t);
588 case dst_typ_aux_type_deriv:
589 size = sizeof (DST_aux_type_deriv (entry));
591 case dst_typ_locpool:
592 size = sizeof (DST_locpool (entry))
593 + ((int) DST_locpool (entry).length -
594 dst_dummy_array_size);
596 case dst_typ_variable:
597 size = sizeof (DST_variable (entry));
600 size = sizeof (DST_label (entry));
603 size = sizeof (DST_entry (entry));
605 case dst_typ_aux_lifetime:
606 size = sizeof (DST_aux_lifetime (entry));
608 case dst_typ_aux_ptr_base:
609 size = sizeof (DST_aux_ptr_base (entry));
611 case dst_typ_aux_src_range:
612 size = sizeof (DST_aux_src_range (entry));
614 case dst_typ_aux_reg_val:
615 size = sizeof (DST_aux_reg_val (entry));
617 case dst_typ_aux_unit_names:
618 size = sizeof (DST_aux_unit_names (entry))
619 + ((int) DST_aux_unit_names (entry).number_of_names
620 - dst_dummy_array_size) * sizeof (dst_rel_offset_t);
622 case dst_typ_aux_sect_info:
623 size = sizeof (DST_aux_sect_info (entry))
624 + ((int) DST_aux_sect_info (entry).number_of_refs
625 - dst_dummy_array_size) * sizeof (dst_sect_ref_t);
633 fprintf_unfiltered (gdb_stderr, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
634 (int) entry->rec_type,
636 fprintf_unfiltered (gdb_stderr, "Last unknown_3 value: %d\n", lu3);
640 last_type = entry->rec_type;
641 if (size & 1) /* Align on a word boundary */
649 next_dst_entry (char **buffer, dst_rec_ptr_t *entry, dst_sec *table)
651 if (*buffer - table->buffer >= table->size)
656 *buffer += get_dst_entry (*buffer, entry);
660 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
661 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
662 #define DST_OFFSET(a, b) ((char *) (a) + (b))
664 static dst_rec_ptr_t section_table = NULL;
667 get_sec_ref (dst_sect_ref_t *ref)
669 dst_sec *section = NULL;
672 if (!section_table || !ref->sect_index)
674 offset = DST_section_tab (section_table).section_base[ref->sect_index - 1]
676 if (offset >= blocks_info.base &&
677 offset < blocks_info.base + blocks_info.size)
678 section = &blocks_info;
679 else if (offset >= symbols_info.base &&
680 offset < symbols_info.base + symbols_info.size)
681 section = &symbols_info;
682 else if (offset >= lines_info.base &&
683 offset < lines_info.base + lines_info.size)
684 section = &lines_info;
687 return section->buffer + (offset - section->base);
691 dst_get_addr (int section, long offset)
693 if (!section_table || !section)
695 return DST_section_tab (section_table).section_base[section - 1] + offset;
699 dst_sym_addr (dst_sect_ref_t *ref)
701 if (!section_table || !ref->sect_index)
703 return DST_section_tab (section_table).section_base[ref->sect_index - 1]
708 create_new_type (struct objfile *objfile)
712 type = (struct type *)
713 obstack_alloc (&objfile->symbol_obstack, sizeof (struct type));
714 memset (type, 0, sizeof (struct type));
718 static struct symbol *
719 create_new_symbol (struct objfile *objfile, char *name)
721 struct symbol *sym = (struct symbol *)
722 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
723 memset (sym, 0, sizeof (struct symbol));
724 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
725 &objfile->symbol_obstack);
726 SYMBOL_VALUE (sym) = 0;
727 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
729 SYMBOL_CLASS (sym) = LOC_BLOCK;
733 static struct type *decode_dst_type (struct objfile *, dst_rec_ptr_t);
736 decode_type_desc (struct objfile *objfile, dst_type_t *type_desc,
741 if (type_desc->std_type.user_defined_type)
743 entry = (dst_rec_ptr_t) DST_OFFSET (base,
744 dst_user_type_offset (*type_desc));
745 type = decode_dst_type (objfile, entry);
749 switch (type_desc->std_type.dtc)
752 type = builtin_type_signed_char;
755 type = builtin_type_short;
758 type = builtin_type_long;
761 type = builtin_type_unsigned_char;
763 case dst_uint16_type:
764 type = builtin_type_unsigned_short;
766 case dst_uint32_type:
767 type = builtin_type_unsigned_long;
769 case dst_real32_type:
770 type = builtin_type_float;
772 case dst_real64_type:
773 type = builtin_type_double;
775 case dst_complex_type:
776 type = builtin_type_complex;
778 case dst_dcomplex_type:
779 type = builtin_type_double_complex;
782 type = builtin_type_char;
784 case dst_bool16_type:
785 type = builtin_type_short;
787 case dst_bool32_type:
788 type = builtin_type_long;
791 type = builtin_type_char;
793 /* The next few are more complex. I will take care
794 * of them properly at a later point.
796 case dst_string_type:
797 type = builtin_type_void;
800 type = builtin_type_void;
803 type = builtin_type_void;
806 type = builtin_type_void;
809 type = builtin_type_void;
811 /* Back tto some ordinary ones */
813 type = builtin_type_void;
816 type = builtin_type_unsigned_char;
819 type = builtin_type_void;
826 struct structure_list
828 struct structure_list *next;
832 static struct structure_list *struct_list = NULL;
835 find_dst_structure (char *name)
837 struct structure_list *element;
839 for (element = struct_list; element; element = element->next)
840 if (!strcmp (name, TYPE_NAME (element->type)))
841 return element->type;
847 decode_dst_structure (struct objfile *objfile, dst_rec_ptr_t entry, int code,
850 struct type *type, *child_type;
852 char *name, *field_name;
854 int fieldoffset, fieldsize;
855 dst_type_t type_desc;
856 struct structure_list *element;
858 struct_name = DST_OFFSET (entry, DST_record (entry).noffset);
859 name = concat ((code == TYPE_CODE_UNION) ? "union " : "struct ",
861 type = find_dst_structure (name);
867 type = create_new_type (objfile);
868 TYPE_NAME (type) = obstack_copy0 (&objfile->symbol_obstack,
869 name, strlen (name));
871 TYPE_CODE (type) = code;
872 TYPE_LENGTH (type) = DST_record (entry).size;
873 TYPE_NFIELDS (type) = DST_record (entry).nfields;
874 TYPE_FIELDS (type) = (struct field *)
875 obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) *
876 DST_record (entry).nfields);
877 fieldoffset = fieldsize = 0;
878 INIT_CPLUS_SPECIFIC (type);
879 element = (struct structure_list *)
880 xmalloc (sizeof (struct structure_list));
881 element->type = type;
882 element->next = struct_list;
883 struct_list = element;
884 for (i = 0; i < DST_record (entry).nfields; i++)
889 field_name = DST_OFFSET (entry,
890 DST_record (entry).f.ofields[i].noffset);
891 fieldoffset = DST_record (entry).f.ofields[i].foffset * 8 +
892 DST_record (entry).f.ofields[i].bit_offset;
893 fieldsize = DST_record (entry).f.ofields[i].size;
894 type_desc = DST_record (entry).f.ofields[i].type_desc;
897 field_name = DST_OFFSET (entry,
898 DST_record (entry).f.fields[i].noffset);
899 type_desc = DST_record (entry).f.fields[i].type_desc;
900 switch (DST_record (entry).f.fields[i].f.field_loc.format_tag)
903 fieldoffset = DST_record (entry).f.
904 fields[i].f.field_byte.offset * 8;
908 fieldoffset = DST_record (entry).f.
909 fields[i].f.field_bit.byte_offset * 8 +
910 DST_record (entry).f.
911 fields[i].f.field_bit.bit_offset;
912 fieldsize = DST_record (entry).f.
913 fields[i].f.field_bit.nbits;
916 fieldoffset += fieldsize;
922 field_name = DST_OFFSET (entry,
923 DST_record (entry).f.sfields[i].noffset);
924 fieldoffset = DST_record (entry).f.sfields[i].foffset;
925 type_desc = DST_record (entry).f.sfields[i].type_desc;
926 if (i < DST_record (entry).nfields - 1)
927 fieldsize = DST_record (entry).f.sfields[i + 1].foffset;
929 fieldsize = DST_record (entry).size;
930 fieldsize -= fieldoffset;
934 TYPE_FIELDS (type)[i].name =
935 obstack_copy0 (&objfile->symbol_obstack,
936 field_name, strlen (field_name));
937 TYPE_FIELDS (type)[i].type = decode_type_desc (objfile,
941 fieldsize = TYPE_LENGTH (TYPE_FIELDS (type)[i].type) *
943 TYPE_FIELDS (type)[i].bitsize = fieldsize;
944 TYPE_FIELDS (type)[i].bitpos = fieldoffset;
950 decode_dst_type (struct objfile *objfile, dst_rec_ptr_t entry)
952 struct type *child_type, *type, *range_type, *index_type;
954 switch (entry->rec_type)
957 return decode_type_desc (objfile,
958 &DST_var (entry).type_desc,
961 case dst_typ_variable:
962 return decode_type_desc (objfile,
963 &DST_variable (entry).type_desc,
966 case dst_typ_short_rec:
967 return decode_dst_structure (objfile, entry, TYPE_CODE_STRUCT, 0);
968 case dst_typ_short_union:
969 return decode_dst_structure (objfile, entry, TYPE_CODE_UNION, 0);
971 return decode_dst_structure (objfile, entry, TYPE_CODE_UNION, 1);
973 return decode_dst_structure (objfile, entry, TYPE_CODE_STRUCT, 1);
974 case dst_typ_old_union:
975 return decode_dst_structure (objfile, entry, TYPE_CODE_UNION, 2);
976 case dst_typ_old_record:
977 return decode_dst_structure (objfile, entry, TYPE_CODE_STRUCT, 2);
978 case dst_typ_pointer:
979 return make_pointer_type (
980 decode_type_desc (objfile,
981 &DST_pointer (entry).type_desc,
985 child_type = decode_type_desc (objfile,
986 &DST_pointer (entry).type_desc,
988 index_type = lookup_fundamental_type (objfile,
990 range_type = create_range_type ((struct type *) NULL,
991 index_type, DST_array (entry).lo_bound,
992 DST_array (entry).hi_bound);
993 return create_array_type ((struct type *) NULL, child_type,
996 return decode_type_desc (objfile,
997 &DST_alias (entry).type_desc,
1000 return builtin_type_int;
1006 struct symbol_list *next;
1007 struct symbol *symbol;
1010 static struct symbol_list *dst_global_symbols = NULL;
1011 static int total_globals = 0;
1014 decode_dst_locstring (char *locstr, struct symbol *sym)
1016 dst_loc_entry_t *entry, *next_entry;
1024 fprintf_unfiltered (gdb_stderr, "Error reading locstring\n");
1027 entry = (dst_loc_entry_t *) locstr;
1028 next_entry = (dst_loc_entry_t *) (locstr + 1);
1029 switch (entry->header.code)
1031 case dst_lsc_end: /* End of string */
1033 case dst_lsc_indirect: /* Indirect through previous. Arg == 6 */
1034 /* Or register ax x == arg */
1035 if (entry->header.arg < 6)
1037 SYMBOL_CLASS (sym) = LOC_REGISTER;
1038 SYMBOL_VALUE (sym) = entry->header.arg + 8;
1040 /* We predict indirects */
1044 SYMBOL_CLASS (sym) = LOC_REGISTER;
1045 SYMBOL_VALUE (sym) = entry->header.arg;
1048 case dst_lsc_section: /* Section (arg+1) */
1049 SYMBOL_VALUE (sym) = dst_get_addr (entry->header.arg + 1, 0);
1052 case dst_lsc_sec_byte: /* Section (next_byte+1) */
1053 SYMBOL_VALUE (sym) = dst_get_addr (locstr[1] + 1, 0);
1056 case dst_lsc_add: /* Add (arg+1)*2 */
1057 case dst_lsc_sub: /* Subtract (arg+1)*2 */
1058 temp = (entry->header.arg + 1) * 2;
1060 if (*locstr == dst_multiply_256)
1065 switch (entry->header.code)
1068 if (SYMBOL_CLASS (sym) == LOC_LOCAL)
1069 SYMBOL_CLASS (sym) = LOC_ARG;
1070 SYMBOL_VALUE (sym) += temp;
1073 SYMBOL_VALUE (sym) -= temp;
1077 case dst_lsc_add_byte:
1078 case dst_lsc_sub_byte:
1079 switch (entry->header.arg & 0x03)
1082 temp = (unsigned char) locstr[1];
1086 temp = *(unsigned short *) (locstr + 1);
1090 temp = *(unsigned long *) (locstr + 1);
1094 if (*locstr == dst_multiply_256)
1099 switch (entry->header.code)
1101 case dst_lsc_add_byte:
1102 if (SYMBOL_CLASS (sym) == LOC_LOCAL)
1103 SYMBOL_CLASS (sym) = LOC_ARG;
1104 SYMBOL_VALUE (sym) += temp;
1106 case dst_lsc_sub_byte:
1107 SYMBOL_VALUE (sym) -= temp;
1111 case dst_lsc_sbreg: /* Stack base register (frame pointer). Arg==0 */
1112 if (next_entry->header.code != dst_lsc_indirect)
1114 SYMBOL_VALUE (sym) = 0;
1115 SYMBOL_CLASS (sym) = LOC_STATIC;
1118 SYMBOL_VALUE (sym) = 0;
1119 SYMBOL_CLASS (sym) = LOC_LOCAL;
1123 SYMBOL_VALUE (sym) = 0;
1124 SYMBOL_CLASS (sym) = LOC_STATIC;
1130 static struct symbol_list *
1131 process_dst_symbols (struct objfile *objfile, dst_rec_ptr_t entry, char *name,
1134 struct symbol_list *list = NULL, *element;
1142 dst_var_attr_t attr;
1143 dst_var_loc_t loc_type;
1152 location = (char *) entry;
1153 while (NEXT_SYM (&location, &entry) &&
1154 entry->rec_type != dst_typ_end_scope)
1156 if (entry->rec_type == dst_typ_var)
1158 if (DST_var (entry).short_locs)
1160 loc_type = DST_var (entry).locs.shorts[0].loc_type;
1161 loc_index = DST_var (entry).locs.shorts[0].loc_index;
1162 loc_value = DST_var (entry).locs.shorts[0].location;
1166 loc_type = DST_var (entry).locs.longs[0].loc_type;
1167 loc_index = DST_var (entry).locs.longs[0].loc_index;
1168 loc_value = DST_var (entry).locs.longs[0].location;
1170 if (loc_type == dst_var_loc_external)
1172 symname = DST_OFFSET (entry, DST_var (entry).noffset);
1173 line = DST_var (entry).src_loc.line_number;
1174 symtype = DST_var (entry).type_desc;
1175 attr = DST_var (entry).attributes;
1177 else if (entry->rec_type == dst_typ_variable)
1179 symname = DST_OFFSET (entry,
1180 DST_variable (entry).noffset);
1181 line = DST_variable (entry).src_loc.line_number;
1182 symtype = DST_variable (entry).type_desc;
1183 attr = DST_variable (entry).attributes;
1189 if (symname && name && !strcmp (symname, name))
1190 /* It's the function return value */
1192 sym = create_new_symbol (objfile, symname);
1194 if ((attr & (1 << dst_var_attr_global)) ||
1195 (attr & (1 << dst_var_attr_static)))
1196 SYMBOL_CLASS (sym) = LOC_STATIC;
1198 SYMBOL_CLASS (sym) = LOC_LOCAL;
1199 SYMBOL_LINE (sym) = line;
1200 SYMBOL_TYPE (sym) = decode_type_desc (objfile, &symtype,
1202 SYMBOL_VALUE (sym) = 0;
1203 switch (entry->rec_type)
1208 case dst_var_loc_abs:
1209 SYMBOL_VALUE_ADDRESS (sym) = loc_value;
1211 case dst_var_loc_sect_off:
1212 case dst_var_loc_ind_sect_off: /* What is this? */
1213 SYMBOL_VALUE_ADDRESS (sym) = dst_get_addr (
1217 case dst_var_loc_ind_reg_rel: /* What is this? */
1218 case dst_var_loc_reg_rel:
1219 /* If it isn't fp relative, specify the
1220 * register it's relative to.
1224 sym->aux_value.basereg = loc_index;
1226 SYMBOL_VALUE (sym) = loc_value;
1227 if (loc_value > 0 &&
1228 SYMBOL_CLASS (sym) == LOC_BASEREG)
1229 SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
1231 case dst_var_loc_reg:
1232 SYMBOL_VALUE (sym) = loc_index;
1233 SYMBOL_CLASS (sym) = LOC_REGISTER;
1237 case dst_typ_variable:
1238 /* External variable..... don't try to interpret
1239 * its nonexistant locstring.
1241 if (DST_variable (entry).loffset == -1)
1243 decode_dst_locstring (DST_OFFSET (entry,
1244 DST_variable (entry).loffset),
1247 element = (struct symbol_list *)
1248 xmalloc (sizeof (struct symbol_list));
1250 if (attr & (1 << dst_var_attr_global))
1252 element->next = dst_global_symbols;
1253 dst_global_symbols = element;
1258 element->next = list;
1262 element->symbol = sym;
1269 static struct symbol *
1270 process_dst_function (struct objfile *objfile, dst_rec_ptr_t entry, char *name,
1274 struct type *type, *ftype;
1275 dst_rec_ptr_t sym_entry, typ_entry;
1277 struct symbol_list *element;
1279 type = builtin_type_int;
1280 sym = create_new_symbol (objfile, name);
1281 SYMBOL_CLASS (sym) = LOC_BLOCK;
1285 location = (char *) entry;
1288 NEXT_SYM (&location, &sym_entry);
1290 while (sym_entry && sym_entry->rec_type != dst_typ_signature);
1295 DST_signature (sym_entry).src_loc.line_number;
1296 if (DST_signature (sym_entry).result)
1298 typ_entry = (dst_rec_ptr_t)
1299 DST_OFFSET (sym_entry,
1300 DST_signature (sym_entry).result);
1301 type = decode_dst_type (objfile, typ_entry);
1306 if (!type->function_type)
1308 ftype = create_new_type (objfile);
1309 type->function_type = ftype;
1310 ftype->target_type = type;
1311 ftype->code = TYPE_CODE_FUNC;
1313 SYMBOL_TYPE (sym) = type->function_type;
1315 /* Now add ourselves to the global symbols list */
1316 element = (struct symbol_list *)
1317 xmalloc (sizeof (struct symbol_list));
1319 element->next = dst_global_symbols;
1320 dst_global_symbols = element;
1322 element->symbol = sym;
1327 static struct block *
1328 process_dst_block (struct objfile *objfile, dst_rec_ptr_t entry)
1330 struct block *block;
1331 struct symbol *function = NULL;
1335 dst_rec_ptr_t child_entry, symbol_entry;
1336 struct block *child_block;
1337 int total_symbols = 0;
1339 static long fake_seq = 0;
1340 struct symbol_list *symlist, *nextsym;
1343 if (DST_block (entry).noffset)
1344 name = DST_OFFSET (entry, DST_block (entry).noffset);
1347 if (DST_block (entry).n_of_code_ranges)
1349 address = dst_sym_addr (
1350 &DST_block (entry).code_ranges[0].code_start);
1351 size = DST_block (entry).code_ranges[0].code_size;
1358 symbol_entry = (dst_rec_ptr_t) get_sec_ref (&DST_block (entry).symbols_start);
1359 switch (DST_block (entry).block_type)
1361 /* These are all really functions. Even the "program" type.
1362 * This is because the Apollo OS was written in Pascal, and
1363 * in Pascal, the main procedure is described as the Program.
1366 case dst_block_procedure:
1367 case dst_block_function:
1368 case dst_block_subroutine:
1369 case dst_block_program:
1370 prim_record_minimal_symbol (name, address, mst_text, objfile);
1371 function = process_dst_function (
1376 enter_all_lines (get_sec_ref (&DST_block (entry).code_ranges[0].lines_start), address);
1378 case dst_block_block_data:
1382 /* GDB has to call it something, and the module name
1385 sprintf (fake_name, "block_%08lx", fake_seq++);
1386 function = process_dst_function (
1387 objfile, NULL, fake_name, address);
1390 symlist = process_dst_symbols (objfile, symbol_entry,
1391 name, &total_symbols);
1392 block = (struct block *)
1393 obstack_alloc (&objfile->symbol_obstack,
1394 sizeof (struct block) +
1395 (total_symbols - 1) * sizeof (struct symbol *));
1400 nextsym = symlist->next;
1402 block->sym[symnum] = symlist->symbol;
1408 BLOCK_NSYMS (block) = total_symbols;
1409 BLOCK_START (block) = address;
1410 BLOCK_END (block) = address + size;
1411 BLOCK_SUPERBLOCK (block) = 0;
1414 SYMBOL_BLOCK_VALUE (function) = block;
1415 BLOCK_FUNCTION (block) = function;
1418 BLOCK_FUNCTION (block) = 0;
1420 if (DST_block (entry).child_block_off)
1422 child_entry = (dst_rec_ptr_t) DST_OFFSET (entry,
1423 DST_block (entry).child_block_off);
1426 child_block = process_dst_block (objfile, child_entry);
1429 if (BLOCK_START (child_block) <
1430 BLOCK_START (block) ||
1431 BLOCK_START (block) == -1)
1432 BLOCK_START (block) =
1433 BLOCK_START (child_block);
1434 if (BLOCK_END (child_block) >
1435 BLOCK_END (block) ||
1436 BLOCK_END (block) == -1)
1438 BLOCK_END (child_block);
1439 BLOCK_SUPERBLOCK (child_block) = block;
1441 if (DST_block (child_entry).sibling_block_off)
1442 child_entry = (dst_rec_ptr_t) DST_OFFSET (
1444 DST_block (child_entry).sibling_block_off);
1449 record_pending_block (objfile, block, NULL);
1455 read_dst_symtab (struct objfile *objfile)
1458 dst_rec_ptr_t entry, file_table, root_block;
1460 struct block *block, *global_block;
1462 struct symbol_list *nextsym;
1464 struct structure_list *element;
1466 current_objfile = objfile;
1467 buffer = blocks_info.buffer;
1468 while (NEXT_BLK (&buffer, &entry))
1470 if (entry->rec_type == dst_typ_comp_unit)
1472 file_table = (dst_rec_ptr_t) DST_OFFSET (entry,
1473 DST_comp_unit (entry).file_table);
1474 section_table = (dst_rec_ptr_t) DST_OFFSET (entry,
1475 DST_comp_unit (entry).section_table);
1476 root_block = (dst_rec_ptr_t) DST_OFFSET (entry,
1477 DST_comp_unit (entry).root_block_offset);
1478 source_file = DST_OFFSET (file_table,
1479 DST_file_tab (file_table).files[0].noffset);
1480 /* Point buffer to the start of the next comp_unit */
1481 buffer = DST_OFFSET (entry,
1482 DST_comp_unit (entry).data_size);
1483 dst_start_symtab ();
1485 block = process_dst_block (objfile, root_block);
1487 global_block = (struct block *)
1488 obstack_alloc (&objfile->symbol_obstack,
1489 sizeof (struct block) +
1490 (total_globals - 1) *
1491 sizeof (struct symbol *));
1492 BLOCK_NSYMS (global_block) = total_globals;
1493 for (symnum = 0; symnum < total_globals; symnum++)
1495 nextsym = dst_global_symbols->next;
1497 global_block->sym[symnum] =
1498 dst_global_symbols->symbol;
1500 xfree (dst_global_symbols);
1501 dst_global_symbols = nextsym;
1503 dst_global_symbols = NULL;
1505 BLOCK_FUNCTION (global_block) = 0;
1506 BLOCK_START (global_block) = BLOCK_START (block);
1507 BLOCK_END (global_block) = BLOCK_END (block);
1508 BLOCK_SUPERBLOCK (global_block) = 0;
1509 BLOCK_SUPERBLOCK (block) = global_block;
1510 record_pending_block (objfile, global_block, NULL);
1512 complete_symtab (source_file,
1513 BLOCK_START (block),
1514 BLOCK_END (block) - BLOCK_START (block));
1516 dst_end_symtab (objfile);
1520 prim_record_minimal_symbol ("<end_of_program>",
1521 BLOCK_END (block), mst_text, objfile);
1522 /* One more faked symbol to make sure nothing can ever run off the
1523 * end of the symbol table. This one represents the end of the
1524 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1525 * int possible), but some parts of gdb treated it as a signed
1526 * number and failed comparisons. We could equally use 7fffffff,
1527 * but no functions are ever mapped to an address higher than
1530 prim_record_minimal_symbol ("<end_of_text>",
1531 (CORE_ADDR) 0x40000000,
1535 element = struct_list;
1536 struct_list = element->next;
1542 /* Support for line number handling */
1543 static char *linetab = NULL;
1544 static long linetab_offset;
1545 static unsigned long linetab_size;
1547 /* Read in all the line numbers for fast lookups later. Leave them in
1548 external (unswapped) format in memory; we'll swap them as we enter
1549 them into GDB's data structures. */
1551 init_one_section (int chan, dst_sec *secinfo)
1553 if (secinfo->size == 0
1554 || lseek (chan, secinfo->position, 0) == -1
1555 || (secinfo->buffer = xmalloc (secinfo->size)) == NULL
1556 || myread (chan, secinfo->buffer, secinfo->size) == -1)
1563 init_dst_sections (int chan)
1566 if (!init_one_section (chan, &blocks_info) ||
1567 !init_one_section (chan, &lines_info) ||
1568 !init_one_section (chan, &symbols_info))
1574 /* Fake up support for relocating symbol addresses. FIXME. */
1576 struct section_offsets dst_symfile_faker =
1580 dst_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
1582 objfile->num_sections = 1;
1583 objfile->section_offsets = &dst_symfile_faker;
1586 /* Register our ability to parse symbols for DST BFD files */
1588 static struct sym_fns dst_sym_fns =
1590 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1591 a separate flavour like ecoff? */
1592 (enum bfd_flavour) -2,
1594 dst_new_init, /* sym_new_init: init anything gbl to entire symtab */
1595 dst_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1596 dst_symfile_read, /* sym_read: read a symbol file into symtab */
1597 dst_symfile_finish, /* sym_finish: finished with file, cleanup */
1598 dst_symfile_offsets, /* sym_offsets: xlate external to internal form */
1599 NULL /* next: pointer to next struct sym_fns */
1603 _initialize_dstread (void)
1605 add_symtab_fns (&dst_sym_fns);