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