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