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