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