2002-07-29 Andrew Cagney <ac131313@redhat.com>
[deliverable/binutils-gdb.git] / gdb / dstread.c
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, 1994, 1995, 1996, 1997, 1998, 1999, 2000
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22 \f
23 #include "defs.h"
24 #include "symtab.h"
25 #include "gdbtypes.h"
26 #include "breakpoint.h"
27 #include "bfd.h"
28 #include "symfile.h"
29 #include "objfiles.h"
30 #include "buildsym.h"
31 #include "gdb_obstack.h"
32
33 #include "gdb_string.h"
34
35 #include "dst.h"
36
37 CORE_ADDR cur_src_start_addr, cur_src_end_addr;
38 dst_sec blocks_info, lines_info, symbols_info;
39
40 /* Vector of line number information. */
41
42 static struct linetable *line_vector;
43
44 /* Index of next entry to go in line_vector_index. */
45
46 static int line_vector_index;
47
48 /* Last line number recorded in the line vector. */
49
50 static int prev_line_number;
51
52 /* Number of elements allocated for line_vector currently. */
53
54 static int line_vector_length;
55
56 static int init_dst_sections (int);
57
58 static void read_dst_symtab (struct objfile *);
59
60 static void find_dst_sections (bfd *, sec_ptr, PTR);
61
62 static void dst_symfile_init (struct objfile *);
63
64 static void dst_new_init (struct objfile *);
65
66 static void dst_symfile_read (struct objfile *, int);
67
68 static void dst_symfile_finish (struct objfile *);
69
70 static void dst_end_symtab (struct objfile *);
71
72 static void complete_symtab (char *, CORE_ADDR, unsigned int);
73
74 static void dst_start_symtab (void);
75
76 static void dst_record_line (int, CORE_ADDR);
77
78 /* Manage the vector of line numbers. */
79 /* FIXME: Use record_line instead. */
80
81 static void
82 dst_record_line (int line, CORE_ADDR pc)
83 {
84 struct linetable_entry *e;
85 /* Make sure line vector is big enough. */
86
87 if (line_vector_index + 2 >= line_vector_length)
88 {
89 line_vector_length *= 2;
90 line_vector = (struct linetable *)
91 xrealloc ((char *) line_vector, sizeof (struct linetable)
92 + (line_vector_length
93 * sizeof (struct linetable_entry)));
94 }
95
96 e = line_vector->item + line_vector_index++;
97 e->line = line;
98 e->pc = pc;
99 }
100 \f
101 /* Start a new symtab for a new source file.
102 It indicates the start of data for one original source file. */
103 /* FIXME: use start_symtab, like coffread.c now does. */
104
105 static void
106 dst_start_symtab (void)
107 {
108 /* Initialize the source file line number information for this file. */
109
110 if (line_vector) /* Unlikely, but maybe possible? */
111 xfree (line_vector);
112 line_vector_index = 0;
113 line_vector_length = 1000;
114 prev_line_number = -2; /* Force first line number to be explicit */
115 line_vector = (struct linetable *)
116 xmalloc (sizeof (struct linetable)
117 + line_vector_length * sizeof (struct linetable_entry));
118 }
119
120 /* Save the vital information from when starting to read a file,
121 for use when closing off the current file.
122 NAME is the file name the symbols came from, START_ADDR is the first
123 text address for the file, and SIZE is the number of bytes of text. */
124
125 static void
126 complete_symtab (char *name, CORE_ADDR start_addr, unsigned int size)
127 {
128 last_source_file = savestring (name, strlen (name));
129 cur_src_start_addr = start_addr;
130 cur_src_end_addr = start_addr + size;
131
132 if (current_objfile->ei.entry_point >= cur_src_start_addr &&
133 current_objfile->ei.entry_point < cur_src_end_addr)
134 {
135 current_objfile->ei.entry_file_lowpc = cur_src_start_addr;
136 current_objfile->ei.entry_file_highpc = cur_src_end_addr;
137 }
138 }
139
140 /* Finish the symbol definitions for one main source file,
141 close off all the lexical contexts for that file
142 (creating struct block's for them), then make the
143 struct symtab for that file and put it in the list of all such. */
144 /* FIXME: Use end_symtab, like coffread.c now does. */
145
146 static void
147 dst_end_symtab (struct objfile *objfile)
148 {
149 register struct symtab *symtab;
150 register struct blockvector *blockvector;
151 register struct linetable *lv;
152
153 /* Create the blockvector that points to all the file's blocks. */
154
155 blockvector = make_blockvector (objfile);
156
157 /* Now create the symtab object for this source file. */
158 symtab = allocate_symtab (last_source_file, objfile);
159
160 /* Fill in its components. */
161 symtab->blockvector = blockvector;
162 symtab->free_code = free_linetable;
163 symtab->free_ptr = 0;
164 symtab->filename = last_source_file;
165 symtab->dirname = NULL;
166 symtab->debugformat = obsavestring ("Apollo DST", 10,
167 &objfile->symbol_obstack);
168 lv = line_vector;
169 lv->nitems = line_vector_index;
170 symtab->linetable = (struct linetable *)
171 xrealloc ((char *) lv, (sizeof (struct linetable)
172 + lv->nitems * sizeof (struct linetable_entry)));
173
174 free_named_symtabs (symtab->filename);
175
176 /* Reinitialize for beginning of new file. */
177 line_vector = 0;
178 line_vector_length = -1;
179 last_source_file = NULL;
180 }
181 \f
182 /* dst_symfile_init ()
183 is the dst-specific initialization routine for reading symbols.
184
185 We will only be called if this is a DST or DST-like file.
186 BFD handles figuring out the format of the file, and code in symtab.c
187 uses BFD's determination to vector to us.
188
189 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
190
191 static void
192 dst_symfile_init (struct objfile *objfile)
193 {
194 asection *section;
195 bfd *abfd = objfile->obfd;
196
197 init_entry_point_info (objfile);
198
199 }
200
201 /* This function is called for every section; it finds the outer limits
202 of the line table (minimum and maximum file offset) so that the
203 mainline code can read the whole thing for efficiency. */
204
205 /* ARGSUSED */
206 static void
207 find_dst_sections (bfd *abfd, sec_ptr asect, PTR vpinfo)
208 {
209 int size, count;
210 long base;
211 file_ptr offset, maxoff;
212 dst_sec *section;
213
214 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
215 size = asect->_raw_size;
216 offset = asect->filepos;
217 base = asect->vma;
218 /* End of warning */
219
220 section = NULL;
221 if (!strcmp (asect->name, ".blocks"))
222 section = &blocks_info;
223 else if (!strcmp (asect->name, ".lines"))
224 section = &lines_info;
225 else if (!strcmp (asect->name, ".symbols"))
226 section = &symbols_info;
227 if (!section)
228 return;
229 section->size = size;
230 section->position = offset;
231 section->base = base;
232 }
233
234
235 /* The BFD for this file -- only good while we're actively reading
236 symbols into a psymtab or a symtab. */
237
238 static bfd *symfile_bfd;
239
240 /* Read a symbol file, after initialization by dst_symfile_init. */
241 /* FIXME! Addr and Mainline are not used yet -- this will not work for
242 shared libraries or add_file! */
243
244 /* ARGSUSED */
245 static void
246 dst_symfile_read (struct objfile *objfile, int mainline)
247 {
248 bfd *abfd = objfile->obfd;
249 char *name = bfd_get_filename (abfd);
250 int desc;
251 register int val;
252 int num_symbols;
253 int symtab_offset;
254 int stringtab_offset;
255
256 symfile_bfd = abfd; /* Kludge for swap routines */
257
258 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
259 desc = fileno ((FILE *) (abfd->iostream)); /* File descriptor */
260
261 /* Read the line number table, all at once. */
262 bfd_map_over_sections (abfd, find_dst_sections, (PTR) NULL);
263
264 val = init_dst_sections (desc);
265 if (val < 0)
266 error ("\"%s\": error reading debugging symbol tables\n", name);
267
268 init_minimal_symbol_collection ();
269 make_cleanup_discard_minimal_symbols ();
270
271 /* Now that the executable file is positioned at symbol table,
272 process it and define symbols accordingly. */
273
274 read_dst_symtab (objfile);
275
276 /* Sort symbols alphabetically within each block. */
277
278 {
279 struct symtab *s;
280 for (s = objfile->symtabs; s != NULL; s = s->next)
281 {
282 sort_symtab_syms (s);
283 }
284 }
285
286 /* Install any minimal symbols that have been collected as the current
287 minimal symbols for this objfile. */
288
289 install_minimal_symbols (objfile);
290 }
291
292 static void
293 dst_new_init (struct objfile *ignore)
294 {
295 /* Nothin' to do */
296 }
297
298 /* Perform any local cleanups required when we are done with a particular
299 objfile. I.E, we are in the process of discarding all symbol information
300 for an objfile, freeing up all memory held for it, and unlinking the
301 objfile struct from the global list of known objfiles. */
302
303 static void
304 dst_symfile_finish (struct objfile *objfile)
305 {
306 /* Nothing to do */
307 }
308 \f
309
310 /* Get the next line number from the DST. Returns 0 when we hit an
311 * end directive or cannot continue for any other reason.
312 *
313 * Note that ordinary pc deltas are multiplied by two. Apparently
314 * this is what was really intended.
315 */
316 static int
317 get_dst_line (signed char **buffer, long *pc)
318 {
319 static last_pc = 0;
320 static long last_line = 0;
321 static int last_file = 0;
322 dst_ln_entry_ptr_t entry;
323 int size;
324 dst_src_loc_t *src_loc;
325
326 if (*pc != -1)
327 {
328 last_pc = *pc;
329 *pc = -1;
330 }
331 entry = (dst_ln_entry_ptr_t) * buffer;
332
333 while (dst_ln_ln_delta (*entry) == dst_ln_escape_flag)
334 {
335 switch (entry->esc.esc_code)
336 {
337 case dst_ln_pad:
338 size = 1; /* pad byte */
339 break;
340 case dst_ln_file:
341 /* file escape. Next 4 bytes are a dst_src_loc_t */
342 size = 5;
343 src_loc = (dst_src_loc_t *) (*buffer + 1);
344 last_line = src_loc->line_number;
345 last_file = src_loc->file_index;
346 break;
347 case dst_ln_dln1_dpc1:
348 /* 1 byte line delta, 1 byte pc delta */
349 last_line += (*buffer)[1];
350 last_pc += 2 * (unsigned char) (*buffer)[2];
351 dst_record_line (last_line, last_pc);
352 size = 3;
353 break;
354 case dst_ln_dln2_dpc2:
355 /* 2 bytes line delta, 2 bytes pc delta */
356 last_line += *(short *) (*buffer + 1);
357 last_pc += 2 * (*(short *) (*buffer + 3));
358 size = 5;
359 dst_record_line (last_line, last_pc);
360 break;
361 case dst_ln_ln4_pc4:
362 /* 4 bytes ABSOLUTE line number, 4 bytes ABSOLUTE pc */
363 last_line = *(unsigned long *) (*buffer + 1);
364 last_pc = *(unsigned long *) (*buffer + 5);
365 size = 9;
366 dst_record_line (last_line, last_pc);
367 break;
368 case dst_ln_dln1_dpc0:
369 /* 1 byte line delta, pc delta = 0 */
370 size = 2;
371 last_line += (*buffer)[1];
372 break;
373 case dst_ln_ln_off_1:
374 /* statement escape, stmt # = 1 (2nd stmt on line) */
375 size = 1;
376 break;
377 case dst_ln_ln_off:
378 /* statement escape, stmt # = next byte */
379 size = 2;
380 break;
381 case dst_ln_entry:
382 /* entry escape, next byte is entry number */
383 size = 2;
384 break;
385 case dst_ln_exit:
386 /* exit escape */
387 size = 1;
388 break;
389 case dst_ln_stmt_end:
390 /* gap escape, 4 bytes pc delta */
391 size = 5;
392 /* last_pc += 2 * (*(long *) (*buffer + 1)); */
393 /* Apparently this isn't supposed to actually modify
394 * the pc value. Totally weird.
395 */
396 break;
397 case dst_ln_escape_11:
398 case dst_ln_escape_12:
399 case dst_ln_escape_13:
400 size = 1;
401 break;
402 case dst_ln_nxt_byte:
403 /* This shouldn't happen. If it does, we're SOL */
404 return 0;
405 break;
406 case dst_ln_end:
407 /* end escape, final entry follows */
408 return 0;
409 }
410 *buffer += (size < 0) ? -size : size;
411 entry = (dst_ln_entry_ptr_t) * buffer;
412 }
413 last_line += dst_ln_ln_delta (*entry);
414 last_pc += entry->delta.pc_delta * 2;
415 (*buffer)++;
416 dst_record_line (last_line, last_pc);
417 return 1;
418 }
419
420 static void
421 enter_all_lines (char *buffer, long address)
422 {
423 if (buffer)
424 while (get_dst_line (&buffer, &address));
425 }
426
427 static int
428 get_dst_entry (char *buffer, dst_rec_ptr_t *ret_entry)
429 {
430 int size;
431 dst_rec_ptr_t entry;
432 static int last_type;
433 int ar_size;
434 static unsigned lu3;
435
436 entry = (dst_rec_ptr_t) buffer;
437 switch (entry->rec_type)
438 {
439 case dst_typ_pad:
440 size = 0;
441 break;
442 case dst_typ_comp_unit:
443 size = sizeof (DST_comp_unit (entry));
444 break;
445 case dst_typ_section_tab:
446 size = sizeof (DST_section_tab (entry))
447 + ((int) DST_section_tab (entry).number_of_sections
448 - dst_dummy_array_size) * sizeof (long);
449 break;
450 case dst_typ_file_tab:
451 size = sizeof (DST_file_tab (entry))
452 + ((int) DST_file_tab (entry).number_of_files
453 - dst_dummy_array_size) * sizeof (dst_file_desc_t);
454 break;
455 case dst_typ_block:
456 size = sizeof (DST_block (entry))
457 + ((int) DST_block (entry).n_of_code_ranges
458 - dst_dummy_array_size) * sizeof (dst_code_range_t);
459 break;
460 case dst_typ_5:
461 size = -1;
462 break;
463 case dst_typ_var:
464 size = sizeof (DST_var (entry)) -
465 sizeof (dst_var_loc_long_t) * dst_dummy_array_size +
466 DST_var (entry).no_of_locs *
467 (DST_var (entry).short_locs ?
468 sizeof (dst_var_loc_short_t) :
469 sizeof (dst_var_loc_long_t));
470 break;
471 case dst_typ_pointer:
472 size = sizeof (DST_pointer (entry));
473 break;
474 case dst_typ_array:
475 size = sizeof (DST_array (entry));
476 break;
477 case dst_typ_subrange:
478 size = sizeof (DST_subrange (entry));
479 break;
480 case dst_typ_set:
481 size = sizeof (DST_set (entry));
482 break;
483 case dst_typ_implicit_enum:
484 size = sizeof (DST_implicit_enum (entry))
485 + ((int) DST_implicit_enum (entry).nelems
486 - dst_dummy_array_size) * sizeof (dst_rel_offset_t);
487 break;
488 case dst_typ_explicit_enum:
489 size = sizeof (DST_explicit_enum (entry))
490 + ((int) DST_explicit_enum (entry).nelems
491 - dst_dummy_array_size) * sizeof (dst_enum_elem_t);
492 break;
493 case dst_typ_short_rec:
494 size = sizeof (DST_short_rec (entry))
495 + DST_short_rec (entry).nfields * sizeof (dst_short_field_t)
496 - dst_dummy_array_size * sizeof (dst_field_t);
497 break;
498 case dst_typ_short_union:
499 size = sizeof (DST_short_union (entry))
500 + DST_short_union (entry).nfields * sizeof (dst_short_field_t)
501 - dst_dummy_array_size * sizeof (dst_field_t);
502 break;
503 case dst_typ_file:
504 size = sizeof (DST_file (entry));
505 break;
506 case dst_typ_offset:
507 size = sizeof (DST_offset (entry));
508 break;
509 case dst_typ_alias:
510 size = sizeof (DST_alias (entry));
511 break;
512 case dst_typ_signature:
513 size = sizeof (DST_signature (entry)) +
514 ((int) DST_signature (entry).nargs -
515 dst_dummy_array_size) * sizeof (dst_arg_t);
516 break;
517 case dst_typ_21:
518 size = -1;
519 break;
520 case dst_typ_old_label:
521 size = sizeof (DST_old_label (entry));
522 break;
523 case dst_typ_scope:
524 size = sizeof (DST_scope (entry));
525 break;
526 case dst_typ_end_scope:
527 size = 0;
528 break;
529 case dst_typ_25:
530 case dst_typ_26:
531 size = -1;
532 break;
533 case dst_typ_string_tab:
534 case dst_typ_global_name_tab:
535 size = sizeof (DST_string_tab (entry))
536 + DST_string_tab (entry).length
537 - dst_dummy_array_size;
538 break;
539 case dst_typ_forward:
540 size = sizeof (DST_forward (entry));
541 get_dst_entry ((char *) entry + DST_forward (entry).rec_off, &entry);
542 break;
543 case dst_typ_aux_size:
544 size = sizeof (DST_aux_size (entry));
545 break;
546 case dst_typ_aux_align:
547 size = sizeof (DST_aux_align (entry));
548 break;
549 case dst_typ_aux_field_size:
550 size = sizeof (DST_aux_field_size (entry));
551 break;
552 case dst_typ_aux_field_off:
553 size = sizeof (DST_aux_field_off (entry));
554 break;
555 case dst_typ_aux_field_align:
556 size = sizeof (DST_aux_field_align (entry));
557 break;
558 case dst_typ_aux_qual:
559 size = sizeof (DST_aux_qual (entry));
560 break;
561 case dst_typ_aux_var_bound:
562 size = sizeof (DST_aux_var_bound (entry));
563 break;
564 case dst_typ_extension:
565 size = DST_extension (entry).rec_size;
566 break;
567 case dst_typ_string:
568 size = sizeof (DST_string (entry));
569 break;
570 case dst_typ_old_entry:
571 size = 48; /* Obsolete entry type */
572 break;
573 case dst_typ_const:
574 size = sizeof (DST_const (entry))
575 + DST_const (entry).value.length
576 - sizeof (DST_const (entry).value.val);
577 break;
578 case dst_typ_reference:
579 size = sizeof (DST_reference (entry));
580 break;
581 case dst_typ_old_record:
582 case dst_typ_old_union:
583 case dst_typ_record:
584 case dst_typ_union:
585 size = sizeof (DST_record (entry))
586 + ((int) DST_record (entry).nfields
587 - dst_dummy_array_size) * sizeof (dst_field_t);
588 break;
589 case dst_typ_aux_type_deriv:
590 size = sizeof (DST_aux_type_deriv (entry));
591 break;
592 case dst_typ_locpool:
593 size = sizeof (DST_locpool (entry))
594 + ((int) DST_locpool (entry).length -
595 dst_dummy_array_size);
596 break;
597 case dst_typ_variable:
598 size = sizeof (DST_variable (entry));
599 break;
600 case dst_typ_label:
601 size = sizeof (DST_label (entry));
602 break;
603 case dst_typ_entry:
604 size = sizeof (DST_entry (entry));
605 break;
606 case dst_typ_aux_lifetime:
607 size = sizeof (DST_aux_lifetime (entry));
608 break;
609 case dst_typ_aux_ptr_base:
610 size = sizeof (DST_aux_ptr_base (entry));
611 break;
612 case dst_typ_aux_src_range:
613 size = sizeof (DST_aux_src_range (entry));
614 break;
615 case dst_typ_aux_reg_val:
616 size = sizeof (DST_aux_reg_val (entry));
617 break;
618 case dst_typ_aux_unit_names:
619 size = sizeof (DST_aux_unit_names (entry))
620 + ((int) DST_aux_unit_names (entry).number_of_names
621 - dst_dummy_array_size) * sizeof (dst_rel_offset_t);
622 break;
623 case dst_typ_aux_sect_info:
624 size = sizeof (DST_aux_sect_info (entry))
625 + ((int) DST_aux_sect_info (entry).number_of_refs
626 - dst_dummy_array_size) * sizeof (dst_sect_ref_t);
627 break;
628 default:
629 size = -1;
630 break;
631 }
632 if (size == -1)
633 {
634 fprintf_unfiltered (gdb_stderr, "Warning: unexpected DST entry type (%d) found\nLast valid entry was of type: %d\n",
635 (int) entry->rec_type,
636 last_type);
637 fprintf_unfiltered (gdb_stderr, "Last unknown_3 value: %d\n", lu3);
638 size = 0;
639 }
640 else
641 last_type = entry->rec_type;
642 if (size & 1) /* Align on a word boundary */
643 size++;
644 size += 2;
645 *ret_entry = entry;
646 return size;
647 }
648
649 static int
650 next_dst_entry (char **buffer, dst_rec_ptr_t *entry, dst_sec *table)
651 {
652 if (*buffer - table->buffer >= table->size)
653 {
654 *entry = NULL;
655 return 0;
656 }
657 *buffer += get_dst_entry (*buffer, entry);
658 return 1;
659 }
660
661 #define NEXT_BLK(a, b) next_dst_entry(a, b, &blocks_info)
662 #define NEXT_SYM(a, b) next_dst_entry(a, b, &symbols_info)
663 #define DST_OFFSET(a, b) ((char *) (a) + (b))
664
665 static dst_rec_ptr_t section_table = NULL;
666
667 char *
668 get_sec_ref (dst_sect_ref_t *ref)
669 {
670 dst_sec *section = NULL;
671 long offset;
672
673 if (!section_table || !ref->sect_index)
674 return NULL;
675 offset = DST_section_tab (section_table).section_base[ref->sect_index - 1]
676 + ref->sect_offset;
677 if (offset >= blocks_info.base &&
678 offset < blocks_info.base + blocks_info.size)
679 section = &blocks_info;
680 else if (offset >= symbols_info.base &&
681 offset < symbols_info.base + symbols_info.size)
682 section = &symbols_info;
683 else if (offset >= lines_info.base &&
684 offset < lines_info.base + lines_info.size)
685 section = &lines_info;
686 if (!section)
687 return NULL;
688 return section->buffer + (offset - section->base);
689 }
690
691 CORE_ADDR
692 dst_get_addr (int section, long offset)
693 {
694 if (!section_table || !section)
695 return 0;
696 return DST_section_tab (section_table).section_base[section - 1] + offset;
697 }
698
699 CORE_ADDR
700 dst_sym_addr (dst_sect_ref_t *ref)
701 {
702 if (!section_table || !ref->sect_index)
703 return 0;
704 return DST_section_tab (section_table).section_base[ref->sect_index - 1]
705 + ref->sect_offset;
706 }
707
708 static struct symbol *
709 create_new_symbol (struct objfile *objfile, char *name)
710 {
711 struct symbol *sym = (struct symbol *)
712 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
713 memset (sym, 0, sizeof (struct symbol));
714 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
715 &objfile->symbol_obstack);
716 SYMBOL_VALUE (sym) = 0;
717 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
718
719 SYMBOL_CLASS (sym) = LOC_BLOCK;
720 return sym;
721 };
722
723 static struct type *decode_dst_type (struct objfile *, dst_rec_ptr_t);
724
725 static struct type *
726 decode_type_desc (struct objfile *objfile, dst_type_t *type_desc,
727 dst_rec_ptr_t base)
728 {
729 struct type *type;
730 dst_rec_ptr_t entry;
731 if (type_desc->std_type.user_defined_type)
732 {
733 entry = (dst_rec_ptr_t) DST_OFFSET (base,
734 dst_user_type_offset (*type_desc));
735 type = decode_dst_type (objfile, entry);
736 }
737 else
738 {
739 switch (type_desc->std_type.dtc)
740 {
741 case dst_int8_type:
742 type = builtin_type_signed_char;
743 break;
744 case dst_int16_type:
745 type = builtin_type_short;
746 break;
747 case dst_int32_type:
748 type = builtin_type_long;
749 break;
750 case dst_uint8_type:
751 type = builtin_type_unsigned_char;
752 break;
753 case dst_uint16_type:
754 type = builtin_type_unsigned_short;
755 break;
756 case dst_uint32_type:
757 type = builtin_type_unsigned_long;
758 break;
759 case dst_real32_type:
760 type = builtin_type_float;
761 break;
762 case dst_real64_type:
763 type = builtin_type_double;
764 break;
765 case dst_complex_type:
766 type = builtin_type_complex;
767 break;
768 case dst_dcomplex_type:
769 type = builtin_type_double_complex;
770 break;
771 case dst_bool8_type:
772 type = builtin_type_char;
773 break;
774 case dst_bool16_type:
775 type = builtin_type_short;
776 break;
777 case dst_bool32_type:
778 type = builtin_type_long;
779 break;
780 case dst_char_type:
781 type = builtin_type_char;
782 break;
783 /* The next few are more complex. I will take care
784 * of them properly at a later point.
785 */
786 case dst_string_type:
787 type = builtin_type_void;
788 break;
789 case dst_ptr_type:
790 type = builtin_type_void;
791 break;
792 case dst_set_type:
793 type = builtin_type_void;
794 break;
795 case dst_proc_type:
796 type = builtin_type_void;
797 break;
798 case dst_func_type:
799 type = builtin_type_void;
800 break;
801 /* Back tto some ordinary ones */
802 case dst_void_type:
803 type = builtin_type_void;
804 break;
805 case dst_uchar_type:
806 type = builtin_type_unsigned_char;
807 break;
808 default:
809 type = builtin_type_void;
810 break;
811 }
812 }
813 return type;
814 }
815
816 struct structure_list
817 {
818 struct structure_list *next;
819 struct type *type;
820 };
821
822 static struct structure_list *struct_list = NULL;
823
824 static struct type *
825 find_dst_structure (char *name)
826 {
827 struct structure_list *element;
828
829 for (element = struct_list; element; element = element->next)
830 if (!strcmp (name, TYPE_NAME (element->type)))
831 return element->type;
832 return NULL;
833 }
834
835
836 static struct type *
837 decode_dst_structure (struct objfile *objfile, dst_rec_ptr_t entry, int code,
838 int version)
839 {
840 struct type *type, *child_type;
841 char *struct_name;
842 char *name, *field_name;
843 int i;
844 int fieldoffset, fieldsize;
845 dst_type_t type_desc;
846 struct structure_list *element;
847
848 struct_name = DST_OFFSET (entry, DST_record (entry).noffset);
849 name = concat ((code == TYPE_CODE_UNION) ? "union " : "struct ",
850 struct_name, NULL);
851 type = find_dst_structure (name);
852 if (type)
853 {
854 xfree (name);
855 return type;
856 }
857 type = alloc_type (objfile);
858 TYPE_NAME (type) = obstack_copy0 (&objfile->symbol_obstack,
859 name, strlen (name));
860 xfree (name);
861 TYPE_CODE (type) = code;
862 TYPE_LENGTH (type) = DST_record (entry).size;
863 TYPE_NFIELDS (type) = DST_record (entry).nfields;
864 TYPE_FIELDS (type) = (struct field *)
865 obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) *
866 DST_record (entry).nfields);
867 fieldoffset = fieldsize = 0;
868 INIT_CPLUS_SPECIFIC (type);
869 element = (struct structure_list *)
870 xmalloc (sizeof (struct structure_list));
871 element->type = type;
872 element->next = struct_list;
873 struct_list = element;
874 for (i = 0; i < DST_record (entry).nfields; i++)
875 {
876 switch (version)
877 {
878 case 2:
879 field_name = DST_OFFSET (entry,
880 DST_record (entry).f.ofields[i].noffset);
881 fieldoffset = DST_record (entry).f.ofields[i].foffset * 8 +
882 DST_record (entry).f.ofields[i].bit_offset;
883 fieldsize = DST_record (entry).f.ofields[i].size;
884 type_desc = DST_record (entry).f.ofields[i].type_desc;
885 break;
886 case 1:
887 field_name = DST_OFFSET (entry,
888 DST_record (entry).f.fields[i].noffset);
889 type_desc = DST_record (entry).f.fields[i].type_desc;
890 switch (DST_record (entry).f.fields[i].f.field_loc.format_tag)
891 {
892 case dst_field_byte:
893 fieldoffset = DST_record (entry).f.
894 fields[i].f.field_byte.offset * 8;
895 fieldsize = -1;
896 break;
897 case dst_field_bit:
898 fieldoffset = DST_record (entry).f.
899 fields[i].f.field_bit.byte_offset * 8 +
900 DST_record (entry).f.
901 fields[i].f.field_bit.bit_offset;
902 fieldsize = DST_record (entry).f.
903 fields[i].f.field_bit.nbits;
904 break;
905 case dst_field_loc:
906 fieldoffset += fieldsize;
907 fieldsize = -1;
908 break;
909 }
910 break;
911 case 0:
912 field_name = DST_OFFSET (entry,
913 DST_record (entry).f.sfields[i].noffset);
914 fieldoffset = DST_record (entry).f.sfields[i].foffset;
915 type_desc = DST_record (entry).f.sfields[i].type_desc;
916 if (i < DST_record (entry).nfields - 1)
917 fieldsize = DST_record (entry).f.sfields[i + 1].foffset;
918 else
919 fieldsize = DST_record (entry).size;
920 fieldsize -= fieldoffset;
921 fieldoffset *= 8;
922 fieldsize *= 8;
923 }
924 TYPE_FIELDS (type)[i].name =
925 obstack_copy0 (&objfile->symbol_obstack,
926 field_name, strlen (field_name));
927 TYPE_FIELDS (type)[i].type = decode_type_desc (objfile,
928 &type_desc,
929 entry);
930 if (fieldsize == -1)
931 fieldsize = TYPE_LENGTH (TYPE_FIELDS (type)[i].type) *
932 8;
933 TYPE_FIELDS (type)[i].bitsize = fieldsize;
934 TYPE_FIELDS (type)[i].bitpos = fieldoffset;
935 }
936 return type;
937 }
938
939 static struct type *
940 decode_dst_type (struct objfile *objfile, dst_rec_ptr_t entry)
941 {
942 struct type *child_type, *type, *range_type, *index_type;
943
944 switch (entry->rec_type)
945 {
946 case dst_typ_var:
947 return decode_type_desc (objfile,
948 &DST_var (entry).type_desc,
949 entry);
950 break;
951 case dst_typ_variable:
952 return decode_type_desc (objfile,
953 &DST_variable (entry).type_desc,
954 entry);
955 break;
956 case dst_typ_short_rec:
957 return decode_dst_structure (objfile, entry, TYPE_CODE_STRUCT, 0);
958 case dst_typ_short_union:
959 return decode_dst_structure (objfile, entry, TYPE_CODE_UNION, 0);
960 case dst_typ_union:
961 return decode_dst_structure (objfile, entry, TYPE_CODE_UNION, 1);
962 case dst_typ_record:
963 return decode_dst_structure (objfile, entry, TYPE_CODE_STRUCT, 1);
964 case dst_typ_old_union:
965 return decode_dst_structure (objfile, entry, TYPE_CODE_UNION, 2);
966 case dst_typ_old_record:
967 return decode_dst_structure (objfile, entry, TYPE_CODE_STRUCT, 2);
968 case dst_typ_pointer:
969 return make_pointer_type (
970 decode_type_desc (objfile,
971 &DST_pointer (entry).type_desc,
972 entry),
973 NULL);
974 case dst_typ_array:
975 child_type = decode_type_desc (objfile,
976 &DST_pointer (entry).type_desc,
977 entry);
978 index_type = lookup_fundamental_type (objfile,
979 FT_INTEGER);
980 range_type = create_range_type ((struct type *) NULL,
981 index_type, DST_array (entry).lo_bound,
982 DST_array (entry).hi_bound);
983 return create_array_type ((struct type *) NULL, child_type,
984 range_type);
985 case dst_typ_alias:
986 return decode_type_desc (objfile,
987 &DST_alias (entry).type_desc,
988 entry);
989 default:
990 return builtin_type_int;
991 }
992 }
993
994 struct symbol_list
995 {
996 struct symbol_list *next;
997 struct symbol *symbol;
998 };
999
1000 static struct symbol_list *dst_global_symbols = NULL;
1001 static int total_globals = 0;
1002
1003 static void
1004 decode_dst_locstring (char *locstr, struct symbol *sym)
1005 {
1006 dst_loc_entry_t *entry, *next_entry;
1007 CORE_ADDR temp;
1008 int count = 0;
1009
1010 while (1)
1011 {
1012 if (count++ == 100)
1013 {
1014 fprintf_unfiltered (gdb_stderr, "Error reading locstring\n");
1015 break;
1016 }
1017 entry = (dst_loc_entry_t *) locstr;
1018 next_entry = (dst_loc_entry_t *) (locstr + 1);
1019 switch (entry->header.code)
1020 {
1021 case dst_lsc_end: /* End of string */
1022 return;
1023 case dst_lsc_indirect: /* Indirect through previous. Arg == 6 */
1024 /* Or register ax x == arg */
1025 if (entry->header.arg < 6)
1026 {
1027 SYMBOL_CLASS (sym) = LOC_REGISTER;
1028 SYMBOL_VALUE (sym) = entry->header.arg + 8;
1029 }
1030 /* We predict indirects */
1031 locstr++;
1032 break;
1033 case dst_lsc_dreg:
1034 SYMBOL_CLASS (sym) = LOC_REGISTER;
1035 SYMBOL_VALUE (sym) = entry->header.arg;
1036 locstr++;
1037 break;
1038 case dst_lsc_section: /* Section (arg+1) */
1039 SYMBOL_VALUE (sym) = dst_get_addr (entry->header.arg + 1, 0);
1040 locstr++;
1041 break;
1042 case dst_lsc_sec_byte: /* Section (next_byte+1) */
1043 SYMBOL_VALUE (sym) = dst_get_addr (locstr[1] + 1, 0);
1044 locstr += 2;
1045 break;
1046 case dst_lsc_add: /* Add (arg+1)*2 */
1047 case dst_lsc_sub: /* Subtract (arg+1)*2 */
1048 temp = (entry->header.arg + 1) * 2;
1049 locstr++;
1050 if (*locstr == dst_multiply_256)
1051 {
1052 temp <<= 8;
1053 locstr++;
1054 }
1055 switch (entry->header.code)
1056 {
1057 case dst_lsc_add:
1058 if (SYMBOL_CLASS (sym) == LOC_LOCAL)
1059 SYMBOL_CLASS (sym) = LOC_ARG;
1060 SYMBOL_VALUE (sym) += temp;
1061 break;
1062 case dst_lsc_sub:
1063 SYMBOL_VALUE (sym) -= temp;
1064 break;
1065 }
1066 break;
1067 case dst_lsc_add_byte:
1068 case dst_lsc_sub_byte:
1069 switch (entry->header.arg & 0x03)
1070 {
1071 case 1:
1072 temp = (unsigned char) locstr[1];
1073 locstr += 2;
1074 break;
1075 case 2:
1076 temp = *(unsigned short *) (locstr + 1);
1077 locstr += 3;
1078 break;
1079 case 3:
1080 temp = *(unsigned long *) (locstr + 1);
1081 locstr += 5;
1082 break;
1083 }
1084 if (*locstr == dst_multiply_256)
1085 {
1086 temp <<= 8;
1087 locstr++;
1088 }
1089 switch (entry->header.code)
1090 {
1091 case dst_lsc_add_byte:
1092 if (SYMBOL_CLASS (sym) == LOC_LOCAL)
1093 SYMBOL_CLASS (sym) = LOC_ARG;
1094 SYMBOL_VALUE (sym) += temp;
1095 break;
1096 case dst_lsc_sub_byte:
1097 SYMBOL_VALUE (sym) -= temp;
1098 break;
1099 }
1100 break;
1101 case dst_lsc_sbreg: /* Stack base register (frame pointer). Arg==0 */
1102 if (next_entry->header.code != dst_lsc_indirect)
1103 {
1104 SYMBOL_VALUE (sym) = 0;
1105 SYMBOL_CLASS (sym) = LOC_STATIC;
1106 return;
1107 }
1108 SYMBOL_VALUE (sym) = 0;
1109 SYMBOL_CLASS (sym) = LOC_LOCAL;
1110 locstr++;
1111 break;
1112 default:
1113 SYMBOL_VALUE (sym) = 0;
1114 SYMBOL_CLASS (sym) = LOC_STATIC;
1115 return;
1116 }
1117 }
1118 }
1119
1120 static struct symbol_list *
1121 process_dst_symbols (struct objfile *objfile, dst_rec_ptr_t entry, char *name,
1122 int *nsyms_ret)
1123 {
1124 struct symbol_list *list = NULL, *element;
1125 struct symbol *sym;
1126 char *symname;
1127 int nsyms = 0;
1128 char *location;
1129 long line;
1130 dst_type_t symtype;
1131 struct type *type;
1132 dst_var_attr_t attr;
1133 dst_var_loc_t loc_type;
1134 unsigned loc_index;
1135 long loc_value;
1136
1137 if (!entry)
1138 {
1139 *nsyms_ret = 0;
1140 return NULL;
1141 }
1142 location = (char *) entry;
1143 while (NEXT_SYM (&location, &entry) &&
1144 entry->rec_type != dst_typ_end_scope)
1145 {
1146 if (entry->rec_type == dst_typ_var)
1147 {
1148 if (DST_var (entry).short_locs)
1149 {
1150 loc_type = DST_var (entry).locs.shorts[0].loc_type;
1151 loc_index = DST_var (entry).locs.shorts[0].loc_index;
1152 loc_value = DST_var (entry).locs.shorts[0].location;
1153 }
1154 else
1155 {
1156 loc_type = DST_var (entry).locs.longs[0].loc_type;
1157 loc_index = DST_var (entry).locs.longs[0].loc_index;
1158 loc_value = DST_var (entry).locs.longs[0].location;
1159 }
1160 if (loc_type == dst_var_loc_external)
1161 continue;
1162 symname = DST_OFFSET (entry, DST_var (entry).noffset);
1163 line = DST_var (entry).src_loc.line_number;
1164 symtype = DST_var (entry).type_desc;
1165 attr = DST_var (entry).attributes;
1166 }
1167 else if (entry->rec_type == dst_typ_variable)
1168 {
1169 symname = DST_OFFSET (entry,
1170 DST_variable (entry).noffset);
1171 line = DST_variable (entry).src_loc.line_number;
1172 symtype = DST_variable (entry).type_desc;
1173 attr = DST_variable (entry).attributes;
1174 }
1175 else
1176 {
1177 continue;
1178 }
1179 if (symname && name && !strcmp (symname, name))
1180 /* It's the function return value */
1181 continue;
1182 sym = create_new_symbol (objfile, symname);
1183
1184 if ((attr & (1 << dst_var_attr_global)) ||
1185 (attr & (1 << dst_var_attr_static)))
1186 SYMBOL_CLASS (sym) = LOC_STATIC;
1187 else
1188 SYMBOL_CLASS (sym) = LOC_LOCAL;
1189 SYMBOL_LINE (sym) = line;
1190 SYMBOL_TYPE (sym) = decode_type_desc (objfile, &symtype,
1191 entry);
1192 SYMBOL_VALUE (sym) = 0;
1193 switch (entry->rec_type)
1194 {
1195 case dst_typ_var:
1196 switch (loc_type)
1197 {
1198 case dst_var_loc_abs:
1199 SYMBOL_VALUE_ADDRESS (sym) = loc_value;
1200 break;
1201 case dst_var_loc_sect_off:
1202 case dst_var_loc_ind_sect_off: /* What is this? */
1203 SYMBOL_VALUE_ADDRESS (sym) = dst_get_addr (
1204 loc_index,
1205 loc_value);
1206 break;
1207 case dst_var_loc_ind_reg_rel: /* What is this? */
1208 case dst_var_loc_reg_rel:
1209 /* If it isn't fp relative, specify the
1210 * register it's relative to.
1211 */
1212 if (loc_index)
1213 {
1214 sym->aux_value.basereg = loc_index;
1215 }
1216 SYMBOL_VALUE (sym) = loc_value;
1217 if (loc_value > 0 &&
1218 SYMBOL_CLASS (sym) == LOC_BASEREG)
1219 SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
1220 break;
1221 case dst_var_loc_reg:
1222 SYMBOL_VALUE (sym) = loc_index;
1223 SYMBOL_CLASS (sym) = LOC_REGISTER;
1224 break;
1225 }
1226 break;
1227 case dst_typ_variable:
1228 /* External variable..... don't try to interpret
1229 * its nonexistant locstring.
1230 */
1231 if (DST_variable (entry).loffset == -1)
1232 continue;
1233 decode_dst_locstring (DST_OFFSET (entry,
1234 DST_variable (entry).loffset),
1235 sym);
1236 }
1237 element = (struct symbol_list *)
1238 xmalloc (sizeof (struct symbol_list));
1239
1240 if (attr & (1 << dst_var_attr_global))
1241 {
1242 element->next = dst_global_symbols;
1243 dst_global_symbols = element;
1244 total_globals++;
1245 }
1246 else
1247 {
1248 element->next = list;
1249 list = element;
1250 nsyms++;
1251 }
1252 element->symbol = sym;
1253 }
1254 *nsyms_ret = nsyms;
1255 return list;
1256 }
1257
1258
1259 static struct symbol *
1260 process_dst_function (struct objfile *objfile, dst_rec_ptr_t entry, char *name,
1261 CORE_ADDR address)
1262 {
1263 struct symbol *sym;
1264 struct type *type, *ftype;
1265 dst_rec_ptr_t sym_entry, typ_entry;
1266 char *location;
1267 struct symbol_list *element;
1268
1269 type = builtin_type_int;
1270 sym = create_new_symbol (objfile, name);
1271 SYMBOL_CLASS (sym) = LOC_BLOCK;
1272
1273 if (entry)
1274 {
1275 location = (char *) entry;
1276 do
1277 {
1278 NEXT_SYM (&location, &sym_entry);
1279 }
1280 while (sym_entry && sym_entry->rec_type != dst_typ_signature);
1281
1282 if (sym_entry)
1283 {
1284 SYMBOL_LINE (sym) =
1285 DST_signature (sym_entry).src_loc.line_number;
1286 if (DST_signature (sym_entry).result)
1287 {
1288 typ_entry = (dst_rec_ptr_t)
1289 DST_OFFSET (sym_entry,
1290 DST_signature (sym_entry).result);
1291 type = decode_dst_type (objfile, typ_entry);
1292 }
1293 }
1294 }
1295
1296 if (!type->function_type)
1297 {
1298 ftype = alloc_type (objfile);
1299 type->function_type = ftype;
1300 TYPE_TARGET_TYPE (ftype) = type;
1301 TYPE_CODE (ftype) = TYPE_CODE_FUNC;
1302 }
1303 SYMBOL_TYPE (sym) = type->function_type;
1304
1305 /* Now add ourselves to the global symbols list */
1306 element = (struct symbol_list *)
1307 xmalloc (sizeof (struct symbol_list));
1308
1309 element->next = dst_global_symbols;
1310 dst_global_symbols = element;
1311 total_globals++;
1312 element->symbol = sym;
1313
1314 return sym;
1315 }
1316
1317 static struct block *
1318 process_dst_block (struct objfile *objfile, dst_rec_ptr_t entry)
1319 {
1320 struct block *block;
1321 struct symbol *function = NULL;
1322 CORE_ADDR address;
1323 long size;
1324 char *name;
1325 dst_rec_ptr_t child_entry, symbol_entry;
1326 struct block *child_block;
1327 int total_symbols = 0;
1328 char fake_name[20];
1329 static long fake_seq = 0;
1330 struct symbol_list *symlist, *nextsym;
1331 int symnum;
1332
1333 if (DST_block (entry).noffset)
1334 name = DST_OFFSET (entry, DST_block (entry).noffset);
1335 else
1336 name = NULL;
1337 if (DST_block (entry).n_of_code_ranges)
1338 {
1339 address = dst_sym_addr (
1340 &DST_block (entry).code_ranges[0].code_start);
1341 size = DST_block (entry).code_ranges[0].code_size;
1342 }
1343 else
1344 {
1345 address = -1;
1346 size = 0;
1347 }
1348 symbol_entry = (dst_rec_ptr_t) get_sec_ref (&DST_block (entry).symbols_start);
1349 switch (DST_block (entry).block_type)
1350 {
1351 /* These are all really functions. Even the "program" type.
1352 * This is because the Apollo OS was written in Pascal, and
1353 * in Pascal, the main procedure is described as the Program.
1354 * Cute, huh?
1355 */
1356 case dst_block_procedure:
1357 case dst_block_function:
1358 case dst_block_subroutine:
1359 case dst_block_program:
1360 prim_record_minimal_symbol (name, address, mst_text, objfile);
1361 function = process_dst_function (
1362 objfile,
1363 symbol_entry,
1364 name,
1365 address);
1366 enter_all_lines (get_sec_ref (&DST_block (entry).code_ranges[0].lines_start), address);
1367 break;
1368 case dst_block_block_data:
1369 break;
1370
1371 default:
1372 /* GDB has to call it something, and the module name
1373 * won't cut it
1374 */
1375 sprintf (fake_name, "block_%08lx", fake_seq++);
1376 function = process_dst_function (
1377 objfile, NULL, fake_name, address);
1378 break;
1379 }
1380 symlist = process_dst_symbols (objfile, symbol_entry,
1381 name, &total_symbols);
1382 block = (struct block *)
1383 obstack_alloc (&objfile->symbol_obstack,
1384 sizeof (struct block) +
1385 (total_symbols - 1) * sizeof (struct symbol *));
1386
1387 symnum = 0;
1388 while (symlist)
1389 {
1390 nextsym = symlist->next;
1391
1392 block->sym[symnum] = symlist->symbol;
1393
1394 xfree (symlist);
1395 symlist = nextsym;
1396 symnum++;
1397 }
1398 BLOCK_NSYMS (block) = total_symbols;
1399 BLOCK_HASHTABLE (block) = 0;
1400 BLOCK_START (block) = address;
1401 BLOCK_END (block) = address + size;
1402 BLOCK_SUPERBLOCK (block) = 0;
1403 if (function)
1404 {
1405 SYMBOL_BLOCK_VALUE (function) = block;
1406 BLOCK_FUNCTION (block) = function;
1407 }
1408 else
1409 BLOCK_FUNCTION (block) = 0;
1410
1411 if (DST_block (entry).child_block_off)
1412 {
1413 child_entry = (dst_rec_ptr_t) DST_OFFSET (entry,
1414 DST_block (entry).child_block_off);
1415 while (child_entry)
1416 {
1417 child_block = process_dst_block (objfile, child_entry);
1418 if (child_block)
1419 {
1420 if (BLOCK_START (child_block) <
1421 BLOCK_START (block) ||
1422 BLOCK_START (block) == -1)
1423 BLOCK_START (block) =
1424 BLOCK_START (child_block);
1425 if (BLOCK_END (child_block) >
1426 BLOCK_END (block) ||
1427 BLOCK_END (block) == -1)
1428 BLOCK_END (block) =
1429 BLOCK_END (child_block);
1430 BLOCK_SUPERBLOCK (child_block) = block;
1431 }
1432 if (DST_block (child_entry).sibling_block_off)
1433 child_entry = (dst_rec_ptr_t) DST_OFFSET (
1434 child_entry,
1435 DST_block (child_entry).sibling_block_off);
1436 else
1437 child_entry = NULL;
1438 }
1439 }
1440 record_pending_block (objfile, block, NULL);
1441 return block;
1442 }
1443
1444
1445 static void
1446 read_dst_symtab (struct objfile *objfile)
1447 {
1448 char *buffer;
1449 dst_rec_ptr_t entry, file_table, root_block;
1450 char *source_file;
1451 struct block *block, *global_block;
1452 int symnum;
1453 struct symbol_list *nextsym;
1454 int module_num = 0;
1455 struct structure_list *element;
1456
1457 current_objfile = objfile;
1458 buffer = blocks_info.buffer;
1459 while (NEXT_BLK (&buffer, &entry))
1460 {
1461 if (entry->rec_type == dst_typ_comp_unit)
1462 {
1463 file_table = (dst_rec_ptr_t) DST_OFFSET (entry,
1464 DST_comp_unit (entry).file_table);
1465 section_table = (dst_rec_ptr_t) DST_OFFSET (entry,
1466 DST_comp_unit (entry).section_table);
1467 root_block = (dst_rec_ptr_t) DST_OFFSET (entry,
1468 DST_comp_unit (entry).root_block_offset);
1469 source_file = DST_OFFSET (file_table,
1470 DST_file_tab (file_table).files[0].noffset);
1471 /* Point buffer to the start of the next comp_unit */
1472 buffer = DST_OFFSET (entry,
1473 DST_comp_unit (entry).data_size);
1474 dst_start_symtab ();
1475
1476 block = process_dst_block (objfile, root_block);
1477
1478 global_block = (struct block *)
1479 obstack_alloc (&objfile->symbol_obstack,
1480 sizeof (struct block) +
1481 (total_globals - 1) *
1482 sizeof (struct symbol *));
1483 BLOCK_NSYMS (global_block) = total_globals;
1484 BLOCK_HASHTABLE (global_block) = 0;
1485 for (symnum = 0; symnum < total_globals; symnum++)
1486 {
1487 nextsym = dst_global_symbols->next;
1488
1489 global_block->sym[symnum] =
1490 dst_global_symbols->symbol;
1491
1492 xfree (dst_global_symbols);
1493 dst_global_symbols = nextsym;
1494 }
1495 dst_global_symbols = NULL;
1496 total_globals = 0;
1497 BLOCK_FUNCTION (global_block) = 0;
1498 BLOCK_START (global_block) = BLOCK_START (block);
1499 BLOCK_END (global_block) = BLOCK_END (block);
1500 BLOCK_SUPERBLOCK (global_block) = 0;
1501 BLOCK_SUPERBLOCK (block) = global_block;
1502 record_pending_block (objfile, global_block, NULL);
1503
1504 complete_symtab (source_file,
1505 BLOCK_START (block),
1506 BLOCK_END (block) - BLOCK_START (block));
1507 module_num++;
1508 dst_end_symtab (objfile);
1509 }
1510 }
1511 if (module_num)
1512 prim_record_minimal_symbol ("<end_of_program>",
1513 BLOCK_END (block), mst_text, objfile);
1514 /* One more faked symbol to make sure nothing can ever run off the
1515 * end of the symbol table. This one represents the end of the
1516 * text space. It used to be (CORE_ADDR) -1 (effectively the highest
1517 * int possible), but some parts of gdb treated it as a signed
1518 * number and failed comparisons. We could equally use 7fffffff,
1519 * but no functions are ever mapped to an address higher than
1520 * 40000000
1521 */
1522 prim_record_minimal_symbol ("<end_of_text>",
1523 (CORE_ADDR) 0x40000000,
1524 mst_text, objfile);
1525 while (struct_list)
1526 {
1527 element = struct_list;
1528 struct_list = element->next;
1529 xfree (element);
1530 }
1531 }
1532 \f
1533
1534 /* Support for line number handling */
1535 static char *linetab = NULL;
1536 static long linetab_offset;
1537 static unsigned long linetab_size;
1538
1539 /* Read in all the line numbers for fast lookups later. Leave them in
1540 external (unswapped) format in memory; we'll swap them as we enter
1541 them into GDB's data structures. */
1542 static int
1543 init_one_section (int chan, dst_sec *secinfo)
1544 {
1545 if (secinfo->size == 0
1546 || lseek (chan, secinfo->position, 0) == -1
1547 || (secinfo->buffer = xmalloc (secinfo->size)) == NULL
1548 || myread (chan, secinfo->buffer, secinfo->size) == -1)
1549 return 0;
1550 else
1551 return 1;
1552 }
1553
1554 static int
1555 init_dst_sections (int chan)
1556 {
1557
1558 if (!init_one_section (chan, &blocks_info) ||
1559 !init_one_section (chan, &lines_info) ||
1560 !init_one_section (chan, &symbols_info))
1561 return -1;
1562 else
1563 return 0;
1564 }
1565
1566 /* Fake up support for relocating symbol addresses. FIXME. */
1567
1568 struct section_offsets dst_symfile_faker =
1569 {0};
1570
1571 void
1572 dst_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
1573 {
1574 objfile->num_sections = 1;
1575 objfile->section_offsets = &dst_symfile_faker;
1576 }
1577
1578 /* Register our ability to parse symbols for DST BFD files */
1579
1580 static struct sym_fns dst_sym_fns =
1581 {
1582 /* FIXME: Can this be integrated with coffread.c? If not, should it be
1583 a separate flavour like ecoff? */
1584 (enum bfd_flavour) -2,
1585
1586 dst_new_init, /* sym_new_init: init anything gbl to entire symtab */
1587 dst_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1588 dst_symfile_read, /* sym_read: read a symbol file into symtab */
1589 dst_symfile_finish, /* sym_finish: finished with file, cleanup */
1590 dst_symfile_offsets, /* sym_offsets: xlate external to internal form */
1591 NULL /* next: pointer to next struct sym_fns */
1592 };
1593
1594 void
1595 _initialize_dstread (void)
1596 {
1597 add_symtab_fns (&dst_sym_fns);
1598 }
This page took 0.06491 seconds and 4 git commands to generate.