Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Read coff symbol tables and convert to internal format, for GDB. |
d8ce1326 | 2 | Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu). |
f2c365f5 JK |
3 | Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1993 |
4 | Free Software Foundation, Inc. | |
bd5635a1 RP |
5 | |
6 | This file is part of GDB. | |
7 | ||
99a7de40 | 8 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 9 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | |
bd5635a1 | 12 | |
99a7de40 | 13 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
f2c365f5 | 21 | |
bd5635a1 | 22 | #include "defs.h" |
bd5635a1 | 23 | #include "symtab.h" |
318bf84f | 24 | #include "gdbtypes.h" |
bd5635a1 RP |
25 | #include "breakpoint.h" |
26 | #include "bfd.h" | |
bd5635a1 | 27 | #include "symfile.h" |
3624c875 | 28 | #include "objfiles.h" |
318bf84f | 29 | #include "buildsym.h" |
51b80b00 | 30 | #include "complaints.h" |
bd5635a1 | 31 | #include <obstack.h> |
318bf84f | 32 | |
bd5635a1 RP |
33 | #include <string.h> |
34 | ||
de9bef49 | 35 | #include "libbfd.h" /* FIXME secret internal data from BFD */ |
f5f0679a | 36 | #include "coff/internal.h" /* Internal format of COFF symbols in BFD */ |
63989338 JG |
37 | #include "libcoff.h" /* FIXME secret internal data from BFD */ |
38 | ||
de9bef49 JG |
39 | /* Translate an external name string into a user-visible name. */ |
40 | #define EXTERNAL_NAME(string, abfd) \ | |
41 | (string[0] == bfd_get_symbol_leading_char(abfd)? string+1: string) | |
42 | ||
8714ff35 JK |
43 | /* To be an sdb debug type, type must have at least a basic or primary |
44 | derived type. Using this rather than checking against T_NULL is | |
ab8f22a9 JK |
45 | said to prevent core dumps if we try to operate on Michael Bloom |
46 | dbx-in-coff file. */ | |
8714ff35 JK |
47 | |
48 | #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK)) | |
49 | ||
d8ce1326 JG |
50 | /* |
51 | * Convert from an sdb register number to an internal gdb register number. | |
52 | * This should be defined in tm.h, if REGISTER_NAMES is not set up | |
53 | * to map one to one onto the sdb register numbers. | |
54 | */ | |
55 | #ifndef SDB_REG_TO_REGNUM | |
56 | # define SDB_REG_TO_REGNUM(value) (value) | |
57 | #endif | |
58 | ||
bd5635a1 RP |
59 | /* Core address of start and end of text of current source file. |
60 | This comes from a ".text" symbol where x_nlinno > 0. */ | |
61 | ||
62 | static CORE_ADDR cur_src_start_addr; | |
63 | static CORE_ADDR cur_src_end_addr; | |
64 | ||
65 | /* Core address of the end of the first object file. */ | |
66 | static CORE_ADDR first_object_file_end; | |
67 | ||
bd5635a1 RP |
68 | /* The addresses of the symbol table stream and number of symbols |
69 | of the object file we are reading (as copied into core). */ | |
70 | ||
71 | static FILE *nlist_stream_global; | |
72 | static int nlist_nsyms_global; | |
73 | ||
bd5635a1 RP |
74 | /* Vector of line number information. */ |
75 | ||
76 | static struct linetable *line_vector; | |
77 | ||
78 | /* Index of next entry to go in line_vector_index. */ | |
79 | ||
80 | static int line_vector_index; | |
81 | ||
82 | /* Last line number recorded in the line vector. */ | |
83 | ||
84 | static int prev_line_number; | |
85 | ||
86 | /* Number of elements allocated for line_vector currently. */ | |
87 | ||
88 | static int line_vector_length; | |
89 | ||
d8ce1326 JG |
90 | /* Pointers to scratch storage, used for reading raw symbols and auxents. */ |
91 | ||
92 | static char *temp_sym; | |
93 | static char *temp_aux; | |
94 | ||
95 | /* Local variables that hold the shift and mask values for the | |
96 | COFF file that we are currently reading. These come back to us | |
97 | from BFD, and are referenced by their macro names, as well as | |
98 | internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF | |
99 | macros from ../internalcoff.h . */ | |
100 | ||
101 | static unsigned local_n_btmask; | |
102 | static unsigned local_n_btshft; | |
103 | static unsigned local_n_tmask; | |
104 | static unsigned local_n_tshift; | |
105 | ||
106 | #define N_BTMASK local_n_btmask | |
107 | #define N_BTSHFT local_n_btshft | |
108 | #define N_TMASK local_n_tmask | |
109 | #define N_TSHIFT local_n_tshift | |
110 | ||
111 | /* Local variables that hold the sizes in the file of various COFF structures. | |
112 | (We only need to know this to read them from the file -- BFD will then | |
113 | translate the data in them, into `internal_xxx' structs in the right | |
114 | byte order, alignment, etc.) */ | |
115 | ||
116 | static unsigned local_linesz; | |
117 | static unsigned local_symesz; | |
118 | static unsigned local_auxesz; | |
119 | ||
120 | ||
bd5635a1 RP |
121 | /* Chain of typedefs of pointers to empty struct/union types. |
122 | They are chained thru the SYMBOL_VALUE_CHAIN. */ | |
123 | ||
bd5635a1 RP |
124 | static struct symbol *opaque_type_chain[HASHSIZE]; |
125 | ||
126 | /* Record the symbols defined for each context in a list. | |
127 | We don't create a struct block for the context until we | |
128 | know how long to make it. */ | |
129 | ||
318bf84f | 130 | struct coff_pending |
bd5635a1 | 131 | { |
318bf84f | 132 | struct coff_pending *next; |
bd5635a1 RP |
133 | struct symbol *symbol; |
134 | }; | |
135 | ||
136 | /* Here are the three lists that symbols are put on. */ | |
137 | ||
318bf84f | 138 | struct coff_pending *coff_file_symbols; /* static at top level, and types */ |
bd5635a1 | 139 | |
85f0a848 | 140 | struct coff_pending *coff_global_symbols; /* global functions and variables */ |
bd5635a1 | 141 | |
85f0a848 | 142 | struct coff_pending *coff_local_symbols; /* everything local to lexical context */ |
bd5635a1 RP |
143 | |
144 | /* List of unclosed lexical contexts | |
145 | (that will become blocks, eventually). */ | |
146 | ||
318bf84f | 147 | struct coff_context_stack |
bd5635a1 | 148 | { |
318bf84f FF |
149 | struct coff_context_stack *next; |
150 | struct coff_pending *locals; | |
bd5635a1 RP |
151 | struct pending_block *old_blocks; |
152 | struct symbol *name; | |
153 | CORE_ADDR start_addr; | |
154 | int depth; | |
155 | }; | |
156 | ||
318bf84f | 157 | struct coff_context_stack *coff_context_stack; |
bd5635a1 RP |
158 | |
159 | /* Nonzero if within a function (so symbols should be local, | |
160 | if nothing says specifically). */ | |
161 | ||
162 | int within_function; | |
163 | ||
d8ce1326 JG |
164 | #if 0 |
165 | /* The type of the function we are currently reading in. This is | |
166 | used by define_symbol to record the type of arguments to a function. */ | |
167 | ||
168 | struct type *in_function_type; | |
169 | #endif | |
170 | ||
bd5635a1 RP |
171 | struct pending_block *pending_blocks; |
172 | ||
bd5635a1 RP |
173 | /* Complaints about various problems in the file being read */ |
174 | ||
175 | struct complaint ef_complaint = | |
176 | {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0}; | |
177 | ||
7e258d18 PB |
178 | struct complaint bf_no_aux_complaint = |
179 | {"`.bf' symbol %d has no aux entry", 0, 0}; | |
180 | ||
181 | struct complaint ef_no_aux_complaint = | |
182 | {"`.ef' symbol %d has no aux entry", 0, 0}; | |
e64fbb3a | 183 | |
63989338 JG |
184 | struct complaint lineno_complaint = |
185 | {"Line number pointer %d lower than start of line numbers", 0, 0}; | |
186 | ||
7e258d18 PB |
187 | struct complaint unexpected_type_complaint = |
188 | {"Unexpected type for symbol %s", 0, 0}; | |
189 | ||
190 | struct complaint bad_sclass_complaint = | |
191 | {"Bad n_sclass for symbol %s", 0, 0}; | |
318bf84f | 192 | |
f70be3e4 JG |
193 | struct complaint misordered_blocks_complaint = |
194 | {"Blocks out of order at address %x", 0, 0}; | |
195 | ||
196 | struct complaint tagndx_bad_complaint = | |
197 | {"Symbol table entry for %s has bad tagndx value", 0, 0}; | |
198 | ||
de9bef49 JG |
199 | struct complaint eb_complaint = |
200 | {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0}; | |
201 | ||
318bf84f FF |
202 | /* Simplified internal version of coff symbol table information */ |
203 | ||
204 | struct coff_symbol { | |
205 | char *c_name; | |
206 | int c_symnum; /* symbol number of this entry */ | |
207 | int c_naux; /* 0 if syment only, 1 if syment + auxent, etc */ | |
208 | long c_value; | |
209 | int c_sclass; | |
210 | int c_secnum; | |
211 | unsigned int c_type; | |
212 | }; | |
213 | ||
214 | static struct type * | |
215 | coff_read_struct_type PARAMS ((int, int, int)); | |
216 | ||
217 | static struct type * | |
218 | decode_base_type PARAMS ((struct coff_symbol *, unsigned int, | |
219 | union internal_auxent *)); | |
220 | ||
221 | static struct type * | |
222 | decode_type PARAMS ((struct coff_symbol *, unsigned int, | |
223 | union internal_auxent *)); | |
224 | ||
225 | static struct type * | |
226 | decode_function_type PARAMS ((struct coff_symbol *, unsigned int, | |
227 | union internal_auxent *)); | |
228 | ||
229 | static struct type * | |
230 | coff_read_enum_type PARAMS ((int, int, int)); | |
231 | ||
232 | static struct blockvector * | |
233 | make_blockvector PARAMS ((struct objfile *)); | |
234 | ||
235 | static struct symbol * | |
236 | process_coff_symbol PARAMS ((struct coff_symbol *, union internal_auxent *, | |
237 | struct objfile *)); | |
238 | ||
f70be3e4 JG |
239 | static void |
240 | patch_opaque_types PARAMS ((struct symtab *)); | |
318bf84f FF |
241 | |
242 | static void | |
243 | patch_type PARAMS ((struct type *, struct type *)); | |
244 | ||
245 | static void | |
246 | enter_linenos PARAMS ((long, int, int)); | |
247 | ||
e09c5e26 JK |
248 | static void |
249 | free_linetab PARAMS ((void)); | |
250 | ||
318bf84f FF |
251 | static int |
252 | init_lineno PARAMS ((int, long, int)); | |
253 | ||
254 | static char * | |
255 | getfilename PARAMS ((union internal_auxent *)); | |
256 | ||
257 | static char * | |
258 | getsymname PARAMS ((struct internal_syment *)); | |
259 | ||
260 | static void | |
261 | free_stringtab PARAMS ((void)); | |
262 | ||
263 | static int | |
264 | init_stringtab PARAMS ((int, long)); | |
265 | ||
266 | static void | |
267 | read_one_sym PARAMS ((struct coff_symbol *, struct internal_syment *, | |
268 | union internal_auxent *)); | |
269 | ||
270 | static void | |
f70be3e4 | 271 | read_coff_symtab PARAMS ((long, int, struct objfile *)); |
318bf84f FF |
272 | |
273 | static void | |
80d68b1d | 274 | find_linenos PARAMS ((bfd *, sec_ptr, PTR)); |
318bf84f FF |
275 | |
276 | static void | |
80d68b1d | 277 | coff_symfile_init PARAMS ((struct objfile *)); |
318bf84f FF |
278 | |
279 | static void | |
80d68b1d | 280 | coff_new_init PARAMS ((struct objfile *)); |
318bf84f FF |
281 | |
282 | static void | |
85f0a848 | 283 | coff_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int)); |
80d68b1d FF |
284 | |
285 | static void | |
286 | coff_symfile_finish PARAMS ((struct objfile *)); | |
318bf84f FF |
287 | |
288 | static void | |
f70be3e4 | 289 | record_minimal_symbol PARAMS ((char *, CORE_ADDR, enum minimal_symbol_type)); |
318bf84f FF |
290 | |
291 | static void | |
292 | coff_end_symtab PARAMS ((struct objfile *)); | |
293 | ||
294 | static void | |
295 | complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int)); | |
296 | ||
297 | static void | |
298 | coff_start_symtab PARAMS ((void)); | |
299 | ||
300 | static void | |
301 | coff_record_line PARAMS ((int, CORE_ADDR)); | |
302 | ||
303 | static void | |
304 | coff_finish_block PARAMS ((struct symbol *, struct coff_pending **, | |
305 | struct pending_block *, CORE_ADDR, CORE_ADDR, | |
306 | struct objfile *)); | |
307 | ||
308 | static void | |
309 | coff_add_symbol_to_list PARAMS ((struct symbol *, struct coff_pending **)); | |
310 | ||
311 | static struct type * | |
312 | coff_alloc_type PARAMS ((int)); | |
313 | ||
314 | static struct type ** | |
315 | coff_lookup_type PARAMS ((int)); | |
316 | ||
bd5635a1 RP |
317 | \f |
318 | /* Look up a coff type-number index. Return the address of the slot | |
319 | where the type for that index is stored. | |
320 | The type-number is in INDEX. | |
321 | ||
322 | This can be used for finding the type associated with that index | |
323 | or for associating a new type with the index. */ | |
324 | ||
325 | static struct type ** | |
326 | coff_lookup_type (index) | |
327 | register int index; | |
328 | { | |
329 | if (index >= type_vector_length) | |
330 | { | |
331 | int old_vector_length = type_vector_length; | |
332 | ||
333 | type_vector_length *= 2; | |
f2c365f5 | 334 | if (index /* is still */ >= type_vector_length) { |
bd5635a1 RP |
335 | type_vector_length = index * 2; |
336 | } | |
159a075e | 337 | type_vector = (struct type **) |
318bf84f FF |
338 | xrealloc ((char *) type_vector, |
339 | type_vector_length * sizeof (struct type *)); | |
4ed3a9ea | 340 | memset (&type_vector[old_vector_length], 0, |
bd5635a1 RP |
341 | (type_vector_length - old_vector_length) * sizeof(struct type *)); |
342 | } | |
159a075e | 343 | return &type_vector[index]; |
bd5635a1 RP |
344 | } |
345 | ||
346 | /* Make sure there is a type allocated for type number index | |
347 | and return the type object. | |
348 | This can create an empty (zeroed) type object. */ | |
349 | ||
350 | static struct type * | |
351 | coff_alloc_type (index) | |
352 | int index; | |
353 | { | |
354 | register struct type **type_addr = coff_lookup_type (index); | |
355 | register struct type *type = *type_addr; | |
356 | ||
357 | /* If we are referring to a type not known at all yet, | |
358 | allocate an empty type for it. | |
359 | We will fill it in later if we find out how. */ | |
318bf84f | 360 | if (type == NULL) |
bd5635a1 | 361 | { |
318bf84f | 362 | type = alloc_type (current_objfile); |
bd5635a1 RP |
363 | *type_addr = type; |
364 | } | |
365 | return type; | |
366 | } | |
367 | \f | |
368 | /* maintain the lists of symbols and blocks */ | |
369 | ||
370 | /* Add a symbol to one of the lists of symbols. */ | |
371 | static void | |
318bf84f | 372 | coff_add_symbol_to_list (symbol, listhead) |
bd5635a1 | 373 | struct symbol *symbol; |
318bf84f | 374 | struct coff_pending **listhead; |
bd5635a1 | 375 | { |
318bf84f FF |
376 | register struct coff_pending *link |
377 | = (struct coff_pending *) xmalloc (sizeof (struct coff_pending)); | |
bd5635a1 RP |
378 | |
379 | link->next = *listhead; | |
380 | link->symbol = symbol; | |
381 | *listhead = link; | |
382 | } | |
383 | ||
384 | /* Take one of the lists of symbols and make a block from it. | |
385 | Put the block on the list of pending blocks. */ | |
386 | ||
387 | static void | |
318bf84f | 388 | coff_finish_block (symbol, listhead, old_blocks, start, end, objfile) |
bd5635a1 | 389 | struct symbol *symbol; |
318bf84f | 390 | struct coff_pending **listhead; |
bd5635a1 RP |
391 | struct pending_block *old_blocks; |
392 | CORE_ADDR start, end; | |
318bf84f | 393 | struct objfile *objfile; |
bd5635a1 | 394 | { |
318bf84f | 395 | register struct coff_pending *next, *next1; |
bd5635a1 RP |
396 | register struct block *block; |
397 | register struct pending_block *pblock; | |
398 | struct pending_block *opblock; | |
399 | register int i; | |
400 | ||
401 | /* Count the length of the list of symbols. */ | |
402 | ||
403 | for (next = *listhead, i = 0; next; next = next->next, i++); | |
404 | ||
405 | block = (struct block *) | |
318bf84f | 406 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct block) + (i - 1) * sizeof (struct symbol *)); |
bd5635a1 RP |
407 | |
408 | /* Copy the symbols into the block. */ | |
409 | ||
410 | BLOCK_NSYMS (block) = i; | |
411 | for (next = *listhead; next; next = next->next) | |
412 | BLOCK_SYM (block, --i) = next->symbol; | |
413 | ||
414 | BLOCK_START (block) = start; | |
415 | BLOCK_END (block) = end; | |
416 | BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */ | |
417 | ||
418 | /* Put the block in as the value of the symbol that names it. */ | |
419 | ||
420 | if (symbol) | |
421 | { | |
422 | SYMBOL_BLOCK_VALUE (symbol) = block; | |
423 | BLOCK_FUNCTION (block) = symbol; | |
424 | } | |
425 | else | |
426 | BLOCK_FUNCTION (block) = 0; | |
427 | ||
428 | /* Now free the links of the list, and empty the list. */ | |
429 | ||
430 | for (next = *listhead; next; next = next1) | |
431 | { | |
432 | next1 = next->next; | |
f70be3e4 | 433 | free ((PTR)next); |
bd5635a1 RP |
434 | } |
435 | *listhead = 0; | |
436 | ||
437 | /* Install this block as the superblock | |
438 | of all blocks made since the start of this scope | |
439 | that don't have superblocks yet. */ | |
440 | ||
441 | opblock = 0; | |
442 | for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next) | |
443 | { | |
444 | if (BLOCK_SUPERBLOCK (pblock->block) == 0) | |
445 | BLOCK_SUPERBLOCK (pblock->block) = block; | |
446 | opblock = pblock; | |
447 | } | |
448 | ||
449 | /* Record this block on the list of all blocks in the file. | |
450 | Put it after opblock, or at the beginning if opblock is 0. | |
451 | This puts the block in the list after all its subblocks. */ | |
452 | ||
453 | pblock = (struct pending_block *) xmalloc (sizeof (struct pending_block)); | |
454 | pblock->block = block; | |
455 | if (opblock) | |
456 | { | |
457 | pblock->next = opblock->next; | |
458 | opblock->next = pblock; | |
459 | } | |
460 | else | |
461 | { | |
462 | pblock->next = pending_blocks; | |
463 | pending_blocks = pblock; | |
464 | } | |
465 | } | |
466 | ||
467 | static struct blockvector * | |
318bf84f FF |
468 | make_blockvector (objfile) |
469 | struct objfile *objfile; | |
bd5635a1 RP |
470 | { |
471 | register struct pending_block *next, *next1; | |
472 | register struct blockvector *blockvector; | |
473 | register int i; | |
474 | ||
475 | /* Count the length of the list of blocks. */ | |
476 | ||
477 | for (next = pending_blocks, i = 0; next; next = next->next, i++); | |
478 | ||
479 | blockvector = (struct blockvector *) | |
318bf84f | 480 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct blockvector) + (i - 1) * sizeof (struct block *)); |
bd5635a1 RP |
481 | |
482 | /* Copy the blocks into the blockvector. | |
483 | This is done in reverse order, which happens to put | |
484 | the blocks into the proper order (ascending starting address). | |
318bf84f | 485 | coff_finish_block has hair to insert each block into the list |
bd5635a1 RP |
486 | after its subblocks in order to make sure this is true. */ |
487 | ||
488 | BLOCKVECTOR_NBLOCKS (blockvector) = i; | |
489 | for (next = pending_blocks; next; next = next->next) | |
490 | BLOCKVECTOR_BLOCK (blockvector, --i) = next->block; | |
491 | ||
492 | /* Now free the links of the list, and empty the list. */ | |
493 | ||
494 | for (next = pending_blocks; next; next = next1) | |
495 | { | |
496 | next1 = next->next; | |
f70be3e4 | 497 | free ((PTR)next); |
bd5635a1 RP |
498 | } |
499 | pending_blocks = 0; | |
500 | ||
501 | return blockvector; | |
502 | } | |
503 | ||
504 | /* Manage the vector of line numbers. */ | |
505 | ||
e1ce8aa5 | 506 | static void |
318bf84f | 507 | coff_record_line (line, pc) |
bd5635a1 RP |
508 | int line; |
509 | CORE_ADDR pc; | |
510 | { | |
511 | struct linetable_entry *e; | |
512 | /* Make sure line vector is big enough. */ | |
513 | ||
514 | if (line_vector_index + 2 >= line_vector_length) | |
515 | { | |
516 | line_vector_length *= 2; | |
517 | line_vector = (struct linetable *) | |
318bf84f | 518 | xrealloc ((char *) line_vector, sizeof (struct linetable) |
bd5635a1 RP |
519 | + (line_vector_length |
520 | * sizeof (struct linetable_entry))); | |
521 | } | |
522 | ||
523 | e = line_vector->item + line_vector_index++; | |
524 | e->line = line; e->pc = pc; | |
525 | } | |
526 | \f | |
527 | /* Start a new symtab for a new source file. | |
528 | This is called when a COFF ".file" symbol is seen; | |
529 | it indicates the start of data for one original source file. */ | |
530 | ||
531 | static void | |
318bf84f | 532 | coff_start_symtab () |
bd5635a1 | 533 | { |
318bf84f FF |
534 | coff_file_symbols = 0; |
535 | coff_global_symbols = 0; | |
536 | coff_context_stack = 0; | |
bd5635a1 | 537 | within_function = 0; |
85f0a848 | 538 | last_source_file = NULL; |
bd5635a1 | 539 | |
cadbb07a | 540 | /* Initialize the source file line number information for this file. */ |
bd5635a1 | 541 | |
cadbb07a | 542 | if (line_vector) /* Unlikely, but maybe possible? */ |
f70be3e4 | 543 | free ((PTR)line_vector); |
bd5635a1 RP |
544 | line_vector_index = 0; |
545 | line_vector_length = 1000; | |
546 | prev_line_number = -2; /* Force first line number to be explicit */ | |
547 | line_vector = (struct linetable *) | |
548 | xmalloc (sizeof (struct linetable) | |
549 | + line_vector_length * sizeof (struct linetable_entry)); | |
550 | } | |
551 | ||
552 | /* Save the vital information from when starting to read a file, | |
553 | for use when closing off the current file. | |
554 | NAME is the file name the symbols came from, START_ADDR is the first | |
555 | text address for the file, and SIZE is the number of bytes of text. */ | |
556 | ||
557 | static void | |
558 | complete_symtab (name, start_addr, size) | |
559 | char *name; | |
560 | CORE_ADDR start_addr; | |
561 | unsigned int size; | |
562 | { | |
563 | last_source_file = savestring (name, strlen (name)); | |
564 | cur_src_start_addr = start_addr; | |
565 | cur_src_end_addr = start_addr + size; | |
566 | ||
3624c875 FF |
567 | if (current_objfile -> ei.entry_point >= cur_src_start_addr && |
568 | current_objfile -> ei.entry_point < cur_src_end_addr) | |
bd5635a1 | 569 | { |
3624c875 FF |
570 | current_objfile -> ei.entry_file_lowpc = cur_src_start_addr; |
571 | current_objfile -> ei.entry_file_highpc = cur_src_end_addr; | |
bd5635a1 RP |
572 | } |
573 | } | |
574 | ||
575 | /* Finish the symbol definitions for one main source file, | |
576 | close off all the lexical contexts for that file | |
577 | (creating struct block's for them), then make the | |
578 | struct symtab for that file and put it in the list of all such. */ | |
579 | ||
580 | static void | |
318bf84f | 581 | coff_end_symtab (objfile) |
a048c8f5 | 582 | struct objfile *objfile; |
bd5635a1 RP |
583 | { |
584 | register struct symtab *symtab; | |
318bf84f | 585 | register struct coff_context_stack *cstk; |
bd5635a1 RP |
586 | register struct blockvector *blockvector; |
587 | register struct linetable *lv; | |
588 | ||
589 | /* Finish the lexical context of the last function in the file. */ | |
590 | ||
318bf84f | 591 | if (coff_context_stack) |
bd5635a1 | 592 | { |
318bf84f FF |
593 | cstk = coff_context_stack; |
594 | coff_context_stack = 0; | |
bd5635a1 | 595 | /* Make a block for the local symbols within. */ |
318bf84f FF |
596 | coff_finish_block (cstk->name, &coff_local_symbols, cstk->old_blocks, |
597 | cstk->start_addr, cur_src_end_addr, objfile); | |
f70be3e4 | 598 | free ((PTR)cstk); |
bd5635a1 RP |
599 | } |
600 | ||
601 | /* Ignore a file that has no functions with real debugging info. */ | |
318bf84f | 602 | if (pending_blocks == 0 && coff_file_symbols == 0 && coff_global_symbols == 0) |
bd5635a1 | 603 | { |
f70be3e4 | 604 | free ((PTR)line_vector); |
bd5635a1 RP |
605 | line_vector = 0; |
606 | line_vector_length = -1; | |
85f0a848 | 607 | last_source_file = NULL; |
bd5635a1 RP |
608 | return; |
609 | } | |
610 | ||
f70be3e4 JG |
611 | /* It is unfortunate that in amdcoff, pending blocks might not be ordered |
612 | in this stage. Especially, blocks for static functions will show up at | |
613 | the end. We need to sort them, so tools like `find_pc_function' and | |
614 | `find_pc_block' can work reliably. */ | |
615 | if (pending_blocks) { | |
616 | /* FIXME! Remove this horrid bubble sort and use qsort!!! */ | |
617 | int swapped; | |
618 | do { | |
619 | struct pending_block *pb, *pbnext; | |
620 | ||
621 | pb = pending_blocks, pbnext = pb->next; | |
622 | swapped = 0; | |
623 | ||
624 | while ( pbnext ) { | |
625 | ||
626 | /* swap blocks if unordered! */ | |
627 | ||
628 | if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block)) { | |
629 | struct block *tmp = pb->block; | |
51b80b00 | 630 | complain (&misordered_blocks_complaint, BLOCK_START (pb->block)); |
f70be3e4 JG |
631 | pb->block = pbnext->block; |
632 | pbnext->block = tmp; | |
633 | swapped = 1; | |
634 | } | |
635 | pb = pbnext; | |
636 | pbnext = pbnext->next; | |
637 | } | |
638 | } while (swapped); | |
639 | } | |
640 | ||
a6e2b424 JG |
641 | /* Create the two top-level blocks for this file (STATIC_BLOCK and |
642 | GLOBAL_BLOCK). */ | |
318bf84f FF |
643 | coff_finish_block (0, &coff_file_symbols, 0, cur_src_start_addr, cur_src_end_addr, objfile); |
644 | coff_finish_block (0, &coff_global_symbols, 0, cur_src_start_addr, cur_src_end_addr, objfile); | |
bd5635a1 RP |
645 | |
646 | /* Create the blockvector that points to all the file's blocks. */ | |
318bf84f | 647 | blockvector = make_blockvector (objfile); |
bd5635a1 RP |
648 | |
649 | /* Now create the symtab object for this source file. */ | |
a048c8f5 | 650 | symtab = allocate_symtab (last_source_file, objfile); |
bd5635a1 RP |
651 | |
652 | /* Fill in its components. */ | |
653 | symtab->blockvector = blockvector; | |
654 | symtab->free_code = free_linetable; | |
d8ce1326 | 655 | symtab->free_ptr = 0; |
bd5635a1 | 656 | symtab->filename = last_source_file; |
b203fc18 | 657 | symtab->dirname = NULL; |
bd5635a1 RP |
658 | lv = line_vector; |
659 | lv->nitems = line_vector_index; | |
660 | symtab->linetable = (struct linetable *) | |
318bf84f | 661 | xrealloc ((char *) lv, (sizeof (struct linetable) |
bd5635a1 | 662 | + lv->nitems * sizeof (struct linetable_entry))); |
b203fc18 | 663 | |
a6e2b424 JG |
664 | free_named_symtabs (symtab->filename); |
665 | ||
bd5635a1 RP |
666 | /* Reinitialize for beginning of new file. */ |
667 | line_vector = 0; | |
668 | line_vector_length = -1; | |
85f0a848 | 669 | last_source_file = NULL; |
bd5635a1 RP |
670 | } |
671 | \f | |
672 | static void | |
f70be3e4 | 673 | record_minimal_symbol (name, address, type) |
bd5635a1 RP |
674 | char *name; |
675 | CORE_ADDR address; | |
f70be3e4 | 676 | enum minimal_symbol_type type; |
bd5635a1 | 677 | { |
318bf84f | 678 | /* We don't want TDESC entry points in the minimal symbol table */ |
bd5635a1 | 679 | if (name[0] == '@') return; |
e140f1da | 680 | |
e09c5e26 | 681 | prim_record_minimal_symbol (savestring (name, strlen (name)), address, type); |
bd5635a1 RP |
682 | } |
683 | \f | |
684 | /* coff_symfile_init () | |
685 | is the coff-specific initialization routine for reading symbols. | |
3624c875 | 686 | It is passed a struct objfile which contains, among other things, |
bd5635a1 RP |
687 | the BFD for the file whose symbols are being read, and a slot for |
688 | a pointer to "private data" which we fill with cookies and other | |
689 | treats for coff_symfile_read (). | |
690 | ||
691 | We will only be called if this is a COFF or COFF-like file. | |
692 | BFD handles figuring out the format of the file, and code in symtab.c | |
693 | uses BFD's determination to vector to us. | |
694 | ||
695 | The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */ | |
696 | ||
697 | struct coff_symfile_info { | |
698 | file_ptr min_lineno_offset; /* Where in file lowest line#s are */ | |
699 | file_ptr max_lineno_offset; /* 1+last byte of line#s in file */ | |
700 | }; | |
701 | ||
d8ce1326 JG |
702 | static int text_bfd_scnum; |
703 | ||
9bba3334 | 704 | static void |
80d68b1d FF |
705 | coff_symfile_init (objfile) |
706 | struct objfile *objfile; | |
bd5635a1 | 707 | { |
d8ce1326 | 708 | asection *section; |
80d68b1d | 709 | bfd *abfd = objfile->obfd; |
bd5635a1 RP |
710 | |
711 | /* Allocate struct to keep track of the symfile */ | |
80d68b1d FF |
712 | objfile -> sym_private = xmmalloc (objfile -> md, |
713 | sizeof (struct coff_symfile_info)); | |
bd5635a1 | 714 | |
3624c875 FF |
715 | init_entry_point_info (objfile); |
716 | ||
717 | /* Save the section number for the text section */ | |
f70be3e4 JG |
718 | section = bfd_get_section_by_name(abfd,".text"); |
719 | if (section) | |
3624c875 | 720 | text_bfd_scnum = section->index; |
bd5635a1 | 721 | else |
3624c875 | 722 | text_bfd_scnum = -1; |
bd5635a1 RP |
723 | } |
724 | ||
725 | /* This function is called for every section; it finds the outer limits | |
726 | of the line table (minimum and maximum file offset) so that the | |
727 | mainline code can read the whole thing for efficiency. */ | |
728 | ||
e1ce8aa5 | 729 | /* ARGSUSED */ |
bd5635a1 RP |
730 | static void |
731 | find_linenos (abfd, asect, vpinfo) | |
732 | bfd *abfd; | |
733 | sec_ptr asect; | |
318bf84f | 734 | PTR vpinfo; |
bd5635a1 RP |
735 | { |
736 | struct coff_symfile_info *info; | |
737 | int size, count; | |
738 | file_ptr offset, maxoff; | |
739 | ||
740 | /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */ | |
741 | count = asect->lineno_count; | |
742 | /* End of warning */ | |
743 | ||
744 | if (count == 0) | |
745 | return; | |
d8ce1326 | 746 | size = count * local_linesz; |
bd5635a1 RP |
747 | |
748 | info = (struct coff_symfile_info *)vpinfo; | |
749 | /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */ | |
750 | offset = asect->line_filepos; | |
751 | /* End of warning */ | |
752 | ||
753 | if (offset < info->min_lineno_offset || info->min_lineno_offset == 0) | |
754 | info->min_lineno_offset = offset; | |
755 | ||
756 | maxoff = offset + size; | |
757 | if (maxoff > info->max_lineno_offset) | |
758 | info->max_lineno_offset = maxoff; | |
759 | } | |
760 | ||
761 | ||
e1ce8aa5 JK |
762 | /* The BFD for this file -- only good while we're actively reading |
763 | symbols into a psymtab or a symtab. */ | |
764 | ||
765 | static bfd *symfile_bfd; | |
766 | ||
bd5635a1 RP |
767 | /* Read a symbol file, after initialization by coff_symfile_init. */ |
768 | /* FIXME! Addr and Mainline are not used yet -- this will not work for | |
769 | shared libraries or add_file! */ | |
770 | ||
61a7292f | 771 | /* ARGSUSED */ |
9bba3334 | 772 | static void |
85f0a848 | 773 | coff_symfile_read (objfile, section_offsets, mainline) |
80d68b1d | 774 | struct objfile *objfile; |
85f0a848 | 775 | struct section_offsets *section_offsets; |
bd5635a1 RP |
776 | int mainline; |
777 | { | |
80d68b1d FF |
778 | struct coff_symfile_info *info; |
779 | bfd *abfd = objfile->obfd; | |
d8ce1326 | 780 | coff_data_type *cdata = coff_data (abfd); |
bd5635a1 RP |
781 | char *name = bfd_get_filename (abfd); |
782 | int desc; | |
783 | register int val; | |
784 | int num_symbols; | |
785 | int symtab_offset; | |
786 | int stringtab_offset; | |
e09c5e26 | 787 | struct cleanup *back_to; |
bd5635a1 | 788 | |
80d68b1d | 789 | info = (struct coff_symfile_info *) objfile -> sym_private; |
bd5635a1 RP |
790 | symfile_bfd = abfd; /* Kludge for swap routines */ |
791 | ||
792 | /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */ | |
d8ce1326 | 793 | desc = fileno ((FILE *)(abfd->iostream)); /* File descriptor */ |
bd5635a1 | 794 | num_symbols = bfd_get_symcount (abfd); /* How many syms */ |
d8ce1326 JG |
795 | symtab_offset = cdata->sym_filepos; /* Symbol table file offset */ |
796 | stringtab_offset = symtab_offset + /* String table file offset */ | |
797 | num_symbols * cdata->local_symesz; | |
798 | ||
799 | /* Set a few file-statics that give us specific information about | |
800 | the particular COFF file format we're reading. */ | |
801 | local_linesz = cdata->local_linesz; | |
802 | local_n_btmask = cdata->local_n_btmask; | |
803 | local_n_btshft = cdata->local_n_btshft; | |
804 | local_n_tmask = cdata->local_n_tmask; | |
805 | local_n_tshift = cdata->local_n_tshift; | |
806 | local_linesz = cdata->local_linesz; | |
807 | local_symesz = cdata->local_symesz; | |
808 | local_auxesz = cdata->local_auxesz; | |
809 | ||
810 | /* Allocate space for raw symbol and aux entries, based on their | |
811 | space requirements as reported by BFD. */ | |
812 | temp_sym = (char *) xmalloc | |
813 | (cdata->local_symesz + cdata->local_auxesz); | |
814 | temp_aux = temp_sym + cdata->local_symesz; | |
e09c5e26 | 815 | back_to = make_cleanup (free_current_contents, &temp_sym); |
bd5635a1 RP |
816 | /* End of warning */ |
817 | ||
bd5635a1 RP |
818 | /* Read the line number table, all at once. */ |
819 | info->min_lineno_offset = 0; | |
820 | info->max_lineno_offset = 0; | |
f70be3e4 | 821 | bfd_map_over_sections (abfd, find_linenos, (PTR)info); |
bd5635a1 | 822 | |
e09c5e26 | 823 | make_cleanup (free_linetab, 0); |
bd5635a1 RP |
824 | val = init_lineno (desc, info->min_lineno_offset, |
825 | info->max_lineno_offset - info->min_lineno_offset); | |
826 | if (val < 0) | |
827 | error ("\"%s\": error reading line numbers\n", name); | |
828 | ||
829 | /* Now read the string table, all at once. */ | |
830 | ||
e09c5e26 | 831 | make_cleanup (free_stringtab, 0); |
bd5635a1 RP |
832 | val = init_stringtab (desc, stringtab_offset); |
833 | if (val < 0) | |
a048c8f5 | 834 | error ("\"%s\": can't get string table", name); |
bd5635a1 | 835 | |
318bf84f FF |
836 | init_minimal_symbol_collection (); |
837 | make_cleanup (discard_minimal_symbols, 0); | |
bd5635a1 RP |
838 | |
839 | /* Now that the executable file is positioned at symbol table, | |
840 | process it and define symbols accordingly. */ | |
841 | ||
f70be3e4 | 842 | read_coff_symtab ((long)symtab_offset, num_symbols, objfile); |
bd5635a1 RP |
843 | |
844 | /* Sort symbols alphabetically within each block. */ | |
845 | ||
846 | sort_all_symtab_syms (); | |
847 | ||
318bf84f FF |
848 | /* Install any minimal symbols that have been collected as the current |
849 | minimal symbols for this objfile. */ | |
bd5635a1 | 850 | |
80d68b1d | 851 | install_minimal_symbols (objfile); |
e09c5e26 JK |
852 | |
853 | do_cleanups (back_to); | |
bd5635a1 RP |
854 | } |
855 | ||
9bba3334 | 856 | static void |
f70be3e4 JG |
857 | coff_new_init (ignore) |
858 | struct objfile *ignore; | |
bd5635a1 | 859 | { |
a048c8f5 | 860 | /* Nothin' to do */ |
bd5635a1 | 861 | } |
80d68b1d FF |
862 | |
863 | /* Perform any local cleanups required when we are done with a particular | |
864 | objfile. I.E, we are in the process of discarding all symbol information | |
865 | for an objfile, freeing up all memory held for it, and unlinking the | |
866 | objfile struct from the global list of known objfiles. */ | |
867 | ||
868 | static void | |
869 | coff_symfile_finish (objfile) | |
870 | struct objfile *objfile; | |
871 | { | |
872 | if (objfile -> sym_private != NULL) | |
873 | { | |
874 | mfree (objfile -> md, objfile -> sym_private); | |
875 | } | |
876 | } | |
877 | ||
bd5635a1 | 878 | \f |
bd5635a1 RP |
879 | /* Given pointers to a symbol table in coff style exec file, |
880 | analyze them and create struct symtab's describing the symbols. | |
881 | NSYMS is the number of symbols in the symbol table. | |
882 | We read them one at a time using read_one_sym (). */ | |
883 | ||
884 | static void | |
f70be3e4 JG |
885 | read_coff_symtab (symtab_offset, nsyms, objfile) |
886 | long symtab_offset; | |
bd5635a1 | 887 | int nsyms; |
a048c8f5 | 888 | struct objfile *objfile; |
bd5635a1 | 889 | { |
bd5635a1 | 890 | FILE *stream; |
318bf84f | 891 | register struct coff_context_stack *new; |
bd5635a1 RP |
892 | struct coff_symbol coff_symbol; |
893 | register struct coff_symbol *cs = &coff_symbol; | |
dcc35536 JG |
894 | static struct internal_syment main_sym; |
895 | static union internal_auxent main_aux; | |
bd5635a1 | 896 | struct coff_symbol fcn_cs_saved; |
dcc35536 JG |
897 | static struct internal_syment fcn_sym_saved; |
898 | static union internal_auxent fcn_aux_saved; | |
f70be3e4 JG |
899 | struct symtab *s; |
900 | ||
bd5635a1 RP |
901 | /* A .file is open. */ |
902 | int in_source_file = 0; | |
903 | int num_object_files = 0; | |
904 | int next_file_symnum = -1; | |
905 | ||
906 | /* Name of the current file. */ | |
907 | char *filestring = ""; | |
f70be3e4 JG |
908 | int depth = 0; |
909 | int fcn_first_line = 0; | |
910 | int fcn_last_line = 0; | |
911 | int fcn_start_addr = 0; | |
912 | long fcn_line_ptr = 0; | |
f70be3e4 | 913 | int val; |
bd5635a1 | 914 | |
de9bef49 | 915 | stream = bfd_cache_lookup(objfile->obfd); |
f70be3e4 JG |
916 | if (!stream) |
917 | perror_with_name(objfile->name); | |
bd5635a1 | 918 | |
f2c365f5 | 919 | /* Work around a stdio bug in SunOS4.1.1 (this makes me nervous.... |
fc312cc6 JK |
920 | it's hard to know I've really worked around it. The fix should be |
921 | harmless, anyway). The symptom of the bug is that the first | |
922 | fread (in read_one_sym), will (in my example) actually get data | |
923 | from file offset 268, when the fseek was to 264 (and ftell shows | |
924 | 264). This causes all hell to break loose. I was unable to | |
925 | reproduce this on a short test program which operated on the same | |
926 | file, performing (I think) the same sequence of operations. | |
927 | ||
928 | It stopped happening when I put in this rewind(). | |
929 | ||
930 | FIXME: Find out if this has been reported to Sun, whether it has | |
931 | been fixed in a later release, etc. */ | |
932 | ||
f2c365f5 JK |
933 | rewind (stream); |
934 | ||
f70be3e4 JG |
935 | /* Position to read the symbol table. */ |
936 | val = fseek (stream, (long)symtab_offset, 0); | |
937 | if (val < 0) | |
938 | perror_with_name (objfile->name); | |
bd5635a1 | 939 | |
318bf84f | 940 | current_objfile = objfile; |
bd5635a1 RP |
941 | nlist_stream_global = stream; |
942 | nlist_nsyms_global = nsyms; | |
85f0a848 | 943 | last_source_file = NULL; |
4ed3a9ea | 944 | memset (opaque_type_chain, 0, sizeof opaque_type_chain); |
bd5635a1 | 945 | |
cadbb07a | 946 | if (type_vector) /* Get rid of previous one */ |
f70be3e4 | 947 | free ((PTR)type_vector); |
bd5635a1 | 948 | type_vector_length = 160; |
159a075e SG |
949 | type_vector = (struct type **) |
950 | xmalloc (type_vector_length * sizeof (struct type *)); | |
4ed3a9ea | 951 | memset (type_vector, 0, type_vector_length * sizeof (struct type *)); |
bd5635a1 | 952 | |
318bf84f | 953 | coff_start_symtab (); |
bd5635a1 RP |
954 | |
955 | symnum = 0; | |
956 | while (symnum < nsyms) | |
957 | { | |
958 | QUIT; /* Make this command interruptable. */ | |
959 | read_one_sym (cs, &main_sym, &main_aux); | |
960 | ||
961 | #ifdef SEM | |
962 | temp_sem_val = cs->c_name[0] << 24 | cs->c_name[1] << 16 | | |
963 | cs->c_name[2] << 8 | cs->c_name[3]; | |
964 | if (int_sem_val == temp_sem_val) | |
965 | last_coffsem = (int) strtol (cs->c_name+4, (char **) NULL, 10); | |
966 | #endif | |
967 | ||
968 | if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) | |
969 | { | |
970 | if (last_source_file) | |
318bf84f | 971 | coff_end_symtab (objfile); |
bd5635a1 | 972 | |
318bf84f | 973 | coff_start_symtab (); |
bd5635a1 RP |
974 | complete_symtab ("_globals_", 0, first_object_file_end); |
975 | /* done with all files, everything from here on out is globals */ | |
976 | } | |
977 | ||
978 | /* Special case for file with type declarations only, no text. */ | |
8714ff35 JK |
979 | if (!last_source_file && SDB_TYPE (cs->c_type) |
980 | && cs->c_secnum == N_DEBUG) | |
bd5635a1 RP |
981 | complete_symtab (filestring, 0, 0); |
982 | ||
983 | /* Typedefs should not be treated as symbol definitions. */ | |
984 | if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF) | |
985 | { | |
e09c5e26 | 986 | /* Record all functions -- external and static -- in minsyms. */ |
f70be3e4 | 987 | record_minimal_symbol (cs->c_name, cs->c_value, mst_text); |
bd5635a1 RP |
988 | |
989 | fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr; | |
990 | fcn_start_addr = cs->c_value; | |
991 | fcn_cs_saved = *cs; | |
992 | fcn_sym_saved = main_sym; | |
993 | fcn_aux_saved = main_aux; | |
994 | continue; | |
995 | } | |
996 | ||
997 | switch (cs->c_sclass) | |
998 | { | |
999 | case C_EFCN: | |
1000 | case C_EXTDEF: | |
1001 | case C_ULABEL: | |
1002 | case C_USTATIC: | |
1003 | case C_LINE: | |
1004 | case C_ALIAS: | |
1005 | case C_HIDDEN: | |
7e258d18 | 1006 | complain (&bad_sclass_complaint, cs->c_name); |
bd5635a1 RP |
1007 | break; |
1008 | ||
1009 | case C_FILE: | |
1010 | /* | |
1011 | * c_value field contains symnum of next .file entry in table | |
1012 | * or symnum of first global after last .file. | |
1013 | */ | |
1014 | next_file_symnum = cs->c_value; | |
1015 | filestring = getfilename (&main_aux); | |
1016 | /* | |
1017 | * Complete symbol table for last object file | |
1018 | * containing debugging information. | |
1019 | */ | |
1020 | if (last_source_file) | |
1021 | { | |
318bf84f FF |
1022 | coff_end_symtab (objfile); |
1023 | coff_start_symtab (); | |
bd5635a1 RP |
1024 | } |
1025 | in_source_file = 1; | |
1026 | break; | |
1027 | ||
1028 | case C_STAT: | |
1029 | if (cs->c_name[0] == '.') { | |
c653bc6d | 1030 | if (STREQ (cs->c_name, ".text")) { |
d8ce1326 JG |
1031 | /* FIXME: don't wire in ".text" as section name |
1032 | or symbol name! */ | |
bd5635a1 RP |
1033 | if (++num_object_files == 1) { |
1034 | /* last address of startup file */ | |
1035 | first_object_file_end = cs->c_value + | |
1036 | main_aux.x_scn.x_scnlen; | |
1037 | } | |
1038 | /* Check for in_source_file deals with case of | |
1039 | a file with debugging symbols | |
1040 | followed by a later file with no symbols. */ | |
1041 | if (in_source_file) | |
1042 | complete_symtab (filestring, cs->c_value, | |
1043 | main_aux.x_scn.x_scnlen); | |
1044 | in_source_file = 0; | |
1045 | } | |
1046 | /* flush rest of '.' symbols */ | |
1047 | break; | |
1048 | } | |
8714ff35 | 1049 | else if (!SDB_TYPE (cs->c_type) |
bd5635a1 RP |
1050 | && cs->c_name[0] == 'L' |
1051 | && (strncmp (cs->c_name, "LI%", 3) == 0 | |
8714ff35 | 1052 | || strncmp (cs->c_name, "LF%", 3) == 0 |
bd5635a1 RP |
1053 | || strncmp (cs->c_name,"LC%",3) == 0 |
1054 | || strncmp (cs->c_name,"LP%",3) == 0 | |
1055 | || strncmp (cs->c_name,"LPB%",4) == 0 | |
1056 | || strncmp (cs->c_name,"LBB%",4) == 0 | |
1057 | || strncmp (cs->c_name,"LBE%",4) == 0 | |
1058 | || strncmp (cs->c_name,"LPBX%",5) == 0)) | |
1059 | /* At least on a 3b1, gcc generates swbeg and string labels | |
1060 | that look like this. Ignore them. */ | |
1061 | break; | |
1062 | /* fall in for static symbols that don't start with '.' */ | |
1063 | case C_EXT: | |
e09c5e26 JK |
1064 | /* Record external symbols in minsyms if we don't have debug |
1065 | info for them. FIXME, this is probably the wrong thing | |
1066 | to do. Why don't we record them even if we do have | |
1067 | debug symbol info? What really belongs in the minsyms | |
1068 | anyway? Fred!?? */ | |
8714ff35 | 1069 | if (!SDB_TYPE (cs->c_type)) { |
d8ce1326 JG |
1070 | /* FIXME: This is BOGUS Will Robinson! |
1071 | Coff should provide the SEC_CODE flag for executable sections, | |
1072 | then if we could look up sections by section number we | |
1073 | could see if the flags indicate SEC_CODE. If so, then | |
318bf84f FF |
1074 | record this symbol as a function in the minimal symbol table. |
1075 | But why are absolute syms recorded as functions, anyway? */ | |
d8ce1326 | 1076 | if (cs->c_secnum <= text_bfd_scnum+1) {/* text or abs */ |
f70be3e4 JG |
1077 | record_minimal_symbol (cs->c_name, cs->c_value, |
1078 | mst_text); | |
bd5635a1 RP |
1079 | break; |
1080 | } else { | |
f70be3e4 JG |
1081 | record_minimal_symbol (cs->c_name, cs->c_value, |
1082 | mst_data); | |
1083 | break; | |
bd5635a1 RP |
1084 | } |
1085 | } | |
4ed3a9ea | 1086 | process_coff_symbol (cs, &main_aux, objfile); |
bd5635a1 RP |
1087 | break; |
1088 | ||
1089 | case C_FCN: | |
c653bc6d | 1090 | if (STREQ (cs->c_name, ".bf")) |
bd5635a1 RP |
1091 | { |
1092 | within_function = 1; | |
1093 | ||
1094 | /* value contains address of first non-init type code */ | |
1095 | /* main_aux.x_sym.x_misc.x_lnsz.x_lnno | |
1096 | contains line number of '{' } */ | |
e64fbb3a | 1097 | if (cs->c_naux != 1) |
51b80b00 | 1098 | complain (&bf_no_aux_complaint, cs->c_symnum); |
bd5635a1 RP |
1099 | fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno; |
1100 | ||
318bf84f FF |
1101 | new = (struct coff_context_stack *) |
1102 | xmalloc (sizeof (struct coff_context_stack)); | |
bd5635a1 RP |
1103 | new->depth = depth = 0; |
1104 | new->next = 0; | |
318bf84f | 1105 | coff_context_stack = new; |
bd5635a1 RP |
1106 | new->locals = 0; |
1107 | new->old_blocks = pending_blocks; | |
1108 | new->start_addr = fcn_start_addr; | |
1109 | fcn_cs_saved.c_name = getsymname (&fcn_sym_saved); | |
1110 | new->name = process_coff_symbol (&fcn_cs_saved, | |
318bf84f | 1111 | &fcn_aux_saved, objfile); |
bd5635a1 | 1112 | } |
c653bc6d | 1113 | else if (STREQ (cs->c_name, ".ef")) |
bd5635a1 RP |
1114 | { |
1115 | /* the value of .ef is the address of epilogue code; | |
1116 | * not useful for gdb | |
1117 | */ | |
1118 | /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno | |
1119 | contains number of lines to '}' */ | |
318bf84f | 1120 | new = coff_context_stack; |
bd5635a1 RP |
1121 | if (new == 0) |
1122 | { | |
51b80b00 | 1123 | complain (&ef_complaint, cs->c_symnum); |
bd5635a1 RP |
1124 | within_function = 0; |
1125 | break; | |
1126 | } | |
e64fbb3a | 1127 | if (cs->c_naux != 1) { |
51b80b00 | 1128 | complain (&ef_no_aux_complaint, cs->c_symnum); |
e64fbb3a JG |
1129 | fcn_last_line = 0x7FFFFFFF; |
1130 | } else { | |
1131 | fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno; | |
1132 | } | |
bd5635a1 RP |
1133 | enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line); |
1134 | ||
318bf84f | 1135 | coff_finish_block (new->name, &coff_local_symbols, new->old_blocks, |
bd5635a1 RP |
1136 | new->start_addr, |
1137 | #if defined (FUNCTION_EPILOGUE_SIZE) | |
1138 | /* This macro should be defined only on | |
1139 | machines where the | |
1140 | fcn_aux_saved.x_sym.x_misc.x_fsize | |
1141 | field is always zero. | |
1142 | So use the .bf record information that | |
1143 | points to the epilogue and add the size | |
1144 | of the epilogue. */ | |
318bf84f | 1145 | cs->c_value + FUNCTION_EPILOGUE_SIZE, |
bd5635a1 RP |
1146 | #else |
1147 | fcn_cs_saved.c_value + | |
318bf84f | 1148 | fcn_aux_saved.x_sym.x_misc.x_fsize, |
bd5635a1 | 1149 | #endif |
318bf84f | 1150 | objfile |
bd5635a1 | 1151 | ); |
318bf84f | 1152 | coff_context_stack = 0; |
bd5635a1 | 1153 | within_function = 0; |
f70be3e4 | 1154 | free ((PTR)new); |
bd5635a1 RP |
1155 | } |
1156 | break; | |
1157 | ||
1158 | case C_BLOCK: | |
c653bc6d | 1159 | if (STREQ (cs->c_name, ".bb")) |
bd5635a1 | 1160 | { |
318bf84f FF |
1161 | new = (struct coff_context_stack *) |
1162 | xmalloc (sizeof (struct coff_context_stack)); | |
bd5635a1 RP |
1163 | depth++; |
1164 | new->depth = depth; | |
318bf84f FF |
1165 | new->next = coff_context_stack; |
1166 | coff_context_stack = new; | |
1167 | new->locals = coff_local_symbols; | |
bd5635a1 RP |
1168 | new->old_blocks = pending_blocks; |
1169 | new->start_addr = cs->c_value; | |
1170 | new->name = 0; | |
318bf84f | 1171 | coff_local_symbols = 0; |
bd5635a1 | 1172 | } |
c653bc6d | 1173 | else if (STREQ (cs->c_name, ".eb")) |
bd5635a1 | 1174 | { |
318bf84f | 1175 | new = coff_context_stack; |
bd5635a1 | 1176 | if (new == 0 || depth != new->depth) |
de9bef49 JG |
1177 | { |
1178 | complain (&eb_complaint, (char *)symnum); | |
1179 | break; | |
1180 | } | |
318bf84f | 1181 | if (coff_local_symbols && coff_context_stack->next) |
bd5635a1 RP |
1182 | { |
1183 | /* Make a block for the local symbols within. */ | |
318bf84f FF |
1184 | coff_finish_block (0, &coff_local_symbols, new->old_blocks, |
1185 | new->start_addr, cs->c_value, objfile); | |
bd5635a1 RP |
1186 | } |
1187 | depth--; | |
318bf84f FF |
1188 | coff_local_symbols = new->locals; |
1189 | coff_context_stack = new->next; | |
f70be3e4 | 1190 | free ((PTR)new); |
bd5635a1 RP |
1191 | } |
1192 | break; | |
bd5635a1 RP |
1193 | |
1194 | default: | |
4ed3a9ea | 1195 | process_coff_symbol (cs, &main_aux, objfile); |
bd5635a1 RP |
1196 | break; |
1197 | } | |
1198 | } | |
1199 | ||
1200 | if (last_source_file) | |
318bf84f | 1201 | coff_end_symtab (objfile); |
f70be3e4 JG |
1202 | |
1203 | /* Patch up any opaque types (references to types that are not defined | |
1204 | in the file where they are referenced, e.g. "struct foo *bar"). */ | |
1205 | ALL_OBJFILE_SYMTABS (objfile, s) | |
1206 | patch_opaque_types (s); | |
1207 | ||
318bf84f | 1208 | current_objfile = NULL; |
bd5635a1 RP |
1209 | } |
1210 | \f | |
1211 | /* Routines for reading headers and symbols from executable. */ | |
1212 | ||
1213 | #ifdef FIXME | |
1214 | /* Move these XXXMAGIC symbol defns into BFD! */ | |
1215 | ||
1216 | /* Read COFF file header, check magic number, | |
1217 | and return number of symbols. */ | |
1218 | read_file_hdr (chan, file_hdr) | |
1219 | int chan; | |
1220 | FILHDR *file_hdr; | |
1221 | { | |
1222 | lseek (chan, 0L, 0); | |
1223 | if (myread (chan, (char *)file_hdr, FILHSZ) < 0) | |
1224 | return -1; | |
1225 | ||
1226 | switch (file_hdr->f_magic) | |
1227 | { | |
1228 | #ifdef MC68MAGIC | |
1229 | case MC68MAGIC: | |
1230 | #endif | |
1231 | #ifdef NS32GMAGIC | |
1232 | case NS32GMAGIC: | |
1233 | case NS32SMAGIC: | |
1234 | #endif | |
1235 | #ifdef I386MAGIC | |
1236 | case I386MAGIC: | |
1237 | #endif | |
1238 | #ifdef CLIPPERMAGIC | |
1239 | case CLIPPERMAGIC: | |
1240 | #endif | |
1241 | #if defined (MC68KWRMAGIC) \ | |
1242 | && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC) | |
1243 | case MC68KWRMAGIC: | |
1244 | #endif | |
1245 | #ifdef MC68KROMAGIC | |
1246 | case MC68KROMAGIC: | |
1247 | case MC68KPGMAGIC: | |
1248 | #endif | |
1249 | #ifdef MC88DGMAGIC | |
1250 | case MC88DGMAGIC: | |
1251 | #endif | |
1252 | #ifdef MC88MAGIC | |
1253 | case MC88MAGIC: | |
1254 | #endif | |
1255 | #ifdef I960ROMAGIC | |
1256 | case I960ROMAGIC: /* Intel 960 */ | |
1257 | #endif | |
1258 | #ifdef I960RWMAGIC | |
1259 | case I960RWMAGIC: /* Intel 960 */ | |
1260 | #endif | |
1261 | return file_hdr->f_nsyms; | |
1262 | ||
1263 | default: | |
1264 | #ifdef BADMAG | |
1265 | if (BADMAG(file_hdr)) | |
1266 | return -1; | |
1267 | else | |
1268 | return file_hdr->f_nsyms; | |
1269 | #else | |
1270 | return -1; | |
1271 | #endif | |
1272 | } | |
1273 | } | |
1274 | #endif | |
1275 | ||
dcc35536 JG |
1276 | /* Read the next symbol, swap it, and return it in both internal_syment |
1277 | form, and coff_symbol form. Also return its first auxent, if any, | |
1278 | in internal_auxent form, and skip any other auxents. */ | |
bd5635a1 RP |
1279 | |
1280 | static void | |
1281 | read_one_sym (cs, sym, aux) | |
1282 | register struct coff_symbol *cs; | |
dcc35536 JG |
1283 | register struct internal_syment *sym; |
1284 | register union internal_auxent *aux; | |
bd5635a1 | 1285 | { |
bd5635a1 RP |
1286 | int i; |
1287 | ||
1288 | cs->c_symnum = symnum; | |
d8ce1326 JG |
1289 | fread (temp_sym, local_symesz, 1, nlist_stream_global); |
1290 | bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *)sym); | |
e64fbb3a JG |
1291 | cs->c_naux = sym->n_numaux & 0xff; |
1292 | if (cs->c_naux >= 1) | |
bd5635a1 | 1293 | { |
d8ce1326 JG |
1294 | fread (temp_aux, local_auxesz, 1, nlist_stream_global); |
1295 | bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass, | |
1296 | (char *)aux); | |
bd5635a1 RP |
1297 | /* If more than one aux entry, read past it (only the first aux |
1298 | is important). */ | |
e64fbb3a | 1299 | for (i = 1; i < cs->c_naux; i++) |
d8ce1326 | 1300 | fread (temp_aux, local_auxesz, 1, nlist_stream_global); |
bd5635a1 RP |
1301 | } |
1302 | cs->c_name = getsymname (sym); | |
1303 | cs->c_value = sym->n_value; | |
1304 | cs->c_sclass = (sym->n_sclass & 0xff); | |
1305 | cs->c_secnum = sym->n_scnum; | |
1306 | cs->c_type = (unsigned) sym->n_type; | |
8714ff35 JK |
1307 | if (!SDB_TYPE (cs->c_type)) |
1308 | cs->c_type = 0; | |
bd5635a1 | 1309 | |
e64fbb3a | 1310 | symnum += 1 + cs->c_naux; |
bd5635a1 RP |
1311 | } |
1312 | \f | |
1313 | /* Support for string table handling */ | |
1314 | ||
1315 | static char *stringtab = NULL; | |
1316 | ||
1317 | static int | |
1318 | init_stringtab (chan, offset) | |
1319 | int chan; | |
1320 | long offset; | |
1321 | { | |
1322 | long length; | |
1323 | int val; | |
1324 | unsigned char lengthbuf[4]; | |
1325 | ||
e09c5e26 | 1326 | free_stringtab (); |
bd5635a1 RP |
1327 | |
1328 | if (lseek (chan, offset, 0) < 0) | |
1329 | return -1; | |
1330 | ||
1331 | val = myread (chan, (char *)lengthbuf, sizeof lengthbuf); | |
dcc35536 | 1332 | length = bfd_h_get_32 (symfile_bfd, lengthbuf); |
bd5635a1 RP |
1333 | |
1334 | /* If no string table is needed, then the file may end immediately | |
1335 | after the symbols. Just return with `stringtab' set to null. */ | |
e09c5e26 | 1336 | if (val != sizeof lengthbuf || length < sizeof lengthbuf) |
bd5635a1 RP |
1337 | return 0; |
1338 | ||
1339 | stringtab = (char *) xmalloc (length); | |
1340 | if (stringtab == NULL) | |
1341 | return -1; | |
1342 | ||
4ed3a9ea | 1343 | memcpy (stringtab, &length, sizeof length); |
bd5635a1 RP |
1344 | if (length == sizeof length) /* Empty table -- just the count */ |
1345 | return 0; | |
1346 | ||
e09c5e26 JK |
1347 | val = myread (chan, stringtab + sizeof lengthbuf, length - sizeof lengthbuf); |
1348 | if (val != length - sizeof lengthbuf || stringtab[length - 1] != '\0') | |
bd5635a1 RP |
1349 | return -1; |
1350 | ||
1351 | return 0; | |
1352 | } | |
1353 | ||
1354 | static void | |
1355 | free_stringtab () | |
1356 | { | |
1357 | if (stringtab) | |
1358 | free (stringtab); | |
1359 | stringtab = NULL; | |
1360 | } | |
1361 | ||
1362 | static char * | |
1363 | getsymname (symbol_entry) | |
dcc35536 | 1364 | struct internal_syment *symbol_entry; |
bd5635a1 RP |
1365 | { |
1366 | static char buffer[SYMNMLEN+1]; | |
1367 | char *result; | |
1368 | ||
dcc35536 | 1369 | if (symbol_entry->_n._n_n._n_zeroes == 0) |
bd5635a1 | 1370 | { |
dcc35536 | 1371 | result = stringtab + symbol_entry->_n._n_n._n_offset; |
bd5635a1 RP |
1372 | } |
1373 | else | |
1374 | { | |
dcc35536 | 1375 | strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN); |
bd5635a1 RP |
1376 | buffer[SYMNMLEN] = '\0'; |
1377 | result = buffer; | |
1378 | } | |
1379 | return result; | |
1380 | } | |
1381 | ||
c653bc6d JG |
1382 | /* Extract the file name from the aux entry of a C_FILE symbol. Return |
1383 | only the last component of the name. Result is in static storage and | |
1384 | is only good for temporary use. */ | |
1385 | ||
bd5635a1 RP |
1386 | static char * |
1387 | getfilename (aux_entry) | |
dcc35536 | 1388 | union internal_auxent *aux_entry; |
bd5635a1 RP |
1389 | { |
1390 | static char buffer[BUFSIZ]; | |
1391 | register char *temp; | |
1392 | char *result; | |
bd5635a1 | 1393 | |
bd5635a1 RP |
1394 | if (aux_entry->x_file.x_n.x_zeroes == 0) |
1395 | strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset); | |
1396 | else | |
bd5635a1 | 1397 | { |
bd5635a1 | 1398 | strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN); |
bd5635a1 RP |
1399 | buffer[FILNMLEN] = '\0'; |
1400 | } | |
1401 | result = buffer; | |
318bf84f | 1402 | if ((temp = strrchr (result, '/')) != NULL) |
bd5635a1 RP |
1403 | result = temp + 1; |
1404 | return (result); | |
1405 | } | |
1406 | \f | |
1407 | /* Support for line number handling */ | |
1408 | static char *linetab = NULL; | |
1409 | static long linetab_offset; | |
1410 | static unsigned long linetab_size; | |
1411 | ||
dcc35536 JG |
1412 | /* Read in all the line numbers for fast lookups later. Leave them in |
1413 | external (unswapped) format in memory; we'll swap them as we enter | |
1414 | them into GDB's data structures. */ | |
bd5635a1 RP |
1415 | |
1416 | static int | |
1417 | init_lineno (chan, offset, size) | |
1418 | int chan; | |
1419 | long offset; | |
1420 | int size; | |
1421 | { | |
1422 | int val; | |
bd5635a1 | 1423 | |
61a7292f SG |
1424 | linetab_offset = offset; |
1425 | linetab_size = size; | |
1426 | ||
e09c5e26 JK |
1427 | free_linetab(); |
1428 | ||
61a7292f SG |
1429 | if (size == 0) |
1430 | return 0; | |
1431 | ||
bd5635a1 RP |
1432 | if (lseek (chan, offset, 0) < 0) |
1433 | return -1; | |
1434 | ||
e64fbb3a JG |
1435 | /* Allocate the desired table, plus a sentinel */ |
1436 | linetab = (char *) xmalloc (size + local_linesz); | |
bd5635a1 | 1437 | |
e09c5e26 JK |
1438 | if (linetab == NULL) |
1439 | return -1; | |
1440 | ||
bd5635a1 RP |
1441 | val = myread (chan, linetab, size); |
1442 | if (val != size) | |
1443 | return -1; | |
1444 | ||
e64fbb3a | 1445 | /* Terminate it with an all-zero sentinel record */ |
4ed3a9ea | 1446 | memset (linetab + size, 0, local_linesz); |
e64fbb3a | 1447 | |
bd5635a1 RP |
1448 | return 0; |
1449 | } | |
1450 | ||
e09c5e26 JK |
1451 | static void |
1452 | free_linetab () | |
1453 | { | |
1454 | if (linetab) | |
1455 | free (linetab); | |
1456 | linetab = NULL; | |
1457 | } | |
1458 | ||
bd5635a1 RP |
1459 | #if !defined (L_LNNO32) |
1460 | #define L_LNNO32(lp) ((lp)->l_lnno) | |
1461 | #endif | |
1462 | ||
1463 | static void | |
1464 | enter_linenos (file_offset, first_line, last_line) | |
1465 | long file_offset; | |
1466 | register int first_line; | |
1467 | register int last_line; | |
1468 | { | |
1469 | register char *rawptr; | |
dcc35536 | 1470 | struct internal_lineno lptr; |
bd5635a1 RP |
1471 | |
1472 | if (file_offset < linetab_offset) | |
1473 | { | |
51b80b00 | 1474 | complain (&lineno_complaint, file_offset); |
63989338 JG |
1475 | if (file_offset > linetab_size) /* Too big to be an offset? */ |
1476 | return; | |
1477 | file_offset += linetab_offset; /* Try reading at that linetab offset */ | |
bd5635a1 RP |
1478 | } |
1479 | ||
1480 | rawptr = &linetab[file_offset - linetab_offset]; | |
1481 | ||
1482 | /* skip first line entry for each function */ | |
d8ce1326 | 1483 | rawptr += local_linesz; |
bd5635a1 RP |
1484 | /* line numbers start at one for the first line of the function */ |
1485 | first_line--; | |
1486 | ||
dcc35536 | 1487 | for (;;) { |
d8ce1326 JG |
1488 | bfd_coff_swap_lineno_in (symfile_bfd, rawptr, &lptr); |
1489 | rawptr += local_linesz; | |
e64fbb3a | 1490 | /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */ |
dcc35536 | 1491 | if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line) |
318bf84f | 1492 | coff_record_line (first_line + L_LNNO32 (&lptr), lptr.l_addr.l_paddr); |
dcc35536 JG |
1493 | else |
1494 | break; | |
1495 | } | |
bd5635a1 RP |
1496 | } |
1497 | \f | |
bd5635a1 RP |
1498 | static void |
1499 | patch_type (type, real_type) | |
1500 | struct type *type; | |
1501 | struct type *real_type; | |
1502 | { | |
1503 | register struct type *target = TYPE_TARGET_TYPE (type); | |
1504 | register struct type *real_target = TYPE_TARGET_TYPE (real_type); | |
1505 | int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field); | |
1506 | ||
1507 | TYPE_LENGTH (target) = TYPE_LENGTH (real_target); | |
1508 | TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target); | |
85f0a848 | 1509 | TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target, field_size); |
bd5635a1 | 1510 | |
4ed3a9ea | 1511 | memcpy (TYPE_FIELDS (target), TYPE_FIELDS (real_target), field_size); |
bd5635a1 RP |
1512 | |
1513 | if (TYPE_NAME (real_target)) | |
1514 | { | |
1515 | if (TYPE_NAME (target)) | |
1516 | free (TYPE_NAME (target)); | |
58ae87f6 | 1517 | TYPE_NAME (target) = concat (TYPE_NAME (real_target), NULL); |
bd5635a1 RP |
1518 | } |
1519 | } | |
1520 | ||
7e258d18 | 1521 | /* Patch up all appropriate typedef symbols in the opaque_type_chains |
f70be3e4 | 1522 | so that they can be used to print out opaque data structures properly. */ |
bd5635a1 | 1523 | |
f70be3e4 JG |
1524 | static void |
1525 | patch_opaque_types (s) | |
318bf84f | 1526 | struct symtab *s; |
318bf84f FF |
1527 | { |
1528 | register struct block *b; | |
1529 | register int i; | |
1530 | register struct symbol *real_sym; | |
1531 | ||
1532 | /* Go through the per-file symbols only */ | |
1533 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); | |
1534 | for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--) | |
bd5635a1 | 1535 | { |
318bf84f FF |
1536 | /* Find completed typedefs to use to fix opaque ones. |
1537 | Remove syms from the chain when their types are stored, | |
1538 | but search the whole chain, as there may be several syms | |
1539 | from different files with the same name. */ | |
1540 | real_sym = BLOCK_SYM (b, i); | |
1541 | if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF && | |
1542 | SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE && | |
1543 | TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR && | |
1544 | TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0) | |
bd5635a1 | 1545 | { |
318bf84f FF |
1546 | register char *name = SYMBOL_NAME (real_sym); |
1547 | register int hash = hashname (name); | |
1548 | register struct symbol *sym, *prev; | |
1549 | ||
1550 | prev = 0; | |
1551 | for (sym = opaque_type_chain[hash]; sym;) | |
bd5635a1 | 1552 | { |
318bf84f | 1553 | if (name[0] == SYMBOL_NAME (sym)[0] && |
c653bc6d | 1554 | STREQ (name + 1, SYMBOL_NAME (sym) + 1)) |
bd5635a1 | 1555 | { |
318bf84f | 1556 | if (prev) |
bd5635a1 | 1557 | { |
318bf84f | 1558 | SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym); |
bd5635a1 RP |
1559 | } |
1560 | else | |
1561 | { | |
318bf84f | 1562 | opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym); |
bd5635a1 | 1563 | } |
318bf84f FF |
1564 | |
1565 | patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym)); | |
1566 | ||
1567 | if (prev) | |
1568 | { | |
1569 | sym = SYMBOL_VALUE_CHAIN (prev); | |
1570 | } | |
1571 | else | |
1572 | { | |
1573 | sym = opaque_type_chain[hash]; | |
1574 | } | |
1575 | } | |
1576 | else | |
1577 | { | |
1578 | prev = sym; | |
1579 | sym = SYMBOL_VALUE_CHAIN (sym); | |
bd5635a1 RP |
1580 | } |
1581 | } | |
1582 | } | |
1583 | } | |
1584 | } | |
1585 | \f | |
bd5635a1 | 1586 | static struct symbol * |
318bf84f | 1587 | process_coff_symbol (cs, aux, objfile) |
bd5635a1 | 1588 | register struct coff_symbol *cs; |
dcc35536 | 1589 | register union internal_auxent *aux; |
318bf84f | 1590 | struct objfile *objfile; |
bd5635a1 RP |
1591 | { |
1592 | register struct symbol *sym | |
c653bc6d JG |
1593 | = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, |
1594 | sizeof (struct symbol)); | |
bd5635a1 | 1595 | char *name; |
318bf84f | 1596 | struct type *temptype; |
bd5635a1 | 1597 | |
4ed3a9ea | 1598 | memset (sym, 0, sizeof (struct symbol)); |
bd5635a1 | 1599 | name = cs->c_name; |
de9bef49 | 1600 | name = EXTERNAL_NAME (name, objfile->obfd); |
c653bc6d JG |
1601 | SYMBOL_NAME (sym) = obstack_copy0 (&objfile->symbol_obstack, name, |
1602 | strlen (name)); | |
bd5635a1 RP |
1603 | |
1604 | /* default assumptions */ | |
1605 | SYMBOL_VALUE (sym) = cs->c_value; | |
1606 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
1607 | ||
1608 | if (ISFCN (cs->c_type)) | |
1609 | { | |
d8ce1326 JG |
1610 | #if 0 |
1611 | /* FIXME: This has NOT been tested. The DBX version has.. */ | |
1612 | /* Generate a template for the type of this function. The | |
1613 | types of the arguments will be added as we read the symbol | |
1614 | table. */ | |
1615 | struct type *new = (struct type *) | |
318bf84f | 1616 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct type)); |
d8ce1326 | 1617 | |
4ed3a9ea | 1618 | memcpy (new, lookup_function_type (decode_function_type (cs, cs->c_type, aux)), |
51b57ded | 1619 | sizeof(struct type)); |
d8ce1326 JG |
1620 | SYMBOL_TYPE (sym) = new; |
1621 | in_function_type = SYMBOL_TYPE(sym); | |
1622 | #else | |
1623 | SYMBOL_TYPE(sym) = | |
1624 | lookup_function_type (decode_function_type (cs, cs->c_type, aux)); | |
1625 | #endif | |
1626 | ||
bd5635a1 RP |
1627 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
1628 | if (cs->c_sclass == C_STAT) | |
318bf84f | 1629 | coff_add_symbol_to_list (sym, &coff_file_symbols); |
bd5635a1 | 1630 | else if (cs->c_sclass == C_EXT) |
318bf84f | 1631 | coff_add_symbol_to_list (sym, &coff_global_symbols); |
bd5635a1 RP |
1632 | } |
1633 | else | |
1634 | { | |
1635 | SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux); | |
1636 | switch (cs->c_sclass) | |
1637 | { | |
1638 | case C_NULL: | |
1639 | break; | |
1640 | ||
1641 | case C_AUTO: | |
1642 | SYMBOL_CLASS (sym) = LOC_LOCAL; | |
318bf84f | 1643 | coff_add_symbol_to_list (sym, &coff_local_symbols); |
bd5635a1 RP |
1644 | break; |
1645 | ||
1646 | case C_EXT: | |
1647 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
1648 | SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value; | |
318bf84f | 1649 | coff_add_symbol_to_list (sym, &coff_global_symbols); |
bd5635a1 RP |
1650 | break; |
1651 | ||
1652 | case C_STAT: | |
1653 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
1654 | SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value; | |
1655 | if (within_function) { | |
1656 | /* Static symbol of local scope */ | |
318bf84f | 1657 | coff_add_symbol_to_list (sym, &coff_local_symbols); |
bd5635a1 RP |
1658 | } |
1659 | else { | |
1660 | /* Static symbol at top level of file */ | |
318bf84f | 1661 | coff_add_symbol_to_list (sym, &coff_file_symbols); |
bd5635a1 RP |
1662 | } |
1663 | break; | |
1664 | ||
d8ce1326 JG |
1665 | #ifdef C_GLBLREG /* AMD coff */ |
1666 | case C_GLBLREG: | |
1667 | #endif | |
bd5635a1 RP |
1668 | case C_REG: |
1669 | SYMBOL_CLASS (sym) = LOC_REGISTER; | |
d8ce1326 | 1670 | SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value); |
318bf84f | 1671 | coff_add_symbol_to_list (sym, &coff_local_symbols); |
bd5635a1 RP |
1672 | break; |
1673 | ||
1674 | case C_LABEL: | |
1675 | break; | |
1676 | ||
1677 | case C_ARG: | |
1678 | SYMBOL_CLASS (sym) = LOC_ARG; | |
d8ce1326 | 1679 | #if 0 |
7e258d18 | 1680 | /* FIXME: This has not been tested. */ |
d8ce1326 JG |
1681 | /* Add parameter to function. */ |
1682 | add_param_to_type(&in_function_type,sym); | |
1683 | #endif | |
318bf84f | 1684 | coff_add_symbol_to_list (sym, &coff_local_symbols); |
f2c365f5 | 1685 | #if !defined (BELIEVE_PCC_PROMOTION) && (TARGET_BYTE_ORDER == BIG_ENDIAN) |
bd5635a1 | 1686 | /* If PCC says a parameter is a short or a char, |
f2c365f5 JK |
1687 | aligned on an int boundary, realign it to the "little end" |
1688 | of the int. */ | |
318bf84f FF |
1689 | temptype = lookup_fundamental_type (current_objfile, FT_INTEGER); |
1690 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype) | |
f2c365f5 JK |
1691 | && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT |
1692 | && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype)) | |
318bf84f | 1693 | { |
f2c365f5 JK |
1694 | SYMBOL_VALUE (sym) += TYPE_LENGTH (temptype) |
1695 | - TYPE_LENGTH (SYMBOL_TYPE (sym)); | |
318bf84f | 1696 | } |
bd5635a1 RP |
1697 | #endif |
1698 | break; | |
1699 | ||
1700 | case C_REGPARM: | |
1701 | SYMBOL_CLASS (sym) = LOC_REGPARM; | |
d8ce1326 | 1702 | SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value); |
318bf84f | 1703 | coff_add_symbol_to_list (sym, &coff_local_symbols); |
bd5635a1 | 1704 | #if !defined (BELIEVE_PCC_PROMOTION) |
f2c365f5 JK |
1705 | /* FIXME: This should retain the current type, since it's just |
1706 | a register value. gnu@adobe, 26Feb93 */ | |
bd5635a1 RP |
1707 | /* If PCC says a parameter is a short or a char, |
1708 | it is really an int. */ | |
318bf84f FF |
1709 | temptype = lookup_fundamental_type (current_objfile, FT_INTEGER); |
1710 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype) | |
1711 | && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT) | |
1712 | { | |
1713 | SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym)) | |
1714 | ? lookup_fundamental_type (current_objfile, | |
1715 | FT_UNSIGNED_INTEGER) | |
1716 | : temptype; | |
1717 | } | |
bd5635a1 RP |
1718 | #endif |
1719 | break; | |
1720 | ||
1721 | case C_TPDEF: | |
1722 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
1723 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
1724 | ||
1725 | /* If type has no name, give it one */ | |
318bf84f FF |
1726 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
1727 | TYPE_NAME (SYMBOL_TYPE (sym)) = concat (SYMBOL_NAME (sym), NULL); | |
bd5635a1 RP |
1728 | |
1729 | /* Keep track of any type which points to empty structured type, | |
f70be3e4 JG |
1730 | so it can be filled from a definition from another file. A |
1731 | simple forward reference (TYPE_CODE_UNDEF) is not an | |
1732 | empty structured type, though; the forward references | |
1733 | work themselves out via the magic of coff_lookup_type. */ | |
bd5635a1 | 1734 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR && |
f70be3e4 JG |
1735 | TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0 && |
1736 | TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) != | |
1737 | TYPE_CODE_UNDEF) | |
bd5635a1 RP |
1738 | { |
1739 | register int i = hashname (SYMBOL_NAME (sym)); | |
1740 | ||
1741 | SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i]; | |
1742 | opaque_type_chain[i] = sym; | |
1743 | } | |
318bf84f | 1744 | coff_add_symbol_to_list (sym, &coff_file_symbols); |
bd5635a1 RP |
1745 | break; |
1746 | ||
1747 | case C_STRTAG: | |
1748 | case C_UNTAG: | |
1749 | case C_ENTAG: | |
1750 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
1751 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; | |
e09c5e26 JK |
1752 | |
1753 | /* Some compilers try to be helpful by inventing "fake" | |
1754 | names for anonymous enums, structures, and unions, like | |
1755 | "~0fake" or ".0fake". Thanks, but no thanks... */ | |
1756 | if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0) | |
1757 | if (SYMBOL_NAME(sym) != NULL | |
1758 | && *SYMBOL_NAME(sym) != '~' | |
1759 | && *SYMBOL_NAME(sym) != '.') | |
1760 | TYPE_TAG_NAME (SYMBOL_TYPE (sym)) = | |
1761 | concat (SYMBOL_NAME (sym), NULL); | |
1762 | ||
318bf84f | 1763 | coff_add_symbol_to_list (sym, &coff_file_symbols); |
bd5635a1 RP |
1764 | break; |
1765 | ||
1766 | default: | |
1767 | break; | |
1768 | } | |
1769 | } | |
1770 | return sym; | |
1771 | } | |
1772 | \f | |
1773 | /* Decode a coff type specifier; | |
1774 | return the type that is meant. */ | |
1775 | ||
1776 | static | |
1777 | struct type * | |
1778 | decode_type (cs, c_type, aux) | |
1779 | register struct coff_symbol *cs; | |
1780 | unsigned int c_type; | |
dcc35536 | 1781 | register union internal_auxent *aux; |
bd5635a1 RP |
1782 | { |
1783 | register struct type *type = 0; | |
1784 | unsigned int new_c_type; | |
1785 | ||
1786 | if (c_type & ~N_BTMASK) | |
1787 | { | |
1788 | new_c_type = DECREF (c_type); | |
1789 | if (ISPTR (c_type)) | |
1790 | { | |
1791 | type = decode_type (cs, new_c_type, aux); | |
1792 | type = lookup_pointer_type (type); | |
1793 | } | |
1794 | else if (ISFCN (c_type)) | |
1795 | { | |
1796 | type = decode_type (cs, new_c_type, aux); | |
1797 | type = lookup_function_type (type); | |
1798 | } | |
1799 | else if (ISARY (c_type)) | |
1800 | { | |
1801 | int i, n; | |
1802 | register unsigned short *dim; | |
a8a69e63 | 1803 | struct type *base_type, *index_type, *range_type; |
bd5635a1 RP |
1804 | |
1805 | /* Define an array type. */ | |
1806 | /* auxent refers to array, not base type */ | |
6988f5c0 | 1807 | if (aux->x_sym.x_tagndx.l == 0) |
e64fbb3a | 1808 | cs->c_naux = 0; |
bd5635a1 RP |
1809 | |
1810 | /* shift the indices down */ | |
1811 | dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0]; | |
1812 | i = 1; | |
1813 | n = dim[0]; | |
1814 | for (i = 0; *dim && i < DIMNUM - 1; i++, dim++) | |
1815 | *dim = *(dim + 1); | |
1816 | *dim = 0; | |
1817 | ||
bd5635a1 | 1818 | base_type = decode_type (cs, new_c_type, aux); |
85f0a848 | 1819 | index_type = lookup_fundamental_type (current_objfile, FT_INTEGER); |
a8a69e63 FF |
1820 | range_type = |
1821 | create_range_type ((struct type *) NULL, index_type, 0, n - 1); | |
1822 | type = | |
1823 | create_array_type ((struct type *) NULL, base_type, range_type); | |
bd5635a1 RP |
1824 | } |
1825 | return type; | |
1826 | } | |
1827 | ||
f70be3e4 JG |
1828 | /* Reference to existing type. This only occurs with the |
1829 | struct, union, and enum types. EPI a29k coff | |
1830 | fakes us out by producing aux entries with a nonzero | |
1831 | x_tagndx for definitions of structs, unions, and enums, so we | |
117f631e ILT |
1832 | have to check the c_sclass field. SCO 3.2v4 cc gets confused |
1833 | with pointers to pointers to defined structs, and generates | |
1834 | negative x_tagndx fields. */ | |
e64fbb3a | 1835 | if (cs->c_naux > 0 && aux->x_sym.x_tagndx.l != 0) |
bd5635a1 | 1836 | { |
117f631e ILT |
1837 | if (cs->c_sclass != C_STRTAG |
1838 | && cs->c_sclass != C_UNTAG | |
1839 | && cs->c_sclass != C_ENTAG | |
1840 | && aux->x_sym.x_tagndx.l >= 0) | |
f70be3e4 JG |
1841 | { |
1842 | type = coff_alloc_type (aux->x_sym.x_tagndx.l); | |
1843 | return type; | |
1844 | } else { | |
1845 | complain (&tagndx_bad_complaint, cs->c_name); | |
1846 | /* And fall through to decode_base_type... */ | |
1847 | } | |
bd5635a1 RP |
1848 | } |
1849 | ||
1850 | return decode_base_type (cs, BTYPE (c_type), aux); | |
1851 | } | |
1852 | ||
1853 | /* Decode a coff type specifier for function definition; | |
1854 | return the type that the function returns. */ | |
1855 | ||
1856 | static | |
1857 | struct type * | |
1858 | decode_function_type (cs, c_type, aux) | |
1859 | register struct coff_symbol *cs; | |
1860 | unsigned int c_type; | |
dcc35536 | 1861 | register union internal_auxent *aux; |
bd5635a1 | 1862 | { |
6988f5c0 | 1863 | if (aux->x_sym.x_tagndx.l == 0) |
e64fbb3a | 1864 | cs->c_naux = 0; /* auxent refers to function, not base type */ |
bd5635a1 RP |
1865 | |
1866 | return decode_type (cs, DECREF (c_type), aux); | |
1867 | } | |
1868 | \f | |
1869 | /* basic C types */ | |
1870 | ||
1871 | static | |
1872 | struct type * | |
1873 | decode_base_type (cs, c_type, aux) | |
1874 | register struct coff_symbol *cs; | |
1875 | unsigned int c_type; | |
dcc35536 | 1876 | register union internal_auxent *aux; |
bd5635a1 RP |
1877 | { |
1878 | struct type *type; | |
1879 | ||
1880 | switch (c_type) | |
1881 | { | |
1882 | case T_NULL: | |
1883 | /* shows up with "void (*foo)();" structure members */ | |
318bf84f | 1884 | return lookup_fundamental_type (current_objfile, FT_VOID); |
bd5635a1 | 1885 | |
8aa13b87 JK |
1886 | #if 0 |
1887 | /* DGUX actually defines both T_ARG and T_VOID to the same value. */ | |
bd5635a1 RP |
1888 | #ifdef T_ARG |
1889 | case T_ARG: | |
1890 | /* Shows up in DGUX, I think. Not sure where. */ | |
318bf84f | 1891 | return lookup_fundamental_type (current_objfile, FT_VOID); /* shouldn't show up here */ |
bd5635a1 | 1892 | #endif |
8aa13b87 | 1893 | #endif /* 0 */ |
bd5635a1 RP |
1894 | |
1895 | #ifdef T_VOID | |
1896 | case T_VOID: | |
1897 | /* Intel 960 COFF has this symbol and meaning. */ | |
318bf84f | 1898 | return lookup_fundamental_type (current_objfile, FT_VOID); |
bd5635a1 RP |
1899 | #endif |
1900 | ||
1901 | case T_CHAR: | |
318bf84f | 1902 | return lookup_fundamental_type (current_objfile, FT_CHAR); |
bd5635a1 RP |
1903 | |
1904 | case T_SHORT: | |
318bf84f | 1905 | return lookup_fundamental_type (current_objfile, FT_SHORT); |
bd5635a1 RP |
1906 | |
1907 | case T_INT: | |
318bf84f | 1908 | return lookup_fundamental_type (current_objfile, FT_INTEGER); |
bd5635a1 RP |
1909 | |
1910 | case T_LONG: | |
318bf84f | 1911 | return lookup_fundamental_type (current_objfile, FT_LONG); |
bd5635a1 RP |
1912 | |
1913 | case T_FLOAT: | |
318bf84f | 1914 | return lookup_fundamental_type (current_objfile, FT_FLOAT); |
bd5635a1 RP |
1915 | |
1916 | case T_DOUBLE: | |
318bf84f | 1917 | return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT); |
bd5635a1 RP |
1918 | |
1919 | case T_STRUCT: | |
e64fbb3a | 1920 | if (cs->c_naux != 1) |
bd5635a1 RP |
1921 | { |
1922 | /* anonymous structure type */ | |
1923 | type = coff_alloc_type (cs->c_symnum); | |
1924 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
e09c5e26 JK |
1925 | TYPE_NAME (type) = NULL; |
1926 | /* This used to set the tag to "<opaque>". But I think setting it | |
1927 | to NULL is right, and the printing code can print it as | |
1928 | "struct {...}". */ | |
1929 | TYPE_TAG_NAME (type) = NULL; | |
be8303da | 1930 | INIT_CPLUS_SPECIFIC(type); |
bd5635a1 RP |
1931 | TYPE_LENGTH (type) = 0; |
1932 | TYPE_FIELDS (type) = 0; | |
1933 | TYPE_NFIELDS (type) = 0; | |
1934 | } | |
1935 | else | |
1936 | { | |
318bf84f | 1937 | type = coff_read_struct_type (cs->c_symnum, |
bd5635a1 | 1938 | aux->x_sym.x_misc.x_lnsz.x_size, |
be8303da | 1939 | aux->x_sym.x_fcnary.x_fcn.x_endndx.l); |
bd5635a1 RP |
1940 | } |
1941 | return type; | |
1942 | ||
1943 | case T_UNION: | |
e64fbb3a | 1944 | if (cs->c_naux != 1) |
bd5635a1 RP |
1945 | { |
1946 | /* anonymous union type */ | |
1947 | type = coff_alloc_type (cs->c_symnum); | |
e09c5e26 JK |
1948 | TYPE_NAME (type) = NULL; |
1949 | /* This used to set the tag to "<opaque>". But I think setting it | |
1950 | to NULL is right, and the printing code can print it as | |
1951 | "union {...}". */ | |
1952 | TYPE_TAG_NAME (type) = NULL; | |
be8303da | 1953 | INIT_CPLUS_SPECIFIC(type); |
f1d77e90 | 1954 | TYPE_LENGTH (type) = 0; |
bd5635a1 RP |
1955 | TYPE_FIELDS (type) = 0; |
1956 | TYPE_NFIELDS (type) = 0; | |
1957 | } | |
1958 | else | |
1959 | { | |
318bf84f | 1960 | type = coff_read_struct_type (cs->c_symnum, |
bd5635a1 | 1961 | aux->x_sym.x_misc.x_lnsz.x_size, |
be8303da | 1962 | aux->x_sym.x_fcnary.x_fcn.x_endndx.l); |
bd5635a1 RP |
1963 | } |
1964 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
1965 | return type; | |
1966 | ||
1967 | case T_ENUM: | |
e09c5e26 JK |
1968 | if (cs->c_naux != 1) |
1969 | { | |
1970 | /* anonymous enum type */ | |
1971 | type = coff_alloc_type (cs->c_symnum); | |
1972 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
1973 | TYPE_NAME (type) = NULL; | |
1974 | /* This used to set the tag to "<opaque>". But I think setting it | |
1975 | to NULL is right, and the printing code can print it as | |
1976 | "enum {...}". */ | |
1977 | TYPE_TAG_NAME (type) = NULL; | |
1978 | TYPE_LENGTH (type) = 0; | |
1979 | TYPE_FIELDS (type) = 0; | |
1980 | TYPE_NFIELDS(type) = 0; | |
1981 | } | |
1982 | else | |
1983 | { | |
1984 | type = coff_read_enum_type (cs->c_symnum, | |
1985 | aux->x_sym.x_misc.x_lnsz.x_size, | |
1986 | aux->x_sym.x_fcnary.x_fcn.x_endndx.l); | |
1987 | } | |
1988 | return type; | |
bd5635a1 RP |
1989 | |
1990 | case T_MOE: | |
1991 | /* shouldn't show up here */ | |
1992 | break; | |
1993 | ||
1994 | case T_UCHAR: | |
318bf84f | 1995 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR); |
bd5635a1 RP |
1996 | |
1997 | case T_USHORT: | |
318bf84f | 1998 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT); |
bd5635a1 RP |
1999 | |
2000 | case T_UINT: | |
318bf84f | 2001 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER); |
bd5635a1 RP |
2002 | |
2003 | case T_ULONG: | |
318bf84f | 2004 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG); |
bd5635a1 | 2005 | } |
7e258d18 | 2006 | complain (&unexpected_type_complaint, cs->c_name); |
318bf84f | 2007 | return lookup_fundamental_type (current_objfile, FT_VOID); |
bd5635a1 RP |
2008 | } |
2009 | \f | |
2010 | /* This page contains subroutines of read_type. */ | |
2011 | ||
2012 | /* Read the description of a structure (or union type) | |
2013 | and return an object describing the type. */ | |
2014 | ||
2015 | static struct type * | |
318bf84f | 2016 | coff_read_struct_type (index, length, lastsym) |
bd5635a1 RP |
2017 | int index; |
2018 | int length; | |
2019 | int lastsym; | |
2020 | { | |
2021 | struct nextfield | |
2022 | { | |
2023 | struct nextfield *next; | |
2024 | struct field field; | |
2025 | }; | |
2026 | ||
2027 | register struct type *type; | |
2028 | register struct nextfield *list = 0; | |
2029 | struct nextfield *new; | |
2030 | int nfields = 0; | |
2031 | register int n; | |
2032 | char *name; | |
bd5635a1 RP |
2033 | struct coff_symbol member_sym; |
2034 | register struct coff_symbol *ms = &member_sym; | |
dcc35536 JG |
2035 | struct internal_syment sub_sym; |
2036 | union internal_auxent sub_aux; | |
bd5635a1 RP |
2037 | int done = 0; |
2038 | ||
2039 | type = coff_alloc_type (index); | |
2040 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
be8303da | 2041 | INIT_CPLUS_SPECIFIC(type); |
bd5635a1 RP |
2042 | TYPE_LENGTH (type) = length; |
2043 | ||
2044 | while (!done && symnum < lastsym && symnum < nlist_nsyms_global) | |
2045 | { | |
2046 | read_one_sym (ms, &sub_sym, &sub_aux); | |
2047 | name = ms->c_name; | |
de9bef49 | 2048 | name = EXTERNAL_NAME (name, current_objfile->obfd); |
bd5635a1 RP |
2049 | |
2050 | switch (ms->c_sclass) | |
2051 | { | |
2052 | case C_MOS: | |
2053 | case C_MOU: | |
2054 | ||
2055 | /* Get space to record the next field's data. */ | |
2056 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
2057 | new->next = list; | |
2058 | list = new; | |
2059 | ||
2060 | /* Save the data. */ | |
2061 | list->field.name = savestring (name, strlen (name)); | |
2062 | list->field.type = decode_type (ms, ms->c_type, &sub_aux); | |
2063 | list->field.bitpos = 8 * ms->c_value; | |
2064 | list->field.bitsize = 0; | |
2065 | nfields++; | |
2066 | break; | |
2067 | ||
2068 | case C_FIELD: | |
2069 | ||
2070 | /* Get space to record the next field's data. */ | |
2071 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
2072 | new->next = list; | |
2073 | list = new; | |
2074 | ||
2075 | /* Save the data. */ | |
2076 | list->field.name = savestring (name, strlen (name)); | |
2077 | list->field.type = decode_type (ms, ms->c_type, &sub_aux); | |
2078 | list->field.bitpos = ms->c_value; | |
2079 | list->field.bitsize = sub_aux.x_sym.x_misc.x_lnsz.x_size; | |
2080 | nfields++; | |
2081 | break; | |
2082 | ||
2083 | case C_EOS: | |
2084 | done = 1; | |
2085 | break; | |
2086 | } | |
2087 | } | |
2088 | /* Now create the vector of fields, and record how big it is. */ | |
2089 | ||
2090 | TYPE_NFIELDS (type) = nfields; | |
2091 | TYPE_FIELDS (type) = (struct field *) | |
85f0a848 | 2092 | TYPE_ALLOC (type, sizeof (struct field) * nfields); |
bd5635a1 RP |
2093 | |
2094 | /* Copy the saved-up fields into the field vector. */ | |
2095 | ||
2096 | for (n = nfields; list; list = list->next) | |
2097 | TYPE_FIELD (type, --n) = list->field; | |
2098 | ||
2099 | return type; | |
2100 | } | |
2101 | \f | |
2102 | /* Read a definition of an enumeration type, | |
2103 | and create and return a suitable type object. | |
2104 | Also defines the symbols that represent the values of the type. */ | |
2105 | ||
61a7292f | 2106 | /* ARGSUSED */ |
bd5635a1 | 2107 | static struct type * |
318bf84f | 2108 | coff_read_enum_type (index, length, lastsym) |
bd5635a1 RP |
2109 | int index; |
2110 | int length; | |
2111 | int lastsym; | |
2112 | { | |
2113 | register struct symbol *sym; | |
2114 | register struct type *type; | |
2115 | int nsyms = 0; | |
2116 | int done = 0; | |
318bf84f | 2117 | struct coff_pending **symlist; |
bd5635a1 RP |
2118 | struct coff_symbol member_sym; |
2119 | register struct coff_symbol *ms = &member_sym; | |
dcc35536 JG |
2120 | struct internal_syment sub_sym; |
2121 | union internal_auxent sub_aux; | |
318bf84f | 2122 | struct coff_pending *osyms, *syms; |
bd5635a1 RP |
2123 | register int n; |
2124 | char *name; | |
bd5635a1 RP |
2125 | |
2126 | type = coff_alloc_type (index); | |
2127 | if (within_function) | |
318bf84f | 2128 | symlist = &coff_local_symbols; |
bd5635a1 | 2129 | else |
318bf84f | 2130 | symlist = &coff_file_symbols; |
bd5635a1 RP |
2131 | osyms = *symlist; |
2132 | ||
2133 | while (!done && symnum < lastsym && symnum < nlist_nsyms_global) | |
2134 | { | |
2135 | read_one_sym (ms, &sub_sym, &sub_aux); | |
2136 | name = ms->c_name; | |
de9bef49 | 2137 | name = EXTERNAL_NAME (name, current_objfile->obfd); |
bd5635a1 RP |
2138 | |
2139 | switch (ms->c_sclass) | |
2140 | { | |
2141 | case C_MOE: | |
2142 | sym = (struct symbol *) xmalloc (sizeof (struct symbol)); | |
4ed3a9ea | 2143 | memset (sym, 0, sizeof (struct symbol)); |
bd5635a1 RP |
2144 | |
2145 | SYMBOL_NAME (sym) = savestring (name, strlen (name)); | |
2146 | SYMBOL_CLASS (sym) = LOC_CONST; | |
2147 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
2148 | SYMBOL_VALUE (sym) = ms->c_value; | |
318bf84f | 2149 | coff_add_symbol_to_list (sym, symlist); |
bd5635a1 RP |
2150 | nsyms++; |
2151 | break; | |
2152 | ||
2153 | case C_EOS: | |
2154 | /* Sometimes the linker (on 386/ix 2.0.2 at least) screws | |
2155 | up the count of how many symbols to read. So stop | |
2156 | on .eos. */ | |
2157 | done = 1; | |
2158 | break; | |
2159 | } | |
2160 | } | |
2161 | ||
2162 | /* Now fill in the fields of the type-structure. */ | |
2163 | ||
f2c365f5 JK |
2164 | if (length > 0) |
2165 | TYPE_LENGTH (type) = length; | |
2166 | else | |
2167 | TYPE_LENGTH (type) = TARGET_INT_BIT / TARGET_CHAR_BIT; /* Assume ints */ | |
bd5635a1 RP |
2168 | TYPE_CODE (type) = TYPE_CODE_ENUM; |
2169 | TYPE_NFIELDS (type) = nsyms; | |
2170 | TYPE_FIELDS (type) = (struct field *) | |
85f0a848 | 2171 | TYPE_ALLOC (type, sizeof (struct field) * nsyms); |
bd5635a1 RP |
2172 | |
2173 | /* Find the symbols for the values and put them into the type. | |
2174 | The symbols can be found in the symlist that we put them on | |
2175 | to cause them to be defined. osyms contains the old value | |
2176 | of that symlist; everything up to there was defined by us. */ | |
2177 | ||
2178 | for (syms = *symlist, n = nsyms; syms != osyms; syms = syms->next) | |
2179 | { | |
2180 | SYMBOL_TYPE (syms->symbol) = type; | |
2181 | TYPE_FIELD_NAME (type, --n) = SYMBOL_NAME (syms->symbol); | |
2182 | TYPE_FIELD_VALUE (type, n) = 0; | |
2183 | TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (syms->symbol); | |
2184 | TYPE_FIELD_BITSIZE (type, n) = 0; | |
2185 | } | |
e09c5e26 JK |
2186 | #if 0 |
2187 | /* This screws up perfectly good C programs with enums. FIXME. */ | |
d8ce1326 JG |
2188 | /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */ |
2189 | if(TYPE_NFIELDS(type) == 2 && | |
c653bc6d JG |
2190 | ((STREQ(TYPE_FIELD_NAME(type,0),"TRUE") && |
2191 | STREQ(TYPE_FIELD_NAME(type,1),"FALSE")) || | |
2192 | (STREQ(TYPE_FIELD_NAME(type,1),"TRUE") && | |
2193 | STREQ(TYPE_FIELD_NAME(type,0),"FALSE")))) | |
d8ce1326 | 2194 | TYPE_CODE(type) = TYPE_CODE_BOOL; |
e09c5e26 | 2195 | #endif |
bd5635a1 RP |
2196 | return type; |
2197 | } | |
2198 | ||
85f0a848 FF |
2199 | /* Fake up support for relocating symbol addresses. FIXME. */ |
2200 | ||
2201 | struct section_offsets coff_symfile_faker = {0}; | |
2202 | ||
2203 | struct section_offsets * | |
2204 | coff_symfile_offsets (objfile, addr) | |
2205 | struct objfile *objfile; | |
2206 | CORE_ADDR addr; | |
2207 | { | |
2208 | return &coff_symfile_faker; | |
2209 | } | |
2210 | ||
bd5635a1 RP |
2211 | /* Register our ability to parse symbols for coff BFD files */ |
2212 | ||
2213 | static struct sym_fns coff_sym_fns = | |
2214 | { | |
80d68b1d FF |
2215 | "coff", /* sym_name: name or name prefix of BFD target type */ |
2216 | 4, /* sym_namelen: number of significant sym_name chars */ | |
2217 | coff_new_init, /* sym_new_init: init anything gbl to entire symtab */ | |
2218 | coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
2219 | coff_symfile_read, /* sym_read: read a symbol file into symtab */ | |
2220 | coff_symfile_finish, /* sym_finish: finished with file, cleanup */ | |
85f0a848 | 2221 | coff_symfile_offsets, /* sym_offsets: xlate external to internal form */ |
80d68b1d | 2222 | NULL /* next: pointer to next struct sym_fns */ |
bd5635a1 RP |
2223 | }; |
2224 | ||
2225 | void | |
2226 | _initialize_coffread () | |
2227 | { | |
2228 | add_symtab_fns(&coff_sym_fns); | |
2229 | } |