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