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