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