1 /* Read apollo DST symbol tables and convert to internal format, for GDB.
2 Contributed by Troy Rollo, University of NSW (troy@cbme.unsw.edu.au).
3 Copyright 1993 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "breakpoint.h"
32 #include "gdb_string.h"
36 CORE_ADDR cur_src_start_addr
, cur_src_end_addr
;
37 dst_sec blocks_info
, lines_info
, symbols_info
;
39 /* Vector of line number information. */
41 static struct linetable
*line_vector
;
43 /* Index of next entry to go in line_vector_index. */
45 static int line_vector_index
;
47 /* Last line number recorded in the line vector. */
49 static int prev_line_number
;
51 /* Number of elements allocated for line_vector currently. */
53 static int line_vector_length
;
55 static int init_dst_sections (int);
57 static void read_dst_symtab (struct objfile
*);
59 static void find_dst_sections (bfd
*, sec_ptr
, PTR
);
61 static void dst_symfile_init (struct objfile
*);
63 static void dst_new_init (struct objfile
*);
65 static void dst_symfile_read (struct objfile
*, int);
67 static void dst_symfile_finish (struct objfile
*);
69 static void dst_end_symtab (struct objfile
*);
71 static void complete_symtab (char *, CORE_ADDR
, unsigned int);
73 static void dst_start_symtab (void);
75 static void dst_record_line (int, CORE_ADDR
);
77 /* Manage the vector of line numbers. */
78 /* FIXME: Use record_line instead. */
81 dst_record_line (line
, pc
)
85 struct linetable_entry
*e
;
86 /* Make sure line vector is big enough. */
88 if (line_vector_index
+ 2 >= line_vector_length
)
90 line_vector_length
*= 2;
91 line_vector
= (struct linetable
*)
92 xrealloc ((char *) line_vector
, sizeof (struct linetable
)
94 * sizeof (struct linetable_entry
)));
97 e
= line_vector
->item
+ line_vector_index
++;
102 /* Start a new symtab for a new source file.
103 It indicates the start of data for one original source file. */
104 /* FIXME: use start_symtab, like coffread.c now does. */
109 /* Initialize the source file line number information for this file. */
111 if (line_vector
) /* Unlikely, but maybe possible? */
112 free ((PTR
) line_vector
);
113 line_vector_index
= 0;
114 line_vector_length
= 1000;
115 prev_line_number
= -2; /* Force first line number to be explicit */
116 line_vector
= (struct linetable
*)
117 xmalloc (sizeof (struct linetable
)
118 + line_vector_length
* sizeof (struct linetable_entry
));
121 /* Save the vital information from when starting to read a file,
122 for use when closing off the current file.
123 NAME is the file name the symbols came from, START_ADDR is the first
124 text address for the file, and SIZE is the number of bytes of text. */
127 complete_symtab (name
, start_addr
, size
)
129 CORE_ADDR start_addr
;
132 last_source_file
= savestring (name
, strlen (name
));
133 cur_src_start_addr
= start_addr
;
134 cur_src_end_addr
= start_addr
+ size
;
136 if (current_objfile
->ei
.entry_point
>= cur_src_start_addr
&&
137 current_objfile
->ei
.entry_point
< cur_src_end_addr
)
139 current_objfile
->ei
.entry_file_lowpc
= cur_src_start_addr
;
140 current_objfile
->ei
.entry_file_highpc
= cur_src_end_addr
;
144 /* Finish the symbol definitions for one main source file,
145 close off all the lexical contexts for that file
146 (creating struct block's for them), then make the
147 struct symtab for that file and put it in the list of all such. */
148 /* FIXME: Use end_symtab, like coffread.c now does. */
151 dst_end_symtab (objfile
)
152 struct objfile
*objfile
;
154 register struct symtab
*symtab
;
155 register struct blockvector
*blockvector
;
156 register struct linetable
*lv
;
158 /* Create the blockvector that points to all the file's blocks. */
160 blockvector
= make_blockvector (objfile
);
162 /* Now create the symtab object for this source file. */
163 symtab
= allocate_symtab (last_source_file
, objfile
);
165 /* Fill in its components. */
166 symtab
->blockvector
= blockvector
;
167 symtab
->free_code
= free_linetable
;
168 symtab
->free_ptr
= 0;
169 symtab
->filename
= last_source_file
;
170 symtab
->dirname
= NULL
;
171 symtab
->debugformat
= obsavestring ("Apollo DST", 10,
172 &objfile
->symbol_obstack
);
174 lv
->nitems
= line_vector_index
;
175 symtab
->linetable
= (struct linetable
*)
176 xrealloc ((char *) lv
, (sizeof (struct linetable
)
177 + lv
->nitems
* sizeof (struct linetable_entry
)));
179 free_named_symtabs (symtab
->filename
);
181 /* Reinitialize for beginning of new file. */
183 line_vector_length
= -1;
184 last_source_file
= NULL
;
187 /* dst_symfile_init ()
188 is the dst-specific initialization routine for reading symbols.
190 We will only be called if this is a DST or DST-like file.
191 BFD handles figuring out the format of the file, and code in symtab.c
192 uses BFD's determination to vector to us.
194 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
197 dst_symfile_init (objfile
)
198 struct objfile
*objfile
;
201 bfd
*abfd
= objfile
->obfd
;
203 init_entry_point_info (objfile
);
207 /* This function is called for every section; it finds the outer limits
208 of the line table (minimum and maximum file offset) so that the
209 mainline code can read the whole thing for efficiency. */
213 find_dst_sections (abfd
, asect
, vpinfo
)
220 file_ptr offset
, maxoff
;
223 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
224 size
= asect
->_raw_size
;
225 offset
= asect
->filepos
;
230 if (!strcmp (asect
->name
, ".blocks"))
231 section
= &blocks_info
;
232 else if (!strcmp (asect
->name
, ".lines"))
233 section
= &lines_info
;
234 else if (!strcmp (asect
->name
, ".symbols"))
235 section
= &symbols_info
;
238 section
->size
= size
;
239 section
->position
= offset
;
240 section
->base
= base
;
244 /* The BFD for this file -- only good while we're actively reading
245 symbols into a psymtab or a symtab. */
247 static bfd
*symfile_bfd
;
249 /* Read a symbol file, after initialization by dst_symfile_init. */
250 /* FIXME! Addr and Mainline are not used yet -- this will not work for
251 shared libraries or add_file! */
255 dst_symfile_read (objfile
, mainline
)
256 struct objfile
*objfile
;
259 bfd
*abfd
= objfile
->obfd
;
260 char *name
= bfd_get_filename (abfd
);
265 int stringtab_offset
;
267 symfile_bfd
= abfd
; /* Kludge for swap routines */
269 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
270 desc
= fileno ((FILE *) (abfd
->iostream
)); /* File descriptor */
272 /* Read the line number table, all at once. */
273 bfd_map_over_sections (abfd
, find_dst_sections
, (PTR
) NULL
);
275 val
= init_dst_sections (desc
);
277 error ("\"%s\": error reading debugging symbol tables\n", name
);
279 init_minimal_symbol_collection ();
280 make_cleanup_discard_minimal_symbols ();
282 /* Now that the executable file is positioned at symbol table,
283 process it and define symbols accordingly. */
285 read_dst_symtab (objfile
);
287 /* Sort symbols alphabetically within each block. */
291 for (s
= objfile
->symtabs
; s
!= NULL
; s
= s
->next
)
293 sort_symtab_syms (s
);
297 /* Install any minimal symbols that have been collected as the current
298 minimal symbols for this objfile. */
300 install_minimal_symbols (objfile
);
304 dst_new_init (ignore
)
305 struct objfile
*ignore
;
310 /* Perform any local cleanups required when we are done with a particular
311 objfile. I.E, we are in the process of discarding all symbol information
312 for an objfile, freeing up all memory held for it, and unlinking the
313 objfile struct from the global list of known objfiles. */
316 dst_symfile_finish (objfile
)
317 struct objfile
*objfile
;
323 /* Get the next line number from the DST. Returns 0 when we hit an
324 * end directive or cannot continue for any other reason.
326 * Note that ordinary pc deltas are multiplied by two. Apparently
327 * this is what was really intended.
330 get_dst_line (buffer
, pc
)
331 signed char **buffer
;
335 static long last_line
= 0;
336 static int last_file
= 0;
337 dst_ln_entry_ptr_t entry
;
339 dst_src_loc_t
*src_loc
;
346 entry
= (dst_ln_entry_ptr_t
) * buffer
;
348 while (dst_ln_ln_delta (*entry
) == dst_ln_escape_flag
)
350 switch (entry
->esc
.esc_code
)
353 size
= 1; /* pad byte */
356 /* file escape. Next 4 bytes are a dst_src_loc_t */
358 src_loc
= (dst_src_loc_t
*) (*buffer
+ 1);
359 last_line
= src_loc
->line_number
;
360 last_file
= src_loc
->file_index
;
362 case dst_ln_dln1_dpc1
:
363 /* 1 byte line delta, 1 byte pc delta */
364 last_line
+= (*buffer
)[1];
365 last_pc
+= 2 * (unsigned char) (*buffer
)[2];
366 dst_record_line (last_line
, last_pc
);
369 case dst_ln_dln2_dpc2
:
370 /* 2 bytes line delta, 2 bytes pc delta */
371 last_line
+= *(short *) (*buffer
+ 1);
372 last_pc
+= 2 * (*(short *) (*buffer
+ 3));
374 dst_record_line (last_line
, last_pc
);
377 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
378 last_line
= *(unsigned long *) (*buffer
+ 1);
379 last_pc
= *(unsigned long *) (*buffer
+ 5);
381 dst_record_line (last_line
, last_pc
);
383 case dst_ln_dln1_dpc0
:
384 /* 1 byte line delta, pc delta = 0 */
386 last_line
+= (*buffer
)[1];
388 case dst_ln_ln_off_1
:
389 /* statement escape, stmt # = 1 (2nd stmt on line) */
393 /* statement escape, stmt # = next byte */
397 /* entry escape, next byte is entry number */
404 case dst_ln_stmt_end
:
405 /* gap escape, 4 bytes pc delta */
407 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
408 /* Apparently this isn't supposed to actually modify
409 * the pc value. Totally weird.
412 case dst_ln_escape_11
:
413 case dst_ln_escape_12
:
414 case dst_ln_escape_13
:
417 case dst_ln_nxt_byte
:
418 /* This shouldn't happen. If it does, we're SOL */
422 /* end escape, final entry follows */
425 *buffer
+= (size
< 0) ? -size
: size
;
426 entry
= (dst_ln_entry_ptr_t
) * buffer
;
428 last_line
+= dst_ln_ln_delta (*entry
);
429 last_pc
+= entry
->delta
.pc_delta
* 2;
431 dst_record_line (last_line
, last_pc
);
436 enter_all_lines (buffer
, address
)
441 while (get_dst_line (&buffer
, &address
));
445 get_dst_entry (buffer
, ret_entry
)
447 dst_rec_ptr_t
*ret_entry
;
451 static int last_type
;
455 entry
= (dst_rec_ptr_t
) buffer
;
456 switch (entry
->rec_type
)
461 case dst_typ_comp_unit
:
462 size
= sizeof (DST_comp_unit (entry
));
464 case dst_typ_section_tab
:
465 size
= sizeof (DST_section_tab (entry
))
466 + ((int) DST_section_tab (entry
).number_of_sections
467 - dst_dummy_array_size
) * sizeof (long);
469 case dst_typ_file_tab
:
470 size
= sizeof (DST_file_tab (entry
))
471 + ((int) DST_file_tab (entry
).number_of_files
472 - dst_dummy_array_size
) * sizeof (dst_file_desc_t
);
475 size
= sizeof (DST_block (entry
))
476 + ((int) DST_block (entry
).n_of_code_ranges
477 - dst_dummy_array_size
) * sizeof (dst_code_range_t
);
483 size
= sizeof (DST_var (entry
)) -
484 sizeof (dst_var_loc_long_t
) * dst_dummy_array_size
+
485 DST_var (entry
).no_of_locs
*
486 (DST_var (entry
).short_locs
?
487 sizeof (dst_var_loc_short_t
) :
488 sizeof (dst_var_loc_long_t
));
490 case dst_typ_pointer
:
491 size
= sizeof (DST_pointer (entry
));
494 size
= sizeof (DST_array (entry
));
496 case dst_typ_subrange
:
497 size
= sizeof (DST_subrange (entry
));
500 size
= sizeof (DST_set (entry
));
502 case dst_typ_implicit_enum
:
503 size
= sizeof (DST_implicit_enum (entry
))
504 + ((int) DST_implicit_enum (entry
).nelems
505 - dst_dummy_array_size
) * sizeof (dst_rel_offset_t
);
507 case dst_typ_explicit_enum
:
508 size
= sizeof (DST_explicit_enum (entry
))
509 + ((int) DST_explicit_enum (entry
).nelems
510 - dst_dummy_array_size
) * sizeof (dst_enum_elem_t
);
512 case dst_typ_short_rec
:
513 size
= sizeof (DST_short_rec (entry
))
514 + DST_short_rec (entry
).nfields
* sizeof (dst_short_field_t
)
515 - dst_dummy_array_size
* sizeof (dst_field_t
);
517 case dst_typ_short_union
:
518 size
= sizeof (DST_short_union (entry
))
519 + DST_short_union (entry
).nfields
* sizeof (dst_short_field_t
)
520 - dst_dummy_array_size
* sizeof (dst_field_t
);
523 size
= sizeof (DST_file (entry
));
526 size
= sizeof (DST_offset (entry
));
529 size
= sizeof (DST_alias (entry
));
531 case dst_typ_signature
:
532 size
= sizeof (DST_signature (entry
)) +
533 ((int) DST_signature (entry
).nargs
-
534 dst_dummy_array_size
) * sizeof (dst_arg_t
);
539 case dst_typ_old_label
:
540 size
= sizeof (DST_old_label (entry
));
543 size
= sizeof (DST_scope (entry
));
545 case dst_typ_end_scope
:
552 case dst_typ_string_tab
:
553 case dst_typ_global_name_tab
:
554 size
= sizeof (DST_string_tab (entry
))
555 + DST_string_tab (entry
).length
556 - dst_dummy_array_size
;
558 case dst_typ_forward
:
559 size
= sizeof (DST_forward (entry
));
560 get_dst_entry ((char *) entry
+ DST_forward (entry
).rec_off
, &entry
);
562 case dst_typ_aux_size
:
563 size
= sizeof (DST_aux_size (entry
));
565 case dst_typ_aux_align
:
566 size
= sizeof (DST_aux_align (entry
));
568 case dst_typ_aux_field_size
:
569 size
= sizeof (DST_aux_field_size (entry
));
571 case dst_typ_aux_field_off
:
572 size
= sizeof (DST_aux_field_off (entry
));
574 case dst_typ_aux_field_align
:
575 size
= sizeof (DST_aux_field_align (entry
));
577 case dst_typ_aux_qual
:
578 size
= sizeof (DST_aux_qual (entry
));
580 case dst_typ_aux_var_bound
:
581 size
= sizeof (DST_aux_var_bound (entry
));
583 case dst_typ_extension
:
584 size
= DST_extension (entry
).rec_size
;
587 size
= sizeof (DST_string (entry
));
589 case dst_typ_old_entry
:
590 size
= 48; /* Obsolete entry type */
593 size
= sizeof (DST_const (entry
))
594 + DST_const (entry
).value
.length
595 - sizeof (DST_const (entry
).value
.val
);
597 case dst_typ_reference
:
598 size
= sizeof (DST_reference (entry
));
600 case dst_typ_old_record
:
601 case dst_typ_old_union
:
604 size
= sizeof (DST_record (entry
))
605 + ((int) DST_record (entry
).nfields
606 - dst_dummy_array_size
) * sizeof (dst_field_t
);
608 case dst_typ_aux_type_deriv
:
609 size
= sizeof (DST_aux_type_deriv (entry
));
611 case dst_typ_locpool
:
612 size
= sizeof (DST_locpool (entry
))
613 + ((int) DST_locpool (entry
).length
-
614 dst_dummy_array_size
);
616 case dst_typ_variable
:
617 size
= sizeof (DST_variable (entry
));
620 size
= sizeof (DST_label (entry
));
623 size
= sizeof (DST_entry (entry
));
625 case dst_typ_aux_lifetime
:
626 size
= sizeof (DST_aux_lifetime (entry
));
628 case dst_typ_aux_ptr_base
:
629 size
= sizeof (DST_aux_ptr_base (entry
));
631 case dst_typ_aux_src_range
:
632 size
= sizeof (DST_aux_src_range (entry
));
634 case dst_typ_aux_reg_val
:
635 size
= sizeof (DST_aux_reg_val (entry
));
637 case dst_typ_aux_unit_names
:
638 size
= sizeof (DST_aux_unit_names (entry
))
639 + ((int) DST_aux_unit_names (entry
).number_of_names
640 - dst_dummy_array_size
) * sizeof (dst_rel_offset_t
);
642 case dst_typ_aux_sect_info
:
643 size
= sizeof (DST_aux_sect_info (entry
))
644 + ((int) DST_aux_sect_info (entry
).number_of_refs
645 - dst_dummy_array_size
) * sizeof (dst_sect_ref_t
);
653 fprintf_unfiltered (gdb_stderr
, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
654 (int) entry
->rec_type
,
656 fprintf_unfiltered (gdb_stderr
, "Last unknown_3 value: %d\n", lu3
);
660 last_type
= entry
->rec_type
;
661 if (size
& 1) /* Align on a word boundary */
669 next_dst_entry (buffer
, entry
, table
)
671 dst_rec_ptr_t
*entry
;
674 if (*buffer
- table
->buffer
>= table
->size
)
679 *buffer
+= get_dst_entry (*buffer
, entry
);
683 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
684 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
685 #define DST_OFFSET(a, b) ((char *) (a) + (b))
687 static dst_rec_ptr_t section_table
= NULL
;
693 dst_sec
*section
= NULL
;
696 if (!section_table
|| !ref
->sect_index
)
698 offset
= DST_section_tab (section_table
).section_base
[ref
->sect_index
- 1]
700 if (offset
>= blocks_info
.base
&&
701 offset
< blocks_info
.base
+ blocks_info
.size
)
702 section
= &blocks_info
;
703 else if (offset
>= symbols_info
.base
&&
704 offset
< symbols_info
.base
+ symbols_info
.size
)
705 section
= &symbols_info
;
706 else if (offset
>= lines_info
.base
&&
707 offset
< lines_info
.base
+ lines_info
.size
)
708 section
= &lines_info
;
711 return section
->buffer
+ (offset
- section
->base
);
715 dst_get_addr (int section
, long offset
)
717 if (!section_table
|| !section
)
719 return DST_section_tab (section_table
).section_base
[section
- 1] + offset
;
726 if (!section_table
|| !ref
->sect_index
)
728 return DST_section_tab (section_table
).section_base
[ref
->sect_index
- 1]
733 create_new_type (objfile
)
734 struct objfile
*objfile
;
738 type
= (struct type
*)
739 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct type
));
740 memset (type
, 0, sizeof (struct type
));
744 static struct symbol
*
745 create_new_symbol (objfile
, name
)
746 struct objfile
*objfile
;
749 struct symbol
*sym
= (struct symbol
*)
750 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
751 memset (sym
, 0, sizeof (struct symbol
));
752 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
753 &objfile
->symbol_obstack
);
754 SYMBOL_VALUE (sym
) = 0;
755 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
757 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
761 static struct type
*decode_dst_type (struct objfile
*, dst_rec_ptr_t
);
764 decode_type_desc (objfile
, type_desc
, base
)
765 struct objfile
*objfile
;
766 dst_type_t
*type_desc
;
771 if (type_desc
->std_type
.user_defined_type
)
773 entry
= (dst_rec_ptr_t
) DST_OFFSET (base
,
774 dst_user_type_offset (*type_desc
));
775 type
= decode_dst_type (objfile
, entry
);
779 switch (type_desc
->std_type
.dtc
)
782 type
= builtin_type_signed_char
;
785 type
= builtin_type_short
;
788 type
= builtin_type_long
;
791 type
= builtin_type_unsigned_char
;
793 case dst_uint16_type
:
794 type
= builtin_type_unsigned_short
;
796 case dst_uint32_type
:
797 type
= builtin_type_unsigned_long
;
799 case dst_real32_type
:
800 type
= builtin_type_float
;
802 case dst_real64_type
:
803 type
= builtin_type_double
;
805 case dst_complex_type
:
806 type
= builtin_type_complex
;
808 case dst_dcomplex_type
:
809 type
= builtin_type_double_complex
;
812 type
= builtin_type_char
;
814 case dst_bool16_type
:
815 type
= builtin_type_short
;
817 case dst_bool32_type
:
818 type
= builtin_type_long
;
821 type
= builtin_type_char
;
823 /* The next few are more complex. I will take care
824 * of them properly at a later point.
826 case dst_string_type
:
827 type
= builtin_type_void
;
830 type
= builtin_type_void
;
833 type
= builtin_type_void
;
836 type
= builtin_type_void
;
839 type
= builtin_type_void
;
841 /* Back tto some ordinary ones */
843 type
= builtin_type_void
;
846 type
= builtin_type_unsigned_char
;
849 type
= builtin_type_void
;
856 struct structure_list
858 struct structure_list
*next
;
862 static struct structure_list
*struct_list
= NULL
;
865 find_dst_structure (name
)
868 struct structure_list
*element
;
870 for (element
= struct_list
; element
; element
= element
->next
)
871 if (!strcmp (name
, TYPE_NAME (element
->type
)))
872 return element
->type
;
878 decode_dst_structure (objfile
, entry
, code
, version
)
879 struct objfile
*objfile
;
884 struct type
*type
, *child_type
;
886 char *name
, *field_name
;
888 int fieldoffset
, fieldsize
;
889 dst_type_t type_desc
;
890 struct structure_list
*element
;
892 struct_name
= DST_OFFSET (entry
, DST_record (entry
).noffset
);
893 name
= concat ((code
== TYPE_CODE_UNION
) ? "union " : "struct ",
895 type
= find_dst_structure (name
);
901 type
= create_new_type (objfile
);
902 TYPE_NAME (type
) = obstack_copy0 (&objfile
->symbol_obstack
,
903 name
, strlen (name
));
905 TYPE_CODE (type
) = code
;
906 TYPE_LENGTH (type
) = DST_record (entry
).size
;
907 TYPE_NFIELDS (type
) = DST_record (entry
).nfields
;
908 TYPE_FIELDS (type
) = (struct field
*)
909 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) *
910 DST_record (entry
).nfields
);
911 fieldoffset
= fieldsize
= 0;
912 INIT_CPLUS_SPECIFIC (type
);
913 element
= (struct structure_list
*)
914 xmalloc (sizeof (struct structure_list
));
915 element
->type
= type
;
916 element
->next
= struct_list
;
917 struct_list
= element
;
918 for (i
= 0; i
< DST_record (entry
).nfields
; i
++)
923 field_name
= DST_OFFSET (entry
,
924 DST_record (entry
).f
.ofields
[i
].noffset
);
925 fieldoffset
= DST_record (entry
).f
.ofields
[i
].foffset
* 8 +
926 DST_record (entry
).f
.ofields
[i
].bit_offset
;
927 fieldsize
= DST_record (entry
).f
.ofields
[i
].size
;
928 type_desc
= DST_record (entry
).f
.ofields
[i
].type_desc
;
931 field_name
= DST_OFFSET (entry
,
932 DST_record (entry
).f
.fields
[i
].noffset
);
933 type_desc
= DST_record (entry
).f
.fields
[i
].type_desc
;
934 switch (DST_record (entry
).f
.fields
[i
].f
.field_loc
.format_tag
)
937 fieldoffset
= DST_record (entry
).f
.
938 fields
[i
].f
.field_byte
.offset
* 8;
942 fieldoffset
= DST_record (entry
).f
.
943 fields
[i
].f
.field_bit
.byte_offset
* 8 +
944 DST_record (entry
).f
.
945 fields
[i
].f
.field_bit
.bit_offset
;
946 fieldsize
= DST_record (entry
).f
.
947 fields
[i
].f
.field_bit
.nbits
;
950 fieldoffset
+= fieldsize
;
956 field_name
= DST_OFFSET (entry
,
957 DST_record (entry
).f
.sfields
[i
].noffset
);
958 fieldoffset
= DST_record (entry
).f
.sfields
[i
].foffset
;
959 type_desc
= DST_record (entry
).f
.sfields
[i
].type_desc
;
960 if (i
< DST_record (entry
).nfields
- 1)
961 fieldsize
= DST_record (entry
).f
.sfields
[i
+ 1].foffset
;
963 fieldsize
= DST_record (entry
).size
;
964 fieldsize
-= fieldoffset
;
968 TYPE_FIELDS (type
)[i
].name
=
969 obstack_copy0 (&objfile
->symbol_obstack
,
970 field_name
, strlen (field_name
));
971 TYPE_FIELDS (type
)[i
].type
= decode_type_desc (objfile
,
975 fieldsize
= TYPE_LENGTH (TYPE_FIELDS (type
)[i
].type
) *
977 TYPE_FIELDS (type
)[i
].bitsize
= fieldsize
;
978 TYPE_FIELDS (type
)[i
].bitpos
= fieldoffset
;
984 decode_dst_type (objfile
, entry
)
985 struct objfile
*objfile
;
988 struct type
*child_type
, *type
, *range_type
, *index_type
;
990 switch (entry
->rec_type
)
993 return decode_type_desc (objfile
,
994 &DST_var (entry
).type_desc
,
997 case dst_typ_variable
:
998 return decode_type_desc (objfile
,
999 &DST_variable (entry
).type_desc
,
1002 case dst_typ_short_rec
:
1003 return decode_dst_structure (objfile
, entry
, TYPE_CODE_STRUCT
, 0);
1004 case dst_typ_short_union
:
1005 return decode_dst_structure (objfile
, entry
, TYPE_CODE_UNION
, 0);
1007 return decode_dst_structure (objfile
, entry
, TYPE_CODE_UNION
, 1);
1008 case dst_typ_record
:
1009 return decode_dst_structure (objfile
, entry
, TYPE_CODE_STRUCT
, 1);
1010 case dst_typ_old_union
:
1011 return decode_dst_structure (objfile
, entry
, TYPE_CODE_UNION
, 2);
1012 case dst_typ_old_record
:
1013 return decode_dst_structure (objfile
, entry
, TYPE_CODE_STRUCT
, 2);
1014 case dst_typ_pointer
:
1015 return make_pointer_type (
1016 decode_type_desc (objfile
,
1017 &DST_pointer (entry
).type_desc
,
1021 child_type
= decode_type_desc (objfile
,
1022 &DST_pointer (entry
).type_desc
,
1024 index_type
= lookup_fundamental_type (objfile
,
1026 range_type
= create_range_type ((struct type
*) NULL
,
1027 index_type
, DST_array (entry
).lo_bound
,
1028 DST_array (entry
).hi_bound
);
1029 return create_array_type ((struct type
*) NULL
, child_type
,
1032 return decode_type_desc (objfile
,
1033 &DST_alias (entry
).type_desc
,
1036 return builtin_type_int
;
1042 struct symbol_list
*next
;
1043 struct symbol
*symbol
;
1046 static struct symbol_list
*dst_global_symbols
= NULL
;
1047 static int total_globals
= 0;
1050 decode_dst_locstring (locstr
, sym
)
1054 dst_loc_entry_t
*entry
, *next_entry
;
1062 fprintf_unfiltered (gdb_stderr
, "Error reading locstring\n");
1065 entry
= (dst_loc_entry_t
*) locstr
;
1066 next_entry
= (dst_loc_entry_t
*) (locstr
+ 1);
1067 switch (entry
->header
.code
)
1069 case dst_lsc_end
: /* End of string */
1071 case dst_lsc_indirect
: /* Indirect through previous. Arg == 6 */
1072 /* Or register ax x == arg */
1073 if (entry
->header
.arg
< 6)
1075 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1076 SYMBOL_VALUE (sym
) = entry
->header
.arg
+ 8;
1078 /* We predict indirects */
1082 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1083 SYMBOL_VALUE (sym
) = entry
->header
.arg
;
1086 case dst_lsc_section
: /* Section (arg+1) */
1087 SYMBOL_VALUE (sym
) = dst_get_addr (entry
->header
.arg
+ 1, 0);
1090 case dst_lsc_sec_byte
: /* Section (next_byte+1) */
1091 SYMBOL_VALUE (sym
) = dst_get_addr (locstr
[1] + 1, 0);
1094 case dst_lsc_add
: /* Add (arg+1)*2 */
1095 case dst_lsc_sub
: /* Subtract (arg+1)*2 */
1096 temp
= (entry
->header
.arg
+ 1) * 2;
1098 if (*locstr
== dst_multiply_256
)
1103 switch (entry
->header
.code
)
1106 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
)
1107 SYMBOL_CLASS (sym
) = LOC_ARG
;
1108 SYMBOL_VALUE (sym
) += temp
;
1111 SYMBOL_VALUE (sym
) -= temp
;
1115 case dst_lsc_add_byte
:
1116 case dst_lsc_sub_byte
:
1117 switch (entry
->header
.arg
& 0x03)
1120 temp
= (unsigned char) locstr
[1];
1124 temp
= *(unsigned short *) (locstr
+ 1);
1128 temp
= *(unsigned long *) (locstr
+ 1);
1132 if (*locstr
== dst_multiply_256
)
1137 switch (entry
->header
.code
)
1139 case dst_lsc_add_byte
:
1140 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
)
1141 SYMBOL_CLASS (sym
) = LOC_ARG
;
1142 SYMBOL_VALUE (sym
) += temp
;
1144 case dst_lsc_sub_byte
:
1145 SYMBOL_VALUE (sym
) -= temp
;
1149 case dst_lsc_sbreg
: /* Stack base register (frame pointer). Arg==0 */
1150 if (next_entry
->header
.code
!= dst_lsc_indirect
)
1152 SYMBOL_VALUE (sym
) = 0;
1153 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1156 SYMBOL_VALUE (sym
) = 0;
1157 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1161 SYMBOL_VALUE (sym
) = 0;
1162 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1168 static struct symbol_list
*
1169 process_dst_symbols (objfile
, entry
, name
, nsyms_ret
)
1170 struct objfile
*objfile
;
1171 dst_rec_ptr_t entry
;
1175 struct symbol_list
*list
= NULL
, *element
;
1183 dst_var_attr_t attr
;
1184 dst_var_loc_t loc_type
;
1193 location
= (char *) entry
;
1194 while (NEXT_SYM (&location
, &entry
) &&
1195 entry
->rec_type
!= dst_typ_end_scope
)
1197 if (entry
->rec_type
== dst_typ_var
)
1199 if (DST_var (entry
).short_locs
)
1201 loc_type
= DST_var (entry
).locs
.shorts
[0].loc_type
;
1202 loc_index
= DST_var (entry
).locs
.shorts
[0].loc_index
;
1203 loc_value
= DST_var (entry
).locs
.shorts
[0].location
;
1207 loc_type
= DST_var (entry
).locs
.longs
[0].loc_type
;
1208 loc_index
= DST_var (entry
).locs
.longs
[0].loc_index
;
1209 loc_value
= DST_var (entry
).locs
.longs
[0].location
;
1211 if (loc_type
== dst_var_loc_external
)
1213 symname
= DST_OFFSET (entry
, DST_var (entry
).noffset
);
1214 line
= DST_var (entry
).src_loc
.line_number
;
1215 symtype
= DST_var (entry
).type_desc
;
1216 attr
= DST_var (entry
).attributes
;
1218 else if (entry
->rec_type
== dst_typ_variable
)
1220 symname
= DST_OFFSET (entry
,
1221 DST_variable (entry
).noffset
);
1222 line
= DST_variable (entry
).src_loc
.line_number
;
1223 symtype
= DST_variable (entry
).type_desc
;
1224 attr
= DST_variable (entry
).attributes
;
1230 if (symname
&& name
&& !strcmp (symname
, name
))
1231 /* It's the function return value */
1233 sym
= create_new_symbol (objfile
, symname
);
1235 if ((attr
& (1 << dst_var_attr_global
)) ||
1236 (attr
& (1 << dst_var_attr_static
)))
1237 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1239 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1240 SYMBOL_LINE (sym
) = line
;
1241 SYMBOL_TYPE (sym
) = decode_type_desc (objfile
, &symtype
,
1243 SYMBOL_VALUE (sym
) = 0;
1244 switch (entry
->rec_type
)
1249 case dst_var_loc_abs
:
1250 SYMBOL_VALUE_ADDRESS (sym
) = loc_value
;
1252 case dst_var_loc_sect_off
:
1253 case dst_var_loc_ind_sect_off
: /* What is this? */
1254 SYMBOL_VALUE_ADDRESS (sym
) = dst_get_addr (
1258 case dst_var_loc_ind_reg_rel
: /* What is this? */
1259 case dst_var_loc_reg_rel
:
1260 /* If it isn't fp relative, specify the
1261 * register it's relative to.
1265 sym
->aux_value
.basereg
= loc_index
;
1267 SYMBOL_VALUE (sym
) = loc_value
;
1268 if (loc_value
> 0 &&
1269 SYMBOL_CLASS (sym
) == LOC_BASEREG
)
1270 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
1272 case dst_var_loc_reg
:
1273 SYMBOL_VALUE (sym
) = loc_index
;
1274 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1278 case dst_typ_variable
:
1279 /* External variable..... don't try to interpret
1280 * its nonexistant locstring.
1282 if (DST_variable (entry
).loffset
== -1)
1284 decode_dst_locstring (DST_OFFSET (entry
,
1285 DST_variable (entry
).loffset
),
1288 element
= (struct symbol_list
*)
1289 xmalloc (sizeof (struct symbol_list
));
1291 if (attr
& (1 << dst_var_attr_global
))
1293 element
->next
= dst_global_symbols
;
1294 dst_global_symbols
= element
;
1299 element
->next
= list
;
1303 element
->symbol
= sym
;
1310 static struct symbol
*
1311 process_dst_function (objfile
, entry
, name
, address
)
1312 struct objfile
*objfile
;
1313 dst_rec_ptr_t entry
;
1318 struct type
*type
, *ftype
;
1319 dst_rec_ptr_t sym_entry
, typ_entry
;
1321 struct symbol_list
*element
;
1323 type
= builtin_type_int
;
1324 sym
= create_new_symbol (objfile
, name
);
1325 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1329 location
= (char *) entry
;
1332 NEXT_SYM (&location
, &sym_entry
);
1334 while (sym_entry
&& sym_entry
->rec_type
!= dst_typ_signature
);
1339 DST_signature (sym_entry
).src_loc
.line_number
;
1340 if (DST_signature (sym_entry
).result
)
1342 typ_entry
= (dst_rec_ptr_t
)
1343 DST_OFFSET (sym_entry
,
1344 DST_signature (sym_entry
).result
);
1345 type
= decode_dst_type (objfile
, typ_entry
);
1350 if (!type
->function_type
)
1352 ftype
= create_new_type (objfile
);
1353 type
->function_type
= ftype
;
1354 ftype
->target_type
= type
;
1355 ftype
->code
= TYPE_CODE_FUNC
;
1357 SYMBOL_TYPE (sym
) = type
->function_type
;
1359 /* Now add ourselves to the global symbols list */
1360 element
= (struct symbol_list
*)
1361 xmalloc (sizeof (struct symbol_list
));
1363 element
->next
= dst_global_symbols
;
1364 dst_global_symbols
= element
;
1366 element
->symbol
= sym
;
1371 static struct block
*
1372 process_dst_block (objfile
, entry
)
1373 struct objfile
*objfile
;
1374 dst_rec_ptr_t entry
;
1376 struct block
*block
;
1377 struct symbol
*function
= NULL
;
1381 dst_rec_ptr_t child_entry
, symbol_entry
;
1382 struct block
*child_block
;
1383 int total_symbols
= 0;
1385 static long fake_seq
= 0;
1386 struct symbol_list
*symlist
, *nextsym
;
1389 if (DST_block (entry
).noffset
)
1390 name
= DST_OFFSET (entry
, DST_block (entry
).noffset
);
1393 if (DST_block (entry
).n_of_code_ranges
)
1395 address
= dst_sym_addr (
1396 &DST_block (entry
).code_ranges
[0].code_start
);
1397 size
= DST_block (entry
).code_ranges
[0].code_size
;
1404 symbol_entry
= (dst_rec_ptr_t
) get_sec_ref (&DST_block (entry
).symbols_start
);
1405 switch (DST_block (entry
).block_type
)
1407 /* These are all really functions. Even the "program" type.
1408 * This is because the Apollo OS was written in Pascal, and
1409 * in Pascal, the main procedure is described as the Program.
1412 case dst_block_procedure
:
1413 case dst_block_function
:
1414 case dst_block_subroutine
:
1415 case dst_block_program
:
1416 prim_record_minimal_symbol (name
, address
, mst_text
, objfile
);
1417 function
= process_dst_function (
1422 enter_all_lines (get_sec_ref (&DST_block (entry
).code_ranges
[0].lines_start
), address
);
1424 case dst_block_block_data
:
1428 /* GDB has to call it something, and the module name
1431 sprintf (fake_name
, "block_%08lx", fake_seq
++);
1432 function
= process_dst_function (
1433 objfile
, NULL
, fake_name
, address
);
1436 symlist
= process_dst_symbols (objfile
, symbol_entry
,
1437 name
, &total_symbols
);
1438 block
= (struct block
*)
1439 obstack_alloc (&objfile
->symbol_obstack
,
1440 sizeof (struct block
) +
1441 (total_symbols
- 1) * sizeof (struct symbol
*));
1446 nextsym
= symlist
->next
;
1448 block
->sym
[symnum
] = symlist
->symbol
;
1450 free ((PTR
) symlist
);
1454 BLOCK_NSYMS (block
) = total_symbols
;
1455 BLOCK_START (block
) = address
;
1456 BLOCK_END (block
) = address
+ size
;
1457 BLOCK_SUPERBLOCK (block
) = 0;
1460 SYMBOL_BLOCK_VALUE (function
) = block
;
1461 BLOCK_FUNCTION (block
) = function
;
1464 BLOCK_FUNCTION (block
) = 0;
1466 if (DST_block (entry
).child_block_off
)
1468 child_entry
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1469 DST_block (entry
).child_block_off
);
1472 child_block
= process_dst_block (objfile
, child_entry
);
1475 if (BLOCK_START (child_block
) <
1476 BLOCK_START (block
) ||
1477 BLOCK_START (block
) == -1)
1478 BLOCK_START (block
) =
1479 BLOCK_START (child_block
);
1480 if (BLOCK_END (child_block
) >
1481 BLOCK_END (block
) ||
1482 BLOCK_END (block
) == -1)
1484 BLOCK_END (child_block
);
1485 BLOCK_SUPERBLOCK (child_block
) = block
;
1487 if (DST_block (child_entry
).sibling_block_off
)
1488 child_entry
= (dst_rec_ptr_t
) DST_OFFSET (
1490 DST_block (child_entry
).sibling_block_off
);
1495 record_pending_block (objfile
, block
, NULL
);
1501 read_dst_symtab (objfile
)
1502 struct objfile
*objfile
;
1505 dst_rec_ptr_t entry
, file_table
, root_block
;
1507 struct block
*block
, *global_block
;
1509 struct symbol_list
*nextsym
;
1511 struct structure_list
*element
;
1513 current_objfile
= objfile
;
1514 buffer
= blocks_info
.buffer
;
1515 while (NEXT_BLK (&buffer
, &entry
))
1517 if (entry
->rec_type
== dst_typ_comp_unit
)
1519 file_table
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1520 DST_comp_unit (entry
).file_table
);
1521 section_table
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1522 DST_comp_unit (entry
).section_table
);
1523 root_block
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1524 DST_comp_unit (entry
).root_block_offset
);
1525 source_file
= DST_OFFSET (file_table
,
1526 DST_file_tab (file_table
).files
[0].noffset
);
1527 /* Point buffer to the start of the next comp_unit */
1528 buffer
= DST_OFFSET (entry
,
1529 DST_comp_unit (entry
).data_size
);
1530 dst_start_symtab ();
1532 block
= process_dst_block (objfile
, root_block
);
1534 global_block
= (struct block
*)
1535 obstack_alloc (&objfile
->symbol_obstack
,
1536 sizeof (struct block
) +
1537 (total_globals
- 1) *
1538 sizeof (struct symbol
*));
1539 BLOCK_NSYMS (global_block
) = total_globals
;
1540 for (symnum
= 0; symnum
< total_globals
; symnum
++)
1542 nextsym
= dst_global_symbols
->next
;
1544 global_block
->sym
[symnum
] =
1545 dst_global_symbols
->symbol
;
1547 free ((PTR
) dst_global_symbols
);
1548 dst_global_symbols
= nextsym
;
1550 dst_global_symbols
= NULL
;
1552 BLOCK_FUNCTION (global_block
) = 0;
1553 BLOCK_START (global_block
) = BLOCK_START (block
);
1554 BLOCK_END (global_block
) = BLOCK_END (block
);
1555 BLOCK_SUPERBLOCK (global_block
) = 0;
1556 BLOCK_SUPERBLOCK (block
) = global_block
;
1557 record_pending_block (objfile
, global_block
, NULL
);
1559 complete_symtab (source_file
,
1560 BLOCK_START (block
),
1561 BLOCK_END (block
) - BLOCK_START (block
));
1563 dst_end_symtab (objfile
);
1567 prim_record_minimal_symbol ("<end_of_program>",
1568 BLOCK_END (block
), mst_text
, objfile
);
1569 /* One more faked symbol to make sure nothing can ever run off the
1570 * end of the symbol table. This one represents the end of the
1571 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1572 * int possible), but some parts of gdb treated it as a signed
1573 * number and failed comparisons. We could equally use 7fffffff,
1574 * but no functions are ever mapped to an address higher than
1577 prim_record_minimal_symbol ("<end_of_text>",
1578 (CORE_ADDR
) 0x40000000,
1582 element
= struct_list
;
1583 struct_list
= element
->next
;
1584 free ((PTR
) element
);
1589 /* Support for line number handling */
1590 static char *linetab
= NULL
;
1591 static long linetab_offset
;
1592 static unsigned long linetab_size
;
1594 /* Read in all the line numbers for fast lookups later. Leave them in
1595 external (unswapped) format in memory; we'll swap them as we enter
1596 them into GDB's data structures. */
1598 init_one_section (chan
, secinfo
)
1602 if (secinfo
->size
== 0
1603 || lseek (chan
, secinfo
->position
, 0) == -1
1604 || (secinfo
->buffer
= xmalloc (secinfo
->size
)) == NULL
1605 || myread (chan
, secinfo
->buffer
, secinfo
->size
) == -1)
1612 init_dst_sections (chan
)
1616 if (!init_one_section (chan
, &blocks_info
) ||
1617 !init_one_section (chan
, &lines_info
) ||
1618 !init_one_section (chan
, &symbols_info
))
1624 /* Fake up support for relocating symbol addresses. FIXME. */
1626 struct section_offsets dst_symfile_faker
=
1630 dst_symfile_offsets (objfile
, addr
)
1631 struct objfile
*objfile
;
1632 struct section_addr_info
*addrs
;
1634 objfile
->num_sections
= 1;
1635 objfile
->section_offsets
= &dst_symfile_faker
;
1638 /* Register our ability to parse symbols for DST BFD files */
1640 static struct sym_fns dst_sym_fns
=
1642 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1643 a separate flavour like ecoff? */
1644 (enum bfd_flavour
) -2,
1646 dst_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1647 dst_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1648 dst_symfile_read
, /* sym_read: read a symbol file into symtab */
1649 dst_symfile_finish
, /* sym_finish: finished with file, cleanup */
1650 dst_symfile_offsets
, /* sym_offsets: xlate external to internal form */
1651 NULL
/* next: pointer to next struct sym_fns */
1655 _initialize_dstread ()
1657 add_symtab_fns (&dst_sym_fns
);