1 /* Read apollo DST symbol tables and convert to internal format, for GDB.
2 Contributed by Troy Rollo, University of NSW (troy@cbme.unsw.edu.au).
3 Copyright 1993 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "breakpoint.h"
32 #include "gdb_string.h"
36 CORE_ADDR cur_src_start_addr
, cur_src_end_addr
;
37 dst_sec blocks_info
, lines_info
, symbols_info
;
39 /* Vector of line number information. */
41 static struct linetable
*line_vector
;
43 /* Index of next entry to go in line_vector_index. */
45 static int line_vector_index
;
47 /* Last line number recorded in the line vector. */
49 static int prev_line_number
;
51 /* Number of elements allocated for line_vector currently. */
53 static int line_vector_length
;
56 init_dst_sections
PARAMS ((int));
59 read_dst_symtab
PARAMS ((struct objfile
*));
62 find_dst_sections
PARAMS ((bfd
*, sec_ptr
, PTR
));
65 dst_symfile_init
PARAMS ((struct objfile
*));
68 dst_new_init
PARAMS ((struct objfile
*));
71 dst_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
74 dst_symfile_finish
PARAMS ((struct objfile
*));
77 dst_end_symtab
PARAMS ((struct objfile
*));
80 complete_symtab
PARAMS ((char *, CORE_ADDR
, unsigned int));
83 dst_start_symtab
PARAMS ((void));
86 dst_record_line
PARAMS ((int, CORE_ADDR
));
88 /* Manage the vector of line numbers. */
89 /* FIXME: Use record_line instead. */
92 dst_record_line (line
, pc
)
96 struct linetable_entry
*e
;
97 /* Make sure line vector is big enough. */
99 if (line_vector_index
+ 2 >= line_vector_length
)
101 line_vector_length
*= 2;
102 line_vector
= (struct linetable
*)
103 xrealloc ((char *) line_vector
, sizeof (struct linetable
)
104 + (line_vector_length
105 * sizeof (struct linetable_entry
)));
108 e
= line_vector
->item
+ line_vector_index
++;
113 /* Start a new symtab for a new source file.
114 It indicates the start of data for one original source file. */
115 /* FIXME: use start_symtab, like coffread.c now does. */
120 /* Initialize the source file line number information for this file. */
122 if (line_vector
) /* Unlikely, but maybe possible? */
123 free ((PTR
) line_vector
);
124 line_vector_index
= 0;
125 line_vector_length
= 1000;
126 prev_line_number
= -2; /* Force first line number to be explicit */
127 line_vector
= (struct linetable
*)
128 xmalloc (sizeof (struct linetable
)
129 + line_vector_length
* sizeof (struct linetable_entry
));
132 /* Save the vital information from when starting to read a file,
133 for use when closing off the current file.
134 NAME is the file name the symbols came from, START_ADDR is the first
135 text address for the file, and SIZE is the number of bytes of text. */
138 complete_symtab (name
, start_addr
, size
)
140 CORE_ADDR start_addr
;
143 last_source_file
= savestring (name
, strlen (name
));
144 cur_src_start_addr
= start_addr
;
145 cur_src_end_addr
= start_addr
+ size
;
147 if (current_objfile
->ei
.entry_point
>= cur_src_start_addr
&&
148 current_objfile
->ei
.entry_point
< cur_src_end_addr
)
150 current_objfile
->ei
.entry_file_lowpc
= cur_src_start_addr
;
151 current_objfile
->ei
.entry_file_highpc
= cur_src_end_addr
;
155 /* Finish the symbol definitions for one main source file,
156 close off all the lexical contexts for that file
157 (creating struct block's for them), then make the
158 struct symtab for that file and put it in the list of all such. */
159 /* FIXME: Use end_symtab, like coffread.c now does. */
162 dst_end_symtab (objfile
)
163 struct objfile
*objfile
;
165 register struct symtab
*symtab
;
166 register struct blockvector
*blockvector
;
167 register struct linetable
*lv
;
169 /* Create the blockvector that points to all the file's blocks. */
171 blockvector
= make_blockvector (objfile
);
173 /* Now create the symtab object for this source file. */
174 symtab
= allocate_symtab (last_source_file
, objfile
);
176 /* Fill in its components. */
177 symtab
->blockvector
= blockvector
;
178 symtab
->free_code
= free_linetable
;
179 symtab
->free_ptr
= 0;
180 symtab
->filename
= last_source_file
;
181 symtab
->dirname
= NULL
;
182 symtab
->debugformat
= obsavestring ("Apollo DST", 10,
183 &objfile
->symbol_obstack
);
185 lv
->nitems
= line_vector_index
;
186 symtab
->linetable
= (struct linetable
*)
187 xrealloc ((char *) lv
, (sizeof (struct linetable
)
188 + lv
->nitems
* sizeof (struct linetable_entry
)));
190 free_named_symtabs (symtab
->filename
);
192 /* Reinitialize for beginning of new file. */
194 line_vector_length
= -1;
195 last_source_file
= NULL
;
198 /* dst_symfile_init ()
199 is the dst-specific initialization routine for reading symbols.
201 We will only be called if this is a DST or DST-like file.
202 BFD handles figuring out the format of the file, and code in symtab.c
203 uses BFD's determination to vector to us.
205 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
208 dst_symfile_init (objfile
)
209 struct objfile
*objfile
;
212 bfd
*abfd
= objfile
->obfd
;
214 init_entry_point_info (objfile
);
218 /* This function is called for every section; it finds the outer limits
219 of the line table (minimum and maximum file offset) so that the
220 mainline code can read the whole thing for efficiency. */
224 find_dst_sections (abfd
, asect
, vpinfo
)
231 file_ptr offset
, maxoff
;
234 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
235 size
= asect
->_raw_size
;
236 offset
= asect
->filepos
;
241 if (!strcmp (asect
->name
, ".blocks"))
242 section
= &blocks_info
;
243 else if (!strcmp (asect
->name
, ".lines"))
244 section
= &lines_info
;
245 else if (!strcmp (asect
->name
, ".symbols"))
246 section
= &symbols_info
;
249 section
->size
= size
;
250 section
->position
= offset
;
251 section
->base
= base
;
255 /* The BFD for this file -- only good while we're actively reading
256 symbols into a psymtab or a symtab. */
258 static bfd
*symfile_bfd
;
260 /* Read a symbol file, after initialization by dst_symfile_init. */
261 /* FIXME! Addr and Mainline are not used yet -- this will not work for
262 shared libraries or add_file! */
266 dst_symfile_read (objfile
, section_offsets
, mainline
)
267 struct objfile
*objfile
;
268 struct section_offsets
*section_offsets
;
271 bfd
*abfd
= objfile
->obfd
;
272 char *name
= bfd_get_filename (abfd
);
277 int stringtab_offset
;
279 symfile_bfd
= abfd
; /* Kludge for swap routines */
281 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
282 desc
= fileno ((FILE *) (abfd
->iostream
)); /* File descriptor */
284 /* Read the line number table, all at once. */
285 bfd_map_over_sections (abfd
, find_dst_sections
, (PTR
) NULL
);
287 val
= init_dst_sections (desc
);
289 error ("\"%s\": error reading debugging symbol tables\n", name
);
291 init_minimal_symbol_collection ();
292 make_cleanup (discard_minimal_symbols
, 0);
294 /* Now that the executable file is positioned at symbol table,
295 process it and define symbols accordingly. */
297 read_dst_symtab (objfile
);
299 /* Sort symbols alphabetically within each block. */
303 for (s
= objfile
->symtabs
; s
!= NULL
; s
= s
->next
)
305 sort_symtab_syms (s
);
309 /* Install any minimal symbols that have been collected as the current
310 minimal symbols for this objfile. */
312 install_minimal_symbols (objfile
);
316 dst_new_init (ignore
)
317 struct objfile
*ignore
;
322 /* Perform any local cleanups required when we are done with a particular
323 objfile. I.E, we are in the process of discarding all symbol information
324 for an objfile, freeing up all memory held for it, and unlinking the
325 objfile struct from the global list of known objfiles. */
328 dst_symfile_finish (objfile
)
329 struct objfile
*objfile
;
335 /* Get the next line number from the DST. Returns 0 when we hit an
336 * end directive or cannot continue for any other reason.
338 * Note that ordinary pc deltas are multiplied by two. Apparently
339 * this is what was really intended.
342 get_dst_line (buffer
, pc
)
343 signed char **buffer
;
347 static long last_line
= 0;
348 static int last_file
= 0;
349 dst_ln_entry_ptr_t entry
;
351 dst_src_loc_t
*src_loc
;
358 entry
= (dst_ln_entry_ptr_t
) * buffer
;
360 while (dst_ln_ln_delta (*entry
) == dst_ln_escape_flag
)
362 switch (entry
->esc
.esc_code
)
365 size
= 1; /* pad byte */
368 /* file escape. Next 4 bytes are a dst_src_loc_t */
370 src_loc
= (dst_src_loc_t
*) (*buffer
+ 1);
371 last_line
= src_loc
->line_number
;
372 last_file
= src_loc
->file_index
;
374 case dst_ln_dln1_dpc1
:
375 /* 1 byte line delta, 1 byte pc delta */
376 last_line
+= (*buffer
)[1];
377 last_pc
+= 2 * (unsigned char) (*buffer
)[2];
378 dst_record_line (last_line
, last_pc
);
381 case dst_ln_dln2_dpc2
:
382 /* 2 bytes line delta, 2 bytes pc delta */
383 last_line
+= *(short *) (*buffer
+ 1);
384 last_pc
+= 2 * (*(short *) (*buffer
+ 3));
386 dst_record_line (last_line
, last_pc
);
389 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
390 last_line
= *(unsigned long *) (*buffer
+ 1);
391 last_pc
= *(unsigned long *) (*buffer
+ 5);
393 dst_record_line (last_line
, last_pc
);
395 case dst_ln_dln1_dpc0
:
396 /* 1 byte line delta, pc delta = 0 */
398 last_line
+= (*buffer
)[1];
400 case dst_ln_ln_off_1
:
401 /* statement escape, stmt # = 1 (2nd stmt on line) */
405 /* statement escape, stmt # = next byte */
409 /* entry escape, next byte is entry number */
416 case dst_ln_stmt_end
:
417 /* gap escape, 4 bytes pc delta */
419 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
420 /* Apparently this isn't supposed to actually modify
421 * the pc value. Totally weird.
424 case dst_ln_escape_11
:
425 case dst_ln_escape_12
:
426 case dst_ln_escape_13
:
429 case dst_ln_nxt_byte
:
430 /* This shouldn't happen. If it does, we're SOL */
434 /* end escape, final entry follows */
437 *buffer
+= (size
< 0) ? -size
: size
;
438 entry
= (dst_ln_entry_ptr_t
) * buffer
;
440 last_line
+= dst_ln_ln_delta (*entry
);
441 last_pc
+= entry
->delta
.pc_delta
* 2;
443 dst_record_line (last_line
, last_pc
);
448 enter_all_lines (buffer
, address
)
453 while (get_dst_line (&buffer
, &address
));
457 get_dst_entry (buffer
, ret_entry
)
459 dst_rec_ptr_t
*ret_entry
;
463 static int last_type
;
467 entry
= (dst_rec_ptr_t
) buffer
;
468 switch (entry
->rec_type
)
473 case dst_typ_comp_unit
:
474 size
= sizeof (DST_comp_unit (entry
));
476 case dst_typ_section_tab
:
477 size
= sizeof (DST_section_tab (entry
))
478 + ((int) DST_section_tab (entry
).number_of_sections
479 - dst_dummy_array_size
) * sizeof (long);
481 case dst_typ_file_tab
:
482 size
= sizeof (DST_file_tab (entry
))
483 + ((int) DST_file_tab (entry
).number_of_files
484 - dst_dummy_array_size
) * sizeof (dst_file_desc_t
);
487 size
= sizeof (DST_block (entry
))
488 + ((int) DST_block (entry
).n_of_code_ranges
489 - dst_dummy_array_size
) * sizeof (dst_code_range_t
);
495 size
= sizeof (DST_var (entry
)) -
496 sizeof (dst_var_loc_long_t
) * dst_dummy_array_size
+
497 DST_var (entry
).no_of_locs
*
498 (DST_var (entry
).short_locs
?
499 sizeof (dst_var_loc_short_t
) :
500 sizeof (dst_var_loc_long_t
));
502 case dst_typ_pointer
:
503 size
= sizeof (DST_pointer (entry
));
506 size
= sizeof (DST_array (entry
));
508 case dst_typ_subrange
:
509 size
= sizeof (DST_subrange (entry
));
512 size
= sizeof (DST_set (entry
));
514 case dst_typ_implicit_enum
:
515 size
= sizeof (DST_implicit_enum (entry
))
516 + ((int) DST_implicit_enum (entry
).nelems
517 - dst_dummy_array_size
) * sizeof (dst_rel_offset_t
);
519 case dst_typ_explicit_enum
:
520 size
= sizeof (DST_explicit_enum (entry
))
521 + ((int) DST_explicit_enum (entry
).nelems
522 - dst_dummy_array_size
) * sizeof (dst_enum_elem_t
);
524 case dst_typ_short_rec
:
525 size
= sizeof (DST_short_rec (entry
))
526 + DST_short_rec (entry
).nfields
* sizeof (dst_short_field_t
)
527 - dst_dummy_array_size
* sizeof (dst_field_t
);
529 case dst_typ_short_union
:
530 size
= sizeof (DST_short_union (entry
))
531 + DST_short_union (entry
).nfields
* sizeof (dst_short_field_t
)
532 - dst_dummy_array_size
* sizeof (dst_field_t
);
535 size
= sizeof (DST_file (entry
));
538 size
= sizeof (DST_offset (entry
));
541 size
= sizeof (DST_alias (entry
));
543 case dst_typ_signature
:
544 size
= sizeof (DST_signature (entry
)) +
545 ((int) DST_signature (entry
).nargs
-
546 dst_dummy_array_size
) * sizeof (dst_arg_t
);
551 case dst_typ_old_label
:
552 size
= sizeof (DST_old_label (entry
));
555 size
= sizeof (DST_scope (entry
));
557 case dst_typ_end_scope
:
564 case dst_typ_string_tab
:
565 case dst_typ_global_name_tab
:
566 size
= sizeof (DST_string_tab (entry
))
567 + DST_string_tab (entry
).length
568 - dst_dummy_array_size
;
570 case dst_typ_forward
:
571 size
= sizeof (DST_forward (entry
));
572 get_dst_entry ((char *) entry
+ DST_forward (entry
).rec_off
, &entry
);
574 case dst_typ_aux_size
:
575 size
= sizeof (DST_aux_size (entry
));
577 case dst_typ_aux_align
:
578 size
= sizeof (DST_aux_align (entry
));
580 case dst_typ_aux_field_size
:
581 size
= sizeof (DST_aux_field_size (entry
));
583 case dst_typ_aux_field_off
:
584 size
= sizeof (DST_aux_field_off (entry
));
586 case dst_typ_aux_field_align
:
587 size
= sizeof (DST_aux_field_align (entry
));
589 case dst_typ_aux_qual
:
590 size
= sizeof (DST_aux_qual (entry
));
592 case dst_typ_aux_var_bound
:
593 size
= sizeof (DST_aux_var_bound (entry
));
595 case dst_typ_extension
:
596 size
= DST_extension (entry
).rec_size
;
599 size
= sizeof (DST_string (entry
));
601 case dst_typ_old_entry
:
602 size
= 48; /* Obsolete entry type */
605 size
= sizeof (DST_const (entry
))
606 + DST_const (entry
).value
.length
607 - sizeof (DST_const (entry
).value
.val
);
609 case dst_typ_reference
:
610 size
= sizeof (DST_reference (entry
));
612 case dst_typ_old_record
:
613 case dst_typ_old_union
:
616 size
= sizeof (DST_record (entry
))
617 + ((int) DST_record (entry
).nfields
618 - dst_dummy_array_size
) * sizeof (dst_field_t
);
620 case dst_typ_aux_type_deriv
:
621 size
= sizeof (DST_aux_type_deriv (entry
));
623 case dst_typ_locpool
:
624 size
= sizeof (DST_locpool (entry
))
625 + ((int) DST_locpool (entry
).length
-
626 dst_dummy_array_size
);
628 case dst_typ_variable
:
629 size
= sizeof (DST_variable (entry
));
632 size
= sizeof (DST_label (entry
));
635 size
= sizeof (DST_entry (entry
));
637 case dst_typ_aux_lifetime
:
638 size
= sizeof (DST_aux_lifetime (entry
));
640 case dst_typ_aux_ptr_base
:
641 size
= sizeof (DST_aux_ptr_base (entry
));
643 case dst_typ_aux_src_range
:
644 size
= sizeof (DST_aux_src_range (entry
));
646 case dst_typ_aux_reg_val
:
647 size
= sizeof (DST_aux_reg_val (entry
));
649 case dst_typ_aux_unit_names
:
650 size
= sizeof (DST_aux_unit_names (entry
))
651 + ((int) DST_aux_unit_names (entry
).number_of_names
652 - dst_dummy_array_size
) * sizeof (dst_rel_offset_t
);
654 case dst_typ_aux_sect_info
:
655 size
= sizeof (DST_aux_sect_info (entry
))
656 + ((int) DST_aux_sect_info (entry
).number_of_refs
657 - dst_dummy_array_size
) * sizeof (dst_sect_ref_t
);
665 fprintf_unfiltered (gdb_stderr
, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
666 (int) entry
->rec_type
,
668 fprintf_unfiltered (gdb_stderr
, "Last unknown_3 value: %d\n", lu3
);
672 last_type
= entry
->rec_type
;
673 if (size
& 1) /* Align on a word boundary */
681 next_dst_entry (buffer
, entry
, table
)
683 dst_rec_ptr_t
*entry
;
686 if (*buffer
- table
->buffer
>= table
->size
)
691 *buffer
+= get_dst_entry (*buffer
, entry
);
695 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
696 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
697 #define DST_OFFSET(a, b) ((char *) (a) + (b))
699 static dst_rec_ptr_t section_table
= NULL
;
705 dst_sec
*section
= NULL
;
708 if (!section_table
|| !ref
->sect_index
)
710 offset
= DST_section_tab (section_table
).section_base
[ref
->sect_index
- 1]
712 if (offset
>= blocks_info
.base
&&
713 offset
< blocks_info
.base
+ blocks_info
.size
)
714 section
= &blocks_info
;
715 else if (offset
>= symbols_info
.base
&&
716 offset
< symbols_info
.base
+ symbols_info
.size
)
717 section
= &symbols_info
;
718 else if (offset
>= lines_info
.base
&&
719 offset
< lines_info
.base
+ lines_info
.size
)
720 section
= &lines_info
;
723 return section
->buffer
+ (offset
- section
->base
);
727 dst_get_addr (int section
, long offset
)
729 if (!section_table
|| !section
)
731 return DST_section_tab (section_table
).section_base
[section
- 1] + offset
;
738 if (!section_table
|| !ref
->sect_index
)
740 return DST_section_tab (section_table
).section_base
[ref
->sect_index
- 1]
745 create_new_type (objfile
)
746 struct objfile
*objfile
;
750 type
= (struct type
*)
751 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct type
));
752 memset (type
, 0, sizeof (struct type
));
756 static struct symbol
*
757 create_new_symbol (objfile
, name
)
758 struct objfile
*objfile
;
761 struct symbol
*sym
= (struct symbol
*)
762 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
763 memset (sym
, 0, sizeof (struct symbol
));
764 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
765 &objfile
->symbol_obstack
);
766 SYMBOL_VALUE (sym
) = 0;
767 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
769 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
774 decode_dst_type
PARAMS ((struct objfile
*, dst_rec_ptr_t
));
777 decode_type_desc (objfile
, type_desc
, base
)
778 struct objfile
*objfile
;
779 dst_type_t
*type_desc
;
784 if (type_desc
->std_type
.user_defined_type
)
786 entry
= (dst_rec_ptr_t
) DST_OFFSET (base
,
787 dst_user_type_offset (*type_desc
));
788 type
= decode_dst_type (objfile
, entry
);
792 switch (type_desc
->std_type
.dtc
)
795 type
= builtin_type_signed_char
;
798 type
= builtin_type_short
;
801 type
= builtin_type_long
;
804 type
= builtin_type_unsigned_char
;
806 case dst_uint16_type
:
807 type
= builtin_type_unsigned_short
;
809 case dst_uint32_type
:
810 type
= builtin_type_unsigned_long
;
812 case dst_real32_type
:
813 type
= builtin_type_float
;
815 case dst_real64_type
:
816 type
= builtin_type_double
;
818 case dst_complex_type
:
819 type
= builtin_type_complex
;
821 case dst_dcomplex_type
:
822 type
= builtin_type_double_complex
;
825 type
= builtin_type_char
;
827 case dst_bool16_type
:
828 type
= builtin_type_short
;
830 case dst_bool32_type
:
831 type
= builtin_type_long
;
834 type
= builtin_type_char
;
836 /* The next few are more complex. I will take care
837 * of them properly at a later point.
839 case dst_string_type
:
840 type
= builtin_type_void
;
843 type
= builtin_type_void
;
846 type
= builtin_type_void
;
849 type
= builtin_type_void
;
852 type
= builtin_type_void
;
854 /* Back tto some ordinary ones */
856 type
= builtin_type_void
;
859 type
= builtin_type_unsigned_char
;
862 type
= builtin_type_void
;
869 struct structure_list
871 struct structure_list
*next
;
875 static struct structure_list
*struct_list
= NULL
;
878 find_dst_structure (name
)
881 struct structure_list
*element
;
883 for (element
= struct_list
; element
; element
= element
->next
)
884 if (!strcmp (name
, TYPE_NAME (element
->type
)))
885 return element
->type
;
891 decode_dst_structure (objfile
, entry
, code
, version
)
892 struct objfile
*objfile
;
897 struct type
*type
, *child_type
;
899 char *name
, *field_name
;
901 int fieldoffset
, fieldsize
;
902 dst_type_t type_desc
;
903 struct structure_list
*element
;
905 struct_name
= DST_OFFSET (entry
, DST_record (entry
).noffset
);
906 name
= concat ((code
== TYPE_CODE_UNION
) ? "union " : "struct ",
908 type
= find_dst_structure (name
);
914 type
= create_new_type (objfile
);
915 TYPE_NAME (type
) = obstack_copy0 (&objfile
->symbol_obstack
,
916 name
, strlen (name
));
918 TYPE_CODE (type
) = code
;
919 TYPE_LENGTH (type
) = DST_record (entry
).size
;
920 TYPE_NFIELDS (type
) = DST_record (entry
).nfields
;
921 TYPE_FIELDS (type
) = (struct field
*)
922 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) *
923 DST_record (entry
).nfields
);
924 fieldoffset
= fieldsize
= 0;
925 INIT_CPLUS_SPECIFIC (type
);
926 element
= (struct structure_list
*)
927 xmalloc (sizeof (struct structure_list
));
928 element
->type
= type
;
929 element
->next
= struct_list
;
930 struct_list
= element
;
931 for (i
= 0; i
< DST_record (entry
).nfields
; i
++)
936 field_name
= DST_OFFSET (entry
,
937 DST_record (entry
).f
.ofields
[i
].noffset
);
938 fieldoffset
= DST_record (entry
).f
.ofields
[i
].foffset
* 8 +
939 DST_record (entry
).f
.ofields
[i
].bit_offset
;
940 fieldsize
= DST_record (entry
).f
.ofields
[i
].size
;
941 type_desc
= DST_record (entry
).f
.ofields
[i
].type_desc
;
944 field_name
= DST_OFFSET (entry
,
945 DST_record (entry
).f
.fields
[i
].noffset
);
946 type_desc
= DST_record (entry
).f
.fields
[i
].type_desc
;
947 switch (DST_record (entry
).f
.fields
[i
].f
.field_loc
.format_tag
)
950 fieldoffset
= DST_record (entry
).f
.
951 fields
[i
].f
.field_byte
.offset
* 8;
955 fieldoffset
= DST_record (entry
).f
.
956 fields
[i
].f
.field_bit
.byte_offset
* 8 +
957 DST_record (entry
).f
.
958 fields
[i
].f
.field_bit
.bit_offset
;
959 fieldsize
= DST_record (entry
).f
.
960 fields
[i
].f
.field_bit
.nbits
;
963 fieldoffset
+= fieldsize
;
969 field_name
= DST_OFFSET (entry
,
970 DST_record (entry
).f
.sfields
[i
].noffset
);
971 fieldoffset
= DST_record (entry
).f
.sfields
[i
].foffset
;
972 type_desc
= DST_record (entry
).f
.sfields
[i
].type_desc
;
973 if (i
< DST_record (entry
).nfields
- 1)
974 fieldsize
= DST_record (entry
).f
.sfields
[i
+ 1].foffset
;
976 fieldsize
= DST_record (entry
).size
;
977 fieldsize
-= fieldoffset
;
981 TYPE_FIELDS (type
)[i
].name
=
982 obstack_copy0 (&objfile
->symbol_obstack
,
983 field_name
, strlen (field_name
));
984 TYPE_FIELDS (type
)[i
].type
= decode_type_desc (objfile
,
988 fieldsize
= TYPE_LENGTH (TYPE_FIELDS (type
)[i
].type
) *
990 TYPE_FIELDS (type
)[i
].bitsize
= fieldsize
;
991 TYPE_FIELDS (type
)[i
].bitpos
= fieldoffset
;
997 decode_dst_type (objfile
, entry
)
998 struct objfile
*objfile
;
1001 struct type
*child_type
, *type
, *range_type
, *index_type
;
1003 switch (entry
->rec_type
)
1006 return decode_type_desc (objfile
,
1007 &DST_var (entry
).type_desc
,
1010 case dst_typ_variable
:
1011 return decode_type_desc (objfile
,
1012 &DST_variable (entry
).type_desc
,
1015 case dst_typ_short_rec
:
1016 return decode_dst_structure (objfile
, entry
, TYPE_CODE_STRUCT
, 0);
1017 case dst_typ_short_union
:
1018 return decode_dst_structure (objfile
, entry
, TYPE_CODE_UNION
, 0);
1020 return decode_dst_structure (objfile
, entry
, TYPE_CODE_UNION
, 1);
1021 case dst_typ_record
:
1022 return decode_dst_structure (objfile
, entry
, TYPE_CODE_STRUCT
, 1);
1023 case dst_typ_old_union
:
1024 return decode_dst_structure (objfile
, entry
, TYPE_CODE_UNION
, 2);
1025 case dst_typ_old_record
:
1026 return decode_dst_structure (objfile
, entry
, TYPE_CODE_STRUCT
, 2);
1027 case dst_typ_pointer
:
1028 return make_pointer_type (
1029 decode_type_desc (objfile
,
1030 &DST_pointer (entry
).type_desc
,
1034 child_type
= decode_type_desc (objfile
,
1035 &DST_pointer (entry
).type_desc
,
1037 index_type
= lookup_fundamental_type (objfile
,
1039 range_type
= create_range_type ((struct type
*) NULL
,
1040 index_type
, DST_array (entry
).lo_bound
,
1041 DST_array (entry
).hi_bound
);
1042 return create_array_type ((struct type
*) NULL
, child_type
,
1045 return decode_type_desc (objfile
,
1046 &DST_alias (entry
).type_desc
,
1049 return builtin_type_int
;
1055 struct symbol_list
*next
;
1056 struct symbol
*symbol
;
1059 static struct symbol_list
*dst_global_symbols
= NULL
;
1060 static int total_globals
= 0;
1063 decode_dst_locstring (locstr
, sym
)
1067 dst_loc_entry_t
*entry
, *next_entry
;
1075 fprintf_unfiltered (gdb_stderr
, "Error reading locstring\n");
1078 entry
= (dst_loc_entry_t
*) locstr
;
1079 next_entry
= (dst_loc_entry_t
*) (locstr
+ 1);
1080 switch (entry
->header
.code
)
1082 case dst_lsc_end
: /* End of string */
1084 case dst_lsc_indirect
: /* Indirect through previous. Arg == 6 */
1085 /* Or register ax x == arg */
1086 if (entry
->header
.arg
< 6)
1088 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1089 SYMBOL_VALUE (sym
) = entry
->header
.arg
+ 8;
1091 /* We predict indirects */
1095 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1096 SYMBOL_VALUE (sym
) = entry
->header
.arg
;
1099 case dst_lsc_section
: /* Section (arg+1) */
1100 SYMBOL_VALUE (sym
) = dst_get_addr (entry
->header
.arg
+ 1, 0);
1103 case dst_lsc_sec_byte
: /* Section (next_byte+1) */
1104 SYMBOL_VALUE (sym
) = dst_get_addr (locstr
[1] + 1, 0);
1107 case dst_lsc_add
: /* Add (arg+1)*2 */
1108 case dst_lsc_sub
: /* Subtract (arg+1)*2 */
1109 temp
= (entry
->header
.arg
+ 1) * 2;
1111 if (*locstr
== dst_multiply_256
)
1116 switch (entry
->header
.code
)
1119 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
)
1120 SYMBOL_CLASS (sym
) = LOC_ARG
;
1121 SYMBOL_VALUE (sym
) += temp
;
1124 SYMBOL_VALUE (sym
) -= temp
;
1128 case dst_lsc_add_byte
:
1129 case dst_lsc_sub_byte
:
1130 switch (entry
->header
.arg
& 0x03)
1133 temp
= (unsigned char) locstr
[1];
1137 temp
= *(unsigned short *) (locstr
+ 1);
1141 temp
= *(unsigned long *) (locstr
+ 1);
1145 if (*locstr
== dst_multiply_256
)
1150 switch (entry
->header
.code
)
1152 case dst_lsc_add_byte
:
1153 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
)
1154 SYMBOL_CLASS (sym
) = LOC_ARG
;
1155 SYMBOL_VALUE (sym
) += temp
;
1157 case dst_lsc_sub_byte
:
1158 SYMBOL_VALUE (sym
) -= temp
;
1162 case dst_lsc_sbreg
: /* Stack base register (frame pointer). Arg==0 */
1163 if (next_entry
->header
.code
!= dst_lsc_indirect
)
1165 SYMBOL_VALUE (sym
) = 0;
1166 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1169 SYMBOL_VALUE (sym
) = 0;
1170 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1174 SYMBOL_VALUE (sym
) = 0;
1175 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1181 static struct symbol_list
*
1182 process_dst_symbols (objfile
, entry
, name
, nsyms_ret
)
1183 struct objfile
*objfile
;
1184 dst_rec_ptr_t entry
;
1188 struct symbol_list
*list
= NULL
, *element
;
1196 dst_var_attr_t attr
;
1197 dst_var_loc_t loc_type
;
1206 location
= (char *) entry
;
1207 while (NEXT_SYM (&location
, &entry
) &&
1208 entry
->rec_type
!= dst_typ_end_scope
)
1210 if (entry
->rec_type
== dst_typ_var
)
1212 if (DST_var (entry
).short_locs
)
1214 loc_type
= DST_var (entry
).locs
.shorts
[0].loc_type
;
1215 loc_index
= DST_var (entry
).locs
.shorts
[0].loc_index
;
1216 loc_value
= DST_var (entry
).locs
.shorts
[0].location
;
1220 loc_type
= DST_var (entry
).locs
.longs
[0].loc_type
;
1221 loc_index
= DST_var (entry
).locs
.longs
[0].loc_index
;
1222 loc_value
= DST_var (entry
).locs
.longs
[0].location
;
1224 if (loc_type
== dst_var_loc_external
)
1226 symname
= DST_OFFSET (entry
, DST_var (entry
).noffset
);
1227 line
= DST_var (entry
).src_loc
.line_number
;
1228 symtype
= DST_var (entry
).type_desc
;
1229 attr
= DST_var (entry
).attributes
;
1231 else if (entry
->rec_type
== dst_typ_variable
)
1233 symname
= DST_OFFSET (entry
,
1234 DST_variable (entry
).noffset
);
1235 line
= DST_variable (entry
).src_loc
.line_number
;
1236 symtype
= DST_variable (entry
).type_desc
;
1237 attr
= DST_variable (entry
).attributes
;
1243 if (symname
&& name
&& !strcmp (symname
, name
))
1244 /* It's the function return value */
1246 sym
= create_new_symbol (objfile
, symname
);
1248 if ((attr
& (1 << dst_var_attr_global
)) ||
1249 (attr
& (1 << dst_var_attr_static
)))
1250 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1252 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1253 SYMBOL_LINE (sym
) = line
;
1254 SYMBOL_TYPE (sym
) = decode_type_desc (objfile
, &symtype
,
1256 SYMBOL_VALUE (sym
) = 0;
1257 switch (entry
->rec_type
)
1262 case dst_var_loc_abs
:
1263 SYMBOL_VALUE_ADDRESS (sym
) = loc_value
;
1265 case dst_var_loc_sect_off
:
1266 case dst_var_loc_ind_sect_off
: /* What is this? */
1267 SYMBOL_VALUE_ADDRESS (sym
) = dst_get_addr (
1271 case dst_var_loc_ind_reg_rel
: /* What is this? */
1272 case dst_var_loc_reg_rel
:
1273 /* If it isn't fp relative, specify the
1274 * register it's relative to.
1278 sym
->aux_value
.basereg
= loc_index
;
1280 SYMBOL_VALUE (sym
) = loc_value
;
1281 if (loc_value
> 0 &&
1282 SYMBOL_CLASS (sym
) == LOC_BASEREG
)
1283 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
1285 case dst_var_loc_reg
:
1286 SYMBOL_VALUE (sym
) = loc_index
;
1287 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1291 case dst_typ_variable
:
1292 /* External variable..... don't try to interpret
1293 * its nonexistant locstring.
1295 if (DST_variable (entry
).loffset
== -1)
1297 decode_dst_locstring (DST_OFFSET (entry
,
1298 DST_variable (entry
).loffset
),
1301 element
= (struct symbol_list
*)
1302 xmalloc (sizeof (struct symbol_list
));
1304 if (attr
& (1 << dst_var_attr_global
))
1306 element
->next
= dst_global_symbols
;
1307 dst_global_symbols
= element
;
1312 element
->next
= list
;
1316 element
->symbol
= sym
;
1323 static struct symbol
*
1324 process_dst_function (objfile
, entry
, name
, address
)
1325 struct objfile
*objfile
;
1326 dst_rec_ptr_t entry
;
1331 struct type
*type
, *ftype
;
1332 dst_rec_ptr_t sym_entry
, typ_entry
;
1334 struct symbol_list
*element
;
1336 type
= builtin_type_int
;
1337 sym
= create_new_symbol (objfile
, name
);
1338 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1342 location
= (char *) entry
;
1345 NEXT_SYM (&location
, &sym_entry
);
1347 while (sym_entry
&& sym_entry
->rec_type
!= dst_typ_signature
);
1352 DST_signature (sym_entry
).src_loc
.line_number
;
1353 if (DST_signature (sym_entry
).result
)
1355 typ_entry
= (dst_rec_ptr_t
)
1356 DST_OFFSET (sym_entry
,
1357 DST_signature (sym_entry
).result
);
1358 type
= decode_dst_type (objfile
, typ_entry
);
1363 if (!type
->function_type
)
1365 ftype
= create_new_type (objfile
);
1366 type
->function_type
= ftype
;
1367 ftype
->target_type
= type
;
1368 ftype
->code
= TYPE_CODE_FUNC
;
1370 SYMBOL_TYPE (sym
) = type
->function_type
;
1372 /* Now add ourselves to the global symbols list */
1373 element
= (struct symbol_list
*)
1374 xmalloc (sizeof (struct symbol_list
));
1376 element
->next
= dst_global_symbols
;
1377 dst_global_symbols
= element
;
1379 element
->symbol
= sym
;
1384 static struct block
*
1385 process_dst_block (objfile
, entry
)
1386 struct objfile
*objfile
;
1387 dst_rec_ptr_t entry
;
1389 struct block
*block
;
1390 struct symbol
*function
= NULL
;
1394 dst_rec_ptr_t child_entry
, symbol_entry
;
1395 struct block
*child_block
;
1396 int total_symbols
= 0;
1398 static long fake_seq
= 0;
1399 struct symbol_list
*symlist
, *nextsym
;
1402 if (DST_block (entry
).noffset
)
1403 name
= DST_OFFSET (entry
, DST_block (entry
).noffset
);
1406 if (DST_block (entry
).n_of_code_ranges
)
1408 address
= dst_sym_addr (
1409 &DST_block (entry
).code_ranges
[0].code_start
);
1410 size
= DST_block (entry
).code_ranges
[0].code_size
;
1417 symbol_entry
= (dst_rec_ptr_t
) get_sec_ref (&DST_block (entry
).symbols_start
);
1418 switch (DST_block (entry
).block_type
)
1420 /* These are all really functions. Even the "program" type.
1421 * This is because the Apollo OS was written in Pascal, and
1422 * in Pascal, the main procedure is described as the Program.
1425 case dst_block_procedure
:
1426 case dst_block_function
:
1427 case dst_block_subroutine
:
1428 case dst_block_program
:
1429 prim_record_minimal_symbol (name
, address
, mst_text
, objfile
);
1430 function
= process_dst_function (
1435 enter_all_lines (get_sec_ref (&DST_block (entry
).code_ranges
[0].lines_start
), address
);
1437 case dst_block_block_data
:
1441 /* GDB has to call it something, and the module name
1444 sprintf (fake_name
, "block_%08lx", fake_seq
++);
1445 function
= process_dst_function (
1446 objfile
, NULL
, fake_name
, address
);
1449 symlist
= process_dst_symbols (objfile
, symbol_entry
,
1450 name
, &total_symbols
);
1451 block
= (struct block
*)
1452 obstack_alloc (&objfile
->symbol_obstack
,
1453 sizeof (struct block
) +
1454 (total_symbols
- 1) * sizeof (struct symbol
*));
1459 nextsym
= symlist
->next
;
1461 block
->sym
[symnum
] = symlist
->symbol
;
1463 free ((PTR
) symlist
);
1467 BLOCK_NSYMS (block
) = total_symbols
;
1468 BLOCK_START (block
) = address
;
1469 BLOCK_END (block
) = address
+ size
;
1470 BLOCK_SUPERBLOCK (block
) = 0;
1473 SYMBOL_BLOCK_VALUE (function
) = block
;
1474 BLOCK_FUNCTION (block
) = function
;
1477 BLOCK_FUNCTION (block
) = 0;
1479 if (DST_block (entry
).child_block_off
)
1481 child_entry
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1482 DST_block (entry
).child_block_off
);
1485 child_block
= process_dst_block (objfile
, child_entry
);
1488 if (BLOCK_START (child_block
) <
1489 BLOCK_START (block
) ||
1490 BLOCK_START (block
) == -1)
1491 BLOCK_START (block
) =
1492 BLOCK_START (child_block
);
1493 if (BLOCK_END (child_block
) >
1494 BLOCK_END (block
) ||
1495 BLOCK_END (block
) == -1)
1497 BLOCK_END (child_block
);
1498 BLOCK_SUPERBLOCK (child_block
) = block
;
1500 if (DST_block (child_entry
).sibling_block_off
)
1501 child_entry
= (dst_rec_ptr_t
) DST_OFFSET (
1503 DST_block (child_entry
).sibling_block_off
);
1508 record_pending_block (objfile
, block
, NULL
);
1514 read_dst_symtab (objfile
)
1515 struct objfile
*objfile
;
1518 dst_rec_ptr_t entry
, file_table
, root_block
;
1520 struct block
*block
, *global_block
;
1522 struct symbol_list
*nextsym
;
1524 struct structure_list
*element
;
1526 current_objfile
= objfile
;
1527 buffer
= blocks_info
.buffer
;
1528 while (NEXT_BLK (&buffer
, &entry
))
1530 if (entry
->rec_type
== dst_typ_comp_unit
)
1532 file_table
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1533 DST_comp_unit (entry
).file_table
);
1534 section_table
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1535 DST_comp_unit (entry
).section_table
);
1536 root_block
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1537 DST_comp_unit (entry
).root_block_offset
);
1538 source_file
= DST_OFFSET (file_table
,
1539 DST_file_tab (file_table
).files
[0].noffset
);
1540 /* Point buffer to the start of the next comp_unit */
1541 buffer
= DST_OFFSET (entry
,
1542 DST_comp_unit (entry
).data_size
);
1543 dst_start_symtab ();
1545 block
= process_dst_block (objfile
, root_block
);
1547 global_block
= (struct block
*)
1548 obstack_alloc (&objfile
->symbol_obstack
,
1549 sizeof (struct block
) +
1550 (total_globals
- 1) *
1551 sizeof (struct symbol
*));
1552 BLOCK_NSYMS (global_block
) = total_globals
;
1553 for (symnum
= 0; symnum
< total_globals
; symnum
++)
1555 nextsym
= dst_global_symbols
->next
;
1557 global_block
->sym
[symnum
] =
1558 dst_global_symbols
->symbol
;
1560 free ((PTR
) dst_global_symbols
);
1561 dst_global_symbols
= nextsym
;
1563 dst_global_symbols
= NULL
;
1565 BLOCK_FUNCTION (global_block
) = 0;
1566 BLOCK_START (global_block
) = BLOCK_START (block
);
1567 BLOCK_END (global_block
) = BLOCK_END (block
);
1568 BLOCK_SUPERBLOCK (global_block
) = 0;
1569 BLOCK_SUPERBLOCK (block
) = global_block
;
1570 record_pending_block (objfile
, global_block
, NULL
);
1572 complete_symtab (source_file
,
1573 BLOCK_START (block
),
1574 BLOCK_END (block
) - BLOCK_START (block
));
1576 dst_end_symtab (objfile
);
1580 prim_record_minimal_symbol ("<end_of_program>",
1581 BLOCK_END (block
), mst_text
, objfile
);
1582 /* One more faked symbol to make sure nothing can ever run off the
1583 * end of the symbol table. This one represents the end of the
1584 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1585 * int possible), but some parts of gdb treated it as a signed
1586 * number and failed comparisons. We could equally use 7fffffff,
1587 * but no functions are ever mapped to an address higher than
1590 prim_record_minimal_symbol ("<end_of_text>",
1591 (CORE_ADDR
) 0x40000000,
1595 element
= struct_list
;
1596 struct_list
= element
->next
;
1597 free ((PTR
) element
);
1602 /* Support for line number handling */
1603 static char *linetab
= NULL
;
1604 static long linetab_offset
;
1605 static unsigned long linetab_size
;
1607 /* Read in all the line numbers for fast lookups later. Leave them in
1608 external (unswapped) format in memory; we'll swap them as we enter
1609 them into GDB's data structures. */
1611 init_one_section (chan
, secinfo
)
1615 if (secinfo
->size
== 0
1616 || lseek (chan
, secinfo
->position
, 0) == -1
1617 || (secinfo
->buffer
= xmalloc (secinfo
->size
)) == NULL
1618 || myread (chan
, secinfo
->buffer
, secinfo
->size
) == -1)
1625 init_dst_sections (chan
)
1629 if (!init_one_section (chan
, &blocks_info
) ||
1630 !init_one_section (chan
, &lines_info
) ||
1631 !init_one_section (chan
, &symbols_info
))
1637 /* Fake up support for relocating symbol addresses. FIXME. */
1639 struct section_offsets dst_symfile_faker
=
1642 struct section_offsets
*
1643 dst_symfile_offsets (objfile
, addr
)
1644 struct objfile
*objfile
;
1647 objfile
->num_sections
= 1;
1648 return &dst_symfile_faker
;
1651 /* Register our ability to parse symbols for DST BFD files */
1653 static struct sym_fns dst_sym_fns
=
1655 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1656 a separate flavour like ecoff? */
1657 (enum bfd_flavour
) -2,
1659 dst_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1660 dst_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1661 dst_symfile_read
, /* sym_read: read a symbol file into symtab */
1662 dst_symfile_finish
, /* sym_finish: finished with file, cleanup */
1663 dst_symfile_offsets
, /* sym_offsets: xlate external to internal form */
1664 NULL
/* next: pointer to next struct sym_fns */
1668 _initialize_dstread ()
1670 add_symtab_fns (&dst_sym_fns
);