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"
31 #include "gdb_string.h"
35 CORE_ADDR cur_src_start_addr
, cur_src_end_addr
;
36 dst_sec blocks_info
, lines_info
, symbols_info
;
38 /* Vector of line number information. */
40 static struct linetable
*line_vector
;
42 /* Index of next entry to go in line_vector_index. */
44 static int line_vector_index
;
46 /* Last line number recorded in the line vector. */
48 static int prev_line_number
;
50 /* Number of elements allocated for line_vector currently. */
52 static int line_vector_length
;
54 static struct blockvector
*
55 make_blockvector
PARAMS ((struct objfile
*));
58 init_dst_sections
PARAMS ((int));
61 read_dst_symtab
PARAMS ((struct objfile
*));
64 find_dst_sections
PARAMS ((bfd
*, sec_ptr
, PTR
));
67 dst_symfile_init
PARAMS ((struct objfile
*));
70 dst_new_init
PARAMS ((struct objfile
*));
73 dst_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
76 dst_symfile_finish
PARAMS ((struct objfile
*));
79 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
83 dst_end_symtab
PARAMS ((struct objfile
*));
86 complete_symtab
PARAMS ((char *, CORE_ADDR
, unsigned int));
89 dst_start_symtab
PARAMS ((void));
92 dst_record_line
PARAMS ((int, CORE_ADDR
));
94 static struct blockvector
*
95 make_blockvector (objfile
)
96 struct objfile
*objfile
;
98 register struct pending_block
*next
, *next1
;
99 register struct blockvector
*blockvector
;
102 /* Count the length of the list of blocks. */
104 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
106 blockvector
= (struct blockvector
*)
107 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
109 /* Copy the blocks into the blockvector.
110 This is done in reverse order, which happens to put
111 the blocks into the proper order (ascending starting address).
114 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
115 for (next
= pending_blocks
; next
; next
= next
->next
)
116 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
118 /* Now free the links of the list, and empty the list. */
120 for (next
= pending_blocks
; next
; next
= next1
)
130 /* Manage the vector of line numbers. */
131 /* FIXME: Use record_line instead. */
134 dst_record_line (line
, pc
)
138 struct linetable_entry
*e
;
139 /* Make sure line vector is big enough. */
141 if (line_vector_index
+ 2 >= line_vector_length
)
143 line_vector_length
*= 2;
144 line_vector
= (struct linetable
*)
145 xrealloc ((char *) line_vector
, sizeof (struct linetable
)
146 + (line_vector_length
147 * sizeof (struct linetable_entry
)));
150 e
= line_vector
->item
+ line_vector_index
++;
151 e
->line
= line
; e
->pc
= pc
;
154 /* Start a new symtab for a new source file.
155 It indicates the start of data for one original source file. */
156 /* FIXME: use start_symtab, like coffread.c now does. */
161 /* Initialize the source file line number information for this file. */
163 if (line_vector
) /* Unlikely, but maybe possible? */
164 free ((PTR
)line_vector
);
165 line_vector_index
= 0;
166 line_vector_length
= 1000;
167 prev_line_number
= -2; /* Force first line number to be explicit */
168 line_vector
= (struct linetable
*)
169 xmalloc (sizeof (struct linetable
)
170 + line_vector_length
* sizeof (struct linetable_entry
));
173 /* Save the vital information from when starting to read a file,
174 for use when closing off the current file.
175 NAME is the file name the symbols came from, START_ADDR is the first
176 text address for the file, and SIZE is the number of bytes of text. */
179 complete_symtab (name
, start_addr
, size
)
181 CORE_ADDR start_addr
;
184 last_source_file
= savestring (name
, strlen (name
));
185 cur_src_start_addr
= start_addr
;
186 cur_src_end_addr
= start_addr
+ size
;
188 if (current_objfile
-> ei
.entry_point
>= cur_src_start_addr
&&
189 current_objfile
-> ei
.entry_point
< cur_src_end_addr
)
191 current_objfile
-> ei
.entry_file_lowpc
= cur_src_start_addr
;
192 current_objfile
-> ei
.entry_file_highpc
= cur_src_end_addr
;
196 /* Finish the symbol definitions for one main source file,
197 close off all the lexical contexts for that file
198 (creating struct block's for them), then make the
199 struct symtab for that file and put it in the list of all such. */
200 /* FIXME: Use end_symtab, like coffread.c now does. */
203 dst_end_symtab (objfile
)
204 struct objfile
*objfile
;
206 register struct symtab
*symtab
;
207 register struct blockvector
*blockvector
;
208 register struct linetable
*lv
;
210 /* Create the blockvector that points to all the file's blocks. */
212 blockvector
= make_blockvector (objfile
);
214 /* Now create the symtab object for this source file. */
215 symtab
= allocate_symtab (last_source_file
, objfile
);
217 /* Fill in its components. */
218 symtab
->blockvector
= blockvector
;
219 symtab
->free_code
= free_linetable
;
220 symtab
->free_ptr
= 0;
221 symtab
->filename
= last_source_file
;
222 symtab
->dirname
= NULL
;
224 lv
->nitems
= line_vector_index
;
225 symtab
->linetable
= (struct linetable
*)
226 xrealloc ((char *) lv
, (sizeof (struct linetable
)
227 + lv
->nitems
* sizeof (struct linetable_entry
)));
229 free_named_symtabs (symtab
->filename
);
231 /* Reinitialize for beginning of new file. */
233 line_vector_length
= -1;
234 last_source_file
= NULL
;
238 record_minimal_symbol (name
, address
, type
, objfile
)
241 enum minimal_symbol_type type
;
242 struct objfile
*objfile
;
244 prim_record_minimal_symbol (savestring (name
, strlen (name
)),
250 /* dst_symfile_init ()
251 is the dst-specific initialization routine for reading symbols.
253 We will only be called if this is a DST or DST-like file.
254 BFD handles figuring out the format of the file, and code in symtab.c
255 uses BFD's determination to vector to us.
257 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
260 dst_symfile_init (objfile
)
261 struct objfile
*objfile
;
264 bfd
*abfd
= objfile
->obfd
;
266 init_entry_point_info (objfile
);
270 /* This function is called for every section; it finds the outer limits
271 of the line table (minimum and maximum file offset) so that the
272 mainline code can read the whole thing for efficiency. */
276 find_dst_sections (abfd
, asect
, vpinfo
)
283 file_ptr offset
, maxoff
;
286 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
287 size
= asect
->_raw_size
;
288 offset
= asect
->filepos
;
293 if (!strcmp(asect
->name
, ".blocks"))
294 section
= &blocks_info
;
295 else if (!strcmp(asect
->name
, ".lines"))
296 section
= &lines_info
;
297 else if (!strcmp(asect
->name
, ".symbols"))
298 section
= &symbols_info
;
301 section
->size
= size
;
302 section
->position
= offset
;
303 section
->base
= base
;
307 /* The BFD for this file -- only good while we're actively reading
308 symbols into a psymtab or a symtab. */
310 static bfd
*symfile_bfd
;
312 /* Read a symbol file, after initialization by dst_symfile_init. */
313 /* FIXME! Addr and Mainline are not used yet -- this will not work for
314 shared libraries or add_file! */
318 dst_symfile_read (objfile
, section_offsets
, mainline
)
319 struct objfile
*objfile
;
320 struct section_offsets
*section_offsets
;
323 bfd
*abfd
= objfile
->obfd
;
324 char *name
= bfd_get_filename (abfd
);
329 int stringtab_offset
;
331 symfile_bfd
= abfd
; /* Kludge for swap routines */
333 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
334 desc
= fileno ((GDB_FILE
*)(abfd
->iostream
)); /* File descriptor */
336 /* Read the line number table, all at once. */
337 bfd_map_over_sections (abfd
, find_dst_sections
, (PTR
)NULL
);
339 val
= init_dst_sections (desc
);
341 error ("\"%s\": error reading debugging symbol tables\n", name
);
343 init_minimal_symbol_collection ();
344 make_cleanup (discard_minimal_symbols
, 0);
346 /* Now that the executable file is positioned at symbol table,
347 process it and define symbols accordingly. */
349 read_dst_symtab (objfile
);
351 /* Sort symbols alphabetically within each block. */
355 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
357 sort_symtab_syms (s
);
361 /* Install any minimal symbols that have been collected as the current
362 minimal symbols for this objfile. */
364 install_minimal_symbols (objfile
);
368 dst_new_init (ignore
)
369 struct objfile
*ignore
;
374 /* Perform any local cleanups required when we are done with a particular
375 objfile. I.E, we are in the process of discarding all symbol information
376 for an objfile, freeing up all memory held for it, and unlinking the
377 objfile struct from the global list of known objfiles. */
380 dst_symfile_finish (objfile
)
381 struct objfile
*objfile
;
387 /* Get the next line number from the DST. Returns 0 when we hit an
388 * end directive or cannot continue for any other reason.
390 * Note that ordinary pc deltas are multiplied by two. Apparently
391 * this is what was really intended.
394 get_dst_line(buffer
, pc
)
395 signed char **buffer
;
399 static long last_line
= 0;
400 static int last_file
= 0;
401 dst_ln_entry_ptr_t entry
;
403 dst_src_loc_t
*src_loc
;
410 entry
= (dst_ln_entry_ptr_t
) *buffer
;
412 while (dst_ln_ln_delta(*entry
) == dst_ln_escape_flag
)
414 switch(entry
->esc
.esc_code
)
417 size
= 1; /* pad byte */
420 /* file escape. Next 4 bytes are a dst_src_loc_t */
422 src_loc
= (dst_src_loc_t
*) (*buffer
+ 1);
423 last_line
= src_loc
->line_number
;
424 last_file
= src_loc
->file_index
;
426 case dst_ln_dln1_dpc1
:
427 /* 1 byte line delta, 1 byte pc delta */
428 last_line
+= (*buffer
)[1];
429 last_pc
+= 2 * (unsigned char) (*buffer
)[2];
430 dst_record_line(last_line
, last_pc
);
433 case dst_ln_dln2_dpc2
:
434 /* 2 bytes line delta, 2 bytes pc delta */
435 last_line
+= *(short *) (*buffer
+ 1);
436 last_pc
+= 2 * (*(short *) (*buffer
+ 3));
438 dst_record_line(last_line
, last_pc
);
441 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
442 last_line
= *(unsigned long *) (*buffer
+ 1);
443 last_pc
= *(unsigned long *) (*buffer
+ 5);
445 dst_record_line(last_line
, last_pc
);
447 case dst_ln_dln1_dpc0
:
448 /* 1 byte line delta, pc delta = 0 */
450 last_line
+= (*buffer
)[1];
452 case dst_ln_ln_off_1
:
453 /* statement escape, stmt # = 1 (2nd stmt on line) */
457 /* statement escape, stmt # = next byte */
461 /* entry escape, next byte is entry number */
468 case dst_ln_stmt_end
:
469 /* gap escape, 4 bytes pc delta */
471 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
472 /* Apparently this isn't supposed to actually modify
473 * the pc value. Totally weird.
476 case dst_ln_escape_11
:
477 case dst_ln_escape_12
:
478 case dst_ln_escape_13
:
481 case dst_ln_nxt_byte
:
482 /* This shouldn't happen. If it does, we're SOL */
486 /* end escape, final entry follows */
489 *buffer
+= (size
< 0) ? -size
: size
;
490 entry
= (dst_ln_entry_ptr_t
) *buffer
;
492 last_line
+= dst_ln_ln_delta(*entry
);
493 last_pc
+= entry
->delta
.pc_delta
* 2;
495 dst_record_line(last_line
, last_pc
);
500 enter_all_lines(buffer
, address
)
505 while (get_dst_line(&buffer
, &address
));
509 get_dst_entry(buffer
, ret_entry
)
511 dst_rec_ptr_t
*ret_entry
;
515 static int last_type
;
519 entry
= (dst_rec_ptr_t
) buffer
;
520 switch(entry
->rec_type
)
525 case dst_typ_comp_unit
:
526 size
= sizeof(DST_comp_unit(entry
));
528 case dst_typ_section_tab
:
529 size
= sizeof(DST_section_tab(entry
))
530 + ((int) DST_section_tab(entry
).number_of_sections
531 - dst_dummy_array_size
) * sizeof(long);
533 case dst_typ_file_tab
:
534 size
= sizeof(DST_file_tab(entry
))
535 + ((int) DST_file_tab(entry
).number_of_files
536 - dst_dummy_array_size
) * sizeof(dst_file_desc_t
);
539 size
= sizeof(DST_block(entry
))
540 + ((int) DST_block(entry
).n_of_code_ranges
541 - dst_dummy_array_size
) * sizeof(dst_code_range_t
);
547 size
= sizeof(DST_var(entry
)) -
548 sizeof(dst_var_loc_long_t
) * dst_dummy_array_size
+
549 DST_var(entry
).no_of_locs
*
550 ( DST_var(entry
).short_locs
?
551 sizeof(dst_var_loc_short_t
):
552 sizeof(dst_var_loc_long_t
));
554 case dst_typ_pointer
:
555 size
= sizeof(DST_pointer(entry
));
558 size
= sizeof(DST_array(entry
));
560 case dst_typ_subrange
:
561 size
= sizeof(DST_subrange(entry
));
564 size
= sizeof(DST_set(entry
));
566 case dst_typ_implicit_enum
:
567 size
= sizeof(DST_implicit_enum(entry
))
568 + ((int) DST_implicit_enum(entry
).nelems
569 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
571 case dst_typ_explicit_enum
:
572 size
= sizeof(DST_explicit_enum(entry
))
573 + ((int) DST_explicit_enum(entry
).nelems
574 - dst_dummy_array_size
) * sizeof(dst_enum_elem_t
);
576 case dst_typ_short_rec
:
577 size
= sizeof(DST_short_rec(entry
))
578 + DST_short_rec(entry
).nfields
* sizeof(dst_short_field_t
)
579 - dst_dummy_array_size
* sizeof(dst_field_t
);
581 case dst_typ_short_union
:
582 size
= sizeof(DST_short_union(entry
))
583 + DST_short_union(entry
).nfields
* sizeof(dst_short_field_t
)
584 - dst_dummy_array_size
* sizeof(dst_field_t
);
587 size
= sizeof(DST_file(entry
));
590 size
= sizeof(DST_offset(entry
));
593 size
= sizeof(DST_alias(entry
));
595 case dst_typ_signature
:
596 size
= sizeof(DST_signature(entry
)) +
597 ((int) DST_signature(entry
).nargs
-
598 dst_dummy_array_size
) * sizeof(dst_arg_t
);
603 case dst_typ_old_label
:
604 size
= sizeof(DST_old_label(entry
));
607 size
= sizeof(DST_scope(entry
));
609 case dst_typ_end_scope
:
616 case dst_typ_string_tab
:
617 case dst_typ_global_name_tab
:
618 size
= sizeof(DST_string_tab(entry
))
619 + DST_string_tab(entry
).length
620 - dst_dummy_array_size
;
622 case dst_typ_forward
:
623 size
= sizeof(DST_forward(entry
));
624 get_dst_entry((char *) entry
+ DST_forward(entry
).rec_off
, &entry
);
626 case dst_typ_aux_size
:
627 size
= sizeof(DST_aux_size(entry
));
629 case dst_typ_aux_align
:
630 size
= sizeof(DST_aux_align(entry
));
632 case dst_typ_aux_field_size
:
633 size
= sizeof(DST_aux_field_size(entry
));
635 case dst_typ_aux_field_off
:
636 size
= sizeof(DST_aux_field_off(entry
));
638 case dst_typ_aux_field_align
:
639 size
= sizeof(DST_aux_field_align(entry
));
641 case dst_typ_aux_qual
:
642 size
= sizeof(DST_aux_qual(entry
));
644 case dst_typ_aux_var_bound
:
645 size
= sizeof(DST_aux_var_bound(entry
));
647 case dst_typ_extension
:
648 size
= DST_extension(entry
).rec_size
;
651 size
= sizeof(DST_string(entry
));
653 case dst_typ_old_entry
:
654 size
= 48; /* Obsolete entry type */
657 size
= sizeof(DST_const(entry
))
658 + DST_const(entry
).value
.length
659 - sizeof(DST_const(entry
).value
.val
);
661 case dst_typ_reference
:
662 size
= sizeof(DST_reference(entry
));
664 case dst_typ_old_record
:
665 case dst_typ_old_union
:
668 size
= sizeof(DST_record(entry
))
669 + ((int) DST_record(entry
).nfields
670 - dst_dummy_array_size
) * sizeof(dst_field_t
);
672 case dst_typ_aux_type_deriv
:
673 size
= sizeof(DST_aux_type_deriv(entry
));
675 case dst_typ_locpool
:
676 size
= sizeof(DST_locpool(entry
))
677 + ((int) DST_locpool(entry
).length
-
678 dst_dummy_array_size
);
680 case dst_typ_variable
:
681 size
= sizeof(DST_variable(entry
));
684 size
= sizeof(DST_label(entry
));
687 size
= sizeof(DST_entry(entry
));
689 case dst_typ_aux_lifetime
:
690 size
= sizeof(DST_aux_lifetime(entry
));
692 case dst_typ_aux_ptr_base
:
693 size
= sizeof(DST_aux_ptr_base(entry
));
695 case dst_typ_aux_src_range
:
696 size
= sizeof(DST_aux_src_range(entry
));
698 case dst_typ_aux_reg_val
:
699 size
= sizeof(DST_aux_reg_val(entry
));
701 case dst_typ_aux_unit_names
:
702 size
= sizeof(DST_aux_unit_names(entry
))
703 + ((int) DST_aux_unit_names(entry
).number_of_names
704 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
706 case dst_typ_aux_sect_info
:
707 size
= sizeof(DST_aux_sect_info(entry
))
708 + ((int) DST_aux_sect_info(entry
).number_of_refs
709 - dst_dummy_array_size
) * sizeof(dst_sect_ref_t
);
717 fprintf_unfiltered(gdb_stderr
, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
718 (int) entry
->rec_type
,
720 fprintf_unfiltered(gdb_stderr
, "Last unknown_3 value: %d\n", lu3
);
724 last_type
= entry
->rec_type
;
725 if (size
& 1) /* Align on a word boundary */
732 static int next_dst_entry(buffer
, entry
, table
)
734 dst_rec_ptr_t
*entry
;
737 if (*buffer
- table
->buffer
>= table
->size
)
742 *buffer
+= get_dst_entry(*buffer
, entry
);
746 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
747 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
748 #define DST_OFFSET(a, b) ((char *) (a) + (b))
750 static dst_rec_ptr_t section_table
= NULL
;
756 dst_sec
*section
= NULL
;
759 if (!section_table
|| !ref
->sect_index
)
761 offset
= DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
763 if (offset
>= blocks_info
.base
&&
764 offset
< blocks_info
.base
+ blocks_info
.size
)
765 section
= &blocks_info
;
766 else if (offset
>= symbols_info
.base
&&
767 offset
< symbols_info
.base
+ symbols_info
.size
)
768 section
= &symbols_info
;
769 else if (offset
>= lines_info
.base
&&
770 offset
< lines_info
.base
+ lines_info
.size
)
771 section
= &lines_info
;
774 return section
->buffer
+ (offset
- section
->base
);
778 dst_get_addr(int section
, long offset
)
780 if (!section_table
|| !section
)
782 return DST_section_tab(section_table
).section_base
[section
-1] + offset
;
789 if (!section_table
|| !ref
->sect_index
)
791 return DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
796 create_new_type(objfile
)
797 struct objfile
*objfile
;
801 type
= (struct type
*)
802 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct type
));
803 memset(type
, 0, sizeof(struct type
));
807 static struct symbol
*
808 create_new_symbol(objfile
, name
)
809 struct objfile
*objfile
;
812 struct symbol
*sym
= (struct symbol
*)
813 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
814 memset (sym
, 0, sizeof (struct symbol
));
815 SYMBOL_NAME (sym
) = obstack_copy0 (&objfile
->symbol_obstack
,
816 name
, strlen (name
));
817 SYMBOL_VALUE (sym
) = 0;
818 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
820 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
825 decode_dst_type
PARAMS ((struct objfile
*, dst_rec_ptr_t
));
828 decode_type_desc(objfile
, type_desc
, base
)
829 struct objfile
*objfile
;
830 dst_type_t
*type_desc
;
835 if (type_desc
->std_type
.user_defined_type
)
837 entry
= (dst_rec_ptr_t
) DST_OFFSET(base
,
838 dst_user_type_offset(*type_desc
));
839 type
= decode_dst_type(objfile
, entry
);
843 switch(type_desc
->std_type
.dtc
)
846 type
= builtin_type_signed_char
;
849 type
= builtin_type_short
;
852 type
= builtin_type_long
;
855 type
= builtin_type_unsigned_char
;
857 case dst_uint16_type
:
858 type
= builtin_type_unsigned_short
;
860 case dst_uint32_type
:
861 type
= builtin_type_unsigned_long
;
863 case dst_real32_type
:
864 type
= builtin_type_float
;
866 case dst_real64_type
:
867 type
= builtin_type_double
;
869 case dst_complex_type
:
870 type
= builtin_type_complex
;
872 case dst_dcomplex_type
:
873 type
= builtin_type_double_complex
;
876 type
= builtin_type_char
;
878 case dst_bool16_type
:
879 type
= builtin_type_short
;
881 case dst_bool32_type
:
882 type
= builtin_type_long
;
885 type
= builtin_type_char
;
887 /* The next few are more complex. I will take care
888 * of them properly at a later point.
890 case dst_string_type
:
891 type
= builtin_type_void
;
894 type
= builtin_type_void
;
897 type
= builtin_type_void
;
900 type
= builtin_type_void
;
903 type
= builtin_type_void
;
905 /* Back tto some ordinary ones */
907 type
= builtin_type_void
;
910 type
= builtin_type_unsigned_char
;
913 type
= builtin_type_void
;
920 struct structure_list
922 struct structure_list
*next
;
926 static struct structure_list
*struct_list
= NULL
;
929 find_dst_structure(name
)
932 struct structure_list
*element
;
934 for (element
= struct_list
; element
; element
= element
->next
)
935 if (!strcmp(name
, TYPE_NAME(element
->type
)))
936 return element
->type
;
942 decode_dst_structure(objfile
, entry
, code
, version
)
943 struct objfile
*objfile
;
948 struct type
*type
, *child_type
;
950 char *name
, *field_name
;
952 int fieldoffset
, fieldsize
;
953 dst_type_t type_desc
;
954 struct structure_list
*element
;
956 struct_name
= DST_OFFSET(entry
, DST_record(entry
).noffset
);
957 name
= concat( (code
== TYPE_CODE_UNION
)?"union ":"struct ",
959 type
= find_dst_structure(name
);
965 type
= create_new_type(objfile
);
966 TYPE_NAME(type
) = obstack_copy0 (&objfile
->symbol_obstack
,
969 TYPE_CODE(type
) = code
;
970 TYPE_LENGTH(type
) = DST_record(entry
).size
;
971 TYPE_NFIELDS(type
) = DST_record(entry
).nfields
;
972 TYPE_FIELDS(type
) = (struct field
*)
973 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) *
974 DST_record(entry
).nfields
);
975 fieldoffset
= fieldsize
= 0;
976 INIT_CPLUS_SPECIFIC(type
);
977 element
= (struct structure_list
*)
978 xmalloc(sizeof(struct structure_list
));
979 element
->type
= type
;
980 element
->next
= struct_list
;
981 struct_list
= element
;
982 for (i
= 0; i
< DST_record(entry
).nfields
; i
++)
987 field_name
= DST_OFFSET(entry
,
988 DST_record(entry
).f
.ofields
[i
].noffset
);
989 fieldoffset
= DST_record(entry
).f
.ofields
[i
].foffset
*8 +
990 DST_record(entry
).f
.ofields
[i
].bit_offset
;
991 fieldsize
= DST_record(entry
).f
.ofields
[i
].size
;
992 type_desc
= DST_record(entry
).f
.ofields
[i
].type_desc
;
995 field_name
= DST_OFFSET(entry
,
996 DST_record(entry
).f
.fields
[i
].noffset
);
997 type_desc
= DST_record(entry
).f
.fields
[i
].type_desc
;
998 switch(DST_record(entry
).f
.fields
[i
].f
.field_loc
.format_tag
)
1000 case dst_field_byte
:
1001 fieldoffset
= DST_record(entry
).f
.
1002 fields
[i
].f
.field_byte
.offset
* 8;
1006 fieldoffset
= DST_record(entry
).f
.
1007 fields
[i
].f
.field_bit
.byte_offset
* 8 +
1008 DST_record(entry
).f
.
1009 fields
[i
].f
.field_bit
.bit_offset
;
1010 fieldsize
= DST_record(entry
).f
.
1011 fields
[i
].f
.field_bit
.nbits
;
1014 fieldoffset
+= fieldsize
;
1020 field_name
= DST_OFFSET(entry
,
1021 DST_record(entry
).f
.sfields
[i
].noffset
);
1022 fieldoffset
= DST_record(entry
).f
.sfields
[i
].foffset
;
1023 type_desc
= DST_record(entry
).f
.sfields
[i
].type_desc
;
1024 if (i
< DST_record(entry
).nfields
- 1)
1025 fieldsize
= DST_record(entry
).f
.sfields
[i
+1].foffset
;
1027 fieldsize
= DST_record(entry
).size
;
1028 fieldsize
-= fieldoffset
;
1032 TYPE_FIELDS(type
)[i
].name
=
1033 obstack_copy0 (&objfile
->symbol_obstack
,
1034 field_name
, strlen(field_name
));
1035 TYPE_FIELDS(type
)[i
].type
= decode_type_desc(objfile
,
1038 if (fieldsize
== -1)
1039 fieldsize
= TYPE_LENGTH(TYPE_FIELDS(type
)[i
].type
) *
1041 TYPE_FIELDS(type
)[i
].bitsize
= fieldsize
;
1042 TYPE_FIELDS(type
)[i
].bitpos
= fieldoffset
;
1047 static struct type
*
1048 decode_dst_type(objfile
, entry
)
1049 struct objfile
*objfile
;
1050 dst_rec_ptr_t entry
;
1052 struct type
*child_type
, *type
, *range_type
, *index_type
;
1054 switch(entry
->rec_type
)
1057 return decode_type_desc(objfile
,
1058 &DST_var(entry
).type_desc
,
1061 case dst_typ_variable
:
1062 return decode_type_desc(objfile
,
1063 &DST_variable(entry
).type_desc
,
1066 case dst_typ_short_rec
:
1067 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,0);
1068 case dst_typ_short_union
:
1069 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 0);
1071 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 1);
1072 case dst_typ_record
:
1073 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,1);
1074 case dst_typ_old_union
:
1075 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 2);
1076 case dst_typ_old_record
:
1077 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,2);
1078 case dst_typ_pointer
:
1079 return make_pointer_type(
1080 decode_type_desc(objfile
,
1081 &DST_pointer(entry
).type_desc
,
1085 child_type
= decode_type_desc(objfile
,
1086 &DST_pointer(entry
).type_desc
,
1088 index_type
= lookup_fundamental_type(objfile
,
1090 range_type
= create_range_type ((struct type
*) NULL
,
1091 index_type
, DST_array(entry
).lo_bound
,
1092 DST_array(entry
).hi_bound
);
1093 return create_array_type ((struct type
*) NULL
, child_type
,
1096 return decode_type_desc(objfile
,
1097 &DST_alias(entry
).type_desc
,
1100 return builtin_type_int
;
1104 struct symbol_list
{
1105 struct symbol_list
*next
;
1106 struct symbol
*symbol
;
1109 static struct symbol_list
*dst_global_symbols
= NULL
;
1110 static int total_globals
= 0;
1113 decode_dst_locstring(locstr
, sym
)
1117 dst_loc_entry_t
*entry
, *next_entry
;
1125 fprintf_unfiltered(gdb_stderr
, "Error reading locstring\n");
1128 entry
= (dst_loc_entry_t
*) locstr
;
1129 next_entry
= (dst_loc_entry_t
*) (locstr
+ 1);
1130 switch (entry
->header
.code
)
1132 case dst_lsc_end
: /* End of string */
1134 case dst_lsc_indirect
:/* Indirect through previous. Arg == 6 */
1135 /* Or register ax x == arg */
1136 if (entry
->header
.arg
< 6)
1138 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1139 SYMBOL_VALUE(sym
) = entry
->header
.arg
+ 8;
1141 /* We predict indirects */
1145 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1146 SYMBOL_VALUE(sym
) = entry
->header
.arg
;
1149 case dst_lsc_section
:/* Section (arg+1) */
1150 SYMBOL_VALUE(sym
) = dst_get_addr(entry
->header
.arg
+1, 0);
1153 case dst_lsc_sec_byte
: /* Section (next_byte+1) */
1154 SYMBOL_VALUE(sym
) = dst_get_addr(locstr
[1]+1, 0);
1157 case dst_lsc_add
: /* Add (arg+1)*2 */
1158 case dst_lsc_sub
: /* Subtract (arg+1)*2 */
1159 temp
= (entry
->header
.arg
+ 1) * 2;
1161 if (*locstr
== dst_multiply_256
)
1166 switch(entry
->header
.code
)
1169 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1170 SYMBOL_CLASS(sym
) = LOC_ARG
;
1171 SYMBOL_VALUE(sym
) += temp
;
1174 SYMBOL_VALUE(sym
) -= temp
;
1178 case dst_lsc_add_byte
:
1179 case dst_lsc_sub_byte
:
1180 switch (entry
->header
.arg
& 0x03)
1183 temp
= (unsigned char) locstr
[1];
1187 temp
= * (unsigned short *) (locstr
+ 1);
1191 temp
= * (unsigned long *) (locstr
+ 1);
1195 if (*locstr
== dst_multiply_256
)
1200 switch(entry
->header
.code
)
1202 case dst_lsc_add_byte
:
1203 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1204 SYMBOL_CLASS(sym
) = LOC_ARG
;
1205 SYMBOL_VALUE(sym
) += temp
;
1207 case dst_lsc_sub_byte
:
1208 SYMBOL_VALUE(sym
) -= temp
;
1212 case dst_lsc_sbreg
: /* Stack base register (frame pointer). Arg==0*/
1213 if (next_entry
->header
.code
!= dst_lsc_indirect
)
1215 SYMBOL_VALUE(sym
) = 0;
1216 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1219 SYMBOL_VALUE(sym
) = 0;
1220 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1224 SYMBOL_VALUE(sym
) = 0;
1225 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1231 static struct symbol_list
*
1232 process_dst_symbols(objfile
, entry
, name
, nsyms_ret
)
1233 struct objfile
*objfile
;
1234 dst_rec_ptr_t entry
;
1238 struct symbol_list
*list
= NULL
, *element
;
1246 dst_var_attr_t attr
;
1247 dst_var_loc_t loc_type
;
1256 location
= (char *) entry
;
1257 while (NEXT_SYM(&location
, &entry
) &&
1258 entry
->rec_type
!= dst_typ_end_scope
)
1260 if (entry
->rec_type
== dst_typ_var
)
1262 if (DST_var(entry
).short_locs
)
1264 loc_type
= DST_var(entry
).locs
.shorts
[0].loc_type
;
1265 loc_index
= DST_var(entry
).locs
.shorts
[0].loc_index
;
1266 loc_value
= DST_var(entry
).locs
.shorts
[0].location
;
1270 loc_type
= DST_var(entry
).locs
.longs
[0].loc_type
;
1271 loc_index
= DST_var(entry
).locs
.longs
[0].loc_index
;
1272 loc_value
= DST_var(entry
).locs
.longs
[0].location
;
1274 if (loc_type
== dst_var_loc_external
)
1276 symname
= DST_OFFSET(entry
, DST_var(entry
).noffset
);
1277 line
= DST_var(entry
).src_loc
.line_number
;
1278 symtype
= DST_var(entry
).type_desc
;
1279 attr
= DST_var(entry
).attributes
;
1281 else if (entry
->rec_type
== dst_typ_variable
)
1283 symname
= DST_OFFSET(entry
,
1284 DST_variable(entry
).noffset
);
1285 line
= DST_variable(entry
).src_loc
.line_number
;
1286 symtype
= DST_variable(entry
).type_desc
;
1287 attr
= DST_variable(entry
).attributes
;
1293 if (symname
&& name
&& !strcmp(symname
, name
))
1294 /* It's the function return value */
1296 sym
= create_new_symbol(objfile
, symname
);
1298 if ((attr
& (1<<dst_var_attr_global
)) ||
1299 (attr
& (1<<dst_var_attr_static
)))
1300 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1302 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1303 SYMBOL_LINE(sym
) = line
;
1304 SYMBOL_TYPE(sym
) = decode_type_desc(objfile
, &symtype
,
1306 SYMBOL_VALUE(sym
) = 0;
1307 switch (entry
->rec_type
)
1312 case dst_var_loc_abs
:
1313 SYMBOL_VALUE_ADDRESS(sym
) = loc_value
;
1315 case dst_var_loc_sect_off
:
1316 case dst_var_loc_ind_sect_off
: /* What is this? */
1317 SYMBOL_VALUE_ADDRESS(sym
) = dst_get_addr(
1321 case dst_var_loc_ind_reg_rel
: /* What is this? */
1322 case dst_var_loc_reg_rel
:
1323 /* If it isn't fp relative, specify the
1324 * register it's relative to.
1328 sym
->aux_value
.basereg
= loc_index
;
1330 SYMBOL_VALUE(sym
) = loc_value
;
1331 if (loc_value
> 0 &&
1332 SYMBOL_CLASS(sym
) == LOC_BASEREG
)
1333 SYMBOL_CLASS(sym
) = LOC_BASEREG_ARG
;
1335 case dst_var_loc_reg
:
1336 SYMBOL_VALUE(sym
) = loc_index
;
1337 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1341 case dst_typ_variable
:
1342 /* External variable..... don't try to interpret
1343 * its nonexistant locstring.
1345 if (DST_variable(entry
).loffset
== -1)
1347 decode_dst_locstring(DST_OFFSET(entry
,
1348 DST_variable(entry
).loffset
),
1351 element
= (struct symbol_list
*)
1352 xmalloc(sizeof(struct symbol_list
));
1354 if (attr
& (1<<dst_var_attr_global
))
1356 element
->next
= dst_global_symbols
;
1357 dst_global_symbols
= element
;
1362 element
->next
= list
;
1366 element
->symbol
= sym
;
1373 static struct symbol
*
1374 process_dst_function(objfile
, entry
, name
, address
)
1375 struct objfile
*objfile
;
1376 dst_rec_ptr_t entry
;
1381 struct type
*type
, *ftype
;
1382 dst_rec_ptr_t sym_entry
, typ_entry
;
1384 struct symbol_list
*element
;
1386 type
= builtin_type_int
;
1387 sym
= create_new_symbol(objfile
, name
);
1388 SYMBOL_CLASS(sym
) = LOC_BLOCK
;
1392 location
= (char *) entry
;
1395 NEXT_SYM(&location
, &sym_entry
);
1396 } while (sym_entry
&& sym_entry
->rec_type
!= dst_typ_signature
);
1401 DST_signature(sym_entry
).src_loc
.line_number
;
1402 if (DST_signature(sym_entry
).result
)
1404 typ_entry
= (dst_rec_ptr_t
)
1405 DST_OFFSET(sym_entry
,
1406 DST_signature(sym_entry
).result
);
1407 type
= decode_dst_type(objfile
, typ_entry
);
1412 if (!type
->function_type
)
1414 ftype
= create_new_type(objfile
);
1415 type
->function_type
= ftype
;
1416 ftype
->target_type
= type
;
1417 ftype
->code
= TYPE_CODE_FUNC
;
1419 SYMBOL_TYPE(sym
) = type
->function_type
;
1421 /* Now add ourselves to the global symbols list */
1422 element
= (struct symbol_list
*)
1423 xmalloc(sizeof(struct symbol_list
));
1425 element
->next
= dst_global_symbols
;
1426 dst_global_symbols
= element
;
1428 element
->symbol
= sym
;
1433 static struct block
*
1434 process_dst_block(objfile
, entry
)
1435 struct objfile
*objfile
;
1436 dst_rec_ptr_t entry
;
1438 struct block
*block
;
1439 struct symbol
*function
= NULL
;
1443 dst_rec_ptr_t child_entry
, symbol_entry
;
1444 struct block
*child_block
;
1445 int total_symbols
= 0;
1446 struct pending_block
*pblock
;
1448 static long fake_seq
= 0;
1449 struct symbol_list
*symlist
, *nextsym
;
1452 if (DST_block(entry
).noffset
)
1453 name
= DST_OFFSET(entry
, DST_block(entry
).noffset
);
1456 if (DST_block(entry
).n_of_code_ranges
)
1458 address
= dst_sym_addr(
1459 &DST_block(entry
).code_ranges
[0].code_start
);
1460 size
= DST_block(entry
).code_ranges
[0].code_size
;
1467 symbol_entry
= (dst_rec_ptr_t
) get_sec_ref(&DST_block(entry
).symbols_start
);
1468 switch(DST_block(entry
).block_type
)
1470 /* These are all really functions. Even the "program" type.
1471 * This is because the Apollo OS was written in Pascal, and
1472 * in Pascal, the main procedure is described as the Program.
1475 case dst_block_procedure
:
1476 case dst_block_function
:
1477 case dst_block_subroutine
:
1478 case dst_block_program
:
1479 record_minimal_symbol(name
, address
, mst_text
, objfile
);
1480 function
= process_dst_function(
1485 enter_all_lines(get_sec_ref(&DST_block(entry
).code_ranges
[0].lines_start
), address
);
1487 case dst_block_block_data
:
1491 /* GDB has to call it something, and the module name
1494 sprintf(fake_name
, "block_%08lx", fake_seq
++);
1495 function
= process_dst_function(
1496 objfile
, NULL
, fake_name
, address
);
1499 symlist
= process_dst_symbols(objfile
, symbol_entry
,
1500 name
, &total_symbols
);
1501 block
= (struct block
*)
1502 obstack_alloc (&objfile
->symbol_obstack
,
1503 sizeof (struct block
) +
1504 (total_symbols
- 1) * sizeof (struct symbol
*));
1509 nextsym
= symlist
->next
;
1511 block
->sym
[symnum
] = symlist
->symbol
;
1513 free((PTR
) symlist
);
1517 BLOCK_NSYMS (block
) = total_symbols
;
1518 BLOCK_START (block
) = address
;
1519 BLOCK_END (block
) = address
+ size
;
1520 BLOCK_SUPERBLOCK (block
) = 0;
1523 SYMBOL_BLOCK_VALUE (function
) = block
;
1524 BLOCK_FUNCTION (block
) = function
;
1527 BLOCK_FUNCTION (block
) = 0;
1529 pblock
= (struct pending_block
*)
1530 xmalloc (sizeof (struct pending_block
));
1531 pblock
->block
= block
;
1532 pblock
->next
= pending_blocks
;
1533 pending_blocks
= pblock
;
1534 if (DST_block(entry
).child_block_off
)
1536 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1537 DST_block(entry
).child_block_off
);
1540 child_block
= process_dst_block(objfile
, child_entry
);
1543 if (BLOCK_START(child_block
) <
1544 BLOCK_START(block
) ||
1545 BLOCK_START(block
) == -1)
1546 BLOCK_START(block
) =
1547 BLOCK_START(child_block
);
1548 if (BLOCK_END(child_block
) >
1550 BLOCK_END(block
) == -1)
1552 BLOCK_END(child_block
);
1553 BLOCK_SUPERBLOCK (child_block
) = block
;
1555 if (DST_block(child_entry
).sibling_block_off
)
1556 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(
1558 DST_block(child_entry
).sibling_block_off
);
1568 read_dst_symtab (objfile
)
1569 struct objfile
*objfile
;
1572 dst_rec_ptr_t entry
, file_table
, root_block
;
1574 struct block
*block
, *global_block
;
1575 struct pending_block
*pblock
;
1577 struct symbol_list
*nextsym
;
1579 struct structure_list
*element
;
1581 current_objfile
= objfile
;
1582 buffer
= blocks_info
.buffer
;
1583 while (NEXT_BLK(&buffer
, &entry
))
1585 if (entry
->rec_type
== dst_typ_comp_unit
)
1587 file_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1588 DST_comp_unit(entry
).file_table
);
1589 section_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1590 DST_comp_unit(entry
).section_table
);
1591 root_block
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1592 DST_comp_unit(entry
).root_block_offset
);
1593 source_file
= DST_OFFSET(file_table
,
1594 DST_file_tab(file_table
).files
[0].noffset
);
1595 /* Point buffer to the start of the next comp_unit */
1596 buffer
= DST_OFFSET(entry
,
1597 DST_comp_unit(entry
).data_size
);
1600 pblock
= (struct pending_block
*)
1601 xmalloc (sizeof (struct pending_block
));
1602 pblock
->next
= NULL
;
1603 pending_blocks
= pblock
;
1605 block
= process_dst_block(objfile
, root_block
);
1607 global_block
= (struct block
*)
1608 obstack_alloc (&objfile
->symbol_obstack
,
1609 sizeof (struct block
) +
1610 (total_globals
- 1) *
1611 sizeof (struct symbol
*));
1612 BLOCK_NSYMS(global_block
) = total_globals
;
1613 for (symnum
= 0; symnum
< total_globals
; symnum
++)
1615 nextsym
= dst_global_symbols
->next
;
1617 global_block
->sym
[symnum
] =
1618 dst_global_symbols
->symbol
;
1620 free((PTR
) dst_global_symbols
);
1621 dst_global_symbols
= nextsym
;
1623 dst_global_symbols
= NULL
;
1625 BLOCK_FUNCTION(global_block
) = 0;
1626 BLOCK_START(global_block
) = BLOCK_START(block
);
1627 BLOCK_END(global_block
) = BLOCK_END(block
);
1628 BLOCK_SUPERBLOCK(global_block
) = 0;
1629 BLOCK_SUPERBLOCK(block
) = global_block
;
1630 pblock
->block
= global_block
;
1632 complete_symtab(source_file
,
1634 BLOCK_END(block
) - BLOCK_START(block
));
1636 dst_end_symtab(objfile
);
1640 record_minimal_symbol("<end_of_program>",
1641 BLOCK_END(block
), mst_text
, objfile
);
1642 /* One more faked symbol to make sure nothing can ever run off the
1643 * end of the symbol table. This one represents the end of the
1644 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1645 * int possible), but some parts of gdb treated it as a signed
1646 * number and failed comparisons. We could equally use 7fffffff,
1647 * but no functions are ever mapped to an address higher than
1650 record_minimal_symbol("<end_of_text>",
1651 (CORE_ADDR
) 0x40000000,
1655 element
= struct_list
;
1656 struct_list
= element
->next
;
1657 free((PTR
) element
);
1662 /* Support for line number handling */
1663 static char *linetab
= NULL
;
1664 static long linetab_offset
;
1665 static unsigned long linetab_size
;
1667 /* Read in all the line numbers for fast lookups later. Leave them in
1668 external (unswapped) format in memory; we'll swap them as we enter
1669 them into GDB's data structures. */
1671 init_one_section(chan
, secinfo
)
1675 if (secinfo
->size
== 0
1676 || lseek(chan
, secinfo
->position
, 0) == -1
1677 || (secinfo
->buffer
= xmalloc(secinfo
->size
)) == NULL
1678 || myread(chan
, secinfo
->buffer
, secinfo
->size
) == -1)
1685 init_dst_sections (chan
)
1689 if (!init_one_section(chan
, &blocks_info
) ||
1690 !init_one_section(chan
, &lines_info
) ||
1691 !init_one_section(chan
, &symbols_info
))
1697 /* Fake up support for relocating symbol addresses. FIXME. */
1699 struct section_offsets dst_symfile_faker
= {0};
1701 struct section_offsets
*
1702 dst_symfile_offsets (objfile
, addr
)
1703 struct objfile
*objfile
;
1706 objfile
->num_sections
= 1;
1707 return &dst_symfile_faker
;
1710 /* Register our ability to parse symbols for DST BFD files */
1712 static struct sym_fns dst_sym_fns
=
1714 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1715 a separate flavour like ecoff? */
1716 (enum bfd_flavour
)-2,
1718 dst_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1719 dst_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1720 dst_symfile_read
, /* sym_read: read a symbol file into symtab */
1721 dst_symfile_finish
, /* sym_finish: finished with file, cleanup */
1722 dst_symfile_offsets
, /* sym_offsets: xlate external to internal form */
1723 NULL
/* next: pointer to next struct sym_fns */
1727 _initialize_dstread ()
1729 add_symtab_fns(&dst_sym_fns
);