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