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