1 /* Read apollo DST symbol tables and convert to internal format, for GDB.
2 Contributed by Troy Rollo, University of NSW (troy@cbme.unsw.edu.au).
3 Copyright 1993 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "breakpoint.h"
35 CORE_ADDR cur_src_start_addr
, cur_src_end_addr
;
36 dst_sec blocks_info
, lines_info
, symbols_info
;
38 /* Vector of line number information. */
40 static struct linetable
*line_vector
;
42 /* Index of next entry to go in line_vector_index. */
44 static int line_vector_index
;
46 /* Last line number recorded in the line vector. */
48 static int prev_line_number
;
50 /* Number of elements allocated for line_vector currently. */
52 static int line_vector_length
;
54 struct pending_block
*pending_blocks
;
56 static struct blockvector
*
57 make_blockvector
PARAMS ((struct objfile
*));
60 init_dst_sections
PARAMS ((int));
63 read_dst_symtab
PARAMS ((struct objfile
*));
66 find_dst_sections
PARAMS ((bfd
*, sec_ptr
, PTR
));
69 dst_symfile_init
PARAMS ((struct objfile
*));
72 dst_new_init
PARAMS ((struct objfile
*));
75 dst_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
78 dst_symfile_finish
PARAMS ((struct objfile
*));
81 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
));
84 dst_end_symtab
PARAMS ((struct objfile
*));
87 complete_symtab
PARAMS ((char *, CORE_ADDR
, unsigned int));
90 dst_start_symtab
PARAMS ((void));
93 dst_record_line
PARAMS ((int, CORE_ADDR
));
95 static struct blockvector
*
96 make_blockvector (objfile
)
97 struct objfile
*objfile
;
99 register struct pending_block
*next
, *next1
;
100 register struct blockvector
*blockvector
;
103 /* Count the length of the list of blocks. */
105 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
107 blockvector
= (struct blockvector
*)
108 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
110 /* Copy the blocks into the blockvector.
111 This is done in reverse order, which happens to put
112 the blocks into the proper order (ascending starting address).
115 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
116 for (next
= pending_blocks
; next
; next
= next
->next
)
117 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
119 /* Now free the links of the list, and empty the list. */
121 for (next
= pending_blocks
; next
; next
= next1
)
131 /* Manage the vector of line numbers. */
132 /* FIXME: Use record_line instead. */
135 dst_record_line (line
, pc
)
139 struct linetable_entry
*e
;
140 /* Make sure line vector is big enough. */
142 if (line_vector_index
+ 2 >= line_vector_length
)
144 line_vector_length
*= 2;
145 line_vector
= (struct linetable
*)
146 xrealloc ((char *) line_vector
, sizeof (struct linetable
)
147 + (line_vector_length
148 * sizeof (struct linetable_entry
)));
151 e
= line_vector
->item
+ line_vector_index
++;
152 e
->line
= line
; e
->pc
= pc
;
155 /* Start a new symtab for a new source file.
156 It indicates the start of data for one original source file. */
157 /* FIXME: use start_symtab, like coffread.c now does. */
162 /* Initialize the source file line number information for this file. */
164 if (line_vector
) /* Unlikely, but maybe possible? */
165 free ((PTR
)line_vector
);
166 line_vector_index
= 0;
167 line_vector_length
= 1000;
168 prev_line_number
= -2; /* Force first line number to be explicit */
169 line_vector
= (struct linetable
*)
170 xmalloc (sizeof (struct linetable
)
171 + line_vector_length
* sizeof (struct linetable_entry
));
174 /* Save the vital information from when starting to read a file,
175 for use when closing off the current file.
176 NAME is the file name the symbols came from, START_ADDR is the first
177 text address for the file, and SIZE is the number of bytes of text. */
180 complete_symtab (name
, start_addr
, size
)
182 CORE_ADDR start_addr
;
185 last_source_file
= savestring (name
, strlen (name
));
186 cur_src_start_addr
= start_addr
;
187 cur_src_end_addr
= start_addr
+ size
;
189 if (current_objfile
-> ei
.entry_point
>= cur_src_start_addr
&&
190 current_objfile
-> ei
.entry_point
< cur_src_end_addr
)
192 current_objfile
-> ei
.entry_file_lowpc
= cur_src_start_addr
;
193 current_objfile
-> ei
.entry_file_highpc
= cur_src_end_addr
;
197 /* Finish the symbol definitions for one main source file,
198 close off all the lexical contexts for that file
199 (creating struct block's for them), then make the
200 struct symtab for that file and put it in the list of all such. */
201 /* FIXME: Use end_symtab, like coffread.c now does. */
204 dst_end_symtab (objfile
)
205 struct objfile
*objfile
;
207 register struct symtab
*symtab
;
208 register struct blockvector
*blockvector
;
209 register struct linetable
*lv
;
211 /* Create the blockvector that points to all the file's blocks. */
213 blockvector
= make_blockvector (objfile
);
215 /* Now create the symtab object for this source file. */
216 symtab
= allocate_symtab (last_source_file
, objfile
);
218 /* Fill in its components. */
219 symtab
->blockvector
= blockvector
;
220 symtab
->free_code
= free_linetable
;
221 symtab
->free_ptr
= 0;
222 symtab
->filename
= last_source_file
;
223 symtab
->dirname
= NULL
;
225 lv
->nitems
= line_vector_index
;
226 symtab
->linetable
= (struct linetable
*)
227 xrealloc ((char *) lv
, (sizeof (struct linetable
)
228 + lv
->nitems
* sizeof (struct linetable_entry
)));
230 free_named_symtabs (symtab
->filename
);
232 /* Reinitialize for beginning of new file. */
234 line_vector_length
= -1;
235 last_source_file
= NULL
;
239 record_minimal_symbol (name
, address
, type
)
242 enum minimal_symbol_type type
;
244 prim_record_minimal_symbol (savestring (name
, strlen (name
)),
249 /* dst_symfile_init ()
250 is the dst-specific initialization routine for reading symbols.
252 We will only be called if this is a DST or DST-like file.
253 BFD handles figuring out the format of the file, and code in symtab.c
254 uses BFD's determination to vector to us.
256 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
259 dst_symfile_init (objfile
)
260 struct objfile
*objfile
;
263 bfd
*abfd
= objfile
->obfd
;
265 init_entry_point_info (objfile
);
269 /* This function is called for every section; it finds the outer limits
270 of the line table (minimum and maximum file offset) so that the
271 mainline code can read the whole thing for efficiency. */
275 find_dst_sections (abfd
, asect
, vpinfo
)
282 file_ptr offset
, maxoff
;
285 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
286 size
= asect
->_raw_size
;
287 offset
= asect
->filepos
;
292 if (!strcmp(asect
->name
, ".blocks"))
293 section
= &blocks_info
;
294 else if (!strcmp(asect
->name
, ".lines"))
295 section
= &lines_info
;
296 else if (!strcmp(asect
->name
, ".symbols"))
297 section
= &symbols_info
;
300 section
->size
= size
;
301 section
->position
= offset
;
302 section
->base
= base
;
306 /* The BFD for this file -- only good while we're actively reading
307 symbols into a psymtab or a symtab. */
309 static bfd
*symfile_bfd
;
311 /* Read a symbol file, after initialization by dst_symfile_init. */
312 /* FIXME! Addr and Mainline are not used yet -- this will not work for
313 shared libraries or add_file! */
317 dst_symfile_read (objfile
, section_offsets
, mainline
)
318 struct objfile
*objfile
;
319 struct section_offsets
*section_offsets
;
322 bfd
*abfd
= objfile
->obfd
;
323 char *name
= bfd_get_filename (abfd
);
328 int stringtab_offset
;
330 symfile_bfd
= abfd
; /* Kludge for swap routines */
332 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
333 desc
= fileno ((GDB_FILE
*)(abfd
->iostream
)); /* File descriptor */
335 /* Read the line number table, all at once. */
336 bfd_map_over_sections (abfd
, find_dst_sections
, (PTR
)NULL
);
338 val
= init_dst_sections (desc
);
340 error ("\"%s\": error reading debugging symbol tables\n", name
);
342 init_minimal_symbol_collection ();
343 make_cleanup (discard_minimal_symbols
, 0);
345 /* Now that the executable file is positioned at symbol table,
346 process it and define symbols accordingly. */
348 read_dst_symtab (objfile
);
350 /* Sort symbols alphabetically within each block. */
354 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
356 sort_symtab_syms (s
);
360 /* Install any minimal symbols that have been collected as the current
361 minimal symbols for this objfile. */
363 install_minimal_symbols (objfile
);
367 dst_new_init (ignore
)
368 struct objfile
*ignore
;
373 /* Perform any local cleanups required when we are done with a particular
374 objfile. I.E, we are in the process of discarding all symbol information
375 for an objfile, freeing up all memory held for it, and unlinking the
376 objfile struct from the global list of known objfiles. */
379 dst_symfile_finish (objfile
)
380 struct objfile
*objfile
;
386 /* Get the next line number from the DST. Returns 0 when we hit an
387 * end directive or cannot continue for any other reason.
389 * Note that ordinary pc deltas are multiplied by two. Apparently
390 * this is what was really intended.
393 get_dst_line(buffer
, pc
)
394 signed char **buffer
;
398 static long last_line
= 0;
399 static int last_file
= 0;
400 dst_ln_entry_ptr_t entry
;
402 dst_src_loc_t
*src_loc
;
409 entry
= (dst_ln_entry_ptr_t
) *buffer
;
411 while (dst_ln_ln_delta(*entry
) == dst_ln_escape_flag
)
413 switch(entry
->esc
.esc_code
)
416 size
= 1; /* pad byte */
419 /* file escape. Next 4 bytes are a dst_src_loc_t */
421 src_loc
= (dst_src_loc_t
*) (*buffer
+ 1);
422 last_line
= src_loc
->line_number
;
423 last_file
= src_loc
->file_index
;
425 case dst_ln_dln1_dpc1
:
426 /* 1 byte line delta, 1 byte pc delta */
427 last_line
+= (*buffer
)[1];
428 last_pc
+= 2 * (unsigned char) (*buffer
)[2];
429 dst_record_line(last_line
, last_pc
);
432 case dst_ln_dln2_dpc2
:
433 /* 2 bytes line delta, 2 bytes pc delta */
434 last_line
+= *(short *) (*buffer
+ 1);
435 last_pc
+= 2 * (*(short *) (*buffer
+ 3));
437 dst_record_line(last_line
, last_pc
);
440 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
441 last_line
= *(unsigned long *) (*buffer
+ 1);
442 last_pc
= *(unsigned long *) (*buffer
+ 5);
444 dst_record_line(last_line
, last_pc
);
446 case dst_ln_dln1_dpc0
:
447 /* 1 byte line delta, pc delta = 0 */
449 last_line
+= (*buffer
)[1];
451 case dst_ln_ln_off_1
:
452 /* statement escape, stmt # = 1 (2nd stmt on line) */
456 /* statement escape, stmt # = next byte */
460 /* entry escape, next byte is entry number */
467 case dst_ln_stmt_end
:
468 /* gap escape, 4 bytes pc delta */
470 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
471 /* Apparently this isn't supposed to actually modify
472 * the pc value. Totally weird.
475 case dst_ln_escape_11
:
476 case dst_ln_escape_12
:
477 case dst_ln_escape_13
:
480 case dst_ln_nxt_byte
:
481 /* This shouldn't happen. If it does, we're SOL */
485 /* end escape, final entry follows */
488 *buffer
+= (size
< 0) ? -size
: size
;
489 entry
= (dst_ln_entry_ptr_t
) *buffer
;
491 last_line
+= dst_ln_ln_delta(*entry
);
492 last_pc
+= entry
->delta
.pc_delta
* 2;
494 dst_record_line(last_line
, last_pc
);
499 enter_all_lines(buffer
, address
)
504 while (get_dst_line(&buffer
, &address
));
508 get_dst_entry(buffer
, ret_entry
)
510 dst_rec_ptr_t
*ret_entry
;
514 static int last_type
;
518 entry
= (dst_rec_ptr_t
) buffer
;
519 switch(entry
->rec_type
)
524 case dst_typ_comp_unit
:
525 size
= sizeof(DST_comp_unit(entry
));
527 case dst_typ_section_tab
:
528 size
= sizeof(DST_section_tab(entry
))
529 + ((int) DST_section_tab(entry
).number_of_sections
530 - dst_dummy_array_size
) * sizeof(long);
532 case dst_typ_file_tab
:
533 size
= sizeof(DST_file_tab(entry
))
534 + ((int) DST_file_tab(entry
).number_of_files
535 - dst_dummy_array_size
) * sizeof(dst_file_desc_t
);
538 size
= sizeof(DST_block(entry
))
539 + ((int) DST_block(entry
).n_of_code_ranges
540 - dst_dummy_array_size
) * sizeof(dst_code_range_t
);
546 size
= sizeof(DST_var(entry
)) -
547 sizeof(dst_var_loc_long_t
) * dst_dummy_array_size
+
548 DST_var(entry
).no_of_locs
*
549 ( DST_var(entry
).short_locs
?
550 sizeof(dst_var_loc_short_t
):
551 sizeof(dst_var_loc_long_t
));
553 case dst_typ_pointer
:
554 size
= sizeof(DST_pointer(entry
));
557 size
= sizeof(DST_array(entry
));
559 case dst_typ_subrange
:
560 size
= sizeof(DST_subrange(entry
));
563 size
= sizeof(DST_set(entry
));
565 case dst_typ_implicit_enum
:
566 size
= sizeof(DST_implicit_enum(entry
))
567 + ((int) DST_implicit_enum(entry
).nelems
568 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
570 case dst_typ_explicit_enum
:
571 size
= sizeof(DST_explicit_enum(entry
))
572 + ((int) DST_explicit_enum(entry
).nelems
573 - dst_dummy_array_size
) * sizeof(dst_enum_elem_t
);
575 case dst_typ_short_rec
:
576 size
= sizeof(DST_short_rec(entry
))
577 + DST_short_rec(entry
).nfields
* sizeof(dst_short_field_t
)
578 - dst_dummy_array_size
* sizeof(dst_field_t
);
580 case dst_typ_short_union
:
581 size
= sizeof(DST_short_union(entry
))
582 + DST_short_union(entry
).nfields
* sizeof(dst_short_field_t
)
583 - dst_dummy_array_size
* sizeof(dst_field_t
);
586 size
= sizeof(DST_file(entry
));
589 size
= sizeof(DST_offset(entry
));
592 size
= sizeof(DST_alias(entry
));
594 case dst_typ_signature
:
595 size
= sizeof(DST_signature(entry
)) +
596 ((int) DST_signature(entry
).nargs
-
597 dst_dummy_array_size
) * sizeof(dst_arg_t
);
602 case dst_typ_old_label
:
603 size
= sizeof(DST_old_label(entry
));
606 size
= sizeof(DST_scope(entry
));
608 case dst_typ_end_scope
:
615 case dst_typ_string_tab
:
616 case dst_typ_global_name_tab
:
617 size
= sizeof(DST_string_tab(entry
))
618 + DST_string_tab(entry
).length
619 - dst_dummy_array_size
;
621 case dst_typ_forward
:
622 size
= sizeof(DST_forward(entry
));
623 get_dst_entry((char *) entry
+ DST_forward(entry
).rec_off
, &entry
);
625 case dst_typ_aux_size
:
626 size
= sizeof(DST_aux_size(entry
));
628 case dst_typ_aux_align
:
629 size
= sizeof(DST_aux_align(entry
));
631 case dst_typ_aux_field_size
:
632 size
= sizeof(DST_aux_field_size(entry
));
634 case dst_typ_aux_field_off
:
635 size
= sizeof(DST_aux_field_off(entry
));
637 case dst_typ_aux_field_align
:
638 size
= sizeof(DST_aux_field_align(entry
));
640 case dst_typ_aux_qual
:
641 size
= sizeof(DST_aux_qual(entry
));
643 case dst_typ_aux_var_bound
:
644 size
= sizeof(DST_aux_var_bound(entry
));
646 case dst_typ_extension
:
647 size
= DST_extension(entry
).rec_size
;
650 size
= sizeof(DST_string(entry
));
652 case dst_typ_old_entry
:
653 size
= 48; /* Obsolete entry type */
656 size
= sizeof(DST_const(entry
))
657 + DST_const(entry
).value
.length
658 - sizeof(DST_const(entry
).value
.val
);
660 case dst_typ_reference
:
661 size
= sizeof(DST_reference(entry
));
663 case dst_typ_old_record
:
664 case dst_typ_old_union
:
667 size
= sizeof(DST_record(entry
))
668 + ((int) DST_record(entry
).nfields
669 - dst_dummy_array_size
) * sizeof(dst_field_t
);
671 case dst_typ_aux_type_deriv
:
672 size
= sizeof(DST_aux_type_deriv(entry
));
674 case dst_typ_locpool
:
675 size
= sizeof(DST_locpool(entry
))
676 + ((int) DST_locpool(entry
).length
-
677 dst_dummy_array_size
);
679 case dst_typ_variable
:
680 size
= sizeof(DST_variable(entry
));
683 size
= sizeof(DST_label(entry
));
686 size
= sizeof(DST_entry(entry
));
688 case dst_typ_aux_lifetime
:
689 size
= sizeof(DST_aux_lifetime(entry
));
691 case dst_typ_aux_ptr_base
:
692 size
= sizeof(DST_aux_ptr_base(entry
));
694 case dst_typ_aux_src_range
:
695 size
= sizeof(DST_aux_src_range(entry
));
697 case dst_typ_aux_reg_val
:
698 size
= sizeof(DST_aux_reg_val(entry
));
700 case dst_typ_aux_unit_names
:
701 size
= sizeof(DST_aux_unit_names(entry
))
702 + ((int) DST_aux_unit_names(entry
).number_of_names
703 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
705 case dst_typ_aux_sect_info
:
706 size
= sizeof(DST_aux_sect_info(entry
))
707 + ((int) DST_aux_sect_info(entry
).number_of_refs
708 - dst_dummy_array_size
) * sizeof(dst_sect_ref_t
);
716 fprintf_unfiltered(gdb_stderr
, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
717 (int) entry
->rec_type
,
719 fprintf_unfiltered(gdb_stderr
, "Last unknown_3 value: %d\n", lu3
);
723 last_type
= entry
->rec_type
;
724 if (size
& 1) /* Align on a word boundary */
731 static int next_dst_entry(buffer
, entry
, table
)
733 dst_rec_ptr_t
*entry
;
736 if (*buffer
- table
->buffer
>= table
->size
)
741 *buffer
+= get_dst_entry(*buffer
, entry
);
745 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
746 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
747 #define DST_OFFSET(a, b) ((char *) (a) + (b))
749 static dst_rec_ptr_t section_table
= NULL
;
755 dst_sec
*section
= NULL
;
758 if (!section_table
|| !ref
->sect_index
)
760 offset
= DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
762 if (offset
>= blocks_info
.base
&&
763 offset
< blocks_info
.base
+ blocks_info
.size
)
764 section
= &blocks_info
;
765 else if (offset
>= symbols_info
.base
&&
766 offset
< symbols_info
.base
+ symbols_info
.size
)
767 section
= &symbols_info
;
768 else if (offset
>= lines_info
.base
&&
769 offset
< lines_info
.base
+ lines_info
.size
)
770 section
= &lines_info
;
773 return section
->buffer
+ (offset
- section
->base
);
777 dst_get_addr(int section
, long offset
)
779 if (!section_table
|| !section
)
781 return DST_section_tab(section_table
).section_base
[section
-1] + offset
;
788 if (!section_table
|| !ref
->sect_index
)
790 return DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
795 create_new_type(objfile
)
796 struct objfile
*objfile
;
800 type
= (struct type
*)
801 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct type
));
802 memset(type
, 0, sizeof(struct type
));
806 static struct symbol
*
807 create_new_symbol(objfile
, name
)
808 struct objfile
*objfile
;
811 struct symbol
*sym
= (struct symbol
*)
812 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
813 memset (sym
, 0, sizeof (struct symbol
));
814 SYMBOL_NAME (sym
) = obstack_copy0 (&objfile
->symbol_obstack
,
815 name
, strlen (name
));
816 SYMBOL_VALUE (sym
) = 0;
817 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
819 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
824 decode_dst_type
PARAMS ((struct objfile
*, dst_rec_ptr_t
));
827 decode_type_desc(objfile
, type_desc
, base
)
828 struct objfile
*objfile
;
829 dst_type_t
*type_desc
;
834 if (type_desc
->std_type
.user_defined_type
)
836 entry
= (dst_rec_ptr_t
) DST_OFFSET(base
,
837 dst_user_type_offset(*type_desc
));
838 type
= decode_dst_type(objfile
, entry
);
842 switch(type_desc
->std_type
.dtc
)
845 type
= builtin_type_signed_char
;
848 type
= builtin_type_short
;
851 type
= builtin_type_long
;
854 type
= builtin_type_unsigned_char
;
856 case dst_uint16_type
:
857 type
= builtin_type_unsigned_short
;
859 case dst_uint32_type
:
860 type
= builtin_type_unsigned_long
;
862 case dst_real32_type
:
863 type
= builtin_type_float
;
865 case dst_real64_type
:
866 type
= builtin_type_double
;
868 case dst_complex_type
:
869 type
= builtin_type_complex
;
871 case dst_dcomplex_type
:
872 type
= builtin_type_double_complex
;
875 type
= builtin_type_char
;
877 case dst_bool16_type
:
878 type
= builtin_type_short
;
880 case dst_bool32_type
:
881 type
= builtin_type_long
;
884 type
= builtin_type_char
;
886 /* The next few are more complex. I will take care
887 * of them properly at a later point.
889 case dst_string_type
:
890 type
= builtin_type_void
;
893 type
= builtin_type_void
;
896 type
= builtin_type_void
;
899 type
= builtin_type_void
;
902 type
= builtin_type_void
;
904 /* Back tto some ordinary ones */
906 type
= builtin_type_void
;
909 type
= builtin_type_unsigned_char
;
912 type
= builtin_type_void
;
919 struct structure_list
921 struct structure_list
*next
;
925 static struct structure_list
*struct_list
= NULL
;
928 find_dst_structure(name
)
931 struct structure_list
*element
;
933 for (element
= struct_list
; element
; element
= element
->next
)
934 if (!strcmp(name
, TYPE_NAME(element
->type
)))
935 return element
->type
;
941 decode_dst_structure(objfile
, entry
, code
, version
)
942 struct objfile
*objfile
;
947 struct type
*type
, *child_type
;
949 char *name
, *field_name
;
951 int fieldoffset
, fieldsize
;
952 dst_type_t type_desc
;
953 struct structure_list
*element
;
955 struct_name
= DST_OFFSET(entry
, DST_record(entry
).noffset
);
956 name
= concat( (code
== TYPE_CODE_UNION
)?"union ":"struct ",
958 type
= find_dst_structure(name
);
964 type
= create_new_type(objfile
);
965 TYPE_NAME(type
) = obstack_copy0 (&objfile
->symbol_obstack
,
968 TYPE_CODE(type
) = code
;
969 TYPE_LENGTH(type
) = DST_record(entry
).size
;
970 TYPE_NFIELDS(type
) = DST_record(entry
).nfields
;
971 TYPE_FIELDS(type
) = (struct field
*)
972 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) *
973 DST_record(entry
).nfields
);
974 fieldoffset
= fieldsize
= 0;
975 INIT_CPLUS_SPECIFIC(type
);
976 element
= (struct structure_list
*)
977 xmalloc(sizeof(struct structure_list
));
978 element
->type
= type
;
979 element
->next
= struct_list
;
980 struct_list
= element
;
981 for (i
= 0; i
< DST_record(entry
).nfields
; i
++)
986 field_name
= DST_OFFSET(entry
,
987 DST_record(entry
).f
.ofields
[i
].noffset
);
988 fieldoffset
= DST_record(entry
).f
.ofields
[i
].foffset
*8 +
989 DST_record(entry
).f
.ofields
[i
].bit_offset
;
990 fieldsize
= DST_record(entry
).f
.ofields
[i
].size
;
991 type_desc
= DST_record(entry
).f
.ofields
[i
].type_desc
;
994 field_name
= DST_OFFSET(entry
,
995 DST_record(entry
).f
.fields
[i
].noffset
);
996 type_desc
= DST_record(entry
).f
.fields
[i
].type_desc
;
997 switch(DST_record(entry
).f
.fields
[i
].f
.field_loc
.format_tag
)
1000 fieldoffset
= DST_record(entry
).f
.
1001 fields
[i
].f
.field_byte
.offset
* 8;
1005 fieldoffset
= DST_record(entry
).f
.
1006 fields
[i
].f
.field_bit
.byte_offset
* 8 +
1007 DST_record(entry
).f
.
1008 fields
[i
].f
.field_bit
.bit_offset
;
1009 fieldsize
= DST_record(entry
).f
.
1010 fields
[i
].f
.field_bit
.nbits
;
1013 fieldoffset
+= fieldsize
;
1019 field_name
= DST_OFFSET(entry
,
1020 DST_record(entry
).f
.sfields
[i
].noffset
);
1021 fieldoffset
= DST_record(entry
).f
.sfields
[i
].foffset
;
1022 type_desc
= DST_record(entry
).f
.sfields
[i
].type_desc
;
1023 if (i
< DST_record(entry
).nfields
- 1)
1024 fieldsize
= DST_record(entry
).f
.sfields
[i
+1].foffset
;
1026 fieldsize
= DST_record(entry
).size
;
1027 fieldsize
-= fieldoffset
;
1031 TYPE_FIELDS(type
)[i
].name
=
1032 obstack_copy0 (&objfile
->symbol_obstack
,
1033 field_name
, strlen(field_name
));
1034 TYPE_FIELDS(type
)[i
].type
= decode_type_desc(objfile
,
1037 if (fieldsize
== -1)
1038 fieldsize
= TYPE_LENGTH(TYPE_FIELDS(type
)[i
].type
) *
1040 TYPE_FIELDS(type
)[i
].bitsize
= fieldsize
;
1041 TYPE_FIELDS(type
)[i
].bitpos
= fieldoffset
;
1046 static struct type
*
1047 decode_dst_type(objfile
, entry
)
1048 struct objfile
*objfile
;
1049 dst_rec_ptr_t entry
;
1051 struct type
*child_type
, *type
, *range_type
, *index_type
;
1053 switch(entry
->rec_type
)
1056 return decode_type_desc(objfile
,
1057 &DST_var(entry
).type_desc
,
1060 case dst_typ_variable
:
1061 return decode_type_desc(objfile
,
1062 &DST_variable(entry
).type_desc
,
1065 case dst_typ_short_rec
:
1066 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,0);
1067 case dst_typ_short_union
:
1068 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 0);
1070 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 1);
1071 case dst_typ_record
:
1072 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,1);
1073 case dst_typ_old_union
:
1074 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 2);
1075 case dst_typ_old_record
:
1076 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,2);
1077 case dst_typ_pointer
:
1078 return make_pointer_type(
1079 decode_type_desc(objfile
,
1080 &DST_pointer(entry
).type_desc
,
1084 child_type
= decode_type_desc(objfile
,
1085 &DST_pointer(entry
).type_desc
,
1087 index_type
= lookup_fundamental_type(objfile
,
1089 range_type
= create_range_type ((struct type
*) NULL
,
1090 index_type
, DST_array(entry
).lo_bound
,
1091 DST_array(entry
).hi_bound
);
1092 return create_array_type ((struct type
*) NULL
, child_type
,
1095 return decode_type_desc(objfile
,
1096 &DST_alias(entry
).type_desc
,
1099 return builtin_type_int
;
1103 struct symbol_list
{
1104 struct symbol_list
*next
;
1105 struct symbol
*symbol
;
1108 static struct symbol_list
*dst_global_symbols
= NULL
;
1109 static int total_globals
= 0;
1112 decode_dst_locstring(locstr
, sym
)
1116 dst_loc_entry_t
*entry
, *next_entry
;
1124 fprintf_unfiltered(gdb_stderr
, "Error reading locstring\n");
1127 entry
= (dst_loc_entry_t
*) locstr
;
1128 next_entry
= (dst_loc_entry_t
*) (locstr
+ 1);
1129 switch (entry
->header
.code
)
1131 case dst_lsc_end
: /* End of string */
1133 case dst_lsc_indirect
:/* Indirect through previous. Arg == 6 */
1134 /* Or register ax x == arg */
1135 if (entry
->header
.arg
< 6)
1137 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1138 SYMBOL_VALUE(sym
) = entry
->header
.arg
+ 8;
1140 /* We predict indirects */
1144 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1145 SYMBOL_VALUE(sym
) = entry
->header
.arg
;
1148 case dst_lsc_section
:/* Section (arg+1) */
1149 SYMBOL_VALUE(sym
) = dst_get_addr(entry
->header
.arg
+1, 0);
1152 case dst_lsc_sec_byte
: /* Section (next_byte+1) */
1153 SYMBOL_VALUE(sym
) = dst_get_addr(locstr
[1]+1, 0);
1156 case dst_lsc_add
: /* Add (arg+1)*2 */
1157 case dst_lsc_sub
: /* Subtract (arg+1)*2 */
1158 temp
= (entry
->header
.arg
+ 1) * 2;
1160 if (*locstr
== dst_multiply_256
)
1165 switch(entry
->header
.code
)
1168 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1169 SYMBOL_CLASS(sym
) = LOC_ARG
;
1170 SYMBOL_VALUE(sym
) += temp
;
1173 SYMBOL_VALUE(sym
) -= temp
;
1177 case dst_lsc_add_byte
:
1178 case dst_lsc_sub_byte
:
1179 switch (entry
->header
.arg
& 0x03)
1182 temp
= (unsigned char) locstr
[1];
1186 temp
= * (unsigned short *) (locstr
+ 1);
1190 temp
= * (unsigned long *) (locstr
+ 1);
1194 if (*locstr
== dst_multiply_256
)
1199 switch(entry
->header
.code
)
1201 case dst_lsc_add_byte
:
1202 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1203 SYMBOL_CLASS(sym
) = LOC_ARG
;
1204 SYMBOL_VALUE(sym
) += temp
;
1206 case dst_lsc_sub_byte
:
1207 SYMBOL_VALUE(sym
) -= temp
;
1211 case dst_lsc_sbreg
: /* Stack base register (frame pointer). Arg==0*/
1212 if (next_entry
->header
.code
!= dst_lsc_indirect
)
1214 SYMBOL_VALUE(sym
) = 0;
1215 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1218 SYMBOL_VALUE(sym
) = 0;
1219 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1223 SYMBOL_VALUE(sym
) = 0;
1224 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1230 static struct symbol_list
*
1231 process_dst_symbols(objfile
, entry
, name
, nsyms_ret
)
1232 struct objfile
*objfile
;
1233 dst_rec_ptr_t entry
;
1237 struct symbol_list
*list
= NULL
, *element
;
1245 dst_var_attr_t attr
;
1246 dst_var_loc_t loc_type
;
1255 location
= (char *) entry
;
1256 while (NEXT_SYM(&location
, &entry
) &&
1257 entry
->rec_type
!= dst_typ_end_scope
)
1259 if (entry
->rec_type
== dst_typ_var
)
1261 if (DST_var(entry
).short_locs
)
1263 loc_type
= DST_var(entry
).locs
.shorts
[0].loc_type
;
1264 loc_index
= DST_var(entry
).locs
.shorts
[0].loc_index
;
1265 loc_value
= DST_var(entry
).locs
.shorts
[0].location
;
1269 loc_type
= DST_var(entry
).locs
.longs
[0].loc_type
;
1270 loc_index
= DST_var(entry
).locs
.longs
[0].loc_index
;
1271 loc_value
= DST_var(entry
).locs
.longs
[0].location
;
1273 if (loc_type
== dst_var_loc_external
)
1275 symname
= DST_OFFSET(entry
, DST_var(entry
).noffset
);
1276 line
= DST_var(entry
).src_loc
.line_number
;
1277 symtype
= DST_var(entry
).type_desc
;
1278 attr
= DST_var(entry
).attributes
;
1280 else if (entry
->rec_type
== dst_typ_variable
)
1282 symname
= DST_OFFSET(entry
,
1283 DST_variable(entry
).noffset
);
1284 line
= DST_variable(entry
).src_loc
.line_number
;
1285 symtype
= DST_variable(entry
).type_desc
;
1286 attr
= DST_variable(entry
).attributes
;
1292 if (symname
&& name
&& !strcmp(symname
, name
))
1293 /* It's the function return value */
1295 sym
= create_new_symbol(objfile
, symname
);
1297 if ((attr
& (1<<dst_var_attr_global
)) ||
1298 (attr
& (1<<dst_var_attr_static
)))
1299 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1301 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1302 SYMBOL_LINE(sym
) = line
;
1303 SYMBOL_TYPE(sym
) = decode_type_desc(objfile
, &symtype
,
1305 SYMBOL_VALUE(sym
) = 0;
1306 switch (entry
->rec_type
)
1311 case dst_var_loc_abs
:
1312 SYMBOL_VALUE_ADDRESS(sym
) = loc_value
;
1314 case dst_var_loc_sect_off
:
1315 case dst_var_loc_ind_sect_off
: /* What is this? */
1316 SYMBOL_VALUE_ADDRESS(sym
) = dst_get_addr(
1320 case dst_var_loc_ind_reg_rel
: /* What is this? */
1321 case dst_var_loc_reg_rel
:
1322 /* If it isn't fp relative, specify the
1323 * register it's relative to.
1327 sym
->aux_value
.basereg
= loc_index
;
1329 SYMBOL_VALUE(sym
) = loc_value
;
1330 if (loc_value
> 0 &&
1331 SYMBOL_CLASS(sym
) == LOC_BASEREG
)
1332 SYMBOL_CLASS(sym
) = LOC_BASEREG_ARG
;
1334 case dst_var_loc_reg
:
1335 SYMBOL_VALUE(sym
) = loc_index
;
1336 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1340 case dst_typ_variable
:
1341 /* External variable..... don't try to interpret
1342 * its nonexistant locstring.
1344 if (DST_variable(entry
).loffset
== -1)
1346 decode_dst_locstring(DST_OFFSET(entry
,
1347 DST_variable(entry
).loffset
),
1350 element
= (struct symbol_list
*)
1351 xmalloc(sizeof(struct symbol_list
));
1353 if (attr
& (1<<dst_var_attr_global
))
1355 element
->next
= dst_global_symbols
;
1356 dst_global_symbols
= element
;
1361 element
->next
= list
;
1365 element
->symbol
= sym
;
1372 static struct symbol
*
1373 process_dst_function(objfile
, entry
, name
, address
)
1374 struct objfile
*objfile
;
1375 dst_rec_ptr_t entry
;
1380 struct type
*type
, *ftype
;
1381 dst_rec_ptr_t sym_entry
, typ_entry
;
1383 struct symbol_list
*element
;
1385 type
= builtin_type_int
;
1386 sym
= create_new_symbol(objfile
, name
);
1387 SYMBOL_CLASS(sym
) = LOC_BLOCK
;
1391 location
= (char *) entry
;
1394 NEXT_SYM(&location
, &sym_entry
);
1395 } while (sym_entry
&& sym_entry
->rec_type
!= dst_typ_signature
);
1400 DST_signature(sym_entry
).src_loc
.line_number
;
1401 if (DST_signature(sym_entry
).result
)
1403 typ_entry
= (dst_rec_ptr_t
)
1404 DST_OFFSET(sym_entry
,
1405 DST_signature(sym_entry
).result
);
1406 type
= decode_dst_type(objfile
, typ_entry
);
1411 if (!type
->function_type
)
1413 ftype
= create_new_type(objfile
);
1414 type
->function_type
= ftype
;
1415 ftype
->target_type
= type
;
1416 ftype
->code
= TYPE_CODE_FUNC
;
1418 SYMBOL_TYPE(sym
) = type
->function_type
;
1420 /* Now add ourselves to the global symbols list */
1421 element
= (struct symbol_list
*)
1422 xmalloc(sizeof(struct symbol_list
));
1424 element
->next
= dst_global_symbols
;
1425 dst_global_symbols
= element
;
1427 element
->symbol
= sym
;
1432 static struct block
*
1433 process_dst_block(objfile
, entry
)
1434 struct objfile
*objfile
;
1435 dst_rec_ptr_t entry
;
1437 struct block
*block
;
1438 struct symbol
*function
= NULL
;
1442 dst_rec_ptr_t child_entry
, symbol_entry
;
1443 struct block
*child_block
;
1444 int total_symbols
= 0;
1445 struct pending_block
*pblock
;
1447 static long fake_seq
= 0;
1448 struct symbol_list
*symlist
, *nextsym
;
1451 if (DST_block(entry
).noffset
)
1452 name
= DST_OFFSET(entry
, DST_block(entry
).noffset
);
1455 if (DST_block(entry
).n_of_code_ranges
)
1457 address
= dst_sym_addr(
1458 &DST_block(entry
).code_ranges
[0].code_start
);
1459 size
= DST_block(entry
).code_ranges
[0].code_size
;
1466 symbol_entry
= (dst_rec_ptr_t
) get_sec_ref(&DST_block(entry
).symbols_start
);
1467 switch(DST_block(entry
).block_type
)
1469 /* These are all really functions. Even the "program" type.
1470 * This is because the Apollo OS was written in Pascal, and
1471 * in Pascal, the main procedure is described as the Program.
1474 case dst_block_procedure
:
1475 case dst_block_function
:
1476 case dst_block_subroutine
:
1477 case dst_block_program
:
1478 record_minimal_symbol(name
, address
, mst_text
);
1479 function
= process_dst_function(
1484 enter_all_lines(get_sec_ref(&DST_block(entry
).code_ranges
[0].lines_start
), address
);
1486 case dst_block_block_data
:
1490 /* GDB has to call it something, and the module name
1493 sprintf(fake_name
, "block_%08lx", fake_seq
++);
1494 function
= process_dst_function(
1495 objfile
, NULL
, fake_name
, address
);
1498 symlist
= process_dst_symbols(objfile
, symbol_entry
,
1499 name
, &total_symbols
);
1500 block
= (struct block
*)
1501 obstack_alloc (&objfile
->symbol_obstack
,
1502 sizeof (struct block
) +
1503 (total_symbols
- 1) * sizeof (struct symbol
*));
1508 nextsym
= symlist
->next
;
1510 block
->sym
[symnum
] = symlist
->symbol
;
1512 free((PTR
) symlist
);
1516 BLOCK_NSYMS (block
) = total_symbols
;
1517 BLOCK_START (block
) = address
;
1518 BLOCK_END (block
) = address
+ size
;
1519 BLOCK_SUPERBLOCK (block
) = 0;
1522 SYMBOL_BLOCK_VALUE (function
) = block
;
1523 BLOCK_FUNCTION (block
) = function
;
1526 BLOCK_FUNCTION (block
) = 0;
1528 pblock
= (struct pending_block
*)
1529 xmalloc (sizeof (struct pending_block
));
1530 pblock
->block
= block
;
1531 pblock
->next
= pending_blocks
;
1532 pending_blocks
= pblock
;
1533 if (DST_block(entry
).child_block_off
)
1535 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1536 DST_block(entry
).child_block_off
);
1539 child_block
= process_dst_block(objfile
, child_entry
);
1542 if (BLOCK_START(child_block
) <
1543 BLOCK_START(block
) ||
1544 BLOCK_START(block
) == -1)
1545 BLOCK_START(block
) =
1546 BLOCK_START(child_block
);
1547 if (BLOCK_END(child_block
) >
1549 BLOCK_END(block
) == -1)
1551 BLOCK_END(child_block
);
1552 BLOCK_SUPERBLOCK (child_block
) = block
;
1554 if (DST_block(child_entry
).sibling_block_off
)
1555 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(
1557 DST_block(child_entry
).sibling_block_off
);
1567 read_dst_symtab (objfile
)
1568 struct objfile
*objfile
;
1571 dst_rec_ptr_t entry
, file_table
, root_block
;
1573 struct block
*block
, *global_block
;
1574 struct pending_block
*pblock
;
1576 struct symbol_list
*nextsym
;
1578 struct structure_list
*element
;
1580 current_objfile
= objfile
;
1581 buffer
= blocks_info
.buffer
;
1582 while (NEXT_BLK(&buffer
, &entry
))
1584 if (entry
->rec_type
== dst_typ_comp_unit
)
1586 file_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1587 DST_comp_unit(entry
).file_table
);
1588 section_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1589 DST_comp_unit(entry
).section_table
);
1590 root_block
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1591 DST_comp_unit(entry
).root_block_offset
);
1592 source_file
= DST_OFFSET(file_table
,
1593 DST_file_tab(file_table
).files
[0].noffset
);
1594 /* Point buffer to the start of the next comp_unit */
1595 buffer
= DST_OFFSET(entry
,
1596 DST_comp_unit(entry
).data_size
);
1599 pblock
= (struct pending_block
*)
1600 xmalloc (sizeof (struct pending_block
));
1601 pblock
->next
= NULL
;
1602 pending_blocks
= pblock
;
1604 block
= process_dst_block(objfile
, root_block
);
1606 global_block
= (struct block
*)
1607 obstack_alloc (&objfile
->symbol_obstack
,
1608 sizeof (struct block
) +
1609 (total_globals
- 1) *
1610 sizeof (struct symbol
*));
1611 BLOCK_NSYMS(global_block
) = total_globals
;
1612 for (symnum
= 0; symnum
< total_globals
; symnum
++)
1614 nextsym
= dst_global_symbols
->next
;
1616 global_block
->sym
[symnum
] =
1617 dst_global_symbols
->symbol
;
1619 free((PTR
) dst_global_symbols
);
1620 dst_global_symbols
= nextsym
;
1622 dst_global_symbols
= NULL
;
1624 BLOCK_FUNCTION(global_block
) = 0;
1625 BLOCK_START(global_block
) = BLOCK_START(block
);
1626 BLOCK_END(global_block
) = BLOCK_END(block
);
1627 BLOCK_SUPERBLOCK(global_block
) = 0;
1628 BLOCK_SUPERBLOCK(block
) = global_block
;
1629 pblock
->block
= global_block
;
1631 complete_symtab(source_file
,
1633 BLOCK_END(block
) - BLOCK_START(block
));
1635 dst_end_symtab(objfile
);
1639 record_minimal_symbol("<end_of_program>",
1640 BLOCK_END(block
), mst_text
);
1641 /* One more faked symbol to make sure nothing can ever run off the
1642 * end of the symbol table. This one represents the end of the
1643 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1644 * int possible), but some parts of gdb treated it as a signed
1645 * number and failed comparisons. We could equally use 7fffffff,
1646 * but no functions are ever mapped to an address higher than
1649 record_minimal_symbol("<end_of_text>",
1650 (CORE_ADDR
) 0x40000000,
1654 element
= struct_list
;
1655 struct_list
= element
->next
;
1656 free((PTR
) element
);
1661 /* Support for line number handling */
1662 static char *linetab
= NULL
;
1663 static long linetab_offset
;
1664 static unsigned long linetab_size
;
1666 /* Read in all the line numbers for fast lookups later. Leave them in
1667 external (unswapped) format in memory; we'll swap them as we enter
1668 them into GDB's data structures. */
1670 init_one_section(chan
, secinfo
)
1674 if (secinfo
->size
== 0
1675 || lseek(chan
, secinfo
->position
, 0) == -1
1676 || (secinfo
->buffer
= xmalloc(secinfo
->size
)) == NULL
1677 || myread(chan
, secinfo
->buffer
, secinfo
->size
) == -1)
1684 init_dst_sections (chan
)
1688 if (!init_one_section(chan
, &blocks_info
) ||
1689 !init_one_section(chan
, &lines_info
) ||
1690 !init_one_section(chan
, &symbols_info
))
1696 /* Fake up support for relocating symbol addresses. FIXME. */
1698 struct section_offsets dst_symfile_faker
= {0};
1700 struct section_offsets
*
1701 dst_symfile_offsets (objfile
, addr
)
1702 struct objfile
*objfile
;
1705 objfile
->num_sections
= 1;
1706 return &dst_symfile_faker
;
1709 /* Register our ability to parse symbols for DST BFD files */
1711 static struct sym_fns dst_sym_fns
=
1713 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1714 a separate flavour like ecoff? */
1715 (enum bfd_flavour
)-2,
1717 dst_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1718 dst_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1719 dst_symfile_read
, /* sym_read: read a symbol file into symtab */
1720 dst_symfile_finish
, /* sym_finish: finished with file, cleanup */
1721 dst_symfile_offsets
, /* sym_offsets: xlate external to internal form */
1722 NULL
/* next: pointer to next struct sym_fns */
1726 _initialize_dstread ()
1728 add_symtab_fns(&dst_sym_fns
);