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
,
85 dst_end_symtab
PARAMS ((struct objfile
*));
88 complete_symtab
PARAMS ((char *, CORE_ADDR
, unsigned int));
91 dst_start_symtab
PARAMS ((void));
94 dst_record_line
PARAMS ((int, CORE_ADDR
));
96 static struct blockvector
*
97 make_blockvector (objfile
)
98 struct objfile
*objfile
;
100 register struct pending_block
*next
, *next1
;
101 register struct blockvector
*blockvector
;
104 /* Count the length of the list of blocks. */
106 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
108 blockvector
= (struct blockvector
*)
109 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
111 /* Copy the blocks into the blockvector.
112 This is done in reverse order, which happens to put
113 the blocks into the proper order (ascending starting address).
116 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
117 for (next
= pending_blocks
; next
; next
= next
->next
)
118 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
120 /* Now free the links of the list, and empty the list. */
122 for (next
= pending_blocks
; next
; next
= next1
)
132 /* Manage the vector of line numbers. */
133 /* FIXME: Use record_line instead. */
136 dst_record_line (line
, pc
)
140 struct linetable_entry
*e
;
141 /* Make sure line vector is big enough. */
143 if (line_vector_index
+ 2 >= line_vector_length
)
145 line_vector_length
*= 2;
146 line_vector
= (struct linetable
*)
147 xrealloc ((char *) line_vector
, sizeof (struct linetable
)
148 + (line_vector_length
149 * sizeof (struct linetable_entry
)));
152 e
= line_vector
->item
+ line_vector_index
++;
153 e
->line
= line
; e
->pc
= pc
;
156 /* Start a new symtab for a new source file.
157 It indicates the start of data for one original source file. */
158 /* FIXME: use start_symtab, like coffread.c now does. */
163 /* Initialize the source file line number information for this file. */
165 if (line_vector
) /* Unlikely, but maybe possible? */
166 free ((PTR
)line_vector
);
167 line_vector_index
= 0;
168 line_vector_length
= 1000;
169 prev_line_number
= -2; /* Force first line number to be explicit */
170 line_vector
= (struct linetable
*)
171 xmalloc (sizeof (struct linetable
)
172 + line_vector_length
* sizeof (struct linetable_entry
));
175 /* Save the vital information from when starting to read a file,
176 for use when closing off the current file.
177 NAME is the file name the symbols came from, START_ADDR is the first
178 text address for the file, and SIZE is the number of bytes of text. */
181 complete_symtab (name
, start_addr
, size
)
183 CORE_ADDR start_addr
;
186 last_source_file
= savestring (name
, strlen (name
));
187 cur_src_start_addr
= start_addr
;
188 cur_src_end_addr
= start_addr
+ size
;
190 if (current_objfile
-> ei
.entry_point
>= cur_src_start_addr
&&
191 current_objfile
-> ei
.entry_point
< cur_src_end_addr
)
193 current_objfile
-> ei
.entry_file_lowpc
= cur_src_start_addr
;
194 current_objfile
-> ei
.entry_file_highpc
= cur_src_end_addr
;
198 /* Finish the symbol definitions for one main source file,
199 close off all the lexical contexts for that file
200 (creating struct block's for them), then make the
201 struct symtab for that file and put it in the list of all such. */
202 /* FIXME: Use end_symtab, like coffread.c now does. */
205 dst_end_symtab (objfile
)
206 struct objfile
*objfile
;
208 register struct symtab
*symtab
;
209 register struct blockvector
*blockvector
;
210 register struct linetable
*lv
;
212 /* Create the blockvector that points to all the file's blocks. */
214 blockvector
= make_blockvector (objfile
);
216 /* Now create the symtab object for this source file. */
217 symtab
= allocate_symtab (last_source_file
, objfile
);
219 /* Fill in its components. */
220 symtab
->blockvector
= blockvector
;
221 symtab
->free_code
= free_linetable
;
222 symtab
->free_ptr
= 0;
223 symtab
->filename
= last_source_file
;
224 symtab
->dirname
= NULL
;
226 lv
->nitems
= line_vector_index
;
227 symtab
->linetable
= (struct linetable
*)
228 xrealloc ((char *) lv
, (sizeof (struct linetable
)
229 + lv
->nitems
* sizeof (struct linetable_entry
)));
231 free_named_symtabs (symtab
->filename
);
233 /* Reinitialize for beginning of new file. */
235 line_vector_length
= -1;
236 last_source_file
= NULL
;
240 record_minimal_symbol (name
, address
, type
, objfile
)
243 enum minimal_symbol_type type
;
244 struct objfile
*objfile
;
246 prim_record_minimal_symbol (savestring (name
, strlen (name
)),
252 /* dst_symfile_init ()
253 is the dst-specific initialization routine for reading symbols.
255 We will only be called if this is a DST or DST-like file.
256 BFD handles figuring out the format of the file, and code in symtab.c
257 uses BFD's determination to vector to us.
259 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
262 dst_symfile_init (objfile
)
263 struct objfile
*objfile
;
266 bfd
*abfd
= objfile
->obfd
;
268 init_entry_point_info (objfile
);
272 /* This function is called for every section; it finds the outer limits
273 of the line table (minimum and maximum file offset) so that the
274 mainline code can read the whole thing for efficiency. */
278 find_dst_sections (abfd
, asect
, vpinfo
)
285 file_ptr offset
, maxoff
;
288 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
289 size
= asect
->_raw_size
;
290 offset
= asect
->filepos
;
295 if (!strcmp(asect
->name
, ".blocks"))
296 section
= &blocks_info
;
297 else if (!strcmp(asect
->name
, ".lines"))
298 section
= &lines_info
;
299 else if (!strcmp(asect
->name
, ".symbols"))
300 section
= &symbols_info
;
303 section
->size
= size
;
304 section
->position
= offset
;
305 section
->base
= base
;
309 /* The BFD for this file -- only good while we're actively reading
310 symbols into a psymtab or a symtab. */
312 static bfd
*symfile_bfd
;
314 /* Read a symbol file, after initialization by dst_symfile_init. */
315 /* FIXME! Addr and Mainline are not used yet -- this will not work for
316 shared libraries or add_file! */
320 dst_symfile_read (objfile
, section_offsets
, mainline
)
321 struct objfile
*objfile
;
322 struct section_offsets
*section_offsets
;
325 bfd
*abfd
= objfile
->obfd
;
326 char *name
= bfd_get_filename (abfd
);
331 int stringtab_offset
;
333 symfile_bfd
= abfd
; /* Kludge for swap routines */
335 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
336 desc
= fileno ((GDB_FILE
*)(abfd
->iostream
)); /* File descriptor */
338 /* Read the line number table, all at once. */
339 bfd_map_over_sections (abfd
, find_dst_sections
, (PTR
)NULL
);
341 val
= init_dst_sections (desc
);
343 error ("\"%s\": error reading debugging symbol tables\n", name
);
345 init_minimal_symbol_collection ();
346 make_cleanup (discard_minimal_symbols
, 0);
348 /* Now that the executable file is positioned at symbol table,
349 process it and define symbols accordingly. */
351 read_dst_symtab (objfile
);
353 /* Sort symbols alphabetically within each block. */
357 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
359 sort_symtab_syms (s
);
363 /* Install any minimal symbols that have been collected as the current
364 minimal symbols for this objfile. */
366 install_minimal_symbols (objfile
);
370 dst_new_init (ignore
)
371 struct objfile
*ignore
;
376 /* Perform any local cleanups required when we are done with a particular
377 objfile. I.E, we are in the process of discarding all symbol information
378 for an objfile, freeing up all memory held for it, and unlinking the
379 objfile struct from the global list of known objfiles. */
382 dst_symfile_finish (objfile
)
383 struct objfile
*objfile
;
389 /* Get the next line number from the DST. Returns 0 when we hit an
390 * end directive or cannot continue for any other reason.
392 * Note that ordinary pc deltas are multiplied by two. Apparently
393 * this is what was really intended.
396 get_dst_line(buffer
, pc
)
397 signed char **buffer
;
401 static long last_line
= 0;
402 static int last_file
= 0;
403 dst_ln_entry_ptr_t entry
;
405 dst_src_loc_t
*src_loc
;
412 entry
= (dst_ln_entry_ptr_t
) *buffer
;
414 while (dst_ln_ln_delta(*entry
) == dst_ln_escape_flag
)
416 switch(entry
->esc
.esc_code
)
419 size
= 1; /* pad byte */
422 /* file escape. Next 4 bytes are a dst_src_loc_t */
424 src_loc
= (dst_src_loc_t
*) (*buffer
+ 1);
425 last_line
= src_loc
->line_number
;
426 last_file
= src_loc
->file_index
;
428 case dst_ln_dln1_dpc1
:
429 /* 1 byte line delta, 1 byte pc delta */
430 last_line
+= (*buffer
)[1];
431 last_pc
+= 2 * (unsigned char) (*buffer
)[2];
432 dst_record_line(last_line
, last_pc
);
435 case dst_ln_dln2_dpc2
:
436 /* 2 bytes line delta, 2 bytes pc delta */
437 last_line
+= *(short *) (*buffer
+ 1);
438 last_pc
+= 2 * (*(short *) (*buffer
+ 3));
440 dst_record_line(last_line
, last_pc
);
443 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
444 last_line
= *(unsigned long *) (*buffer
+ 1);
445 last_pc
= *(unsigned long *) (*buffer
+ 5);
447 dst_record_line(last_line
, last_pc
);
449 case dst_ln_dln1_dpc0
:
450 /* 1 byte line delta, pc delta = 0 */
452 last_line
+= (*buffer
)[1];
454 case dst_ln_ln_off_1
:
455 /* statement escape, stmt # = 1 (2nd stmt on line) */
459 /* statement escape, stmt # = next byte */
463 /* entry escape, next byte is entry number */
470 case dst_ln_stmt_end
:
471 /* gap escape, 4 bytes pc delta */
473 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
474 /* Apparently this isn't supposed to actually modify
475 * the pc value. Totally weird.
478 case dst_ln_escape_11
:
479 case dst_ln_escape_12
:
480 case dst_ln_escape_13
:
483 case dst_ln_nxt_byte
:
484 /* This shouldn't happen. If it does, we're SOL */
488 /* end escape, final entry follows */
491 *buffer
+= (size
< 0) ? -size
: size
;
492 entry
= (dst_ln_entry_ptr_t
) *buffer
;
494 last_line
+= dst_ln_ln_delta(*entry
);
495 last_pc
+= entry
->delta
.pc_delta
* 2;
497 dst_record_line(last_line
, last_pc
);
502 enter_all_lines(buffer
, address
)
507 while (get_dst_line(&buffer
, &address
));
511 get_dst_entry(buffer
, ret_entry
)
513 dst_rec_ptr_t
*ret_entry
;
517 static int last_type
;
521 entry
= (dst_rec_ptr_t
) buffer
;
522 switch(entry
->rec_type
)
527 case dst_typ_comp_unit
:
528 size
= sizeof(DST_comp_unit(entry
));
530 case dst_typ_section_tab
:
531 size
= sizeof(DST_section_tab(entry
))
532 + ((int) DST_section_tab(entry
).number_of_sections
533 - dst_dummy_array_size
) * sizeof(long);
535 case dst_typ_file_tab
:
536 size
= sizeof(DST_file_tab(entry
))
537 + ((int) DST_file_tab(entry
).number_of_files
538 - dst_dummy_array_size
) * sizeof(dst_file_desc_t
);
541 size
= sizeof(DST_block(entry
))
542 + ((int) DST_block(entry
).n_of_code_ranges
543 - dst_dummy_array_size
) * sizeof(dst_code_range_t
);
549 size
= sizeof(DST_var(entry
)) -
550 sizeof(dst_var_loc_long_t
) * dst_dummy_array_size
+
551 DST_var(entry
).no_of_locs
*
552 ( DST_var(entry
).short_locs
?
553 sizeof(dst_var_loc_short_t
):
554 sizeof(dst_var_loc_long_t
));
556 case dst_typ_pointer
:
557 size
= sizeof(DST_pointer(entry
));
560 size
= sizeof(DST_array(entry
));
562 case dst_typ_subrange
:
563 size
= sizeof(DST_subrange(entry
));
566 size
= sizeof(DST_set(entry
));
568 case dst_typ_implicit_enum
:
569 size
= sizeof(DST_implicit_enum(entry
))
570 + ((int) DST_implicit_enum(entry
).nelems
571 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
573 case dst_typ_explicit_enum
:
574 size
= sizeof(DST_explicit_enum(entry
))
575 + ((int) DST_explicit_enum(entry
).nelems
576 - dst_dummy_array_size
) * sizeof(dst_enum_elem_t
);
578 case dst_typ_short_rec
:
579 size
= sizeof(DST_short_rec(entry
))
580 + DST_short_rec(entry
).nfields
* sizeof(dst_short_field_t
)
581 - dst_dummy_array_size
* sizeof(dst_field_t
);
583 case dst_typ_short_union
:
584 size
= sizeof(DST_short_union(entry
))
585 + DST_short_union(entry
).nfields
* sizeof(dst_short_field_t
)
586 - dst_dummy_array_size
* sizeof(dst_field_t
);
589 size
= sizeof(DST_file(entry
));
592 size
= sizeof(DST_offset(entry
));
595 size
= sizeof(DST_alias(entry
));
597 case dst_typ_signature
:
598 size
= sizeof(DST_signature(entry
)) +
599 ((int) DST_signature(entry
).nargs
-
600 dst_dummy_array_size
) * sizeof(dst_arg_t
);
605 case dst_typ_old_label
:
606 size
= sizeof(DST_old_label(entry
));
609 size
= sizeof(DST_scope(entry
));
611 case dst_typ_end_scope
:
618 case dst_typ_string_tab
:
619 case dst_typ_global_name_tab
:
620 size
= sizeof(DST_string_tab(entry
))
621 + DST_string_tab(entry
).length
622 - dst_dummy_array_size
;
624 case dst_typ_forward
:
625 size
= sizeof(DST_forward(entry
));
626 get_dst_entry((char *) entry
+ DST_forward(entry
).rec_off
, &entry
);
628 case dst_typ_aux_size
:
629 size
= sizeof(DST_aux_size(entry
));
631 case dst_typ_aux_align
:
632 size
= sizeof(DST_aux_align(entry
));
634 case dst_typ_aux_field_size
:
635 size
= sizeof(DST_aux_field_size(entry
));
637 case dst_typ_aux_field_off
:
638 size
= sizeof(DST_aux_field_off(entry
));
640 case dst_typ_aux_field_align
:
641 size
= sizeof(DST_aux_field_align(entry
));
643 case dst_typ_aux_qual
:
644 size
= sizeof(DST_aux_qual(entry
));
646 case dst_typ_aux_var_bound
:
647 size
= sizeof(DST_aux_var_bound(entry
));
649 case dst_typ_extension
:
650 size
= DST_extension(entry
).rec_size
;
653 size
= sizeof(DST_string(entry
));
655 case dst_typ_old_entry
:
656 size
= 48; /* Obsolete entry type */
659 size
= sizeof(DST_const(entry
))
660 + DST_const(entry
).value
.length
661 - sizeof(DST_const(entry
).value
.val
);
663 case dst_typ_reference
:
664 size
= sizeof(DST_reference(entry
));
666 case dst_typ_old_record
:
667 case dst_typ_old_union
:
670 size
= sizeof(DST_record(entry
))
671 + ((int) DST_record(entry
).nfields
672 - dst_dummy_array_size
) * sizeof(dst_field_t
);
674 case dst_typ_aux_type_deriv
:
675 size
= sizeof(DST_aux_type_deriv(entry
));
677 case dst_typ_locpool
:
678 size
= sizeof(DST_locpool(entry
))
679 + ((int) DST_locpool(entry
).length
-
680 dst_dummy_array_size
);
682 case dst_typ_variable
:
683 size
= sizeof(DST_variable(entry
));
686 size
= sizeof(DST_label(entry
));
689 size
= sizeof(DST_entry(entry
));
691 case dst_typ_aux_lifetime
:
692 size
= sizeof(DST_aux_lifetime(entry
));
694 case dst_typ_aux_ptr_base
:
695 size
= sizeof(DST_aux_ptr_base(entry
));
697 case dst_typ_aux_src_range
:
698 size
= sizeof(DST_aux_src_range(entry
));
700 case dst_typ_aux_reg_val
:
701 size
= sizeof(DST_aux_reg_val(entry
));
703 case dst_typ_aux_unit_names
:
704 size
= sizeof(DST_aux_unit_names(entry
))
705 + ((int) DST_aux_unit_names(entry
).number_of_names
706 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
708 case dst_typ_aux_sect_info
:
709 size
= sizeof(DST_aux_sect_info(entry
))
710 + ((int) DST_aux_sect_info(entry
).number_of_refs
711 - dst_dummy_array_size
) * sizeof(dst_sect_ref_t
);
719 fprintf_unfiltered(gdb_stderr
, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
720 (int) entry
->rec_type
,
722 fprintf_unfiltered(gdb_stderr
, "Last unknown_3 value: %d\n", lu3
);
726 last_type
= entry
->rec_type
;
727 if (size
& 1) /* Align on a word boundary */
734 static int next_dst_entry(buffer
, entry
, table
)
736 dst_rec_ptr_t
*entry
;
739 if (*buffer
- table
->buffer
>= table
->size
)
744 *buffer
+= get_dst_entry(*buffer
, entry
);
748 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
749 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
750 #define DST_OFFSET(a, b) ((char *) (a) + (b))
752 static dst_rec_ptr_t section_table
= NULL
;
758 dst_sec
*section
= NULL
;
761 if (!section_table
|| !ref
->sect_index
)
763 offset
= DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
765 if (offset
>= blocks_info
.base
&&
766 offset
< blocks_info
.base
+ blocks_info
.size
)
767 section
= &blocks_info
;
768 else if (offset
>= symbols_info
.base
&&
769 offset
< symbols_info
.base
+ symbols_info
.size
)
770 section
= &symbols_info
;
771 else if (offset
>= lines_info
.base
&&
772 offset
< lines_info
.base
+ lines_info
.size
)
773 section
= &lines_info
;
776 return section
->buffer
+ (offset
- section
->base
);
780 dst_get_addr(int section
, long offset
)
782 if (!section_table
|| !section
)
784 return DST_section_tab(section_table
).section_base
[section
-1] + offset
;
791 if (!section_table
|| !ref
->sect_index
)
793 return DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
798 create_new_type(objfile
)
799 struct objfile
*objfile
;
803 type
= (struct type
*)
804 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct type
));
805 memset(type
, 0, sizeof(struct type
));
809 static struct symbol
*
810 create_new_symbol(objfile
, name
)
811 struct objfile
*objfile
;
814 struct symbol
*sym
= (struct symbol
*)
815 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
816 memset (sym
, 0, sizeof (struct symbol
));
817 SYMBOL_NAME (sym
) = obstack_copy0 (&objfile
->symbol_obstack
,
818 name
, strlen (name
));
819 SYMBOL_VALUE (sym
) = 0;
820 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
822 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
827 decode_dst_type
PARAMS ((struct objfile
*, dst_rec_ptr_t
));
830 decode_type_desc(objfile
, type_desc
, base
)
831 struct objfile
*objfile
;
832 dst_type_t
*type_desc
;
837 if (type_desc
->std_type
.user_defined_type
)
839 entry
= (dst_rec_ptr_t
) DST_OFFSET(base
,
840 dst_user_type_offset(*type_desc
));
841 type
= decode_dst_type(objfile
, entry
);
845 switch(type_desc
->std_type
.dtc
)
848 type
= builtin_type_signed_char
;
851 type
= builtin_type_short
;
854 type
= builtin_type_long
;
857 type
= builtin_type_unsigned_char
;
859 case dst_uint16_type
:
860 type
= builtin_type_unsigned_short
;
862 case dst_uint32_type
:
863 type
= builtin_type_unsigned_long
;
865 case dst_real32_type
:
866 type
= builtin_type_float
;
868 case dst_real64_type
:
869 type
= builtin_type_double
;
871 case dst_complex_type
:
872 type
= builtin_type_complex
;
874 case dst_dcomplex_type
:
875 type
= builtin_type_double_complex
;
878 type
= builtin_type_char
;
880 case dst_bool16_type
:
881 type
= builtin_type_short
;
883 case dst_bool32_type
:
884 type
= builtin_type_long
;
887 type
= builtin_type_char
;
889 /* The next few are more complex. I will take care
890 * of them properly at a later point.
892 case dst_string_type
:
893 type
= builtin_type_void
;
896 type
= builtin_type_void
;
899 type
= builtin_type_void
;
902 type
= builtin_type_void
;
905 type
= builtin_type_void
;
907 /* Back tto some ordinary ones */
909 type
= builtin_type_void
;
912 type
= builtin_type_unsigned_char
;
915 type
= builtin_type_void
;
922 struct structure_list
924 struct structure_list
*next
;
928 static struct structure_list
*struct_list
= NULL
;
931 find_dst_structure(name
)
934 struct structure_list
*element
;
936 for (element
= struct_list
; element
; element
= element
->next
)
937 if (!strcmp(name
, TYPE_NAME(element
->type
)))
938 return element
->type
;
944 decode_dst_structure(objfile
, entry
, code
, version
)
945 struct objfile
*objfile
;
950 struct type
*type
, *child_type
;
952 char *name
, *field_name
;
954 int fieldoffset
, fieldsize
;
955 dst_type_t type_desc
;
956 struct structure_list
*element
;
958 struct_name
= DST_OFFSET(entry
, DST_record(entry
).noffset
);
959 name
= concat( (code
== TYPE_CODE_UNION
)?"union ":"struct ",
961 type
= find_dst_structure(name
);
967 type
= create_new_type(objfile
);
968 TYPE_NAME(type
) = obstack_copy0 (&objfile
->symbol_obstack
,
971 TYPE_CODE(type
) = code
;
972 TYPE_LENGTH(type
) = DST_record(entry
).size
;
973 TYPE_NFIELDS(type
) = DST_record(entry
).nfields
;
974 TYPE_FIELDS(type
) = (struct field
*)
975 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) *
976 DST_record(entry
).nfields
);
977 fieldoffset
= fieldsize
= 0;
978 INIT_CPLUS_SPECIFIC(type
);
979 element
= (struct structure_list
*)
980 xmalloc(sizeof(struct structure_list
));
981 element
->type
= type
;
982 element
->next
= struct_list
;
983 struct_list
= element
;
984 for (i
= 0; i
< DST_record(entry
).nfields
; i
++)
989 field_name
= DST_OFFSET(entry
,
990 DST_record(entry
).f
.ofields
[i
].noffset
);
991 fieldoffset
= DST_record(entry
).f
.ofields
[i
].foffset
*8 +
992 DST_record(entry
).f
.ofields
[i
].bit_offset
;
993 fieldsize
= DST_record(entry
).f
.ofields
[i
].size
;
994 type_desc
= DST_record(entry
).f
.ofields
[i
].type_desc
;
997 field_name
= DST_OFFSET(entry
,
998 DST_record(entry
).f
.fields
[i
].noffset
);
999 type_desc
= DST_record(entry
).f
.fields
[i
].type_desc
;
1000 switch(DST_record(entry
).f
.fields
[i
].f
.field_loc
.format_tag
)
1002 case dst_field_byte
:
1003 fieldoffset
= DST_record(entry
).f
.
1004 fields
[i
].f
.field_byte
.offset
* 8;
1008 fieldoffset
= DST_record(entry
).f
.
1009 fields
[i
].f
.field_bit
.byte_offset
* 8 +
1010 DST_record(entry
).f
.
1011 fields
[i
].f
.field_bit
.bit_offset
;
1012 fieldsize
= DST_record(entry
).f
.
1013 fields
[i
].f
.field_bit
.nbits
;
1016 fieldoffset
+= fieldsize
;
1022 field_name
= DST_OFFSET(entry
,
1023 DST_record(entry
).f
.sfields
[i
].noffset
);
1024 fieldoffset
= DST_record(entry
).f
.sfields
[i
].foffset
;
1025 type_desc
= DST_record(entry
).f
.sfields
[i
].type_desc
;
1026 if (i
< DST_record(entry
).nfields
- 1)
1027 fieldsize
= DST_record(entry
).f
.sfields
[i
+1].foffset
;
1029 fieldsize
= DST_record(entry
).size
;
1030 fieldsize
-= fieldoffset
;
1034 TYPE_FIELDS(type
)[i
].name
=
1035 obstack_copy0 (&objfile
->symbol_obstack
,
1036 field_name
, strlen(field_name
));
1037 TYPE_FIELDS(type
)[i
].type
= decode_type_desc(objfile
,
1040 if (fieldsize
== -1)
1041 fieldsize
= TYPE_LENGTH(TYPE_FIELDS(type
)[i
].type
) *
1043 TYPE_FIELDS(type
)[i
].bitsize
= fieldsize
;
1044 TYPE_FIELDS(type
)[i
].bitpos
= fieldoffset
;
1049 static struct type
*
1050 decode_dst_type(objfile
, entry
)
1051 struct objfile
*objfile
;
1052 dst_rec_ptr_t entry
;
1054 struct type
*child_type
, *type
, *range_type
, *index_type
;
1056 switch(entry
->rec_type
)
1059 return decode_type_desc(objfile
,
1060 &DST_var(entry
).type_desc
,
1063 case dst_typ_variable
:
1064 return decode_type_desc(objfile
,
1065 &DST_variable(entry
).type_desc
,
1068 case dst_typ_short_rec
:
1069 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,0);
1070 case dst_typ_short_union
:
1071 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 0);
1073 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 1);
1074 case dst_typ_record
:
1075 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,1);
1076 case dst_typ_old_union
:
1077 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 2);
1078 case dst_typ_old_record
:
1079 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,2);
1080 case dst_typ_pointer
:
1081 return make_pointer_type(
1082 decode_type_desc(objfile
,
1083 &DST_pointer(entry
).type_desc
,
1087 child_type
= decode_type_desc(objfile
,
1088 &DST_pointer(entry
).type_desc
,
1090 index_type
= lookup_fundamental_type(objfile
,
1092 range_type
= create_range_type ((struct type
*) NULL
,
1093 index_type
, DST_array(entry
).lo_bound
,
1094 DST_array(entry
).hi_bound
);
1095 return create_array_type ((struct type
*) NULL
, child_type
,
1098 return decode_type_desc(objfile
,
1099 &DST_alias(entry
).type_desc
,
1102 return builtin_type_int
;
1106 struct symbol_list
{
1107 struct symbol_list
*next
;
1108 struct symbol
*symbol
;
1111 static struct symbol_list
*dst_global_symbols
= NULL
;
1112 static int total_globals
= 0;
1115 decode_dst_locstring(locstr
, sym
)
1119 dst_loc_entry_t
*entry
, *next_entry
;
1127 fprintf_unfiltered(gdb_stderr
, "Error reading locstring\n");
1130 entry
= (dst_loc_entry_t
*) locstr
;
1131 next_entry
= (dst_loc_entry_t
*) (locstr
+ 1);
1132 switch (entry
->header
.code
)
1134 case dst_lsc_end
: /* End of string */
1136 case dst_lsc_indirect
:/* Indirect through previous. Arg == 6 */
1137 /* Or register ax x == arg */
1138 if (entry
->header
.arg
< 6)
1140 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1141 SYMBOL_VALUE(sym
) = entry
->header
.arg
+ 8;
1143 /* We predict indirects */
1147 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1148 SYMBOL_VALUE(sym
) = entry
->header
.arg
;
1151 case dst_lsc_section
:/* Section (arg+1) */
1152 SYMBOL_VALUE(sym
) = dst_get_addr(entry
->header
.arg
+1, 0);
1155 case dst_lsc_sec_byte
: /* Section (next_byte+1) */
1156 SYMBOL_VALUE(sym
) = dst_get_addr(locstr
[1]+1, 0);
1159 case dst_lsc_add
: /* Add (arg+1)*2 */
1160 case dst_lsc_sub
: /* Subtract (arg+1)*2 */
1161 temp
= (entry
->header
.arg
+ 1) * 2;
1163 if (*locstr
== dst_multiply_256
)
1168 switch(entry
->header
.code
)
1171 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1172 SYMBOL_CLASS(sym
) = LOC_ARG
;
1173 SYMBOL_VALUE(sym
) += temp
;
1176 SYMBOL_VALUE(sym
) -= temp
;
1180 case dst_lsc_add_byte
:
1181 case dst_lsc_sub_byte
:
1182 switch (entry
->header
.arg
& 0x03)
1185 temp
= (unsigned char) locstr
[1];
1189 temp
= * (unsigned short *) (locstr
+ 1);
1193 temp
= * (unsigned long *) (locstr
+ 1);
1197 if (*locstr
== dst_multiply_256
)
1202 switch(entry
->header
.code
)
1204 case dst_lsc_add_byte
:
1205 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1206 SYMBOL_CLASS(sym
) = LOC_ARG
;
1207 SYMBOL_VALUE(sym
) += temp
;
1209 case dst_lsc_sub_byte
:
1210 SYMBOL_VALUE(sym
) -= temp
;
1214 case dst_lsc_sbreg
: /* Stack base register (frame pointer). Arg==0*/
1215 if (next_entry
->header
.code
!= dst_lsc_indirect
)
1217 SYMBOL_VALUE(sym
) = 0;
1218 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1221 SYMBOL_VALUE(sym
) = 0;
1222 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1226 SYMBOL_VALUE(sym
) = 0;
1227 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1233 static struct symbol_list
*
1234 process_dst_symbols(objfile
, entry
, name
, nsyms_ret
)
1235 struct objfile
*objfile
;
1236 dst_rec_ptr_t entry
;
1240 struct symbol_list
*list
= NULL
, *element
;
1248 dst_var_attr_t attr
;
1249 dst_var_loc_t loc_type
;
1258 location
= (char *) entry
;
1259 while (NEXT_SYM(&location
, &entry
) &&
1260 entry
->rec_type
!= dst_typ_end_scope
)
1262 if (entry
->rec_type
== dst_typ_var
)
1264 if (DST_var(entry
).short_locs
)
1266 loc_type
= DST_var(entry
).locs
.shorts
[0].loc_type
;
1267 loc_index
= DST_var(entry
).locs
.shorts
[0].loc_index
;
1268 loc_value
= DST_var(entry
).locs
.shorts
[0].location
;
1272 loc_type
= DST_var(entry
).locs
.longs
[0].loc_type
;
1273 loc_index
= DST_var(entry
).locs
.longs
[0].loc_index
;
1274 loc_value
= DST_var(entry
).locs
.longs
[0].location
;
1276 if (loc_type
== dst_var_loc_external
)
1278 symname
= DST_OFFSET(entry
, DST_var(entry
).noffset
);
1279 line
= DST_var(entry
).src_loc
.line_number
;
1280 symtype
= DST_var(entry
).type_desc
;
1281 attr
= DST_var(entry
).attributes
;
1283 else if (entry
->rec_type
== dst_typ_variable
)
1285 symname
= DST_OFFSET(entry
,
1286 DST_variable(entry
).noffset
);
1287 line
= DST_variable(entry
).src_loc
.line_number
;
1288 symtype
= DST_variable(entry
).type_desc
;
1289 attr
= DST_variable(entry
).attributes
;
1295 if (symname
&& name
&& !strcmp(symname
, name
))
1296 /* It's the function return value */
1298 sym
= create_new_symbol(objfile
, symname
);
1300 if ((attr
& (1<<dst_var_attr_global
)) ||
1301 (attr
& (1<<dst_var_attr_static
)))
1302 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1304 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1305 SYMBOL_LINE(sym
) = line
;
1306 SYMBOL_TYPE(sym
) = decode_type_desc(objfile
, &symtype
,
1308 SYMBOL_VALUE(sym
) = 0;
1309 switch (entry
->rec_type
)
1314 case dst_var_loc_abs
:
1315 SYMBOL_VALUE_ADDRESS(sym
) = loc_value
;
1317 case dst_var_loc_sect_off
:
1318 case dst_var_loc_ind_sect_off
: /* What is this? */
1319 SYMBOL_VALUE_ADDRESS(sym
) = dst_get_addr(
1323 case dst_var_loc_ind_reg_rel
: /* What is this? */
1324 case dst_var_loc_reg_rel
:
1325 /* If it isn't fp relative, specify the
1326 * register it's relative to.
1330 sym
->aux_value
.basereg
= loc_index
;
1332 SYMBOL_VALUE(sym
) = loc_value
;
1333 if (loc_value
> 0 &&
1334 SYMBOL_CLASS(sym
) == LOC_BASEREG
)
1335 SYMBOL_CLASS(sym
) = LOC_BASEREG_ARG
;
1337 case dst_var_loc_reg
:
1338 SYMBOL_VALUE(sym
) = loc_index
;
1339 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1343 case dst_typ_variable
:
1344 /* External variable..... don't try to interpret
1345 * its nonexistant locstring.
1347 if (DST_variable(entry
).loffset
== -1)
1349 decode_dst_locstring(DST_OFFSET(entry
,
1350 DST_variable(entry
).loffset
),
1353 element
= (struct symbol_list
*)
1354 xmalloc(sizeof(struct symbol_list
));
1356 if (attr
& (1<<dst_var_attr_global
))
1358 element
->next
= dst_global_symbols
;
1359 dst_global_symbols
= element
;
1364 element
->next
= list
;
1368 element
->symbol
= sym
;
1375 static struct symbol
*
1376 process_dst_function(objfile
, entry
, name
, address
)
1377 struct objfile
*objfile
;
1378 dst_rec_ptr_t entry
;
1383 struct type
*type
, *ftype
;
1384 dst_rec_ptr_t sym_entry
, typ_entry
;
1386 struct symbol_list
*element
;
1388 type
= builtin_type_int
;
1389 sym
= create_new_symbol(objfile
, name
);
1390 SYMBOL_CLASS(sym
) = LOC_BLOCK
;
1394 location
= (char *) entry
;
1397 NEXT_SYM(&location
, &sym_entry
);
1398 } while (sym_entry
&& sym_entry
->rec_type
!= dst_typ_signature
);
1403 DST_signature(sym_entry
).src_loc
.line_number
;
1404 if (DST_signature(sym_entry
).result
)
1406 typ_entry
= (dst_rec_ptr_t
)
1407 DST_OFFSET(sym_entry
,
1408 DST_signature(sym_entry
).result
);
1409 type
= decode_dst_type(objfile
, typ_entry
);
1414 if (!type
->function_type
)
1416 ftype
= create_new_type(objfile
);
1417 type
->function_type
= ftype
;
1418 ftype
->target_type
= type
;
1419 ftype
->code
= TYPE_CODE_FUNC
;
1421 SYMBOL_TYPE(sym
) = type
->function_type
;
1423 /* Now add ourselves to the global symbols list */
1424 element
= (struct symbol_list
*)
1425 xmalloc(sizeof(struct symbol_list
));
1427 element
->next
= dst_global_symbols
;
1428 dst_global_symbols
= element
;
1430 element
->symbol
= sym
;
1435 static struct block
*
1436 process_dst_block(objfile
, entry
)
1437 struct objfile
*objfile
;
1438 dst_rec_ptr_t entry
;
1440 struct block
*block
;
1441 struct symbol
*function
= NULL
;
1445 dst_rec_ptr_t child_entry
, symbol_entry
;
1446 struct block
*child_block
;
1447 int total_symbols
= 0;
1448 struct pending_block
*pblock
;
1450 static long fake_seq
= 0;
1451 struct symbol_list
*symlist
, *nextsym
;
1454 if (DST_block(entry
).noffset
)
1455 name
= DST_OFFSET(entry
, DST_block(entry
).noffset
);
1458 if (DST_block(entry
).n_of_code_ranges
)
1460 address
= dst_sym_addr(
1461 &DST_block(entry
).code_ranges
[0].code_start
);
1462 size
= DST_block(entry
).code_ranges
[0].code_size
;
1469 symbol_entry
= (dst_rec_ptr_t
) get_sec_ref(&DST_block(entry
).symbols_start
);
1470 switch(DST_block(entry
).block_type
)
1472 /* These are all really functions. Even the "program" type.
1473 * This is because the Apollo OS was written in Pascal, and
1474 * in Pascal, the main procedure is described as the Program.
1477 case dst_block_procedure
:
1478 case dst_block_function
:
1479 case dst_block_subroutine
:
1480 case dst_block_program
:
1481 record_minimal_symbol(name
, address
, mst_text
, objfile
);
1482 function
= process_dst_function(
1487 enter_all_lines(get_sec_ref(&DST_block(entry
).code_ranges
[0].lines_start
), address
);
1489 case dst_block_block_data
:
1493 /* GDB has to call it something, and the module name
1496 sprintf(fake_name
, "block_%08lx", fake_seq
++);
1497 function
= process_dst_function(
1498 objfile
, NULL
, fake_name
, address
);
1501 symlist
= process_dst_symbols(objfile
, symbol_entry
,
1502 name
, &total_symbols
);
1503 block
= (struct block
*)
1504 obstack_alloc (&objfile
->symbol_obstack
,
1505 sizeof (struct block
) +
1506 (total_symbols
- 1) * sizeof (struct symbol
*));
1511 nextsym
= symlist
->next
;
1513 block
->sym
[symnum
] = symlist
->symbol
;
1515 free((PTR
) symlist
);
1519 BLOCK_NSYMS (block
) = total_symbols
;
1520 BLOCK_START (block
) = address
;
1521 BLOCK_END (block
) = address
+ size
;
1522 BLOCK_SUPERBLOCK (block
) = 0;
1525 SYMBOL_BLOCK_VALUE (function
) = block
;
1526 BLOCK_FUNCTION (block
) = function
;
1529 BLOCK_FUNCTION (block
) = 0;
1531 pblock
= (struct pending_block
*)
1532 xmalloc (sizeof (struct pending_block
));
1533 pblock
->block
= block
;
1534 pblock
->next
= pending_blocks
;
1535 pending_blocks
= pblock
;
1536 if (DST_block(entry
).child_block_off
)
1538 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1539 DST_block(entry
).child_block_off
);
1542 child_block
= process_dst_block(objfile
, child_entry
);
1545 if (BLOCK_START(child_block
) <
1546 BLOCK_START(block
) ||
1547 BLOCK_START(block
) == -1)
1548 BLOCK_START(block
) =
1549 BLOCK_START(child_block
);
1550 if (BLOCK_END(child_block
) >
1552 BLOCK_END(block
) == -1)
1554 BLOCK_END(child_block
);
1555 BLOCK_SUPERBLOCK (child_block
) = block
;
1557 if (DST_block(child_entry
).sibling_block_off
)
1558 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(
1560 DST_block(child_entry
).sibling_block_off
);
1570 read_dst_symtab (objfile
)
1571 struct objfile
*objfile
;
1574 dst_rec_ptr_t entry
, file_table
, root_block
;
1576 struct block
*block
, *global_block
;
1577 struct pending_block
*pblock
;
1579 struct symbol_list
*nextsym
;
1581 struct structure_list
*element
;
1583 current_objfile
= objfile
;
1584 buffer
= blocks_info
.buffer
;
1585 while (NEXT_BLK(&buffer
, &entry
))
1587 if (entry
->rec_type
== dst_typ_comp_unit
)
1589 file_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1590 DST_comp_unit(entry
).file_table
);
1591 section_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1592 DST_comp_unit(entry
).section_table
);
1593 root_block
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1594 DST_comp_unit(entry
).root_block_offset
);
1595 source_file
= DST_OFFSET(file_table
,
1596 DST_file_tab(file_table
).files
[0].noffset
);
1597 /* Point buffer to the start of the next comp_unit */
1598 buffer
= DST_OFFSET(entry
,
1599 DST_comp_unit(entry
).data_size
);
1602 pblock
= (struct pending_block
*)
1603 xmalloc (sizeof (struct pending_block
));
1604 pblock
->next
= NULL
;
1605 pending_blocks
= pblock
;
1607 block
= process_dst_block(objfile
, root_block
);
1609 global_block
= (struct block
*)
1610 obstack_alloc (&objfile
->symbol_obstack
,
1611 sizeof (struct block
) +
1612 (total_globals
- 1) *
1613 sizeof (struct symbol
*));
1614 BLOCK_NSYMS(global_block
) = total_globals
;
1615 for (symnum
= 0; symnum
< total_globals
; symnum
++)
1617 nextsym
= dst_global_symbols
->next
;
1619 global_block
->sym
[symnum
] =
1620 dst_global_symbols
->symbol
;
1622 free((PTR
) dst_global_symbols
);
1623 dst_global_symbols
= nextsym
;
1625 dst_global_symbols
= NULL
;
1627 BLOCK_FUNCTION(global_block
) = 0;
1628 BLOCK_START(global_block
) = BLOCK_START(block
);
1629 BLOCK_END(global_block
) = BLOCK_END(block
);
1630 BLOCK_SUPERBLOCK(global_block
) = 0;
1631 BLOCK_SUPERBLOCK(block
) = global_block
;
1632 pblock
->block
= global_block
;
1634 complete_symtab(source_file
,
1636 BLOCK_END(block
) - BLOCK_START(block
));
1638 dst_end_symtab(objfile
);
1642 record_minimal_symbol("<end_of_program>",
1643 BLOCK_END(block
), mst_text
, objfile
);
1644 /* One more faked symbol to make sure nothing can ever run off the
1645 * end of the symbol table. This one represents the end of the
1646 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1647 * int possible), but some parts of gdb treated it as a signed
1648 * number and failed comparisons. We could equally use 7fffffff,
1649 * but no functions are ever mapped to an address higher than
1652 record_minimal_symbol("<end_of_text>",
1653 (CORE_ADDR
) 0x40000000,
1657 element
= struct_list
;
1658 struct_list
= element
->next
;
1659 free((PTR
) element
);
1664 /* Support for line number handling */
1665 static char *linetab
= NULL
;
1666 static long linetab_offset
;
1667 static unsigned long linetab_size
;
1669 /* Read in all the line numbers for fast lookups later. Leave them in
1670 external (unswapped) format in memory; we'll swap them as we enter
1671 them into GDB's data structures. */
1673 init_one_section(chan
, secinfo
)
1677 if (secinfo
->size
== 0
1678 || lseek(chan
, secinfo
->position
, 0) == -1
1679 || (secinfo
->buffer
= xmalloc(secinfo
->size
)) == NULL
1680 || myread(chan
, secinfo
->buffer
, secinfo
->size
) == -1)
1687 init_dst_sections (chan
)
1691 if (!init_one_section(chan
, &blocks_info
) ||
1692 !init_one_section(chan
, &lines_info
) ||
1693 !init_one_section(chan
, &symbols_info
))
1699 /* Fake up support for relocating symbol addresses. FIXME. */
1701 struct section_offsets dst_symfile_faker
= {0};
1703 struct section_offsets
*
1704 dst_symfile_offsets (objfile
, addr
)
1705 struct objfile
*objfile
;
1708 objfile
->num_sections
= 1;
1709 return &dst_symfile_faker
;
1712 /* Register our ability to parse symbols for DST BFD files */
1714 static struct sym_fns dst_sym_fns
=
1716 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1717 a separate flavour like ecoff? */
1718 (enum bfd_flavour
)-2,
1720 dst_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1721 dst_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1722 dst_symfile_read
, /* sym_read: read a symbol file into symtab */
1723 dst_symfile_finish
, /* sym_finish: finished with file, cleanup */
1724 dst_symfile_offsets
, /* sym_offsets: xlate external to internal form */
1725 NULL
/* next: pointer to next struct sym_fns */
1729 _initialize_dstread ()
1731 add_symtab_fns(&dst_sym_fns
);