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