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