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, Boston, MA 02111-1307, 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
;
55 init_dst_sections
PARAMS ((int));
58 read_dst_symtab
PARAMS ((struct objfile
*));
61 find_dst_sections
PARAMS ((bfd
*, sec_ptr
, PTR
));
64 dst_symfile_init
PARAMS ((struct objfile
*));
67 dst_new_init
PARAMS ((struct objfile
*));
70 dst_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
73 dst_symfile_finish
PARAMS ((struct objfile
*));
76 dst_end_symtab
PARAMS ((struct objfile
*));
79 complete_symtab
PARAMS ((char *, CORE_ADDR
, unsigned int));
82 dst_start_symtab
PARAMS ((void));
85 dst_record_line
PARAMS ((int, CORE_ADDR
));
87 /* Manage the vector of line numbers. */
88 /* FIXME: Use record_line instead. */
91 dst_record_line (line
, pc
)
95 struct linetable_entry
*e
;
96 /* Make sure line vector is big enough. */
98 if (line_vector_index
+ 2 >= line_vector_length
)
100 line_vector_length
*= 2;
101 line_vector
= (struct linetable
*)
102 xrealloc ((char *) line_vector
, sizeof (struct linetable
)
103 + (line_vector_length
104 * sizeof (struct linetable_entry
)));
107 e
= line_vector
->item
+ line_vector_index
++;
108 e
->line
= line
; e
->pc
= pc
;
111 /* Start a new symtab for a new source file.
112 It indicates the start of data for one original source file. */
113 /* FIXME: use start_symtab, like coffread.c now does. */
118 /* Initialize the source file line number information for this file. */
120 if (line_vector
) /* Unlikely, but maybe possible? */
121 free ((PTR
)line_vector
);
122 line_vector_index
= 0;
123 line_vector_length
= 1000;
124 prev_line_number
= -2; /* Force first line number to be explicit */
125 line_vector
= (struct linetable
*)
126 xmalloc (sizeof (struct linetable
)
127 + line_vector_length
* sizeof (struct linetable_entry
));
130 /* Save the vital information from when starting to read a file,
131 for use when closing off the current file.
132 NAME is the file name the symbols came from, START_ADDR is the first
133 text address for the file, and SIZE is the number of bytes of text. */
136 complete_symtab (name
, start_addr
, size
)
138 CORE_ADDR start_addr
;
141 last_source_file
= savestring (name
, strlen (name
));
142 cur_src_start_addr
= start_addr
;
143 cur_src_end_addr
= start_addr
+ size
;
145 if (current_objfile
-> ei
.entry_point
>= cur_src_start_addr
&&
146 current_objfile
-> ei
.entry_point
< cur_src_end_addr
)
148 current_objfile
-> ei
.entry_file_lowpc
= cur_src_start_addr
;
149 current_objfile
-> ei
.entry_file_highpc
= cur_src_end_addr
;
153 /* Finish the symbol definitions for one main source file,
154 close off all the lexical contexts for that file
155 (creating struct block's for them), then make the
156 struct symtab for that file and put it in the list of all such. */
157 /* FIXME: Use end_symtab, like coffread.c now does. */
160 dst_end_symtab (objfile
)
161 struct objfile
*objfile
;
163 register struct symtab
*symtab
;
164 register struct blockvector
*blockvector
;
165 register struct linetable
*lv
;
167 /* Create the blockvector that points to all the file's blocks. */
169 blockvector
= make_blockvector (objfile
);
171 /* Now create the symtab object for this source file. */
172 symtab
= allocate_symtab (last_source_file
, objfile
);
174 /* Fill in its components. */
175 symtab
->blockvector
= blockvector
;
176 symtab
->free_code
= free_linetable
;
177 symtab
->free_ptr
= 0;
178 symtab
->filename
= last_source_file
;
179 symtab
->dirname
= NULL
;
181 lv
->nitems
= line_vector_index
;
182 symtab
->linetable
= (struct linetable
*)
183 xrealloc ((char *) lv
, (sizeof (struct linetable
)
184 + lv
->nitems
* sizeof (struct linetable_entry
)));
186 free_named_symtabs (symtab
->filename
);
188 /* Reinitialize for beginning of new file. */
190 line_vector_length
= -1;
191 last_source_file
= NULL
;
194 /* dst_symfile_init ()
195 is the dst-specific initialization routine for reading symbols.
197 We will only be called if this is a DST or DST-like file.
198 BFD handles figuring out the format of the file, and code in symtab.c
199 uses BFD's determination to vector to us.
201 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
204 dst_symfile_init (objfile
)
205 struct objfile
*objfile
;
208 bfd
*abfd
= objfile
->obfd
;
210 init_entry_point_info (objfile
);
214 /* This function is called for every section; it finds the outer limits
215 of the line table (minimum and maximum file offset) so that the
216 mainline code can read the whole thing for efficiency. */
220 find_dst_sections (abfd
, asect
, vpinfo
)
227 file_ptr offset
, maxoff
;
230 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
231 size
= asect
->_raw_size
;
232 offset
= asect
->filepos
;
237 if (!strcmp(asect
->name
, ".blocks"))
238 section
= &blocks_info
;
239 else if (!strcmp(asect
->name
, ".lines"))
240 section
= &lines_info
;
241 else if (!strcmp(asect
->name
, ".symbols"))
242 section
= &symbols_info
;
245 section
->size
= size
;
246 section
->position
= offset
;
247 section
->base
= base
;
251 /* The BFD for this file -- only good while we're actively reading
252 symbols into a psymtab or a symtab. */
254 static bfd
*symfile_bfd
;
256 /* Read a symbol file, after initialization by dst_symfile_init. */
257 /* FIXME! Addr and Mainline are not used yet -- this will not work for
258 shared libraries or add_file! */
262 dst_symfile_read (objfile
, section_offsets
, mainline
)
263 struct objfile
*objfile
;
264 struct section_offsets
*section_offsets
;
267 bfd
*abfd
= objfile
->obfd
;
268 char *name
= bfd_get_filename (abfd
);
273 int stringtab_offset
;
275 symfile_bfd
= abfd
; /* Kludge for swap routines */
277 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
278 desc
= fileno ((GDB_FILE
*)(abfd
->iostream
)); /* File descriptor */
280 /* Read the line number table, all at once. */
281 bfd_map_over_sections (abfd
, find_dst_sections
, (PTR
)NULL
);
283 val
= init_dst_sections (desc
);
285 error ("\"%s\": error reading debugging symbol tables\n", name
);
287 init_minimal_symbol_collection ();
288 make_cleanup (discard_minimal_symbols
, 0);
290 /* Now that the executable file is positioned at symbol table,
291 process it and define symbols accordingly. */
293 read_dst_symtab (objfile
);
295 /* Sort symbols alphabetically within each block. */
299 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
301 sort_symtab_syms (s
);
305 /* Install any minimal symbols that have been collected as the current
306 minimal symbols for this objfile. */
308 install_minimal_symbols (objfile
);
312 dst_new_init (ignore
)
313 struct objfile
*ignore
;
318 /* Perform any local cleanups required when we are done with a particular
319 objfile. I.E, we are in the process of discarding all symbol information
320 for an objfile, freeing up all memory held for it, and unlinking the
321 objfile struct from the global list of known objfiles. */
324 dst_symfile_finish (objfile
)
325 struct objfile
*objfile
;
331 /* Get the next line number from the DST. Returns 0 when we hit an
332 * end directive or cannot continue for any other reason.
334 * Note that ordinary pc deltas are multiplied by two. Apparently
335 * this is what was really intended.
338 get_dst_line(buffer
, pc
)
339 signed char **buffer
;
343 static long last_line
= 0;
344 static int last_file
= 0;
345 dst_ln_entry_ptr_t entry
;
347 dst_src_loc_t
*src_loc
;
354 entry
= (dst_ln_entry_ptr_t
) *buffer
;
356 while (dst_ln_ln_delta(*entry
) == dst_ln_escape_flag
)
358 switch(entry
->esc
.esc_code
)
361 size
= 1; /* pad byte */
364 /* file escape. Next 4 bytes are a dst_src_loc_t */
366 src_loc
= (dst_src_loc_t
*) (*buffer
+ 1);
367 last_line
= src_loc
->line_number
;
368 last_file
= src_loc
->file_index
;
370 case dst_ln_dln1_dpc1
:
371 /* 1 byte line delta, 1 byte pc delta */
372 last_line
+= (*buffer
)[1];
373 last_pc
+= 2 * (unsigned char) (*buffer
)[2];
374 dst_record_line(last_line
, last_pc
);
377 case dst_ln_dln2_dpc2
:
378 /* 2 bytes line delta, 2 bytes pc delta */
379 last_line
+= *(short *) (*buffer
+ 1);
380 last_pc
+= 2 * (*(short *) (*buffer
+ 3));
382 dst_record_line(last_line
, last_pc
);
385 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
386 last_line
= *(unsigned long *) (*buffer
+ 1);
387 last_pc
= *(unsigned long *) (*buffer
+ 5);
389 dst_record_line(last_line
, last_pc
);
391 case dst_ln_dln1_dpc0
:
392 /* 1 byte line delta, pc delta = 0 */
394 last_line
+= (*buffer
)[1];
396 case dst_ln_ln_off_1
:
397 /* statement escape, stmt # = 1 (2nd stmt on line) */
401 /* statement escape, stmt # = next byte */
405 /* entry escape, next byte is entry number */
412 case dst_ln_stmt_end
:
413 /* gap escape, 4 bytes pc delta */
415 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
416 /* Apparently this isn't supposed to actually modify
417 * the pc value. Totally weird.
420 case dst_ln_escape_11
:
421 case dst_ln_escape_12
:
422 case dst_ln_escape_13
:
425 case dst_ln_nxt_byte
:
426 /* This shouldn't happen. If it does, we're SOL */
430 /* end escape, final entry follows */
433 *buffer
+= (size
< 0) ? -size
: size
;
434 entry
= (dst_ln_entry_ptr_t
) *buffer
;
436 last_line
+= dst_ln_ln_delta(*entry
);
437 last_pc
+= entry
->delta
.pc_delta
* 2;
439 dst_record_line(last_line
, last_pc
);
444 enter_all_lines(buffer
, address
)
449 while (get_dst_line(&buffer
, &address
));
453 get_dst_entry(buffer
, ret_entry
)
455 dst_rec_ptr_t
*ret_entry
;
459 static int last_type
;
463 entry
= (dst_rec_ptr_t
) buffer
;
464 switch(entry
->rec_type
)
469 case dst_typ_comp_unit
:
470 size
= sizeof(DST_comp_unit(entry
));
472 case dst_typ_section_tab
:
473 size
= sizeof(DST_section_tab(entry
))
474 + ((int) DST_section_tab(entry
).number_of_sections
475 - dst_dummy_array_size
) * sizeof(long);
477 case dst_typ_file_tab
:
478 size
= sizeof(DST_file_tab(entry
))
479 + ((int) DST_file_tab(entry
).number_of_files
480 - dst_dummy_array_size
) * sizeof(dst_file_desc_t
);
483 size
= sizeof(DST_block(entry
))
484 + ((int) DST_block(entry
).n_of_code_ranges
485 - dst_dummy_array_size
) * sizeof(dst_code_range_t
);
491 size
= sizeof(DST_var(entry
)) -
492 sizeof(dst_var_loc_long_t
) * dst_dummy_array_size
+
493 DST_var(entry
).no_of_locs
*
494 ( DST_var(entry
).short_locs
?
495 sizeof(dst_var_loc_short_t
):
496 sizeof(dst_var_loc_long_t
));
498 case dst_typ_pointer
:
499 size
= sizeof(DST_pointer(entry
));
502 size
= sizeof(DST_array(entry
));
504 case dst_typ_subrange
:
505 size
= sizeof(DST_subrange(entry
));
508 size
= sizeof(DST_set(entry
));
510 case dst_typ_implicit_enum
:
511 size
= sizeof(DST_implicit_enum(entry
))
512 + ((int) DST_implicit_enum(entry
).nelems
513 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
515 case dst_typ_explicit_enum
:
516 size
= sizeof(DST_explicit_enum(entry
))
517 + ((int) DST_explicit_enum(entry
).nelems
518 - dst_dummy_array_size
) * sizeof(dst_enum_elem_t
);
520 case dst_typ_short_rec
:
521 size
= sizeof(DST_short_rec(entry
))
522 + DST_short_rec(entry
).nfields
* sizeof(dst_short_field_t
)
523 - dst_dummy_array_size
* sizeof(dst_field_t
);
525 case dst_typ_short_union
:
526 size
= sizeof(DST_short_union(entry
))
527 + DST_short_union(entry
).nfields
* sizeof(dst_short_field_t
)
528 - dst_dummy_array_size
* sizeof(dst_field_t
);
531 size
= sizeof(DST_file(entry
));
534 size
= sizeof(DST_offset(entry
));
537 size
= sizeof(DST_alias(entry
));
539 case dst_typ_signature
:
540 size
= sizeof(DST_signature(entry
)) +
541 ((int) DST_signature(entry
).nargs
-
542 dst_dummy_array_size
) * sizeof(dst_arg_t
);
547 case dst_typ_old_label
:
548 size
= sizeof(DST_old_label(entry
));
551 size
= sizeof(DST_scope(entry
));
553 case dst_typ_end_scope
:
560 case dst_typ_string_tab
:
561 case dst_typ_global_name_tab
:
562 size
= sizeof(DST_string_tab(entry
))
563 + DST_string_tab(entry
).length
564 - dst_dummy_array_size
;
566 case dst_typ_forward
:
567 size
= sizeof(DST_forward(entry
));
568 get_dst_entry((char *) entry
+ DST_forward(entry
).rec_off
, &entry
);
570 case dst_typ_aux_size
:
571 size
= sizeof(DST_aux_size(entry
));
573 case dst_typ_aux_align
:
574 size
= sizeof(DST_aux_align(entry
));
576 case dst_typ_aux_field_size
:
577 size
= sizeof(DST_aux_field_size(entry
));
579 case dst_typ_aux_field_off
:
580 size
= sizeof(DST_aux_field_off(entry
));
582 case dst_typ_aux_field_align
:
583 size
= sizeof(DST_aux_field_align(entry
));
585 case dst_typ_aux_qual
:
586 size
= sizeof(DST_aux_qual(entry
));
588 case dst_typ_aux_var_bound
:
589 size
= sizeof(DST_aux_var_bound(entry
));
591 case dst_typ_extension
:
592 size
= DST_extension(entry
).rec_size
;
595 size
= sizeof(DST_string(entry
));
597 case dst_typ_old_entry
:
598 size
= 48; /* Obsolete entry type */
601 size
= sizeof(DST_const(entry
))
602 + DST_const(entry
).value
.length
603 - sizeof(DST_const(entry
).value
.val
);
605 case dst_typ_reference
:
606 size
= sizeof(DST_reference(entry
));
608 case dst_typ_old_record
:
609 case dst_typ_old_union
:
612 size
= sizeof(DST_record(entry
))
613 + ((int) DST_record(entry
).nfields
614 - dst_dummy_array_size
) * sizeof(dst_field_t
);
616 case dst_typ_aux_type_deriv
:
617 size
= sizeof(DST_aux_type_deriv(entry
));
619 case dst_typ_locpool
:
620 size
= sizeof(DST_locpool(entry
))
621 + ((int) DST_locpool(entry
).length
-
622 dst_dummy_array_size
);
624 case dst_typ_variable
:
625 size
= sizeof(DST_variable(entry
));
628 size
= sizeof(DST_label(entry
));
631 size
= sizeof(DST_entry(entry
));
633 case dst_typ_aux_lifetime
:
634 size
= sizeof(DST_aux_lifetime(entry
));
636 case dst_typ_aux_ptr_base
:
637 size
= sizeof(DST_aux_ptr_base(entry
));
639 case dst_typ_aux_src_range
:
640 size
= sizeof(DST_aux_src_range(entry
));
642 case dst_typ_aux_reg_val
:
643 size
= sizeof(DST_aux_reg_val(entry
));
645 case dst_typ_aux_unit_names
:
646 size
= sizeof(DST_aux_unit_names(entry
))
647 + ((int) DST_aux_unit_names(entry
).number_of_names
648 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
650 case dst_typ_aux_sect_info
:
651 size
= sizeof(DST_aux_sect_info(entry
))
652 + ((int) DST_aux_sect_info(entry
).number_of_refs
653 - dst_dummy_array_size
) * sizeof(dst_sect_ref_t
);
661 fprintf_unfiltered(gdb_stderr
, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
662 (int) entry
->rec_type
,
664 fprintf_unfiltered(gdb_stderr
, "Last unknown_3 value: %d\n", lu3
);
668 last_type
= entry
->rec_type
;
669 if (size
& 1) /* Align on a word boundary */
676 static int next_dst_entry(buffer
, entry
, table
)
678 dst_rec_ptr_t
*entry
;
681 if (*buffer
- table
->buffer
>= table
->size
)
686 *buffer
+= get_dst_entry(*buffer
, entry
);
690 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
691 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
692 #define DST_OFFSET(a, b) ((char *) (a) + (b))
694 static dst_rec_ptr_t section_table
= NULL
;
700 dst_sec
*section
= NULL
;
703 if (!section_table
|| !ref
->sect_index
)
705 offset
= DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
707 if (offset
>= blocks_info
.base
&&
708 offset
< blocks_info
.base
+ blocks_info
.size
)
709 section
= &blocks_info
;
710 else if (offset
>= symbols_info
.base
&&
711 offset
< symbols_info
.base
+ symbols_info
.size
)
712 section
= &symbols_info
;
713 else if (offset
>= lines_info
.base
&&
714 offset
< lines_info
.base
+ lines_info
.size
)
715 section
= &lines_info
;
718 return section
->buffer
+ (offset
- section
->base
);
722 dst_get_addr(int section
, long offset
)
724 if (!section_table
|| !section
)
726 return DST_section_tab(section_table
).section_base
[section
-1] + offset
;
733 if (!section_table
|| !ref
->sect_index
)
735 return DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
740 create_new_type(objfile
)
741 struct objfile
*objfile
;
745 type
= (struct type
*)
746 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct type
));
747 memset(type
, 0, sizeof(struct type
));
751 static struct symbol
*
752 create_new_symbol(objfile
, name
)
753 struct objfile
*objfile
;
756 struct symbol
*sym
= (struct symbol
*)
757 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
758 memset (sym
, 0, sizeof (struct symbol
));
759 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
760 &objfile
->symbol_obstack
);
761 SYMBOL_VALUE (sym
) = 0;
762 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
764 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
769 decode_dst_type
PARAMS ((struct objfile
*, dst_rec_ptr_t
));
772 decode_type_desc(objfile
, type_desc
, base
)
773 struct objfile
*objfile
;
774 dst_type_t
*type_desc
;
779 if (type_desc
->std_type
.user_defined_type
)
781 entry
= (dst_rec_ptr_t
) DST_OFFSET(base
,
782 dst_user_type_offset(*type_desc
));
783 type
= decode_dst_type(objfile
, entry
);
787 switch(type_desc
->std_type
.dtc
)
790 type
= builtin_type_signed_char
;
793 type
= builtin_type_short
;
796 type
= builtin_type_long
;
799 type
= builtin_type_unsigned_char
;
801 case dst_uint16_type
:
802 type
= builtin_type_unsigned_short
;
804 case dst_uint32_type
:
805 type
= builtin_type_unsigned_long
;
807 case dst_real32_type
:
808 type
= builtin_type_float
;
810 case dst_real64_type
:
811 type
= builtin_type_double
;
813 case dst_complex_type
:
814 type
= builtin_type_complex
;
816 case dst_dcomplex_type
:
817 type
= builtin_type_double_complex
;
820 type
= builtin_type_char
;
822 case dst_bool16_type
:
823 type
= builtin_type_short
;
825 case dst_bool32_type
:
826 type
= builtin_type_long
;
829 type
= builtin_type_char
;
831 /* The next few are more complex. I will take care
832 * of them properly at a later point.
834 case dst_string_type
:
835 type
= builtin_type_void
;
838 type
= builtin_type_void
;
841 type
= builtin_type_void
;
844 type
= builtin_type_void
;
847 type
= builtin_type_void
;
849 /* Back tto some ordinary ones */
851 type
= builtin_type_void
;
854 type
= builtin_type_unsigned_char
;
857 type
= builtin_type_void
;
864 struct structure_list
866 struct structure_list
*next
;
870 static struct structure_list
*struct_list
= NULL
;
873 find_dst_structure(name
)
876 struct structure_list
*element
;
878 for (element
= struct_list
; element
; element
= element
->next
)
879 if (!strcmp(name
, TYPE_NAME(element
->type
)))
880 return element
->type
;
886 decode_dst_structure(objfile
, entry
, code
, version
)
887 struct objfile
*objfile
;
892 struct type
*type
, *child_type
;
894 char *name
, *field_name
;
896 int fieldoffset
, fieldsize
;
897 dst_type_t type_desc
;
898 struct structure_list
*element
;
900 struct_name
= DST_OFFSET(entry
, DST_record(entry
).noffset
);
901 name
= concat( (code
== TYPE_CODE_UNION
)?"union ":"struct ",
903 type
= find_dst_structure(name
);
909 type
= create_new_type(objfile
);
910 TYPE_NAME(type
) = obstack_copy0 (&objfile
->symbol_obstack
,
913 TYPE_CODE(type
) = code
;
914 TYPE_LENGTH(type
) = DST_record(entry
).size
;
915 TYPE_NFIELDS(type
) = DST_record(entry
).nfields
;
916 TYPE_FIELDS(type
) = (struct field
*)
917 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) *
918 DST_record(entry
).nfields
);
919 fieldoffset
= fieldsize
= 0;
920 INIT_CPLUS_SPECIFIC(type
);
921 element
= (struct structure_list
*)
922 xmalloc(sizeof(struct structure_list
));
923 element
->type
= type
;
924 element
->next
= struct_list
;
925 struct_list
= element
;
926 for (i
= 0; i
< DST_record(entry
).nfields
; i
++)
931 field_name
= DST_OFFSET(entry
,
932 DST_record(entry
).f
.ofields
[i
].noffset
);
933 fieldoffset
= DST_record(entry
).f
.ofields
[i
].foffset
*8 +
934 DST_record(entry
).f
.ofields
[i
].bit_offset
;
935 fieldsize
= DST_record(entry
).f
.ofields
[i
].size
;
936 type_desc
= DST_record(entry
).f
.ofields
[i
].type_desc
;
939 field_name
= DST_OFFSET(entry
,
940 DST_record(entry
).f
.fields
[i
].noffset
);
941 type_desc
= DST_record(entry
).f
.fields
[i
].type_desc
;
942 switch(DST_record(entry
).f
.fields
[i
].f
.field_loc
.format_tag
)
945 fieldoffset
= DST_record(entry
).f
.
946 fields
[i
].f
.field_byte
.offset
* 8;
950 fieldoffset
= DST_record(entry
).f
.
951 fields
[i
].f
.field_bit
.byte_offset
* 8 +
953 fields
[i
].f
.field_bit
.bit_offset
;
954 fieldsize
= DST_record(entry
).f
.
955 fields
[i
].f
.field_bit
.nbits
;
958 fieldoffset
+= fieldsize
;
964 field_name
= DST_OFFSET(entry
,
965 DST_record(entry
).f
.sfields
[i
].noffset
);
966 fieldoffset
= DST_record(entry
).f
.sfields
[i
].foffset
;
967 type_desc
= DST_record(entry
).f
.sfields
[i
].type_desc
;
968 if (i
< DST_record(entry
).nfields
- 1)
969 fieldsize
= DST_record(entry
).f
.sfields
[i
+1].foffset
;
971 fieldsize
= DST_record(entry
).size
;
972 fieldsize
-= fieldoffset
;
976 TYPE_FIELDS(type
)[i
].name
=
977 obstack_copy0 (&objfile
->symbol_obstack
,
978 field_name
, strlen(field_name
));
979 TYPE_FIELDS(type
)[i
].type
= decode_type_desc(objfile
,
983 fieldsize
= TYPE_LENGTH(TYPE_FIELDS(type
)[i
].type
) *
985 TYPE_FIELDS(type
)[i
].bitsize
= fieldsize
;
986 TYPE_FIELDS(type
)[i
].bitpos
= fieldoffset
;
992 decode_dst_type(objfile
, entry
)
993 struct objfile
*objfile
;
996 struct type
*child_type
, *type
, *range_type
, *index_type
;
998 switch(entry
->rec_type
)
1001 return decode_type_desc(objfile
,
1002 &DST_var(entry
).type_desc
,
1005 case dst_typ_variable
:
1006 return decode_type_desc(objfile
,
1007 &DST_variable(entry
).type_desc
,
1010 case dst_typ_short_rec
:
1011 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,0);
1012 case dst_typ_short_union
:
1013 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 0);
1015 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 1);
1016 case dst_typ_record
:
1017 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,1);
1018 case dst_typ_old_union
:
1019 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 2);
1020 case dst_typ_old_record
:
1021 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,2);
1022 case dst_typ_pointer
:
1023 return make_pointer_type(
1024 decode_type_desc(objfile
,
1025 &DST_pointer(entry
).type_desc
,
1029 child_type
= decode_type_desc(objfile
,
1030 &DST_pointer(entry
).type_desc
,
1032 index_type
= lookup_fundamental_type(objfile
,
1034 range_type
= create_range_type ((struct type
*) NULL
,
1035 index_type
, DST_array(entry
).lo_bound
,
1036 DST_array(entry
).hi_bound
);
1037 return create_array_type ((struct type
*) NULL
, child_type
,
1040 return decode_type_desc(objfile
,
1041 &DST_alias(entry
).type_desc
,
1044 return builtin_type_int
;
1048 struct symbol_list
{
1049 struct symbol_list
*next
;
1050 struct symbol
*symbol
;
1053 static struct symbol_list
*dst_global_symbols
= NULL
;
1054 static int total_globals
= 0;
1057 decode_dst_locstring(locstr
, sym
)
1061 dst_loc_entry_t
*entry
, *next_entry
;
1069 fprintf_unfiltered(gdb_stderr
, "Error reading locstring\n");
1072 entry
= (dst_loc_entry_t
*) locstr
;
1073 next_entry
= (dst_loc_entry_t
*) (locstr
+ 1);
1074 switch (entry
->header
.code
)
1076 case dst_lsc_end
: /* End of string */
1078 case dst_lsc_indirect
:/* Indirect through previous. Arg == 6 */
1079 /* Or register ax x == arg */
1080 if (entry
->header
.arg
< 6)
1082 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1083 SYMBOL_VALUE(sym
) = entry
->header
.arg
+ 8;
1085 /* We predict indirects */
1089 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1090 SYMBOL_VALUE(sym
) = entry
->header
.arg
;
1093 case dst_lsc_section
:/* Section (arg+1) */
1094 SYMBOL_VALUE(sym
) = dst_get_addr(entry
->header
.arg
+1, 0);
1097 case dst_lsc_sec_byte
: /* Section (next_byte+1) */
1098 SYMBOL_VALUE(sym
) = dst_get_addr(locstr
[1]+1, 0);
1101 case dst_lsc_add
: /* Add (arg+1)*2 */
1102 case dst_lsc_sub
: /* Subtract (arg+1)*2 */
1103 temp
= (entry
->header
.arg
+ 1) * 2;
1105 if (*locstr
== dst_multiply_256
)
1110 switch(entry
->header
.code
)
1113 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1114 SYMBOL_CLASS(sym
) = LOC_ARG
;
1115 SYMBOL_VALUE(sym
) += temp
;
1118 SYMBOL_VALUE(sym
) -= temp
;
1122 case dst_lsc_add_byte
:
1123 case dst_lsc_sub_byte
:
1124 switch (entry
->header
.arg
& 0x03)
1127 temp
= (unsigned char) locstr
[1];
1131 temp
= * (unsigned short *) (locstr
+ 1);
1135 temp
= * (unsigned long *) (locstr
+ 1);
1139 if (*locstr
== dst_multiply_256
)
1144 switch(entry
->header
.code
)
1146 case dst_lsc_add_byte
:
1147 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1148 SYMBOL_CLASS(sym
) = LOC_ARG
;
1149 SYMBOL_VALUE(sym
) += temp
;
1151 case dst_lsc_sub_byte
:
1152 SYMBOL_VALUE(sym
) -= temp
;
1156 case dst_lsc_sbreg
: /* Stack base register (frame pointer). Arg==0*/
1157 if (next_entry
->header
.code
!= dst_lsc_indirect
)
1159 SYMBOL_VALUE(sym
) = 0;
1160 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1163 SYMBOL_VALUE(sym
) = 0;
1164 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1168 SYMBOL_VALUE(sym
) = 0;
1169 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1175 static struct symbol_list
*
1176 process_dst_symbols(objfile
, entry
, name
, nsyms_ret
)
1177 struct objfile
*objfile
;
1178 dst_rec_ptr_t entry
;
1182 struct symbol_list
*list
= NULL
, *element
;
1190 dst_var_attr_t attr
;
1191 dst_var_loc_t loc_type
;
1200 location
= (char *) entry
;
1201 while (NEXT_SYM(&location
, &entry
) &&
1202 entry
->rec_type
!= dst_typ_end_scope
)
1204 if (entry
->rec_type
== dst_typ_var
)
1206 if (DST_var(entry
).short_locs
)
1208 loc_type
= DST_var(entry
).locs
.shorts
[0].loc_type
;
1209 loc_index
= DST_var(entry
).locs
.shorts
[0].loc_index
;
1210 loc_value
= DST_var(entry
).locs
.shorts
[0].location
;
1214 loc_type
= DST_var(entry
).locs
.longs
[0].loc_type
;
1215 loc_index
= DST_var(entry
).locs
.longs
[0].loc_index
;
1216 loc_value
= DST_var(entry
).locs
.longs
[0].location
;
1218 if (loc_type
== dst_var_loc_external
)
1220 symname
= DST_OFFSET(entry
, DST_var(entry
).noffset
);
1221 line
= DST_var(entry
).src_loc
.line_number
;
1222 symtype
= DST_var(entry
).type_desc
;
1223 attr
= DST_var(entry
).attributes
;
1225 else if (entry
->rec_type
== dst_typ_variable
)
1227 symname
= DST_OFFSET(entry
,
1228 DST_variable(entry
).noffset
);
1229 line
= DST_variable(entry
).src_loc
.line_number
;
1230 symtype
= DST_variable(entry
).type_desc
;
1231 attr
= DST_variable(entry
).attributes
;
1237 if (symname
&& name
&& !strcmp(symname
, name
))
1238 /* It's the function return value */
1240 sym
= create_new_symbol(objfile
, symname
);
1242 if ((attr
& (1<<dst_var_attr_global
)) ||
1243 (attr
& (1<<dst_var_attr_static
)))
1244 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1246 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1247 SYMBOL_LINE(sym
) = line
;
1248 SYMBOL_TYPE(sym
) = decode_type_desc(objfile
, &symtype
,
1250 SYMBOL_VALUE(sym
) = 0;
1251 switch (entry
->rec_type
)
1256 case dst_var_loc_abs
:
1257 SYMBOL_VALUE_ADDRESS(sym
) = loc_value
;
1259 case dst_var_loc_sect_off
:
1260 case dst_var_loc_ind_sect_off
: /* What is this? */
1261 SYMBOL_VALUE_ADDRESS(sym
) = dst_get_addr(
1265 case dst_var_loc_ind_reg_rel
: /* What is this? */
1266 case dst_var_loc_reg_rel
:
1267 /* If it isn't fp relative, specify the
1268 * register it's relative to.
1272 sym
->aux_value
.basereg
= loc_index
;
1274 SYMBOL_VALUE(sym
) = loc_value
;
1275 if (loc_value
> 0 &&
1276 SYMBOL_CLASS(sym
) == LOC_BASEREG
)
1277 SYMBOL_CLASS(sym
) = LOC_BASEREG_ARG
;
1279 case dst_var_loc_reg
:
1280 SYMBOL_VALUE(sym
) = loc_index
;
1281 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1285 case dst_typ_variable
:
1286 /* External variable..... don't try to interpret
1287 * its nonexistant locstring.
1289 if (DST_variable(entry
).loffset
== -1)
1291 decode_dst_locstring(DST_OFFSET(entry
,
1292 DST_variable(entry
).loffset
),
1295 element
= (struct symbol_list
*)
1296 xmalloc(sizeof(struct symbol_list
));
1298 if (attr
& (1<<dst_var_attr_global
))
1300 element
->next
= dst_global_symbols
;
1301 dst_global_symbols
= element
;
1306 element
->next
= list
;
1310 element
->symbol
= sym
;
1317 static struct symbol
*
1318 process_dst_function(objfile
, entry
, name
, address
)
1319 struct objfile
*objfile
;
1320 dst_rec_ptr_t entry
;
1325 struct type
*type
, *ftype
;
1326 dst_rec_ptr_t sym_entry
, typ_entry
;
1328 struct symbol_list
*element
;
1330 type
= builtin_type_int
;
1331 sym
= create_new_symbol(objfile
, name
);
1332 SYMBOL_CLASS(sym
) = LOC_BLOCK
;
1336 location
= (char *) entry
;
1339 NEXT_SYM(&location
, &sym_entry
);
1340 } while (sym_entry
&& sym_entry
->rec_type
!= dst_typ_signature
);
1345 DST_signature(sym_entry
).src_loc
.line_number
;
1346 if (DST_signature(sym_entry
).result
)
1348 typ_entry
= (dst_rec_ptr_t
)
1349 DST_OFFSET(sym_entry
,
1350 DST_signature(sym_entry
).result
);
1351 type
= decode_dst_type(objfile
, typ_entry
);
1356 if (!type
->function_type
)
1358 ftype
= create_new_type(objfile
);
1359 type
->function_type
= ftype
;
1360 ftype
->target_type
= type
;
1361 ftype
->code
= TYPE_CODE_FUNC
;
1363 SYMBOL_TYPE(sym
) = type
->function_type
;
1365 /* Now add ourselves to the global symbols list */
1366 element
= (struct symbol_list
*)
1367 xmalloc(sizeof(struct symbol_list
));
1369 element
->next
= dst_global_symbols
;
1370 dst_global_symbols
= element
;
1372 element
->symbol
= sym
;
1377 static struct block
*
1378 process_dst_block(objfile
, entry
)
1379 struct objfile
*objfile
;
1380 dst_rec_ptr_t entry
;
1382 struct block
*block
;
1383 struct symbol
*function
= NULL
;
1387 dst_rec_ptr_t child_entry
, symbol_entry
;
1388 struct block
*child_block
;
1389 int total_symbols
= 0;
1391 static long fake_seq
= 0;
1392 struct symbol_list
*symlist
, *nextsym
;
1395 if (DST_block(entry
).noffset
)
1396 name
= DST_OFFSET(entry
, DST_block(entry
).noffset
);
1399 if (DST_block(entry
).n_of_code_ranges
)
1401 address
= dst_sym_addr(
1402 &DST_block(entry
).code_ranges
[0].code_start
);
1403 size
= DST_block(entry
).code_ranges
[0].code_size
;
1410 symbol_entry
= (dst_rec_ptr_t
) get_sec_ref(&DST_block(entry
).symbols_start
);
1411 switch(DST_block(entry
).block_type
)
1413 /* These are all really functions. Even the "program" type.
1414 * This is because the Apollo OS was written in Pascal, and
1415 * in Pascal, the main procedure is described as the Program.
1418 case dst_block_procedure
:
1419 case dst_block_function
:
1420 case dst_block_subroutine
:
1421 case dst_block_program
:
1422 prim_record_minimal_symbol(name
, address
, mst_text
, objfile
);
1423 function
= process_dst_function(
1428 enter_all_lines(get_sec_ref(&DST_block(entry
).code_ranges
[0].lines_start
), address
);
1430 case dst_block_block_data
:
1434 /* GDB has to call it something, and the module name
1437 sprintf(fake_name
, "block_%08lx", fake_seq
++);
1438 function
= process_dst_function(
1439 objfile
, NULL
, fake_name
, address
);
1442 symlist
= process_dst_symbols(objfile
, symbol_entry
,
1443 name
, &total_symbols
);
1444 block
= (struct block
*)
1445 obstack_alloc (&objfile
->symbol_obstack
,
1446 sizeof (struct block
) +
1447 (total_symbols
- 1) * sizeof (struct symbol
*));
1452 nextsym
= symlist
->next
;
1454 block
->sym
[symnum
] = symlist
->symbol
;
1456 free((PTR
) symlist
);
1460 BLOCK_NSYMS (block
) = total_symbols
;
1461 BLOCK_START (block
) = address
;
1462 BLOCK_END (block
) = address
+ size
;
1463 BLOCK_SUPERBLOCK (block
) = 0;
1466 SYMBOL_BLOCK_VALUE (function
) = block
;
1467 BLOCK_FUNCTION (block
) = function
;
1470 BLOCK_FUNCTION (block
) = 0;
1472 if (DST_block(entry
).child_block_off
)
1474 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1475 DST_block(entry
).child_block_off
);
1478 child_block
= process_dst_block(objfile
, child_entry
);
1481 if (BLOCK_START(child_block
) <
1482 BLOCK_START(block
) ||
1483 BLOCK_START(block
) == -1)
1484 BLOCK_START(block
) =
1485 BLOCK_START(child_block
);
1486 if (BLOCK_END(child_block
) >
1488 BLOCK_END(block
) == -1)
1490 BLOCK_END(child_block
);
1491 BLOCK_SUPERBLOCK (child_block
) = block
;
1493 if (DST_block(child_entry
).sibling_block_off
)
1494 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(
1496 DST_block(child_entry
).sibling_block_off
);
1501 record_pending_block (objfile
, block
, NULL
);
1507 read_dst_symtab (objfile
)
1508 struct objfile
*objfile
;
1511 dst_rec_ptr_t entry
, file_table
, root_block
;
1513 struct block
*block
, *global_block
;
1515 struct symbol_list
*nextsym
;
1517 struct structure_list
*element
;
1519 current_objfile
= objfile
;
1520 buffer
= blocks_info
.buffer
;
1521 while (NEXT_BLK(&buffer
, &entry
))
1523 if (entry
->rec_type
== dst_typ_comp_unit
)
1525 file_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1526 DST_comp_unit(entry
).file_table
);
1527 section_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1528 DST_comp_unit(entry
).section_table
);
1529 root_block
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1530 DST_comp_unit(entry
).root_block_offset
);
1531 source_file
= DST_OFFSET(file_table
,
1532 DST_file_tab(file_table
).files
[0].noffset
);
1533 /* Point buffer to the start of the next comp_unit */
1534 buffer
= DST_OFFSET(entry
,
1535 DST_comp_unit(entry
).data_size
);
1538 block
= process_dst_block(objfile
, root_block
);
1540 global_block
= (struct block
*)
1541 obstack_alloc (&objfile
->symbol_obstack
,
1542 sizeof (struct block
) +
1543 (total_globals
- 1) *
1544 sizeof (struct symbol
*));
1545 BLOCK_NSYMS(global_block
) = total_globals
;
1546 for (symnum
= 0; symnum
< total_globals
; symnum
++)
1548 nextsym
= dst_global_symbols
->next
;
1550 global_block
->sym
[symnum
] =
1551 dst_global_symbols
->symbol
;
1553 free((PTR
) dst_global_symbols
);
1554 dst_global_symbols
= nextsym
;
1556 dst_global_symbols
= NULL
;
1558 BLOCK_FUNCTION(global_block
) = 0;
1559 BLOCK_START(global_block
) = BLOCK_START(block
);
1560 BLOCK_END(global_block
) = BLOCK_END(block
);
1561 BLOCK_SUPERBLOCK(global_block
) = 0;
1562 BLOCK_SUPERBLOCK(block
) = global_block
;
1563 record_pending_block (objfile
, global_block
, NULL
);
1565 complete_symtab(source_file
,
1567 BLOCK_END(block
) - BLOCK_START(block
));
1569 dst_end_symtab(objfile
);
1573 prim_record_minimal_symbol("<end_of_program>",
1574 BLOCK_END(block
), mst_text
, objfile
);
1575 /* One more faked symbol to make sure nothing can ever run off the
1576 * end of the symbol table. This one represents the end of the
1577 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1578 * int possible), but some parts of gdb treated it as a signed
1579 * number and failed comparisons. We could equally use 7fffffff,
1580 * but no functions are ever mapped to an address higher than
1583 prim_record_minimal_symbol("<end_of_text>",
1584 (CORE_ADDR
) 0x40000000,
1588 element
= struct_list
;
1589 struct_list
= element
->next
;
1590 free((PTR
) element
);
1595 /* Support for line number handling */
1596 static char *linetab
= NULL
;
1597 static long linetab_offset
;
1598 static unsigned long linetab_size
;
1600 /* Read in all the line numbers for fast lookups later. Leave them in
1601 external (unswapped) format in memory; we'll swap them as we enter
1602 them into GDB's data structures. */
1604 init_one_section(chan
, secinfo
)
1608 if (secinfo
->size
== 0
1609 || lseek(chan
, secinfo
->position
, 0) == -1
1610 || (secinfo
->buffer
= xmalloc(secinfo
->size
)) == NULL
1611 || myread(chan
, secinfo
->buffer
, secinfo
->size
) == -1)
1618 init_dst_sections (chan
)
1622 if (!init_one_section(chan
, &blocks_info
) ||
1623 !init_one_section(chan
, &lines_info
) ||
1624 !init_one_section(chan
, &symbols_info
))
1630 /* Fake up support for relocating symbol addresses. FIXME. */
1632 struct section_offsets dst_symfile_faker
= {0};
1634 struct section_offsets
*
1635 dst_symfile_offsets (objfile
, addr
)
1636 struct objfile
*objfile
;
1639 objfile
->num_sections
= 1;
1640 return &dst_symfile_faker
;
1643 /* Register our ability to parse symbols for DST BFD files */
1645 static struct sym_fns dst_sym_fns
=
1647 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1648 a separate flavour like ecoff? */
1649 (enum bfd_flavour
)-2,
1651 dst_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1652 dst_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1653 dst_symfile_read
, /* sym_read: read a symbol file into symtab */
1654 dst_symfile_finish
, /* sym_finish: finished with file, cleanup */
1655 dst_symfile_offsets
, /* sym_offsets: xlate external to internal form */
1656 NULL
/* next: pointer to next struct sym_fns */
1660 _initialize_dstread ()
1662 add_symtab_fns(&dst_sym_fns
);