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