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