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