Change defn of LOCAL_LABEL_PREFIX to ""
[external/binutils.git] / gdb / xcoffread.c
1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2    Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
3    Free Software Foundation, Inc.
4    Derived from coffread.c, dbxread.c, and a lot of hacking.
5    Contributed by IBM Corporation.
6
7    This file is part of GDB.
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 59 Temple Place - Suite 330,
22    Boston, MA 02111-1307, USA.  */
23
24 #include "defs.h"
25 #include "bfd.h"
26
27 #include <sys/types.h>
28 #include <fcntl.h>
29 #include <ctype.h>
30 #include "gdb_string.h"
31
32 #include <sys/param.h>
33 #ifndef NO_SYS_FILE
34 #include <sys/file.h>
35 #endif
36 #include "gdb_stat.h"
37
38 #include "coff/internal.h"
39 #include "libcoff.h"            /* FIXME, internal data from BFD */
40 #include "coff/rs6000.h"
41
42 #include "symtab.h"
43 #include "gdbtypes.h"
44 #include "symfile.h"
45 #include "objfiles.h"
46 #include "buildsym.h"
47 #include "stabsread.h"
48 #include "expression.h"
49 #include "language.h"           /* Needed inside partial-stab.h */
50 #include "complaints.h"
51
52 #include "gdb-stabs.h"
53
54 /* For interface with stabsread.c.  */
55 #include "aout/stab_gnu.h"
56
57 /* For interface with partial-stab.h.  */
58 #define N_UNDF  0               /* Undefined symbol */
59 #undef N_ABS
60 #define N_ABS 2
61 #define N_TEXT  4               /* Text sym -- defined at offset in text seg */
62 #define N_DATA  6               /* Data sym -- defined at offset in data seg */
63 #define N_BSS   8               /* BSS  sym -- defined at offset in zero'd seg */
64 #define N_COMM  0x12            /* Common symbol (visible after shared lib dynlink) */
65 #define N_FN    0x1f            /* File name of .o file */
66 #define N_FN_SEQ 0x0C           /* N_FN from Sequent compilers (sigh) */
67 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
68    N_DATA, or N_BSS.  When the low-order bit of other types is set,
69    (e.g. N_WARNING versus N_FN), they are two different types.  */
70 #define N_EXT   1               /* External symbol (as opposed to local-to-this-file) */
71 #define N_INDR 0x0a
72
73 /* The following symbols refer to set elements.
74    All the N_SET[ATDB] symbols with the same name form one set.
75    Space is allocated for the set in the text section, and each set
76    elements value is stored into one word of the space.
77    The first word of the space is the length of the set (number of elements).
78
79    The address of the set is made into an N_SETV symbol
80    whose name is the same as the name of the set.
81    This symbol acts like a N_DATA global symbol
82    in that it can satisfy undefined external references.  */
83
84 /* These appear as input to LD, in a .o file.  */
85 #define N_SETA  0x14            /* Absolute set element symbol */
86 #define N_SETT  0x16            /* Text set element symbol */
87 #define N_SETD  0x18            /* Data set element symbol */
88 #define N_SETB  0x1A            /* Bss set element symbol */
89
90 /* This is output from LD.  */
91 #define N_SETV  0x1C            /* Pointer to set vector in data area.  */
92 \f
93 /* We put a pointer to this structure in the read_symtab_private field
94    of the psymtab.  */
95
96 struct symloc
97   {
98
99     /* First symbol number for this file.  */
100
101     int first_symnum;
102
103     /* Number of symbols in the section of the symbol table devoted to
104        this file's symbols (actually, the section bracketed may contain
105        more than just this file's symbols).  If numsyms is 0, the only
106        reason for this thing's existence is the dependency list.  Nothing
107        else will happen when it is read in.  */
108
109     int numsyms;
110
111     /* Position of the start of the line number information for this psymtab.  */
112     unsigned int lineno_off;
113   };
114
115 /* Remember what we deduced to be the source language of this psymtab. */
116
117 static enum language psymtab_language = language_unknown;
118 \f
119
120 /* Simplified internal version of coff symbol table information */
121
122 struct coff_symbol
123   {
124     char *c_name;
125     int c_symnum;               /* symbol number of this entry */
126     int c_naux;                 /* 0 if syment only, 1 if syment + auxent */
127     long c_value;
128     unsigned char c_sclass;
129     int c_secnum;
130     unsigned int c_type;
131   };
132
133 /* last function's saved coff symbol `cs' */
134
135 static struct coff_symbol fcn_cs_saved;
136
137 static bfd *symfile_bfd;
138
139 /* Core address of start and end of text of current source file.
140    This is calculated from the first function seen after a C_FILE
141    symbol. */
142
143
144 static CORE_ADDR cur_src_end_addr;
145
146 /* Core address of the end of the first object file.  */
147
148 static CORE_ADDR first_object_file_end;
149
150 /* initial symbol-table-debug-string vector length */
151
152 #define INITIAL_STABVECTOR_LENGTH       40
153
154 /* Nonzero if within a function (so symbols should be local,
155    if nothing says specifically).  */
156
157 int within_function;
158
159 /* Size of a COFF symbol.  I think it is always 18, so I'm not sure
160    there is any reason not to just use a #define, but might as well
161    ask BFD for the size and store it here, I guess.  */
162
163 static unsigned local_symesz;
164
165 struct coff_symfile_info
166   {
167     file_ptr min_lineno_offset; /* Where in file lowest line#s are */
168     file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
169
170     /* Pointer to the string table.  */
171     char *strtbl;
172
173     /* Pointer to debug section.  */
174     char *debugsec;
175
176     /* Pointer to the a.out symbol table.  */
177     char *symtbl;
178
179     /* Number of symbols in symtbl.  */
180     int symtbl_num_syms;
181
182     /* Offset in data section to TOC anchor.  */
183     CORE_ADDR toc_offset;
184   };
185
186 static struct complaint storclass_complaint =
187 {"Unexpected storage class: %d", 0, 0};
188
189 static struct complaint bf_notfound_complaint =
190 {"line numbers off, `.bf' symbol not found", 0, 0};
191
192 static struct complaint ef_complaint =
193 {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
194
195 static struct complaint eb_complaint =
196 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
197
198 static void xcoff_initial_scan (struct objfile *, int);
199
200 static void scan_xcoff_symtab (struct objfile *);
201
202 static char *xcoff_next_symbol_text (struct objfile *);
203
204 static void record_include_begin (struct coff_symbol *);
205
206 static void
207 enter_line_range (struct subfile *, unsigned, unsigned,
208                   CORE_ADDR, CORE_ADDR, unsigned *);
209
210 static void init_stringtab (bfd *, file_ptr, struct objfile *);
211
212 static void xcoff_symfile_init (struct objfile *);
213
214 static void xcoff_new_init (struct objfile *);
215
216 static void xcoff_symfile_finish (struct objfile *);
217
218 static void
219 xcoff_symfile_offsets (struct objfile *, struct section_addr_info *addrs);
220
221 static void find_linenos (bfd *, sec_ptr, PTR);
222
223 static char *coff_getfilename (union internal_auxent *, struct objfile *);
224
225 static void read_symbol (struct internal_syment *, int);
226
227 static int read_symbol_lineno (int);
228
229 static CORE_ADDR read_symbol_nvalue (int);
230
231 static struct symbol *process_xcoff_symbol (struct coff_symbol *,
232                                             struct objfile *);
233
234 static void read_xcoff_symtab (struct partial_symtab *);
235
236 #if 0
237 static void add_stab_to_list (char *, struct pending_stabs **);
238 #endif
239
240 static int compare_lte (const void *, const void *);
241
242 static struct linetable *arrange_linetable (struct linetable *);
243
244 static void record_include_end (struct coff_symbol *);
245
246 static void process_linenos (CORE_ADDR, CORE_ADDR);
247 \f
248
249 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
250    code.  */
251 static int secnum_to_section (int, struct objfile *);
252 static asection *secnum_to_bfd_section (int, struct objfile *);
253
254 struct find_targ_sec_arg
255   {
256     int targ_index;
257     int *resultp;
258     asection **bfd_sect;
259     struct objfile *objfile;
260   };
261
262 static void find_targ_sec (bfd *, asection *, void *);
263
264 static void
265 find_targ_sec (bfd *abfd, asection *sect, PTR obj)
266 {
267   struct find_targ_sec_arg *args = (struct find_targ_sec_arg *) obj;
268   struct objfile *objfile = args->objfile;
269   if (sect->target_index == args->targ_index)
270     {
271       /* This is the section.  Figure out what SECT_OFF_* code it is.  */
272       if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
273         *args->resultp = SECT_OFF_TEXT (objfile);
274       else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
275         *args->resultp = SECT_OFF_DATA (objfile);
276       else
277         *args->resultp = sect->index;
278       *args->bfd_sect = sect;
279     }
280 }
281
282 /* Return the section number (SECT_OFF_*) that CS points to.  */
283 static int
284 secnum_to_section (int secnum, struct objfile *objfile)
285 {
286   int off = SECT_OFF_TEXT (objfile);
287   asection *sect = NULL;
288   struct find_targ_sec_arg args;
289   args.targ_index = secnum;
290   args.resultp = &off;
291   args.bfd_sect = &sect;
292   args.objfile = objfile;
293   bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
294   return off;
295 }
296
297 /* Return the BFD section that CS points to.  */
298 static asection *
299 secnum_to_bfd_section (int secnum, struct objfile *objfile)
300 {
301   int off = SECT_OFF_TEXT (objfile);
302   asection *sect = NULL;
303   struct find_targ_sec_arg args;
304   args.targ_index = secnum;
305   args.resultp = &off;
306   args.bfd_sect = &sect;
307   args.objfile = objfile;
308   bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
309   return sect;
310 }
311 \f
312 /* add a given stab string into given stab vector. */
313
314 #if 0
315
316 static void
317 add_stab_to_list (char *stabname, struct pending_stabs **stabvector)
318 {
319   if (*stabvector == NULL)
320     {
321       *stabvector = (struct pending_stabs *)
322         xmalloc (sizeof (struct pending_stabs) +
323                  INITIAL_STABVECTOR_LENGTH * sizeof (char *));
324       (*stabvector)->count = 0;
325       (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
326     }
327   else if ((*stabvector)->count >= (*stabvector)->length)
328     {
329       (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
330       *stabvector = (struct pending_stabs *)
331         xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
332                     (*stabvector)->length * sizeof (char *));
333     }
334   (*stabvector)->stab[(*stabvector)->count++] = stabname;
335 }
336
337 #endif
338 \f/* *INDENT-OFF* */
339 /* Linenos are processed on a file-by-file basis.
340
341    Two reasons:
342
343    1) xlc (IBM's native c compiler) postpones static function code
344    emission to the end of a compilation unit. This way it can
345    determine if those functions (statics) are needed or not, and
346    can do some garbage collection (I think). This makes line
347    numbers and corresponding addresses unordered, and we end up
348    with a line table like:
349
350
351    lineno       addr
352    foo()          10    0x100
353    20   0x200
354    30   0x300
355
356    foo3()         70    0x400
357    80   0x500
358    90   0x600
359
360    static foo2()
361    40   0x700
362    50   0x800
363    60   0x900           
364
365    and that breaks gdb's binary search on line numbers, if the
366    above table is not sorted on line numbers. And that sort
367    should be on function based, since gcc can emit line numbers
368    like:
369
370    10   0x100   - for the init/test part of a for stmt.
371    20   0x200
372    30   0x300
373    10   0x400   - for the increment part of a for stmt.
374
375    arrange_linetable() will do this sorting.            
376
377    2)   aix symbol table might look like:
378
379    c_file               // beginning of a new file
380    .bi          // beginning of include file
381    .ei          // end of include file
382    .bi
383    .ei
384
385    basically, .bi/.ei pairs do not necessarily encapsulate
386    their scope. They need to be recorded, and processed later
387    on when we come the end of the compilation unit.
388    Include table (inclTable) and process_linenos() handle
389    that.  */
390 /* *INDENT-ON* */
391
392
393
394 /* compare line table entry addresses. */
395
396 static int
397 compare_lte (const void *lte1p, const void *lte2p)
398 {
399   struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
400   struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
401   return lte1->pc - lte2->pc;
402 }
403
404 /* Given a line table with function entries are marked, arrange its functions
405    in ascending order and strip off function entry markers and return it in
406    a newly created table. If the old one is good enough, return the old one. */
407 /* FIXME: I think all this stuff can be replaced by just passing
408    sort_linevec = 1 to end_symtab.  */
409
410 static struct linetable *
411 arrange_linetable (struct linetable *oldLineTb)
412 {
413   int ii, jj, newline,          /* new line count */
414     function_count;             /* # of functions */
415
416   struct linetable_entry *fentry;       /* function entry vector */
417   int fentry_size;              /* # of function entries */
418   struct linetable *newLineTb;  /* new line table */
419
420 #define NUM_OF_FUNCTIONS 20
421
422   fentry_size = NUM_OF_FUNCTIONS;
423   fentry = (struct linetable_entry *)
424     xmalloc (fentry_size * sizeof (struct linetable_entry));
425
426   for (function_count = 0, ii = 0; ii < oldLineTb->nitems; ++ii)
427     {
428
429       if (oldLineTb->item[ii].line == 0)
430         {                       /* function entry found. */
431
432           if (function_count >= fentry_size)
433             {                   /* make sure you have room. */
434               fentry_size *= 2;
435               fentry = (struct linetable_entry *)
436                 xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
437             }
438           fentry[function_count].line = ii;
439           fentry[function_count].pc = oldLineTb->item[ii].pc;
440           ++function_count;
441         }
442     }
443
444   if (function_count == 0)
445     {
446       xfree (fentry);
447       return oldLineTb;
448     }
449   else if (function_count > 1)
450     qsort (fentry, function_count, sizeof (struct linetable_entry), compare_lte);
451
452   /* allocate a new line table. */
453   newLineTb = (struct linetable *)
454     xmalloc
455     (sizeof (struct linetable) +
456     (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
457
458   /* if line table does not start with a function beginning, copy up until
459      a function begin. */
460
461   newline = 0;
462   if (oldLineTb->item[0].line != 0)
463     for (newline = 0;
464     newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
465       newLineTb->item[newline] = oldLineTb->item[newline];
466
467   /* Now copy function lines one by one. */
468
469   for (ii = 0; ii < function_count; ++ii)
470     {
471       for (jj = fentry[ii].line + 1;
472            jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
473            ++jj, ++newline)
474         newLineTb->item[newline] = oldLineTb->item[jj];
475     }
476   xfree (fentry);
477   newLineTb->nitems = oldLineTb->nitems - function_count;
478   return newLineTb;
479 }
480
481 /* include file support: C_BINCL/C_EINCL pairs will be kept in the 
482    following `IncludeChain'. At the end of each symtab (end_symtab),
483    we will determine if we should create additional symtab's to
484    represent if (the include files. */
485
486
487 typedef struct _inclTable
488 {
489   char *name;                   /* include filename */
490
491   /* Offsets to the line table.  end points to the last entry which is
492      part of this include file.  */
493   int begin, end;
494
495   struct subfile *subfile;
496   unsigned funStartLine;        /* start line # of its function */
497 }
498 InclTable;
499
500 #define INITIAL_INCLUDE_TABLE_LENGTH    20
501 static InclTable *inclTable;    /* global include table */
502 static int inclIndx;            /* last entry to table */
503 static int inclLength;          /* table length */
504 static int inclDepth;           /* nested include depth */
505
506 static void allocate_include_entry (void);
507
508 static void
509 record_include_begin (struct coff_symbol *cs)
510 {
511   if (inclDepth)
512     {
513       /* In xcoff, we assume include files cannot be nested (not in .c files
514          of course, but in corresponding .s files.).  */
515
516       /* This can happen with old versions of GCC.
517          GCC 2.3.3-930426 does not exhibit this on a test case which
518          a user said produced the message for him.  */
519       static struct complaint msg =
520       {"Nested C_BINCL symbols", 0, 0};
521       complain (&msg);
522     }
523   ++inclDepth;
524
525   allocate_include_entry ();
526
527   inclTable[inclIndx].name = cs->c_name;
528   inclTable[inclIndx].begin = cs->c_value;
529 }
530
531 static void
532 record_include_end (struct coff_symbol *cs)
533 {
534   InclTable *pTbl;
535
536   if (inclDepth == 0)
537     {
538       static struct complaint msg =
539       {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
540       complain (&msg);
541     }
542
543   allocate_include_entry ();
544
545   pTbl = &inclTable[inclIndx];
546   pTbl->end = cs->c_value;
547
548   --inclDepth;
549   ++inclIndx;
550 }
551
552 static void
553 allocate_include_entry (void)
554 {
555   if (inclTable == NULL)
556     {
557       inclTable = (InclTable *)
558         xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
559       memset (inclTable,
560               '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
561       inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
562       inclIndx = 0;
563     }
564   else if (inclIndx >= inclLength)
565     {
566       inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
567       inclTable = (InclTable *)
568         xrealloc (inclTable, sizeof (InclTable) * inclLength);
569       memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
570               '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
571     }
572 }
573
574 /* Global variable to pass the psymtab down to all the routines involved
575    in psymtab to symtab processing.  */
576 static struct partial_symtab *this_symtab_psymtab;
577
578 /* given the start and end addresses of a compilation unit (or a csect,
579    at times) process its lines and create appropriate line vectors. */
580
581 static void
582 process_linenos (CORE_ADDR start, CORE_ADDR end)
583 {
584   int offset, ii;
585   file_ptr max_offset =
586   ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
587   ->max_lineno_offset;
588
589   /* subfile structure for the main compilation unit.  */
590   struct subfile main_subfile;
591
592   /* In the main source file, any time we see a function entry, we
593      reset this variable to function's absolute starting line number.
594      All the following line numbers in the function are relative to
595      this, and we record absolute line numbers in record_line().  */
596
597   unsigned int main_source_baseline = 0;
598
599   unsigned *firstLine;
600
601   offset =
602     ((struct symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off;
603   if (offset == 0)
604     goto return_after_cleanup;
605
606   memset (&main_subfile, '\0', sizeof (main_subfile));
607
608   if (inclIndx == 0)
609     /* All source lines were in the main source file. None in include files. */
610
611     enter_line_range (&main_subfile, offset, 0, start, end,
612                       &main_source_baseline);
613
614   else
615     {
616       /* There was source with line numbers in include files.  */
617
618       int linesz =
619         coff_data (this_symtab_psymtab->objfile->obfd)->local_linesz;
620       main_source_baseline = 0;
621
622       for (ii = 0; ii < inclIndx; ++ii)
623         {
624           struct subfile *tmpSubfile;
625
626           /* If there is main file source before include file, enter it.  */
627           if (offset < inclTable[ii].begin)
628             {
629               enter_line_range
630                 (&main_subfile, offset, inclTable[ii].begin - linesz,
631                  start, 0, &main_source_baseline);
632             }
633
634           /* Have a new subfile for the include file.  */
635
636           tmpSubfile = inclTable[ii].subfile =
637             (struct subfile *) xmalloc (sizeof (struct subfile));
638
639           memset (tmpSubfile, '\0', sizeof (struct subfile));
640           firstLine = &(inclTable[ii].funStartLine);
641
642           /* Enter include file's lines now.  */
643           enter_line_range (tmpSubfile, inclTable[ii].begin,
644                             inclTable[ii].end, start, 0, firstLine);
645
646           if (offset <= inclTable[ii].end)
647             offset = inclTable[ii].end + linesz;
648         }
649
650       /* All the include files' line have been processed at this point.  Now,
651          enter remaining lines of the main file, if any left.  */
652       if (offset < max_offset + 1 - linesz)
653         {
654           enter_line_range (&main_subfile, offset, 0, start, end,
655                             &main_source_baseline);
656         }
657     }
658
659   /* Process main file's line numbers.  */
660   if (main_subfile.line_vector)
661     {
662       struct linetable *lineTb, *lv;
663
664       lv = main_subfile.line_vector;
665
666       /* Line numbers are not necessarily ordered. xlc compilation will
667          put static function to the end. */
668
669       lineTb = arrange_linetable (lv);
670       if (lv == lineTb)
671         {
672           current_subfile->line_vector = (struct linetable *)
673             xrealloc (lv, (sizeof (struct linetable)
674                            + lv->nitems * sizeof (struct linetable_entry)));
675         }
676       else
677         {
678           xfree (lv);
679           current_subfile->line_vector = lineTb;
680         }
681
682       current_subfile->line_vector_length =
683         current_subfile->line_vector->nitems;
684     }
685
686   /* Now, process included files' line numbers.  */
687
688   for (ii = 0; ii < inclIndx; ++ii)
689     {
690       if ((inclTable[ii].subfile)->line_vector)         /* Useless if!!! FIXMEmgo */
691         {
692           struct linetable *lineTb, *lv;
693
694           lv = (inclTable[ii].subfile)->line_vector;
695
696           /* Line numbers are not necessarily ordered. xlc compilation will
697              put static function to the end. */
698
699           lineTb = arrange_linetable (lv);
700
701           push_subfile ();
702
703           /* For the same include file, we might want to have more than one
704              subfile.  This happens if we have something like:
705
706              ......
707              #include "foo.h"
708              ......
709              #include "foo.h"
710              ......
711
712              while foo.h including code in it. (stupid but possible)
713              Since start_subfile() looks at the name and uses an
714              existing one if finds, we need to provide a fake name and
715              fool it.  */
716
717 #if 0
718           start_subfile (inclTable[ii].name, (char *) 0);
719 #else
720           {
721             /* Pick a fake name that will produce the same results as this
722                one when passed to deduce_language_from_filename.  Kludge on
723                top of kludge.  */
724             char *fakename = strrchr (inclTable[ii].name, '.');
725             if (fakename == NULL)
726               fakename = " ?";
727             start_subfile (fakename, (char *) 0);
728             xfree (current_subfile->name);
729           }
730           current_subfile->name = xstrdup (inclTable[ii].name);
731 #endif
732
733           if (lv == lineTb)
734             {
735               current_subfile->line_vector =
736                 (struct linetable *) xrealloc
737                 (lv, (sizeof (struct linetable)
738                       + lv->nitems * sizeof (struct linetable_entry)));
739
740             }
741           else
742             {
743               xfree (lv);
744               current_subfile->line_vector = lineTb;
745             }
746
747           current_subfile->line_vector_length =
748             current_subfile->line_vector->nitems;
749           start_subfile (pop_subfile (), (char *) 0);
750         }
751     }
752
753 return_after_cleanup:
754
755   /* We don't want to keep alloc/free'ing the global include file table.  */
756   inclIndx = 0;
757
758   /* Start with a fresh subfile structure for the next file.  */
759   memset (&main_subfile, '\0', sizeof (struct subfile));
760 }
761
762 void
763 aix_process_linenos (void)
764 {
765   /* process line numbers and enter them into line vector */
766   process_linenos (last_source_start_addr, cur_src_end_addr);
767 }
768
769
770 /* Enter a given range of lines into the line vector.
771    can be called in the following two ways:
772    enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine)  or
773    enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
774
775    endoffset points to the last line table entry that we should pay
776    attention to.  */
777
778 static void
779 enter_line_range (struct subfile *subfile, unsigned beginoffset, unsigned endoffset,    /* offsets to line table */
780                   CORE_ADDR startaddr,  /* offsets to line table */
781                   CORE_ADDR endaddr, unsigned *firstLine)
782 {
783   unsigned int curoffset;
784   CORE_ADDR addr;
785   void *ext_lnno;
786   struct internal_lineno int_lnno;
787   unsigned int limit_offset;
788   bfd *abfd;
789   int linesz;
790
791   if (endoffset == 0 && startaddr == 0 && endaddr == 0)
792     return;
793   curoffset = beginoffset;
794   limit_offset =
795     ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
796     ->max_lineno_offset;
797
798   if (endoffset != 0)
799     {
800       if (endoffset >= limit_offset)
801         {
802           static struct complaint msg =
803           {"Bad line table offset in C_EINCL directive", 0, 0};
804           complain (&msg);
805           return;
806         }
807       limit_offset = endoffset;
808     }
809   else
810     limit_offset -= 1;
811
812   abfd = this_symtab_psymtab->objfile->obfd;
813   linesz = coff_data (abfd)->local_linesz;
814   ext_lnno = alloca (linesz);
815
816   while (curoffset <= limit_offset)
817     {
818       bfd_seek (abfd, curoffset, SEEK_SET);
819       bfd_read (ext_lnno, linesz, 1, abfd);
820       bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno);
821
822       /* Find the address this line represents.  */
823       addr = (int_lnno.l_lnno
824               ? int_lnno.l_addr.l_paddr
825               : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
826       addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets,
827                         SECT_OFF_TEXT (this_symtab_psymtab->objfile));
828
829       if (addr < startaddr || (endaddr && addr >= endaddr))
830         return;
831
832       if (int_lnno.l_lnno == 0)
833         {
834           *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
835           record_line (subfile, 0, addr);
836           --(*firstLine);
837         }
838       else
839         record_line (subfile, *firstLine + int_lnno.l_lnno, addr);
840       curoffset += linesz;
841     }
842 }
843
844
845 /* Save the vital information for use when closing off the current file.
846    NAME is the file name the symbols came from, START_ADDR is the first
847    text address for the file, and SIZE is the number of bytes of text.  */
848
849 #define complete_symtab(name, start_addr) {     \
850   last_source_file = savestring (name, strlen (name));  \
851   last_source_start_addr = start_addr;                  \
852 }
853
854
855 /* Refill the symbol table input buffer
856    and set the variables that control fetching entries from it.
857    Reports an error if no data available.
858    This function can read past the end of the symbol table
859    (into the string table) but this does no harm.  */
860
861 /* Reading symbol table has to be fast! Keep the followings as macros, rather
862    than functions. */
863
864 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
865 {                                               \
866   char *namestr;                                \
867   namestr = (NAME); \
868   if (namestr[0] == '.') ++namestr; \
869   prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
870                                        (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
871   misc_func_recorded = 1;                                       \
872 }
873
874
875 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
876    nested. At any given time, a symbol can only be in one static block.
877    This is the base address of current static block, zero if non exists. */
878
879 static int static_block_base = 0;
880
881 /* Section number for the current static block.  */
882
883 static int static_block_section = -1;
884
885 /* true if space for symbol name has been allocated. */
886
887 static int symname_alloced = 0;
888
889 /* Next symbol to read.  Pointer into raw seething symbol table.  */
890
891 static char *raw_symbol;
892
893 /* This is the function which stabsread.c calls to get symbol
894    continuations.  */
895
896 static char *
897 xcoff_next_symbol_text (struct objfile *objfile)
898 {
899   struct internal_syment symbol;
900   static struct complaint msg =
901   {"Unexpected symbol continuation", 0, 0};
902   char *retval;
903   /* FIXME: is this the same as the passed arg? */
904   objfile = this_symtab_psymtab->objfile;
905
906   bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
907   if (symbol.n_zeroes)
908     {
909       complain (&msg);
910
911       /* Return something which points to '\0' and hope the symbol reading
912          code does something reasonable.  */
913       retval = "";
914     }
915   else if (symbol.n_sclass & 0x80)
916     {
917       retval =
918         ((struct coff_symfile_info *) objfile->sym_private)->debugsec
919         + symbol.n_offset;
920       raw_symbol +=
921         coff_data (objfile->obfd)->local_symesz;
922       ++symnum;
923     }
924   else
925     {
926       complain (&msg);
927
928       /* Return something which points to '\0' and hope the symbol reading
929          code does something reasonable.  */
930       retval = "";
931     }
932   return retval;
933 }
934
935 /* Read symbols for a given partial symbol table.  */
936
937 static void
938 read_xcoff_symtab (struct partial_symtab *pst)
939 {
940   struct objfile *objfile = pst->objfile;
941   bfd *abfd = objfile->obfd;
942   char *raw_auxptr;             /* Pointer to first raw aux entry for sym */
943   char *strtbl = ((struct coff_symfile_info *) objfile->sym_private)->strtbl;
944   char *debugsec =
945   ((struct coff_symfile_info *) objfile->sym_private)->debugsec;
946   char *debugfmt = xcoff_data (abfd)->xcoff64 ? "XCOFF64" : "XCOFF";
947
948   struct internal_syment symbol[1];
949   union internal_auxent main_aux;
950   struct coff_symbol cs[1];
951   CORE_ADDR file_start_addr = 0;
952   CORE_ADDR file_end_addr = 0;
953
954   int next_file_symnum = -1;
955   unsigned int max_symnum;
956   int just_started = 1;
957   int depth = 0;
958   int fcn_start_addr = 0;
959
960   struct coff_symbol fcn_stab_saved;
961
962   /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
963   union internal_auxent fcn_aux_saved;
964   struct context_stack *new;
965
966   char *filestring = " _start_ ";       /* Name of the current file. */
967
968   char *last_csect_name;        /* last seen csect's name and value */
969   CORE_ADDR last_csect_val;
970   int last_csect_sec;
971
972   this_symtab_psymtab = pst;
973
974   /* Get the appropriate COFF "constants" related to the file we're
975      handling. */
976   local_symesz = coff_data (abfd)->local_symesz;
977
978   last_source_file = NULL;
979   last_csect_name = 0;
980   last_csect_val = 0;
981
982   start_stabs ();
983   start_symtab (filestring, (char *) NULL, file_start_addr);
984   record_debugformat (debugfmt);
985   symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum;
986   max_symnum =
987     symnum + ((struct symloc *) pst->read_symtab_private)->numsyms;
988   first_object_file_end = 0;
989
990   raw_symbol =
991     ((struct coff_symfile_info *) objfile->sym_private)->symtbl
992     + symnum * local_symesz;
993
994   while (symnum < max_symnum)
995     {
996
997       QUIT;                     /* make this command interruptable.  */
998
999       /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1000       /* read one symbol into `cs' structure. After processing the
1001          whole symbol table, only string table will be kept in memory,
1002          symbol table and debug section of xcoff will be freed. Thus
1003          we can mark symbols with names in string table as
1004          `alloced'. */
1005       {
1006         int ii;
1007
1008         /* Swap and align the symbol into a reasonable C structure.  */
1009         bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1010
1011         cs->c_symnum = symnum;
1012         cs->c_naux = symbol->n_numaux;
1013         if (symbol->n_zeroes)
1014           {
1015             symname_alloced = 0;
1016             /* We must use the original, unswapped, name here so the name field
1017                pointed to by cs->c_name will persist throughout xcoffread.  If
1018                we use the new field, it gets overwritten for each symbol.  */
1019             cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name;
1020             /* If it's exactly E_SYMNMLEN characters long it isn't
1021                '\0'-terminated.  */
1022             if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1023               {
1024                 char *p;
1025                 p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
1026                 strncpy (p, cs->c_name, E_SYMNMLEN);
1027                 p[E_SYMNMLEN] = '\0';
1028                 cs->c_name = p;
1029                 symname_alloced = 1;
1030               }
1031           }
1032         else if (symbol->n_sclass & 0x80)
1033           {
1034             cs->c_name = debugsec + symbol->n_offset;
1035             symname_alloced = 0;
1036           }
1037         else
1038           {
1039             /* in string table */
1040             cs->c_name = strtbl + (int) symbol->n_offset;
1041             symname_alloced = 1;
1042           }
1043         cs->c_value = symbol->n_value;
1044         cs->c_sclass = symbol->n_sclass;
1045         cs->c_secnum = symbol->n_scnum;
1046         cs->c_type = (unsigned) symbol->n_type;
1047
1048         raw_symbol += local_symesz;
1049         ++symnum;
1050
1051         /* Save addr of first aux entry.  */
1052         raw_auxptr = raw_symbol;
1053
1054         /* Skip all the auxents associated with this symbol.  */
1055         for (ii = symbol->n_numaux; ii; --ii)
1056           {
1057             raw_symbol += coff_data (abfd)->local_auxesz;
1058             ++symnum;
1059           }
1060       }
1061
1062       /* if symbol name starts with ".$" or "$", ignore it. */
1063       if (cs->c_name[0] == '$'
1064           || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1065         continue;
1066
1067       if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1068         {
1069           if (last_source_file)
1070             {
1071               pst->symtab =
1072                 end_symtab (cur_src_end_addr, objfile, SECT_OFF_TEXT (objfile));
1073               end_stabs ();
1074             }
1075
1076           start_stabs ();
1077           start_symtab ("_globals_", (char *) NULL, (CORE_ADDR) 0);
1078           record_debugformat (debugfmt);
1079           cur_src_end_addr = first_object_file_end;
1080           /* done with all files, everything from here on is globals */
1081         }
1082
1083       /* if explicitly specified as a function, treat is as one. */
1084       if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
1085         {
1086           bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1087                                 0, cs->c_naux, &main_aux);
1088           goto function_entry_point;
1089         }
1090
1091       if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1092           && cs->c_naux == 1)
1093         {
1094           /* Dealing with a symbol with a csect entry.  */
1095
1096 #define CSECT(PP) ((PP)->x_csect)
1097 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1098 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1099 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1100 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1101
1102           /* Convert the auxent to something we can access.  */
1103           bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1104                                 0, cs->c_naux, &main_aux);
1105
1106           switch (CSECT_SMTYP (&main_aux))
1107             {
1108
1109             case XTY_ER:
1110               /* Ignore all external references.  */
1111               continue;
1112
1113             case XTY_SD:
1114               /* A section description.  */
1115               {
1116                 switch (CSECT_SCLAS (&main_aux))
1117                   {
1118
1119                   case XMC_PR:
1120                     {
1121
1122                       /* A program csect is seen.  We have to allocate one
1123                          symbol table for each program csect.  Normally gdb
1124                          prefers one symtab for each source file.  In case
1125                          of AIX, one source file might include more than one
1126                          [PR] csect, and they don't have to be adjacent in
1127                          terms of the space they occupy in memory. Thus, one
1128                          single source file might get fragmented in the
1129                          memory and gdb's file start and end address
1130                          approach does not work!  GCC (and I think xlc) seem
1131                          to put all the code in the unnamed program csect.  */
1132
1133                       if (last_csect_name)
1134                         {
1135                           complete_symtab (filestring, file_start_addr);
1136                           cur_src_end_addr = file_end_addr;
1137                           end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1138                           end_stabs ();
1139                           start_stabs ();
1140                           /* Give all csects for this source file the same
1141                              name.  */
1142                           start_symtab (filestring, NULL, (CORE_ADDR) 0);
1143                           record_debugformat (debugfmt);
1144                         }
1145
1146                       /* If this is the very first csect seen,
1147                          basically `__start'. */
1148                       if (just_started)
1149                         {
1150                           first_object_file_end
1151                             = cs->c_value + CSECT_LEN (&main_aux);
1152                           just_started = 0;
1153                         }
1154
1155                       file_start_addr =
1156                         cs->c_value + ANOFFSET (objfile->section_offsets,
1157                                                 SECT_OFF_TEXT (objfile));
1158                       file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1159
1160                       if (cs->c_name && cs->c_name[0] == '.')
1161                         {
1162                           last_csect_name = cs->c_name;
1163                           last_csect_val = cs->c_value;
1164                           last_csect_sec = secnum_to_section (cs->c_secnum, objfile);
1165                         }
1166                     }
1167                     continue;
1168
1169                     /* All other symbols are put into the minimal symbol
1170                        table only.  */
1171
1172                   case XMC_RW:
1173                     continue;
1174
1175                   case XMC_TC0:
1176                     continue;
1177
1178                   case XMC_TC:
1179                     continue;
1180
1181                   default:
1182                     /* Ignore the symbol.  */
1183                     continue;
1184                   }
1185               }
1186               break;
1187
1188             case XTY_LD:
1189
1190               switch (CSECT_SCLAS (&main_aux))
1191                 {
1192                 case XMC_PR:
1193                   /* a function entry point. */
1194                 function_entry_point:
1195
1196                   fcn_start_addr = cs->c_value;
1197
1198                   /* save the function header info, which will be used
1199                      when `.bf' is seen. */
1200                   fcn_cs_saved = *cs;
1201                   fcn_aux_saved = main_aux;
1202                   continue;
1203
1204                 case XMC_GL:
1205                   /* shared library function trampoline code entry point. */
1206                   continue;
1207
1208                 case XMC_DS:
1209                   /* The symbols often have the same names as debug symbols for
1210                      functions, and confuse lookup_symbol.  */
1211                   continue;
1212
1213                 default:
1214                   /* xlc puts each variable in a separate csect, so we get
1215                      an XTY_SD for each variable.  But gcc puts several
1216                      variables in a csect, so that each variable only gets
1217                      an XTY_LD. This will typically be XMC_RW; I suspect
1218                      XMC_RO and XMC_BS might be possible too.
1219                      These variables are put in the minimal symbol table
1220                      only.  */
1221                   continue;
1222                 }
1223               break;
1224
1225             case XTY_CM:
1226               /* Common symbols are put into the minimal symbol table only.  */
1227               continue;
1228
1229             default:
1230               break;
1231             }
1232         }
1233
1234       switch (cs->c_sclass)
1235         {
1236
1237         case C_FILE:
1238
1239           /* c_value field contains symnum of next .file entry in table
1240              or symnum of first global after last .file. */
1241
1242           next_file_symnum = cs->c_value;
1243
1244           /* Complete symbol table for last object file containing
1245              debugging information. */
1246
1247           /* Whether or not there was a csect in the previous file, we
1248              have to call `end_stabs' and `start_stabs' to reset
1249              type_vector, line_vector, etc. structures.  */
1250
1251           complete_symtab (filestring, file_start_addr);
1252           cur_src_end_addr = file_end_addr;
1253           end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1254           end_stabs ();
1255
1256           /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1257              in cs->c_name.  But xlc 1.3.0.2 has decided to do things the
1258              standard COFF way and put it in the auxent.  We use the auxent if
1259              the symbol is ".file" and an auxent exists, otherwise use the symbol
1260              itself.  Simple enough.  */
1261           if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1262             {
1263               bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1264                                     0, cs->c_naux, &main_aux);
1265               filestring = coff_getfilename (&main_aux, objfile);
1266             }
1267           else
1268             filestring = cs->c_name;
1269
1270           start_stabs ();
1271           start_symtab (filestring, (char *) NULL, (CORE_ADDR) 0);
1272           record_debugformat (debugfmt);
1273           last_csect_name = 0;
1274
1275           /* reset file start and end addresses. A compilation unit with no text
1276              (only data) should have zero file boundaries. */
1277           file_start_addr = file_end_addr = 0;
1278           break;
1279
1280         case C_FUN:
1281           fcn_stab_saved = *cs;
1282           break;
1283
1284         case C_FCN:
1285           if (STREQ (cs->c_name, ".bf"))
1286             {
1287               CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1288                                         SECT_OFF_TEXT (objfile));
1289               bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1290                                     0, cs->c_naux, &main_aux);
1291
1292               within_function = 1;
1293
1294               new = push_context (0, fcn_start_addr + off);
1295
1296               new->name = define_symbol
1297                 (fcn_cs_saved.c_value + off,
1298                  fcn_stab_saved.c_name, 0, 0, objfile);
1299               if (new->name != NULL)
1300                 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT (objfile);
1301             }
1302           else if (STREQ (cs->c_name, ".ef"))
1303             {
1304
1305               bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1306                                     0, cs->c_naux, &main_aux);
1307
1308               /* The value of .ef is the address of epilogue code;
1309                  not useful for gdb.  */
1310               /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1311                  contains number of lines to '}' */
1312
1313               if (context_stack_depth <= 0)
1314                 {               /* We attempted to pop an empty context stack */
1315                   complain (&ef_complaint, cs->c_symnum);
1316                   within_function = 0;
1317                   break;
1318                 }
1319               new = pop_context ();
1320               /* Stack must be empty now.  */
1321               if (context_stack_depth > 0 || new == NULL)
1322                 {
1323                   complain (&ef_complaint, cs->c_symnum);
1324                   within_function = 0;
1325                   break;
1326                 }
1327
1328               finish_block (new->name, &local_symbols, new->old_blocks,
1329                             new->start_addr,
1330                             (fcn_cs_saved.c_value
1331                              + fcn_aux_saved.x_sym.x_misc.x_fsize
1332                              + ANOFFSET (objfile->section_offsets,
1333                                          SECT_OFF_TEXT (objfile))),
1334                             objfile);
1335               within_function = 0;
1336             }
1337           break;
1338
1339         case C_BSTAT:
1340           /* Begin static block.  */
1341           {
1342             struct internal_syment symbol;
1343
1344             read_symbol (&symbol, cs->c_value);
1345             static_block_base = symbol.n_value;
1346             static_block_section =
1347               secnum_to_section (symbol.n_scnum, objfile);
1348           }
1349           break;
1350
1351         case C_ESTAT:
1352           /* End of static block.  */
1353           static_block_base = 0;
1354           static_block_section = -1;
1355           break;
1356
1357         case C_ARG:
1358         case C_REGPARM:
1359         case C_REG:
1360         case C_TPDEF:
1361         case C_STRTAG:
1362         case C_UNTAG:
1363         case C_ENTAG:
1364           {
1365             static struct complaint msg =
1366             {"Unrecognized storage class %d.", 0, 0};
1367             complain (&msg, cs->c_sclass);
1368           }
1369           break;
1370
1371         case C_LABEL:
1372         case C_NULL:
1373           /* Ignore these.  */
1374           break;
1375
1376         case C_HIDEXT:
1377         case C_STAT:
1378           break;
1379
1380         case C_BINCL:
1381           /* beginning of include file */
1382           /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1383              order. Thus, when wee see them, we might not know enough info
1384              to process them. Thus, we'll be saving them into a table 
1385              (inclTable) and postpone their processing. */
1386
1387           record_include_begin (cs);
1388           break;
1389
1390         case C_EINCL:
1391           /* End of include file.  */
1392           /* See the comment after case C_BINCL.  */
1393           record_include_end (cs);
1394           break;
1395
1396         case C_BLOCK:
1397           if (STREQ (cs->c_name, ".bb"))
1398             {
1399               depth++;
1400               new = push_context (depth,
1401                                   (cs->c_value
1402                                    + ANOFFSET (objfile->section_offsets,
1403                                                SECT_OFF_TEXT (objfile))));
1404             }
1405           else if (STREQ (cs->c_name, ".eb"))
1406             {
1407               if (context_stack_depth <= 0)
1408                 {               /* We attempted to pop an empty context stack */
1409                   complain (&eb_complaint, cs->c_symnum);
1410                   break;
1411                 }
1412               new = pop_context ();
1413               if (depth-- != new->depth)
1414                 {
1415                   complain (&eb_complaint, cs->c_symnum);
1416                   break;
1417                 }
1418               if (local_symbols && context_stack_depth > 0)
1419                 {
1420                   /* Make a block for the local symbols within.  */
1421                   finish_block (new->name, &local_symbols, new->old_blocks,
1422                                 new->start_addr,
1423                                 (cs->c_value
1424                                  + ANOFFSET (objfile->section_offsets,
1425                                              SECT_OFF_TEXT (objfile))),
1426                                 objfile);
1427                 }
1428               local_symbols = new->locals;
1429             }
1430           break;
1431
1432         default:
1433           process_xcoff_symbol (cs, objfile);
1434           break;
1435         }
1436     }
1437
1438   if (last_source_file)
1439     {
1440       struct symtab *s;
1441
1442       complete_symtab (filestring, file_start_addr);
1443       cur_src_end_addr = file_end_addr;
1444       s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1445       /* When reading symbols for the last C_FILE of the objfile, try
1446          to make sure that we set pst->symtab to the symtab for the
1447          file, not to the _globals_ symtab.  I'm not sure whether this
1448          actually works right or when/if it comes up.  */
1449       if (pst->symtab == NULL)
1450         pst->symtab = s;
1451       end_stabs ();
1452     }
1453 }
1454
1455 #define SYMBOL_DUP(SYMBOL1, SYMBOL2)    \
1456   (SYMBOL2) = (struct symbol *)         \
1457         obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1458   *(SYMBOL2) = *(SYMBOL1);
1459
1460
1461 #define SYMNAME_ALLOC(NAME, ALLOCED)    \
1462   (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1463
1464
1465 static struct type *func_symbol_type;
1466 static struct type *var_symbol_type;
1467
1468 /* process one xcoff symbol. */
1469
1470 static struct symbol *
1471 process_xcoff_symbol (register struct coff_symbol *cs, struct objfile *objfile)
1472 {
1473   struct symbol onesymbol;
1474   register struct symbol *sym = &onesymbol;
1475   struct symbol *sym2 = NULL;
1476   char *name, *pp;
1477
1478   int sec;
1479   CORE_ADDR off;
1480
1481   if (cs->c_secnum < 0)
1482     {
1483       /* The value is a register number, offset within a frame, etc.,
1484          and does not get relocated.  */
1485       off = 0;
1486       sec = -1;
1487     }
1488   else
1489     {
1490       sec = secnum_to_section (cs->c_secnum, objfile);
1491       off = ANOFFSET (objfile->section_offsets, sec);
1492     }
1493
1494   name = cs->c_name;
1495   if (name[0] == '.')
1496     ++name;
1497
1498   memset (sym, '\0', sizeof (struct symbol));
1499
1500   /* default assumptions */
1501   SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off;
1502   SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1503   SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1504
1505   if (ISFCN (cs->c_type))
1506     {
1507       /* At this point, we don't know the type of the function.  This
1508          will be patched with the type from its stab entry later on in
1509          patch_block_stabs (), unless the file was compiled without -g.  */
1510
1511       SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1512       SYMBOL_TYPE (sym) = func_symbol_type;
1513
1514       SYMBOL_CLASS (sym) = LOC_BLOCK;
1515       SYMBOL_DUP (sym, sym2);
1516
1517       if (cs->c_sclass == C_EXT)
1518         add_symbol_to_list (sym2, &global_symbols);
1519       else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1520         add_symbol_to_list (sym2, &file_symbols);
1521     }
1522   else
1523     {
1524       /* In case we can't figure out the type, provide default. */
1525       SYMBOL_TYPE (sym) = var_symbol_type;
1526
1527       switch (cs->c_sclass)
1528         {
1529 #if 0
1530           /* The values of functions and global symbols are now resolved
1531              via the global_sym_chain in stabsread.c.  */
1532         case C_FUN:
1533           if (fcn_cs_saved.c_sclass == C_EXT)
1534             add_stab_to_list (name, &global_stabs);
1535           else
1536             add_stab_to_list (name, &file_stabs);
1537           break;
1538
1539         case C_GSYM:
1540           add_stab_to_list (name, &global_stabs);
1541           break;
1542 #endif
1543
1544         case C_BCOMM:
1545           common_block_start (cs->c_name, objfile);
1546           break;
1547
1548         case C_ECOMM:
1549           common_block_end (objfile);
1550           break;
1551
1552         default:
1553           complain (&storclass_complaint, cs->c_sclass);
1554           /* FALLTHROUGH */
1555
1556         case C_DECL:
1557         case C_PSYM:
1558         case C_RPSYM:
1559         case C_ECOML:
1560         case C_LSYM:
1561         case C_RSYM:
1562         case C_GSYM:
1563
1564           {
1565             sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1566             if (sym != NULL)
1567               {
1568                 SYMBOL_SECTION (sym) = sec;
1569               }
1570             return sym;
1571           }
1572
1573         case C_STSYM:
1574
1575           /* For xlc (not GCC), the 'V' symbol descriptor is used for
1576              all statics and we need to distinguish file-scope versus
1577              function-scope using within_function.  We do this by
1578              changing the string we pass to define_symbol to use 'S'
1579              where we need to, which is not necessarily super-clean,
1580              but seems workable enough.  */
1581
1582           if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
1583             return NULL;
1584
1585           ++pp;
1586           if (*pp == 'V' && !within_function)
1587             *pp = 'S';
1588           sym = define_symbol ((cs->c_value
1589                                 + ANOFFSET (objfile->section_offsets,
1590                                             static_block_section)),
1591                                cs->c_name, 0, 0, objfile);
1592           if (sym != NULL)
1593             {
1594               SYMBOL_VALUE_ADDRESS (sym) += static_block_base;
1595               SYMBOL_SECTION (sym) = static_block_section;
1596             }
1597           return sym;
1598
1599         }
1600     }
1601   return sym2;
1602 }
1603
1604 /* Extract the file name from the aux entry of a C_FILE symbol.
1605    Result is in static storage and is only good for temporary use.  */
1606
1607 static char *
1608 coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile)
1609 {
1610   static char buffer[BUFSIZ];
1611
1612   if (aux_entry->x_file.x_n.x_zeroes == 0)
1613     strcpy (buffer,
1614             ((struct coff_symfile_info *) objfile->sym_private)->strtbl
1615             + aux_entry->x_file.x_n.x_offset);
1616   else
1617     {
1618       strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1619       buffer[FILNMLEN] = '\0';
1620     }
1621   return (buffer);
1622 }
1623
1624 /* Set *SYMBOL to symbol number symno in symtbl.  */
1625 static void
1626 read_symbol (struct internal_syment *symbol, int symno)
1627 {
1628   int nsyms =
1629   ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
1630   ->symtbl_num_syms;
1631   char *stbl =
1632   ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
1633   ->symtbl;
1634   if (symno < 0 || symno >= nsyms)
1635     {
1636       static struct complaint msg =
1637       {"Invalid symbol offset", 0, 0};
1638       complain (&msg);
1639       symbol->n_value = 0;
1640       symbol->n_scnum = -1;
1641       return;
1642     }
1643   bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1644                         stbl + (symno * local_symesz),
1645                         symbol);
1646 }
1647
1648 /* Get value corresponding to symbol number symno in symtbl.  */
1649
1650 static CORE_ADDR
1651 read_symbol_nvalue (int symno)
1652 {
1653   struct internal_syment symbol[1];
1654
1655   read_symbol (symbol, symno);
1656   return symbol->n_value;
1657 }
1658
1659
1660 /* Find the address of the function corresponding to symno, where
1661    symno is the symbol pointed to by the linetable.  */
1662
1663 static int
1664 read_symbol_lineno (int symno)
1665 {
1666   struct objfile *objfile = this_symtab_psymtab->objfile;
1667   boolean xcoff64 = xcoff_data (objfile->obfd)->xcoff64;
1668
1669   struct coff_symfile_info *info =
1670     (struct coff_symfile_info *)objfile->sym_private;
1671   int nsyms = info->symtbl_num_syms;
1672   char *stbl = info->symtbl;
1673   char *strtbl = info->strtbl;
1674
1675   struct internal_syment symbol[1];
1676   union internal_auxent main_aux[1];
1677
1678   if (symno < 0)
1679     {
1680       complain (&bf_notfound_complaint);
1681       return 0;
1682     }
1683
1684   /* Note that just searching for a short distance (e.g. 50 symbols)
1685      is not enough, at least in the following case.
1686
1687      .extern foo
1688      [many .stabx entries]
1689      [a few functions, referring to foo]
1690      .globl foo
1691      .bf
1692
1693      What happens here is that the assembler moves the .stabx entries
1694      to right before the ".bf" for foo, but the symbol for "foo" is before
1695      all the stabx entries.  See PR gdb/2222.  */
1696
1697   /* Maintaining a table of .bf entries might be preferable to this search.
1698      If I understand things correctly it would need to be done only for
1699      the duration of a single psymtab to symtab conversion.  */
1700   while (symno < nsyms)
1701     {
1702       bfd_coff_swap_sym_in (symfile_bfd,
1703                             stbl + (symno * local_symesz), symbol);
1704       if (symbol->n_sclass == C_FCN)
1705         {
1706           char *name = xcoff64 ? strtbl + symbol->n_offset : symbol->n_name;
1707           if (STREQ (name, ".bf"))
1708             goto gotit;
1709         }
1710       symno += symbol->n_numaux + 1;
1711     }
1712
1713   complain (&bf_notfound_complaint);
1714   return 0;
1715
1716 gotit:
1717   /* take aux entry and return its lineno */
1718   symno++;
1719   bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz,
1720                         symbol->n_type, symbol->n_sclass,
1721                         0, symbol->n_numaux, main_aux);
1722
1723   return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1724 }
1725
1726 /* Support for line number handling */
1727
1728 /* This function is called for every section; it finds the outer limits
1729  * of the line table (minimum and maximum file offset) so that the
1730  * mainline code can read the whole thing for efficiency.
1731  */
1732 static void
1733 find_linenos (bfd *abfd, sec_ptr asect, PTR vpinfo)
1734 {
1735   struct coff_symfile_info *info;
1736   int size, count;
1737   file_ptr offset, maxoff;
1738
1739   count = asect->lineno_count;
1740
1741   if (!STREQ (asect->name, ".text") || count == 0)
1742     return;
1743
1744   size = count * coff_data (abfd)->local_linesz;
1745   info = (struct coff_symfile_info *) vpinfo;
1746   offset = asect->line_filepos;
1747   maxoff = offset + size;
1748
1749   if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1750     info->min_lineno_offset = offset;
1751
1752   if (maxoff > info->max_lineno_offset)
1753     info->max_lineno_offset = maxoff;
1754 }
1755 \f
1756 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab *);
1757
1758 static void
1759 xcoff_psymtab_to_symtab_1 (struct partial_symtab *pst)
1760 {
1761   struct cleanup *old_chain;
1762   int i;
1763
1764   if (!pst)
1765     return;
1766
1767   if (pst->readin)
1768     {
1769       fprintf_unfiltered
1770         (gdb_stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
1771          pst->filename);
1772       return;
1773     }
1774
1775   /* Read in all partial symtabs on which this one is dependent */
1776   for (i = 0; i < pst->number_of_dependencies; i++)
1777     if (!pst->dependencies[i]->readin)
1778       {
1779         /* Inform about additional files that need to be read in.  */
1780         if (info_verbose)
1781           {
1782             fputs_filtered (" ", gdb_stdout);
1783             wrap_here ("");
1784             fputs_filtered ("and ", gdb_stdout);
1785             wrap_here ("");
1786             printf_filtered ("%s...", pst->dependencies[i]->filename);
1787             wrap_here ("");     /* Flush output */
1788             gdb_flush (gdb_stdout);
1789           }
1790         xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1791       }
1792
1793   if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
1794     {
1795       /* Init stuff necessary for reading in symbols.  */
1796       stabsread_init ();
1797       buildsym_init ();
1798       old_chain = make_cleanup (really_free_pendings, 0);
1799
1800       read_xcoff_symtab (pst);
1801       sort_symtab_syms (pst->symtab);
1802
1803       do_cleanups (old_chain);
1804     }
1805
1806   pst->readin = 1;
1807 }
1808
1809 static void xcoff_psymtab_to_symtab (struct partial_symtab *);
1810
1811 /* Read in all of the symbols for a given psymtab for real.
1812    Be verbose about it if the user wants that.  */
1813
1814 static void
1815 xcoff_psymtab_to_symtab (struct partial_symtab *pst)
1816 {
1817   bfd *sym_bfd;
1818
1819   if (!pst)
1820     return;
1821
1822   if (pst->readin)
1823     {
1824       fprintf_unfiltered
1825         (gdb_stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
1826          pst->filename);
1827       return;
1828     }
1829
1830   if (((struct symloc *) pst->read_symtab_private)->numsyms != 0
1831       || pst->number_of_dependencies)
1832     {
1833       /* Print the message now, before reading the string table,
1834          to avoid disconcerting pauses.  */
1835       if (info_verbose)
1836         {
1837           printf_filtered ("Reading in symbols for %s...", pst->filename);
1838           gdb_flush (gdb_stdout);
1839         }
1840
1841       sym_bfd = pst->objfile->obfd;
1842
1843       next_symbol_text_func = xcoff_next_symbol_text;
1844
1845       xcoff_psymtab_to_symtab_1 (pst);
1846
1847       /* Match with global symbols.  This only needs to be done once,
1848          after all of the symtabs and dependencies have been read in.   */
1849       scan_file_globals (pst->objfile);
1850
1851       /* Finish up the debug error message.  */
1852       if (info_verbose)
1853         printf_filtered ("done.\n");
1854     }
1855 }
1856 \f
1857 static void
1858 xcoff_new_init (struct objfile *objfile)
1859 {
1860   stabsread_new_init ();
1861   buildsym_new_init ();
1862 }
1863
1864 /* Do initialization in preparation for reading symbols from OBJFILE.
1865
1866    We will only be called if this is an XCOFF or XCOFF-like file.
1867    BFD handles figuring out the format of the file, and code in symfile.c
1868    uses BFD's determination to vector to us.  */
1869
1870 static void
1871 xcoff_symfile_init (struct objfile *objfile)
1872 {
1873   /* Allocate struct to keep track of the symfile */
1874   objfile->sym_private = xmmalloc (objfile->md,
1875                                    sizeof (struct coff_symfile_info));
1876
1877   /* XCOFF objects may be reordered, so set OBJF_REORDERED.  If we
1878      find this causes a significant slowdown in gdb then we could
1879      set it in the debug symbol readers only when necessary.  */
1880   objfile->flags |= OBJF_REORDERED;
1881
1882   init_entry_point_info (objfile);
1883 }
1884
1885 /* Perform any local cleanups required when we are done with a particular
1886    objfile.  I.E, we are in the process of discarding all symbol information
1887    for an objfile, freeing up all memory held for it, and unlinking the
1888    objfile struct from the global list of known objfiles. */
1889
1890 static void
1891 xcoff_symfile_finish (struct objfile *objfile)
1892 {
1893   if (objfile->sym_private != NULL)
1894     {
1895       mfree (objfile->md, objfile->sym_private);
1896     }
1897
1898   /* Start with a fresh include table for the next objfile.  */
1899   if (inclTable)
1900     {
1901       xfree (inclTable);
1902       inclTable = NULL;
1903     }
1904   inclIndx = inclLength = inclDepth = 0;
1905 }
1906
1907
1908 static void
1909 init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile)
1910 {
1911   long length;
1912   int val;
1913   unsigned char lengthbuf[4];
1914   char *strtbl;
1915
1916   ((struct coff_symfile_info *) objfile->sym_private)->strtbl = NULL;
1917
1918   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1919     error ("cannot seek to string table in %s: %s",
1920            bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1921
1922   val = bfd_read ((char *) lengthbuf, 1, sizeof lengthbuf, abfd);
1923   length = bfd_h_get_32 (abfd, lengthbuf);
1924
1925   /* If no string table is needed, then the file may end immediately
1926      after the symbols.  Just return with `strtbl' set to NULL.  */
1927
1928   if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1929     return;
1930
1931   /* Allocate string table from symbol_obstack. We will need this table
1932      as long as we have its symbol table around. */
1933
1934   strtbl = (char *) obstack_alloc (&objfile->symbol_obstack, length);
1935   ((struct coff_symfile_info *) objfile->sym_private)->strtbl = strtbl;
1936
1937   /* Copy length buffer, the first byte is usually zero and is
1938      used for stabs with a name length of zero.  */
1939   memcpy (strtbl, lengthbuf, sizeof lengthbuf);
1940   if (length == sizeof lengthbuf)
1941     return;
1942
1943   val = bfd_read (strtbl + sizeof lengthbuf, 1, length - sizeof lengthbuf,
1944                   abfd);
1945
1946   if (val != length - sizeof lengthbuf)
1947     error ("cannot read string table from %s: %s",
1948            bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1949   if (strtbl[length - 1] != '\0')
1950     error ("bad symbol file: string table does not end with null character");
1951
1952   return;
1953 }
1954 \f
1955 /* If we have not yet seen a function for this psymtab, this is 0.  If we
1956    have seen one, it is the offset in the line numbers of the line numbers
1957    for the psymtab.  */
1958 static unsigned int first_fun_line_offset;
1959
1960 static struct partial_symtab *xcoff_start_psymtab
1961   (struct objfile *, char *, int,
1962    struct partial_symbol **, struct partial_symbol **);
1963
1964 /* Allocate and partially fill a partial symtab.  It will be
1965    completely filled at the end of the symbol list.
1966
1967    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1968    is the address relative to which its symbols are (incremental) or 0
1969    (normal). */
1970
1971 static struct partial_symtab *
1972 xcoff_start_psymtab (struct objfile *objfile, char *filename, int first_symnum,
1973                      struct partial_symbol **global_syms,
1974                      struct partial_symbol **static_syms)
1975 {
1976   struct partial_symtab *result =
1977   start_psymtab_common (objfile, objfile->section_offsets,
1978                         filename,
1979                         /* We fill in textlow later.  */
1980                         0,
1981                         global_syms, static_syms);
1982
1983   result->read_symtab_private = (char *)
1984     obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
1985   ((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum;
1986   result->read_symtab = xcoff_psymtab_to_symtab;
1987
1988   /* Deduce the source language from the filename for this psymtab. */
1989   psymtab_language = deduce_language_from_filename (filename);
1990
1991   return result;
1992 }
1993
1994 static struct partial_symtab *xcoff_end_psymtab
1995   (struct partial_symtab *, char **, int, int,
1996    struct partial_symtab **, int, int);
1997
1998 /* Close off the current usage of PST.  
1999    Returns PST, or NULL if the partial symtab was empty and thrown away.
2000
2001    CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2002
2003    INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2004    are the information for includes and dependencies.  */
2005
2006 static struct partial_symtab *
2007 xcoff_end_psymtab (struct partial_symtab *pst, char **include_list,
2008                    int num_includes, int capping_symbol_number,
2009                    struct partial_symtab **dependency_list,
2010                    int number_dependencies, int textlow_not_set)
2011 {
2012   int i;
2013   struct objfile *objfile = pst->objfile;
2014
2015   if (capping_symbol_number != -1)
2016     ((struct symloc *) pst->read_symtab_private)->numsyms =
2017       capping_symbol_number
2018       - ((struct symloc *) pst->read_symtab_private)->first_symnum;
2019   ((struct symloc *) pst->read_symtab_private)->lineno_off =
2020     first_fun_line_offset;
2021   first_fun_line_offset = 0;
2022   pst->n_global_syms =
2023     objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2024   pst->n_static_syms =
2025     objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2026
2027   pst->number_of_dependencies = number_dependencies;
2028   if (number_dependencies)
2029     {
2030       pst->dependencies = (struct partial_symtab **)
2031         obstack_alloc (&objfile->psymbol_obstack,
2032                     number_dependencies * sizeof (struct partial_symtab *));
2033       memcpy (pst->dependencies, dependency_list,
2034               number_dependencies * sizeof (struct partial_symtab *));
2035     }
2036   else
2037     pst->dependencies = 0;
2038
2039   for (i = 0; i < num_includes; i++)
2040     {
2041       struct partial_symtab *subpst =
2042       allocate_psymtab (include_list[i], objfile);
2043
2044       subpst->section_offsets = pst->section_offsets;
2045       subpst->read_symtab_private =
2046         (char *) obstack_alloc (&objfile->psymbol_obstack,
2047                                 sizeof (struct symloc));
2048       ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
2049       ((struct symloc *) subpst->read_symtab_private)->numsyms = 0;
2050       subpst->textlow = 0;
2051       subpst->texthigh = 0;
2052
2053       /* We could save slight bits of space by only making one of these,
2054          shared by the entire set of include files.  FIXME-someday.  */
2055       subpst->dependencies = (struct partial_symtab **)
2056         obstack_alloc (&objfile->psymbol_obstack,
2057                        sizeof (struct partial_symtab *));
2058       subpst->dependencies[0] = pst;
2059       subpst->number_of_dependencies = 1;
2060
2061       subpst->globals_offset =
2062         subpst->n_global_syms =
2063         subpst->statics_offset =
2064         subpst->n_static_syms = 0;
2065
2066       subpst->readin = 0;
2067       subpst->symtab = 0;
2068       subpst->read_symtab = pst->read_symtab;
2069     }
2070
2071   sort_pst_symbols (pst);
2072
2073   /* If there is already a psymtab or symtab for a file of this name,
2074      remove it.  (If there is a symtab, more drastic things also
2075      happen.)  This happens in VxWorks.  */
2076   free_named_symtabs (pst->filename);
2077
2078   if (num_includes == 0
2079       && number_dependencies == 0
2080       && pst->n_global_syms == 0
2081       && pst->n_static_syms == 0)
2082     {
2083       /* Throw away this psymtab, it's empty.  We can't deallocate it, since
2084          it is on the obstack, but we can forget to chain it on the list.  */
2085       /* Empty psymtabs happen as a result of header files which don't have
2086          any symbols in them.  There can be a lot of them.  */
2087
2088       discard_psymtab (pst);
2089
2090       /* Indicate that psymtab was thrown away.  */
2091       pst = (struct partial_symtab *) NULL;
2092     }
2093   return pst;
2094 }
2095
2096 static void swap_sym (struct internal_syment *,
2097                       union internal_auxent *, char **, char **,
2098                       unsigned int *, struct objfile *);
2099
2100 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2101    *SYMBOL, the first auxent in *AUX.  Advance *RAW and *SYMNUMP over
2102    the symbol and its auxents.  */
2103
2104 static void
2105 swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
2106           char **name, char **raw, unsigned int *symnump,
2107           struct objfile *objfile)
2108 {
2109   bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2110   if (symbol->n_zeroes)
2111     {
2112       /* If it's exactly E_SYMNMLEN characters long it isn't
2113          '\0'-terminated.  */
2114       if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2115         {
2116           /* FIXME: wastes memory for symbols which we don't end up putting
2117              into the minimal symbols.  */
2118           char *p;
2119           p = obstack_alloc (&objfile->psymbol_obstack, E_SYMNMLEN + 1);
2120           strncpy (p, symbol->n_name, E_SYMNMLEN);
2121           p[E_SYMNMLEN] = '\0';
2122           *name = p;
2123         }
2124       else
2125         /* Point to the unswapped name as that persists as long as the
2126            objfile does.  */
2127         *name = ((struct external_syment *) *raw)->e.e_name;
2128     }
2129   else if (symbol->n_sclass & 0x80)
2130     {
2131       *name = ((struct coff_symfile_info *) objfile->sym_private)->debugsec
2132         + symbol->n_offset;
2133     }
2134   else
2135     {
2136       *name = ((struct coff_symfile_info *) objfile->sym_private)->strtbl
2137         + symbol->n_offset;
2138     }
2139   ++*symnump;
2140   *raw += coff_data (objfile->obfd)->local_symesz;
2141   if (symbol->n_numaux > 0)
2142     {
2143       bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2144                             symbol->n_sclass, 0, symbol->n_numaux, aux);
2145
2146       *symnump += symbol->n_numaux;
2147       *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2148     }
2149 }
2150
2151 static void
2152 scan_xcoff_symtab (struct objfile *objfile)
2153 {
2154   CORE_ADDR toc_offset = 0;     /* toc offset value in data section. */
2155   char *filestring = NULL;
2156
2157   char *namestring;
2158   int past_first_source_file = 0;
2159   bfd *abfd;
2160   asection *bfd_sect;
2161   unsigned int nsyms;
2162
2163   /* Current partial symtab */
2164   struct partial_symtab *pst;
2165
2166   /* List of current psymtab's include files */
2167   char **psymtab_include_list;
2168   int includes_allocated;
2169   int includes_used;
2170
2171   /* Index within current psymtab dependency list */
2172   struct partial_symtab **dependency_list;
2173   int dependencies_used, dependencies_allocated;
2174
2175   char *sraw_symbol;
2176   struct internal_syment symbol;
2177   union internal_auxent main_aux[5];
2178   unsigned int ssymnum;
2179
2180   char *last_csect_name = NULL; /* last seen csect's name and value */
2181   CORE_ADDR last_csect_val = 0;
2182   int last_csect_sec = 0;
2183   int misc_func_recorded = 0;   /* true if any misc. function */
2184   int textlow_not_set = 1;
2185
2186   pst = (struct partial_symtab *) 0;
2187
2188   includes_allocated = 30;
2189   includes_used = 0;
2190   psymtab_include_list = (char **) alloca (includes_allocated *
2191                                            sizeof (char *));
2192
2193   dependencies_allocated = 30;
2194   dependencies_used = 0;
2195   dependency_list =
2196     (struct partial_symtab **) alloca (dependencies_allocated *
2197                                        sizeof (struct partial_symtab *));
2198
2199   last_source_file = NULL;
2200
2201   abfd = objfile->obfd;
2202
2203   sraw_symbol = ((struct coff_symfile_info *) objfile->sym_private)->symtbl;
2204   nsyms = ((struct coff_symfile_info *) objfile->sym_private)->symtbl_num_syms;
2205   ssymnum = 0;
2206   while (ssymnum < nsyms)
2207     {
2208       int sclass;
2209       /* This is the type we pass to partial-stab.h.  A less kludgy solution
2210          would be to break out partial-stab.h into its various parts--shuffle
2211          off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2212          pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc.  */
2213       int stype;
2214
2215       QUIT;
2216
2217       bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol);
2218       sclass = symbol.n_sclass;
2219
2220       switch (sclass)
2221         {
2222         case C_EXT:
2223         case C_HIDEXT:
2224           {
2225             /* The CSECT auxent--always the last auxent.  */
2226             union internal_auxent csect_aux;
2227             unsigned int symnum_before = ssymnum;
2228
2229             swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2230                       &ssymnum, objfile);
2231             if (symbol.n_numaux > 1)
2232               {
2233                 bfd_coff_swap_aux_in
2234                   (objfile->obfd,
2235                    sraw_symbol - coff_data (abfd)->local_symesz,
2236                    symbol.n_type,
2237                    symbol.n_sclass,
2238                    symbol.n_numaux - 1,
2239                    symbol.n_numaux,
2240                    &csect_aux);
2241               }
2242             else
2243               csect_aux = main_aux[0];
2244
2245             /* If symbol name starts with ".$" or "$", ignore it.  */
2246             if (namestring[0] == '$'
2247                 || (namestring[0] == '.' && namestring[1] == '$'))
2248               break;
2249
2250             switch (csect_aux.x_csect.x_smtyp & 0x7)
2251               {
2252               case XTY_SD:
2253                 switch (csect_aux.x_csect.x_smclas)
2254                   {
2255                   case XMC_PR:
2256                     if (last_csect_name)
2257                       {
2258                         /* If no misc. function recorded in the last
2259                            seen csect, enter it as a function. This
2260                            will take care of functions like strcmp()
2261                            compiled by xlc.  */
2262
2263                         if (!misc_func_recorded)
2264                           {
2265                             RECORD_MINIMAL_SYMBOL
2266                               (last_csect_name, last_csect_val,
2267                                mst_text, last_csect_sec,
2268                                objfile);
2269                           }
2270
2271                         if (pst != NULL)
2272                           {
2273                             /* We have to allocate one psymtab for
2274                                each program csect, because their text
2275                                sections need not be adjacent.  */
2276                             xcoff_end_psymtab
2277                               (pst, psymtab_include_list, includes_used,
2278                                symnum_before, dependency_list,
2279                                dependencies_used, textlow_not_set);
2280                             includes_used = 0;
2281                             dependencies_used = 0;
2282                             /* Give all psymtabs for this source file the same
2283                                name.  */
2284                             pst = xcoff_start_psymtab
2285                               (objfile,
2286                                filestring,
2287                                symnum_before,
2288                                objfile->global_psymbols.next,
2289                                objfile->static_psymbols.next);
2290                           }
2291                       }
2292                     if (namestring && namestring[0] == '.')
2293                       {
2294                         last_csect_name = namestring;
2295                         last_csect_val = symbol.n_value;
2296                         last_csect_sec =
2297                           secnum_to_section (symbol.n_scnum, objfile);
2298                       }
2299                     if (pst != NULL)
2300                       {
2301                         CORE_ADDR highval =
2302                         symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2303                         if (highval > pst->texthigh)
2304                           pst->texthigh = highval;
2305                         if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2306                           pst->textlow = symbol.n_value;
2307                       }
2308                     misc_func_recorded = 0;
2309                     break;
2310
2311                   case XMC_RW:
2312                     /* Data variables are recorded in the minimal symbol
2313                        table, except for section symbols.  */
2314                     if (*namestring != '.')
2315                       prim_record_minimal_symbol_and_info
2316                         (namestring, symbol.n_value,
2317                          sclass == C_HIDEXT ? mst_file_data : mst_data,
2318                          NULL, secnum_to_section (symbol.n_scnum, objfile),
2319                          NULL, objfile);
2320                     break;
2321
2322                   case XMC_TC0:
2323                     if (toc_offset)
2324                       warning ("More than one XMC_TC0 symbol found.");
2325                     toc_offset = symbol.n_value;
2326
2327                     /* Make TOC offset relative to start address of section.  */
2328                     bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile);
2329                     if (bfd_sect)
2330                       toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect);
2331                     break;
2332
2333                   case XMC_TC:
2334                     /* These symbols tell us where the TOC entry for a
2335                        variable is, not the variable itself.  */
2336                     break;
2337
2338                   default:
2339                     break;
2340                   }
2341                 break;
2342
2343               case XTY_LD:
2344                 switch (csect_aux.x_csect.x_smclas)
2345                   {
2346                   case XMC_PR:
2347                     /* A function entry point.  */
2348
2349                     if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
2350                       first_fun_line_offset =
2351                         main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr;
2352                     RECORD_MINIMAL_SYMBOL
2353                       (namestring, symbol.n_value,
2354                        sclass == C_HIDEXT ? mst_file_text : mst_text,
2355                        secnum_to_section (symbol.n_scnum, objfile),
2356                        objfile);
2357                     break;
2358
2359                   case XMC_GL:
2360                     /* shared library function trampoline code entry
2361                        point. */
2362
2363                     /* record trampoline code entries as
2364                        mst_solib_trampoline symbol.  When we lookup mst
2365                        symbols, we will choose mst_text over
2366                        mst_solib_trampoline. */
2367                     RECORD_MINIMAL_SYMBOL
2368                       (namestring, symbol.n_value,
2369                        mst_solib_trampoline,
2370                        secnum_to_section (symbol.n_scnum, objfile),
2371                        objfile);
2372                     break;
2373
2374                   case XMC_DS:
2375                     /* The symbols often have the same names as
2376                        debug symbols for functions, and confuse
2377                        lookup_symbol.  */
2378                     break;
2379
2380                   default:
2381
2382                     /* xlc puts each variable in a separate csect,
2383                        so we get an XTY_SD for each variable.  But
2384                        gcc puts several variables in a csect, so
2385                        that each variable only gets an XTY_LD.  We
2386                        still need to record them.  This will
2387                        typically be XMC_RW; I suspect XMC_RO and
2388                        XMC_BS might be possible too.  */
2389                     if (*namestring != '.')
2390                       prim_record_minimal_symbol_and_info
2391                         (namestring, symbol.n_value,
2392                          sclass == C_HIDEXT ? mst_file_data : mst_data,
2393                          NULL, secnum_to_section (symbol.n_scnum, objfile),
2394                          NULL, objfile);
2395                     break;
2396                   }
2397                 break;
2398
2399               case XTY_CM:
2400                 switch (csect_aux.x_csect.x_smclas)
2401                   {
2402                   case XMC_RW:
2403                   case XMC_BS:
2404                     /* Common variables are recorded in the minimal symbol
2405                        table, except for section symbols.  */
2406                     if (*namestring != '.')
2407                       prim_record_minimal_symbol_and_info
2408                         (namestring, symbol.n_value,
2409                          sclass == C_HIDEXT ? mst_file_bss : mst_bss,
2410                          NULL, secnum_to_section (symbol.n_scnum, objfile),
2411                          NULL, objfile);
2412                     break;
2413                   }
2414                 break;
2415
2416               default:
2417                 break;
2418               }
2419           }
2420           break;
2421         case C_FILE:
2422           {
2423             unsigned int symnum_before;
2424
2425             symnum_before = ssymnum;
2426             swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2427                       &ssymnum, objfile);
2428
2429             /* See if the last csect needs to be recorded.  */
2430
2431             if (last_csect_name && !misc_func_recorded)
2432               {
2433
2434                 /* If no misc. function recorded in the last seen csect, enter
2435                    it as a function.  This will take care of functions like
2436                    strcmp() compiled by xlc.  */
2437
2438                 RECORD_MINIMAL_SYMBOL
2439                   (last_csect_name, last_csect_val,
2440                    mst_text, last_csect_sec, objfile);
2441               }
2442
2443             if (pst)
2444               {
2445                 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2446                                    symnum_before, dependency_list,
2447                                    dependencies_used, textlow_not_set);
2448                 includes_used = 0;
2449                 dependencies_used = 0;
2450               }
2451             first_fun_line_offset = 0;
2452
2453             /* XCOFF, according to the AIX 3.2 documentation, puts the
2454                filename in cs->c_name.  But xlc 1.3.0.2 has decided to
2455                do things the standard COFF way and put it in the auxent.
2456                We use the auxent if the symbol is ".file" and an auxent
2457                exists, otherwise use the symbol itself.  */
2458             if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2459               {
2460                 filestring = coff_getfilename (&main_aux[0], objfile);
2461               }
2462             else
2463               filestring = namestring;
2464
2465             pst = xcoff_start_psymtab (objfile,
2466                                        filestring,
2467                                        symnum_before,
2468                                        objfile->global_psymbols.next,
2469                                        objfile->static_psymbols.next);
2470             last_csect_name = NULL;
2471           }
2472           break;
2473
2474         default:
2475           {
2476             static struct complaint msg =
2477             {"Storage class %d not recognized during scan", 0, 0};
2478             complain (&msg, sclass);
2479           }
2480           /* FALLTHROUGH */
2481
2482           /* C_FCN is .bf and .ef symbols.  I think it is sufficient
2483              to handle only the C_FUN and C_EXT.  */
2484         case C_FCN:
2485
2486         case C_BSTAT:
2487         case C_ESTAT:
2488         case C_ARG:
2489         case C_REGPARM:
2490         case C_REG:
2491         case C_TPDEF:
2492         case C_STRTAG:
2493         case C_UNTAG:
2494         case C_ENTAG:
2495         case C_LABEL:
2496         case C_NULL:
2497
2498           /* C_EINCL means we are switching back to the main file.  But there
2499              is no reason to care; the only thing we want to know about
2500              includes is the names of all the included (.h) files.  */
2501         case C_EINCL:
2502
2503         case C_BLOCK:
2504
2505           /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2506              used instead.  */
2507         case C_STAT:
2508
2509           /* I don't think the name of the common block (as opposed to the
2510              variables within it) is something which is user visible
2511              currently.  */
2512         case C_BCOMM:
2513         case C_ECOMM:
2514
2515         case C_PSYM:
2516         case C_RPSYM:
2517
2518           /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2519              so C_LSYM would appear to be only for locals.  */
2520         case C_LSYM:
2521
2522         case C_AUTO:
2523         case C_RSYM:
2524           {
2525             /* We probably could save a few instructions by assuming that
2526                C_LSYM, C_PSYM, etc., never have auxents.  */
2527             int naux1 = symbol.n_numaux + 1;
2528             ssymnum += naux1;
2529             sraw_symbol += bfd_coff_symesz (abfd) * naux1;
2530           }
2531           break;
2532
2533         case C_BINCL:
2534           stype = N_SOL;
2535           goto pstab;
2536
2537         case C_FUN:
2538           /* The value of the C_FUN is not the address of the function (it
2539              appears to be the address before linking), but as long as it
2540              is smaller than the actual address, then find_pc_partial_function
2541              will use the minimal symbols instead.  I hope.  */
2542
2543         case C_GSYM:
2544         case C_ECOML:
2545         case C_DECL:
2546         case C_STSYM:
2547           stype = N_LSYM;
2548         pstab:
2549           swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2550                     &ssymnum, objfile);
2551 #define CUR_SYMBOL_TYPE stype
2552 #define CUR_SYMBOL_VALUE symbol.n_value
2553
2554 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2555    called from DBXREAD_ONLY or N_SO code.  Likewise for the symnum
2556    variable.  */
2557 #define START_PSYMTAB(ofile,fname,low,symoff,global_syms,static_syms) 0
2558 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
2559   do {} while (0)
2560 /* We have already set the namestring.  */
2561 #define SET_NAMESTRING()        /* */
2562
2563 #include "partial-stab.h"
2564         }
2565     }
2566
2567   if (pst)
2568     {
2569       xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2570                          ssymnum, dependency_list,
2571                          dependencies_used, textlow_not_set);
2572     }
2573
2574   /* Record the toc offset value of this symbol table into objfile structure.
2575      If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2576      this information would be file auxiliary header. */
2577
2578   ((struct coff_symfile_info *) objfile->sym_private)->toc_offset = toc_offset;
2579 }
2580
2581 /* Return the toc offset value for a given objfile.  */
2582
2583 CORE_ADDR
2584 get_toc_offset (struct objfile *objfile)
2585 {
2586   if (objfile)
2587     return ((struct coff_symfile_info *) objfile->sym_private)->toc_offset;
2588   return 0;
2589 }
2590
2591 /* Scan and build partial symbols for a symbol file.
2592    We have been initialized by a call to dbx_symfile_init, which 
2593    put all the relevant info into a "struct dbx_symfile_info",
2594    hung off the objfile structure.
2595
2596    SECTION_OFFSETS contains offsets relative to which the symbols in the
2597    various sections are (depending where the sections were actually loaded).
2598    MAINLINE is true if we are reading the main symbol
2599    table (as opposed to a shared lib or dynamically loaded file).  */
2600
2601 static void
2602 xcoff_initial_scan (struct objfile *objfile, int mainline)
2603 {
2604   bfd *abfd;
2605   int val;
2606   struct cleanup *back_to;
2607   int num_symbols;              /* # of symbols */
2608   file_ptr symtab_offset;       /* symbol table and */
2609   file_ptr stringtab_offset;    /* string table file offsets */
2610   struct coff_symfile_info *info;
2611   char *name;
2612   unsigned int size;
2613
2614   info = (struct coff_symfile_info *) objfile->sym_private;
2615   symfile_bfd = abfd = objfile->obfd;
2616   name = objfile->name;
2617
2618   num_symbols = bfd_get_symcount (abfd);        /* # of symbols */
2619   symtab_offset = obj_sym_filepos (abfd);       /* symbol table file offset */
2620   stringtab_offset = symtab_offset +
2621     num_symbols * coff_data (abfd)->local_symesz;
2622
2623   info->min_lineno_offset = 0;
2624   info->max_lineno_offset = 0;
2625   bfd_map_over_sections (abfd, find_linenos, info);
2626
2627   if (num_symbols > 0)
2628     {
2629       /* Read the string table.  */
2630       init_stringtab (abfd, stringtab_offset, objfile);
2631
2632       /* Read the .debug section, if present.  */
2633       {
2634         sec_ptr secp;
2635         bfd_size_type length;
2636         char *debugsec = NULL;
2637
2638         secp = bfd_get_section_by_name (abfd, ".debug");
2639         if (secp)
2640           {
2641             length = bfd_section_size (abfd, secp);
2642             if (length)
2643               {
2644                 debugsec =
2645                   (char *) obstack_alloc (&objfile->symbol_obstack, length);
2646
2647                 if (!bfd_get_section_contents (abfd, secp, debugsec,
2648                                                (file_ptr) 0, length))
2649                   {
2650                     error ("Error reading .debug section of `%s': %s",
2651                            name, bfd_errmsg (bfd_get_error ()));
2652                   }
2653               }
2654           }
2655         ((struct coff_symfile_info *) objfile->sym_private)->debugsec =
2656           debugsec;
2657       }
2658     }
2659
2660   /* Read the symbols.  We keep them in core because we will want to
2661      access them randomly in read_symbol*.  */
2662   val = bfd_seek (abfd, symtab_offset, SEEK_SET);
2663   if (val < 0)
2664     error ("Error reading symbols from %s: %s",
2665            name, bfd_errmsg (bfd_get_error ()));
2666   size = coff_data (abfd)->local_symesz * num_symbols;
2667   ((struct coff_symfile_info *) objfile->sym_private)->symtbl =
2668     obstack_alloc (&objfile->symbol_obstack, size);
2669   ((struct coff_symfile_info *) objfile->sym_private)->symtbl_num_syms =
2670     num_symbols;
2671
2672   val = bfd_read (((struct coff_symfile_info *) objfile->sym_private)->symtbl,
2673                   size, 1, abfd);
2674   if (val != size)
2675     perror_with_name ("reading symbol table");
2676
2677   /* If we are reinitializing, or if we have never loaded syms yet, init */
2678   if (mainline
2679       || objfile->global_psymbols.size == 0
2680       || objfile->static_psymbols.size == 0)
2681     /* I'm not sure how how good num_symbols is; the rule of thumb in
2682        init_psymbol_list was developed for a.out.  On the one hand,
2683        num_symbols includes auxents.  On the other hand, it doesn't
2684        include N_SLINE.  */
2685     init_psymbol_list (objfile, num_symbols);
2686
2687   free_pending_blocks ();
2688   back_to = make_cleanup (really_free_pendings, 0);
2689
2690   init_minimal_symbol_collection ();
2691   make_cleanup_discard_minimal_symbols ();
2692
2693   /* Now that the symbol table data of the executable file are all in core,
2694      process them and define symbols accordingly.  */
2695
2696   scan_xcoff_symtab (objfile);
2697
2698   /* Install any minimal symbols that have been collected as the current
2699      minimal symbols for this objfile. */
2700
2701   install_minimal_symbols (objfile);
2702
2703   do_cleanups (back_to);
2704 }
2705 \f
2706 static void
2707 xcoff_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
2708 {
2709   asection *sect = NULL;
2710   int i;
2711
2712   objfile->num_sections = SECT_OFF_MAX;
2713   objfile->section_offsets = (struct section_offsets *)
2714     obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
2715
2716   /* Initialize the section indexes for future use. */
2717   sect = bfd_get_section_by_name (objfile->obfd, ".text");
2718   if (sect) 
2719     objfile->sect_index_text = sect->index;
2720
2721   sect = bfd_get_section_by_name (objfile->obfd, ".data");
2722   if (sect) 
2723     objfile->sect_index_data = sect->index;
2724
2725   sect = bfd_get_section_by_name (objfile->obfd, ".bss");
2726   if (sect) 
2727     objfile->sect_index_bss = sect->index;
2728
2729   sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
2730   if (sect) 
2731     objfile->sect_index_rodata = sect->index;
2732
2733   for (i = 0; i < objfile->num_sections; ++i)
2734     {
2735       /* syms_from_objfile kindly subtracts from addr the
2736          bfd_section_vma of the .text section.  This strikes me as
2737          wrong--whether the offset to be applied to symbol reading is
2738          relative to the start address of the section depends on the
2739          symbol format.  In any event, this whole "addr" concept is
2740          pretty broken (it doesn't handle any section but .text
2741          sensibly), so just ignore the addr parameter and use 0.
2742          rs6000-nat.c will set the correct section offsets via
2743          objfile_relocate.  */
2744         (objfile->section_offsets)->offsets[i] = 0;
2745     }
2746 }
2747
2748 /* Register our ability to parse symbols for xcoff BFD files.  */
2749
2750 static struct sym_fns xcoff_sym_fns =
2751 {
2752
2753   /* It is possible that coff and xcoff should be merged as
2754      they do have fundamental similarities (for example, the extra storage
2755      classes used for stabs could presumably be recognized in any COFF file).
2756      However, in addition to obvious things like all the csect hair, there are
2757      some subtler differences between xcoffread.c and coffread.c, notably
2758      the fact that coffread.c has no need to read in all the symbols, but
2759      xcoffread.c reads all the symbols and does in fact randomly access them
2760      (in C_BSTAT and line number processing).  */
2761
2762   bfd_target_xcoff_flavour,
2763
2764   xcoff_new_init,               /* sym_new_init: init anything gbl to entire symtab */
2765   xcoff_symfile_init,           /* sym_init: read initial info, setup for sym_read() */
2766   xcoff_initial_scan,           /* sym_read: read a symbol file into symtab */
2767   xcoff_symfile_finish,         /* sym_finish: finished with file, cleanup */
2768   xcoff_symfile_offsets,        /* sym_offsets: xlate offsets ext->int form */
2769   NULL                          /* next: pointer to next struct sym_fns */
2770 };
2771
2772 void
2773 _initialize_xcoffread (void)
2774 {
2775   add_symtab_fns (&xcoff_sym_fns);
2776
2777   func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
2778                                 "<function, no debug info>", NULL);
2779   TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;
2780   var_symbol_type =
2781     init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
2782                "<variable, no debug info>", NULL);
2783 }