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., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "breakpoint.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 struct pending_block
*pending_blocks
;
56 static struct blockvector
*
57 make_blockvector
PARAMS ((struct objfile
*));
60 init_dst_sections
PARAMS ((int));
63 read_dst_symtab
PARAMS ((struct objfile
*));
66 find_dst_sections
PARAMS ((bfd
*, sec_ptr
, PTR
));
69 dst_symfile_init
PARAMS ((struct objfile
*));
72 dst_new_init
PARAMS ((struct objfile
*));
75 dst_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
78 dst_symfile_finish
PARAMS ((struct objfile
*));
81 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
));
84 dst_end_symtab
PARAMS ((struct objfile
*));
87 complete_symtab
PARAMS ((char *, CORE_ADDR
, unsigned int));
90 dst_start_symtab
PARAMS ((void));
93 dst_record_line
PARAMS ((int, CORE_ADDR
));
95 static struct blockvector
*
96 make_blockvector (objfile
)
97 struct objfile
*objfile
;
99 register struct pending_block
*next
, *next1
;
100 register struct blockvector
*blockvector
;
103 /* Count the length of the list of blocks. */
105 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
107 blockvector
= (struct blockvector
*)
108 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
110 /* Copy the blocks into the blockvector.
111 This is done in reverse order, which happens to put
112 the blocks into the proper order (ascending starting address).
115 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
116 for (next
= pending_blocks
; next
; next
= next
->next
)
117 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
119 /* Now free the links of the list, and empty the list. */
121 for (next
= pending_blocks
; next
; next
= next1
)
131 /* Manage the vector of line numbers. */
132 /* FIXME: Use record_line instead. */
135 dst_record_line (line
, pc
)
139 struct linetable_entry
*e
;
140 /* Make sure line vector is big enough. */
142 if (line_vector_index
+ 2 >= line_vector_length
)
144 line_vector_length
*= 2;
145 line_vector
= (struct linetable
*)
146 xrealloc ((char *) line_vector
, sizeof (struct linetable
)
147 + (line_vector_length
148 * sizeof (struct linetable_entry
)));
151 e
= line_vector
->item
+ line_vector_index
++;
152 e
->line
= line
; e
->pc
= pc
;
155 /* Start a new symtab for a new source file.
156 It indicates the start of data for one original source file. */
157 /* FIXME: use start_symtab, like coffread.c now does. */
162 /* Initialize the source file line number information for this file. */
164 if (line_vector
) /* Unlikely, but maybe possible? */
165 free ((PTR
)line_vector
);
166 line_vector_index
= 0;
167 line_vector_length
= 1000;
168 prev_line_number
= -2; /* Force first line number to be explicit */
169 line_vector
= (struct linetable
*)
170 xmalloc (sizeof (struct linetable
)
171 + line_vector_length
* sizeof (struct linetable_entry
));
174 /* Save the vital information from when starting to read a file,
175 for use when closing off the current file.
176 NAME is the file name the symbols came from, START_ADDR is the first
177 text address for the file, and SIZE is the number of bytes of text. */
180 complete_symtab (name
, start_addr
, size
)
182 CORE_ADDR start_addr
;
185 last_source_file
= savestring (name
, strlen (name
));
186 cur_src_start_addr
= start_addr
;
187 cur_src_end_addr
= start_addr
+ size
;
189 if (current_objfile
-> ei
.entry_point
>= cur_src_start_addr
&&
190 current_objfile
-> ei
.entry_point
< cur_src_end_addr
)
192 current_objfile
-> ei
.entry_file_lowpc
= cur_src_start_addr
;
193 current_objfile
-> ei
.entry_file_highpc
= cur_src_end_addr
;
197 /* Finish the symbol definitions for one main source file,
198 close off all the lexical contexts for that file
199 (creating struct block's for them), then make the
200 struct symtab for that file and put it in the list of all such. */
201 /* FIXME: Use end_symtab, like coffread.c now does. */
204 dst_end_symtab (objfile
)
205 struct objfile
*objfile
;
207 register struct symtab
*symtab
;
208 register struct blockvector
*blockvector
;
209 register struct linetable
*lv
;
211 /* Create the blockvector that points to all the file's blocks. */
213 blockvector
= make_blockvector (objfile
);
215 /* Now create the symtab object for this source file. */
216 symtab
= allocate_symtab (last_source_file
, objfile
);
218 /* Fill in its components. */
219 symtab
->blockvector
= blockvector
;
220 symtab
->free_code
= free_linetable
;
221 symtab
->free_ptr
= 0;
222 symtab
->filename
= last_source_file
;
223 symtab
->dirname
= NULL
;
225 lv
->nitems
= line_vector_index
;
226 symtab
->linetable
= (struct linetable
*)
227 xrealloc ((char *) lv
, (sizeof (struct linetable
)
228 + lv
->nitems
* sizeof (struct linetable_entry
)));
230 free_named_symtabs (symtab
->filename
);
232 /* Reinitialize for beginning of new file. */
234 line_vector_length
= -1;
235 last_source_file
= NULL
;
239 record_minimal_symbol (name
, address
, type
)
242 enum minimal_symbol_type type
;
244 prim_record_minimal_symbol (savestring (name
, strlen (name
)),
249 /* dst_symfile_init ()
250 is the dst-specific initialization routine for reading symbols.
252 We will only be called if this is a DST or DST-like file.
253 BFD handles figuring out the format of the file, and code in symtab.c
254 uses BFD's determination to vector to us.
256 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
259 dst_symfile_init (objfile
)
260 struct objfile
*objfile
;
263 bfd
*abfd
= objfile
->obfd
;
265 init_entry_point_info (objfile
);
269 /* This function is called for every section; it finds the outer limits
270 of the line table (minimum and maximum file offset) so that the
271 mainline code can read the whole thing for efficiency. */
275 find_dst_sections (abfd
, asect
, vpinfo
)
282 file_ptr offset
, maxoff
;
285 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
286 size
= asect
->_raw_size
;
287 offset
= asect
->filepos
;
292 if (!strcmp(asect
->name
, ".blocks"))
293 section
= &blocks_info
;
294 else if (!strcmp(asect
->name
, ".lines"))
295 section
= &lines_info
;
296 else if (!strcmp(asect
->name
, ".symbols"))
297 section
= &symbols_info
;
300 section
->size
= size
;
301 section
->position
= offset
;
302 section
->base
= base
;
306 /* The BFD for this file -- only good while we're actively reading
307 symbols into a psymtab or a symtab. */
309 static bfd
*symfile_bfd
;
311 /* Read a symbol file, after initialization by dst_symfile_init. */
312 /* FIXME! Addr and Mainline are not used yet -- this will not work for
313 shared libraries or add_file! */
317 dst_symfile_read (objfile
, section_offsets
, mainline
)
318 struct objfile
*objfile
;
319 struct section_offsets
*section_offsets
;
322 bfd
*abfd
= objfile
->obfd
;
323 char *name
= bfd_get_filename (abfd
);
328 int stringtab_offset
;
330 symfile_bfd
= abfd
; /* Kludge for swap routines */
332 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
333 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
335 /* Read the line number table, all at once. */
336 bfd_map_over_sections (abfd
, find_dst_sections
, (PTR
)NULL
);
338 val
= init_dst_sections (desc
);
340 error ("\"%s\": error reading debugging symbol tables\n", name
);
342 init_minimal_symbol_collection ();
343 make_cleanup (discard_minimal_symbols
, 0);
345 /* Now that the executable file is positioned at symbol table,
346 process it and define symbols accordingly. */
348 read_dst_symtab (objfile
);
350 /* Sort symbols alphabetically within each block. */
352 sort_all_symtab_syms ();
354 /* Install any minimal symbols that have been collected as the current
355 minimal symbols for this objfile. */
357 install_minimal_symbols (objfile
);
361 dst_new_init (ignore
)
362 struct objfile
*ignore
;
367 /* Perform any local cleanups required when we are done with a particular
368 objfile. I.E, we are in the process of discarding all symbol information
369 for an objfile, freeing up all memory held for it, and unlinking the
370 objfile struct from the global list of known objfiles. */
373 dst_symfile_finish (objfile
)
374 struct objfile
*objfile
;
380 /* Get the next line number from the DST. Returns 0 when we hit an
381 * end directive or cannot continue for any other reason.
383 * Note that ordinary pc deltas are multiplied by two. Apparently
384 * this is what was really intended.
387 get_dst_line(buffer
, pc
)
388 signed char **buffer
;
392 static long last_line
= 0;
393 static int last_file
= 0;
394 dst_ln_entry_ptr_t entry
;
396 dst_src_loc_t
*src_loc
;
403 entry
= (dst_ln_entry_ptr_t
) *buffer
;
405 while (dst_ln_ln_delta(*entry
) == dst_ln_escape_flag
)
407 switch(entry
->esc
.esc_code
)
410 size
= 1; /* pad byte */
413 /* file escape. Next 4 bytes are a dst_src_loc_t */
415 src_loc
= (dst_src_loc_t
*) (*buffer
+ 1);
416 last_line
= src_loc
->line_number
;
417 last_file
= src_loc
->file_index
;
419 case dst_ln_dln1_dpc1
:
420 /* 1 byte line delta, 1 byte pc delta */
421 last_line
+= (*buffer
)[1];
422 last_pc
+= 2 * (unsigned char) (*buffer
)[2];
423 dst_record_line(last_line
, last_pc
);
426 case dst_ln_dln2_dpc2
:
427 /* 2 bytes line delta, 2 bytes pc delta */
428 last_line
+= *(short *) (*buffer
+ 1);
429 last_pc
+= 2 * (*(short *) (*buffer
+ 3));
431 dst_record_line(last_line
, last_pc
);
434 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
435 last_line
= *(unsigned long *) (*buffer
+ 1);
436 last_pc
= *(unsigned long *) (*buffer
+ 5);
438 dst_record_line(last_line
, last_pc
);
440 case dst_ln_dln1_dpc0
:
441 /* 1 byte line delta, pc delta = 0 */
443 last_line
+= (*buffer
)[1];
445 case dst_ln_ln_off_1
:
446 /* statement escape, stmt # = 1 (2nd stmt on line) */
450 /* statement escape, stmt # = next byte */
454 /* entry escape, next byte is entry number */
461 case dst_ln_stmt_end
:
462 /* gap escape, 4 bytes pc delta */
464 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
465 /* Apparently this isn't supposed to actually modify
466 * the pc value. Totally weird.
469 case dst_ln_escape_11
:
470 case dst_ln_escape_12
:
471 case dst_ln_escape_13
:
474 case dst_ln_nxt_byte
:
475 /* This shouldn't happen. If it does, we're SOL */
479 /* end escape, final entry follows */
482 *buffer
+= (size
< 0) ? -size
: size
;
483 entry
= (dst_ln_entry_ptr_t
) *buffer
;
485 last_line
+= dst_ln_ln_delta(*entry
);
486 last_pc
+= entry
->delta
.pc_delta
* 2;
488 dst_record_line(last_line
, last_pc
);
493 enter_all_lines(buffer
, address
)
498 while (get_dst_line(&buffer
, &address
));
502 get_dst_entry(buffer
, ret_entry
)
504 dst_rec_ptr_t
*ret_entry
;
508 static int last_type
;
512 entry
= (dst_rec_ptr_t
) buffer
;
513 switch(entry
->rec_type
)
518 case dst_typ_comp_unit
:
519 size
= sizeof(DST_comp_unit(entry
));
521 case dst_typ_section_tab
:
522 size
= sizeof(DST_section_tab(entry
))
523 + ((int) DST_section_tab(entry
).number_of_sections
524 - dst_dummy_array_size
) * sizeof(long);
526 case dst_typ_file_tab
:
527 size
= sizeof(DST_file_tab(entry
))
528 + ((int) DST_file_tab(entry
).number_of_files
529 - dst_dummy_array_size
) * sizeof(dst_file_desc_t
);
532 size
= sizeof(DST_block(entry
))
533 + ((int) DST_block(entry
).n_of_code_ranges
534 - dst_dummy_array_size
) * sizeof(dst_code_range_t
);
540 size
= sizeof(DST_var(entry
)) -
541 sizeof(dst_var_loc_long_t
) * dst_dummy_array_size
+
542 DST_var(entry
).no_of_locs
*
543 ( DST_var(entry
).short_locs
?
544 sizeof(dst_var_loc_short_t
):
545 sizeof(dst_var_loc_long_t
));
547 case dst_typ_pointer
:
548 size
= sizeof(DST_pointer(entry
));
551 size
= sizeof(DST_array(entry
));
553 case dst_typ_subrange
:
554 size
= sizeof(DST_subrange(entry
));
557 size
= sizeof(DST_set(entry
));
559 case dst_typ_implicit_enum
:
560 size
= sizeof(DST_implicit_enum(entry
))
561 + ((int) DST_implicit_enum(entry
).nelems
562 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
564 case dst_typ_explicit_enum
:
565 size
= sizeof(DST_explicit_enum(entry
))
566 + ((int) DST_explicit_enum(entry
).nelems
567 - dst_dummy_array_size
) * sizeof(dst_enum_elem_t
);
569 case dst_typ_short_rec
:
570 size
= sizeof(DST_short_rec(entry
))
571 + DST_short_rec(entry
).nfields
* sizeof(dst_short_field_t
)
572 - dst_dummy_array_size
* sizeof(dst_field_t
);
574 case dst_typ_short_union
:
575 size
= sizeof(DST_short_union(entry
))
576 + DST_short_union(entry
).nfields
* sizeof(dst_short_field_t
)
577 - dst_dummy_array_size
* sizeof(dst_field_t
);
580 size
= sizeof(DST_file(entry
));
583 size
= sizeof(DST_offset(entry
));
586 size
= sizeof(DST_alias(entry
));
588 case dst_typ_signature
:
589 size
= sizeof(DST_signature(entry
)) +
590 ((int) DST_signature(entry
).nargs
-
591 dst_dummy_array_size
) * sizeof(dst_arg_t
);
596 case dst_typ_old_label
:
597 size
= sizeof(DST_old_label(entry
));
600 size
= sizeof(DST_scope(entry
));
602 case dst_typ_end_scope
:
609 case dst_typ_string_tab
:
610 case dst_typ_global_name_tab
:
611 size
= sizeof(DST_string_tab(entry
))
612 + DST_string_tab(entry
).length
613 - dst_dummy_array_size
;
615 case dst_typ_forward
:
616 size
= sizeof(DST_forward(entry
));
617 get_dst_entry((char *) entry
+ DST_forward(entry
).rec_off
, &entry
);
619 case dst_typ_aux_size
:
620 size
= sizeof(DST_aux_size(entry
));
622 case dst_typ_aux_align
:
623 size
= sizeof(DST_aux_align(entry
));
625 case dst_typ_aux_field_size
:
626 size
= sizeof(DST_aux_field_size(entry
));
628 case dst_typ_aux_field_off
:
629 size
= sizeof(DST_aux_field_off(entry
));
631 case dst_typ_aux_field_align
:
632 size
= sizeof(DST_aux_field_align(entry
));
634 case dst_typ_aux_qual
:
635 size
= sizeof(DST_aux_qual(entry
));
637 case dst_typ_aux_var_bound
:
638 size
= sizeof(DST_aux_var_bound(entry
));
640 case dst_typ_extension
:
641 size
= DST_extension(entry
).rec_size
;
644 size
= sizeof(DST_string(entry
));
646 case dst_typ_old_entry
:
647 size
= 48; /* Obsolete entry type */
650 size
= sizeof(DST_const(entry
))
651 + DST_const(entry
).value
.length
652 - sizeof(DST_const(entry
).value
.val
);
654 case dst_typ_reference
:
655 size
= sizeof(DST_reference(entry
));
657 case dst_typ_old_record
:
658 case dst_typ_old_union
:
661 size
= sizeof(DST_record(entry
))
662 + ((int) DST_record(entry
).nfields
663 - dst_dummy_array_size
) * sizeof(dst_field_t
);
665 case dst_typ_aux_type_deriv
:
666 size
= sizeof(DST_aux_type_deriv(entry
));
668 case dst_typ_locpool
:
669 size
= sizeof(DST_locpool(entry
))
670 + ((int) DST_locpool(entry
).length
-
671 dst_dummy_array_size
);
673 case dst_typ_variable
:
674 size
= sizeof(DST_variable(entry
));
677 size
= sizeof(DST_label(entry
));
680 size
= sizeof(DST_entry(entry
));
682 case dst_typ_aux_lifetime
:
683 size
= sizeof(DST_aux_lifetime(entry
));
685 case dst_typ_aux_ptr_base
:
686 size
= sizeof(DST_aux_ptr_base(entry
));
688 case dst_typ_aux_src_range
:
689 size
= sizeof(DST_aux_src_range(entry
));
691 case dst_typ_aux_reg_val
:
692 size
= sizeof(DST_aux_reg_val(entry
));
694 case dst_typ_aux_unit_names
:
695 size
= sizeof(DST_aux_unit_names(entry
))
696 + ((int) DST_aux_unit_names(entry
).number_of_names
697 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
699 case dst_typ_aux_sect_info
:
700 size
= sizeof(DST_aux_sect_info(entry
))
701 + ((int) DST_aux_sect_info(entry
).number_of_refs
702 - dst_dummy_array_size
) * sizeof(dst_sect_ref_t
);
710 fprintf(stderr
, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
711 (int) entry
->rec_type
,
713 fprintf(stderr
, "Last unknown_3 value: %d\n", lu3
);
717 last_type
= entry
->rec_type
;
718 if (size
& 1) /* Align on a word boundary */
725 static int next_dst_entry(buffer
, entry
, table
)
727 dst_rec_ptr_t
*entry
;
730 if (*buffer
- table
->buffer
>= table
->size
)
735 *buffer
+= get_dst_entry(*buffer
, entry
);
739 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
740 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
741 #define DST_OFFSET(a, b) ((char *) (a) + (b))
743 static dst_rec_ptr_t section_table
= NULL
;
749 dst_sec
*section
= NULL
;
752 if (!section_table
|| !ref
->sect_index
)
754 offset
= DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
756 if (offset
>= blocks_info
.base
&&
757 offset
< blocks_info
.base
+ blocks_info
.size
)
758 section
= &blocks_info
;
759 else if (offset
>= symbols_info
.base
&&
760 offset
< symbols_info
.base
+ symbols_info
.size
)
761 section
= &symbols_info
;
762 else if (offset
>= lines_info
.base
&&
763 offset
< lines_info
.base
+ lines_info
.size
)
764 section
= &lines_info
;
767 return section
->buffer
+ (offset
- section
->base
);
771 dst_get_addr(int section
, long offset
)
773 if (!section_table
|| !section
)
775 return DST_section_tab(section_table
).section_base
[section
-1] + offset
;
782 if (!section_table
|| !ref
->sect_index
)
784 return DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
789 create_new_type(objfile
)
790 struct objfile
*objfile
;
794 type
= (struct type
*)
795 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct type
));
796 memset(type
, 0, sizeof(struct type
));
800 static struct symbol
*
801 create_new_symbol(objfile
, name
)
802 struct objfile
*objfile
;
805 struct symbol
*sym
= (struct symbol
*)
806 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
807 memset (sym
, 0, sizeof (struct symbol
));
808 SYMBOL_NAME (sym
) = obstack_copy0 (&objfile
->symbol_obstack
,
809 name
, strlen (name
));
810 SYMBOL_VALUE (sym
) = 0;
811 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
813 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
818 decode_dst_type
PARAMS ((struct objfile
*, dst_rec_ptr_t
));
821 decode_type_desc(objfile
, type_desc
, base
)
822 struct objfile
*objfile
;
823 dst_type_t
*type_desc
;
828 if (type_desc
->std_type
.user_defined_type
)
830 entry
= (dst_rec_ptr_t
) DST_OFFSET(base
,
831 dst_user_type_offset(*type_desc
));
832 type
= decode_dst_type(objfile
, entry
);
836 switch(type_desc
->std_type
.dtc
)
839 type
= builtin_type_signed_char
;
842 type
= builtin_type_short
;
845 type
= builtin_type_long
;
848 type
= builtin_type_unsigned_char
;
850 case dst_uint16_type
:
851 type
= builtin_type_unsigned_short
;
853 case dst_uint32_type
:
854 type
= builtin_type_unsigned_long
;
856 case dst_real32_type
:
857 type
= builtin_type_float
;
859 case dst_real64_type
:
860 type
= builtin_type_double
;
862 case dst_complex_type
:
863 type
= builtin_type_complex
;
865 case dst_dcomplex_type
:
866 type
= builtin_type_double_complex
;
869 type
= builtin_type_char
;
871 case dst_bool16_type
:
872 type
= builtin_type_short
;
874 case dst_bool32_type
:
875 type
= builtin_type_long
;
878 type
= builtin_type_char
;
880 /* The next few are more complex. I will take care
881 * of them properly at a later point.
883 case dst_string_type
:
884 type
= builtin_type_void
;
887 type
= builtin_type_void
;
890 type
= builtin_type_void
;
893 type
= builtin_type_void
;
896 type
= builtin_type_void
;
898 /* Back tto some ordinary ones */
900 type
= builtin_type_void
;
903 type
= builtin_type_unsigned_char
;
906 type
= builtin_type_void
;
913 struct structure_list
915 struct structure_list
*next
;
919 static struct structure_list
*struct_list
= NULL
;
922 find_dst_structure(name
)
925 struct structure_list
*element
;
927 for (element
= struct_list
; element
; element
= element
->next
)
928 if (!strcmp(name
, TYPE_NAME(element
->type
)))
929 return element
->type
;
935 decode_dst_structure(objfile
, entry
, code
, version
)
936 struct objfile
*objfile
;
941 struct type
*type
, *child_type
;
943 char *name
, *field_name
;
945 int fieldoffset
, fieldsize
;
946 dst_type_t type_desc
;
947 struct structure_list
*element
;
949 struct_name
= DST_OFFSET(entry
, DST_record(entry
).noffset
);
950 name
= concat( (code
== TYPE_CODE_UNION
)?"union ":"struct ",
952 type
= find_dst_structure(name
);
958 type
= create_new_type(objfile
);
959 TYPE_NAME(type
) = obstack_copy0 (&objfile
->symbol_obstack
,
962 TYPE_CODE(type
) = code
;
963 TYPE_LENGTH(type
) = DST_record(entry
).size
;
964 TYPE_NFIELDS(type
) = DST_record(entry
).nfields
;
965 TYPE_FIELDS(type
) = (struct field
*)
966 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) *
967 DST_record(entry
).nfields
);
968 fieldoffset
= fieldsize
= 0;
969 INIT_CPLUS_SPECIFIC(type
);
970 element
= (struct structure_list
*)
971 xmalloc(sizeof(struct structure_list
));
972 element
->type
= type
;
973 element
->next
= struct_list
;
974 struct_list
= element
;
975 for (i
= 0; i
< DST_record(entry
).nfields
; i
++)
980 field_name
= DST_OFFSET(entry
,
981 DST_record(entry
).f
.ofields
[i
].noffset
);
982 fieldoffset
= DST_record(entry
).f
.ofields
[i
].foffset
*8 +
983 DST_record(entry
).f
.ofields
[i
].bit_offset
;
984 fieldsize
= DST_record(entry
).f
.ofields
[i
].size
;
985 type_desc
= DST_record(entry
).f
.ofields
[i
].type_desc
;
988 field_name
= DST_OFFSET(entry
,
989 DST_record(entry
).f
.fields
[i
].noffset
);
990 type_desc
= DST_record(entry
).f
.fields
[i
].type_desc
;
991 switch(DST_record(entry
).f
.fields
[i
].f
.field_loc
.format_tag
)
994 fieldoffset
= DST_record(entry
).f
.
995 fields
[i
].f
.field_byte
.offset
* 8;
999 fieldoffset
= DST_record(entry
).f
.
1000 fields
[i
].f
.field_bit
.byte_offset
* 8 +
1001 DST_record(entry
).f
.
1002 fields
[i
].f
.field_bit
.bit_offset
;
1003 fieldsize
= DST_record(entry
).f
.
1004 fields
[i
].f
.field_bit
.nbits
;
1007 fieldoffset
+= fieldsize
;
1013 field_name
= DST_OFFSET(entry
,
1014 DST_record(entry
).f
.sfields
[i
].noffset
);
1015 fieldoffset
= DST_record(entry
).f
.sfields
[i
].foffset
;
1016 type_desc
= DST_record(entry
).f
.sfields
[i
].type_desc
;
1017 if (i
< DST_record(entry
).nfields
- 1)
1018 fieldsize
= DST_record(entry
).f
.sfields
[i
+1].foffset
;
1020 fieldsize
= DST_record(entry
).size
;
1021 fieldsize
-= fieldoffset
;
1025 TYPE_FIELDS(type
)[i
].name
=
1026 obstack_copy0 (&objfile
->symbol_obstack
,
1027 field_name
, strlen(field_name
));
1028 TYPE_FIELDS(type
)[i
].type
= decode_type_desc(objfile
,
1031 if (fieldsize
== -1)
1032 fieldsize
= TYPE_LENGTH(TYPE_FIELDS(type
)[i
].type
) *
1034 TYPE_FIELDS(type
)[i
].bitsize
= fieldsize
;
1035 TYPE_FIELDS(type
)[i
].bitpos
= fieldoffset
;
1040 static struct type
*
1041 decode_dst_type(objfile
, entry
)
1042 struct objfile
*objfile
;
1043 dst_rec_ptr_t entry
;
1045 struct type
*child_type
, *type
, *range_type
, *index_type
;
1047 switch(entry
->rec_type
)
1050 return decode_type_desc(objfile
,
1051 &DST_var(entry
).type_desc
,
1054 case dst_typ_variable
:
1055 return decode_type_desc(objfile
,
1056 &DST_variable(entry
).type_desc
,
1059 case dst_typ_short_rec
:
1060 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,0);
1061 case dst_typ_short_union
:
1062 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 0);
1064 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 1);
1065 case dst_typ_record
:
1066 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,1);
1067 case dst_typ_old_union
:
1068 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 2);
1069 case dst_typ_old_record
:
1070 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,2);
1071 case dst_typ_pointer
:
1072 return make_pointer_type(
1073 decode_type_desc(objfile
,
1074 &DST_pointer(entry
).type_desc
,
1078 child_type
= decode_type_desc(objfile
,
1079 &DST_pointer(entry
).type_desc
,
1081 index_type
= lookup_fundamental_type(objfile
,
1083 range_type
= create_range_type ((struct type
*) NULL
,
1084 index_type
, DST_array(entry
).lo_bound
,
1085 DST_array(entry
).hi_bound
);
1086 return create_array_type ((struct type
*) NULL
, child_type
,
1089 return decode_type_desc(objfile
,
1090 &DST_alias(entry
).type_desc
,
1093 return builtin_type_int
;
1097 struct symbol_list
{
1098 struct symbol_list
*next
;
1099 struct symbol
*symbol
;
1102 static struct symbol_list
*dst_global_symbols
= NULL
;
1103 static int total_globals
= 0;
1106 decode_dst_locstring(locstr
, sym
)
1110 dst_loc_entry_t
*entry
, *next_entry
;
1118 fprintf(stderr
, "Error reading locstring\n");
1121 entry
= (dst_loc_entry_t
*) locstr
;
1122 next_entry
= (dst_loc_entry_t
*) (locstr
+ 1);
1123 switch (entry
->header
.code
)
1125 case dst_lsc_end
: /* End of string */
1127 case dst_lsc_indirect
:/* Indirect through previous. Arg == 6 */
1128 /* Or register ax x == arg */
1129 if (entry
->header
.arg
< 6)
1131 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1132 SYMBOL_VALUE(sym
) = entry
->header
.arg
+ 8;
1134 /* We predict indirects */
1138 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1139 SYMBOL_VALUE(sym
) = entry
->header
.arg
;
1142 case dst_lsc_section
:/* Section (arg+1) */
1143 SYMBOL_VALUE(sym
) = dst_get_addr(entry
->header
.arg
+1, 0);
1146 case dst_lsc_sec_byte
: /* Section (next_byte+1) */
1147 SYMBOL_VALUE(sym
) = dst_get_addr(locstr
[1]+1, 0);
1150 case dst_lsc_add
: /* Add (arg+1)*2 */
1151 case dst_lsc_sub
: /* Subtract (arg+1)*2 */
1152 temp
= (entry
->header
.arg
+ 1) * 2;
1154 if (*locstr
== dst_multiply_256
)
1159 switch(entry
->header
.code
)
1162 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1163 SYMBOL_CLASS(sym
) = LOC_ARG
;
1164 SYMBOL_VALUE(sym
) += temp
;
1167 SYMBOL_VALUE(sym
) -= temp
;
1171 case dst_lsc_add_byte
:
1172 case dst_lsc_sub_byte
:
1173 switch (entry
->header
.arg
& 0x03)
1176 temp
= (unsigned char) locstr
[1];
1180 temp
= * (unsigned short *) (locstr
+ 1);
1184 temp
= * (unsigned long *) (locstr
+ 1);
1188 if (*locstr
== dst_multiply_256
)
1193 switch(entry
->header
.code
)
1195 case dst_lsc_add_byte
:
1196 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1197 SYMBOL_CLASS(sym
) = LOC_ARG
;
1198 SYMBOL_VALUE(sym
) += temp
;
1200 case dst_lsc_sub_byte
:
1201 SYMBOL_VALUE(sym
) -= temp
;
1205 case dst_lsc_sbreg
: /* Stack base register (frame pointer). Arg==0*/
1206 if (next_entry
->header
.code
!= dst_lsc_indirect
)
1208 SYMBOL_VALUE(sym
) = 0;
1209 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1212 SYMBOL_VALUE(sym
) = 0;
1213 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1217 SYMBOL_VALUE(sym
) = 0;
1218 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1224 static struct symbol_list
*
1225 process_dst_symbols(objfile
, entry
, name
, nsyms_ret
)
1226 struct objfile
*objfile
;
1227 dst_rec_ptr_t entry
;
1231 struct symbol_list
*list
= NULL
, *element
;
1239 dst_var_attr_t attr
;
1240 dst_var_loc_t loc_type
;
1249 location
= (char *) entry
;
1250 while (NEXT_SYM(&location
, &entry
) &&
1251 entry
->rec_type
!= dst_typ_end_scope
)
1253 if (entry
->rec_type
== dst_typ_var
)
1255 if (DST_var(entry
).short_locs
)
1257 loc_type
= DST_var(entry
).locs
.shorts
[0].loc_type
;
1258 loc_index
= DST_var(entry
).locs
.shorts
[0].loc_index
;
1259 loc_value
= DST_var(entry
).locs
.shorts
[0].location
;
1263 loc_type
= DST_var(entry
).locs
.longs
[0].loc_type
;
1264 loc_index
= DST_var(entry
).locs
.longs
[0].loc_index
;
1265 loc_value
= DST_var(entry
).locs
.longs
[0].location
;
1267 if (loc_type
== dst_var_loc_external
)
1269 symname
= DST_OFFSET(entry
, DST_var(entry
).noffset
);
1270 line
= DST_var(entry
).src_loc
.line_number
;
1271 symtype
= DST_var(entry
).type_desc
;
1272 attr
= DST_var(entry
).attributes
;
1274 else if (entry
->rec_type
== dst_typ_variable
)
1276 symname
= DST_OFFSET(entry
,
1277 DST_variable(entry
).noffset
);
1278 line
= DST_variable(entry
).src_loc
.line_number
;
1279 symtype
= DST_variable(entry
).type_desc
;
1280 attr
= DST_variable(entry
).attributes
;
1286 if (symname
&& name
&& !strcmp(symname
, name
))
1287 /* It's the function return value */
1289 sym
= create_new_symbol(objfile
, symname
);
1291 if ((attr
& (1<<dst_var_attr_global
)) ||
1292 (attr
& (1<<dst_var_attr_static
)))
1293 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1295 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1296 SYMBOL_LINE(sym
) = line
;
1297 SYMBOL_TYPE(sym
) = decode_type_desc(objfile
, &symtype
,
1299 SYMBOL_VALUE(sym
) = 0;
1300 switch (entry
->rec_type
)
1305 case dst_var_loc_abs
:
1306 SYMBOL_VALUE_ADDRESS(sym
) = loc_value
;
1308 case dst_var_loc_sect_off
:
1309 case dst_var_loc_ind_sect_off
: /* What is this? */
1310 SYMBOL_VALUE_ADDRESS(sym
) = dst_get_addr(
1314 case dst_var_loc_ind_reg_rel
: /* What is this? */
1315 case dst_var_loc_reg_rel
:
1316 /* If it isn't fp relative, specify the
1317 * register it's relative to.
1321 sym
->aux_value
.basereg
= loc_index
;
1323 SYMBOL_VALUE(sym
) = loc_value
;
1324 if (loc_value
> 0 &&
1325 SYMBOL_CLASS(sym
) == LOC_BASEREG
)
1326 SYMBOL_CLASS(sym
) = LOC_BASEREG_ARG
;
1328 case dst_var_loc_reg
:
1329 SYMBOL_VALUE(sym
) = loc_index
;
1330 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1334 case dst_typ_variable
:
1335 /* External variable..... don't try to interpret
1336 * its nonexistant locstring.
1338 if (DST_variable(entry
).loffset
== -1)
1340 decode_dst_locstring(DST_OFFSET(entry
,
1341 DST_variable(entry
).loffset
),
1344 element
= (struct symbol_list
*)
1345 xmalloc(sizeof(struct symbol_list
));
1347 if (attr
& (1<<dst_var_attr_global
))
1349 element
->next
= dst_global_symbols
;
1350 dst_global_symbols
= element
;
1355 element
->next
= list
;
1359 element
->symbol
= sym
;
1366 static struct symbol
*
1367 process_dst_function(objfile
, entry
, name
, address
)
1368 struct objfile
*objfile
;
1369 dst_rec_ptr_t entry
;
1374 struct type
*type
, *ftype
;
1375 dst_rec_ptr_t sym_entry
, typ_entry
;
1377 struct symbol_list
*element
;
1379 type
= builtin_type_int
;
1380 sym
= create_new_symbol(objfile
, name
);
1381 SYMBOL_CLASS(sym
) = LOC_BLOCK
;
1385 location
= (char *) entry
;
1388 NEXT_SYM(&location
, &sym_entry
);
1389 } while (sym_entry
&& sym_entry
->rec_type
!= dst_typ_signature
);
1394 DST_signature(sym_entry
).src_loc
.line_number
;
1395 if (DST_signature(sym_entry
).result
)
1397 typ_entry
= (dst_rec_ptr_t
)
1398 DST_OFFSET(sym_entry
,
1399 DST_signature(sym_entry
).result
);
1400 type
= decode_dst_type(objfile
, typ_entry
);
1405 if (!type
->function_type
)
1407 ftype
= create_new_type(objfile
);
1408 type
->function_type
= ftype
;
1409 ftype
->target_type
= type
;
1410 ftype
->code
= TYPE_CODE_FUNC
;
1412 SYMBOL_TYPE(sym
) = type
->function_type
;
1414 /* Now add ourselves to the global symbols list */
1415 element
= (struct symbol_list
*)
1416 xmalloc(sizeof(struct symbol_list
));
1418 element
->next
= dst_global_symbols
;
1419 dst_global_symbols
= element
;
1421 element
->symbol
= sym
;
1426 static struct block
*
1427 process_dst_block(objfile
, entry
)
1428 struct objfile
*objfile
;
1429 dst_rec_ptr_t entry
;
1431 struct block
*block
;
1432 struct symbol
*function
= NULL
;
1436 dst_rec_ptr_t child_entry
, symbol_entry
;
1437 struct block
*child_block
;
1438 int total_symbols
= 0;
1439 struct pending_block
*pblock
;
1441 static long fake_seq
= 0;
1442 struct symbol_list
*symlist
, *nextsym
;
1445 if (DST_block(entry
).noffset
)
1446 name
= DST_OFFSET(entry
, DST_block(entry
).noffset
);
1449 if (DST_block(entry
).n_of_code_ranges
)
1451 address
= dst_sym_addr(
1452 &DST_block(entry
).code_ranges
[0].code_start
);
1453 size
= DST_block(entry
).code_ranges
[0].code_size
;
1460 symbol_entry
= (dst_rec_ptr_t
) get_sec_ref(&DST_block(entry
).symbols_start
);
1461 switch(DST_block(entry
).block_type
)
1463 /* These are all really functions. Even the "program" type.
1464 * This is because the Apollo OS was written in Pascal, and
1465 * in Pascal, the main procedure is described as the Program.
1468 case dst_block_procedure
:
1469 case dst_block_function
:
1470 case dst_block_subroutine
:
1471 case dst_block_program
:
1472 record_minimal_symbol(name
, address
, mst_text
);
1473 function
= process_dst_function(
1478 enter_all_lines(get_sec_ref(&DST_block(entry
).code_ranges
[0].lines_start
), address
);
1480 case dst_block_block_data
:
1484 /* GDB has to call it something, and the module name
1487 sprintf(fake_name
, "block_%08lx", fake_seq
++);
1488 function
= process_dst_function(
1489 objfile
, NULL
, fake_name
, address
);
1492 symlist
= process_dst_symbols(objfile
, symbol_entry
,
1493 name
, &total_symbols
);
1494 block
= (struct block
*)
1495 obstack_alloc (&objfile
->symbol_obstack
,
1496 sizeof (struct block
) +
1497 (total_symbols
- 1) * sizeof (struct symbol
*));
1502 nextsym
= symlist
->next
;
1504 block
->sym
[symnum
] = symlist
->symbol
;
1506 free((PTR
) symlist
);
1510 BLOCK_NSYMS (block
) = total_symbols
;
1511 BLOCK_START (block
) = address
;
1512 BLOCK_END (block
) = address
+ size
;
1513 BLOCK_SUPERBLOCK (block
) = 0;
1516 SYMBOL_BLOCK_VALUE (function
) = block
;
1517 BLOCK_FUNCTION (block
) = function
;
1520 BLOCK_FUNCTION (block
) = 0;
1522 pblock
= (struct pending_block
*)
1523 xmalloc (sizeof (struct pending_block
));
1524 pblock
->block
= block
;
1525 pblock
->next
= pending_blocks
;
1526 pending_blocks
= pblock
;
1527 if (DST_block(entry
).child_block_off
)
1529 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1530 DST_block(entry
).child_block_off
);
1533 child_block
= process_dst_block(objfile
, child_entry
);
1536 if (BLOCK_START(child_block
) <
1537 BLOCK_START(block
) ||
1538 BLOCK_START(block
) == -1)
1539 BLOCK_START(block
) =
1540 BLOCK_START(child_block
);
1541 if (BLOCK_END(child_block
) >
1543 BLOCK_END(block
) == -1)
1545 BLOCK_END(child_block
);
1546 BLOCK_SUPERBLOCK (child_block
) = block
;
1548 if (DST_block(child_entry
).sibling_block_off
)
1549 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(
1551 DST_block(child_entry
).sibling_block_off
);
1561 read_dst_symtab (objfile
)
1562 struct objfile
*objfile
;
1565 dst_rec_ptr_t entry
, file_table
, root_block
;
1567 struct block
*block
, *global_block
;
1568 struct pending_block
*pblock
;
1570 struct symbol_list
*nextsym
;
1572 struct structure_list
*element
;
1574 current_objfile
= objfile
;
1575 buffer
= blocks_info
.buffer
;
1576 while (NEXT_BLK(&buffer
, &entry
))
1578 if (entry
->rec_type
== dst_typ_comp_unit
)
1580 file_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1581 DST_comp_unit(entry
).file_table
);
1582 section_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1583 DST_comp_unit(entry
).section_table
);
1584 root_block
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1585 DST_comp_unit(entry
).root_block_offset
);
1586 source_file
= DST_OFFSET(file_table
,
1587 DST_file_tab(file_table
).files
[0].noffset
);
1588 /* Point buffer to the start of the next comp_unit */
1589 buffer
= DST_OFFSET(entry
,
1590 DST_comp_unit(entry
).data_size
);
1593 pblock
= (struct pending_block
*)
1594 xmalloc (sizeof (struct pending_block
));
1595 pblock
->next
= NULL
;
1596 pending_blocks
= pblock
;
1598 block
= process_dst_block(objfile
, root_block
);
1600 global_block
= (struct block
*)
1601 obstack_alloc (&objfile
->symbol_obstack
,
1602 sizeof (struct block
) +
1603 (total_globals
- 1) *
1604 sizeof (struct symbol
*));
1605 BLOCK_NSYMS(global_block
) = total_globals
;
1606 for (symnum
= 0; symnum
< total_globals
; symnum
++)
1608 nextsym
= dst_global_symbols
->next
;
1610 global_block
->sym
[symnum
] =
1611 dst_global_symbols
->symbol
;
1613 free((PTR
) dst_global_symbols
);
1614 dst_global_symbols
= nextsym
;
1616 dst_global_symbols
= NULL
;
1618 BLOCK_FUNCTION(global_block
) = 0;
1619 BLOCK_START(global_block
) = BLOCK_START(block
);
1620 BLOCK_END(global_block
) = BLOCK_END(block
);
1621 BLOCK_SUPERBLOCK(global_block
) = 0;
1622 BLOCK_SUPERBLOCK(block
) = global_block
;
1623 pblock
->block
= global_block
;
1625 complete_symtab(source_file
,
1627 BLOCK_END(block
) - BLOCK_START(block
));
1629 dst_end_symtab(objfile
);
1633 record_minimal_symbol("<end_of_program>",
1634 BLOCK_END(block
), mst_text
);
1635 /* One more faked symbol to make sure nothing can ever run off the
1636 * end of the symbol table. This one represents the end of the
1637 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1638 * int possible), but some parts of gdb treated it as a signed
1639 * number and failed comparisons. We could equally use 7fffffff,
1640 * but no functions are ever mapped to an address higher than
1643 record_minimal_symbol("<end_of_text>",
1644 (CORE_ADDR
) 0x40000000,
1648 element
= struct_list
;
1649 struct_list
= element
->next
;
1650 free((PTR
) element
);
1655 /* Support for line number handling */
1656 static char *linetab
= NULL
;
1657 static long linetab_offset
;
1658 static unsigned long linetab_size
;
1660 /* Read in all the line numbers for fast lookups later. Leave them in
1661 external (unswapped) format in memory; we'll swap them as we enter
1662 them into GDB's data structures. */
1664 init_one_section(chan
, secinfo
)
1668 if (secinfo
->size
== 0
1669 || lseek(chan
, secinfo
->position
, 0) == -1
1670 || (secinfo
->buffer
= xmalloc(secinfo
->size
)) == NULL
1671 || myread(chan
, secinfo
->buffer
, secinfo
->size
) == -1)
1678 init_dst_sections (chan
)
1682 if (!init_one_section(chan
, &blocks_info
) ||
1683 !init_one_section(chan
, &lines_info
) ||
1684 !init_one_section(chan
, &symbols_info
))
1690 /* Fake up support for relocating symbol addresses. FIXME. */
1692 struct section_offsets dst_symfile_faker
= {0};
1694 struct section_offsets
*
1695 dst_symfile_offsets (objfile
, addr
)
1696 struct objfile
*objfile
;
1699 return &dst_symfile_faker
;
1702 /* Register our ability to parse symbols for DST BFD files */
1704 static struct sym_fns dst_sym_fns
=
1706 "apollo", /* sym_name: name or name prefix of BFD target type */
1707 6, /* sym_namelen: number of significant sym_name chars */
1708 dst_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1709 dst_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1710 dst_symfile_read
, /* sym_read: read a symbol file into symtab */
1711 dst_symfile_finish
, /* sym_finish: finished with file, cleanup */
1712 dst_symfile_offsets
, /* sym_offsets: xlate external to internal form */
1713 NULL
/* next: pointer to next struct sym_fns */
1717 _initialize_dstread ()
1719 add_symtab_fns(&dst_sym_fns
);