Commit | Line | Data |
---|---|---|
bd5635a1 RP |
1 | /* Read a symbol table in MIPS' format (Third-Eye). |
2 | Copyright (C) 1986, 1987, 1989-1991 Free Software Foundation, Inc. | |
3 | Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | GDB 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 1, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GDB 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 GDB; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include "param.h" | |
23 | #include "obstack.h" | |
24 | #include <sys/param.h> | |
25 | #include <sys/file.h> | |
26 | #include <sys/stat.h> | |
27 | #include "defs.h" | |
28 | #include "symtab.h" | |
29 | #include "gdbcore.h" | |
30 | #include "symfile.h" | |
31 | #ifdef CMUCS | |
32 | #include <mips/syms.h> | |
31ef19fc JK |
33 | #else /* not CMUCS */ |
34 | #include <syms.h> | |
35 | #endif /* not CMUCS */ | |
bd5635a1 RP |
36 | |
37 | /* Since these things are defined differently on various systems I'll | |
38 | (re)define here what I really need in this module. I only assume the | |
39 | three standard COFF structure definitions: filehdr, aouthdr, scnhdr */ | |
40 | #define MIPS /* Kludge to get MIPS version of coff */ | |
41 | #include "intel-coff.h" | |
42 | ||
43 | struct coff_exec { | |
44 | struct filehdr f; | |
45 | struct aouthdr a; | |
46 | }; | |
47 | #undef a_magic | |
48 | #undef a_text | |
49 | #undef a_data | |
50 | #undef a_bss | |
51 | #undef a_syms | |
52 | #undef a_entry | |
53 | #define a_magic a.magic /* magic number */ | |
54 | #define a_text a.tsize /* size of text segment */ | |
55 | #define a_data a.dsize /* size of initialized data */ | |
56 | #define a_bss a.bsize /* size of uninitialized data */ | |
57 | #define a_syms f.f_nsyms /* size of symbol table */ | |
58 | #define a_entry a.entry /* entry point */ | |
59 | ||
60 | #undef N_BADMAG | |
61 | #define N_BADMAG(x) \ | |
62 | (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC) | |
63 | ||
64 | /* Things we import explicitly from other modules */ | |
65 | ||
66 | extern int info_verbose; | |
67 | extern struct block *block_for_pc(); | |
68 | extern void sort_symtab_syms(); | |
69 | ||
70 | /* Forward declarations */ | |
71 | ||
72 | static void psymtab_to_symtab_1(); | |
73 | ||
74 | /* Macros and extra defs */ | |
75 | ||
76 | struct complaint unknown_ext_complaint = | |
77 | {"unknown external symbol %s", 0, 0}; | |
78 | ||
79 | /* Already parsed symbols are marked specially */ | |
80 | ||
81 | #define stParsed stType | |
82 | ||
83 | /* Puns: hard to find whether -g was used and how */ | |
84 | ||
85 | #define MIN_GLEVEL GLEVEL_0 | |
86 | #define compare_glevel(a,b) \ | |
87 | (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \ | |
88 | ((b) == GLEVEL_3) ? -1 : (int)((b) - (a))) | |
89 | ||
90 | /* When looking at .o files avoid tripping over bad addresses */ | |
91 | ||
92 | #define SAFE_TEXT_ADDR 0x400000 | |
93 | #define SAFE_DATA_ADDR 0x10000000 | |
94 | ||
95 | #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR) | |
96 | ||
97 | \f | |
98 | /* Things we export to other modules */ | |
99 | ||
100 | ||
101 | /* Lists of partial symbols */ | |
102 | ||
103 | struct psymbol_allocation_list global_psymbols, static_psymbols; | |
104 | ||
105 | /* Address bounds for the signal trampoline in inferior, if any */ | |
106 | ||
107 | CORE_ADDR sigtramp_address, sigtramp_end; | |
108 | ||
109 | ||
110 | /* Functions that we really export */ | |
111 | ||
112 | /* THIS DESCRIPTION IS OBSOLETE POST-BFD; FIXME! */ | |
113 | /* Basically, this module must provide two functions: symbol_file_command() | |
114 | which loads the symbol table from a file, and add_file_command() which | |
115 | adds more symbols to the symbol table (incrementally). | |
116 | ||
117 | These two functions only do the minimum work necessary for letting the | |
118 | user "name" things symbolically, they do not read the entire symtab. | |
119 | Instead, they read in the external symbols and put them in partial | |
120 | symbol tables. When more extensive information is requested of a | |
121 | file the corresponding partial symbol table is mutated into a full | |
122 | fledged symbol table by going back and reading the relative symbols | |
123 | for real. mipscoff_psymtab_to_symtab() is the function that does this */ | |
124 | ||
125 | /* The entry point (starting address) of the file, if it is an executable. */ | |
126 | ||
127 | static CORE_ADDR entry_point; | |
128 | ||
129 | extern CORE_ADDR startup_file_start; /* From blockframe.c */ | |
130 | extern CORE_ADDR startup_file_end; /* From blockframe.c */ | |
131 | ||
132 | void | |
133 | mipscoff_new_init() | |
134 | { | |
135 | } | |
136 | ||
137 | void | |
138 | mipscoff_symfile_init (sf) | |
139 | struct sym_fns *sf; | |
140 | { | |
141 | bfd *abfd = sf->sym_bfd; | |
142 | sf->sym_private = NULL; | |
143 | /* Save startup file's range of PC addresses to help blockframe.c | |
144 | decide where the bottom of the stack is. */ | |
145 | if (bfd_get_file_flags (abfd) & EXEC_P) | |
146 | { | |
147 | /* Executable file -- record its entry point so we'll recognize | |
148 | the startup file because it contains the entry point. */ | |
149 | entry_point = bfd_get_start_address (abfd); | |
150 | } | |
151 | else | |
152 | { | |
153 | /* Examination of non-executable.o files. Short-circuit this stuff. */ | |
154 | /* ~0 will not be in any file, we hope. */ | |
155 | entry_point = ~0; | |
156 | /* set the startup file to be an empty range. */ | |
157 | startup_file_start = 0; | |
158 | startup_file_end = 0; | |
159 | } | |
160 | } | |
161 | ||
162 | void | |
163 | mipscoff_symfile_read(sf, addr, mainline) | |
164 | struct sym_fns *sf; | |
165 | CORE_ADDR addr; | |
166 | int mainline; | |
167 | { | |
168 | struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private; | |
169 | bfd *abfd = sf->sym_bfd; | |
170 | char *name = bfd_get_filename (abfd); | |
171 | int desc; | |
172 | register int val; | |
173 | int num_symbols; | |
174 | int symtab_offset; | |
175 | int stringtab_offset; | |
176 | ||
177 | /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */ | |
178 | desc = fileno ((FILE *)(abfd->iostream)); /* Raw file descriptor */ | |
179 | num_symbols = bfd_get_symcount (abfd); /* How many syms */ | |
180 | /* symtab_offset = obj_sym_filepos (abfd); * Symbol table file offset */ | |
181 | /* stringtab_offset = symtab_offset + num_symbols * SYMESZ; * String tab */ | |
182 | /* End of warning */ | |
183 | ||
184 | #ifdef TDESC | |
185 | debug_info = text_hdr.s_relptr; | |
186 | if (tdesc_handle) | |
187 | { | |
188 | dc_terminate (tdesc_handle); | |
189 | tdesc_handle = 0; | |
190 | } | |
191 | #endif | |
192 | ||
193 | #if 0 | |
194 | /* Read the line number table, all at once. */ | |
195 | info->min_lineno_offset = 0; | |
196 | info->max_lineno_offset = 0; | |
197 | bfd_map_over_sections (abfd, find_linenos, info); | |
198 | ||
199 | val = init_lineno (desc, info->min_lineno_offset, | |
200 | info->max_lineno_offset - info->min_lineno_offset); | |
201 | if (val < 0) | |
202 | error ("\"%s\": error reading line numbers\n", name); | |
203 | ||
204 | /* Now read the string table, all at once. */ | |
205 | ||
206 | val = init_stringtab (desc, stringtab_offset); | |
207 | if (val < 0) | |
208 | { | |
209 | free_all_symtabs (); /* FIXME blows whole symtab */ | |
210 | printf ("\"%s\": can't get string table", name); | |
211 | fflush (stdout); | |
212 | return; | |
213 | } | |
214 | make_cleanup (free_stringtab, 0); | |
215 | #endif | |
216 | /* Position to read the symbol table. Do not read it all at once. */ | |
217 | val = lseek (desc, (long)symtab_offset, 0); | |
218 | if (val < 0) | |
219 | perror_with_name (name); | |
220 | ||
221 | init_misc_bunches (); | |
222 | make_cleanup (discard_misc_bunches, 0); | |
223 | ||
224 | /* Now that the executable file is positioned at symbol table, | |
225 | process it and define symbols accordingly. */ | |
226 | ||
227 | printf("Reading symbol data from %s...", name); | |
228 | fflush(stdout); | |
229 | read_mips_symtab(desc, 0); | |
230 | ||
231 | /* patch_opaque_types ();*/ | |
232 | ||
233 | /* Sort symbols alphabetically within each block. */ | |
234 | ||
235 | sort_all_symtab_syms (); | |
236 | ||
237 | /* Go over the misc symbol bunches and install them in vector. */ | |
238 | ||
239 | condense_misc_bunches (0); | |
240 | ||
241 | /* Make a default for file to list. */ | |
242 | ||
243 | select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */ | |
244 | } | |
245 | ||
246 | void | |
247 | mipscoff_symfile_discard() | |
248 | { | |
249 | } | |
250 | ||
251 | ||
252 | #if 0 | |
253 | /* Exported procedure: Reads symbols from file NAME. | |
254 | Invoked at startup time if executable was given. | |
255 | When invoked cleans up the world */ | |
256 | ||
257 | void | |
258 | symbol_file_command(name, from_tty) | |
259 | char *name; | |
260 | int from_tty; | |
261 | { | |
262 | int desc; | |
263 | struct coff_exec hdr; | |
264 | register int val; | |
265 | extern void close(); | |
266 | struct cleanup *old_chain; | |
267 | ||
268 | dont_repeat(); | |
269 | ||
270 | /* | |
271 | * Make sure s/he means it | |
272 | */ | |
273 | if (name == 0) { | |
274 | if ((symtab_list || partial_symtab_list) | |
275 | && from_tty | |
276 | && !query("Discard symbol table? ", 0)) | |
277 | error("Not confirmed."); | |
278 | destroy_all_symtabs(); | |
279 | return; | |
280 | } | |
281 | ||
282 | name = tilde_expand(name); | |
283 | make_cleanup(free, name); | |
284 | ||
285 | if (symtab_list && | |
286 | !query("Load new symbol table from \"%s\"? ", name)) | |
287 | error("Not confirmed."); | |
288 | ||
289 | /* Open the file */ | |
290 | { | |
291 | char *absolute_name; | |
292 | desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name); | |
293 | if (desc < 0) | |
294 | perror_with_name (name); | |
295 | else | |
296 | name = absolute_name; | |
297 | } | |
298 | ||
299 | old_chain = make_cleanup (close, desc); | |
300 | make_cleanup (free_current_contents, &name); | |
301 | ||
302 | /* | |
303 | * Check file is indeed executable | |
304 | */ | |
305 | val = myread(desc, &hdr, sizeof hdr); | |
306 | if (val < 0) | |
307 | perror_with_name(name); | |
308 | ||
309 | if (N_BADMAG(hdr)) | |
310 | error("File \"%s\" not in executable format.", name); | |
311 | ||
312 | if (hdr.a.entry < SAFE_TEXT_ADDR && access(name, 1)) | |
313 | printf_filtered("Warning: %s is not executable!\n", name); | |
314 | ||
315 | if (hdr.a_syms == 0) { | |
316 | printf_filtered("%s does not have a symbol-table.\n", name); | |
317 | fflush(stdout); | |
318 | return; | |
319 | } | |
320 | ||
321 | /* Get the modification time. */ | |
322 | { | |
323 | struct stat symstat; | |
324 | ||
325 | if (fstat (desc, &symstat) < 0) | |
326 | perror_with_name (name); | |
327 | ||
328 | symfile_mtime = symstat.st_mtime; | |
329 | } | |
330 | ||
331 | /* | |
332 | * Throw away the old symbol table. | |
333 | */ | |
334 | ||
335 | destroy_all_symtabs(); | |
336 | ||
337 | /* Make a default for file to list. */ | |
338 | ||
339 | symfile = savestring (name, strlen (name)); | |
340 | ||
341 | /* Prepare to remember misc symbol values */ | |
342 | ||
343 | init_misc_bunches (); | |
344 | make_cleanup (discard_misc_bunches, 0); | |
345 | ||
346 | /* | |
347 | * Now read the new symbol table | |
348 | */ | |
349 | ||
350 | read_mips_symtab(desc, 0); | |
351 | ||
352 | /* Go over the misc symbol bunches and install them in vector. */ | |
353 | ||
354 | condense_misc_bunches (0); | |
355 | ||
356 | /* Don't allow char * to have a typename (else would get caddr_t.) */ | |
357 | ||
358 | TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0; | |
359 | ||
360 | /* Force reinit of the sigtramp info */ | |
361 | sigtramp_address = 0; | |
362 | ||
363 | do_cleanups (old_chain); /* Descriptor closed here */ | |
364 | ||
365 | if (!partial_symtab_list) | |
366 | printf ("\n(no debugging symbols found)..."); | |
367 | ||
368 | printf ("done.\n"); | |
369 | fflush(stdout); | |
370 | } | |
371 | #endif | |
372 | ||
373 | /* C++: | |
374 | This function allows the addition of incrementally linked object files. | |
375 | Since this has a fair amount of code in common with symbol_file_command, | |
376 | it might be worthwhile to consolidate things, as was done with | |
377 | read_dbx_symtab and condense_misc_bunches. */ | |
378 | ||
379 | /* Exported procedure: add more symbols from file NAME. */ | |
380 | ||
381 | void | |
382 | add_file_command(arg_string) | |
383 | char* arg_string; | |
384 | { | |
385 | int desc; | |
386 | struct coff_exec hdr; | |
387 | register int val; | |
388 | extern void close(); | |
389 | struct cleanup *old_chain; | |
390 | char *name; | |
391 | unsigned text_addr; | |
392 | ||
393 | if (arg_string == 0) | |
394 | error ("add-file takes a file name and an address"); | |
395 | ||
396 | if (arg_string == 0) | |
397 | error ("add-file takes a file name and an address"); | |
398 | ||
399 | arg_string = tilde_expand (arg_string); | |
400 | make_cleanup (free, arg_string); | |
401 | ||
402 | for( ; *arg_string == ' '; arg_string++ ); | |
403 | name = arg_string; | |
404 | for( ; *arg_string && *arg_string != ' ' ; arg_string++ ); | |
405 | *arg_string++ = (char) 0; | |
406 | ||
407 | if (name[0] == 0) | |
408 | error ("add-file takes a file name and an address"); | |
409 | ||
410 | text_addr = parse_and_eval_address (arg_string); | |
411 | ||
412 | dont_repeat(); | |
413 | ||
414 | if (!query ("add symbol table from filename \"%s\" at text_addr = 0x%x\n", | |
415 | name, text_addr)) | |
416 | error ("Not confirmed."); | |
417 | ||
418 | /* | |
419 | * Open the file | |
420 | */ | |
421 | { | |
422 | char *absolute_name; | |
423 | ||
424 | desc = openp(getenv("PATH"), 1, name, O_RDONLY, 0, &absolute_name); | |
425 | if (desc < 0) | |
426 | perror_with_name(name); | |
427 | else | |
428 | name = absolute_name; | |
429 | } | |
430 | old_chain = make_cleanup (close, desc); | |
431 | ||
432 | ||
433 | /* | |
434 | * Check file is indeed executable | |
435 | */ | |
436 | val = myread(desc, &hdr, sizeof hdr); | |
437 | if (val < 0) | |
438 | perror_with_name(name); | |
439 | ||
440 | if (N_BADMAG(hdr)) | |
441 | error("File \"%s\" not in executable format.", name); | |
442 | ||
443 | if (hdr.a.entry < SAFE_TEXT_ADDR && access(name, 1)) | |
444 | printf_filtered("Warning: %s is not executable!\n", name); | |
445 | ||
446 | if (hdr.a_syms == 0) { | |
447 | printf_filtered("%s does not have a symbol-table.\n", name); | |
448 | fflush(stdout); | |
449 | return; | |
450 | } | |
451 | ||
452 | if (symfile) | |
453 | free(symfile); | |
454 | symfile = 0; | |
455 | ||
456 | /* | |
457 | * Now read the new symbol table | |
458 | */ | |
459 | ||
460 | symfile = savestring(name, strlen(name)); | |
461 | ||
462 | init_misc_bunches (); | |
463 | make_cleanup (discard_misc_bunches, 0); | |
464 | read_mips_symtab(desc, 1); | |
465 | ||
466 | /* Go over the misc symbol bunches and install them in vector. */ | |
467 | ||
468 | condense_misc_bunches (1); | |
469 | ||
470 | /* Don't allow char * to have a typename (else would get caddr_t.) */ | |
471 | ||
472 | TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0; | |
473 | ||
474 | do_cleanups (old_chain); | |
475 | ||
476 | printf_filtered("done.\n"); | |
477 | fflush(stdout); | |
478 | } | |
479 | ||
480 | /* Exported procedure: Allocate zeroed memory */ | |
481 | ||
482 | char *xzalloc(size) | |
483 | { | |
484 | char *p = xmalloc(size); | |
485 | ||
486 | bzero(p, size); | |
487 | return p; | |
488 | } | |
489 | ||
490 | /* Exported procedure: Builds a symtab from the PST partial one. | |
491 | Restores the environment in effect when PST was created, delegates | |
492 | most of the work to an ancillary procedure, and sorts | |
493 | and reorders the symtab list at the end */ | |
494 | ||
495 | /* Forward decls */ | |
496 | static HDRR *cur_hdr; /* MIPS symtab header for the current file */ | |
497 | ||
498 | void | |
499 | mipscoff_psymtab_to_symtab(pst) | |
500 | struct partial_symtab *pst; | |
501 | { | |
502 | struct symtab *ret; | |
503 | int i; | |
504 | ||
505 | if (!pst) | |
506 | return; | |
507 | ||
508 | if (info_verbose) { | |
509 | printf_filtered("Reading in symbols for %s...", pst->filename); | |
510 | fflush(stdout); | |
511 | } | |
512 | /* Restore the header and list of pending typedefs */ | |
513 | cur_hdr = (HDRR *) pst->ldsymlen; | |
514 | ||
515 | psymtab_to_symtab_1(pst); | |
516 | ||
517 | reorder_symtabs(); | |
518 | ||
519 | /* Finish up the debug error message. */ | |
520 | if (info_verbose) | |
521 | printf_filtered("done.\n"); | |
522 | } | |
523 | ||
524 | /* Exported procedure: Is PC in the signal trampoline code */ | |
525 | ||
526 | int in_sigtramp(pc,name) | |
527 | CORE_ADDR pc; | |
528 | { | |
529 | if (sigtramp_address == 0) | |
530 | fixup_sigtramp(); | |
531 | return (pc >= sigtramp_address && pc < sigtramp_end); | |
532 | } | |
533 | ||
534 | \f | |
535 | /* Things that really are local to this module */ | |
536 | ||
537 | /* All allocated symtabs and psymtabs */ | |
538 | ||
539 | static int all_symtabs_count; | |
540 | static int all_psymtabs_count; | |
541 | ||
542 | /* GDB symtable for the current compilation unit */ | |
543 | ||
544 | static struct symtab *cur_stab; | |
545 | ||
546 | /* Header for executable/object file we read symbols from */ | |
547 | ||
548 | static struct coff_exec filhdr; | |
549 | #define END_OF_TEXT_SEGMENT(f) ((f).a.text_start + (f).a.tsize) | |
550 | ||
551 | /* Pointer to current file decriptor record, and its index */ | |
552 | ||
553 | static FDR *cur_fdr; | |
554 | static int cur_fd; | |
555 | ||
556 | /* Index of current symbol */ | |
557 | ||
558 | static int cur_sdx; | |
559 | ||
560 | /* Note how much "debuggable" this image is. We would like | |
561 | to see at least one FDR with full symbols */ | |
562 | ||
563 | static max_gdbinfo; | |
564 | static max_glevel; | |
565 | ||
566 | /* When examining .o files, report on undefined symbols */ | |
567 | ||
568 | static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs; | |
569 | ||
570 | /* Extra builtin types */ | |
571 | ||
572 | struct type *builtin_type_complex; | |
573 | struct type *builtin_type_double_complex; | |
574 | struct type *builtin_type_fixed_dec; | |
575 | struct type *builtin_type_float_dec; | |
576 | struct type *builtin_type_string; | |
577 | ||
578 | /* Template types */ | |
579 | ||
580 | static struct type *builtin_type_ptr; | |
581 | static struct type *builtin_type_struct; | |
582 | static struct type *builtin_type_union; | |
583 | static struct type *builtin_type_enum; | |
584 | static struct type *builtin_type_range; | |
585 | static struct type *builtin_type_set; | |
586 | ||
587 | ||
588 | /* Forward decls */ | |
589 | ||
590 | static struct symbol *new_symbol(); | |
591 | static struct type *new_type(); | |
592 | static struct field *new_field(); | |
593 | static struct block *new_block(); | |
594 | static struct symtab *new_symtab(); | |
595 | static struct linetable *new_linetable(); | |
596 | static struct blockvector *new_bvect(); | |
597 | ||
598 | static struct type *parse_type(); | |
599 | static struct type *make_type(); | |
600 | static struct symbol *mylookup_symbol(); | |
601 | static struct block *shrink_block(); | |
602 | ||
603 | static int compare_symtabs(); | |
604 | static int compare_psymtabs(); | |
605 | static int compare_blocks(); | |
606 | ||
607 | static struct partial_symtab *new_psymtab(); | |
608 | static struct partial_symbol *new_psymbol(); | |
609 | static struct partial_symtab *parse_fdr(); | |
610 | static int compare_psymbols(); | |
611 | \f | |
612 | /* File-level interface functions */ | |
613 | ||
614 | /* Read the symtab information from file FSYM into memory */ | |
615 | ||
616 | static | |
617 | read_the_mips_symtab(fsym) | |
618 | { | |
619 | int stsize, st_hdrsize; | |
620 | unsigned st_filptr; | |
621 | HDRR st_hdr; | |
622 | ||
623 | /* Find and read the symbol table header */ | |
624 | st_hdrsize = filhdr.f.f_nsyms; | |
625 | st_filptr = filhdr.f.f_symptr; | |
626 | if (st_filptr == 0) | |
627 | return 0; | |
628 | ||
629 | lseek(fsym, st_filptr, L_SET); | |
630 | if (read(fsym, &st_hdr, st_hdrsize) != st_hdrsize) | |
631 | goto readerr; | |
632 | ||
633 | /* Find out how large the symbol table is */ | |
634 | stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize)) | |
635 | + st_hdr.iextMax * cbEXTR; | |
636 | ||
637 | /* Allocate space for the symbol table. Read it in. */ | |
638 | cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize); | |
639 | ||
640 | bcopy(&st_hdr, cur_hdr, st_hdrsize); | |
641 | if (read(fsym, (char *) cur_hdr + st_hdrsize, stsize) != stsize) | |
642 | goto readerr; | |
643 | ||
644 | /* Fixup file_pointers in it */ | |
645 | fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize, | |
646 | st_filptr + st_hdrsize); | |
647 | ||
648 | return; | |
649 | readerr: | |
650 | error("Short read on %s", symfile); | |
651 | } | |
652 | ||
653 | ||
654 | /* Turn all file-relative pointers in the symtab described by HDR | |
655 | into memory pointers, given that the symtab itself is located | |
656 | at DATA in memory and F_PTR in the file. */ | |
657 | ||
658 | static | |
659 | fixup_symtab( hdr, data, f_ptr) | |
660 | HDRR *hdr; | |
661 | char *data; | |
662 | { | |
663 | int f_idx, s_idx; | |
664 | FDR *fh; | |
665 | SYMR *sh; | |
666 | OPTR *op; | |
667 | PDR *pr; | |
668 | EXTR *esh; | |
669 | ||
670 | /* | |
671 | * These fields are useless (and empty) by now: | |
672 | * hdr->cbDnOffset, hdr->cbOptOffset | |
673 | * We use them for other internal purposes. | |
674 | */ | |
675 | hdr->cbDnOffset = 0; | |
676 | hdr->cbOptOffset = 0; | |
677 | ||
678 | #define FIX(off) \ | |
679 | if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr); | |
680 | ||
681 | FIX(cbLineOffset); | |
682 | FIX(cbPdOffset); | |
683 | FIX(cbSymOffset); | |
684 | FIX(cbOptOffset); | |
685 | FIX(cbAuxOffset); | |
686 | FIX(cbSsOffset); | |
687 | FIX(cbSsExtOffset); | |
688 | FIX(cbFdOffset); | |
689 | FIX(cbRfdOffset); | |
690 | FIX(cbExtOffset); | |
691 | #undef FIX | |
692 | ||
693 | ||
694 | /* | |
695 | * Fix all string pointers inside the symtab, and | |
696 | * the FDR records. Also fix other miscellany. | |
697 | */ | |
698 | for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) { | |
699 | register unsigned code_offset; | |
700 | ||
701 | /* Header itself, and strings */ | |
702 | fh = (FDR *) (hdr->cbFdOffset) + f_idx; | |
703 | fh->issBase += hdr->cbSsOffset; | |
704 | if (fh->rss != -1) | |
705 | fh->rss = (long)fh->rss + fh->issBase; | |
706 | for (s_idx = 0; s_idx < fh->csym; s_idx++) { | |
707 | sh = (SYMR*)(hdr->cbSymOffset) + fh->isymBase + s_idx; | |
708 | sh->iss = (long) sh->iss + fh->issBase; | |
709 | sh->reserved = 0; | |
710 | } | |
711 | ||
712 | cur_fd = f_idx; | |
713 | ||
714 | /* Local symbols */ | |
715 | fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase); | |
716 | ||
717 | /* cannot fix fh->ipdFirst because it is a short */ | |
718 | #define IPDFIRST(h,fh) \ | |
719 | ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR)) | |
720 | ||
721 | /* Optional symbols (actually used for partial_symtabs) */ | |
722 | fh->ioptBase = 0; | |
723 | fh->copt = 0; | |
724 | ||
725 | /* Aux symbols */ | |
726 | if (fh->caux) | |
727 | fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(AUXU); | |
728 | /* Relative file descriptor table */ | |
729 | fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT); | |
730 | ||
731 | /* Line numbers */ | |
732 | if (fh->cbLine) | |
733 | fh->cbLineOffset += hdr->cbLineOffset; | |
734 | ||
735 | /* Procedure symbols. (XXX This should be done later) */ | |
736 | code_offset = fh->adr; | |
737 | for (s_idx = 0; s_idx < fh->cpd; s_idx++) { | |
738 | unsigned name, only_ext; | |
739 | ||
740 | pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx; | |
741 | ||
742 | /* Simple rule to find files linked "-x" */ | |
743 | only_ext = fh->rss == -1; | |
744 | if (only_ext) { | |
745 | if (pr->isym == -1) { | |
746 | /* static function */ | |
747 | sh = (SYMR*)-1; | |
748 | } else { | |
749 | /* external */ | |
750 | name = hdr->cbExtOffset + pr->isym * sizeof(EXTR); | |
751 | sh = &((EXTR*)name)->asym; | |
752 | } | |
753 | } else { | |
754 | /* Full symbols */ | |
755 | sh = (SYMR*)fh->isymBase + pr->isym; | |
756 | /* Included code ? */ | |
757 | if (s_idx == 0 && pr->adr != 0) | |
758 | code_offset -= pr->adr; | |
759 | } | |
760 | ||
761 | /* Turn index into a pointer */ | |
762 | pr->isym = (long)sh; | |
763 | ||
764 | /* Fix line numbers */ | |
765 | pr->cbLineOffset += fh->cbLineOffset; | |
766 | ||
767 | /* Relocate address */ | |
768 | if (!only_ext) | |
769 | pr->adr += code_offset; | |
770 | } | |
771 | } | |
772 | ||
773 | /* External symbols: fix string */ | |
774 | for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) { | |
775 | esh = (EXTR*)(hdr->cbExtOffset) + s_idx; | |
776 | esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset; | |
777 | } | |
778 | } | |
779 | ||
780 | ||
781 | /* Find a file descriptor given its index RF relative to a file CF */ | |
782 | ||
783 | static | |
784 | FDR *get_rfd( cf, rf) | |
785 | { | |
786 | register FDR *f; | |
787 | ||
788 | f = (FDR *) (cur_hdr->cbFdOffset) + cf; | |
789 | /* Object files do not have the RFD table, all refs are absolute */ | |
790 | if (f->rfdBase == 0) | |
791 | return (FDR *) (cur_hdr->cbFdOffset) + rf; | |
792 | cf = *((pRFDT) f->rfdBase + rf); | |
793 | return (FDR *) (cur_hdr->cbFdOffset) + cf; | |
794 | } | |
795 | ||
796 | /* Return a safer print NAME for a file descriptor */ | |
797 | ||
798 | static | |
799 | char *fdr_name(name) | |
800 | char *name; | |
801 | { | |
802 | if (name == (char *) -1) | |
803 | return "<stripped file>"; | |
804 | if (UNSAFE_DATA_ADDR(name)) | |
805 | return "<NFY>"; | |
806 | return name; | |
807 | } | |
808 | ||
809 | ||
810 | /* Read in and parse the symtab of the file DESC. INCREMENTAL says | |
811 | whether we are adding to the general symtab or not */ | |
812 | ||
813 | static | |
814 | read_mips_symtab( desc, incremental) | |
815 | { | |
816 | /* | |
817 | * We get here with DESC pointing to the symtab header. But we need | |
818 | * other info from the initial headers | |
819 | */ | |
820 | lseek(desc, 0L, 0); | |
821 | myread(desc, &filhdr, sizeof filhdr); | |
822 | ||
823 | read_the_mips_symtab(desc); | |
824 | ||
825 | parse_partial_symbols(cur_hdr, incremental); | |
826 | cur_hdr = 0; | |
827 | ||
828 | /* | |
829 | * Check to make sure file was compiled with -g. | |
830 | * If not, warn the user of this limitation. | |
831 | */ | |
832 | if (compare_glevel(max_glevel, GLEVEL_2) < 0) { | |
833 | if (max_gdbinfo == 0) | |
834 | printf("\n%s not compiled with -g, debugging support is limited.", symfile); | |
835 | printf("\nYou should compile with -g2 or -g3 for best debugging support.\n"); | |
836 | fflush(stdout); | |
837 | } | |
838 | ||
839 | /* | |
840 | * Dont allow char * to have a typename (else would get | |
841 | * caddr_t.) | |
842 | */ | |
843 | TYPE_NAME(lookup_pointer_type(builtin_type_char)) = 0; | |
844 | } | |
845 | ||
846 | \f | |
847 | /* Local utilities */ | |
848 | ||
849 | ||
850 | /* Map of FDR indexes to partial symtabs */ | |
851 | ||
852 | static struct pst_map { | |
853 | struct partial_symtab *pst; /* the psymtab proper */ | |
854 | int n_globals; /* globals it exports */ | |
855 | } * fdr_to_pst; | |
856 | ||
857 | ||
858 | /* Utility stack, used to nest procedures and blocks properly. | |
859 | It is a doubly linked list, to avoid too many alloc/free. | |
860 | Since we might need it quite a few times it is NOT deallocated | |
861 | after use. */ | |
862 | ||
863 | static struct parse_stack { | |
864 | struct parse_stack *next, *prev; | |
865 | struct symtab *cur_st; /* Current symtab */ | |
866 | struct block *cur_block; /* Block in it */ | |
867 | int blocktype; /* What are we parsing */ | |
868 | int maxsyms; /* Max symbols in this block */ | |
869 | struct type *cur_type; /* Type we parse fields for */ | |
870 | int procadr; /* Start addres of this procedure */ | |
871 | int numargs; /* Its argument count */ | |
872 | } *top_stack; /* Top stack ptr */ | |
873 | ||
874 | ||
875 | /* Enter a new lexical context */ | |
876 | ||
877 | static push_parse_stack() | |
878 | { | |
879 | struct parse_stack *new; | |
880 | ||
881 | /* Reuse frames if possible */ | |
882 | if (top_stack && top_stack->prev) | |
883 | new = top_stack->prev; | |
884 | else | |
885 | new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack)); | |
886 | /* Initialize new frame with previous content */ | |
887 | if (top_stack) { | |
888 | register struct parse_stack *prev = new->prev; | |
889 | ||
890 | *new = *top_stack; | |
891 | top_stack->prev = new; | |
892 | new->prev = prev; | |
893 | new->next = top_stack; | |
894 | } | |
895 | top_stack = new; | |
896 | } | |
897 | ||
898 | /* Exit a lexical context */ | |
899 | ||
900 | static pop_parse_stack() | |
901 | { | |
902 | if (!top_stack) | |
903 | return; | |
904 | if (top_stack->next) | |
905 | top_stack = top_stack->next; | |
906 | } | |
907 | ||
908 | ||
909 | /* Cross-references might be to things we haven't looked at | |
910 | yet, e.g. type references. To avoid too many type | |
911 | duplications we keep a quick fixup table, an array | |
912 | of lists of references indexed by file descriptor */ | |
913 | ||
914 | static struct pending { | |
915 | struct pending *next; /* link */ | |
916 | SYMR *s; /* the symbol */ | |
917 | struct type *t; /* its partial type descriptor */ | |
918 | } **pending_list; | |
919 | ||
920 | ||
921 | /* Check whether we already saw symbol SH in file FH as undefined */ | |
922 | ||
923 | static | |
924 | struct pending *is_pending_symbol(fh, sh) | |
925 | FDR *fh; | |
926 | SYMR *sh; | |
927 | { | |
928 | int f_idx = fh - (FDR *) cur_hdr->cbFdOffset; | |
929 | register struct pending *p; | |
930 | ||
931 | /* Linear search is ok, list is typically no more than 10 deep */ | |
932 | for (p = pending_list[f_idx]; p; p = p->next) | |
933 | if (p->s == sh) | |
934 | break; | |
935 | return p; | |
936 | } | |
937 | ||
938 | /* Check whether we already saw type T in file FH as undefined */ | |
939 | ||
940 | static | |
941 | struct pending *is_pending_type(fh, t) | |
942 | FDR *fh; | |
943 | struct type *t; | |
944 | { | |
945 | int f_idx = fh - (FDR *) cur_hdr->cbFdOffset; | |
946 | register struct pending *p; | |
947 | ||
948 | for (p = pending_list[f_idx]; p; p = p->next) | |
949 | if (p->t == t) | |
950 | break; | |
951 | return p; | |
952 | } | |
953 | ||
954 | /* Add a new undef symbol SH of type T */ | |
955 | ||
956 | static | |
957 | add_pending(fh, sh, t) | |
958 | FDR *fh; | |
959 | SYMR *sh; | |
960 | struct type *t; | |
961 | { | |
962 | int f_idx = fh - (FDR *) cur_hdr->cbFdOffset; | |
963 | struct pending *p = is_pending_symbol(fh, sh); | |
964 | ||
965 | /* Make sure we do not make duplicates */ | |
966 | if (!p) { | |
967 | p = (struct pending *) xmalloc(sizeof(*p)); | |
968 | p->s = sh; | |
969 | p->t = t; | |
970 | p->next = pending_list[f_idx]; | |
971 | pending_list[f_idx] = p; | |
972 | } | |
973 | sh->reserved = 1; /* for quick check */ | |
974 | } | |
975 | ||
976 | /* Throw away undef entries when done with file index F_IDX */ | |
977 | ||
978 | static | |
979 | free_pending(f_idx) | |
980 | { | |
981 | register struct pending *p, *q; | |
982 | ||
983 | for (p = pending_list[f_idx]; p; p = q) { | |
984 | q = p->next; | |
985 | free(p); | |
986 | } | |
987 | pending_list[f_idx] = 0; | |
988 | } | |
989 | ||
990 | /* The number of args to a procedure is not explicit in the symtab, | |
991 | this is the list of all those we know of. | |
992 | This makes parsing more reasonable and avoids extra passes */ | |
993 | ||
994 | static struct numarg { | |
995 | struct numarg *next; /* link */ | |
996 | unsigned adr; /* procedure's start address */ | |
997 | unsigned num; /* arg count */ | |
998 | } *numargs_list; | |
999 | ||
1000 | /* Record that the procedure at ADR takes NUM arguments. */ | |
1001 | ||
1002 | static | |
1003 | got_numargs(adr,num) | |
1004 | { | |
1005 | struct numarg *n = (struct numarg *) xmalloc(sizeof(struct numarg)); | |
1006 | ||
1007 | n->adr = adr; | |
1008 | n->num = num; | |
1009 | n->next = numargs_list; | |
1010 | numargs_list = n; | |
1011 | } | |
1012 | ||
1013 | /* See if we know how many arguments the procedure at ADR takes */ | |
1014 | ||
1015 | static | |
1016 | lookup_numargs(adr) | |
1017 | { | |
1018 | struct numarg *n = numargs_list; | |
1019 | ||
1020 | while (n && n->adr != adr) | |
1021 | n = n->next; | |
1022 | return (n) ? n->num : -1; | |
1023 | } | |
1024 | ||
1025 | /* Release storage when done with this file */ | |
1026 | ||
1027 | static | |
1028 | free_numargs() | |
1029 | { | |
1030 | struct numarg *n = numargs_list, *m; | |
1031 | ||
1032 | while (n) { | |
1033 | m = n->next; | |
1034 | free(n); | |
1035 | n = m; | |
1036 | } | |
1037 | numargs_list = 0; | |
1038 | } | |
1039 | ||
1040 | \f | |
1041 | /* Parsing Routines proper. */ | |
1042 | ||
1043 | /* Parse a single symbol. Mostly just make up a GDB symbol for it. | |
1044 | For blocks, procedures and types we open a new lexical context. | |
1045 | This is basically just a big switch on the symbol's type */ | |
1046 | ||
1047 | static | |
1048 | parse_symbol(sh, ax) | |
1049 | SYMR *sh; | |
1050 | AUXU *ax; | |
1051 | { | |
1052 | struct symbol *s; | |
1053 | struct block *b; | |
1054 | struct type *t; | |
1055 | struct field *f; | |
1056 | /* When a symbol is cross-referenced from other files/symbols | |
1057 | we mark it explicitly */ | |
1058 | int pend = (sh->reserved == 1); | |
1059 | enum address_class class; | |
1060 | ||
1061 | switch (sh->st) { | |
1062 | ||
1063 | case stNil: | |
1064 | break; | |
1065 | ||
1066 | case stGlobal: /* external symbol, goes into the primary block */ | |
1067 | class = LOC_STATIC; | |
d219db01 JG |
1068 | b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st), |
1069 | GLOBAL_BLOCK); | |
bd5635a1 RP |
1070 | goto data; |
1071 | ||
1072 | case stStatic: /* static data, goes into the current block. */ | |
1073 | class = LOC_STATIC; | |
1074 | b = top_stack->cur_block; | |
1075 | goto data; | |
1076 | ||
1077 | case stLocal: /* local variable, goes into the current block */ | |
1078 | if (sh->sc == scRegister) { | |
1079 | class = LOC_REGISTER; | |
1080 | if (sh->value > 31) | |
1081 | sh->value += 6; | |
1082 | } else | |
1083 | class = LOC_LOCAL; | |
1084 | b = top_stack->cur_block; | |
1085 | ||
1086 | data: /* Common code for symbols describing data */ | |
1087 | s = new_symbol(sh->iss); | |
1088 | SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; | |
1089 | SYMBOL_CLASS(s) = class; | |
1090 | add_symbol(s, b); | |
1091 | ||
1092 | /* Type could be missing in a number of cases */ | |
1093 | if (sh->sc == scUndefined || sh->sc == scNil || | |
1094 | sh->index == 0xfffff) | |
1095 | SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */ | |
1096 | else | |
1097 | SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0); | |
1098 | /* Value of a data symbol is its memory address */ | |
1099 | SYMBOL_VALUE(s) = sh->value; | |
1100 | break; | |
1101 | ||
1102 | case stParam: /* argument to procedure, goes into current block */ | |
1103 | max_gdbinfo++; | |
1104 | top_stack->numargs++; | |
1105 | s = new_symbol(sh->iss); | |
1106 | SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; | |
1107 | if (sh->sc == scRegister) { | |
1108 | SYMBOL_CLASS(s) = LOC_REGPARM; | |
1109 | if (sh->value > 31) | |
1110 | sh->value += 6; | |
1111 | } else | |
1112 | SYMBOL_CLASS(s) = LOC_ARG; | |
1113 | SYMBOL_VALUE(s) = sh->value; | |
1114 | SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0); | |
1115 | add_symbol(s, top_stack->cur_block); | |
1116 | break; | |
1117 | ||
1118 | case stLabel: /* label, we do make a symbol for it */ | |
1119 | s = new_symbol(sh->iss); | |
1120 | SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */ | |
1121 | SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */ | |
1122 | SYMBOL_VALUE(s) = sh->value; | |
1123 | SYMBOL_TYPE(s) = builtin_type_int; | |
1124 | add_symbol(s, top_stack->cur_block); | |
1125 | break; | |
1126 | ||
1127 | case stProc: /* Procedure */ | |
1128 | case stStaticProc: /* Static procedure */ | |
1129 | s = new_symbol(sh->iss); | |
1130 | SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; | |
1131 | SYMBOL_CLASS(s) = LOC_BLOCK; | |
1132 | /* Type of the return value */ | |
1133 | if (sh->sc == scUndefined || sh->sc == scNil) | |
1134 | t = builtin_type_int; | |
1135 | else | |
1136 | t = parse_type(ax + sh->index, sh, 0); | |
1137 | add_symbol(s, top_stack->cur_block); | |
1138 | ||
1139 | /* Make a type for the procedure itself */ | |
1140 | SYMBOL_TYPE(s) = lookup_function_type (t); | |
1141 | ||
1142 | /* Create and enter a new lexical context */ | |
1143 | b = new_block(top_stack->maxsyms); | |
1144 | SYMBOL_BLOCK_VALUE(s) = b; | |
1145 | BLOCK_FUNCTION(b) = s; | |
1146 | BLOCK_START(b) = BLOCK_END(b) = sh->value; | |
1147 | BLOCK_SUPERBLOCK(b) = top_stack->cur_block; | |
1148 | add_block(b, top_stack->cur_st); | |
1149 | ||
1150 | /* Not if we only have partial info */ | |
1151 | if (sh->sc == scUndefined || sh->sc == scNil) | |
1152 | break; | |
1153 | ||
1154 | push_parse_stack(); | |
1155 | top_stack->cur_block = b; | |
1156 | top_stack->blocktype = sh->st; | |
1157 | top_stack->cur_type = SYMBOL_TYPE(s); | |
1158 | top_stack->procadr = sh->value; | |
1159 | top_stack->numargs = 0; | |
1160 | ||
1161 | sh->value = (long) SYMBOL_TYPE(s); | |
1162 | break; | |
1163 | ||
1164 | case stBlock: /* Either a lexical block, or some type */ | |
1165 | push_parse_stack(); | |
1166 | top_stack->blocktype = stBlock; | |
1167 | if (sh->sc == scInfo) { /* structure/union/enum def */ | |
1168 | s = new_symbol(sh->iss); | |
1169 | SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE; | |
1170 | SYMBOL_CLASS(s) = LOC_TYPEDEF; | |
1171 | SYMBOL_VALUE(s) = 0; | |
1172 | add_symbol(s, top_stack->cur_block); | |
1173 | /* If this type was expected, use its partial definition */ | |
1174 | if (pend) { | |
1175 | t = is_pending_symbol(cur_fdr, sh)->t; | |
1176 | } else { | |
1177 | /* Uhmm, can`t decide yet. Smash later */ | |
1178 | t = new_type(sh->iss); | |
1179 | TYPE_CODE(t) = TYPE_CODE_UNDEF; | |
1180 | add_pending(cur_fdr, sh, t); | |
1181 | } | |
1182 | SYMBOL_TYPE(s) = t; | |
1183 | /* make this the current type */ | |
1184 | top_stack->cur_type = t; | |
1185 | TYPE_LENGTH(t) = sh->value; | |
1186 | /* Mark that symbol has a type, and say which one */ | |
1187 | sh->value = (long) t; | |
1188 | } else { | |
1189 | /* beginnning of (code) block. Value of symbol | |
1190 | is the displacement from procedure start */ | |
1191 | b = new_block(top_stack->maxsyms); | |
1192 | BLOCK_START(b) = sh->value + top_stack->procadr; | |
1193 | BLOCK_SUPERBLOCK(b) = top_stack->cur_block; | |
1194 | top_stack->cur_block = b; | |
1195 | add_block(b, top_stack->cur_st); | |
1196 | } | |
1197 | break; | |
1198 | ||
1199 | case stEnd: /* end (of anything) */ | |
1200 | if (sh->sc == scInfo) { | |
1201 | /* Finished with type */ | |
1202 | top_stack->cur_type = 0; | |
1203 | } else if (sh->sc == scText && | |
1204 | (top_stack->blocktype == stProc || | |
1205 | top_stack->blocktype == stStaticProc)) { | |
1206 | /* Finished with procedure */ | |
1207 | struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st); | |
1208 | struct block *b; | |
1209 | int i; | |
1210 | ||
1211 | BLOCK_END(top_stack->cur_block) += sh->value; /* size */ | |
1212 | got_numargs(top_stack->procadr, top_stack->numargs); | |
1213 | /* Reallocate symbols, saving memory */ | |
1214 | b = shrink_block(top_stack->cur_block, top_stack->cur_st); | |
1215 | ||
1216 | /* f77 emits proc-level with address bounds==[0,0], | |
1217 | So look for such child blocks, and patch them. */ | |
1218 | for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) { | |
1219 | struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i); | |
1220 | if (BLOCK_SUPERBLOCK(b_bad) == b | |
1221 | && BLOCK_START(b_bad) == top_stack->procadr | |
1222 | && BLOCK_END(b_bad) == top_stack->procadr) { | |
1223 | BLOCK_START(b_bad) = BLOCK_START(b); | |
1224 | BLOCK_END(b_bad) = BLOCK_END(b); | |
1225 | } | |
1226 | } | |
1227 | } else if (sh->sc == scText && top_stack->blocktype == stBlock) { | |
1228 | /* End of (code) block. The value of the symbol | |
1229 | is the displacement from the procedure`s start | |
1230 | address of the end of this block. */ | |
1231 | BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr; | |
1232 | (void) shrink_block(top_stack->cur_block, top_stack->cur_st); | |
1233 | } | |
1234 | pop_parse_stack(); /* restore previous lexical context */ | |
1235 | break; | |
1236 | ||
1237 | case stMember: /* member of struct/union/enum.. */ | |
1238 | f = new_field(top_stack->cur_type, sh->iss); | |
1239 | f->bitpos = sh->value; | |
1240 | f->type = parse_type(ax + sh->index, sh, &f->bitsize); | |
1241 | break; | |
1242 | ||
1243 | case stTypedef: /* type definition */ | |
1244 | s = new_symbol(sh->iss); | |
1245 | SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; | |
1246 | SYMBOL_CLASS(s) = LOC_TYPEDEF; | |
1247 | SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block; | |
1248 | add_symbol(s, top_stack->cur_block); | |
1249 | SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0); | |
1250 | sh->value = (long) SYMBOL_TYPE(s); | |
1251 | break; | |
1252 | ||
1253 | case stFile: /* file name */ | |
1254 | push_parse_stack(); | |
1255 | top_stack->blocktype = sh->st; | |
1256 | break; | |
1257 | ||
1258 | /* I`ve never seen these for C */ | |
1259 | case stRegReloc: | |
1260 | break; /* register relocation */ | |
1261 | case stForward: | |
1262 | break; /* forwarding address */ | |
1263 | case stConstant: | |
1264 | break; /* constant */ | |
1265 | default: | |
1266 | error("Unknown symbol type %x.", sh->st); | |
1267 | } | |
1268 | sh->st = stParsed; | |
1269 | } | |
1270 | ||
1271 | /* Parse the type information provided in the AX entries for | |
1272 | the symbol SH. Return the bitfield size in BS, in case. */ | |
1273 | ||
1274 | static struct type *parse_type(ax, sh, bs) | |
1275 | AUXU *ax; | |
1276 | SYMR *sh; | |
1277 | int *bs; | |
1278 | { | |
1279 | /* Null entries in this map are treated specially */ | |
1280 | static struct type **map_bt[] = | |
1281 | { | |
1282 | &builtin_type_void, /* btNil */ | |
1283 | 0, /* btAdr */ | |
1284 | &builtin_type_char, /* btChar */ | |
1285 | &builtin_type_unsigned_char, /* btUChar */ | |
1286 | &builtin_type_short, /* btShort */ | |
1287 | &builtin_type_unsigned_short, /* btUShort */ | |
1288 | &builtin_type_int, /* btInt */ | |
1289 | &builtin_type_unsigned_int, /* btUInt */ | |
1290 | &builtin_type_long, /* btLong */ | |
1291 | &builtin_type_unsigned_long, /* btULong */ | |
1292 | &builtin_type_float, /* btFloat */ | |
1293 | &builtin_type_double, /* btDouble */ | |
1294 | 0, /* btStruct */ | |
1295 | 0, /* btUnion */ | |
1296 | 0, /* btEnum */ | |
1297 | 0, /* btTypedef */ | |
1298 | 0, /* btRange */ | |
1299 | 0, /* btSet */ | |
1300 | &builtin_type_complex, /* btComplex */ | |
1301 | &builtin_type_double_complex, /* btDComplex */ | |
1302 | 0, /* btIndirect */ | |
1303 | &builtin_type_fixed_dec, /* btFixedDec */ | |
1304 | &builtin_type_float_dec, /* btFloatDec */ | |
1305 | &builtin_type_string, /* btString */ | |
1306 | 0, /* btBit */ | |
1307 | 0, /* btPicture */ | |
1308 | &builtin_type_void, /* btVoid */ | |
1309 | }; | |
1310 | ||
1311 | TIR *t; | |
1312 | struct type *tp = 0, *tp1; | |
1313 | char *fmt = "%s"; | |
1314 | ||
1315 | /* Procedures start off by one */ | |
1316 | if (sh->st == stProc || sh->st == stStaticProc) | |
1317 | ax++; | |
1318 | ||
1319 | /* Undefined ? Should not happen */ | |
1320 | if (ax->rndx.rfd == 0xfff) { | |
1321 | return builtin_type_void; | |
1322 | } | |
1323 | ||
1324 | /* Use aux as a type information record, map its basic type */ | |
1325 | t = &ax->ti; | |
1326 | if (t->bt > 26 || t->bt == btPicture) { | |
1327 | printf_filtered("Internal: cannot map MIPS basic type x%x\n", t->bt); | |
1328 | return builtin_type_int; | |
1329 | } | |
1330 | if (map_bt[t->bt]) | |
1331 | tp = *map_bt[t->bt]; | |
1332 | else { | |
1333 | /* Cannot use builtin types, use templates */ | |
1334 | tp = make_type(TYPE_CODE_VOID, 0, 0, 0); | |
1335 | switch (t->bt) { | |
1336 | case btAdr: | |
1337 | *tp = *builtin_type_ptr; | |
1338 | break; | |
1339 | case btStruct: | |
1340 | *tp = *builtin_type_struct; | |
1341 | fmt = "struct %s"; | |
1342 | break; | |
1343 | case btUnion: | |
1344 | *tp = *builtin_type_union; | |
1345 | fmt = "union %s"; | |
1346 | break; | |
1347 | case btEnum: | |
1348 | *tp = *builtin_type_enum; | |
1349 | fmt = "enum %s"; | |
1350 | break; | |
1351 | case btRange: | |
1352 | *tp = *builtin_type_range; | |
1353 | break; | |
1354 | case btSet: | |
1355 | *tp = *builtin_type_set; | |
1356 | fmt = "set %s"; | |
1357 | break; | |
1358 | } | |
1359 | } | |
1360 | ||
1361 | /* Move on to next aux */ | |
1362 | ax++; | |
1363 | if (t->continued) { | |
1364 | /* This is the way it would work if the compiler worked */ | |
1365 | register TIR *t1 = t; | |
1366 | while (t1->continued) | |
1367 | ax++; | |
1368 | } | |
1369 | ||
1370 | /* For bitfields all we need is the width */ | |
1371 | if (t->fBitfield) { | |
1372 | *bs = ax->width; | |
1373 | return tp; | |
1374 | } | |
1375 | ||
1376 | /* All these types really point to some (common) MIPS type | |
1377 | definition, and only the type-qualifiers fully identify | |
1378 | them. We`ll make the same effort at sharing */ | |
1379 | if (t->bt == btIndirect || | |
1380 | t->bt == btStruct || | |
1381 | t->bt == btUnion || | |
1382 | t->bt == btEnum || | |
1383 | t->bt == btTypedef || | |
1384 | t->bt == btRange || | |
1385 | t->bt == btSet) { | |
1386 | char name[256], *pn; | |
1387 | ||
1388 | /* Try to cross reference this type */ | |
1389 | tp1 = tp; | |
1390 | ax += cross_ref(ax, &tp1, &pn); | |
1391 | /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */ | |
1392 | sprintf(name, fmt, pn); | |
1393 | ||
1394 | /* reading .o file ? */ | |
1395 | if (UNSAFE_DATA_ADDR(tp1)) | |
1396 | tp1 = tp; | |
1397 | if (TYPE_CODE(tp1) == TYPE_CODE_UNDEF) { | |
1398 | /* | |
1399 | * Type was incompletely defined, now we know. | |
1400 | */ | |
1401 | TYPE_CODE(tp1) = TYPE_CODE(tp); | |
1402 | TYPE_NAME(tp1) = obsavestring(name, strlen(name)); | |
1403 | if (TYPE_CODE(tp1) == TYPE_CODE_ENUM) { | |
1404 | int i; | |
1405 | ||
1406 | for (i = 0; i < TYPE_NFIELDS(tp1); i++) | |
1407 | make_enum_constant(&TYPE_FIELD(tp1,i), tp1); | |
1408 | } | |
1409 | } | |
1410 | if (tp1 != tp) { | |
1411 | /* found as cross ref, rid of our template */ | |
1412 | if ((TYPE_FLAGS(tp) & TYPE_FLAG_PERM) == 0) | |
1413 | free(tp); | |
1414 | tp = tp1; | |
1415 | /* stupid idea of prepending "struct" to type names */ | |
1416 | if (t->bt == btStruct && !index(TYPE_NAME(tp), ' ')) { | |
1417 | sprintf(name, fmt, TYPE_NAME(tp)); | |
1418 | TYPE_NAME(tp) = obsavestring(name, strlen(name)); | |
1419 | } | |
1420 | } else | |
1421 | TYPE_NAME(tp) = savestring(name, strlen(name)); | |
1422 | } | |
1423 | ||
1424 | /* Deal with range types */ | |
1425 | if (t->bt == btRange) { | |
1426 | struct field *f; | |
1427 | ||
1428 | f = new_field(tp, "Low"); | |
1429 | f->bitpos = ax->dnLow; | |
1430 | ax++; | |
1431 | f = new_field(tp, "High"); | |
1432 | f->bitpos = ax->dnHigh; | |
1433 | ax++; | |
1434 | } | |
1435 | ||
1436 | /* Parse all the type qualifiers now. If there are more | |
1437 | than 6 the game will continue in the next aux */ | |
1438 | ||
1439 | #define PARSE_TQ(tq) \ | |
1440 | if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh); | |
1441 | ||
1442 | again: PARSE_TQ(tq0); | |
1443 | PARSE_TQ(tq1); | |
1444 | PARSE_TQ(tq2); | |
1445 | PARSE_TQ(tq3); | |
1446 | PARSE_TQ(tq4); | |
1447 | PARSE_TQ(tq5); | |
1448 | #undef PARSE_TQ | |
1449 | ||
1450 | if (t->continued) { | |
1451 | t++; | |
1452 | goto again; | |
1453 | } | |
1454 | return tp; | |
1455 | } | |
1456 | ||
1457 | /* Make up a complex type from a basic one. Type is passed by | |
1458 | reference in TPP and side-effected as necessary. The type | |
1459 | qualifier TQ says how to handle the aux symbols at AX for | |
1460 | the symbol SX we are currently analyzing. | |
1461 | Returns the number of aux symbols we parsed. */ | |
1462 | ||
1463 | static | |
1464 | upgrade_type(tpp, tq, ax, sh) | |
1465 | struct type **tpp; | |
1466 | AUXU *ax; | |
1467 | SYMR *sh; | |
1468 | { | |
1469 | int off = 0; | |
1470 | int ret = 0; | |
1471 | struct type *t; | |
1472 | ||
1473 | if (tq == tqPtr) { | |
1474 | t = lookup_pointer_type (*tpp); | |
1475 | } else if (tq == tqProc) { | |
1476 | t = lookup_function_type (*tpp); | |
1477 | } else if (tq == tqArray) { | |
1478 | int rf, id; | |
1479 | FDR *fh; | |
1480 | struct field *f; | |
1481 | SYMR ss; | |
1482 | ||
1483 | t = make_type(TYPE_CODE_ARRAY, 0, 0, 0); | |
1484 | TYPE_TARGET_TYPE(t) = *tpp; | |
1485 | ||
1486 | /* Pointer to domain type (type of index) */ | |
1487 | id = ax->rndx.index; | |
1488 | if ((rf = ax->rndx.rfd) == 0xfff) | |
1489 | rf = (++ax)->isym, off++; | |
1490 | ||
1491 | fh = get_rfd(cur_fd, rf); | |
1492 | f = new_field(t, 0); | |
1493 | bzero(&ss, sizeof ss); | |
1494 | /* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(AUXU), | |
1495 | &ss, &f->bitsize); | |
1496 | ||
1497 | /* | |
1498 | * This seems to be a pointer to the end of the Block defining | |
1499 | * the type. Why it is here is magic for me, and I have no | |
1500 | * good use for it anyways. | |
1501 | */ | |
1502 | if (off == 0) { | |
1503 | off++; | |
1504 | id = (++ax)->rndx.index; | |
1505 | if ((rf = ax->rndx.rfd) == 0xfff) | |
1506 | rf = (++ax)->isym, off++; | |
1507 | } | |
1508 | f->bitpos = (++ax)->dnLow; /* ?? */ | |
1509 | f->bitsize = (++ax)->dnHigh; /* ?? */ | |
1510 | rf = (++ax)->width - 1; /* bit alignment */ | |
1511 | id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */ | |
1512 | ||
1513 | if (id == 0) { | |
1514 | /* Most likely an undefined type */ | |
1515 | id = rf + 1; | |
1516 | TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3; | |
1517 | } | |
1518 | TYPE_LENGTH(t) = (f->bitsize < 0) ? 0 : | |
1519 | (f->bitsize - f->bitpos + 1) * (id >> 3); | |
1520 | ret = 4 + off; | |
1521 | } else { | |
1522 | if (tq != tqVol) | |
1523 | printf_filtered("Internal: unknown type qualifier %x\n", tq); | |
1524 | return ret; | |
1525 | } | |
1526 | ||
1527 | *tpp = t; | |
1528 | return ret; | |
1529 | } | |
1530 | ||
1531 | ||
1532 | /* Parse a procedure descriptor record PR. Note that the procedure | |
1533 | is parsed _after_ the local symbols, now we just make up the | |
1534 | extra information we need into a special symbol that we insert | |
1535 | in the procedure's main block. Note also that images that | |
1536 | have been partially stripped (ld -x) have been deprived | |
1537 | of local symbols, and we have to cope with them here. | |
1538 | The procedure's code ends at BOUND */ | |
1539 | ||
1540 | static | |
1541 | parse_procedure(pr, bound) | |
1542 | PDR *pr; | |
1543 | { | |
1544 | struct symbol *s, *i; | |
1545 | SYMR *sh = (SYMR*)pr->isym; | |
1546 | struct block *b; | |
1547 | struct mips_extra_func_info *e; | |
1548 | char name[100]; | |
1549 | char *sh_name; | |
1550 | ||
1551 | /* Reuse the MIPS record */ | |
1552 | e = (struct mips_extra_func_info *) pr; | |
1553 | e->numargs = lookup_numargs(pr->adr); | |
1554 | ||
1555 | /* Make up our special symbol */ | |
1556 | i = new_symbol(".gdbinfo."); | |
1557 | SYMBOL_VALUE(i) = (int)e; | |
1558 | SYMBOL_NAMESPACE(i) = LABEL_NAMESPACE; | |
1559 | SYMBOL_CLASS(i) = LOC_CONST; | |
1560 | SYMBOL_TYPE(i) = builtin_type_void; | |
1561 | ||
1562 | /* Make up a name for static procedures. Sigh. */ | |
1563 | if (sh == (SYMR*)-1) { | |
1564 | sprintf(name,".static_procedure@%x",pr->adr); | |
1565 | sh_name = savestring(name, strlen(name)); | |
1566 | s = NULL; | |
1567 | } | |
1568 | else { | |
1569 | sh_name = (char*)sh->iss; | |
1570 | s = mylookup_symbol(sh_name, top_stack->cur_block, | |
1571 | VAR_NAMESPACE, LOC_BLOCK); | |
1572 | } | |
1573 | if (s != 0) { | |
1574 | b = SYMBOL_BLOCK_VALUE(s); | |
1575 | } else { | |
1576 | s = new_symbol(sh_name); | |
1577 | SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; | |
1578 | SYMBOL_CLASS(s) = LOC_BLOCK; | |
1579 | /* Donno its type, hope int is ok */ | |
1580 | SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int); | |
1581 | add_symbol(s, top_stack->cur_block); | |
1582 | /* Wont have symbols for this one */ | |
1583 | b = new_block(2); | |
1584 | SYMBOL_BLOCK_VALUE(s) = b; | |
1585 | BLOCK_FUNCTION(b) = s; | |
1586 | BLOCK_START(b) = pr->adr; | |
1587 | BLOCK_END(b) = bound; | |
1588 | BLOCK_SUPERBLOCK(b) = top_stack->cur_block; | |
1589 | add_block(b, top_stack->cur_st); | |
1590 | } | |
1591 | e->isym = (long)s; | |
1592 | add_symbol(i,b); | |
1593 | } | |
1594 | ||
1595 | /* Parse the external symbol ES. Just call parse_symbol() after | |
1596 | making sure we know where the aux are for it. For procedures, | |
1597 | parsing of the PDRs has already provided all the needed | |
1598 | information, we only parse them if SKIP_PROCEDURES is false, | |
1599 | and only if this causes no symbol duplication */ | |
1600 | ||
1601 | static | |
1602 | parse_external(es, skip_procedures) | |
1603 | EXTR *es; | |
1604 | { | |
1605 | AUXU *ax; | |
1606 | ||
1607 | if (es->ifd != ifdNil) { | |
1608 | cur_fd = es->ifd; | |
1609 | cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd; | |
1610 | ax = (AUXU*)cur_fdr->iauxBase; | |
1611 | } else { | |
1612 | cur_fdr = (FDR*)(cur_hdr->cbFdOffset); | |
1613 | ax = 0; | |
1614 | } | |
1615 | top_stack->cur_st = cur_stab; | |
d219db01 JG |
1616 | top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st), |
1617 | GLOBAL_BLOCK); | |
bd5635a1 RP |
1618 | |
1619 | /* Reading .o files */ | |
1620 | if (es->asym.sc == scUndefined || es->asym.sc == scNil) { | |
1621 | char *what; | |
1622 | switch (es->asym.st) { | |
1623 | case stStaticProc: | |
1624 | case stProc: what = "Procedure"; n_undef_procs++; break; | |
1625 | case stGlobal: what = "Variable"; n_undef_vars++; break; | |
1626 | case stLabel: what = "Label"; n_undef_labels++; break; | |
1627 | default : what = "Symbol"; break; | |
1628 | } | |
1629 | n_undef_symbols++; | |
1630 | if (info_verbose) | |
1631 | printf_filtered("Warning: %s %s is undefined (in %s)\n", what, | |
1632 | es->asym.iss, fdr_name(cur_fdr->rss)); | |
1633 | return; | |
1634 | } | |
1635 | ||
1636 | switch (es->asym.st) { | |
1637 | case stProc: | |
1638 | /* If we have full symbols we do not need more */ | |
1639 | if (skip_procedures) | |
1640 | return; | |
1641 | if (mylookup_symbol (es->asym.iss, top_stack->cur_block, | |
1642 | VAR_NAMESPACE, LOC_BLOCK)) | |
1643 | break; | |
1644 | /* fall through */ | |
1645 | case stGlobal: | |
1646 | case stLabel: | |
1647 | /* | |
1648 | * Note that the case of a symbol with indexNil | |
1649 | * must be handled anyways by parse_symbol(). | |
1650 | */ | |
1651 | parse_symbol(&es->asym, ax); | |
1652 | break; | |
1653 | default: | |
1654 | break; | |
1655 | } | |
1656 | } | |
1657 | ||
1658 | /* Parse the line number info for file descriptor FH into | |
1659 | GDB's linetable LT. MIPS' encoding requires a little bit | |
1660 | of magic to get things out. Note also that MIPS' line | |
1661 | numbers can go back and forth, apparently we can live | |
1662 | with that and do not need to reorder our linetables */ | |
1663 | ||
1664 | static | |
1665 | parse_lines(fh, lt) | |
1666 | FDR *fh; | |
1667 | struct linetable *lt; | |
1668 | { | |
1669 | char *base = (char*)fh->cbLineOffset; | |
1670 | int i, j, k; | |
1671 | int delta, count, lineno = 0; | |
1672 | PDR *pr; | |
1673 | ||
1674 | if (base == 0) | |
1675 | return; | |
1676 | ||
1677 | /* Scan by procedure descriptors */ | |
1678 | i = 0; j = 0, k = 0; | |
1679 | for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) { | |
1680 | int l, halt; | |
1681 | ||
1682 | /* No code for this one */ | |
1683 | if (pr->iline == ilineNil || | |
1684 | pr->lnLow == -1 || pr->lnHigh == -1) | |
1685 | continue; | |
1686 | /* | |
1687 | * Aurgh! To know where to stop expanding we | |
1688 | * must look-ahead. | |
1689 | */ | |
1690 | for (l = 1; l < (fh->cpd - j); l++) | |
1691 | if (pr[l].iline != -1) | |
1692 | break; | |
1693 | if (l == (fh->cpd - j)) | |
1694 | halt = fh->cline; | |
1695 | else | |
1696 | halt = pr[l].iline; | |
1697 | /* | |
1698 | * When procedures are moved around the linenumbers | |
1699 | * are attributed to the next procedure up | |
1700 | */ | |
1701 | if (pr->iline >= halt) continue; | |
1702 | ||
1703 | base = (char*)pr->cbLineOffset; | |
1704 | l = pr->adr >> 2; /* in words */ | |
1705 | halt += (pr->adr >> 2) - pr->iline; | |
1706 | for (lineno = pr->lnLow; l < halt;) { | |
1707 | count = *base & 0x0f; | |
1708 | delta = *base++ >> 4; | |
1709 | if (delta == -8) { | |
1710 | delta = (base[0] << 8) | (base[1] & 0xff); | |
1711 | base += 2; | |
1712 | } | |
1713 | lineno += delta;/* first delta is 0 */ | |
1714 | k = add_line(lt, lineno, l, k); | |
1715 | l += count + 1; | |
1716 | } | |
1717 | } | |
1718 | } | |
1719 | ||
1720 | ||
1721 | /* Parse the symbols of the file described by FH, whose index is F_IDX. | |
1722 | BOUND is the highest core address of this file's procedures */ | |
1723 | ||
1724 | static | |
1725 | parse_one_file(fh, f_idx, bound) | |
1726 | FDR *fh; | |
1727 | { | |
1728 | register int s_idx; | |
1729 | SYMR *sh; | |
1730 | PDR *pr; | |
1731 | ||
1732 | /* Parse local symbols first */ | |
1733 | ||
1734 | for (s_idx = 0; s_idx < fh->csym; s_idx++) { | |
1735 | sh = (SYMR *) (fh->isymBase) + s_idx; | |
1736 | cur_sdx = s_idx; | |
1737 | parse_symbol(sh, fh->iauxBase); | |
1738 | } | |
1739 | ||
1740 | /* Procedures next, note we need to look-ahead to | |
1741 | find out where the procedure's code ends */ | |
1742 | ||
1743 | for (s_idx = 0; s_idx < fh->cpd-1; s_idx++) { | |
1744 | pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx; | |
1745 | parse_procedure(pr, pr[1].adr); /* next proc up */ | |
1746 | } | |
1747 | if (fh->cpd) { | |
1748 | pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx; | |
1749 | parse_procedure(pr, bound); /* next file up */ | |
1750 | } | |
1751 | ||
1752 | /* Linenumbers. At the end, check if we can save memory */ | |
1753 | parse_lines(fh, LINETABLE(cur_stab)); | |
1754 | if (LINETABLE(cur_stab)->nitems < fh->cline) | |
1755 | shrink_linetable(cur_stab); | |
1756 | } | |
1757 | ||
1758 | ||
1759 | /* Master parsing procedure. Parses the symtab described by the | |
1760 | symbolic header HDR. If INCREMENTAL is true we are called | |
1761 | by add-file and must preserve the old symtabs */ | |
1762 | static | |
1763 | parse_partial_symbols(hdr, incremental) | |
1764 | HDRR *hdr; | |
1765 | { | |
1766 | int f_idx, s_idx, h_max; | |
1767 | CORE_ADDR dummy, *prevhigh; | |
1768 | /* Running pointers */ | |
1769 | FDR *fh; | |
1770 | RFDT *rh; | |
1771 | register EXTR *esh; | |
1772 | ||
1773 | /* | |
1774 | * Big plan: | |
1775 | * | |
1776 | * Only parse the External symbols, and the Relative FDR. | |
1777 | * Fixup enough of the loader symtab to be able to use it. | |
1778 | * Allocate space only for the file`s portions we need to | |
1779 | * look at. (XXX) | |
1780 | */ | |
1781 | ||
1782 | cur_hdr = hdr; | |
1783 | max_gdbinfo = 0; | |
1784 | max_glevel = MIN_GLEVEL; | |
1785 | ||
1786 | /* Allocate the map FDR -> PST. | |
1787 | Minor hack: -O3 images might claim some global data belongs | |
1788 | to FDR -1. We`ll go along with that */ | |
1789 | fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst); | |
1790 | fdr_to_pst++; | |
1791 | { | |
1792 | struct partial_symtab * pst = new_psymtab(""); | |
1793 | fdr_to_pst[-1].pst = pst; | |
1794 | pst->ldsymoff = -1; | |
1795 | } | |
1796 | ||
1797 | /* Now scan the FDRs, mostly for dependencies */ | |
1798 | for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) | |
1799 | (void) parse_fdr(f_idx, 1); | |
1800 | ||
1801 | /* Take a good guess at how many symbols we might ever need */ | |
1802 | h_max = hdr->iextMax; | |
1803 | ||
1804 | /* Parse externals: two passes because they can be ordered | |
1805 | in any way */ | |
1806 | ||
1807 | /* Pass 1: Presize and partition the list */ | |
1808 | for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) { | |
1809 | esh = (EXTR *) (hdr->cbExtOffset) + s_idx; | |
1810 | fdr_to_pst[esh->ifd].n_globals++; | |
1811 | } | |
1812 | ||
1813 | if (global_psymbols.list) { | |
1814 | global_psymbols.list = (struct partial_symbol *) | |
1815 | xrealloc( global_psymbols.list, (h_max + | |
1816 | global_psymbols.size) * sizeof(struct partial_symbol)); | |
1817 | global_psymbols.next = global_psymbols.list + global_psymbols.size; | |
1818 | global_psymbols.size += h_max; | |
1819 | } else { | |
1820 | global_psymbols.list = (struct partial_symbol *) | |
1821 | xmalloc( h_max * sizeof(struct partial_symbol)); | |
1822 | global_psymbols.size = h_max; | |
1823 | global_psymbols.next = global_psymbols.list; | |
1824 | } | |
1825 | ||
1826 | s_idx = global_psymbols.next - global_psymbols.list; | |
1827 | for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) { | |
1828 | fdr_to_pst[f_idx].pst->globals_offset = s_idx; | |
1829 | s_idx += fdr_to_pst[f_idx].n_globals; | |
1830 | } | |
1831 | ||
1832 | /* Pass 2: fill in symbols */ | |
1833 | for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) { | |
1834 | register struct partial_symbol *p; | |
1835 | enum misc_function_type misc_type = mf_text; | |
1836 | esh = (EXTR *) (hdr->cbExtOffset) + s_idx; | |
1837 | ||
1838 | if (esh->asym.sc == scUndefined || esh->asym.sc == scNil) | |
1839 | continue; | |
1840 | p = new_psymbol(&global_psymbols, esh->asym.iss, esh->ifd); | |
1841 | SYMBOL_VALUE(p) = esh->asym.value; | |
1842 | SYMBOL_NAMESPACE(p) = VAR_NAMESPACE; | |
1843 | ||
1844 | switch (esh->asym.st) { | |
1845 | case stProc: | |
1846 | SYMBOL_CLASS(p) = LOC_BLOCK; | |
1847 | break; | |
1848 | case stGlobal: | |
1849 | SYMBOL_CLASS(p) = LOC_STATIC; | |
1850 | misc_type = mf_data; | |
1851 | break; | |
1852 | case stLabel: | |
1853 | SYMBOL_CLASS(p) = LOC_LABEL; | |
1854 | break; | |
1855 | default: | |
1856 | misc_type = mf_unknown; | |
1857 | complain (&unknown_ext_complaint, SYMBOL_NAME(p)); | |
1858 | } | |
1859 | prim_record_misc_function (SYMBOL_NAME(p), | |
1860 | SYMBOL_VALUE(p), | |
1861 | misc_type); | |
1862 | } | |
1863 | ||
1864 | ||
1865 | /* The array (of lists) of globals must be sorted. | |
1866 | Take care, since we are at it, of pst->texthigh. | |
1867 | ||
1868 | NOTE: The way we handle textlow/high is incorrect, but good | |
1869 | enough for a first approximation. The case we fail is on a | |
1870 | file "foo.c" that looks like | |
1871 | proc1() {...} | |
1872 | #include "bar.c" -- this contains proc2() | |
1873 | proc3() {...} | |
1874 | where proc3() is attributed to bar.c. But since this is a | |
1875 | dependent file it will cause loading of foo.c as well, so | |
1876 | everything will be fine at the end. */ | |
1877 | ||
1878 | prevhigh = &dummy; | |
1879 | for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) { | |
1880 | struct partial_symtab *pst = fdr_to_pst[f_idx].pst; | |
1881 | if (pst->n_global_syms > 1) | |
1882 | qsort (global_psymbols.list + pst->globals_offset, | |
1883 | pst->n_global_syms, sizeof (struct partial_symbol), | |
1884 | compare_psymbols); | |
1885 | if (pst->textlow) { | |
1886 | *prevhigh = pst->textlow; | |
1887 | prevhigh = &pst->texthigh; | |
1888 | } | |
1889 | } | |
1890 | ||
1891 | /* Mark the last code address, and remember it for later */ | |
1892 | *prevhigh = END_OF_TEXT_SEGMENT(filhdr); | |
1893 | hdr->cbDnOffset = END_OF_TEXT_SEGMENT(filhdr); | |
1894 | ||
1895 | reorder_psymtabs(); | |
1896 | free(&fdr_to_pst[-1]); | |
1897 | fdr_to_pst = 0; | |
1898 | } | |
1899 | ||
1900 | ||
1901 | /* Do the initial analisys of the F_IDX-th file descriptor. | |
1902 | Allocates a partial symtab for it, and builds the list | |
1903 | of dependent files by recursion. LEV says at which level | |
1904 | of recursion we are called (to pretty up debug traces) */ | |
1905 | ||
1906 | static struct partial_symtab * | |
1907 | parse_fdr(f_idx, lev) | |
1908 | int f_idx; | |
1909 | { | |
1910 | register FDR *fh; | |
1911 | register struct partial_symtab *pst; | |
1912 | int s_idx, s_id0; | |
1913 | ||
1914 | fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx; | |
1915 | ||
1916 | /* Use this to indicate into which symtab this file was parsed */ | |
1917 | if (fh->ioptBase) | |
1918 | return (struct partial_symtab *) fh->ioptBase; | |
1919 | ||
1920 | /* Debuggability level */ | |
1921 | if (compare_glevel(max_glevel, fh->glevel) < 0) | |
1922 | max_glevel = fh->glevel; | |
1923 | ||
1924 | /* Make a new partial_symtab */ | |
1925 | pst = new_psymtab(fh->rss); | |
1926 | if (fh->cpd == 0){ | |
1927 | pst->textlow = 0; | |
1928 | pst->texthigh = 0; | |
1929 | } else { | |
1930 | pst->textlow = fh->adr; | |
1931 | pst->texthigh = fh->cpd; /* To be fixed later */ | |
1932 | } | |
1933 | /* Reverse mapping PST -> FDR */ | |
1934 | pst->ldsymoff = f_idx; | |
1935 | ||
1936 | fdr_to_pst[f_idx].pst = pst; | |
1937 | fh->ioptBase = (int)pst; | |
1938 | ||
1939 | /* Analyze its dependencies */ | |
1940 | if (fh->crfd <= 1) | |
1941 | return pst; | |
1942 | ||
1943 | s_id0 = 0; | |
1944 | if (fh->cpd == 0) { /* If there are no functions defined here ... */ | |
1945 | /* ...then presumably a .h file: drop reverse depends .h->.c */ | |
1946 | for (; s_id0 < fh->crfd; s_id0++) { | |
1947 | RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0; | |
1948 | if (*rh == f_idx) { | |
1949 | s_id0++; /* Skip self-dependency */ | |
1950 | break; | |
1951 | } | |
1952 | } | |
1953 | } | |
1954 | pst->number_of_dependencies = fh->crfd - s_id0; | |
1955 | pst->dependencies = (struct partial_symtab **) | |
1956 | obstack_alloc (psymbol_obstack, | |
1957 | pst->number_of_dependencies * sizeof(char*)); | |
1958 | for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) { | |
1959 | RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx; | |
1960 | ||
1961 | pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1); | |
1962 | ||
1963 | } | |
1964 | ||
1965 | return pst; | |
1966 | } | |
1967 | ||
1968 | ||
1969 | /* Ancillary function to psymtab_to_symtab(). Does all the work | |
1970 | for turning the partial symtab PST into a symtab, recurring | |
1971 | first on all dependent psymtabs */ | |
1972 | ||
1973 | static void psymtab_to_symtab_1(pst) | |
1974 | struct partial_symtab *pst; | |
1975 | { | |
1976 | int i, f_max; | |
1977 | struct symtab *st; | |
1978 | FDR *fh; | |
1979 | ||
1980 | if (pst->readin) | |
1981 | return; | |
1982 | pst->readin = 1; | |
1983 | ||
1984 | pending_list = (struct pending **) cur_hdr->cbOptOffset; | |
1985 | if (pending_list == 0) { | |
1986 | pending_list = (struct pending **) | |
1987 | xzalloc(cur_hdr->ifdMax * sizeof(struct pending *)); | |
1988 | cur_hdr->cbOptOffset = (int)pending_list; | |
1989 | } | |
1990 | ||
1991 | /* How many symbols will we need */ | |
1992 | f_max = pst->n_global_syms + pst->n_static_syms; | |
1993 | if (pst->ldsymoff == -1) { | |
1994 | fh = 0; | |
1995 | st = new_symtab( "unknown", f_max, 0); | |
1996 | } else { | |
1997 | fh = (FDR *) (cur_hdr->cbFdOffset) + pst->ldsymoff; | |
1998 | f_max += fh->csym + fh->cpd; | |
1999 | st = new_symtab(pst->filename, 2 * f_max, 2 * fh->cline); | |
2000 | } | |
2001 | ||
2002 | /* | |
2003 | * Read in all partial symbtabs on which this one is dependent. | |
2004 | * NOTE that we do have circular dependencies, sigh. | |
2005 | */ | |
2006 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2007 | if (!pst->dependencies[i]->readin) { | |
2008 | /* | |
2009 | * DO NOT inform about additional files that need to | |
2010 | * be read in, it would only annoy the user. | |
2011 | */ | |
2012 | psymtab_to_symtab_1(pst->dependencies[i]); | |
2013 | } | |
2014 | ||
2015 | /* Now read the symbols for this symtab */ | |
2016 | ||
2017 | cur_fd = pst->ldsymoff; | |
2018 | cur_fdr = fh; | |
2019 | cur_stab = st; | |
2020 | ||
2021 | /* Get a new lexical context */ | |
2022 | ||
2023 | push_parse_stack(); | |
2024 | top_stack->cur_st = cur_stab; | |
d219db01 JG |
2025 | top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab), |
2026 | GLOBAL_BLOCK); | |
bd5635a1 RP |
2027 | BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0; |
2028 | BLOCK_END(top_stack->cur_block) = 0; | |
2029 | top_stack->blocktype = stFile; | |
2030 | top_stack->maxsyms = f_max; | |
2031 | top_stack->cur_type = 0; | |
2032 | top_stack->procadr = 0; | |
2033 | top_stack->numargs = 0; | |
2034 | ||
2035 | /* Parse locals and procedures */ | |
2036 | if (fh) | |
2037 | parse_one_file(fh, cur_fd, (cur_fd == (cur_hdr->ifdMax - 1)) ? | |
2038 | cur_hdr->cbDnOffset : fh[1].adr); | |
2039 | ||
2040 | /* .. and our share of externals. | |
2041 | XXX use the global list to speed up things here. how ? */ | |
2042 | top_stack->blocktype = stFile; | |
2043 | top_stack->maxsyms = cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax; | |
2044 | for (i = 0; i < cur_hdr->iextMax; i++) { | |
2045 | register EXTR *esh = (EXTR *) (cur_hdr->cbExtOffset) + i; | |
2046 | if (esh->ifd == cur_fd) | |
2047 | parse_external(esh, 1); | |
2048 | } | |
2049 | ||
2050 | /* If there are undefined, tell the user */ | |
2051 | if (n_undef_symbols) { | |
2052 | printf_filtered("File %s contains %d unresolved references:", | |
2053 | st->filename, n_undef_symbols); | |
2054 | printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n", | |
2055 | n_undef_vars, n_undef_procs, n_undef_labels); | |
2056 | n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0; | |
2057 | } | |
2058 | ||
2059 | pop_parse_stack(); | |
2060 | ||
2061 | /* | |
2062 | * Sort the symbol table now, we are done adding symbols to it. | |
2063 | */ | |
2064 | sort_symtab_syms(st); | |
2065 | } | |
2066 | ||
2067 | ||
2068 | ||
2069 | \f | |
2070 | /* Ancillary parsing procedures. */ | |
2071 | ||
2072 | /* Lookup the type at relative index RN. Return it in TPP | |
2073 | if found and in any event come up with its name PNAME. | |
2074 | Return value says how many aux symbols we ate */ | |
2075 | ||
2076 | static | |
2077 | cross_ref(rn, tpp, pname) | |
2078 | RNDXR *rn; | |
2079 | struct type **tpp; | |
2080 | char **pname; | |
2081 | { | |
2082 | unsigned rf; | |
2083 | ||
2084 | /* Escape index means 'the next one' */ | |
2085 | if (rn->rfd == 0xfff) | |
2086 | rf = *(unsigned *) (rn + 1); | |
2087 | else | |
2088 | rf = rn->rfd; | |
2089 | ||
2090 | if (rf == -1) { | |
2091 | /* Ooops */ | |
2092 | *pname = "<undefined>"; | |
2093 | } else { | |
2094 | /* | |
2095 | * Find the relative file descriptor and the symbol in it | |
2096 | */ | |
2097 | FDR *fh = get_rfd(cur_fd, rf); | |
2098 | SYMR *sh; | |
2099 | struct type *t; | |
2100 | ||
2101 | /* | |
2102 | * If we have processed this symbol then we left a forwarding | |
2103 | * pointer to the corresponding GDB symbol. If not, we`ll put | |
2104 | * it in a list of pending symbols, to be processed later when | |
2105 | * the file f will be. In any event, we collect the name for | |
2106 | * the type here. Which is why we made a first pass at | |
2107 | * strings. | |
2108 | */ | |
2109 | sh = (SYMR *) (fh->isymBase) + rn->index; | |
2110 | ||
2111 | /* Careful, we might be looking at .o files */ | |
2112 | *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" : | |
2113 | (char *) sh->iss; | |
2114 | ||
2115 | /* Have we parsed it ? */ | |
2116 | if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) { | |
2117 | t = (struct type *) sh->value; | |
2118 | *tpp = t; | |
2119 | } else { | |
2120 | struct pending *p; | |
2121 | ||
2122 | /* Avoid duplicates */ | |
2123 | p = is_pending_symbol(fh, sh); | |
2124 | ||
2125 | if (p) | |
2126 | *tpp = p->t; | |
2127 | else | |
2128 | add_pending(fh, sh, *tpp); | |
2129 | } | |
2130 | } | |
2131 | return (rn->rfd == 0xfff); | |
2132 | } | |
2133 | ||
2134 | ||
2135 | /* Quick&dirty lookup procedure, to avoid the MI ones that require | |
2136 | keeping the symtab sorted */ | |
2137 | ||
2138 | static struct symbol * | |
2139 | mylookup_symbol (name, block, namespace, class) | |
2140 | char *name; | |
2141 | register struct block *block; | |
2142 | enum namespace namespace; | |
2143 | enum address_class class; | |
2144 | { | |
2145 | register int bot, top, inc; | |
2146 | register struct symbol *sym; | |
2147 | ||
2148 | bot = 0; | |
2149 | top = BLOCK_NSYMS(block); | |
2150 | inc = name[0]; | |
2151 | while (bot < top) { | |
2152 | sym = BLOCK_SYM(block, bot); | |
2153 | if (SYMBOL_NAME(sym)[0] == inc | |
2154 | && SYMBOL_NAMESPACE(sym) == namespace | |
2155 | && SYMBOL_CLASS(sym) == class | |
2156 | && !strcmp(SYMBOL_NAME(sym), name)) | |
2157 | return sym; | |
2158 | bot++; | |
2159 | } | |
2160 | if (block = BLOCK_SUPERBLOCK (block)) | |
2161 | return mylookup_symbol (name, block, namespace, class); | |
2162 | return 0; | |
2163 | } | |
2164 | ||
2165 | ||
2166 | /* Add a new symbol S to a block B */ | |
2167 | ||
2168 | static | |
2169 | add_symbol(s,b) | |
2170 | struct symbol *s; | |
2171 | struct block *b; | |
2172 | { | |
2173 | BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s; | |
2174 | if (b == top_stack->cur_block && | |
2175 | BLOCK_NSYMS(b) > top_stack->maxsyms) | |
2176 | printf_filtered("Internal: block at @%x overfilled (by %d)\n", | |
2177 | b, BLOCK_NSYMS(b) - top_stack->maxsyms); | |
2178 | } | |
2179 | ||
2180 | /* Add a new block B to a symtab S */ | |
2181 | ||
2182 | static | |
2183 | add_block(b,s) | |
2184 | struct block *b; | |
2185 | struct symtab *s; | |
2186 | { | |
2187 | struct blockvector *bv = BLOCKVECTOR(s); | |
2188 | ||
2189 | bv = (struct blockvector *)xrealloc(bv, sizeof(struct blockvector) + | |
2190 | BLOCKVECTOR_NBLOCKS(bv) * sizeof(bv->block)); | |
2191 | if (bv != BLOCKVECTOR(s)) | |
2192 | BLOCKVECTOR(s) = bv; | |
2193 | ||
2194 | BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b; | |
2195 | } | |
2196 | ||
2197 | /* Add a new linenumber entry (LINENO,ADR) to a linevector LT. | |
2198 | MIPS' linenumber encoding might need more than one byte | |
2199 | to describe it, LAST is used to detect these continuation lines */ | |
2200 | ||
2201 | static | |
2202 | add_line(lt, lineno, adr, last) | |
2203 | struct linetable *lt; | |
2204 | CORE_ADDR adr; | |
2205 | { | |
2206 | if (last == 0) | |
2207 | last = -2; /* make sure we record first line */ | |
2208 | ||
2209 | if (last == lineno) /* skip continuation lines */ | |
2210 | return lineno; | |
2211 | ||
2212 | lt->item[lt->nitems].line = lineno; | |
2213 | lt->item[lt->nitems++].pc = adr << 2; | |
2214 | return lineno; | |
2215 | } | |
2216 | ||
2217 | ||
2218 | \f | |
2219 | /* Comparison functions, used when sorting things */ | |
2220 | ||
2221 | /* Symtabs must be ordered viz the code segments they cover */ | |
2222 | ||
2223 | static int | |
2224 | compare_symtabs( s1, s2) | |
2225 | struct symtab **s1, **s2; | |
2226 | { | |
2227 | /* "most specific" first */ | |
2228 | ||
2229 | register struct block *b1, *b2; | |
d219db01 JG |
2230 | b1 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1),GLOBAL_BLOCK); |
2231 | b2 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2),GLOBAL_BLOCK); | |
bd5635a1 RP |
2232 | if (BLOCK_END(b1) == BLOCK_END(b2)) |
2233 | return BLOCK_START(b1) - BLOCK_START(b2); | |
2234 | return BLOCK_END(b1) - BLOCK_END(b2); | |
2235 | } | |
2236 | ||
2237 | ||
2238 | /* Partial Symtabs, same */ | |
2239 | ||
2240 | static int | |
2241 | compare_psymtabs( s1, s2) | |
2242 | struct partial_symtab **s1, **s2; | |
2243 | { | |
2244 | /* Perf twist: put the ones with no code at the end */ | |
2245 | ||
2246 | register int a = (*s1)->textlow; | |
2247 | register int b = (*s2)->textlow; | |
2248 | if (a == 0) | |
2249 | return b; | |
2250 | if (b == 0) | |
2251 | return -a; | |
2252 | return a - b; | |
2253 | } | |
2254 | ||
2255 | ||
2256 | /* Partial symbols are compared lexicog by their print names */ | |
2257 | ||
2258 | static int | |
2259 | compare_psymbols (s1, s2) | |
2260 | register struct partial_symbol *s1, *s2; | |
2261 | { | |
2262 | register char | |
2263 | *st1 = SYMBOL_NAME(s1), | |
2264 | *st2 = SYMBOL_NAME(s2); | |
2265 | ||
2266 | return (st1[0] - st2[0] ? st1[0] - st2[0] : | |
2267 | strcmp(st1 + 1, st2 + 1)); | |
2268 | } | |
2269 | ||
2270 | /* Blocks with a smaller low bound should come first */ | |
2271 | ||
2272 | static int compare_blocks(b1,b2) | |
2273 | struct block **b1, **b2; | |
2274 | { | |
2275 | register int addr_diff; | |
2276 | ||
2277 | addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2))); | |
2278 | if (addr_diff == 0) | |
2279 | return (BLOCK_END((*b1))) - (BLOCK_END((*b2))); | |
2280 | return addr_diff; | |
2281 | } | |
2282 | ||
2283 | \f | |
2284 | /* Sorting and reordering procedures */ | |
2285 | ||
2286 | /* Sort the blocks of a symtab S. | |
2287 | Reorder the blocks in the blockvector by code-address, | |
2288 | as required by some MI search routines */ | |
2289 | ||
2290 | static | |
2291 | sort_blocks(s) | |
2292 | struct symtab *s; | |
2293 | { | |
2294 | struct blockvector *bv = BLOCKVECTOR(s); | |
2295 | ||
2296 | if (BLOCKVECTOR_NBLOCKS(bv) <= 2) { | |
2297 | /* Cosmetic */ | |
d219db01 JG |
2298 | if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0) |
2299 | BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0; | |
bd5635a1 RP |
2300 | return; |
2301 | } | |
2302 | /* | |
2303 | * This is very unfortunate: normally all functions are compiled in | |
2304 | * the order they are found, but if the file is compiled -O3 things | |
2305 | * are very different. It would be nice to find a reliable test | |
2306 | * to detect -O3 images in advance. | |
2307 | */ | |
2308 | if (BLOCKVECTOR_NBLOCKS(bv) > 3) | |
d219db01 JG |
2309 | qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK), |
2310 | BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK, | |
bd5635a1 RP |
2311 | sizeof(struct block *), |
2312 | compare_blocks); | |
2313 | ||
2314 | { | |
2315 | register CORE_ADDR high = 0; | |
2316 | register int i, j = BLOCKVECTOR_NBLOCKS(bv); | |
2317 | ||
d219db01 | 2318 | for (i = FIRST_LOCAL_BLOCK; i < j; i++) |
bd5635a1 RP |
2319 | if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i))) |
2320 | high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)); | |
d219db01 | 2321 | BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high; |
bd5635a1 RP |
2322 | } |
2323 | ||
d219db01 JG |
2324 | BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = |
2325 | BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK)); | |
bd5635a1 | 2326 | |
d219db01 JG |
2327 | BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = |
2328 | BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)); | |
2329 | BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = | |
2330 | BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)); | |
bd5635a1 RP |
2331 | } |
2332 | ||
2333 | /* Sort the symtab list, as required by some search procedures. | |
2334 | We want files ordered to make them look right to users, and for | |
2335 | searching (see block_for_pc). */ | |
2336 | ||
2337 | static | |
2338 | reorder_symtabs() | |
2339 | { | |
2340 | register int i; | |
2341 | struct symtab *stab; | |
2342 | struct symtab **all_symtabs = (struct symtab **) | |
2343 | obstack_alloc (psymbol_obstack, | |
2344 | all_symtabs_count * sizeof (struct symtab *)); | |
2345 | ||
2346 | /* Create an array of pointers to all the symtabs. */ | |
2347 | for (i = 0, stab = symtab_list; | |
2348 | i < all_symtabs_count; | |
2349 | i++, stab = stab->next) { | |
2350 | all_symtabs[i] = stab; | |
2351 | /* FIXME: Only do this for new symtabs ??? */ | |
2352 | sort_blocks(all_symtabs[i]); | |
2353 | } | |
2354 | ||
2355 | qsort(all_symtabs, all_symtabs_count, | |
2356 | sizeof(struct symtab *), compare_symtabs); | |
2357 | ||
2358 | /* Re-construct the symtab list, but now it is sorted. */ | |
2359 | for (i = 0; i < all_symtabs_count-1; i++) | |
2360 | all_symtabs[i]->next = all_symtabs[i+1]; | |
2361 | all_symtabs[i]->next = 0; | |
2362 | symtab_list = all_symtabs[0]; | |
2363 | obstack_free (psymbol_obstack, all_symtabs); | |
2364 | } | |
2365 | ||
2366 | /* Sort the partial symtab list, as required by some search procedures */ | |
2367 | ||
2368 | static reorder_psymtabs() | |
2369 | { | |
2370 | register int i; | |
2371 | struct partial_symtab *pstab; | |
2372 | ||
2373 | /* | |
2374 | * PC lookups stop at the first psymtab such that | |
2375 | * textlow <= PC < texthigh | |
2376 | */ | |
2377 | /* Create an array of pointers to all the partial_symtabs. */ | |
2378 | struct partial_symtab **all_psymtabs = (struct partial_symtab **) | |
2379 | obstack_alloc (psymbol_obstack, | |
2380 | all_psymtabs_count*sizeof(struct partial_symtab*)); | |
2381 | for (i = 0, pstab = partial_symtab_list; | |
2382 | i < all_psymtabs_count; | |
2383 | i++, pstab = pstab->next) | |
2384 | all_psymtabs[i] = pstab; | |
2385 | ||
2386 | qsort(all_psymtabs, all_psymtabs_count, | |
2387 | sizeof(struct partial_symtab *), compare_psymtabs); | |
2388 | ||
2389 | /* Re-construct the partial_symtab_list, but now it is sorted. */ | |
2390 | ||
2391 | for (i = 0; i < all_psymtabs_count-1; i++) | |
2392 | all_psymtabs[i]->next = all_psymtabs[i+1]; | |
2393 | all_psymtabs[i]->next = 0; | |
2394 | partial_symtab_list = all_psymtabs[0]; | |
2395 | ||
2396 | obstack_free (psymbol_obstack, all_psymtabs); | |
2397 | } | |
2398 | ||
2399 | ||
2400 | \f | |
2401 | /* Constructor/restructor/destructor procedures */ | |
2402 | ||
2403 | /* Allocate a new symtab for NAME. Needs an estimate of how many symbols | |
2404 | MAXSYMS and linenumbers MAXLINES we'll put in it */ | |
2405 | ||
2406 | static | |
2407 | struct symtab * | |
2408 | new_symtab(name, maxsyms, maxlines) | |
2409 | char *name; | |
2410 | { | |
2411 | struct symtab *s = (struct symtab *) xzalloc(sizeof(struct symtab)); | |
2412 | int i; | |
2413 | ||
2414 | LINETABLE(s) = new_linetable(maxlines); | |
2415 | ||
2416 | s->filename = name; | |
2417 | ||
2418 | /* All symtabs must have at least two blocks */ | |
2419 | BLOCKVECTOR(s) = new_bvect(2); | |
d219db01 JG |
2420 | BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms); |
2421 | BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms); | |
2422 | BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) = | |
2423 | BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK); | |
bd5635a1 RP |
2424 | |
2425 | s->free_code = free_linetable; | |
2426 | ||
2427 | /* Link the new symtab into the list of such. */ | |
2428 | s->next = symtab_list; | |
2429 | symtab_list = s; | |
2430 | ||
2431 | all_symtabs_count++; | |
2432 | ||
2433 | return s; | |
2434 | } | |
2435 | ||
2436 | /* Cleanup before loading a fresh image */ | |
2437 | ||
2438 | static destroy_all_symtabs() | |
2439 | { | |
2440 | if (symfile) | |
2441 | free(symfile); | |
2442 | symfile = 0; | |
2443 | ||
2444 | free_all_symtabs(); | |
2445 | all_symtabs_count = 0; | |
2446 | current_source_symtab = 0; | |
2447 | /* psymtabs! */ | |
2448 | } | |
2449 | ||
2450 | /* Allocate a new partial_symtab NAME */ | |
2451 | ||
2452 | static struct partial_symtab * | |
2453 | new_psymtab(name) | |
2454 | char *name; | |
2455 | { | |
2456 | struct partial_symtab *pst; | |
2457 | ||
2458 | pst = (struct partial_symtab *) | |
2459 | obstack_alloc (psymbol_obstack, sizeof (*pst)); | |
2460 | bzero (pst, sizeof (*pst)); | |
2461 | ||
2462 | if (name == (char*)-1) /* FIXME -- why not null here? */ | |
2463 | pst->filename = "<no name>"; | |
2464 | else | |
2465 | pst->filename = name; | |
2466 | ||
2467 | pst->next = partial_symtab_list; | |
2468 | partial_symtab_list = pst; | |
2469 | all_psymtabs_count++; | |
2470 | ||
2471 | /* Keep a backpointer to the file`s symbols */ | |
2472 | pst->ldsymlen = (int)cur_hdr; | |
2473 | ||
2474 | /* The way to turn this into a symtab is to call... */ | |
2475 | pst->read_symtab = mipscoff_psymtab_to_symtab; | |
2476 | ||
2477 | return pst; | |
2478 | } | |
2479 | ||
2480 | ||
2481 | /* Allocate a new NAME psymbol from LIST, extending it if necessary. | |
2482 | The psymbol belongs to the psymtab at index PST_IDX */ | |
2483 | ||
2484 | static struct partial_symbol * | |
2485 | new_psymbol(list, name, pst_idx) | |
2486 | struct psymbol_allocation_list *list; | |
2487 | char *name; | |
2488 | { | |
2489 | struct partial_symbol *p; | |
2490 | struct partial_symtab *pst = fdr_to_pst[pst_idx].pst; | |
2491 | ||
2492 | /* Lists are pre-sized, we won`t overflow */ | |
2493 | ||
2494 | p = list->list + pst->globals_offset + pst->n_global_syms++; | |
2495 | SYMBOL_NAME(p) = name; | |
2496 | return p; | |
2497 | } | |
2498 | ||
2499 | ||
2500 | /* Allocate a linetable array of the given SIZE */ | |
2501 | ||
2502 | static | |
2503 | struct linetable *new_linetable(size) | |
2504 | { | |
2505 | struct linetable *l; | |
2506 | ||
2507 | size = size * sizeof(l->item) + sizeof(struct linetable); | |
2508 | l = (struct linetable *)xmalloc(size); | |
2509 | l->nitems = 0; | |
2510 | return l; | |
2511 | } | |
2512 | ||
2513 | /* Oops, too big. Shrink it. This was important with the 2.4 linetables, | |
2514 | I am not so sure about the 3.4 ones */ | |
2515 | ||
2516 | static shrink_linetable(s) | |
2517 | struct symtab *s; | |
2518 | { | |
2519 | struct linetable *l = new_linetable(LINETABLE(s)->nitems); | |
2520 | ||
2521 | bcopy(LINETABLE(s), l, | |
2522 | LINETABLE(s)->nitems * sizeof(l->item) + sizeof(struct linetable)); | |
2523 | free (LINETABLE(s)); | |
2524 | LINETABLE(s) = l; | |
2525 | } | |
2526 | ||
2527 | /* Allocate and zero a new blockvector of NBLOCKS blocks. */ | |
2528 | ||
2529 | static | |
2530 | struct blockvector *new_bvect(nblocks) | |
2531 | { | |
2532 | struct blockvector *bv; | |
2533 | int size; | |
2534 | ||
2535 | size = sizeof(struct blockvector) + nblocks * sizeof(struct block*); | |
2536 | bv = (struct blockvector *) xzalloc(size); | |
2537 | ||
2538 | BLOCKVECTOR_NBLOCKS(bv) = nblocks; | |
2539 | ||
2540 | return bv; | |
2541 | } | |
2542 | ||
2543 | /* Allocate and zero a new block of MAXSYMS symbols */ | |
2544 | ||
2545 | static | |
2546 | struct block *new_block(maxsyms) | |
2547 | { | |
2548 | int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *); | |
2549 | struct block *b = (struct block *)xzalloc(size); | |
2550 | ||
2551 | return b; | |
2552 | } | |
2553 | ||
2554 | /* Ooops, too big. Shrink block B in symtab S to its minimal size */ | |
2555 | ||
2556 | static struct block * | |
2557 | shrink_block(b, s) | |
2558 | struct block *b; | |
2559 | struct symtab *s; | |
2560 | { | |
2561 | struct block *new; | |
2562 | struct blockvector *bv = BLOCKVECTOR(s); | |
2563 | int i; | |
2564 | ||
2565 | /* Just get a new one, copy, and fix references to the old one */ | |
2566 | ||
2567 | new = (struct block *)xmalloc(sizeof(struct block) + | |
2568 | (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *)); | |
2569 | ||
2570 | bcopy(b, new, sizeof(*new) + (BLOCK_NSYMS(b) - 1) * sizeof(struct symbol*)); | |
2571 | ||
2572 | /* Should chase pointers to old one. Fortunately, that`s just | |
2573 | the block`s function and inferior blocks */ | |
2574 | if (BLOCK_FUNCTION(b) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b)) == b) | |
2575 | SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b)) = new; | |
2576 | for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) | |
2577 | if (BLOCKVECTOR_BLOCK(bv,i) == b) | |
2578 | BLOCKVECTOR_BLOCK(bv,i) = new; | |
2579 | else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b) | |
2580 | BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new; | |
2581 | free(b); | |
2582 | return new; | |
2583 | } | |
2584 | ||
2585 | /* Create a new symbol with printname NAME */ | |
2586 | ||
2587 | static | |
2588 | struct symbol * | |
2589 | new_symbol(name) | |
2590 | char *name; | |
2591 | { | |
2592 | struct symbol *s = (struct symbol *) | |
2593 | obstack_alloc (symbol_obstack, sizeof (struct symbol)); | |
2594 | ||
2595 | bzero (s, sizeof (*s)); | |
2596 | SYMBOL_NAME(s) = name; | |
2597 | return s; | |
2598 | } | |
2599 | ||
2600 | /* Create a new type with printname NAME */ | |
2601 | ||
2602 | static | |
2603 | struct type * | |
2604 | new_type(name) | |
2605 | char *name; | |
2606 | { | |
2607 | struct type *t = (struct type *) | |
2608 | obstack_alloc (symbol_obstack, sizeof (struct type)); | |
2609 | ||
2610 | bzero (t, sizeof (*t)); | |
2611 | TYPE_NAME(t) = name; | |
2612 | return t; | |
2613 | } | |
2614 | ||
2615 | /* Create and initialize a new type with printname NAME. | |
2616 | CODE and LENGTH are the initial info we put in, | |
2617 | UNS says whether the type is unsigned or not. */ | |
2618 | ||
2619 | static | |
2620 | struct type * | |
2621 | make_type(code, length, uns, name) | |
2622 | enum type_code code; | |
2623 | int length, uns; | |
2624 | char *name; | |
2625 | { | |
2626 | register struct type *type; | |
2627 | ||
2628 | type = (struct type *) xzalloc(sizeof(struct type)); | |
2629 | TYPE_CODE(type) = code; | |
2630 | TYPE_LENGTH(type) = length; | |
2631 | TYPE_FLAGS(type) = uns ? TYPE_FLAG_UNSIGNED : 0; | |
2632 | TYPE_NAME(type) = name; | |
2633 | ||
2634 | return type; | |
2635 | } | |
2636 | ||
2637 | /* Allocate a new field named NAME to the type TYPE */ | |
2638 | ||
2639 | static | |
2640 | struct field *new_field(type,name) | |
2641 | struct type *type; | |
2642 | char *name; | |
2643 | { | |
2644 | struct field *f; | |
2645 | ||
2646 | /* Fields are kept in an array */ | |
2647 | if (TYPE_NFIELDS(type)) | |
2648 | TYPE_FIELDS(type) = (struct field*)xrealloc(TYPE_FIELDS(type), | |
2649 | (TYPE_NFIELDS(type)+1) * sizeof(struct field)); | |
2650 | else | |
2651 | TYPE_FIELDS(type) = (struct field*)xzalloc(2*sizeof(struct field)); | |
2652 | f = &(TYPE_FIELD(type,TYPE_NFIELDS(type)++)); | |
2653 | bzero(f, sizeof(struct field)); | |
2654 | if (name) | |
2655 | f->name = name; | |
2656 | return f; | |
2657 | } | |
2658 | ||
2659 | /* Make an enum constant for a member F of an enumerated type T */ | |
2660 | ||
2661 | static | |
2662 | make_enum_constant(f,t) | |
2663 | struct field *f; | |
2664 | struct type *t; | |
2665 | { | |
2666 | struct symbol *s; | |
2667 | /* | |
2668 | * This is awful, but that`s the way it is supposed to be | |
2669 | * (BTW, no need to free the real 'type', it's a builtin) | |
2670 | */ | |
2671 | f->type = (struct type *) f->bitpos; | |
2672 | ||
2673 | s = new_symbol(f->name); | |
2674 | SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; | |
2675 | SYMBOL_CLASS(s) = LOC_CONST; | |
2676 | SYMBOL_TYPE(s) = t; | |
2677 | SYMBOL_VALUE(s) = f->bitpos; | |
2678 | add_symbol(s, top_stack->cur_block); | |
2679 | } | |
2680 | ||
2681 | ||
2682 | \f | |
2683 | /* Things used for calling functions in the inferior. | |
2684 | These functions are exported to our companion | |
2685 | mips-dep.c file and are here because they play | |
2686 | with the symbol-table explicitly. */ | |
2687 | ||
2688 | #if 0 | |
2689 | /* Need to make a new symbol on the fly for the dummy | |
2690 | frame we put on the stack. Which goes in the.. */ | |
2691 | ||
2692 | static struct symtab *dummy_symtab; | |
2693 | ||
2694 | /* Make up a dummy symbol for the code we put at END_PC, | |
2695 | of size SIZE, invoking a function with NARGS arguments | |
2696 | and using a frame of FRAMESIZE bytes */ | |
2697 | ||
2698 | mips_create_dummy_symbol(end_pc, size, nargs, framesize) | |
2699 | { | |
2700 | struct block *bl; | |
2701 | struct symbol *g; | |
2702 | struct mips_extra_func_info *gdbinfo; | |
2703 | ||
2704 | /* Allocate symtab if not done already */ | |
2705 | if (dummy_symtab == 0) | |
2706 | dummy_symtab = new_symtab(".dummy_symtab.", 100, 0); | |
2707 | ||
2708 | /* Make a new block. Only needs one symbol */ | |
2709 | bl = new_block(1); | |
2710 | BLOCK_START(bl) = end_pc - size; | |
2711 | BLOCK_END(bl) = end_pc; | |
2712 | ||
d219db01 JG |
2713 | BLOCK_SUPERBLOCK(bl) = |
2714 | BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab),GLOBAL_BLOCK); | |
bd5635a1 RP |
2715 | add_block(bl, dummy_symtab); |
2716 | sort_blocks(dummy_symtab); | |
2717 | ||
2718 | BLOCK_FUNCTION(bl) = new_symbol("??"); | |
2719 | SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl)) = bl; | |
2720 | g = new_symbol(".gdbinfo."); | |
2721 | BLOCK_SYM(bl,BLOCK_NSYMS(bl)++) = g; | |
2722 | ||
2723 | SYMBOL_NAMESPACE(g) = LABEL_NAMESPACE; | |
2724 | SYMBOL_CLASS(g) = LOC_CONST; | |
2725 | SYMBOL_TYPE(g) = builtin_type_void; | |
2726 | gdbinfo = (struct mips_extra_func_info *) | |
2727 | xzalloc(sizeof(struct mips_extra_func_info)); | |
2728 | ||
2729 | SYMBOL_VALUE(g) = (long) gdbinfo; | |
2730 | ||
2731 | gdbinfo->numargs = nargs; | |
2732 | gdbinfo->framesize = framesize; | |
2733 | gdbinfo->framereg = 29; | |
2734 | gdbinfo->pcreg = 31; | |
2735 | gdbinfo->regmask = -2; | |
2736 | gdbinfo->regoffset = -4; | |
2737 | gdbinfo->fregmask = 0; /* XXX */ | |
2738 | gdbinfo->fregoffset = 0; /* XXX */ | |
2739 | } | |
2740 | ||
2741 | /* We just returned from the dummy code at END_PC, drop its symbol */ | |
2742 | ||
2743 | mips_destroy_dummy_symbol(end_pc) | |
2744 | { | |
2745 | struct block *bl; | |
2746 | struct blockvector *bv = BLOCKVECTOR(dummy_symtab); | |
2747 | int i; | |
2748 | ||
2749 | bl = block_for_pc(end_pc); | |
2750 | free(BLOCK_FUNCTION(bl)); | |
2751 | free(SYMBOL_VALUE(BLOCK_SYM(bl,0))); | |
2752 | free(BLOCK_SYM(bl,0)); | |
2753 | ||
d219db01 | 2754 | for (i = FIRST_LOCAL_BLOCK; i < BLOCKVECTOR_NBLOCKS(bv); i++) |
bd5635a1 RP |
2755 | if (BLOCKVECTOR_BLOCK(bv,i) == bl) |
2756 | break; | |
2757 | for (; i < BLOCKVECTOR_NBLOCKS(bv) - 1; i++) | |
2758 | BLOCKVECTOR_BLOCK(bv,i) = BLOCKVECTOR_BLOCK(bv,i+1); | |
2759 | BLOCKVECTOR_NBLOCKS(bv)--; | |
2760 | sort_blocks(dummy_symtab); | |
2761 | free(bl); | |
2762 | } | |
2763 | #endif | |
2764 | ||
2765 | /* Sigtramp: make sure we have all the necessary information | |
2766 | about the signal trampoline code. Since the official code | |
2767 | from MIPS does not do so, we make up that information ourselves. | |
2768 | If they fix the library (unlikely) this code will neutralize itself. */ | |
2769 | ||
2770 | static | |
2771 | fixup_sigtramp() | |
2772 | { | |
2773 | struct symbol *s; | |
2774 | struct symtab *st; | |
2775 | struct block *b, *b0; | |
2776 | ||
2777 | sigtramp_address = -1; | |
2778 | ||
2779 | /* We know it is sold as sigvec */ | |
2780 | s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL); | |
2781 | ||
2782 | /* Most programs do not play with signals */ | |
2783 | if (s == 0) | |
2784 | return; | |
2785 | ||
2786 | b0 = SYMBOL_BLOCK_VALUE(s); | |
2787 | ||
2788 | /* A label of sigvec, to be more precise */ | |
2789 | s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL); | |
2790 | ||
2791 | /* But maybe this program uses its own version of sigvec */ | |
2792 | if (s == 0) | |
2793 | return; | |
2794 | ||
2795 | sigtramp_address = SYMBOL_VALUE(s); | |
2796 | sigtramp_end = sigtramp_address + 0x88; /* black magic */ | |
2797 | ||
2798 | /* Did we or MIPSco fix the library ? */ | |
2799 | if (SYMBOL_CLASS(s) == LOC_BLOCK) | |
2800 | return; | |
2801 | ||
2802 | /* But what symtab does it live in ? */ | |
2803 | st = find_pc_symtab(SYMBOL_VALUE(s)); | |
2804 | ||
2805 | /* | |
2806 | * Ok, there goes the fix: turn it into a procedure, with all the | |
2807 | * needed info. Note we make it a nested procedure of sigvec, | |
2808 | * which is the way the (assembly) code is actually written. | |
2809 | */ | |
2810 | SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; | |
2811 | SYMBOL_CLASS(s) = LOC_BLOCK; | |
2812 | SYMBOL_TYPE(s) = make_type(TYPE_CODE_FUNC, 4, 0, 0); | |
2813 | TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void; | |
2814 | ||
2815 | /* Need a block to allocate .gdbinfo. in */ | |
2816 | b = new_block(1); | |
2817 | SYMBOL_BLOCK_VALUE(s) = b; | |
2818 | BLOCK_START(b) = sigtramp_address; | |
2819 | BLOCK_END(b) = sigtramp_end; | |
2820 | BLOCK_FUNCTION(b) = s; | |
2821 | BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0); | |
2822 | add_block(b, st); | |
2823 | sort_blocks(st); | |
2824 | ||
2825 | /* Make a .gdbinfo. for it */ | |
2826 | { | |
2827 | struct mips_extra_func_info *e = | |
2828 | (struct mips_extra_func_info *) | |
2829 | xzalloc(sizeof(struct mips_extra_func_info)); | |
2830 | ||
2831 | e->numargs = 0; /* the kernel thinks otherwise */ | |
2832 | /* align_longword(sigcontext + SIGFRAME) */ | |
2833 | e->framesize = 0x150; | |
2834 | e->framereg = SP_REGNUM; | |
2835 | e->pcreg = 31; | |
2836 | e->regmask = -2; | |
2837 | e->regoffset = -(41 * sizeof(int)); | |
2838 | e->fregmask = -1; | |
2839 | e->fregoffset = -(37 * sizeof(int)); | |
2840 | e->isym = (long)s; | |
2841 | ||
2842 | s = new_symbol(".gdbinfo."); | |
2843 | SYMBOL_VALUE(s) = (int) e; | |
2844 | SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE; | |
2845 | SYMBOL_CLASS(s) = LOC_CONST; | |
2846 | SYMBOL_TYPE(s) = builtin_type_void; | |
2847 | } | |
2848 | ||
2849 | BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s; | |
2850 | } | |
2851 | ||
2852 | \f | |
2853 | /* Initialization */ | |
2854 | ||
2855 | static struct sym_fns ecoff_sym_fns = {"ecoff", 5, | |
2856 | mipscoff_new_init, mipscoff_symfile_init, | |
2857 | mipscoff_symfile_read, mipscoff_symfile_discard}; | |
2858 | ||
2859 | _initialize_mipsread () | |
2860 | { | |
2861 | add_symtab_fns (&ecoff_sym_fns); | |
2862 | ||
2863 | bzero (&global_psymbols, sizeof (global_psymbols)); | |
2864 | bzero (&static_psymbols, sizeof (static_psymbols)); | |
2865 | ||
2866 | add_com("add-file", class_files, add_file_command, | |
2867 | "Add a new symbol table (in mips format) from file FILE."); | |
2868 | ||
2869 | /* Missing basic types */ | |
2870 | builtin_type_string = make_type(TYPE_CODE_PASCAL_ARRAY, | |
2871 | 1, 0, "string"); | |
2872 | builtin_type_complex = make_type(TYPE_CODE_FLT, | |
2873 | 2 * sizeof(float), 0, "complex"); | |
2874 | builtin_type_double_complex = make_type(TYPE_CODE_FLT, | |
2875 | 2 * sizeof(double), 0, "double_complex"); | |
2876 | builtin_type_fixed_dec = make_type(TYPE_CODE_INT, sizeof(int), | |
2877 | 0, "fixed_decimal"); | |
2878 | builtin_type_float_dec = make_type(TYPE_CODE_FLT, sizeof(double), | |
2879 | 0, "floating_decimal"); | |
2880 | ||
2881 | /* Templates types */ | |
2882 | builtin_type_ptr = lookup_pointer_type (builtin_type_void); | |
2883 | builtin_type_struct = make_type(TYPE_CODE_STRUCT, 0, 0, 0); | |
2884 | builtin_type_union = make_type(TYPE_CODE_UNION, 0, 0, 0); | |
2885 | builtin_type_enum = make_type(TYPE_CODE_ENUM, 0, 0, 0); | |
2886 | builtin_type_range = make_type(TYPE_CODE_RANGE, 0, 0, 0); | |
2887 | builtin_type_set = make_type(TYPE_CODE_SET, 0, 0, 0); | |
2888 | } |