1 /* Read apollo DST symbol tables and convert to internal format, for GDB.
2 Contributed by Troy Rollo, University of NSW (troy@cbme.unsw.edu.au).
3 Copyright 1993 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "breakpoint.h"
32 #include "gdb_string.h"
36 CORE_ADDR cur_src_start_addr
, cur_src_end_addr
;
37 dst_sec blocks_info
, lines_info
, symbols_info
;
39 /* Vector of line number information. */
41 static struct linetable
*line_vector
;
43 /* Index of next entry to go in line_vector_index. */
45 static int line_vector_index
;
47 /* Last line number recorded in the line vector. */
49 static int prev_line_number
;
51 /* Number of elements allocated for line_vector currently. */
53 static int line_vector_length
;
56 init_dst_sections
PARAMS ((int));
59 read_dst_symtab
PARAMS ((struct objfile
*));
62 find_dst_sections
PARAMS ((bfd
*, sec_ptr
, PTR
));
65 dst_symfile_init
PARAMS ((struct objfile
*));
68 dst_new_init
PARAMS ((struct objfile
*));
71 dst_symfile_read
PARAMS ((struct objfile
*, int));
74 dst_symfile_finish
PARAMS ((struct objfile
*));
77 dst_end_symtab
PARAMS ((struct objfile
*));
80 complete_symtab
PARAMS ((char *, CORE_ADDR
, unsigned int));
83 dst_start_symtab
PARAMS ((void));
86 dst_record_line
PARAMS ((int, CORE_ADDR
));
88 /* Manage the vector of line numbers. */
89 /* FIXME: Use record_line instead. */
92 dst_record_line (line
, pc
)
96 struct linetable_entry
*e
;
97 /* Make sure line vector is big enough. */
99 if (line_vector_index
+ 2 >= line_vector_length
)
101 line_vector_length
*= 2;
102 line_vector
= (struct linetable
*)
103 xrealloc ((char *) line_vector
, sizeof (struct linetable
)
104 + (line_vector_length
105 * sizeof (struct linetable_entry
)));
108 e
= line_vector
->item
+ line_vector_index
++;
113 /* Start a new symtab for a new source file.
114 It indicates the start of data for one original source file. */
115 /* FIXME: use start_symtab, like coffread.c now does. */
120 /* Initialize the source file line number information for this file. */
122 if (line_vector
) /* Unlikely, but maybe possible? */
123 free ((PTR
) line_vector
);
124 line_vector_index
= 0;
125 line_vector_length
= 1000;
126 prev_line_number
= -2; /* Force first line number to be explicit */
127 line_vector
= (struct linetable
*)
128 xmalloc (sizeof (struct linetable
)
129 + line_vector_length
* sizeof (struct linetable_entry
));
132 /* Save the vital information from when starting to read a file,
133 for use when closing off the current file.
134 NAME is the file name the symbols came from, START_ADDR is the first
135 text address for the file, and SIZE is the number of bytes of text. */
138 complete_symtab (name
, start_addr
, size
)
140 CORE_ADDR start_addr
;
143 last_source_file
= savestring (name
, strlen (name
));
144 cur_src_start_addr
= start_addr
;
145 cur_src_end_addr
= start_addr
+ size
;
147 if (current_objfile
->ei
.entry_point
>= cur_src_start_addr
&&
148 current_objfile
->ei
.entry_point
< cur_src_end_addr
)
150 current_objfile
->ei
.entry_file_lowpc
= cur_src_start_addr
;
151 current_objfile
->ei
.entry_file_highpc
= cur_src_end_addr
;
155 /* Finish the symbol definitions for one main source file,
156 close off all the lexical contexts for that file
157 (creating struct block's for them), then make the
158 struct symtab for that file and put it in the list of all such. */
159 /* FIXME: Use end_symtab, like coffread.c now does. */
162 dst_end_symtab (objfile
)
163 struct objfile
*objfile
;
165 register struct symtab
*symtab
;
166 register struct blockvector
*blockvector
;
167 register struct linetable
*lv
;
169 /* Create the blockvector that points to all the file's blocks. */
171 blockvector
= make_blockvector (objfile
);
173 /* Now create the symtab object for this source file. */
174 symtab
= allocate_symtab (last_source_file
, objfile
);
176 /* Fill in its components. */
177 symtab
->blockvector
= blockvector
;
178 symtab
->free_code
= free_linetable
;
179 symtab
->free_ptr
= 0;
180 symtab
->filename
= last_source_file
;
181 symtab
->dirname
= NULL
;
182 symtab
->debugformat
= obsavestring ("Apollo DST", 10,
183 &objfile
->symbol_obstack
);
185 lv
->nitems
= line_vector_index
;
186 symtab
->linetable
= (struct linetable
*)
187 xrealloc ((char *) lv
, (sizeof (struct linetable
)
188 + lv
->nitems
* sizeof (struct linetable_entry
)));
190 free_named_symtabs (symtab
->filename
);
192 /* Reinitialize for beginning of new file. */
194 line_vector_length
= -1;
195 last_source_file
= NULL
;
198 /* dst_symfile_init ()
199 is the dst-specific initialization routine for reading symbols.
201 We will only be called if this is a DST or DST-like file.
202 BFD handles figuring out the format of the file, and code in symtab.c
203 uses BFD's determination to vector to us.
205 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
208 dst_symfile_init (objfile
)
209 struct objfile
*objfile
;
212 bfd
*abfd
= objfile
->obfd
;
214 init_entry_point_info (objfile
);
218 /* This function is called for every section; it finds the outer limits
219 of the line table (minimum and maximum file offset) so that the
220 mainline code can read the whole thing for efficiency. */
224 find_dst_sections (abfd
, asect
, vpinfo
)
231 file_ptr offset
, maxoff
;
234 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
235 size
= asect
->_raw_size
;
236 offset
= asect
->filepos
;
241 if (!strcmp (asect
->name
, ".blocks"))
242 section
= &blocks_info
;
243 else if (!strcmp (asect
->name
, ".lines"))
244 section
= &lines_info
;
245 else if (!strcmp (asect
->name
, ".symbols"))
246 section
= &symbols_info
;
249 section
->size
= size
;
250 section
->position
= offset
;
251 section
->base
= base
;
255 /* The BFD for this file -- only good while we're actively reading
256 symbols into a psymtab or a symtab. */
258 static bfd
*symfile_bfd
;
260 /* Read a symbol file, after initialization by dst_symfile_init. */
261 /* FIXME! Addr and Mainline are not used yet -- this will not work for
262 shared libraries or add_file! */
266 dst_symfile_read (objfile
, mainline
)
267 struct objfile
*objfile
;
270 bfd
*abfd
= objfile
->obfd
;
271 char *name
= bfd_get_filename (abfd
);
276 int stringtab_offset
;
278 symfile_bfd
= abfd
; /* Kludge for swap routines */
280 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
281 desc
= fileno ((FILE *) (abfd
->iostream
)); /* File descriptor */
283 /* Read the line number table, all at once. */
284 bfd_map_over_sections (abfd
, find_dst_sections
, (PTR
) NULL
);
286 val
= init_dst_sections (desc
);
288 error ("\"%s\": error reading debugging symbol tables\n", name
);
290 init_minimal_symbol_collection ();
291 make_cleanup (discard_minimal_symbols
, 0);
293 /* Now that the executable file is positioned at symbol table,
294 process it and define symbols accordingly. */
296 read_dst_symtab (objfile
);
298 /* Sort symbols alphabetically within each block. */
302 for (s
= objfile
->symtabs
; s
!= NULL
; s
= s
->next
)
304 sort_symtab_syms (s
);
308 /* Install any minimal symbols that have been collected as the current
309 minimal symbols for this objfile. */
311 install_minimal_symbols (objfile
);
315 dst_new_init (ignore
)
316 struct objfile
*ignore
;
321 /* Perform any local cleanups required when we are done with a particular
322 objfile. I.E, we are in the process of discarding all symbol information
323 for an objfile, freeing up all memory held for it, and unlinking the
324 objfile struct from the global list of known objfiles. */
327 dst_symfile_finish (objfile
)
328 struct objfile
*objfile
;
334 /* Get the next line number from the DST. Returns 0 when we hit an
335 * end directive or cannot continue for any other reason.
337 * Note that ordinary pc deltas are multiplied by two. Apparently
338 * this is what was really intended.
341 get_dst_line (buffer
, pc
)
342 signed char **buffer
;
346 static long last_line
= 0;
347 static int last_file
= 0;
348 dst_ln_entry_ptr_t entry
;
350 dst_src_loc_t
*src_loc
;
357 entry
= (dst_ln_entry_ptr_t
) * buffer
;
359 while (dst_ln_ln_delta (*entry
) == dst_ln_escape_flag
)
361 switch (entry
->esc
.esc_code
)
364 size
= 1; /* pad byte */
367 /* file escape. Next 4 bytes are a dst_src_loc_t */
369 src_loc
= (dst_src_loc_t
*) (*buffer
+ 1);
370 last_line
= src_loc
->line_number
;
371 last_file
= src_loc
->file_index
;
373 case dst_ln_dln1_dpc1
:
374 /* 1 byte line delta, 1 byte pc delta */
375 last_line
+= (*buffer
)[1];
376 last_pc
+= 2 * (unsigned char) (*buffer
)[2];
377 dst_record_line (last_line
, last_pc
);
380 case dst_ln_dln2_dpc2
:
381 /* 2 bytes line delta, 2 bytes pc delta */
382 last_line
+= *(short *) (*buffer
+ 1);
383 last_pc
+= 2 * (*(short *) (*buffer
+ 3));
385 dst_record_line (last_line
, last_pc
);
388 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
389 last_line
= *(unsigned long *) (*buffer
+ 1);
390 last_pc
= *(unsigned long *) (*buffer
+ 5);
392 dst_record_line (last_line
, last_pc
);
394 case dst_ln_dln1_dpc0
:
395 /* 1 byte line delta, pc delta = 0 */
397 last_line
+= (*buffer
)[1];
399 case dst_ln_ln_off_1
:
400 /* statement escape, stmt # = 1 (2nd stmt on line) */
404 /* statement escape, stmt # = next byte */
408 /* entry escape, next byte is entry number */
415 case dst_ln_stmt_end
:
416 /* gap escape, 4 bytes pc delta */
418 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
419 /* Apparently this isn't supposed to actually modify
420 * the pc value. Totally weird.
423 case dst_ln_escape_11
:
424 case dst_ln_escape_12
:
425 case dst_ln_escape_13
:
428 case dst_ln_nxt_byte
:
429 /* This shouldn't happen. If it does, we're SOL */
433 /* end escape, final entry follows */
436 *buffer
+= (size
< 0) ? -size
: size
;
437 entry
= (dst_ln_entry_ptr_t
) * buffer
;
439 last_line
+= dst_ln_ln_delta (*entry
);
440 last_pc
+= entry
->delta
.pc_delta
* 2;
442 dst_record_line (last_line
, last_pc
);
447 enter_all_lines (buffer
, address
)
452 while (get_dst_line (&buffer
, &address
));
456 get_dst_entry (buffer
, ret_entry
)
458 dst_rec_ptr_t
*ret_entry
;
462 static int last_type
;
466 entry
= (dst_rec_ptr_t
) buffer
;
467 switch (entry
->rec_type
)
472 case dst_typ_comp_unit
:
473 size
= sizeof (DST_comp_unit (entry
));
475 case dst_typ_section_tab
:
476 size
= sizeof (DST_section_tab (entry
))
477 + ((int) DST_section_tab (entry
).number_of_sections
478 - dst_dummy_array_size
) * sizeof (long);
480 case dst_typ_file_tab
:
481 size
= sizeof (DST_file_tab (entry
))
482 + ((int) DST_file_tab (entry
).number_of_files
483 - dst_dummy_array_size
) * sizeof (dst_file_desc_t
);
486 size
= sizeof (DST_block (entry
))
487 + ((int) DST_block (entry
).n_of_code_ranges
488 - dst_dummy_array_size
) * sizeof (dst_code_range_t
);
494 size
= sizeof (DST_var (entry
)) -
495 sizeof (dst_var_loc_long_t
) * dst_dummy_array_size
+
496 DST_var (entry
).no_of_locs
*
497 (DST_var (entry
).short_locs
?
498 sizeof (dst_var_loc_short_t
) :
499 sizeof (dst_var_loc_long_t
));
501 case dst_typ_pointer
:
502 size
= sizeof (DST_pointer (entry
));
505 size
= sizeof (DST_array (entry
));
507 case dst_typ_subrange
:
508 size
= sizeof (DST_subrange (entry
));
511 size
= sizeof (DST_set (entry
));
513 case dst_typ_implicit_enum
:
514 size
= sizeof (DST_implicit_enum (entry
))
515 + ((int) DST_implicit_enum (entry
).nelems
516 - dst_dummy_array_size
) * sizeof (dst_rel_offset_t
);
518 case dst_typ_explicit_enum
:
519 size
= sizeof (DST_explicit_enum (entry
))
520 + ((int) DST_explicit_enum (entry
).nelems
521 - dst_dummy_array_size
) * sizeof (dst_enum_elem_t
);
523 case dst_typ_short_rec
:
524 size
= sizeof (DST_short_rec (entry
))
525 + DST_short_rec (entry
).nfields
* sizeof (dst_short_field_t
)
526 - dst_dummy_array_size
* sizeof (dst_field_t
);
528 case dst_typ_short_union
:
529 size
= sizeof (DST_short_union (entry
))
530 + DST_short_union (entry
).nfields
* sizeof (dst_short_field_t
)
531 - dst_dummy_array_size
* sizeof (dst_field_t
);
534 size
= sizeof (DST_file (entry
));
537 size
= sizeof (DST_offset (entry
));
540 size
= sizeof (DST_alias (entry
));
542 case dst_typ_signature
:
543 size
= sizeof (DST_signature (entry
)) +
544 ((int) DST_signature (entry
).nargs
-
545 dst_dummy_array_size
) * sizeof (dst_arg_t
);
550 case dst_typ_old_label
:
551 size
= sizeof (DST_old_label (entry
));
554 size
= sizeof (DST_scope (entry
));
556 case dst_typ_end_scope
:
563 case dst_typ_string_tab
:
564 case dst_typ_global_name_tab
:
565 size
= sizeof (DST_string_tab (entry
))
566 + DST_string_tab (entry
).length
567 - dst_dummy_array_size
;
569 case dst_typ_forward
:
570 size
= sizeof (DST_forward (entry
));
571 get_dst_entry ((char *) entry
+ DST_forward (entry
).rec_off
, &entry
);
573 case dst_typ_aux_size
:
574 size
= sizeof (DST_aux_size (entry
));
576 case dst_typ_aux_align
:
577 size
= sizeof (DST_aux_align (entry
));
579 case dst_typ_aux_field_size
:
580 size
= sizeof (DST_aux_field_size (entry
));
582 case dst_typ_aux_field_off
:
583 size
= sizeof (DST_aux_field_off (entry
));
585 case dst_typ_aux_field_align
:
586 size
= sizeof (DST_aux_field_align (entry
));
588 case dst_typ_aux_qual
:
589 size
= sizeof (DST_aux_qual (entry
));
591 case dst_typ_aux_var_bound
:
592 size
= sizeof (DST_aux_var_bound (entry
));
594 case dst_typ_extension
:
595 size
= DST_extension (entry
).rec_size
;
598 size
= sizeof (DST_string (entry
));
600 case dst_typ_old_entry
:
601 size
= 48; /* Obsolete entry type */
604 size
= sizeof (DST_const (entry
))
605 + DST_const (entry
).value
.length
606 - sizeof (DST_const (entry
).value
.val
);
608 case dst_typ_reference
:
609 size
= sizeof (DST_reference (entry
));
611 case dst_typ_old_record
:
612 case dst_typ_old_union
:
615 size
= sizeof (DST_record (entry
))
616 + ((int) DST_record (entry
).nfields
617 - dst_dummy_array_size
) * sizeof (dst_field_t
);
619 case dst_typ_aux_type_deriv
:
620 size
= sizeof (DST_aux_type_deriv (entry
));
622 case dst_typ_locpool
:
623 size
= sizeof (DST_locpool (entry
))
624 + ((int) DST_locpool (entry
).length
-
625 dst_dummy_array_size
);
627 case dst_typ_variable
:
628 size
= sizeof (DST_variable (entry
));
631 size
= sizeof (DST_label (entry
));
634 size
= sizeof (DST_entry (entry
));
636 case dst_typ_aux_lifetime
:
637 size
= sizeof (DST_aux_lifetime (entry
));
639 case dst_typ_aux_ptr_base
:
640 size
= sizeof (DST_aux_ptr_base (entry
));
642 case dst_typ_aux_src_range
:
643 size
= sizeof (DST_aux_src_range (entry
));
645 case dst_typ_aux_reg_val
:
646 size
= sizeof (DST_aux_reg_val (entry
));
648 case dst_typ_aux_unit_names
:
649 size
= sizeof (DST_aux_unit_names (entry
))
650 + ((int) DST_aux_unit_names (entry
).number_of_names
651 - dst_dummy_array_size
) * sizeof (dst_rel_offset_t
);
653 case dst_typ_aux_sect_info
:
654 size
= sizeof (DST_aux_sect_info (entry
))
655 + ((int) DST_aux_sect_info (entry
).number_of_refs
656 - dst_dummy_array_size
) * sizeof (dst_sect_ref_t
);
664 fprintf_unfiltered (gdb_stderr
, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
665 (int) entry
->rec_type
,
667 fprintf_unfiltered (gdb_stderr
, "Last unknown_3 value: %d\n", lu3
);
671 last_type
= entry
->rec_type
;
672 if (size
& 1) /* Align on a word boundary */
680 next_dst_entry (buffer
, entry
, table
)
682 dst_rec_ptr_t
*entry
;
685 if (*buffer
- table
->buffer
>= table
->size
)
690 *buffer
+= get_dst_entry (*buffer
, entry
);
694 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
695 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
696 #define DST_OFFSET(a, b) ((char *) (a) + (b))
698 static dst_rec_ptr_t section_table
= NULL
;
704 dst_sec
*section
= NULL
;
707 if (!section_table
|| !ref
->sect_index
)
709 offset
= DST_section_tab (section_table
).section_base
[ref
->sect_index
- 1]
711 if (offset
>= blocks_info
.base
&&
712 offset
< blocks_info
.base
+ blocks_info
.size
)
713 section
= &blocks_info
;
714 else if (offset
>= symbols_info
.base
&&
715 offset
< symbols_info
.base
+ symbols_info
.size
)
716 section
= &symbols_info
;
717 else if (offset
>= lines_info
.base
&&
718 offset
< lines_info
.base
+ lines_info
.size
)
719 section
= &lines_info
;
722 return section
->buffer
+ (offset
- section
->base
);
726 dst_get_addr (int section
, long offset
)
728 if (!section_table
|| !section
)
730 return DST_section_tab (section_table
).section_base
[section
- 1] + offset
;
737 if (!section_table
|| !ref
->sect_index
)
739 return DST_section_tab (section_table
).section_base
[ref
->sect_index
- 1]
744 create_new_type (objfile
)
745 struct objfile
*objfile
;
749 type
= (struct type
*)
750 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct type
));
751 memset (type
, 0, sizeof (struct type
));
755 static struct symbol
*
756 create_new_symbol (objfile
, name
)
757 struct objfile
*objfile
;
760 struct symbol
*sym
= (struct symbol
*)
761 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
762 memset (sym
, 0, sizeof (struct symbol
));
763 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
764 &objfile
->symbol_obstack
);
765 SYMBOL_VALUE (sym
) = 0;
766 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
768 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
773 decode_dst_type
PARAMS ((struct objfile
*, dst_rec_ptr_t
));
776 decode_type_desc (objfile
, type_desc
, base
)
777 struct objfile
*objfile
;
778 dst_type_t
*type_desc
;
783 if (type_desc
->std_type
.user_defined_type
)
785 entry
= (dst_rec_ptr_t
) DST_OFFSET (base
,
786 dst_user_type_offset (*type_desc
));
787 type
= decode_dst_type (objfile
, entry
);
791 switch (type_desc
->std_type
.dtc
)
794 type
= builtin_type_signed_char
;
797 type
= builtin_type_short
;
800 type
= builtin_type_long
;
803 type
= builtin_type_unsigned_char
;
805 case dst_uint16_type
:
806 type
= builtin_type_unsigned_short
;
808 case dst_uint32_type
:
809 type
= builtin_type_unsigned_long
;
811 case dst_real32_type
:
812 type
= builtin_type_float
;
814 case dst_real64_type
:
815 type
= builtin_type_double
;
817 case dst_complex_type
:
818 type
= builtin_type_complex
;
820 case dst_dcomplex_type
:
821 type
= builtin_type_double_complex
;
824 type
= builtin_type_char
;
826 case dst_bool16_type
:
827 type
= builtin_type_short
;
829 case dst_bool32_type
:
830 type
= builtin_type_long
;
833 type
= builtin_type_char
;
835 /* The next few are more complex. I will take care
836 * of them properly at a later point.
838 case dst_string_type
:
839 type
= builtin_type_void
;
842 type
= builtin_type_void
;
845 type
= builtin_type_void
;
848 type
= builtin_type_void
;
851 type
= builtin_type_void
;
853 /* Back tto some ordinary ones */
855 type
= builtin_type_void
;
858 type
= builtin_type_unsigned_char
;
861 type
= builtin_type_void
;
868 struct structure_list
870 struct structure_list
*next
;
874 static struct structure_list
*struct_list
= NULL
;
877 find_dst_structure (name
)
880 struct structure_list
*element
;
882 for (element
= struct_list
; element
; element
= element
->next
)
883 if (!strcmp (name
, TYPE_NAME (element
->type
)))
884 return element
->type
;
890 decode_dst_structure (objfile
, entry
, code
, version
)
891 struct objfile
*objfile
;
896 struct type
*type
, *child_type
;
898 char *name
, *field_name
;
900 int fieldoffset
, fieldsize
;
901 dst_type_t type_desc
;
902 struct structure_list
*element
;
904 struct_name
= DST_OFFSET (entry
, DST_record (entry
).noffset
);
905 name
= concat ((code
== TYPE_CODE_UNION
) ? "union " : "struct ",
907 type
= find_dst_structure (name
);
913 type
= create_new_type (objfile
);
914 TYPE_NAME (type
) = obstack_copy0 (&objfile
->symbol_obstack
,
915 name
, strlen (name
));
917 TYPE_CODE (type
) = code
;
918 TYPE_LENGTH (type
) = DST_record (entry
).size
;
919 TYPE_NFIELDS (type
) = DST_record (entry
).nfields
;
920 TYPE_FIELDS (type
) = (struct field
*)
921 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) *
922 DST_record (entry
).nfields
);
923 fieldoffset
= fieldsize
= 0;
924 INIT_CPLUS_SPECIFIC (type
);
925 element
= (struct structure_list
*)
926 xmalloc (sizeof (struct structure_list
));
927 element
->type
= type
;
928 element
->next
= struct_list
;
929 struct_list
= element
;
930 for (i
= 0; i
< DST_record (entry
).nfields
; i
++)
935 field_name
= DST_OFFSET (entry
,
936 DST_record (entry
).f
.ofields
[i
].noffset
);
937 fieldoffset
= DST_record (entry
).f
.ofields
[i
].foffset
* 8 +
938 DST_record (entry
).f
.ofields
[i
].bit_offset
;
939 fieldsize
= DST_record (entry
).f
.ofields
[i
].size
;
940 type_desc
= DST_record (entry
).f
.ofields
[i
].type_desc
;
943 field_name
= DST_OFFSET (entry
,
944 DST_record (entry
).f
.fields
[i
].noffset
);
945 type_desc
= DST_record (entry
).f
.fields
[i
].type_desc
;
946 switch (DST_record (entry
).f
.fields
[i
].f
.field_loc
.format_tag
)
949 fieldoffset
= DST_record (entry
).f
.
950 fields
[i
].f
.field_byte
.offset
* 8;
954 fieldoffset
= DST_record (entry
).f
.
955 fields
[i
].f
.field_bit
.byte_offset
* 8 +
956 DST_record (entry
).f
.
957 fields
[i
].f
.field_bit
.bit_offset
;
958 fieldsize
= DST_record (entry
).f
.
959 fields
[i
].f
.field_bit
.nbits
;
962 fieldoffset
+= fieldsize
;
968 field_name
= DST_OFFSET (entry
,
969 DST_record (entry
).f
.sfields
[i
].noffset
);
970 fieldoffset
= DST_record (entry
).f
.sfields
[i
].foffset
;
971 type_desc
= DST_record (entry
).f
.sfields
[i
].type_desc
;
972 if (i
< DST_record (entry
).nfields
- 1)
973 fieldsize
= DST_record (entry
).f
.sfields
[i
+ 1].foffset
;
975 fieldsize
= DST_record (entry
).size
;
976 fieldsize
-= fieldoffset
;
980 TYPE_FIELDS (type
)[i
].name
=
981 obstack_copy0 (&objfile
->symbol_obstack
,
982 field_name
, strlen (field_name
));
983 TYPE_FIELDS (type
)[i
].type
= decode_type_desc (objfile
,
987 fieldsize
= TYPE_LENGTH (TYPE_FIELDS (type
)[i
].type
) *
989 TYPE_FIELDS (type
)[i
].bitsize
= fieldsize
;
990 TYPE_FIELDS (type
)[i
].bitpos
= fieldoffset
;
996 decode_dst_type (objfile
, entry
)
997 struct objfile
*objfile
;
1000 struct type
*child_type
, *type
, *range_type
, *index_type
;
1002 switch (entry
->rec_type
)
1005 return decode_type_desc (objfile
,
1006 &DST_var (entry
).type_desc
,
1009 case dst_typ_variable
:
1010 return decode_type_desc (objfile
,
1011 &DST_variable (entry
).type_desc
,
1014 case dst_typ_short_rec
:
1015 return decode_dst_structure (objfile
, entry
, TYPE_CODE_STRUCT
, 0);
1016 case dst_typ_short_union
:
1017 return decode_dst_structure (objfile
, entry
, TYPE_CODE_UNION
, 0);
1019 return decode_dst_structure (objfile
, entry
, TYPE_CODE_UNION
, 1);
1020 case dst_typ_record
:
1021 return decode_dst_structure (objfile
, entry
, TYPE_CODE_STRUCT
, 1);
1022 case dst_typ_old_union
:
1023 return decode_dst_structure (objfile
, entry
, TYPE_CODE_UNION
, 2);
1024 case dst_typ_old_record
:
1025 return decode_dst_structure (objfile
, entry
, TYPE_CODE_STRUCT
, 2);
1026 case dst_typ_pointer
:
1027 return make_pointer_type (
1028 decode_type_desc (objfile
,
1029 &DST_pointer (entry
).type_desc
,
1033 child_type
= decode_type_desc (objfile
,
1034 &DST_pointer (entry
).type_desc
,
1036 index_type
= lookup_fundamental_type (objfile
,
1038 range_type
= create_range_type ((struct type
*) NULL
,
1039 index_type
, DST_array (entry
).lo_bound
,
1040 DST_array (entry
).hi_bound
);
1041 return create_array_type ((struct type
*) NULL
, child_type
,
1044 return decode_type_desc (objfile
,
1045 &DST_alias (entry
).type_desc
,
1048 return builtin_type_int
;
1054 struct symbol_list
*next
;
1055 struct symbol
*symbol
;
1058 static struct symbol_list
*dst_global_symbols
= NULL
;
1059 static int total_globals
= 0;
1062 decode_dst_locstring (locstr
, sym
)
1066 dst_loc_entry_t
*entry
, *next_entry
;
1074 fprintf_unfiltered (gdb_stderr
, "Error reading locstring\n");
1077 entry
= (dst_loc_entry_t
*) locstr
;
1078 next_entry
= (dst_loc_entry_t
*) (locstr
+ 1);
1079 switch (entry
->header
.code
)
1081 case dst_lsc_end
: /* End of string */
1083 case dst_lsc_indirect
: /* Indirect through previous. Arg == 6 */
1084 /* Or register ax x == arg */
1085 if (entry
->header
.arg
< 6)
1087 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1088 SYMBOL_VALUE (sym
) = entry
->header
.arg
+ 8;
1090 /* We predict indirects */
1094 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1095 SYMBOL_VALUE (sym
) = entry
->header
.arg
;
1098 case dst_lsc_section
: /* Section (arg+1) */
1099 SYMBOL_VALUE (sym
) = dst_get_addr (entry
->header
.arg
+ 1, 0);
1102 case dst_lsc_sec_byte
: /* Section (next_byte+1) */
1103 SYMBOL_VALUE (sym
) = dst_get_addr (locstr
[1] + 1, 0);
1106 case dst_lsc_add
: /* Add (arg+1)*2 */
1107 case dst_lsc_sub
: /* Subtract (arg+1)*2 */
1108 temp
= (entry
->header
.arg
+ 1) * 2;
1110 if (*locstr
== dst_multiply_256
)
1115 switch (entry
->header
.code
)
1118 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
)
1119 SYMBOL_CLASS (sym
) = LOC_ARG
;
1120 SYMBOL_VALUE (sym
) += temp
;
1123 SYMBOL_VALUE (sym
) -= temp
;
1127 case dst_lsc_add_byte
:
1128 case dst_lsc_sub_byte
:
1129 switch (entry
->header
.arg
& 0x03)
1132 temp
= (unsigned char) locstr
[1];
1136 temp
= *(unsigned short *) (locstr
+ 1);
1140 temp
= *(unsigned long *) (locstr
+ 1);
1144 if (*locstr
== dst_multiply_256
)
1149 switch (entry
->header
.code
)
1151 case dst_lsc_add_byte
:
1152 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
)
1153 SYMBOL_CLASS (sym
) = LOC_ARG
;
1154 SYMBOL_VALUE (sym
) += temp
;
1156 case dst_lsc_sub_byte
:
1157 SYMBOL_VALUE (sym
) -= temp
;
1161 case dst_lsc_sbreg
: /* Stack base register (frame pointer). Arg==0 */
1162 if (next_entry
->header
.code
!= dst_lsc_indirect
)
1164 SYMBOL_VALUE (sym
) = 0;
1165 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1168 SYMBOL_VALUE (sym
) = 0;
1169 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1173 SYMBOL_VALUE (sym
) = 0;
1174 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1180 static struct symbol_list
*
1181 process_dst_symbols (objfile
, entry
, name
, nsyms_ret
)
1182 struct objfile
*objfile
;
1183 dst_rec_ptr_t entry
;
1187 struct symbol_list
*list
= NULL
, *element
;
1195 dst_var_attr_t attr
;
1196 dst_var_loc_t loc_type
;
1205 location
= (char *) entry
;
1206 while (NEXT_SYM (&location
, &entry
) &&
1207 entry
->rec_type
!= dst_typ_end_scope
)
1209 if (entry
->rec_type
== dst_typ_var
)
1211 if (DST_var (entry
).short_locs
)
1213 loc_type
= DST_var (entry
).locs
.shorts
[0].loc_type
;
1214 loc_index
= DST_var (entry
).locs
.shorts
[0].loc_index
;
1215 loc_value
= DST_var (entry
).locs
.shorts
[0].location
;
1219 loc_type
= DST_var (entry
).locs
.longs
[0].loc_type
;
1220 loc_index
= DST_var (entry
).locs
.longs
[0].loc_index
;
1221 loc_value
= DST_var (entry
).locs
.longs
[0].location
;
1223 if (loc_type
== dst_var_loc_external
)
1225 symname
= DST_OFFSET (entry
, DST_var (entry
).noffset
);
1226 line
= DST_var (entry
).src_loc
.line_number
;
1227 symtype
= DST_var (entry
).type_desc
;
1228 attr
= DST_var (entry
).attributes
;
1230 else if (entry
->rec_type
== dst_typ_variable
)
1232 symname
= DST_OFFSET (entry
,
1233 DST_variable (entry
).noffset
);
1234 line
= DST_variable (entry
).src_loc
.line_number
;
1235 symtype
= DST_variable (entry
).type_desc
;
1236 attr
= DST_variable (entry
).attributes
;
1242 if (symname
&& name
&& !strcmp (symname
, name
))
1243 /* It's the function return value */
1245 sym
= create_new_symbol (objfile
, symname
);
1247 if ((attr
& (1 << dst_var_attr_global
)) ||
1248 (attr
& (1 << dst_var_attr_static
)))
1249 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1251 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1252 SYMBOL_LINE (sym
) = line
;
1253 SYMBOL_TYPE (sym
) = decode_type_desc (objfile
, &symtype
,
1255 SYMBOL_VALUE (sym
) = 0;
1256 switch (entry
->rec_type
)
1261 case dst_var_loc_abs
:
1262 SYMBOL_VALUE_ADDRESS (sym
) = loc_value
;
1264 case dst_var_loc_sect_off
:
1265 case dst_var_loc_ind_sect_off
: /* What is this? */
1266 SYMBOL_VALUE_ADDRESS (sym
) = dst_get_addr (
1270 case dst_var_loc_ind_reg_rel
: /* What is this? */
1271 case dst_var_loc_reg_rel
:
1272 /* If it isn't fp relative, specify the
1273 * register it's relative to.
1277 sym
->aux_value
.basereg
= loc_index
;
1279 SYMBOL_VALUE (sym
) = loc_value
;
1280 if (loc_value
> 0 &&
1281 SYMBOL_CLASS (sym
) == LOC_BASEREG
)
1282 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
1284 case dst_var_loc_reg
:
1285 SYMBOL_VALUE (sym
) = loc_index
;
1286 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1290 case dst_typ_variable
:
1291 /* External variable..... don't try to interpret
1292 * its nonexistant locstring.
1294 if (DST_variable (entry
).loffset
== -1)
1296 decode_dst_locstring (DST_OFFSET (entry
,
1297 DST_variable (entry
).loffset
),
1300 element
= (struct symbol_list
*)
1301 xmalloc (sizeof (struct symbol_list
));
1303 if (attr
& (1 << dst_var_attr_global
))
1305 element
->next
= dst_global_symbols
;
1306 dst_global_symbols
= element
;
1311 element
->next
= list
;
1315 element
->symbol
= sym
;
1322 static struct symbol
*
1323 process_dst_function (objfile
, entry
, name
, address
)
1324 struct objfile
*objfile
;
1325 dst_rec_ptr_t entry
;
1330 struct type
*type
, *ftype
;
1331 dst_rec_ptr_t sym_entry
, typ_entry
;
1333 struct symbol_list
*element
;
1335 type
= builtin_type_int
;
1336 sym
= create_new_symbol (objfile
, name
);
1337 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1341 location
= (char *) entry
;
1344 NEXT_SYM (&location
, &sym_entry
);
1346 while (sym_entry
&& sym_entry
->rec_type
!= dst_typ_signature
);
1351 DST_signature (sym_entry
).src_loc
.line_number
;
1352 if (DST_signature (sym_entry
).result
)
1354 typ_entry
= (dst_rec_ptr_t
)
1355 DST_OFFSET (sym_entry
,
1356 DST_signature (sym_entry
).result
);
1357 type
= decode_dst_type (objfile
, typ_entry
);
1362 if (!type
->function_type
)
1364 ftype
= create_new_type (objfile
);
1365 type
->function_type
= ftype
;
1366 ftype
->target_type
= type
;
1367 ftype
->code
= TYPE_CODE_FUNC
;
1369 SYMBOL_TYPE (sym
) = type
->function_type
;
1371 /* Now add ourselves to the global symbols list */
1372 element
= (struct symbol_list
*)
1373 xmalloc (sizeof (struct symbol_list
));
1375 element
->next
= dst_global_symbols
;
1376 dst_global_symbols
= element
;
1378 element
->symbol
= sym
;
1383 static struct block
*
1384 process_dst_block (objfile
, entry
)
1385 struct objfile
*objfile
;
1386 dst_rec_ptr_t entry
;
1388 struct block
*block
;
1389 struct symbol
*function
= NULL
;
1393 dst_rec_ptr_t child_entry
, symbol_entry
;
1394 struct block
*child_block
;
1395 int total_symbols
= 0;
1397 static long fake_seq
= 0;
1398 struct symbol_list
*symlist
, *nextsym
;
1401 if (DST_block (entry
).noffset
)
1402 name
= DST_OFFSET (entry
, DST_block (entry
).noffset
);
1405 if (DST_block (entry
).n_of_code_ranges
)
1407 address
= dst_sym_addr (
1408 &DST_block (entry
).code_ranges
[0].code_start
);
1409 size
= DST_block (entry
).code_ranges
[0].code_size
;
1416 symbol_entry
= (dst_rec_ptr_t
) get_sec_ref (&DST_block (entry
).symbols_start
);
1417 switch (DST_block (entry
).block_type
)
1419 /* These are all really functions. Even the "program" type.
1420 * This is because the Apollo OS was written in Pascal, and
1421 * in Pascal, the main procedure is described as the Program.
1424 case dst_block_procedure
:
1425 case dst_block_function
:
1426 case dst_block_subroutine
:
1427 case dst_block_program
:
1428 prim_record_minimal_symbol (name
, address
, mst_text
, objfile
);
1429 function
= process_dst_function (
1434 enter_all_lines (get_sec_ref (&DST_block (entry
).code_ranges
[0].lines_start
), address
);
1436 case dst_block_block_data
:
1440 /* GDB has to call it something, and the module name
1443 sprintf (fake_name
, "block_%08lx", fake_seq
++);
1444 function
= process_dst_function (
1445 objfile
, NULL
, fake_name
, address
);
1448 symlist
= process_dst_symbols (objfile
, symbol_entry
,
1449 name
, &total_symbols
);
1450 block
= (struct block
*)
1451 obstack_alloc (&objfile
->symbol_obstack
,
1452 sizeof (struct block
) +
1453 (total_symbols
- 1) * sizeof (struct symbol
*));
1458 nextsym
= symlist
->next
;
1460 block
->sym
[symnum
] = symlist
->symbol
;
1462 free ((PTR
) symlist
);
1466 BLOCK_NSYMS (block
) = total_symbols
;
1467 BLOCK_START (block
) = address
;
1468 BLOCK_END (block
) = address
+ size
;
1469 BLOCK_SUPERBLOCK (block
) = 0;
1472 SYMBOL_BLOCK_VALUE (function
) = block
;
1473 BLOCK_FUNCTION (block
) = function
;
1476 BLOCK_FUNCTION (block
) = 0;
1478 if (DST_block (entry
).child_block_off
)
1480 child_entry
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1481 DST_block (entry
).child_block_off
);
1484 child_block
= process_dst_block (objfile
, child_entry
);
1487 if (BLOCK_START (child_block
) <
1488 BLOCK_START (block
) ||
1489 BLOCK_START (block
) == -1)
1490 BLOCK_START (block
) =
1491 BLOCK_START (child_block
);
1492 if (BLOCK_END (child_block
) >
1493 BLOCK_END (block
) ||
1494 BLOCK_END (block
) == -1)
1496 BLOCK_END (child_block
);
1497 BLOCK_SUPERBLOCK (child_block
) = block
;
1499 if (DST_block (child_entry
).sibling_block_off
)
1500 child_entry
= (dst_rec_ptr_t
) DST_OFFSET (
1502 DST_block (child_entry
).sibling_block_off
);
1507 record_pending_block (objfile
, block
, NULL
);
1513 read_dst_symtab (objfile
)
1514 struct objfile
*objfile
;
1517 dst_rec_ptr_t entry
, file_table
, root_block
;
1519 struct block
*block
, *global_block
;
1521 struct symbol_list
*nextsym
;
1523 struct structure_list
*element
;
1525 current_objfile
= objfile
;
1526 buffer
= blocks_info
.buffer
;
1527 while (NEXT_BLK (&buffer
, &entry
))
1529 if (entry
->rec_type
== dst_typ_comp_unit
)
1531 file_table
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1532 DST_comp_unit (entry
).file_table
);
1533 section_table
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1534 DST_comp_unit (entry
).section_table
);
1535 root_block
= (dst_rec_ptr_t
) DST_OFFSET (entry
,
1536 DST_comp_unit (entry
).root_block_offset
);
1537 source_file
= DST_OFFSET (file_table
,
1538 DST_file_tab (file_table
).files
[0].noffset
);
1539 /* Point buffer to the start of the next comp_unit */
1540 buffer
= DST_OFFSET (entry
,
1541 DST_comp_unit (entry
).data_size
);
1542 dst_start_symtab ();
1544 block
= process_dst_block (objfile
, root_block
);
1546 global_block
= (struct block
*)
1547 obstack_alloc (&objfile
->symbol_obstack
,
1548 sizeof (struct block
) +
1549 (total_globals
- 1) *
1550 sizeof (struct symbol
*));
1551 BLOCK_NSYMS (global_block
) = total_globals
;
1552 for (symnum
= 0; symnum
< total_globals
; symnum
++)
1554 nextsym
= dst_global_symbols
->next
;
1556 global_block
->sym
[symnum
] =
1557 dst_global_symbols
->symbol
;
1559 free ((PTR
) dst_global_symbols
);
1560 dst_global_symbols
= nextsym
;
1562 dst_global_symbols
= NULL
;
1564 BLOCK_FUNCTION (global_block
) = 0;
1565 BLOCK_START (global_block
) = BLOCK_START (block
);
1566 BLOCK_END (global_block
) = BLOCK_END (block
);
1567 BLOCK_SUPERBLOCK (global_block
) = 0;
1568 BLOCK_SUPERBLOCK (block
) = global_block
;
1569 record_pending_block (objfile
, global_block
, NULL
);
1571 complete_symtab (source_file
,
1572 BLOCK_START (block
),
1573 BLOCK_END (block
) - BLOCK_START (block
));
1575 dst_end_symtab (objfile
);
1579 prim_record_minimal_symbol ("<end_of_program>",
1580 BLOCK_END (block
), mst_text
, objfile
);
1581 /* One more faked symbol to make sure nothing can ever run off the
1582 * end of the symbol table. This one represents the end of the
1583 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1584 * int possible), but some parts of gdb treated it as a signed
1585 * number and failed comparisons. We could equally use 7fffffff,
1586 * but no functions are ever mapped to an address higher than
1589 prim_record_minimal_symbol ("<end_of_text>",
1590 (CORE_ADDR
) 0x40000000,
1594 element
= struct_list
;
1595 struct_list
= element
->next
;
1596 free ((PTR
) element
);
1601 /* Support for line number handling */
1602 static char *linetab
= NULL
;
1603 static long linetab_offset
;
1604 static unsigned long linetab_size
;
1606 /* Read in all the line numbers for fast lookups later. Leave them in
1607 external (unswapped) format in memory; we'll swap them as we enter
1608 them into GDB's data structures. */
1610 init_one_section (chan
, secinfo
)
1614 if (secinfo
->size
== 0
1615 || lseek (chan
, secinfo
->position
, 0) == -1
1616 || (secinfo
->buffer
= xmalloc (secinfo
->size
)) == NULL
1617 || myread (chan
, secinfo
->buffer
, secinfo
->size
) == -1)
1624 init_dst_sections (chan
)
1628 if (!init_one_section (chan
, &blocks_info
) ||
1629 !init_one_section (chan
, &lines_info
) ||
1630 !init_one_section (chan
, &symbols_info
))
1636 /* Fake up support for relocating symbol addresses. FIXME. */
1638 struct section_offsets dst_symfile_faker
=
1642 dst_symfile_offsets (objfile
, addr
)
1643 struct objfile
*objfile
;
1644 struct section_addr_info
*addrs
;
1646 objfile
->num_sections
= 1;
1647 objfile
->section_offsets
= &dst_symfile_faker
;
1650 /* Register our ability to parse symbols for DST BFD files */
1652 static struct sym_fns dst_sym_fns
=
1654 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1655 a separate flavour like ecoff? */
1656 (enum bfd_flavour
) -2,
1658 dst_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1659 dst_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1660 dst_symfile_read
, /* sym_read: read a symbol file into symtab */
1661 dst_symfile_finish
, /* sym_finish: finished with file, cleanup */
1662 dst_symfile_offsets
, /* sym_offsets: xlate external to internal form */
1663 NULL
/* next: pointer to next struct sym_fns */
1667 _initialize_dstread ()
1669 add_symtab_fns (&dst_sym_fns
);