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