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