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
;
180 symtab
->debugformat
= obsavestring ("Apollo DST", 10,
181 &objfile
-> symbol_obstack
);
183 lv
->nitems
= line_vector_index
;
184 symtab
->linetable
= (struct linetable
*)
185 xrealloc ((char *) lv
, (sizeof (struct linetable
)
186 + lv
->nitems
* sizeof (struct linetable_entry
)));
188 free_named_symtabs (symtab
->filename
);
190 /* Reinitialize for beginning of new file. */
192 line_vector_length
= -1;
193 last_source_file
= NULL
;
196 /* dst_symfile_init ()
197 is the dst-specific initialization routine for reading symbols.
199 We will only be called if this is a DST or DST-like file.
200 BFD handles figuring out the format of the file, and code in symtab.c
201 uses BFD's determination to vector to us.
203 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
206 dst_symfile_init (objfile
)
207 struct objfile
*objfile
;
210 bfd
*abfd
= objfile
->obfd
;
212 init_entry_point_info (objfile
);
216 /* This function is called for every section; it finds the outer limits
217 of the line table (minimum and maximum file offset) so that the
218 mainline code can read the whole thing for efficiency. */
222 find_dst_sections (abfd
, asect
, vpinfo
)
229 file_ptr offset
, maxoff
;
232 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
233 size
= asect
->_raw_size
;
234 offset
= asect
->filepos
;
239 if (!strcmp(asect
->name
, ".blocks"))
240 section
= &blocks_info
;
241 else if (!strcmp(asect
->name
, ".lines"))
242 section
= &lines_info
;
243 else if (!strcmp(asect
->name
, ".symbols"))
244 section
= &symbols_info
;
247 section
->size
= size
;
248 section
->position
= offset
;
249 section
->base
= base
;
253 /* The BFD for this file -- only good while we're actively reading
254 symbols into a psymtab or a symtab. */
256 static bfd
*symfile_bfd
;
258 /* Read a symbol file, after initialization by dst_symfile_init. */
259 /* FIXME! Addr and Mainline are not used yet -- this will not work for
260 shared libraries or add_file! */
264 dst_symfile_read (objfile
, section_offsets
, mainline
)
265 struct objfile
*objfile
;
266 struct section_offsets
*section_offsets
;
269 bfd
*abfd
= objfile
->obfd
;
270 char *name
= bfd_get_filename (abfd
);
275 int stringtab_offset
;
277 symfile_bfd
= abfd
; /* Kludge for swap routines */
279 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
280 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
282 /* Read the line number table, all at once. */
283 bfd_map_over_sections (abfd
, find_dst_sections
, (PTR
)NULL
);
285 val
= init_dst_sections (desc
);
287 error ("\"%s\": error reading debugging symbol tables\n", name
);
289 init_minimal_symbol_collection ();
290 make_cleanup (discard_minimal_symbols
, 0);
292 /* Now that the executable file is positioned at symbol table,
293 process it and define symbols accordingly. */
295 read_dst_symtab (objfile
);
297 /* Sort symbols alphabetically within each block. */
301 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
303 sort_symtab_syms (s
);
307 /* Install any minimal symbols that have been collected as the current
308 minimal symbols for this objfile. */
310 install_minimal_symbols (objfile
);
314 dst_new_init (ignore
)
315 struct objfile
*ignore
;
320 /* Perform any local cleanups required when we are done with a particular
321 objfile. I.E, we are in the process of discarding all symbol information
322 for an objfile, freeing up all memory held for it, and unlinking the
323 objfile struct from the global list of known objfiles. */
326 dst_symfile_finish (objfile
)
327 struct objfile
*objfile
;
333 /* Get the next line number from the DST. Returns 0 when we hit an
334 * end directive or cannot continue for any other reason.
336 * Note that ordinary pc deltas are multiplied by two. Apparently
337 * this is what was really intended.
340 get_dst_line(buffer
, pc
)
341 signed char **buffer
;
345 static long last_line
= 0;
346 static int last_file
= 0;
347 dst_ln_entry_ptr_t entry
;
349 dst_src_loc_t
*src_loc
;
356 entry
= (dst_ln_entry_ptr_t
) *buffer
;
358 while (dst_ln_ln_delta(*entry
) == dst_ln_escape_flag
)
360 switch(entry
->esc
.esc_code
)
363 size
= 1; /* pad byte */
366 /* file escape. Next 4 bytes are a dst_src_loc_t */
368 src_loc
= (dst_src_loc_t
*) (*buffer
+ 1);
369 last_line
= src_loc
->line_number
;
370 last_file
= src_loc
->file_index
;
372 case dst_ln_dln1_dpc1
:
373 /* 1 byte line delta, 1 byte pc delta */
374 last_line
+= (*buffer
)[1];
375 last_pc
+= 2 * (unsigned char) (*buffer
)[2];
376 dst_record_line(last_line
, last_pc
);
379 case dst_ln_dln2_dpc2
:
380 /* 2 bytes line delta, 2 bytes pc delta */
381 last_line
+= *(short *) (*buffer
+ 1);
382 last_pc
+= 2 * (*(short *) (*buffer
+ 3));
384 dst_record_line(last_line
, last_pc
);
387 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
388 last_line
= *(unsigned long *) (*buffer
+ 1);
389 last_pc
= *(unsigned long *) (*buffer
+ 5);
391 dst_record_line(last_line
, last_pc
);
393 case dst_ln_dln1_dpc0
:
394 /* 1 byte line delta, pc delta = 0 */
396 last_line
+= (*buffer
)[1];
398 case dst_ln_ln_off_1
:
399 /* statement escape, stmt # = 1 (2nd stmt on line) */
403 /* statement escape, stmt # = next byte */
407 /* entry escape, next byte is entry number */
414 case dst_ln_stmt_end
:
415 /* gap escape, 4 bytes pc delta */
417 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
418 /* Apparently this isn't supposed to actually modify
419 * the pc value. Totally weird.
422 case dst_ln_escape_11
:
423 case dst_ln_escape_12
:
424 case dst_ln_escape_13
:
427 case dst_ln_nxt_byte
:
428 /* This shouldn't happen. If it does, we're SOL */
432 /* end escape, final entry follows */
435 *buffer
+= (size
< 0) ? -size
: size
;
436 entry
= (dst_ln_entry_ptr_t
) *buffer
;
438 last_line
+= dst_ln_ln_delta(*entry
);
439 last_pc
+= entry
->delta
.pc_delta
* 2;
441 dst_record_line(last_line
, last_pc
);
446 enter_all_lines(buffer
, address
)
451 while (get_dst_line(&buffer
, &address
));
455 get_dst_entry(buffer
, ret_entry
)
457 dst_rec_ptr_t
*ret_entry
;
461 static int last_type
;
465 entry
= (dst_rec_ptr_t
) buffer
;
466 switch(entry
->rec_type
)
471 case dst_typ_comp_unit
:
472 size
= sizeof(DST_comp_unit(entry
));
474 case dst_typ_section_tab
:
475 size
= sizeof(DST_section_tab(entry
))
476 + ((int) DST_section_tab(entry
).number_of_sections
477 - dst_dummy_array_size
) * sizeof(long);
479 case dst_typ_file_tab
:
480 size
= sizeof(DST_file_tab(entry
))
481 + ((int) DST_file_tab(entry
).number_of_files
482 - dst_dummy_array_size
) * sizeof(dst_file_desc_t
);
485 size
= sizeof(DST_block(entry
))
486 + ((int) DST_block(entry
).n_of_code_ranges
487 - dst_dummy_array_size
) * sizeof(dst_code_range_t
);
493 size
= sizeof(DST_var(entry
)) -
494 sizeof(dst_var_loc_long_t
) * dst_dummy_array_size
+
495 DST_var(entry
).no_of_locs
*
496 ( DST_var(entry
).short_locs
?
497 sizeof(dst_var_loc_short_t
):
498 sizeof(dst_var_loc_long_t
));
500 case dst_typ_pointer
:
501 size
= sizeof(DST_pointer(entry
));
504 size
= sizeof(DST_array(entry
));
506 case dst_typ_subrange
:
507 size
= sizeof(DST_subrange(entry
));
510 size
= sizeof(DST_set(entry
));
512 case dst_typ_implicit_enum
:
513 size
= sizeof(DST_implicit_enum(entry
))
514 + ((int) DST_implicit_enum(entry
).nelems
515 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
517 case dst_typ_explicit_enum
:
518 size
= sizeof(DST_explicit_enum(entry
))
519 + ((int) DST_explicit_enum(entry
).nelems
520 - dst_dummy_array_size
) * sizeof(dst_enum_elem_t
);
522 case dst_typ_short_rec
:
523 size
= sizeof(DST_short_rec(entry
))
524 + DST_short_rec(entry
).nfields
* sizeof(dst_short_field_t
)
525 - dst_dummy_array_size
* sizeof(dst_field_t
);
527 case dst_typ_short_union
:
528 size
= sizeof(DST_short_union(entry
))
529 + DST_short_union(entry
).nfields
* sizeof(dst_short_field_t
)
530 - dst_dummy_array_size
* sizeof(dst_field_t
);
533 size
= sizeof(DST_file(entry
));
536 size
= sizeof(DST_offset(entry
));
539 size
= sizeof(DST_alias(entry
));
541 case dst_typ_signature
:
542 size
= sizeof(DST_signature(entry
)) +
543 ((int) DST_signature(entry
).nargs
-
544 dst_dummy_array_size
) * sizeof(dst_arg_t
);
549 case dst_typ_old_label
:
550 size
= sizeof(DST_old_label(entry
));
553 size
= sizeof(DST_scope(entry
));
555 case dst_typ_end_scope
:
562 case dst_typ_string_tab
:
563 case dst_typ_global_name_tab
:
564 size
= sizeof(DST_string_tab(entry
))
565 + DST_string_tab(entry
).length
566 - dst_dummy_array_size
;
568 case dst_typ_forward
:
569 size
= sizeof(DST_forward(entry
));
570 get_dst_entry((char *) entry
+ DST_forward(entry
).rec_off
, &entry
);
572 case dst_typ_aux_size
:
573 size
= sizeof(DST_aux_size(entry
));
575 case dst_typ_aux_align
:
576 size
= sizeof(DST_aux_align(entry
));
578 case dst_typ_aux_field_size
:
579 size
= sizeof(DST_aux_field_size(entry
));
581 case dst_typ_aux_field_off
:
582 size
= sizeof(DST_aux_field_off(entry
));
584 case dst_typ_aux_field_align
:
585 size
= sizeof(DST_aux_field_align(entry
));
587 case dst_typ_aux_qual
:
588 size
= sizeof(DST_aux_qual(entry
));
590 case dst_typ_aux_var_bound
:
591 size
= sizeof(DST_aux_var_bound(entry
));
593 case dst_typ_extension
:
594 size
= DST_extension(entry
).rec_size
;
597 size
= sizeof(DST_string(entry
));
599 case dst_typ_old_entry
:
600 size
= 48; /* Obsolete entry type */
603 size
= sizeof(DST_const(entry
))
604 + DST_const(entry
).value
.length
605 - sizeof(DST_const(entry
).value
.val
);
607 case dst_typ_reference
:
608 size
= sizeof(DST_reference(entry
));
610 case dst_typ_old_record
:
611 case dst_typ_old_union
:
614 size
= sizeof(DST_record(entry
))
615 + ((int) DST_record(entry
).nfields
616 - dst_dummy_array_size
) * sizeof(dst_field_t
);
618 case dst_typ_aux_type_deriv
:
619 size
= sizeof(DST_aux_type_deriv(entry
));
621 case dst_typ_locpool
:
622 size
= sizeof(DST_locpool(entry
))
623 + ((int) DST_locpool(entry
).length
-
624 dst_dummy_array_size
);
626 case dst_typ_variable
:
627 size
= sizeof(DST_variable(entry
));
630 size
= sizeof(DST_label(entry
));
633 size
= sizeof(DST_entry(entry
));
635 case dst_typ_aux_lifetime
:
636 size
= sizeof(DST_aux_lifetime(entry
));
638 case dst_typ_aux_ptr_base
:
639 size
= sizeof(DST_aux_ptr_base(entry
));
641 case dst_typ_aux_src_range
:
642 size
= sizeof(DST_aux_src_range(entry
));
644 case dst_typ_aux_reg_val
:
645 size
= sizeof(DST_aux_reg_val(entry
));
647 case dst_typ_aux_unit_names
:
648 size
= sizeof(DST_aux_unit_names(entry
))
649 + ((int) DST_aux_unit_names(entry
).number_of_names
650 - dst_dummy_array_size
) * sizeof(dst_rel_offset_t
);
652 case dst_typ_aux_sect_info
:
653 size
= sizeof(DST_aux_sect_info(entry
))
654 + ((int) DST_aux_sect_info(entry
).number_of_refs
655 - dst_dummy_array_size
) * sizeof(dst_sect_ref_t
);
663 fprintf_unfiltered(gdb_stderr
, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
664 (int) entry
->rec_type
,
666 fprintf_unfiltered(gdb_stderr
, "Last unknown_3 value: %d\n", lu3
);
670 last_type
= entry
->rec_type
;
671 if (size
& 1) /* Align on a word boundary */
678 static int next_dst_entry(buffer
, entry
, table
)
680 dst_rec_ptr_t
*entry
;
683 if (*buffer
- table
->buffer
>= table
->size
)
688 *buffer
+= get_dst_entry(*buffer
, entry
);
692 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
693 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
694 #define DST_OFFSET(a, b) ((char *) (a) + (b))
696 static dst_rec_ptr_t section_table
= NULL
;
702 dst_sec
*section
= NULL
;
705 if (!section_table
|| !ref
->sect_index
)
707 offset
= DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
709 if (offset
>= blocks_info
.base
&&
710 offset
< blocks_info
.base
+ blocks_info
.size
)
711 section
= &blocks_info
;
712 else if (offset
>= symbols_info
.base
&&
713 offset
< symbols_info
.base
+ symbols_info
.size
)
714 section
= &symbols_info
;
715 else if (offset
>= lines_info
.base
&&
716 offset
< lines_info
.base
+ lines_info
.size
)
717 section
= &lines_info
;
720 return section
->buffer
+ (offset
- section
->base
);
724 dst_get_addr(int section
, long offset
)
726 if (!section_table
|| !section
)
728 return DST_section_tab(section_table
).section_base
[section
-1] + offset
;
735 if (!section_table
|| !ref
->sect_index
)
737 return DST_section_tab(section_table
).section_base
[ref
->sect_index
-1]
742 create_new_type(objfile
)
743 struct objfile
*objfile
;
747 type
= (struct type
*)
748 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct type
));
749 memset(type
, 0, sizeof(struct type
));
753 static struct symbol
*
754 create_new_symbol(objfile
, name
)
755 struct objfile
*objfile
;
758 struct symbol
*sym
= (struct symbol
*)
759 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
760 memset (sym
, 0, sizeof (struct symbol
));
761 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
762 &objfile
->symbol_obstack
);
763 SYMBOL_VALUE (sym
) = 0;
764 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
766 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
771 decode_dst_type
PARAMS ((struct objfile
*, dst_rec_ptr_t
));
774 decode_type_desc(objfile
, type_desc
, base
)
775 struct objfile
*objfile
;
776 dst_type_t
*type_desc
;
781 if (type_desc
->std_type
.user_defined_type
)
783 entry
= (dst_rec_ptr_t
) DST_OFFSET(base
,
784 dst_user_type_offset(*type_desc
));
785 type
= decode_dst_type(objfile
, entry
);
789 switch(type_desc
->std_type
.dtc
)
792 type
= builtin_type_signed_char
;
795 type
= builtin_type_short
;
798 type
= builtin_type_long
;
801 type
= builtin_type_unsigned_char
;
803 case dst_uint16_type
:
804 type
= builtin_type_unsigned_short
;
806 case dst_uint32_type
:
807 type
= builtin_type_unsigned_long
;
809 case dst_real32_type
:
810 type
= builtin_type_float
;
812 case dst_real64_type
:
813 type
= builtin_type_double
;
815 case dst_complex_type
:
816 type
= builtin_type_complex
;
818 case dst_dcomplex_type
:
819 type
= builtin_type_double_complex
;
822 type
= builtin_type_char
;
824 case dst_bool16_type
:
825 type
= builtin_type_short
;
827 case dst_bool32_type
:
828 type
= builtin_type_long
;
831 type
= builtin_type_char
;
833 /* The next few are more complex. I will take care
834 * of them properly at a later point.
836 case dst_string_type
:
837 type
= builtin_type_void
;
840 type
= builtin_type_void
;
843 type
= builtin_type_void
;
846 type
= builtin_type_void
;
849 type
= builtin_type_void
;
851 /* Back tto some ordinary ones */
853 type
= builtin_type_void
;
856 type
= builtin_type_unsigned_char
;
859 type
= builtin_type_void
;
866 struct structure_list
868 struct structure_list
*next
;
872 static struct structure_list
*struct_list
= NULL
;
875 find_dst_structure(name
)
878 struct structure_list
*element
;
880 for (element
= struct_list
; element
; element
= element
->next
)
881 if (!strcmp(name
, TYPE_NAME(element
->type
)))
882 return element
->type
;
888 decode_dst_structure(objfile
, entry
, code
, version
)
889 struct objfile
*objfile
;
894 struct type
*type
, *child_type
;
896 char *name
, *field_name
;
898 int fieldoffset
, fieldsize
;
899 dst_type_t type_desc
;
900 struct structure_list
*element
;
902 struct_name
= DST_OFFSET(entry
, DST_record(entry
).noffset
);
903 name
= concat( (code
== TYPE_CODE_UNION
)?"union ":"struct ",
905 type
= find_dst_structure(name
);
911 type
= create_new_type(objfile
);
912 TYPE_NAME(type
) = obstack_copy0 (&objfile
->symbol_obstack
,
915 TYPE_CODE(type
) = code
;
916 TYPE_LENGTH(type
) = DST_record(entry
).size
;
917 TYPE_NFIELDS(type
) = DST_record(entry
).nfields
;
918 TYPE_FIELDS(type
) = (struct field
*)
919 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) *
920 DST_record(entry
).nfields
);
921 fieldoffset
= fieldsize
= 0;
922 INIT_CPLUS_SPECIFIC(type
);
923 element
= (struct structure_list
*)
924 xmalloc(sizeof(struct structure_list
));
925 element
->type
= type
;
926 element
->next
= struct_list
;
927 struct_list
= element
;
928 for (i
= 0; i
< DST_record(entry
).nfields
; i
++)
933 field_name
= DST_OFFSET(entry
,
934 DST_record(entry
).f
.ofields
[i
].noffset
);
935 fieldoffset
= DST_record(entry
).f
.ofields
[i
].foffset
*8 +
936 DST_record(entry
).f
.ofields
[i
].bit_offset
;
937 fieldsize
= DST_record(entry
).f
.ofields
[i
].size
;
938 type_desc
= DST_record(entry
).f
.ofields
[i
].type_desc
;
941 field_name
= DST_OFFSET(entry
,
942 DST_record(entry
).f
.fields
[i
].noffset
);
943 type_desc
= DST_record(entry
).f
.fields
[i
].type_desc
;
944 switch(DST_record(entry
).f
.fields
[i
].f
.field_loc
.format_tag
)
947 fieldoffset
= DST_record(entry
).f
.
948 fields
[i
].f
.field_byte
.offset
* 8;
952 fieldoffset
= DST_record(entry
).f
.
953 fields
[i
].f
.field_bit
.byte_offset
* 8 +
955 fields
[i
].f
.field_bit
.bit_offset
;
956 fieldsize
= DST_record(entry
).f
.
957 fields
[i
].f
.field_bit
.nbits
;
960 fieldoffset
+= fieldsize
;
966 field_name
= DST_OFFSET(entry
,
967 DST_record(entry
).f
.sfields
[i
].noffset
);
968 fieldoffset
= DST_record(entry
).f
.sfields
[i
].foffset
;
969 type_desc
= DST_record(entry
).f
.sfields
[i
].type_desc
;
970 if (i
< DST_record(entry
).nfields
- 1)
971 fieldsize
= DST_record(entry
).f
.sfields
[i
+1].foffset
;
973 fieldsize
= DST_record(entry
).size
;
974 fieldsize
-= fieldoffset
;
978 TYPE_FIELDS(type
)[i
].name
=
979 obstack_copy0 (&objfile
->symbol_obstack
,
980 field_name
, strlen(field_name
));
981 TYPE_FIELDS(type
)[i
].type
= decode_type_desc(objfile
,
985 fieldsize
= TYPE_LENGTH(TYPE_FIELDS(type
)[i
].type
) *
987 TYPE_FIELDS(type
)[i
].bitsize
= fieldsize
;
988 TYPE_FIELDS(type
)[i
].bitpos
= fieldoffset
;
994 decode_dst_type(objfile
, entry
)
995 struct objfile
*objfile
;
998 struct type
*child_type
, *type
, *range_type
, *index_type
;
1000 switch(entry
->rec_type
)
1003 return decode_type_desc(objfile
,
1004 &DST_var(entry
).type_desc
,
1007 case dst_typ_variable
:
1008 return decode_type_desc(objfile
,
1009 &DST_variable(entry
).type_desc
,
1012 case dst_typ_short_rec
:
1013 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,0);
1014 case dst_typ_short_union
:
1015 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 0);
1017 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 1);
1018 case dst_typ_record
:
1019 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,1);
1020 case dst_typ_old_union
:
1021 return decode_dst_structure(objfile
, entry
, TYPE_CODE_UNION
, 2);
1022 case dst_typ_old_record
:
1023 return decode_dst_structure(objfile
, entry
, TYPE_CODE_STRUCT
,2);
1024 case dst_typ_pointer
:
1025 return make_pointer_type(
1026 decode_type_desc(objfile
,
1027 &DST_pointer(entry
).type_desc
,
1031 child_type
= decode_type_desc(objfile
,
1032 &DST_pointer(entry
).type_desc
,
1034 index_type
= lookup_fundamental_type(objfile
,
1036 range_type
= create_range_type ((struct type
*) NULL
,
1037 index_type
, DST_array(entry
).lo_bound
,
1038 DST_array(entry
).hi_bound
);
1039 return create_array_type ((struct type
*) NULL
, child_type
,
1042 return decode_type_desc(objfile
,
1043 &DST_alias(entry
).type_desc
,
1046 return builtin_type_int
;
1050 struct symbol_list
{
1051 struct symbol_list
*next
;
1052 struct symbol
*symbol
;
1055 static struct symbol_list
*dst_global_symbols
= NULL
;
1056 static int total_globals
= 0;
1059 decode_dst_locstring(locstr
, sym
)
1063 dst_loc_entry_t
*entry
, *next_entry
;
1071 fprintf_unfiltered(gdb_stderr
, "Error reading locstring\n");
1074 entry
= (dst_loc_entry_t
*) locstr
;
1075 next_entry
= (dst_loc_entry_t
*) (locstr
+ 1);
1076 switch (entry
->header
.code
)
1078 case dst_lsc_end
: /* End of string */
1080 case dst_lsc_indirect
:/* Indirect through previous. Arg == 6 */
1081 /* Or register ax x == arg */
1082 if (entry
->header
.arg
< 6)
1084 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1085 SYMBOL_VALUE(sym
) = entry
->header
.arg
+ 8;
1087 /* We predict indirects */
1091 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1092 SYMBOL_VALUE(sym
) = entry
->header
.arg
;
1095 case dst_lsc_section
:/* Section (arg+1) */
1096 SYMBOL_VALUE(sym
) = dst_get_addr(entry
->header
.arg
+1, 0);
1099 case dst_lsc_sec_byte
: /* Section (next_byte+1) */
1100 SYMBOL_VALUE(sym
) = dst_get_addr(locstr
[1]+1, 0);
1103 case dst_lsc_add
: /* Add (arg+1)*2 */
1104 case dst_lsc_sub
: /* Subtract (arg+1)*2 */
1105 temp
= (entry
->header
.arg
+ 1) * 2;
1107 if (*locstr
== dst_multiply_256
)
1112 switch(entry
->header
.code
)
1115 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1116 SYMBOL_CLASS(sym
) = LOC_ARG
;
1117 SYMBOL_VALUE(sym
) += temp
;
1120 SYMBOL_VALUE(sym
) -= temp
;
1124 case dst_lsc_add_byte
:
1125 case dst_lsc_sub_byte
:
1126 switch (entry
->header
.arg
& 0x03)
1129 temp
= (unsigned char) locstr
[1];
1133 temp
= * (unsigned short *) (locstr
+ 1);
1137 temp
= * (unsigned long *) (locstr
+ 1);
1141 if (*locstr
== dst_multiply_256
)
1146 switch(entry
->header
.code
)
1148 case dst_lsc_add_byte
:
1149 if (SYMBOL_CLASS(sym
) == LOC_LOCAL
)
1150 SYMBOL_CLASS(sym
) = LOC_ARG
;
1151 SYMBOL_VALUE(sym
) += temp
;
1153 case dst_lsc_sub_byte
:
1154 SYMBOL_VALUE(sym
) -= temp
;
1158 case dst_lsc_sbreg
: /* Stack base register (frame pointer). Arg==0*/
1159 if (next_entry
->header
.code
!= dst_lsc_indirect
)
1161 SYMBOL_VALUE(sym
) = 0;
1162 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1165 SYMBOL_VALUE(sym
) = 0;
1166 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1170 SYMBOL_VALUE(sym
) = 0;
1171 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1177 static struct symbol_list
*
1178 process_dst_symbols(objfile
, entry
, name
, nsyms_ret
)
1179 struct objfile
*objfile
;
1180 dst_rec_ptr_t entry
;
1184 struct symbol_list
*list
= NULL
, *element
;
1192 dst_var_attr_t attr
;
1193 dst_var_loc_t loc_type
;
1202 location
= (char *) entry
;
1203 while (NEXT_SYM(&location
, &entry
) &&
1204 entry
->rec_type
!= dst_typ_end_scope
)
1206 if (entry
->rec_type
== dst_typ_var
)
1208 if (DST_var(entry
).short_locs
)
1210 loc_type
= DST_var(entry
).locs
.shorts
[0].loc_type
;
1211 loc_index
= DST_var(entry
).locs
.shorts
[0].loc_index
;
1212 loc_value
= DST_var(entry
).locs
.shorts
[0].location
;
1216 loc_type
= DST_var(entry
).locs
.longs
[0].loc_type
;
1217 loc_index
= DST_var(entry
).locs
.longs
[0].loc_index
;
1218 loc_value
= DST_var(entry
).locs
.longs
[0].location
;
1220 if (loc_type
== dst_var_loc_external
)
1222 symname
= DST_OFFSET(entry
, DST_var(entry
).noffset
);
1223 line
= DST_var(entry
).src_loc
.line_number
;
1224 symtype
= DST_var(entry
).type_desc
;
1225 attr
= DST_var(entry
).attributes
;
1227 else if (entry
->rec_type
== dst_typ_variable
)
1229 symname
= DST_OFFSET(entry
,
1230 DST_variable(entry
).noffset
);
1231 line
= DST_variable(entry
).src_loc
.line_number
;
1232 symtype
= DST_variable(entry
).type_desc
;
1233 attr
= DST_variable(entry
).attributes
;
1239 if (symname
&& name
&& !strcmp(symname
, name
))
1240 /* It's the function return value */
1242 sym
= create_new_symbol(objfile
, symname
);
1244 if ((attr
& (1<<dst_var_attr_global
)) ||
1245 (attr
& (1<<dst_var_attr_static
)))
1246 SYMBOL_CLASS(sym
) = LOC_STATIC
;
1248 SYMBOL_CLASS(sym
) = LOC_LOCAL
;
1249 SYMBOL_LINE(sym
) = line
;
1250 SYMBOL_TYPE(sym
) = decode_type_desc(objfile
, &symtype
,
1252 SYMBOL_VALUE(sym
) = 0;
1253 switch (entry
->rec_type
)
1258 case dst_var_loc_abs
:
1259 SYMBOL_VALUE_ADDRESS(sym
) = loc_value
;
1261 case dst_var_loc_sect_off
:
1262 case dst_var_loc_ind_sect_off
: /* What is this? */
1263 SYMBOL_VALUE_ADDRESS(sym
) = dst_get_addr(
1267 case dst_var_loc_ind_reg_rel
: /* What is this? */
1268 case dst_var_loc_reg_rel
:
1269 /* If it isn't fp relative, specify the
1270 * register it's relative to.
1274 sym
->aux_value
.basereg
= loc_index
;
1276 SYMBOL_VALUE(sym
) = loc_value
;
1277 if (loc_value
> 0 &&
1278 SYMBOL_CLASS(sym
) == LOC_BASEREG
)
1279 SYMBOL_CLASS(sym
) = LOC_BASEREG_ARG
;
1281 case dst_var_loc_reg
:
1282 SYMBOL_VALUE(sym
) = loc_index
;
1283 SYMBOL_CLASS(sym
) = LOC_REGISTER
;
1287 case dst_typ_variable
:
1288 /* External variable..... don't try to interpret
1289 * its nonexistant locstring.
1291 if (DST_variable(entry
).loffset
== -1)
1293 decode_dst_locstring(DST_OFFSET(entry
,
1294 DST_variable(entry
).loffset
),
1297 element
= (struct symbol_list
*)
1298 xmalloc(sizeof(struct symbol_list
));
1300 if (attr
& (1<<dst_var_attr_global
))
1302 element
->next
= dst_global_symbols
;
1303 dst_global_symbols
= element
;
1308 element
->next
= list
;
1312 element
->symbol
= sym
;
1319 static struct symbol
*
1320 process_dst_function(objfile
, entry
, name
, address
)
1321 struct objfile
*objfile
;
1322 dst_rec_ptr_t entry
;
1327 struct type
*type
, *ftype
;
1328 dst_rec_ptr_t sym_entry
, typ_entry
;
1330 struct symbol_list
*element
;
1332 type
= builtin_type_int
;
1333 sym
= create_new_symbol(objfile
, name
);
1334 SYMBOL_CLASS(sym
) = LOC_BLOCK
;
1338 location
= (char *) entry
;
1341 NEXT_SYM(&location
, &sym_entry
);
1342 } while (sym_entry
&& sym_entry
->rec_type
!= dst_typ_signature
);
1347 DST_signature(sym_entry
).src_loc
.line_number
;
1348 if (DST_signature(sym_entry
).result
)
1350 typ_entry
= (dst_rec_ptr_t
)
1351 DST_OFFSET(sym_entry
,
1352 DST_signature(sym_entry
).result
);
1353 type
= decode_dst_type(objfile
, typ_entry
);
1358 if (!type
->function_type
)
1360 ftype
= create_new_type(objfile
);
1361 type
->function_type
= ftype
;
1362 ftype
->target_type
= type
;
1363 ftype
->code
= TYPE_CODE_FUNC
;
1365 SYMBOL_TYPE(sym
) = type
->function_type
;
1367 /* Now add ourselves to the global symbols list */
1368 element
= (struct symbol_list
*)
1369 xmalloc(sizeof(struct symbol_list
));
1371 element
->next
= dst_global_symbols
;
1372 dst_global_symbols
= element
;
1374 element
->symbol
= sym
;
1379 static struct block
*
1380 process_dst_block(objfile
, entry
)
1381 struct objfile
*objfile
;
1382 dst_rec_ptr_t entry
;
1384 struct block
*block
;
1385 struct symbol
*function
= NULL
;
1389 dst_rec_ptr_t child_entry
, symbol_entry
;
1390 struct block
*child_block
;
1391 int total_symbols
= 0;
1393 static long fake_seq
= 0;
1394 struct symbol_list
*symlist
, *nextsym
;
1397 if (DST_block(entry
).noffset
)
1398 name
= DST_OFFSET(entry
, DST_block(entry
).noffset
);
1401 if (DST_block(entry
).n_of_code_ranges
)
1403 address
= dst_sym_addr(
1404 &DST_block(entry
).code_ranges
[0].code_start
);
1405 size
= DST_block(entry
).code_ranges
[0].code_size
;
1412 symbol_entry
= (dst_rec_ptr_t
) get_sec_ref(&DST_block(entry
).symbols_start
);
1413 switch(DST_block(entry
).block_type
)
1415 /* These are all really functions. Even the "program" type.
1416 * This is because the Apollo OS was written in Pascal, and
1417 * in Pascal, the main procedure is described as the Program.
1420 case dst_block_procedure
:
1421 case dst_block_function
:
1422 case dst_block_subroutine
:
1423 case dst_block_program
:
1424 prim_record_minimal_symbol(name
, address
, mst_text
, objfile
);
1425 function
= process_dst_function(
1430 enter_all_lines(get_sec_ref(&DST_block(entry
).code_ranges
[0].lines_start
), address
);
1432 case dst_block_block_data
:
1436 /* GDB has to call it something, and the module name
1439 sprintf(fake_name
, "block_%08lx", fake_seq
++);
1440 function
= process_dst_function(
1441 objfile
, NULL
, fake_name
, address
);
1444 symlist
= process_dst_symbols(objfile
, symbol_entry
,
1445 name
, &total_symbols
);
1446 block
= (struct block
*)
1447 obstack_alloc (&objfile
->symbol_obstack
,
1448 sizeof (struct block
) +
1449 (total_symbols
- 1) * sizeof (struct symbol
*));
1454 nextsym
= symlist
->next
;
1456 block
->sym
[symnum
] = symlist
->symbol
;
1458 free((PTR
) symlist
);
1462 BLOCK_NSYMS (block
) = total_symbols
;
1463 BLOCK_START (block
) = address
;
1464 BLOCK_END (block
) = address
+ size
;
1465 BLOCK_SUPERBLOCK (block
) = 0;
1468 SYMBOL_BLOCK_VALUE (function
) = block
;
1469 BLOCK_FUNCTION (block
) = function
;
1472 BLOCK_FUNCTION (block
) = 0;
1474 if (DST_block(entry
).child_block_off
)
1476 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1477 DST_block(entry
).child_block_off
);
1480 child_block
= process_dst_block(objfile
, child_entry
);
1483 if (BLOCK_START(child_block
) <
1484 BLOCK_START(block
) ||
1485 BLOCK_START(block
) == -1)
1486 BLOCK_START(block
) =
1487 BLOCK_START(child_block
);
1488 if (BLOCK_END(child_block
) >
1490 BLOCK_END(block
) == -1)
1492 BLOCK_END(child_block
);
1493 BLOCK_SUPERBLOCK (child_block
) = block
;
1495 if (DST_block(child_entry
).sibling_block_off
)
1496 child_entry
= (dst_rec_ptr_t
) DST_OFFSET(
1498 DST_block(child_entry
).sibling_block_off
);
1503 record_pending_block (objfile
, block
, NULL
);
1509 read_dst_symtab (objfile
)
1510 struct objfile
*objfile
;
1513 dst_rec_ptr_t entry
, file_table
, root_block
;
1515 struct block
*block
, *global_block
;
1517 struct symbol_list
*nextsym
;
1519 struct structure_list
*element
;
1521 current_objfile
= objfile
;
1522 buffer
= blocks_info
.buffer
;
1523 while (NEXT_BLK(&buffer
, &entry
))
1525 if (entry
->rec_type
== dst_typ_comp_unit
)
1527 file_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1528 DST_comp_unit(entry
).file_table
);
1529 section_table
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1530 DST_comp_unit(entry
).section_table
);
1531 root_block
= (dst_rec_ptr_t
) DST_OFFSET(entry
,
1532 DST_comp_unit(entry
).root_block_offset
);
1533 source_file
= DST_OFFSET(file_table
,
1534 DST_file_tab(file_table
).files
[0].noffset
);
1535 /* Point buffer to the start of the next comp_unit */
1536 buffer
= DST_OFFSET(entry
,
1537 DST_comp_unit(entry
).data_size
);
1540 block
= process_dst_block(objfile
, root_block
);
1542 global_block
= (struct block
*)
1543 obstack_alloc (&objfile
->symbol_obstack
,
1544 sizeof (struct block
) +
1545 (total_globals
- 1) *
1546 sizeof (struct symbol
*));
1547 BLOCK_NSYMS(global_block
) = total_globals
;
1548 for (symnum
= 0; symnum
< total_globals
; symnum
++)
1550 nextsym
= dst_global_symbols
->next
;
1552 global_block
->sym
[symnum
] =
1553 dst_global_symbols
->symbol
;
1555 free((PTR
) dst_global_symbols
);
1556 dst_global_symbols
= nextsym
;
1558 dst_global_symbols
= NULL
;
1560 BLOCK_FUNCTION(global_block
) = 0;
1561 BLOCK_START(global_block
) = BLOCK_START(block
);
1562 BLOCK_END(global_block
) = BLOCK_END(block
);
1563 BLOCK_SUPERBLOCK(global_block
) = 0;
1564 BLOCK_SUPERBLOCK(block
) = global_block
;
1565 record_pending_block (objfile
, global_block
, NULL
);
1567 complete_symtab(source_file
,
1569 BLOCK_END(block
) - BLOCK_START(block
));
1571 dst_end_symtab(objfile
);
1575 prim_record_minimal_symbol("<end_of_program>",
1576 BLOCK_END(block
), mst_text
, objfile
);
1577 /* One more faked symbol to make sure nothing can ever run off the
1578 * end of the symbol table. This one represents the end of the
1579 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1580 * int possible), but some parts of gdb treated it as a signed
1581 * number and failed comparisons. We could equally use 7fffffff,
1582 * but no functions are ever mapped to an address higher than
1585 prim_record_minimal_symbol("<end_of_text>",
1586 (CORE_ADDR
) 0x40000000,
1590 element
= struct_list
;
1591 struct_list
= element
->next
;
1592 free((PTR
) element
);
1597 /* Support for line number handling */
1598 static char *linetab
= NULL
;
1599 static long linetab_offset
;
1600 static unsigned long linetab_size
;
1602 /* Read in all the line numbers for fast lookups later. Leave them in
1603 external (unswapped) format in memory; we'll swap them as we enter
1604 them into GDB's data structures. */
1606 init_one_section(chan
, secinfo
)
1610 if (secinfo
->size
== 0
1611 || lseek(chan
, secinfo
->position
, 0) == -1
1612 || (secinfo
->buffer
= xmalloc(secinfo
->size
)) == NULL
1613 || myread(chan
, secinfo
->buffer
, secinfo
->size
) == -1)
1620 init_dst_sections (chan
)
1624 if (!init_one_section(chan
, &blocks_info
) ||
1625 !init_one_section(chan
, &lines_info
) ||
1626 !init_one_section(chan
, &symbols_info
))
1632 /* Fake up support for relocating symbol addresses. FIXME. */
1634 struct section_offsets dst_symfile_faker
= {0};
1636 struct section_offsets
*
1637 dst_symfile_offsets (objfile
, addr
)
1638 struct objfile
*objfile
;
1641 objfile
->num_sections
= 1;
1642 return &dst_symfile_faker
;
1645 /* Register our ability to parse symbols for DST BFD files */
1647 static struct sym_fns dst_sym_fns
=
1649 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1650 a separate flavour like ecoff? */
1651 (enum bfd_flavour
)-2,
1653 dst_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1654 dst_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1655 dst_symfile_read
, /* sym_read: read a symbol file into symtab */
1656 dst_symfile_finish
, /* sym_finish: finished with file, cleanup */
1657 dst_symfile_offsets
, /* sym_offsets: xlate external to internal form */
1658 NULL
/* next: pointer to next struct sym_fns */
1662 _initialize_dstread ()
1664 add_symtab_fns(&dst_sym_fns
);