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