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