1 /* Read apollo DST symbol tables and convert to internal format, for GDB.
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, Boston, MA 02111-1307, USA. */
24 #include "breakpoint.h"
31 #include "gdb_string.h"
35 CORE_ADDR cur_src_start_addr, cur_src_end_addr;
36 dst_sec blocks_info, lines_info, symbols_info;
38 /* Vector of line number information. */
40 static struct linetable *line_vector;
42 /* Index of next entry to go in line_vector_index. */
44 static int line_vector_index;
46 /* Last line number recorded in the line vector. */
48 static int prev_line_number;
50 /* Number of elements allocated for line_vector currently. */
52 static int line_vector_length;
54 static struct blockvector *
55 make_blockvector PARAMS ((struct objfile *));
58 init_dst_sections PARAMS ((int));
61 read_dst_symtab PARAMS ((struct objfile *));
64 find_dst_sections PARAMS ((bfd *, sec_ptr, PTR));
67 dst_symfile_init PARAMS ((struct objfile *));
70 dst_new_init PARAMS ((struct objfile *));
73 dst_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
76 dst_symfile_finish PARAMS ((struct objfile *));
79 dst_end_symtab PARAMS ((struct objfile *));
82 complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
85 dst_start_symtab PARAMS ((void));
88 dst_record_line PARAMS ((int, CORE_ADDR));
90 static struct blockvector *
91 make_blockvector (objfile)
92 struct objfile *objfile;
94 register struct pending_block *next, *next1;
95 register struct blockvector *blockvector;
98 /* Count the length of the list of blocks. */
100 for (next = pending_blocks, i = 0; next; next = next->next, i++);
102 blockvector = (struct blockvector *)
103 obstack_alloc (&objfile->symbol_obstack, sizeof (struct blockvector) + (i - 1) * sizeof (struct block *));
105 /* Copy the blocks into the blockvector.
106 This is done in reverse order, which happens to put
107 the blocks into the proper order (ascending starting address).
110 BLOCKVECTOR_NBLOCKS (blockvector) = i;
111 for (next = pending_blocks; next; next = next->next)
112 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
114 /* Now free the links of the list, and empty the list. */
116 for (next = pending_blocks; next; next = next1)
126 /* Manage the vector of line numbers. */
127 /* FIXME: Use record_line instead. */
130 dst_record_line (line, pc)
134 struct linetable_entry *e;
135 /* Make sure line vector is big enough. */
137 if (line_vector_index + 2 >= line_vector_length)
139 line_vector_length *= 2;
140 line_vector = (struct linetable *)
141 xrealloc ((char *) line_vector, sizeof (struct linetable)
142 + (line_vector_length
143 * sizeof (struct linetable_entry)));
146 e = line_vector->item + line_vector_index++;
147 e->line = line; e->pc = pc;
150 /* Start a new symtab for a new source file.
151 It indicates the start of data for one original source file. */
152 /* FIXME: use start_symtab, like coffread.c now does. */
157 /* Initialize the source file line number information for this file. */
159 if (line_vector) /* Unlikely, but maybe possible? */
160 free ((PTR)line_vector);
161 line_vector_index = 0;
162 line_vector_length = 1000;
163 prev_line_number = -2; /* Force first line number to be explicit */
164 line_vector = (struct linetable *)
165 xmalloc (sizeof (struct linetable)
166 + line_vector_length * sizeof (struct linetable_entry));
169 /* Save the vital information from when starting to read a file,
170 for use when closing off the current file.
171 NAME is the file name the symbols came from, START_ADDR is the first
172 text address for the file, and SIZE is the number of bytes of text. */
175 complete_symtab (name, start_addr, size)
177 CORE_ADDR start_addr;
180 last_source_file = savestring (name, strlen (name));
181 cur_src_start_addr = start_addr;
182 cur_src_end_addr = start_addr + size;
184 if (current_objfile -> ei.entry_point >= cur_src_start_addr &&
185 current_objfile -> ei.entry_point < cur_src_end_addr)
187 current_objfile -> ei.entry_file_lowpc = cur_src_start_addr;
188 current_objfile -> ei.entry_file_highpc = cur_src_end_addr;
192 /* Finish the symbol definitions for one main source file,
193 close off all the lexical contexts for that file
194 (creating struct block's for them), then make the
195 struct symtab for that file and put it in the list of all such. */
196 /* FIXME: Use end_symtab, like coffread.c now does. */
199 dst_end_symtab (objfile)
200 struct objfile *objfile;
202 register struct symtab *symtab;
203 register struct blockvector *blockvector;
204 register struct linetable *lv;
206 /* Create the blockvector that points to all the file's blocks. */
208 blockvector = make_blockvector (objfile);
210 /* Now create the symtab object for this source file. */
211 symtab = allocate_symtab (last_source_file, objfile);
213 /* Fill in its components. */
214 symtab->blockvector = blockvector;
215 symtab->free_code = free_linetable;
216 symtab->free_ptr = 0;
217 symtab->filename = last_source_file;
218 symtab->dirname = NULL;
220 lv->nitems = line_vector_index;
221 symtab->linetable = (struct linetable *)
222 xrealloc ((char *) lv, (sizeof (struct linetable)
223 + lv->nitems * sizeof (struct linetable_entry)));
225 free_named_symtabs (symtab->filename);
227 /* Reinitialize for beginning of new file. */
229 line_vector_length = -1;
230 last_source_file = NULL;
233 /* dst_symfile_init ()
234 is the dst-specific initialization routine for reading symbols.
236 We will only be called if this is a DST or DST-like file.
237 BFD handles figuring out the format of the file, and code in symtab.c
238 uses BFD's determination to vector to us.
240 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
243 dst_symfile_init (objfile)
244 struct objfile *objfile;
247 bfd *abfd = objfile->obfd;
249 init_entry_point_info (objfile);
253 /* This function is called for every section; it finds the outer limits
254 of the line table (minimum and maximum file offset) so that the
255 mainline code can read the whole thing for efficiency. */
259 find_dst_sections (abfd, asect, vpinfo)
266 file_ptr offset, maxoff;
269 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
270 size = asect->_raw_size;
271 offset = asect->filepos;
276 if (!strcmp(asect->name, ".blocks"))
277 section = &blocks_info;
278 else if (!strcmp(asect->name, ".lines"))
279 section = &lines_info;
280 else if (!strcmp(asect->name, ".symbols"))
281 section = &symbols_info;
284 section->size = size;
285 section->position = offset;
286 section->base = base;
290 /* The BFD for this file -- only good while we're actively reading
291 symbols into a psymtab or a symtab. */
293 static bfd *symfile_bfd;
295 /* Read a symbol file, after initialization by dst_symfile_init. */
296 /* FIXME! Addr and Mainline are not used yet -- this will not work for
297 shared libraries or add_file! */
301 dst_symfile_read (objfile, section_offsets, mainline)
302 struct objfile *objfile;
303 struct section_offsets *section_offsets;
306 bfd *abfd = objfile->obfd;
307 char *name = bfd_get_filename (abfd);
312 int stringtab_offset;
314 symfile_bfd = abfd; /* Kludge for swap routines */
316 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
317 desc = fileno ((GDB_FILE *)(abfd->iostream)); /* File descriptor */
319 /* Read the line number table, all at once. */
320 bfd_map_over_sections (abfd, find_dst_sections, (PTR)NULL);
322 val = init_dst_sections (desc);
324 error ("\"%s\": error reading debugging symbol tables\n", name);
326 init_minimal_symbol_collection ();
327 make_cleanup (discard_minimal_symbols, 0);
329 /* Now that the executable file is positioned at symbol table,
330 process it and define symbols accordingly. */
332 read_dst_symtab (objfile);
334 /* Sort symbols alphabetically within each block. */
338 for (s = objfile -> symtabs; s != NULL; s = s -> next)
340 sort_symtab_syms (s);
344 /* Install any minimal symbols that have been collected as the current
345 minimal symbols for this objfile. */
347 install_minimal_symbols (objfile);
351 dst_new_init (ignore)
352 struct objfile *ignore;
357 /* Perform any local cleanups required when we are done with a particular
358 objfile. I.E, we are in the process of discarding all symbol information
359 for an objfile, freeing up all memory held for it, and unlinking the
360 objfile struct from the global list of known objfiles. */
363 dst_symfile_finish (objfile)
364 struct objfile *objfile;
370 /* Get the next line number from the DST. Returns 0 when we hit an
371 * end directive or cannot continue for any other reason.
373 * Note that ordinary pc deltas are multiplied by two. Apparently
374 * this is what was really intended.
377 get_dst_line(buffer, pc)
378 signed char **buffer;
382 static long last_line = 0;
383 static int last_file = 0;
384 dst_ln_entry_ptr_t entry;
386 dst_src_loc_t *src_loc;
393 entry = (dst_ln_entry_ptr_t) *buffer;
395 while (dst_ln_ln_delta(*entry) == dst_ln_escape_flag)
397 switch(entry->esc.esc_code)
400 size = 1; /* pad byte */
403 /* file escape. Next 4 bytes are a dst_src_loc_t */
405 src_loc = (dst_src_loc_t *) (*buffer + 1);
406 last_line = src_loc->line_number;
407 last_file = src_loc->file_index;
409 case dst_ln_dln1_dpc1:
410 /* 1 byte line delta, 1 byte pc delta */
411 last_line += (*buffer)[1];
412 last_pc += 2 * (unsigned char) (*buffer)[2];
413 dst_record_line(last_line, last_pc);
416 case dst_ln_dln2_dpc2:
417 /* 2 bytes line delta, 2 bytes pc delta */
418 last_line += *(short *) (*buffer + 1);
419 last_pc += 2 * (*(short *) (*buffer + 3));
421 dst_record_line(last_line, last_pc);
424 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
425 last_line = *(unsigned long *) (*buffer + 1);
426 last_pc = *(unsigned long *) (*buffer + 5);
428 dst_record_line(last_line, last_pc);
430 case dst_ln_dln1_dpc0:
431 /* 1 byte line delta, pc delta = 0 */
433 last_line+= (*buffer)[1];
435 case dst_ln_ln_off_1:
436 /* statement escape, stmt # = 1 (2nd stmt on line) */
440 /* statement escape, stmt # = next byte */
444 /* entry escape, next byte is entry number */
451 case dst_ln_stmt_end:
452 /* gap escape, 4 bytes pc delta */
454 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
455 /* Apparently this isn't supposed to actually modify
456 * the pc value. Totally weird.
459 case dst_ln_escape_11:
460 case dst_ln_escape_12:
461 case dst_ln_escape_13:
464 case dst_ln_nxt_byte:
465 /* This shouldn't happen. If it does, we're SOL */
469 /* end escape, final entry follows */
472 *buffer += (size < 0) ? -size : size;
473 entry = (dst_ln_entry_ptr_t) *buffer;
475 last_line += dst_ln_ln_delta(*entry);
476 last_pc += entry->delta.pc_delta * 2;
478 dst_record_line(last_line, last_pc);
483 enter_all_lines(buffer, address)
488 while (get_dst_line(&buffer, &address));
492 get_dst_entry(buffer, ret_entry)
494 dst_rec_ptr_t *ret_entry;
498 static int last_type;
502 entry = (dst_rec_ptr_t) buffer;
503 switch(entry->rec_type)
508 case dst_typ_comp_unit:
509 size = sizeof(DST_comp_unit(entry));
511 case dst_typ_section_tab:
512 size = sizeof(DST_section_tab(entry))
513 + ((int) DST_section_tab(entry).number_of_sections
514 - dst_dummy_array_size) * sizeof(long);
516 case dst_typ_file_tab:
517 size = sizeof(DST_file_tab(entry))
518 + ((int) DST_file_tab(entry).number_of_files
519 - dst_dummy_array_size) * sizeof(dst_file_desc_t);
522 size = sizeof(DST_block(entry))
523 + ((int) DST_block(entry).n_of_code_ranges
524 - dst_dummy_array_size) * sizeof(dst_code_range_t);
530 size = sizeof(DST_var(entry)) -
531 sizeof(dst_var_loc_long_t) * dst_dummy_array_size +
532 DST_var(entry).no_of_locs *
533 ( DST_var(entry).short_locs ?
534 sizeof(dst_var_loc_short_t):
535 sizeof(dst_var_loc_long_t));
537 case dst_typ_pointer:
538 size = sizeof(DST_pointer(entry));
541 size = sizeof(DST_array(entry));
543 case dst_typ_subrange:
544 size = sizeof(DST_subrange(entry));
547 size = sizeof(DST_set(entry));
549 case dst_typ_implicit_enum:
550 size = sizeof(DST_implicit_enum(entry))
551 + ((int) DST_implicit_enum(entry).nelems
552 - dst_dummy_array_size) * sizeof(dst_rel_offset_t);
554 case dst_typ_explicit_enum:
555 size = sizeof(DST_explicit_enum(entry))
556 + ((int) DST_explicit_enum(entry).nelems
557 - dst_dummy_array_size) * sizeof(dst_enum_elem_t);
559 case dst_typ_short_rec:
560 size = sizeof(DST_short_rec(entry))
561 + DST_short_rec(entry).nfields * sizeof(dst_short_field_t)
562 - dst_dummy_array_size * sizeof(dst_field_t);
564 case dst_typ_short_union:
565 size = sizeof(DST_short_union(entry))
566 + DST_short_union(entry).nfields * sizeof(dst_short_field_t)
567 - dst_dummy_array_size * sizeof(dst_field_t);
570 size = sizeof(DST_file(entry));
573 size = sizeof(DST_offset(entry));
576 size = sizeof(DST_alias(entry));
578 case dst_typ_signature:
579 size = sizeof(DST_signature(entry)) +
580 ((int) DST_signature(entry).nargs -
581 dst_dummy_array_size) * sizeof(dst_arg_t);
586 case dst_typ_old_label:
587 size = sizeof(DST_old_label(entry));
590 size = sizeof(DST_scope(entry));
592 case dst_typ_end_scope:
599 case dst_typ_string_tab:
600 case dst_typ_global_name_tab:
601 size = sizeof(DST_string_tab(entry))
602 + DST_string_tab(entry).length
603 - dst_dummy_array_size;
605 case dst_typ_forward:
606 size = sizeof(DST_forward(entry));
607 get_dst_entry((char *) entry + DST_forward(entry).rec_off, &entry);
609 case dst_typ_aux_size:
610 size = sizeof(DST_aux_size(entry));
612 case dst_typ_aux_align:
613 size = sizeof(DST_aux_align(entry));
615 case dst_typ_aux_field_size:
616 size = sizeof(DST_aux_field_size(entry));
618 case dst_typ_aux_field_off:
619 size = sizeof(DST_aux_field_off(entry));
621 case dst_typ_aux_field_align:
622 size = sizeof(DST_aux_field_align(entry));
624 case dst_typ_aux_qual:
625 size = sizeof(DST_aux_qual(entry));
627 case dst_typ_aux_var_bound:
628 size = sizeof(DST_aux_var_bound(entry));
630 case dst_typ_extension:
631 size = DST_extension(entry).rec_size;
634 size = sizeof(DST_string(entry));
636 case dst_typ_old_entry:
637 size = 48; /* Obsolete entry type */
640 size = sizeof(DST_const(entry))
641 + DST_const(entry).value.length
642 - sizeof(DST_const(entry).value.val);
644 case dst_typ_reference:
645 size = sizeof(DST_reference(entry));
647 case dst_typ_old_record:
648 case dst_typ_old_union:
651 size = sizeof(DST_record(entry))
652 + ((int) DST_record(entry).nfields
653 - dst_dummy_array_size) * sizeof(dst_field_t);
655 case dst_typ_aux_type_deriv:
656 size = sizeof(DST_aux_type_deriv(entry));
658 case dst_typ_locpool:
659 size = sizeof(DST_locpool(entry))
660 + ((int) DST_locpool(entry).length -
661 dst_dummy_array_size);
663 case dst_typ_variable:
664 size = sizeof(DST_variable(entry));
667 size = sizeof(DST_label(entry));
670 size = sizeof(DST_entry(entry));
672 case dst_typ_aux_lifetime:
673 size = sizeof(DST_aux_lifetime(entry));
675 case dst_typ_aux_ptr_base:
676 size = sizeof(DST_aux_ptr_base(entry));
678 case dst_typ_aux_src_range:
679 size = sizeof(DST_aux_src_range(entry));
681 case dst_typ_aux_reg_val:
682 size = sizeof(DST_aux_reg_val(entry));
684 case dst_typ_aux_unit_names:
685 size = sizeof(DST_aux_unit_names(entry))
686 + ((int) DST_aux_unit_names(entry).number_of_names
687 - dst_dummy_array_size) * sizeof(dst_rel_offset_t);
689 case dst_typ_aux_sect_info:
690 size = sizeof(DST_aux_sect_info(entry))
691 + ((int) DST_aux_sect_info(entry).number_of_refs
692 - dst_dummy_array_size) * sizeof(dst_sect_ref_t);
700 fprintf_unfiltered(gdb_stderr, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
701 (int) entry->rec_type,
703 fprintf_unfiltered(gdb_stderr, "Last unknown_3 value: %d\n", lu3);
707 last_type = entry->rec_type;
708 if (size & 1) /* Align on a word boundary */
715 static int next_dst_entry(buffer, entry, table)
717 dst_rec_ptr_t *entry;
720 if (*buffer - table->buffer >= table->size)
725 *buffer += get_dst_entry(*buffer, entry);
729 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
730 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
731 #define DST_OFFSET(a, b) ((char *) (a) + (b))
733 static dst_rec_ptr_t section_table = NULL;
739 dst_sec *section = NULL;
742 if (!section_table || !ref->sect_index)
744 offset = DST_section_tab(section_table).section_base[ref->sect_index-1]
746 if (offset >= blocks_info.base &&
747 offset < blocks_info.base + blocks_info.size)
748 section = &blocks_info;
749 else if (offset >= symbols_info.base &&
750 offset < symbols_info.base + symbols_info.size)
751 section = &symbols_info;
752 else if (offset >= lines_info.base &&
753 offset < lines_info.base + lines_info.size)
754 section = &lines_info;
757 return section->buffer + (offset - section->base);
761 dst_get_addr(int section, long offset)
763 if (!section_table || !section)
765 return DST_section_tab(section_table).section_base[section-1] + offset;
772 if (!section_table || !ref->sect_index)
774 return DST_section_tab(section_table).section_base[ref->sect_index-1]
779 create_new_type(objfile)
780 struct objfile *objfile;
784 type = (struct type *)
785 obstack_alloc (&objfile->symbol_obstack, sizeof (struct type));
786 memset(type, 0, sizeof(struct type));
790 static struct symbol *
791 create_new_symbol(objfile, name)
792 struct objfile *objfile;
795 struct symbol *sym = (struct symbol *)
796 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
797 memset (sym, 0, sizeof (struct symbol));
798 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
799 &objfile->symbol_obstack);
800 SYMBOL_VALUE (sym) = 0;
801 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
803 SYMBOL_CLASS (sym) = LOC_BLOCK;
808 decode_dst_type PARAMS ((struct objfile *, dst_rec_ptr_t));
811 decode_type_desc(objfile, type_desc, base)
812 struct objfile *objfile;
813 dst_type_t *type_desc;
818 if (type_desc->std_type.user_defined_type)
820 entry = (dst_rec_ptr_t) DST_OFFSET(base,
821 dst_user_type_offset(*type_desc));
822 type = decode_dst_type(objfile, entry);
826 switch(type_desc->std_type.dtc)
829 type = builtin_type_signed_char;
832 type = builtin_type_short;
835 type = builtin_type_long;
838 type = builtin_type_unsigned_char;
840 case dst_uint16_type:
841 type = builtin_type_unsigned_short;
843 case dst_uint32_type:
844 type = builtin_type_unsigned_long;
846 case dst_real32_type:
847 type = builtin_type_float;
849 case dst_real64_type:
850 type = builtin_type_double;
852 case dst_complex_type:
853 type = builtin_type_complex;
855 case dst_dcomplex_type:
856 type = builtin_type_double_complex;
859 type = builtin_type_char;
861 case dst_bool16_type:
862 type = builtin_type_short;
864 case dst_bool32_type:
865 type = builtin_type_long;
868 type = builtin_type_char;
870 /* The next few are more complex. I will take care
871 * of them properly at a later point.
873 case dst_string_type:
874 type = builtin_type_void;
877 type = builtin_type_void;
880 type = builtin_type_void;
883 type = builtin_type_void;
886 type = builtin_type_void;
888 /* Back tto some ordinary ones */
890 type = builtin_type_void;
893 type = builtin_type_unsigned_char;
896 type = builtin_type_void;
903 struct structure_list
905 struct structure_list *next;
909 static struct structure_list *struct_list = NULL;
912 find_dst_structure(name)
915 struct structure_list *element;
917 for (element = struct_list; element; element = element->next)
918 if (!strcmp(name, TYPE_NAME(element->type)))
919 return element->type;
925 decode_dst_structure(objfile, entry, code, version)
926 struct objfile *objfile;
931 struct type *type, *child_type;
933 char *name, *field_name;
935 int fieldoffset, fieldsize;
936 dst_type_t type_desc;
937 struct structure_list *element;
939 struct_name = DST_OFFSET(entry, DST_record(entry).noffset);
940 name = concat( (code == TYPE_CODE_UNION)?"union ":"struct ",
942 type = find_dst_structure(name);
948 type = create_new_type(objfile);
949 TYPE_NAME(type) = obstack_copy0 (&objfile->symbol_obstack,
952 TYPE_CODE(type) = code;
953 TYPE_LENGTH(type) = DST_record(entry).size;
954 TYPE_NFIELDS(type) = DST_record(entry).nfields;
955 TYPE_FIELDS(type) = (struct field *)
956 obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) *
957 DST_record(entry).nfields);
958 fieldoffset = fieldsize = 0;
959 INIT_CPLUS_SPECIFIC(type);
960 element = (struct structure_list *)
961 xmalloc(sizeof(struct structure_list));
962 element->type = type;
963 element->next = struct_list;
964 struct_list = element;
965 for (i = 0; i < DST_record(entry).nfields; i++)
970 field_name = DST_OFFSET(entry,
971 DST_record(entry).f.ofields[i].noffset);
972 fieldoffset = DST_record(entry).f.ofields[i].foffset*8 +
973 DST_record(entry).f.ofields[i].bit_offset;
974 fieldsize = DST_record(entry).f.ofields[i].size;
975 type_desc = DST_record(entry).f.ofields[i].type_desc;
978 field_name = DST_OFFSET(entry,
979 DST_record(entry).f.fields[i].noffset);
980 type_desc = DST_record(entry).f.fields[i].type_desc;
981 switch(DST_record(entry).f.fields[i].f.field_loc.format_tag)
984 fieldoffset = DST_record(entry).f.
985 fields[i].f.field_byte.offset * 8;
989 fieldoffset = DST_record(entry).f.
990 fields[i].f.field_bit.byte_offset * 8 +
992 fields[i].f.field_bit.bit_offset;
993 fieldsize = DST_record(entry).f.
994 fields[i].f.field_bit.nbits;
997 fieldoffset += fieldsize;
1003 field_name = DST_OFFSET(entry,
1004 DST_record(entry).f.sfields[i].noffset);
1005 fieldoffset = DST_record(entry).f.sfields[i].foffset;
1006 type_desc = DST_record(entry).f.sfields[i].type_desc;
1007 if (i < DST_record(entry).nfields - 1)
1008 fieldsize = DST_record(entry).f.sfields[i+1].foffset;
1010 fieldsize = DST_record(entry).size;
1011 fieldsize -= fieldoffset;
1015 TYPE_FIELDS(type)[i].name =
1016 obstack_copy0 (&objfile->symbol_obstack,
1017 field_name, strlen(field_name));
1018 TYPE_FIELDS(type)[i].type = decode_type_desc(objfile,
1021 if (fieldsize == -1)
1022 fieldsize = TYPE_LENGTH(TYPE_FIELDS(type)[i].type) *
1024 TYPE_FIELDS(type)[i].bitsize = fieldsize;
1025 TYPE_FIELDS(type)[i].bitpos = fieldoffset;
1030 static struct type *
1031 decode_dst_type(objfile, entry)
1032 struct objfile *objfile;
1033 dst_rec_ptr_t entry;
1035 struct type *child_type, *type, *range_type, *index_type;
1037 switch(entry->rec_type)
1040 return decode_type_desc(objfile,
1041 &DST_var(entry).type_desc,
1044 case dst_typ_variable:
1045 return decode_type_desc(objfile,
1046 &DST_variable(entry).type_desc,
1049 case dst_typ_short_rec:
1050 return decode_dst_structure(objfile, entry, TYPE_CODE_STRUCT,0);
1051 case dst_typ_short_union:
1052 return decode_dst_structure(objfile, entry, TYPE_CODE_UNION, 0);
1054 return decode_dst_structure(objfile, entry, TYPE_CODE_UNION, 1);
1055 case dst_typ_record:
1056 return decode_dst_structure(objfile, entry, TYPE_CODE_STRUCT,1);
1057 case dst_typ_old_union:
1058 return decode_dst_structure(objfile, entry, TYPE_CODE_UNION, 2);
1059 case dst_typ_old_record:
1060 return decode_dst_structure(objfile, entry, TYPE_CODE_STRUCT,2);
1061 case dst_typ_pointer:
1062 return make_pointer_type(
1063 decode_type_desc(objfile,
1064 &DST_pointer(entry).type_desc,
1068 child_type = decode_type_desc(objfile,
1069 &DST_pointer(entry).type_desc,
1071 index_type = lookup_fundamental_type(objfile,
1073 range_type = create_range_type ((struct type *) NULL,
1074 index_type, DST_array(entry).lo_bound,
1075 DST_array(entry).hi_bound);
1076 return create_array_type ((struct type *) NULL, child_type,
1079 return decode_type_desc(objfile,
1080 &DST_alias(entry).type_desc,
1083 return builtin_type_int;
1087 struct symbol_list {
1088 struct symbol_list *next;
1089 struct symbol *symbol;
1092 static struct symbol_list *dst_global_symbols = NULL;
1093 static int total_globals = 0;
1096 decode_dst_locstring(locstr, sym)
1100 dst_loc_entry_t *entry, *next_entry;
1108 fprintf_unfiltered(gdb_stderr, "Error reading locstring\n");
1111 entry = (dst_loc_entry_t *) locstr;
1112 next_entry = (dst_loc_entry_t *) (locstr + 1);
1113 switch (entry->header.code)
1115 case dst_lsc_end: /* End of string */
1117 case dst_lsc_indirect:/* Indirect through previous. Arg == 6 */
1118 /* Or register ax x == arg */
1119 if (entry->header.arg < 6)
1121 SYMBOL_CLASS(sym) = LOC_REGISTER;
1122 SYMBOL_VALUE(sym) = entry->header.arg + 8;
1124 /* We predict indirects */
1128 SYMBOL_CLASS(sym) = LOC_REGISTER;
1129 SYMBOL_VALUE(sym) = entry->header.arg;
1132 case dst_lsc_section:/* Section (arg+1) */
1133 SYMBOL_VALUE(sym) = dst_get_addr(entry->header.arg+1, 0);
1136 case dst_lsc_sec_byte: /* Section (next_byte+1) */
1137 SYMBOL_VALUE(sym) = dst_get_addr(locstr[1]+1, 0);
1140 case dst_lsc_add: /* Add (arg+1)*2 */
1141 case dst_lsc_sub: /* Subtract (arg+1)*2 */
1142 temp = (entry->header.arg + 1) * 2;
1144 if (*locstr == dst_multiply_256)
1149 switch(entry->header.code)
1152 if (SYMBOL_CLASS(sym) == LOC_LOCAL)
1153 SYMBOL_CLASS(sym) = LOC_ARG;
1154 SYMBOL_VALUE(sym) += temp;
1157 SYMBOL_VALUE(sym) -= temp;
1161 case dst_lsc_add_byte:
1162 case dst_lsc_sub_byte:
1163 switch (entry->header.arg & 0x03)
1166 temp = (unsigned char) locstr[1];
1170 temp = * (unsigned short *) (locstr + 1);
1174 temp = * (unsigned long *) (locstr + 1);
1178 if (*locstr == dst_multiply_256)
1183 switch(entry->header.code)
1185 case dst_lsc_add_byte:
1186 if (SYMBOL_CLASS(sym) == LOC_LOCAL)
1187 SYMBOL_CLASS(sym) = LOC_ARG;
1188 SYMBOL_VALUE(sym) += temp;
1190 case dst_lsc_sub_byte:
1191 SYMBOL_VALUE(sym) -= temp;
1195 case dst_lsc_sbreg: /* Stack base register (frame pointer). Arg==0*/
1196 if (next_entry->header.code != dst_lsc_indirect)
1198 SYMBOL_VALUE(sym) = 0;
1199 SYMBOL_CLASS(sym) = LOC_STATIC;
1202 SYMBOL_VALUE(sym) = 0;
1203 SYMBOL_CLASS(sym) = LOC_LOCAL;
1207 SYMBOL_VALUE(sym) = 0;
1208 SYMBOL_CLASS(sym) = LOC_STATIC;
1214 static struct symbol_list *
1215 process_dst_symbols(objfile, entry, name, nsyms_ret)
1216 struct objfile *objfile;
1217 dst_rec_ptr_t entry;
1221 struct symbol_list *list = NULL, *element;
1229 dst_var_attr_t attr;
1230 dst_var_loc_t loc_type;
1239 location = (char *) entry;
1240 while (NEXT_SYM(&location, &entry) &&
1241 entry->rec_type != dst_typ_end_scope)
1243 if (entry->rec_type == dst_typ_var)
1245 if (DST_var(entry).short_locs)
1247 loc_type = DST_var(entry).locs.shorts[0].loc_type;
1248 loc_index = DST_var(entry).locs.shorts[0].loc_index;
1249 loc_value = DST_var(entry).locs.shorts[0].location;
1253 loc_type = DST_var(entry).locs.longs[0].loc_type;
1254 loc_index = DST_var(entry).locs.longs[0].loc_index;
1255 loc_value = DST_var(entry).locs.longs[0].location;
1257 if (loc_type == dst_var_loc_external)
1259 symname = DST_OFFSET(entry, DST_var(entry).noffset);
1260 line = DST_var(entry).src_loc.line_number;
1261 symtype = DST_var(entry).type_desc;
1262 attr = DST_var(entry).attributes;
1264 else if (entry->rec_type == dst_typ_variable)
1266 symname = DST_OFFSET(entry,
1267 DST_variable(entry).noffset);
1268 line = DST_variable(entry).src_loc.line_number;
1269 symtype = DST_variable(entry).type_desc;
1270 attr = DST_variable(entry).attributes;
1276 if (symname && name && !strcmp(symname, name))
1277 /* It's the function return value */
1279 sym = create_new_symbol(objfile, symname);
1281 if ((attr & (1<<dst_var_attr_global)) ||
1282 (attr & (1<<dst_var_attr_static)))
1283 SYMBOL_CLASS(sym) = LOC_STATIC;
1285 SYMBOL_CLASS(sym) = LOC_LOCAL;
1286 SYMBOL_LINE(sym) = line;
1287 SYMBOL_TYPE(sym) = decode_type_desc(objfile, &symtype,
1289 SYMBOL_VALUE(sym) = 0;
1290 switch (entry->rec_type)
1295 case dst_var_loc_abs:
1296 SYMBOL_VALUE_ADDRESS(sym) = loc_value;
1298 case dst_var_loc_sect_off:
1299 case dst_var_loc_ind_sect_off: /* What is this? */
1300 SYMBOL_VALUE_ADDRESS(sym) = dst_get_addr(
1304 case dst_var_loc_ind_reg_rel: /* What is this? */
1305 case dst_var_loc_reg_rel:
1306 /* If it isn't fp relative, specify the
1307 * register it's relative to.
1311 sym->aux_value.basereg = loc_index;
1313 SYMBOL_VALUE(sym) = loc_value;
1314 if (loc_value > 0 &&
1315 SYMBOL_CLASS(sym) == LOC_BASEREG)
1316 SYMBOL_CLASS(sym) = LOC_BASEREG_ARG;
1318 case dst_var_loc_reg:
1319 SYMBOL_VALUE(sym) = loc_index;
1320 SYMBOL_CLASS(sym) = LOC_REGISTER;
1324 case dst_typ_variable:
1325 /* External variable..... don't try to interpret
1326 * its nonexistant locstring.
1328 if (DST_variable(entry).loffset == -1)
1330 decode_dst_locstring(DST_OFFSET(entry,
1331 DST_variable(entry).loffset),
1334 element = (struct symbol_list *)
1335 xmalloc(sizeof(struct symbol_list));
1337 if (attr & (1<<dst_var_attr_global))
1339 element->next = dst_global_symbols;
1340 dst_global_symbols = element;
1345 element->next = list;
1349 element->symbol = sym;
1356 static struct symbol *
1357 process_dst_function(objfile, entry, name, address)
1358 struct objfile *objfile;
1359 dst_rec_ptr_t entry;
1364 struct type *type, *ftype;
1365 dst_rec_ptr_t sym_entry, typ_entry;
1367 struct symbol_list *element;
1369 type = builtin_type_int;
1370 sym = create_new_symbol(objfile, name);
1371 SYMBOL_CLASS(sym) = LOC_BLOCK;
1375 location = (char *) entry;
1378 NEXT_SYM(&location, &sym_entry);
1379 } while (sym_entry && sym_entry->rec_type != dst_typ_signature);
1384 DST_signature(sym_entry).src_loc.line_number;
1385 if (DST_signature(sym_entry).result)
1387 typ_entry = (dst_rec_ptr_t)
1388 DST_OFFSET(sym_entry,
1389 DST_signature(sym_entry).result);
1390 type = decode_dst_type(objfile, typ_entry);
1395 if (!type->function_type)
1397 ftype = create_new_type(objfile);
1398 type->function_type = ftype;
1399 ftype->target_type = type;
1400 ftype->code = TYPE_CODE_FUNC;
1402 SYMBOL_TYPE(sym) = type->function_type;
1404 /* Now add ourselves to the global symbols list */
1405 element = (struct symbol_list *)
1406 xmalloc(sizeof(struct symbol_list));
1408 element->next = dst_global_symbols;
1409 dst_global_symbols = element;
1411 element->symbol = sym;
1416 static struct block *
1417 process_dst_block(objfile, entry)
1418 struct objfile *objfile;
1419 dst_rec_ptr_t entry;
1421 struct block *block;
1422 struct symbol *function = NULL;
1426 dst_rec_ptr_t child_entry, symbol_entry;
1427 struct block *child_block;
1428 int total_symbols = 0;
1429 struct pending_block *pblock;
1431 static long fake_seq = 0;
1432 struct symbol_list *symlist, *nextsym;
1435 if (DST_block(entry).noffset)
1436 name = DST_OFFSET(entry, DST_block(entry).noffset);
1439 if (DST_block(entry).n_of_code_ranges)
1441 address = dst_sym_addr(
1442 &DST_block(entry).code_ranges[0].code_start);
1443 size = DST_block(entry).code_ranges[0].code_size;
1450 symbol_entry = (dst_rec_ptr_t) get_sec_ref(&DST_block(entry).symbols_start);
1451 switch(DST_block(entry).block_type)
1453 /* These are all really functions. Even the "program" type.
1454 * This is because the Apollo OS was written in Pascal, and
1455 * in Pascal, the main procedure is described as the Program.
1458 case dst_block_procedure:
1459 case dst_block_function:
1460 case dst_block_subroutine:
1461 case dst_block_program:
1462 prim_record_minimal_symbol(name, address, mst_text, objfile);
1463 function = process_dst_function(
1468 enter_all_lines(get_sec_ref(&DST_block(entry).code_ranges[0].lines_start), address);
1470 case dst_block_block_data:
1474 /* GDB has to call it something, and the module name
1477 sprintf(fake_name, "block_%08lx", fake_seq++);
1478 function = process_dst_function(
1479 objfile, NULL, fake_name, address);
1482 symlist = process_dst_symbols(objfile, symbol_entry,
1483 name, &total_symbols);
1484 block = (struct block *)
1485 obstack_alloc (&objfile->symbol_obstack,
1486 sizeof (struct block) +
1487 (total_symbols - 1) * sizeof (struct symbol *));
1492 nextsym = symlist->next;
1494 block->sym[symnum] = symlist->symbol;
1496 free((PTR) symlist);
1500 BLOCK_NSYMS (block) = total_symbols;
1501 BLOCK_START (block) = address;
1502 BLOCK_END (block) = address + size;
1503 BLOCK_SUPERBLOCK (block) = 0;
1506 SYMBOL_BLOCK_VALUE (function) = block;
1507 BLOCK_FUNCTION (block) = function;
1510 BLOCK_FUNCTION (block) = 0;
1512 pblock = (struct pending_block *)
1513 xmalloc (sizeof (struct pending_block));
1514 pblock->block = block;
1515 pblock->next = pending_blocks;
1516 pending_blocks = pblock;
1517 if (DST_block(entry).child_block_off)
1519 child_entry = (dst_rec_ptr_t) DST_OFFSET(entry,
1520 DST_block(entry).child_block_off);
1523 child_block = process_dst_block(objfile, child_entry);
1526 if (BLOCK_START(child_block) <
1527 BLOCK_START(block) ||
1528 BLOCK_START(block) == -1)
1529 BLOCK_START(block) =
1530 BLOCK_START(child_block);
1531 if (BLOCK_END(child_block) >
1533 BLOCK_END(block) == -1)
1535 BLOCK_END(child_block);
1536 BLOCK_SUPERBLOCK (child_block) = block;
1538 if (DST_block(child_entry).sibling_block_off)
1539 child_entry = (dst_rec_ptr_t) DST_OFFSET(
1541 DST_block(child_entry).sibling_block_off);
1551 read_dst_symtab (objfile)
1552 struct objfile *objfile;
1555 dst_rec_ptr_t entry, file_table, root_block;
1557 struct block *block, *global_block;
1558 struct pending_block *pblock;
1560 struct symbol_list *nextsym;
1562 struct structure_list *element;
1564 current_objfile = objfile;
1565 buffer = blocks_info.buffer;
1566 while (NEXT_BLK(&buffer, &entry))
1568 if (entry->rec_type == dst_typ_comp_unit)
1570 file_table = (dst_rec_ptr_t) DST_OFFSET(entry,
1571 DST_comp_unit(entry).file_table);
1572 section_table = (dst_rec_ptr_t) DST_OFFSET(entry,
1573 DST_comp_unit(entry).section_table);
1574 root_block = (dst_rec_ptr_t) DST_OFFSET(entry,
1575 DST_comp_unit(entry).root_block_offset);
1576 source_file = DST_OFFSET(file_table,
1577 DST_file_tab(file_table).files[0].noffset);
1578 /* Point buffer to the start of the next comp_unit */
1579 buffer = DST_OFFSET(entry,
1580 DST_comp_unit(entry).data_size);
1583 pblock = (struct pending_block *)
1584 xmalloc (sizeof (struct pending_block));
1585 pblock->next = NULL;
1586 pending_blocks = pblock;
1588 block = process_dst_block(objfile, root_block);
1590 global_block = (struct block *)
1591 obstack_alloc (&objfile->symbol_obstack,
1592 sizeof (struct block) +
1593 (total_globals - 1) *
1594 sizeof (struct symbol *));
1595 BLOCK_NSYMS(global_block) = total_globals;
1596 for (symnum = 0; symnum < total_globals; symnum++)
1598 nextsym = dst_global_symbols->next;
1600 global_block->sym[symnum] =
1601 dst_global_symbols->symbol;
1603 free((PTR) dst_global_symbols);
1604 dst_global_symbols = nextsym;
1606 dst_global_symbols = NULL;
1608 BLOCK_FUNCTION(global_block) = 0;
1609 BLOCK_START(global_block) = BLOCK_START(block);
1610 BLOCK_END(global_block) = BLOCK_END(block);
1611 BLOCK_SUPERBLOCK(global_block) = 0;
1612 BLOCK_SUPERBLOCK(block) = global_block;
1613 pblock->block = global_block;
1615 complete_symtab(source_file,
1617 BLOCK_END(block) - BLOCK_START(block));
1619 dst_end_symtab(objfile);
1623 prim_record_minimal_symbol("<end_of_program>",
1624 BLOCK_END(block), mst_text, objfile);
1625 /* One more faked symbol to make sure nothing can ever run off the
1626 * end of the symbol table. This one represents the end of the
1627 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1628 * int possible), but some parts of gdb treated it as a signed
1629 * number and failed comparisons. We could equally use 7fffffff,
1630 * but no functions are ever mapped to an address higher than
1633 prim_record_minimal_symbol("<end_of_text>",
1634 (CORE_ADDR) 0x40000000,
1638 element = struct_list;
1639 struct_list = element->next;
1640 free((PTR) element);
1645 /* Support for line number handling */
1646 static char *linetab = NULL;
1647 static long linetab_offset;
1648 static unsigned long linetab_size;
1650 /* Read in all the line numbers for fast lookups later. Leave them in
1651 external (unswapped) format in memory; we'll swap them as we enter
1652 them into GDB's data structures. */
1654 init_one_section(chan, secinfo)
1658 if (secinfo->size == 0
1659 || lseek(chan, secinfo->position, 0) == -1
1660 || (secinfo->buffer = xmalloc(secinfo->size)) == NULL
1661 || myread(chan, secinfo->buffer, secinfo->size) == -1)
1668 init_dst_sections (chan)
1672 if (!init_one_section(chan, &blocks_info) ||
1673 !init_one_section(chan, &lines_info) ||
1674 !init_one_section(chan, &symbols_info))
1680 /* Fake up support for relocating symbol addresses. FIXME. */
1682 struct section_offsets dst_symfile_faker = {0};
1684 struct section_offsets *
1685 dst_symfile_offsets (objfile, addr)
1686 struct objfile *objfile;
1689 objfile->num_sections = 1;
1690 return &dst_symfile_faker;
1693 /* Register our ability to parse symbols for DST BFD files */
1695 static struct sym_fns dst_sym_fns =
1697 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1698 a separate flavour like ecoff? */
1699 (enum bfd_flavour)-2,
1701 dst_new_init, /* sym_new_init: init anything gbl to entire symtab */
1702 dst_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1703 dst_symfile_read, /* sym_read: read a symbol file into symtab */
1704 dst_symfile_finish, /* sym_finish: finished with file, cleanup */
1705 dst_symfile_offsets, /* sym_offsets: xlate external to internal form */
1706 NULL /* next: pointer to next struct sym_fns */
1710 _initialize_dstread ()
1712 add_symtab_fns(&dst_sym_fns);