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