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