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