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