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