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