bcopy -> memcpy
[binutils-gdb.git] / gdb / xcoffread.c
1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
3 Free Software Foundation, Inc.
4 Derived from coffread.c, dbxread.c, and a lot of hacking.
5 Contributed by IBM Corporation.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22
23 /* Native only: Need struct tbtable in <sys/debug.h> from host, and
24 need xcoff_add_toc_to_loadinfo in rs6000-tdep.c from target.
25 need xcoff_init_loadinfo ditto.
26 However, if you grab <sys/debug.h> and make it available on your
27 host, and define FAKING_RS6000, then this code will compile. */
28
29 #include "defs.h"
30 #include "bfd.h"
31
32 #include <sys/types.h>
33 #include <fcntl.h>
34 #include <ctype.h>
35
36 #include "obstack.h"
37 #include <sys/param.h>
38 #ifndef NO_SYS_FILE
39 #include <sys/file.h>
40 #endif
41 #include <sys/stat.h>
42 #include <sys/debug.h>
43
44 #include "symtab.h"
45 #include "gdbtypes.h"
46 #include "symfile.h"
47 #include "objfiles.h"
48 #include "buildsym.h"
49 #include "stabsread.h"
50 #include "complaints.h"
51
52 #include "coff/internal.h" /* FIXME, internal data from BFD */
53 #include "libcoff.h" /* FIXME, internal data from BFD */
54 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
55
56 /* For interface with stabsread.c. */
57 #include "aout/stab_gnu.h"
58
59 /* Simplified internal version of coff symbol table information */
60
61 struct coff_symbol {
62 char *c_name;
63 int c_symnum; /* symbol number of this entry */
64 int c_nsyms; /* 0 if syment only, 1 if syment + auxent */
65 long c_value;
66 unsigned char c_sclass;
67 int c_secnum;
68 unsigned int c_type;
69 };
70
71 /* The COFF line table, in raw form. */
72 static char *linetab = NULL; /* Its actual contents */
73 static long linetab_offset; /* Its offset in the file */
74 static unsigned long linetab_size; /* Its size */
75
76 /* last function's saved coff symbol `cs' */
77
78 static struct coff_symbol fcn_cs_saved;
79
80 static bfd *symfile_bfd;
81
82 /* Core address of start and end of text of current source file.
83 This is calculated from the first function seen after a C_FILE
84 symbol. */
85
86
87 static CORE_ADDR cur_src_end_addr;
88
89 /* Core address of the end of the first object file. */
90
91 static CORE_ADDR first_object_file_end;
92
93 /* pointer to the string table */
94 static char *strtbl;
95
96 /* length of the string table */
97 static int strtbl_len;
98
99 /* pointer to debug section */
100 static char *debugsec;
101
102 /* pointer to the a.out symbol table */
103 static char *symtbl;
104
105 /* Number of symbols in symtbl. */
106 static int symtbl_num_syms;
107
108 /* initial symbol-table-debug-string vector length */
109
110 #define INITIAL_STABVECTOR_LENGTH 40
111
112 /* Nonzero if within a function (so symbols should be local,
113 if nothing says specifically). */
114
115 int within_function;
116
117 /* Local variables that hold the shift and mask values for the
118 COFF file that we are currently reading. These come back to us
119 from BFD, and are referenced by their macro names, as well as
120 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
121 macros from ../internalcoff.h . */
122
123 static unsigned local_n_btshft;
124 static unsigned local_n_tmask;
125
126 #undef N_BTSHFT
127 #define N_BTSHFT local_n_btshft
128 #undef N_TMASK
129 #define N_TMASK local_n_tmask
130
131 /* Local variables that hold the sizes in the file of various COFF structures.
132 (We only need to know this to read them from the file -- BFD will then
133 translate the data in them, into `internal_xxx' structs in the right
134 byte order, alignment, etc.) */
135
136 static unsigned local_symesz;
137
138 struct coff_symfile_info {
139 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
140 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
141 };
142
143 static struct complaint rsym_complaint =
144 {"Non-stab C_RSYM `%s' needs special handling", 0, 0};
145
146 static struct complaint storclass_complaint =
147 {"Unexpected storage class: %d", 0, 0};
148
149 static struct complaint bf_notfound_complaint =
150 {"line numbers off, `.bf' symbol not found", 0, 0};
151
152 static void
153 enter_line_range PARAMS ((struct subfile *, unsigned, unsigned,
154 CORE_ADDR, CORE_ADDR, unsigned *));
155
156 static void
157 free_debugsection PARAMS ((void));
158
159 static int
160 init_debugsection PARAMS ((bfd *));
161
162 static int
163 init_stringtab PARAMS ((bfd *, file_ptr, struct objfile *));
164
165 static void
166 xcoff_symfile_init PARAMS ((struct objfile *));
167
168 static void
169 xcoff_new_init PARAMS ((struct objfile *));
170
171 #ifdef __STDC__
172 struct section_offset;
173 #endif
174
175 static void
176 xcoff_symfile_read PARAMS ((struct objfile *, struct section_offset *, int));
177
178 static void
179 xcoff_symfile_finish PARAMS ((struct objfile *));
180
181 static struct section_offsets *
182 xcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
183
184 static int
185 init_lineno PARAMS ((bfd *, file_ptr, int));
186
187 static void
188 free_linetab PARAMS ((void));
189
190 static void
191 find_linenos PARAMS ((bfd *, sec_ptr, PTR));
192
193 static void
194 read_symbol PARAMS ((struct internal_syment *, int));
195
196 static int
197 read_symbol_lineno PARAMS ((int));
198
199 static int
200 read_symbol_nvalue PARAMS ((int));
201
202 static struct symbol *
203 process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *));
204
205 static void
206 read_xcoff_symtab PARAMS ((struct objfile *, int));
207
208 static void
209 add_stab_to_list PARAMS ((char *, struct pending_stabs **));
210
211 /* add a given stab string into given stab vector. */
212
213 static void
214 add_stab_to_list (stabname, stabvector)
215 char *stabname;
216 struct pending_stabs **stabvector;
217 {
218 if ( *stabvector == NULL) {
219 *stabvector = (struct pending_stabs *)
220 xmalloc (sizeof (struct pending_stabs) +
221 INITIAL_STABVECTOR_LENGTH * sizeof (char*));
222 (*stabvector)->count = 0;
223 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
224 }
225 else if ((*stabvector)->count >= (*stabvector)->length) {
226 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
227 *stabvector = (struct pending_stabs *)
228 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
229 (*stabvector)->length * sizeof (char*));
230 }
231 (*stabvector)->stab [(*stabvector)->count++] = stabname;
232 }
233 \f
234 /* Linenos are processed on a file-by-file basis.
235
236 Two reasons:
237
238 1) xlc (IBM's native c compiler) postpones static function code
239 emission to the end of a compilation unit. This way it can
240 determine if those functions (statics) are needed or not, and
241 can do some garbage collection (I think). This makes line
242 numbers and corresponding addresses unordered, and we end up
243 with a line table like:
244
245
246 lineno addr
247 foo() 10 0x100
248 20 0x200
249 30 0x300
250
251 foo3() 70 0x400
252 80 0x500
253 90 0x600
254
255 static foo2()
256 40 0x700
257 50 0x800
258 60 0x900
259
260 and that breaks gdb's binary search on line numbers, if the
261 above table is not sorted on line numbers. And that sort
262 should be on function based, since gcc can emit line numbers
263 like:
264
265 10 0x100 - for the init/test part of a for stmt.
266 20 0x200
267 30 0x300
268 10 0x400 - for the increment part of a for stmt.
269
270 arrange_linetable() will do this sorting.
271
272 2) aix symbol table might look like:
273
274 c_file // beginning of a new file
275 .bi // beginning of include file
276 .ei // end of include file
277 .bi
278 .ei
279
280 basically, .bi/.ei pairs do not necessarily encapsulate
281 their scope. They need to be recorded, and processed later
282 on when we come the end of the compilation unit.
283 Include table (inclTable) and process_linenos() handle
284 that. */
285
286 /* compare line table entry addresses. */
287
288 static int
289 compare_lte (lte1, lte2)
290 struct linetable_entry *lte1, *lte2;
291 {
292 return lte1->pc - lte2->pc;
293 }
294
295 /* Give a line table with function entries are marked, arrange its functions
296 in assending order and strip off function entry markers and return it in
297 a newly created table. If the old one is good enough, return the old one. */
298
299 static struct linetable *
300 arrange_linetable (oldLineTb)
301 struct linetable *oldLineTb; /* old linetable */
302 {
303 int ii, jj,
304 newline, /* new line count */
305 function_count; /* # of functions */
306
307 struct linetable_entry *fentry; /* function entry vector */
308 int fentry_size; /* # of function entries */
309 struct linetable *newLineTb; /* new line table */
310
311 #define NUM_OF_FUNCTIONS 20
312
313 fentry_size = NUM_OF_FUNCTIONS;
314 fentry = (struct linetable_entry*)
315 xmalloc (fentry_size * sizeof (struct linetable_entry));
316
317 for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) {
318
319 if (oldLineTb->item[ii].line == 0) { /* function entry found. */
320
321 if (function_count >= fentry_size) { /* make sure you have room. */
322 fentry_size *= 2;
323 fentry = (struct linetable_entry*)
324 xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
325 }
326 fentry[function_count].line = ii;
327 fentry[function_count].pc = oldLineTb->item[ii].pc;
328 ++function_count;
329 }
330 }
331
332 if (function_count == 0) {
333 free (fentry);
334 return oldLineTb;
335 }
336 else if (function_count > 1)
337 qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte);
338
339 /* allocate a new line table. */
340 newLineTb = (struct linetable *)
341 xmalloc
342 (sizeof (struct linetable) +
343 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
344
345 /* if line table does not start with a function beginning, copy up until
346 a function begin. */
347
348 newline = 0;
349 if (oldLineTb->item[0].line != 0)
350 for (newline=0;
351 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
352 newLineTb->item[newline] = oldLineTb->item[newline];
353
354 /* Now copy function lines one by one. */
355
356 for (ii=0; ii < function_count; ++ii) {
357 for (jj = fentry[ii].line + 1;
358 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
359 ++jj, ++newline)
360 newLineTb->item[newline] = oldLineTb->item[jj];
361 }
362 free (fentry);
363 newLineTb->nitems = oldLineTb->nitems - function_count;
364 return newLineTb;
365 }
366
367
368
369 /* We try to detect the beginning of a compilation unit. That info will
370 be used as an entry in line number recording routines (enter_line_range) */
371
372 static unsigned first_fun_line_offset;
373 static unsigned first_fun_bf;
374
375 #define mark_first_line(OFFSET, SYMNUM) \
376 if (!first_fun_line_offset) { \
377 first_fun_line_offset = OFFSET; \
378 first_fun_bf = SYMNUM; \
379 }
380
381
382 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
383 following `IncludeChain'. At the end of each symtab (end_symtab),
384 we will determine if we should create additional symtab's to
385 represent if (the include files. */
386
387
388 typedef struct _inclTable {
389 char *name; /* include filename */
390
391 /* Offsets to the line table. end points to the last entry which is
392 part of this include file. */
393 int begin, end;
394
395 struct subfile *subfile;
396 unsigned funStartLine; /* start line # of its function */
397 } InclTable;
398
399 #define INITIAL_INCLUDE_TABLE_LENGTH 20
400 static InclTable *inclTable; /* global include table */
401 static int inclIndx; /* last entry to table */
402 static int inclLength; /* table length */
403 static int inclDepth; /* nested include depth */
404
405
406 static void
407 record_include_begin (cs)
408 struct coff_symbol *cs;
409 {
410 if (inclDepth)
411 {
412 /* In xcoff, we assume include files cannot be nested (not in .c files
413 of course, but in corresponding .s files.). */
414
415 /* This can happen with old versions of GCC.
416 GCC 2.3.3-930426 does not exhibit this on a test case which
417 a user said produced the message for him. */
418 static struct complaint msg = {"Nested C_BINCL symbols", 0, 0};
419 complain (&msg);
420 }
421 ++inclDepth;
422
423 /* allocate an include file, or make room for the new entry */
424 if (inclLength == 0) {
425 inclTable = (InclTable*)
426 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
427 bzero (inclTable, sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
428 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
429 inclIndx = 0;
430 }
431 else if (inclIndx >= inclLength) {
432 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
433 inclTable = (InclTable*)
434 xrealloc (inclTable, sizeof (InclTable) * inclLength);
435 bzero (inclTable+inclLength-INITIAL_INCLUDE_TABLE_LENGTH,
436 sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
437 }
438
439 inclTable [inclIndx].name = cs->c_name;
440 inclTable [inclIndx].begin = cs->c_value;
441 }
442
443
444 static void
445 record_include_end (cs)
446 struct coff_symbol *cs;
447 {
448 InclTable *pTbl;
449
450 if (inclDepth == 0)
451 {
452 static struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
453 complain (&msg);
454 }
455
456 pTbl = &inclTable [inclIndx];
457 pTbl->end = cs->c_value;
458
459 --inclDepth;
460 ++inclIndx;
461 }
462
463
464 /* given the start and end addresses of a compilation unit (or a csect, at times)
465 process its lines and create appropriate line vectors. */
466
467 static void
468 process_linenos (start, end)
469 CORE_ADDR start, end;
470 {
471 char *pp;
472 int offset, ii;
473
474 struct subfile main_subfile; /* subfile structure for the main
475 compilation unit. */
476
477 /* in the main source file, any time we see a function entry, we reset
478 this variable to function's absolute starting line number. All the
479 following line numbers in the function are relative to this, and
480 we record absolute line numbers in record_line(). */
481
482 int main_source_baseline = 0;
483
484
485 unsigned *firstLine;
486 CORE_ADDR addr;
487
488 if (!(offset = first_fun_line_offset))
489 goto return_after_cleanup;
490
491 bzero (&main_subfile, sizeof (main_subfile));
492 first_fun_line_offset = 0;
493
494 if (inclIndx == 0)
495 /* All source lines were in the main source file. None in include files. */
496
497 enter_line_range (&main_subfile, offset, 0, start, end,
498 &main_source_baseline);
499
500 /* else, there was source with line numbers in include files */
501 else {
502
503 main_source_baseline = 0;
504 for (ii=0; ii < inclIndx; ++ii) {
505
506 struct subfile *tmpSubfile;
507
508 /* if there is main file source before include file, enter it. */
509 if (offset < inclTable[ii].begin) {
510 enter_line_range
511 (&main_subfile, offset, inclTable[ii].begin - LINESZ, start, 0,
512 &main_source_baseline);
513 }
514
515 /* Have a new subfile for the include file */
516
517 tmpSubfile = inclTable[ii].subfile = (struct subfile*)
518 xmalloc (sizeof (struct subfile));
519
520 bzero (tmpSubfile, sizeof (struct subfile));
521 firstLine = &(inclTable[ii].funStartLine);
522
523 /* enter include file's lines now. */
524 enter_line_range (tmpSubfile, inclTable[ii].begin,
525 inclTable[ii].end, start, 0, firstLine);
526
527 offset = inclTable[ii].end + LINESZ;
528 }
529
530 /* all the include files' line have been processed at this point. Now,
531 enter remaining lines of the main file, if any left. */
532 if (offset < (linetab_offset + linetab_size + 1 - LINESZ)) {
533 enter_line_range (&main_subfile, offset, 0, start, end,
534 &main_source_baseline);
535 }
536 }
537
538 /* Process main file's line numbers. */
539 if (main_subfile.line_vector) {
540 struct linetable *lineTb, *lv;
541
542 lv = main_subfile.line_vector;
543
544 /* Line numbers are not necessarily ordered. xlc compilation will
545 put static function to the end. */
546
547 lineTb = arrange_linetable (lv);
548 if (lv == lineTb) {
549 current_subfile->line_vector = (struct linetable *)
550 xrealloc (lv, (sizeof (struct linetable)
551 + lv->nitems * sizeof (struct linetable_entry)));
552
553 }
554 else {
555 free (lv);
556 current_subfile->line_vector = lineTb;
557 }
558
559 current_subfile->line_vector_length =
560 current_subfile->line_vector->nitems;
561 }
562
563 /* Now, process included files' line numbers. */
564
565 for (ii=0; ii < inclIndx; ++ii) {
566
567 if ( (inclTable[ii].subfile)->line_vector) { /* Useless if!!! FIXMEmgo */
568 struct linetable *lineTb, *lv;
569
570 lv = (inclTable[ii].subfile)->line_vector;
571
572 /* Line numbers are not necessarily ordered. xlc compilation will
573 put static function to the end. */
574
575 lineTb = arrange_linetable (lv);
576
577 push_subfile ();
578
579 /* For the same include file, we might want to have more than one subfile.
580 This happens if we have something like:
581
582 ......
583 #include "foo.h"
584 ......
585 #include "foo.h"
586 ......
587
588 while foo.h including code in it. (stupid but possible)
589 Since start_subfile() looks at the name and uses an existing one if finds,
590 we need to provide a fake name and fool it. */
591
592 /* start_subfile (inclTable[ii].name, (char*)0); */
593 start_subfile (" ?", (char*)0);
594 free (current_subfile->name);
595 current_subfile->name = strdup (inclTable[ii].name);
596
597 if (lv == lineTb) {
598 current_subfile->line_vector = (struct linetable *)
599 xrealloc (lv, (sizeof (struct linetable)
600 + lv->nitems * sizeof (struct linetable_entry)));
601
602 }
603 else {
604 free (lv);
605 current_subfile->line_vector = lineTb;
606 }
607
608 current_subfile->line_vector_length =
609 current_subfile->line_vector->nitems;
610 start_subfile (pop_subfile (), (char*)0);
611 }
612 }
613
614 return_after_cleanup:
615
616 /* We don't want to keep alloc/free'ing the global include file table. */
617 inclIndx = 0;
618
619 /* start with a fresh subfile structure for the next file. */
620 bzero (&main_subfile, sizeof (struct subfile));
621 }
622
623 void
624 aix_process_linenos ()
625 {
626 /* process line numbers and enter them into line vector */
627 process_linenos (last_source_start_addr, cur_src_end_addr);
628 }
629
630
631 /* Enter a given range of lines into the line vector.
632 can be called in the following two ways:
633 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
634 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
635
636 endoffset points to the last line table entry that we should pay
637 attention to. */
638
639 static void
640 enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr, firstLine)
641 struct subfile *subfile;
642 unsigned beginoffset, endoffset; /* offsets to line table */
643 CORE_ADDR startaddr, endaddr;
644 unsigned *firstLine;
645 {
646 char *pp, *limit;
647 CORE_ADDR addr;
648
649 /* Do Byte swapping, if needed. FIXME! */
650 #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno)
651 #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr)
652 #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx)
653
654 pp = &linetab [beginoffset - linetab_offset];
655 if (endoffset != 0 && endoffset - linetab_offset >= linetab_size)
656 {
657 static struct complaint msg =
658 {"Bad line table offset in C_EINCL directive", 0, 0};
659 complain (&msg);
660 return;
661 }
662 limit = endoffset ? &linetab [endoffset - linetab_offset]
663 : &linetab [linetab_size -1];
664
665 while (pp <= limit) {
666
667 /* find the address this line represents */
668 addr = P_LINENO(pp) ?
669 P_LINEADDR(pp) : read_symbol_nvalue (P_LINESYM(pp));
670
671 if (addr < startaddr || (endaddr && addr >= endaddr))
672 return;
673
674 if (P_LINENO(pp) == 0) {
675 *firstLine = read_symbol_lineno (P_LINESYM(pp));
676 record_line (subfile, 0, addr);
677 --(*firstLine);
678 }
679 else
680 record_line (subfile, *firstLine + P_LINENO(pp), addr);
681
682 pp += LINESZ;
683 }
684 }
685
686 typedef struct {
687 int fsize; /* file size */
688 int fixedparms; /* number of fixed parms */
689 int floatparms; /* number of float parms */
690 unsigned int parminfo; /* parameter info.
691 See /usr/include/sys/debug.h
692 tbtable_ext.parminfo */
693 int framesize; /* function frame size */
694 } TracebackInfo;
695
696
697 /* Given a function symbol, return its traceback information. */
698
699 TracebackInfo *
700 retrieve_tracebackinfo (abfd, textsec, cs)
701 bfd *abfd;
702 sec_ptr textsec;
703 struct coff_symbol *cs;
704 {
705 #define TBTABLE_BUFSIZ 2000
706
707 static TracebackInfo tbInfo;
708 struct tbtable *ptb;
709
710 static char buffer [TBTABLE_BUFSIZ];
711
712 int *pinsn;
713 int bytesread=0; /* total # of bytes read so far */
714 int bufferbytes; /* number of bytes in the buffer */
715
716 int functionstart = cs->c_value - textsec->vma;
717
718 bzero (&tbInfo, sizeof (tbInfo));
719
720 /* keep reading blocks of data from the text section, until finding a zero
721 word and a traceback table. */
722
723 /* Note: The logical thing way to write this code would be to assign
724 to bufferbytes within the while condition. But that triggers a
725 compiler (xlc in AIX 3.2) bug, so simplify it... */
726 bufferbytes =
727 (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread) ?
728 TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread));
729 while (bufferbytes
730 && (bfd_get_section_contents
731 (abfd, textsec, buffer,
732 (file_ptr)(functionstart + bytesread), bufferbytes)))
733 {
734 bytesread += bufferbytes;
735 pinsn = (int*) buffer;
736
737 /* if this is the first time we filled the buffer, retrieve function
738 framesize info. */
739
740 if (bytesread == bufferbytes) {
741
742 /* skip over unrelated instructions */
743
744 if (*pinsn == 0x7c0802a6) /* mflr r0 */
745 ++pinsn;
746 if ((*pinsn & 0xfc00003e) == 0x7c000026) /* mfcr Rx */
747 ++pinsn;
748 if ((*pinsn & 0xfc000000) == 0x48000000) /* bl foo, save fprs */
749 ++pinsn;
750 if ((*pinsn & 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
751 ++pinsn;
752
753 do {
754 int tmp = (*pinsn >> 16) & 0xffff;
755
756 if (tmp == 0x9421) { /* stu r1, NUM(r1) */
757 tbInfo.framesize = 0x10000 - (*pinsn & 0xffff);
758 break;
759 }
760 else if ((*pinsn == 0x93e1fffc) || /* st r31,-4(r1) */
761 (tmp == 0x9001)) /* st r0, NUM(r1) */
762 ;
763 /* else, could not find a frame size. */
764 else
765 return NULL;
766
767 } while (++pinsn && *pinsn);
768
769 if (!tbInfo.framesize)
770 return NULL;
771
772 }
773
774 /* look for a zero word. */
775
776 while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int))))
777 ++pinsn;
778
779 if (pinsn >= (int*)(buffer + bufferbytes))
780 continue;
781
782 if (*pinsn == 0) {
783
784 /* function size is the amount of bytes we have skipped so far. */
785 tbInfo.fsize = bytesread - (buffer + bufferbytes - (char*)pinsn);
786
787 ++pinsn;
788
789 /* if we don't have the whole traceback table in the buffer, re-read
790 the whole thing. */
791
792 /* This is how much to read to get the traceback table.
793 8 bytes of the traceback table are always present, plus we
794 look at parminfo. */
795 #define MIN_TBTABSIZ 12
796
797 if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) {
798
799 /* In case if we are *very* close to the end of the text section
800 and cannot read properly from that point on, abort by returning
801 NULL.
802
803 This could happen if the traceback table is only 8 bytes,
804 but we try to read 12 bytes of it.
805 Handle this case more graciously -- FIXME */
806
807 if (!bfd_get_section_contents (
808 abfd, textsec, buffer,
809 (file_ptr)(functionstart +
810 bytesread - (buffer + bufferbytes - (char*)pinsn)),MIN_TBTABSIZ))
811 { printf ("Abnormal return!..\n"); return NULL; }
812
813 ptb = (struct tbtable *)buffer;
814 }
815 else
816 ptb = (struct tbtable *)pinsn;
817
818 tbInfo.fixedparms = ptb->tb.fixedparms;
819 tbInfo.floatparms = ptb->tb.floatparms;
820 tbInfo.parminfo = ptb->tb_ext.parminfo;
821 return &tbInfo;
822 }
823 bufferbytes =
824 (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread) ?
825 TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread));
826 }
827 return NULL;
828 }
829
830 #if 0
831 /* Given a function symbol, return a pointer to its traceback table. */
832
833 struct tbtable *
834 retrieve_traceback (abfd, textsec, cs, size)
835 bfd *abfd;
836 sec_ptr textsec;
837 struct coff_symbol *cs;
838 int *size; /* return function size */
839 {
840 #define TBTABLE_BUFSIZ 2000
841 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
842 traceback table. */
843
844 static char buffer [TBTABLE_BUFSIZ];
845
846 int *pinsn;
847 int bytesread=0; /* total # of bytes read so far */
848 int bufferbytes; /* number of bytes in the buffer */
849
850 int functionstart = cs->c_value - textsec->filepos + textsec->vma;
851 *size = 0;
852
853 /* keep reading blocks of data from the text section, until finding a zero
854 word and a traceback table. */
855
856 while (bfd_get_section_contents (abfd, textsec, buffer,
857 (file_ptr)(functionstart + bytesread),
858 bufferbytes = (
859 (TBTABLE_BUFSIZ < (textsec->size - functionstart - bytesread)) ?
860 TBTABLE_BUFSIZ : (textsec->size - functionstart - bytesread))))
861 {
862 bytesread += bufferbytes;
863 pinsn = (int*) buffer;
864
865 /* look for a zero word. */
866
867 while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int))))
868 ++pinsn;
869
870 if (pinsn >= (int*)(buffer + bufferbytes))
871 continue;
872
873 if (*pinsn == 0) {
874
875 /* function size is the amount of bytes we have skipped so far. */
876 *size = bytesread - (buffer + bufferbytes - pinsn);
877
878 ++pinsn;
879
880 /* if we don't have the whole traceback table in the buffer, re-read
881 the whole thing. */
882
883 if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) {
884
885 /* In case if we are *very* close to the end of the text section
886 and cannot read properly from that point on, abort for now.
887 Handle this case more graciously -- FIXME */
888
889 if (!bfd_get_section_contents (
890 abfd, textsec, buffer,
891 (file_ptr)(functionstart +
892 bytesread - (buffer + bufferbytes - pinsn)),MIN_TBTABSIZ))
893 /* abort (); */ { printf ("abort!!!\n"); return NULL; }
894
895 return (struct tbtable *)buffer;
896 }
897 else
898 return (struct tbtable *)pinsn;
899 }
900 }
901 return NULL;
902 }
903 #endif /* 0 */
904
905
906
907
908 /* Save the vital information for use when closing off the current file.
909 NAME is the file name the symbols came from, START_ADDR is the first
910 text address for the file, and SIZE is the number of bytes of text. */
911
912 #define complete_symtab(name, start_addr) { \
913 last_source_file = savestring (name, strlen (name)); \
914 last_source_start_addr = start_addr; \
915 }
916
917
918 /* Refill the symbol table input buffer
919 and set the variables that control fetching entries from it.
920 Reports an error if no data available.
921 This function can read past the end of the symbol table
922 (into the string table) but this does no harm. */
923
924 /* Reading symbol table has to be fast! Keep the followings as macros, rather
925 than functions. */
926
927 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED, SECTION) \
928 { \
929 char *namestr; \
930 if (ALLOCED) \
931 namestr = (NAME) + 1; \
932 else { \
933 (NAME) = namestr = \
934 obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
935 (ALLOCED) = 1; \
936 } \
937 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
938 (char *)NULL, (SECTION)); \
939 misc_func_recorded = 1; \
940 }
941
942
943 /* A parameter template, used by ADD_PARM_TO_PENDING. It is initialized
944 in our initializer function at the bottom of the file, to avoid
945 dependencies on the exact "struct symbol" format. */
946
947 static struct symbol parmsym;
948
949 /* Add a parameter to a given pending symbol list. */
950
951 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
952 { \
953 PARM = (struct symbol *) \
954 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
955 *(PARM) = parmsym; \
956 SYMBOL_TYPE (PARM) = PTYPE; \
957 SYMBOL_VALUE (PARM) = VALUE; \
958 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
959 }
960
961
962 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
963 nested. At any given time, a symbol can only be in one static block.
964 This is the base address of current static block, zero if non exists. */
965
966 static int static_block_base = 0;
967
968 /* Section number for the current static block. */
969
970 static int static_block_section = -1;
971
972 /* true if space for symbol name has been allocated. */
973
974 static int symname_alloced = 0;
975
976 /* read the whole symbol table of a given bfd. */
977
978 static void
979 read_xcoff_symtab (objfile, nsyms)
980 struct objfile *objfile; /* Object file we're reading from */
981 int nsyms; /* # of symbols */
982 {
983 bfd *abfd = objfile->obfd;
984 char *raw_symbol; /* Pointer into raw seething symbol table */
985 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
986 sec_ptr textsec; /* Pointer to text section */
987 TracebackInfo *ptb; /* Pointer to traceback table */
988
989 struct internal_syment symbol[1];
990 union internal_auxent main_aux[1];
991 struct coff_symbol cs[1];
992 CORE_ADDR file_start_addr = 0;
993 CORE_ADDR file_end_addr = 0;
994
995 int next_file_symnum = -1;
996 int just_started = 1;
997 int depth = 0;
998 int toc_offset = 0; /* toc offset value in data section. */
999 int val;
1000 int fcn_last_line;
1001 int fcn_start_addr;
1002 long fcn_line_offset;
1003 size_t size;
1004
1005 struct coff_symbol fcn_stab_saved;
1006
1007 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1008 union internal_auxent fcn_aux_saved;
1009 struct type *fcn_type_saved = NULL;
1010 struct context_stack *new;
1011
1012 char *filestring = " _start_ "; /* Name of the current file. */
1013
1014 char *last_csect_name; /* last seen csect's name and value */
1015 CORE_ADDR last_csect_val;
1016 int last_csect_sec;
1017 int misc_func_recorded; /* true if any misc. function */
1018
1019 current_objfile = objfile;
1020
1021 /* Get the appropriate COFF "constants" related to the file we're handling. */
1022 N_TMASK = coff_data (abfd)->local_n_tmask;
1023 N_BTSHFT = coff_data (abfd)->local_n_btshft;
1024 local_symesz = coff_data (abfd)->local_symesz;
1025
1026 last_source_file = NULL;
1027 last_csect_name = 0;
1028 last_csect_val = 0;
1029 misc_func_recorded = 0;
1030
1031 start_stabs ();
1032 start_symtab (filestring, (char *)NULL, file_start_addr);
1033 symnum = 0;
1034 first_object_file_end = 0;
1035
1036 /* Allocate space for the entire symbol table at once, and read it
1037 all in. The bfd is already positioned at the beginning of
1038 the symbol table. */
1039
1040 size = coff_data (abfd)->local_symesz * nsyms;
1041 symtbl = xmalloc (size);
1042 symtbl_num_syms = nsyms;
1043
1044 val = bfd_read (symtbl, size, 1, abfd);
1045 if (val != size)
1046 perror_with_name ("reading symbol table");
1047
1048 raw_symbol = symtbl;
1049
1050 textsec = bfd_get_section_by_name (abfd, ".text");
1051 if (!textsec) {
1052 printf ("Unable to locate text section!\n");
1053 }
1054
1055 while (symnum < nsyms) {
1056
1057 QUIT; /* make this command interruptable. */
1058
1059 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1060 /* read one symbol into `cs' structure. After processing the whole symbol
1061 table, only string table will be kept in memory, symbol table and debug
1062 section of xcoff will be freed. Thus we can mark symbols with names
1063 in string table as `alloced'. */
1064 {
1065 int ii;
1066
1067 /* Swap and align the symbol into a reasonable C structure. */
1068 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1069
1070 cs->c_symnum = symnum;
1071 cs->c_nsyms = symbol->n_numaux;
1072 if (symbol->n_zeroes) {
1073 symname_alloced = 0;
1074 /* We must use the original, unswapped, name here so the name field
1075 pointed to by cs->c_name will persist throughout xcoffread. If
1076 we use the new field, it gets overwritten for each symbol. */
1077 cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
1078 /* If it's exactly E_SYMNMLEN characters long it isn't
1079 '\0'-terminated. */
1080 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1081 {
1082 char *p;
1083 p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
1084 strncpy (p, cs->c_name, E_SYMNMLEN);
1085 p[E_SYMNMLEN] = '\0';
1086 cs->c_name = p;
1087 symname_alloced = 1;
1088 }
1089 } else if (symbol->n_sclass & 0x80) {
1090 cs->c_name = debugsec + symbol->n_offset;
1091 symname_alloced = 0;
1092 } else { /* in string table */
1093 cs->c_name = strtbl + (int)symbol->n_offset;
1094 symname_alloced = 1;
1095 }
1096 cs->c_value = symbol->n_value;
1097 cs->c_sclass = symbol->n_sclass;
1098 cs->c_secnum = symbol->n_scnum;
1099 cs->c_type = (unsigned)symbol->n_type;
1100
1101 raw_symbol += coff_data (abfd)->local_symesz;
1102 ++symnum;
1103
1104 raw_auxptr = raw_symbol; /* Save addr of first aux entry */
1105
1106 /* Skip all the auxents associated with this symbol. */
1107 for (ii = symbol->n_numaux; ii; --ii ) {
1108 raw_symbol += coff_data (abfd)->local_auxesz;
1109 ++symnum;
1110 }
1111 }
1112
1113 /* if symbol name starts with ".$" or "$", ignore it. */
1114 if (cs->c_name[0] == '$' || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1115 continue;
1116
1117 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) {
1118 if (last_source_file)
1119 {
1120 end_symtab (cur_src_end_addr, 1, 0, objfile, textsec->target_index);
1121 end_stabs ();
1122 }
1123
1124 start_stabs ();
1125 start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
1126 cur_src_end_addr = first_object_file_end;
1127 /* done with all files, everything from here on is globals */
1128 }
1129
1130 /* if explicitly specified as a function, treat is as one. */
1131 if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF) {
1132 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1133 main_aux);
1134 goto function_entry_point;
1135 }
1136
1137 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_nsyms == 1)
1138 {
1139 /* dealing with a symbol with a csect entry. */
1140
1141 # define CSECT(PP) ((PP)->x_csect)
1142 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
1143 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1144 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1145 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1146
1147 /* Convert the auxent to something we can access. */
1148 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1149 main_aux);
1150
1151 switch (CSECT_SMTYP (main_aux)) {
1152
1153 case XTY_ER :
1154 continue; /* ignore all external references. */
1155
1156 case XTY_SD : /* a section description. */
1157 {
1158 switch (CSECT_SCLAS (main_aux)) {
1159
1160 case XMC_PR : /* a `.text' csect. */
1161 {
1162
1163 /* A program csect is seen. We have to allocate one
1164 symbol table for each program csect. Normally gdb
1165 prefers one symtab for each source file. In case
1166 of AIX, one source file might include more than one
1167 [PR] csect, and they don't have to be adjacent in
1168 terms of the space they occupy in memory. Thus, one
1169 single source file might get fragmented in the
1170 memory and gdb's file start and end address
1171 approach does not work! GCC (and I think xlc) seem
1172 to put all the code in the unnamed program csect. */
1173
1174 if (last_csect_name) {
1175
1176 /* if no misc. function recorded in the last seen csect, enter
1177 it as a function. This will take care of functions like
1178 strcmp() compiled by xlc. */
1179
1180 if (!misc_func_recorded) {
1181 int alloced = 0;
1182 RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val,
1183 mst_text, alloced, last_csect_sec);
1184 }
1185
1186
1187 complete_symtab (filestring, file_start_addr);
1188 cur_src_end_addr = file_end_addr;
1189 end_symtab (file_end_addr, 1, 0, objfile,
1190 textsec->target_index);
1191 end_stabs ();
1192 start_stabs ();
1193 /* Give all csects for this source file the same
1194 name. */
1195 start_symtab (filestring, (char *)NULL, (CORE_ADDR)0);
1196 }
1197
1198 /* If this is the very first csect seen, basically `__start'. */
1199 if (just_started) {
1200 first_object_file_end = cs->c_value + CSECT_LEN (main_aux);
1201 just_started = 0;
1202 }
1203
1204 file_start_addr = cs->c_value;
1205 file_end_addr = cs->c_value + CSECT_LEN (main_aux);
1206
1207 if (cs->c_name && cs->c_name[0] == '.') {
1208 last_csect_name = cs->c_name;
1209 last_csect_val = cs->c_value;
1210 last_csect_sec = cs->c_secnum;
1211 }
1212 }
1213 misc_func_recorded = 0;
1214 continue;
1215
1216 case XMC_RW :
1217 break;
1218
1219 /* If the section is not a data description, ignore it. Note that
1220 uninitialized data will show up as XTY_CM/XMC_RW pair. */
1221
1222 case XMC_TC0:
1223 if (toc_offset)
1224 warning ("More than one xmc_tc0 symbol found.");
1225 toc_offset = cs->c_value;
1226 continue;
1227
1228 case XMC_TC : /* ignore toc entries */
1229 default : /* any other XMC_XXX */
1230 continue;
1231 }
1232 }
1233 break; /* switch CSECT_SCLAS() */
1234
1235 case XTY_LD :
1236
1237 /* a function entry point. */
1238 if (CSECT_SCLAS (main_aux) == XMC_PR) {
1239
1240 function_entry_point:
1241 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text,
1242 symname_alloced, cs->c_secnum);
1243
1244 fcn_line_offset = main_aux->x_sym.x_fcnary.x_fcn.x_lnnoptr;
1245 fcn_start_addr = cs->c_value;
1246
1247 /* save the function header info, which will be used
1248 when `.bf' is seen. */
1249 fcn_cs_saved = *cs;
1250 fcn_aux_saved = *main_aux;
1251
1252
1253 ptb = NULL;
1254
1255 /* If function has two auxent, then debugging information is
1256 already available for it. Process traceback table for
1257 functions with only one auxent. */
1258
1259 if (cs->c_nsyms == 1)
1260 ptb = retrieve_tracebackinfo (abfd, textsec, cs);
1261
1262 else if (cs->c_nsyms != 2)
1263 abort ();
1264
1265 /* If there is traceback info, create and add parameters for it. */
1266
1267 if (ptb && (ptb->fixedparms || ptb->floatparms)) {
1268
1269 int parmcnt = ptb->fixedparms + ptb->floatparms;
1270 char *parmcode = (char*) &ptb->parminfo;
1271 int parmvalue = ptb->framesize + 0x18; /* sizeof(LINK AREA) == 0x18 */
1272 unsigned int ii, mask;
1273
1274 for (ii=0, mask = 0x80000000; ii <parmcnt; ++ii) {
1275 struct symbol *parm;
1276
1277 if (ptb->parminfo & mask) { /* float or double */
1278 mask = mask >> 1;
1279 if (ptb->parminfo & mask) { /* double parm */
1280 ADD_PARM_TO_PENDING
1281 (parm, parmvalue, builtin_type_double, local_symbols);
1282 parmvalue += sizeof (double);
1283 }
1284 else { /* float parm */
1285 ADD_PARM_TO_PENDING
1286 (parm, parmvalue, builtin_type_float, local_symbols);
1287 parmvalue += sizeof (float);
1288 }
1289 }
1290 else { /* fixed parm, use (int*) for hex rep. */
1291 ADD_PARM_TO_PENDING (parm, parmvalue,
1292 lookup_pointer_type (builtin_type_int),
1293 local_symbols);
1294 parmvalue += sizeof (int);
1295 }
1296 mask = mask >> 1;
1297 }
1298
1299 /* Fake this as a function. Needed in process_xcoff_symbol() */
1300 cs->c_type = 32;
1301
1302 finish_block(process_xcoff_symbol (cs, objfile), &local_symbols,
1303 pending_blocks, cs->c_value,
1304 cs->c_value + ptb->fsize, objfile);
1305 }
1306 continue;
1307 }
1308 /* shared library function trampoline code entry point. */
1309 else if (CSECT_SCLAS (main_aux) == XMC_GL) {
1310
1311 /* record trampoline code entries as mst_unknown symbol. When we
1312 lookup mst symbols, we will choose mst_text over mst_unknown. */
1313
1314 #if 1
1315 /* After the implementation of incremental loading of shared
1316 libraries, we don't want to access trampoline entries. This
1317 approach has a consequence of the necessity to bring the whole
1318 shared library at first, in order do anything with it (putting
1319 breakpoints, using malloc, etc). On the other side, this is
1320 consistient with gdb's behaviour on a SUN platform. */
1321
1322 /* Trying to prefer *real* function entry over its trampoline,
1323 by assigning `mst_unknown' type to trampoline entries fails.
1324 Gdb treats those entries as chars. FIXME. */
1325
1326 /* Recording this entry is necessary. Single stepping relies on
1327 this vector to get an idea about function address boundaries. */
1328
1329 prim_record_minimal_symbol_and_info
1330 ("<trampoline>", cs->c_value, mst_unknown,
1331 (char *)NULL, cs->c_secnum);
1332 #else
1333
1334 /* record trampoline code entries as mst_unknown symbol. When we
1335 lookup mst symbols, we will choose mst_text over mst_unknown. */
1336
1337 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_unknown,
1338 symname_alloced);
1339 #endif
1340 continue;
1341 }
1342 break;
1343
1344 default : /* all other XTY_XXXs */
1345 break;
1346 } /* switch CSECT_SMTYP() */ }
1347
1348 switch (cs->c_sclass) {
1349
1350 case C_FILE:
1351
1352 /* see if the last csect needs to be recorded. */
1353
1354 if (last_csect_name && !misc_func_recorded) {
1355
1356 /* if no misc. function recorded in the last seen csect, enter
1357 it as a function. This will take care of functions like
1358 strcmp() compiled by xlc. */
1359
1360 int alloced = 0;
1361 RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val,
1362 mst_text, alloced, last_csect_sec);
1363 }
1364
1365 /* c_value field contains symnum of next .file entry in table
1366 or symnum of first global after last .file. */
1367
1368 next_file_symnum = cs->c_value;
1369
1370 /* complete symbol table for last object file containing
1371 debugging information. */
1372
1373 /* Whether or not there was a csect in the previous file, we have to call
1374 `end_stabs' and `start_stabs' to reset type_vector,
1375 line_vector, etc. structures. */
1376
1377 complete_symtab (filestring, file_start_addr);
1378 cur_src_end_addr = file_end_addr;
1379 end_symtab (file_end_addr, 1, 0, objfile, textsec->target_index);
1380 end_stabs ();
1381 start_stabs ();
1382 start_symtab (cs->c_name, (char *)NULL, (CORE_ADDR)0);
1383 last_csect_name = 0;
1384
1385 /* reset file start and end addresses. A compilation unit with no text
1386 (only data) should have zero file boundaries. */
1387 file_start_addr = file_end_addr = 0;
1388
1389 filestring = cs->c_name;
1390 break;
1391
1392
1393 case C_FUN:
1394 fcn_stab_saved = *cs;
1395 break;
1396
1397
1398 case C_FCN:
1399 if (STREQ (cs->c_name, ".bf")) {
1400
1401 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1402 main_aux);
1403
1404 within_function = 1;
1405
1406 mark_first_line (fcn_line_offset, cs->c_symnum);
1407
1408 new = push_context (0, fcn_start_addr);
1409
1410 new->name = define_symbol
1411 (fcn_cs_saved.c_value, fcn_stab_saved.c_name, 0, 0, objfile);
1412 if (new->name != NULL)
1413 SYMBOL_SECTION (new->name) = cs->c_secnum;
1414 }
1415 else if (STREQ (cs->c_name, ".ef")) {
1416
1417 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1418 main_aux);
1419
1420 /* the value of .ef is the address of epilogue code;
1421 not useful for gdb */
1422 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1423 contains number of lines to '}' */
1424
1425 fcn_last_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1426 new = pop_context ();
1427 if (context_stack_depth != 0)
1428 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1429 symnum);
1430
1431 finish_block (new->name, &local_symbols, new->old_blocks,
1432 new->start_addr,
1433 fcn_cs_saved.c_value +
1434 fcn_aux_saved.x_sym.x_misc.x_fsize, objfile);
1435 within_function = 0;
1436 }
1437 break;
1438
1439 case C_BSTAT : /* begin static block */
1440 {
1441 struct internal_syment symbol;
1442
1443 read_symbol (&symbol, cs->c_value);
1444 static_block_base = symbol.n_value;
1445 static_block_section = symbol.n_scnum;
1446 }
1447 break;
1448
1449 case C_ESTAT : /* end of static block */
1450 static_block_base = 0;
1451 static_block_section = -1;
1452 break;
1453
1454 case C_ARG : /* These are not implemented. */
1455 case C_REGPARM :
1456 case C_TPDEF :
1457 case C_STRTAG :
1458 case C_UNTAG :
1459 case C_ENTAG :
1460 printf ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass);
1461 break;
1462
1463 case C_HIDEXT : /* ignore these.. */
1464 case C_LABEL :
1465 case C_NULL :
1466 break;
1467
1468 case C_BINCL : /* beginning of include file */
1469
1470 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1471 order. Thus, when wee see them, we might not know enough info
1472 to process them. Thus, we'll be saving them into a table
1473 (inclTable) and postpone their processing. */
1474
1475 record_include_begin (cs);
1476 break;
1477
1478 case C_EINCL : /* end of include file */
1479 /* see the comment after case C_BINCL. */
1480 record_include_end (cs);
1481 break;
1482
1483 case C_BLOCK :
1484 if (STREQ (cs->c_name, ".bb")) {
1485 depth++;
1486 new = push_context (depth, cs->c_value);
1487 }
1488 else if (STREQ (cs->c_name, ".eb")) {
1489 new = pop_context ();
1490 if (depth != new->depth)
1491 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1492 symnum);
1493
1494 depth--;
1495 if (local_symbols && context_stack_depth > 0) {
1496 /* Make a block for the local symbols within. */
1497 finish_block (new->name, &local_symbols, new->old_blocks,
1498 new->start_addr, cs->c_value, objfile);
1499 }
1500 local_symbols = new->locals;
1501 }
1502 break;
1503
1504 default :
1505 process_xcoff_symbol (cs, objfile);
1506 break;
1507 }
1508
1509 } /* while */
1510
1511 if (last_source_file)
1512 {
1513 end_symtab (cur_src_end_addr, 1, 0, objfile, textsec->target_index);
1514 end_stabs ();
1515 }
1516
1517 free (symtbl);
1518 current_objfile = NULL;
1519
1520 /* Record the toc offset value of this symbol table into ldinfo structure.
1521 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
1522 this information would be file auxiliary header. */
1523
1524 #ifndef FAKING_RS6000
1525 xcoff_add_toc_to_loadinfo (toc_offset);
1526 #endif
1527 }
1528
1529 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1530 (SYMBOL2) = (struct symbol *) \
1531 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1532 *(SYMBOL2) = *(SYMBOL1);
1533
1534
1535 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1536 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1537
1538
1539 /* process one xcoff symbol. */
1540
1541 static struct symbol *
1542 process_xcoff_symbol (cs, objfile)
1543 register struct coff_symbol *cs;
1544 struct objfile *objfile;
1545 {
1546 struct symbol onesymbol;
1547 register struct symbol *sym = &onesymbol;
1548 struct symbol *sym2 = NULL;
1549 struct type *ttype;
1550 char *name, *pp, *qq;
1551 int struct_and_type_combined;
1552 int nameless;
1553
1554 name = cs->c_name;
1555 if (name[0] == '.')
1556 ++name;
1557
1558 bzero (sym, sizeof (struct symbol));
1559
1560 /* default assumptions */
1561 SYMBOL_VALUE (sym) = cs->c_value;
1562 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1563 SYMBOL_SECTION (sym) = cs->c_secnum;
1564
1565 if (ISFCN (cs->c_type)) {
1566
1567 /* At this point, we don't know the type of the function and assume it
1568 is int. This will be patched with the type from its stab entry later
1569 on in patch_block_stabs () */
1570
1571 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1572 SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (objfile, FT_INTEGER));
1573
1574 SYMBOL_CLASS (sym) = LOC_BLOCK;
1575 SYMBOL_DUP (sym, sym2);
1576
1577 if (cs->c_sclass == C_EXT)
1578 add_symbol_to_list (sym2, &global_symbols);
1579 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1580 add_symbol_to_list (sym2, &file_symbols);
1581 }
1582
1583 else {
1584
1585 /* in case we can't figure out the type, default is `int'. */
1586 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, FT_INTEGER);
1587
1588 switch (cs->c_sclass)
1589 {
1590 #if 0
1591 case C_FUN:
1592 if (fcn_cs_saved.c_sclass == C_EXT)
1593 add_stab_to_list (name, &global_stabs);
1594 else
1595 add_stab_to_list (name, &file_stabs);
1596 break;
1597 #endif
1598
1599 case C_DECL: /* a type decleration?? */
1600
1601 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1602 if (sym != NULL)
1603 SYMBOL_SECTION (sym) = cs->c_secnum;
1604 return sym;
1605
1606 case C_GSYM:
1607 add_stab_to_list (name, &global_stabs);
1608 break;
1609
1610 case C_PSYM:
1611 case C_RPSYM:
1612
1613 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1614 if (sym != NULL)
1615 {
1616 SYMBOL_SECTION (sym) = cs->c_secnum;
1617 }
1618 return sym;
1619
1620 case C_STSYM:
1621
1622 /* If we are going to use Sun dbx's define_symbol(), we need to
1623 massage our stab string a little. Change 'V' type to 'S' to be
1624 comparible with Sun. */
1625 /* FIXME: I believe this is to avoid a Sun-specific hack somewhere.
1626 Needs more investigation. */
1627
1628 if (*name == ':' || (pp = (char *) index (name, ':')) == NULL)
1629 return NULL;
1630
1631 ++pp;
1632 if (*pp == 'V') *pp = 'S';
1633 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1634 if (sym != NULL)
1635 {
1636 SYMBOL_VALUE (sym) += static_block_base;
1637 SYMBOL_SECTION (sym) = static_block_section;
1638 }
1639 return sym;
1640
1641 case C_LSYM:
1642 sym = define_symbol (cs->c_value, cs->c_name, 0, N_LSYM, objfile);
1643 if (sym != NULL)
1644 {
1645 SYMBOL_SECTION (sym) = cs->c_secnum;
1646 }
1647 return sym;
1648
1649 case C_AUTO:
1650 SYMBOL_CLASS (sym) = LOC_LOCAL;
1651 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1652 SYMBOL_SECTION (sym) = cs->c_secnum;
1653 SYMBOL_DUP (sym, sym2);
1654 add_symbol_to_list (sym2, &local_symbols);
1655 break;
1656
1657 case C_EXT:
1658 SYMBOL_CLASS (sym) = LOC_STATIC;
1659 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1660 SYMBOL_SECTION (sym) = cs->c_secnum;
1661 SYMBOL_DUP (sym, sym2);
1662 add_symbol_to_list (sym2, &global_symbols);
1663 break;
1664
1665 case C_STAT:
1666 SYMBOL_CLASS (sym) = LOC_STATIC;
1667 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1668 SYMBOL_SECTION (sym) = cs->c_secnum;
1669 SYMBOL_DUP (sym, sym2);
1670 add_symbol_to_list
1671 (sym2, within_function ? &local_symbols : &file_symbols);
1672 break;
1673
1674 case C_REG:
1675 printf ("ERROR! C_REG is not fully implemented!\n");
1676 SYMBOL_CLASS (sym) = LOC_REGISTER;
1677 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1678 SYMBOL_SECTION (sym) = cs->c_secnum;
1679 SYMBOL_DUP (sym, sym2);
1680 add_symbol_to_list (sym2, &local_symbols);
1681 break;
1682
1683 case C_RSYM:
1684 pp = (char*) strchr (name, ':');
1685 if (pp) {
1686 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1687 if (sym != NULL)
1688 SYMBOL_SECTION (sym) = cs->c_secnum;
1689 return sym;
1690 }
1691 else {
1692 complain (&rsym_complaint, name);
1693 return NULL;
1694 }
1695
1696 default :
1697 complain (&storclass_complaint, cs->c_sclass);
1698 return NULL;
1699 }
1700 }
1701 return sym2;
1702 }
1703
1704 /* Set *SYMBOL to symbol number symno in symtbl. */
1705 static void
1706 read_symbol (symbol, symno)
1707 struct internal_syment *symbol;
1708 int symno;
1709 {
1710 if (symno < 0 || symno >= symtbl_num_syms)
1711 {
1712 static struct complaint msg =
1713 {"Invalid symbol offset", 0, 0};
1714 complain (&msg);
1715 symbol->n_value = 0;
1716 symbol->n_scnum = -1;
1717 return;
1718 }
1719 bfd_coff_swap_sym_in (symfile_bfd, symtbl + (symno*local_symesz), symbol);
1720 }
1721
1722 /* Get value corresponding to symbol number symno in symtbl. */
1723
1724 static int
1725 read_symbol_nvalue (symno)
1726 int symno;
1727 {
1728 struct internal_syment symbol[1];
1729
1730 read_symbol (symbol, symno);
1731 return symbol->n_value;
1732 }
1733
1734
1735 /* Find the address of the function corresponding to symno, where
1736 symno is the symbol pointed to by the linetable. */
1737
1738 static int
1739 read_symbol_lineno (symno)
1740 int symno;
1741 {
1742 struct internal_syment symbol[1];
1743 union internal_auxent main_aux[1];
1744
1745 /* Note that just searching for a short distance (e.g. 50 symbols)
1746 is not enough, at least in the following case.
1747
1748 .extern foo
1749 [many .stabx entries]
1750 [a few functions, referring to foo]
1751 .globl foo
1752 .bf
1753
1754 What happens here is that the assembler moves the .stabx entries
1755 to right before the ".bf" for foo, but the symbol for "foo" is before
1756 all the stabx entries. See PR gdb/2222. */
1757 while (symno < symtbl_num_syms) {
1758 bfd_coff_swap_sym_in (symfile_bfd,
1759 symtbl + (symno*local_symesz), symbol);
1760 if (symbol->n_sclass == C_FCN && STREQ (symbol->n_name, ".bf"))
1761 goto gotit;
1762 symno += symbol->n_numaux+1;
1763 }
1764
1765 complain (&bf_notfound_complaint);
1766 return 0;
1767
1768 gotit:
1769 /* take aux entry and return its lineno */
1770 symno++;
1771 bfd_coff_swap_aux_in (symfile_bfd, symtbl+(symno*local_symesz),
1772 symbol->n_type, symbol->n_sclass, main_aux);
1773
1774 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1775 }
1776
1777 /* Support for line number handling */
1778
1779 /* This function is called for every section; it finds the outer limits
1780 * of the line table (minimum and maximum file offset) so that the
1781 * mainline code can read the whole thing for efficiency.
1782 */
1783 static void
1784 find_linenos(abfd, asect, vpinfo)
1785 bfd *abfd;
1786 sec_ptr asect;
1787 PTR vpinfo;
1788 {
1789 struct coff_symfile_info *info;
1790 int size, count;
1791 file_ptr offset, maxoff;
1792
1793 count = asect->lineno_count;
1794
1795 if (!STREQ (asect->name, ".text") || count == 0)
1796 return;
1797
1798 size = count * coff_data (symfile_bfd)->local_linesz;
1799 info = (struct coff_symfile_info *)vpinfo;
1800 offset = asect->line_filepos;
1801 maxoff = offset + size;
1802
1803 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1804 info->min_lineno_offset = offset;
1805
1806 if (maxoff > info->max_lineno_offset)
1807 info->max_lineno_offset = maxoff;
1808 }
1809
1810
1811 /* Read in all the line numbers for fast lookups later. Leave them in
1812 external (unswapped) format in memory; we'll swap them as we enter
1813 them into GDB's data structures. */
1814
1815 static int
1816 init_lineno (abfd, offset, size)
1817 bfd *abfd;
1818 file_ptr offset;
1819 int size;
1820 {
1821 int val;
1822
1823 free_linetab ();
1824
1825 if (bfd_seek(abfd, offset, L_SET) < 0)
1826 return -1;
1827
1828 linetab = (char *) xmalloc(size);
1829
1830 val = bfd_read(linetab, 1, size, abfd);
1831 if (val != size)
1832 return -1;
1833
1834 linetab_offset = offset;
1835 linetab_size = size;
1836 return 0;
1837 }
1838
1839 static void
1840 free_linetab ()
1841 {
1842 if (linetab)
1843 free (linetab);
1844 linetab = NULL;
1845 }
1846 \f
1847 /* dbx allows the text of a symbol name to be continued into the
1848 next symbol name! When such a continuation is encountered
1849 (a \ at the end of the text of a name)
1850 call this function to get the continuation. */
1851 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1852 for xcoff. */
1853
1854 #undef next_symbol_text
1855 #define next_symbol_text() \
1856 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1857
1858
1859 static void
1860 xcoff_new_init (objfile)
1861 struct objfile *objfile;
1862 {
1863 }
1864
1865
1866 /* xcoff_symfile_init()
1867 is the xcoff-specific initialization routine for reading symbols.
1868 It is passed an objfile which contains, among other things,
1869 the BFD for the file whose symbols are being read, and a slot for
1870 a pointer to "private data" which we fill with cookies and other
1871 treats for xcoff_symfile_read().
1872
1873 We will only be called if this is an XCOFF or XCOFF-like file.
1874 BFD handles figuring out the format of the file, and code in symfile.c
1875 uses BFD's determination to vector to us.
1876
1877 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
1878
1879 static void
1880 xcoff_symfile_init (objfile)
1881 struct objfile *objfile;
1882 {
1883 bfd *abfd = objfile->obfd;
1884
1885 /* Allocate struct to keep track of the symfile */
1886 objfile -> sym_private = xmmalloc (objfile -> md,
1887 sizeof (struct coff_symfile_info));
1888 init_entry_point_info (objfile);
1889 }
1890
1891 /* Perform any local cleanups required when we are done with a particular
1892 objfile. I.E, we are in the process of discarding all symbol information
1893 for an objfile, freeing up all memory held for it, and unlinking the
1894 objfile struct from the global list of known objfiles. */
1895
1896 static void
1897 xcoff_symfile_finish (objfile)
1898 struct objfile *objfile;
1899 {
1900 if (objfile -> sym_private != NULL)
1901 {
1902 mfree (objfile -> md, objfile -> sym_private);
1903 }
1904
1905 /* Start with a fresh include table for the next objfile. */
1906
1907 if (inclTable)
1908 {
1909 free (inclTable);
1910 inclTable = NULL;
1911 }
1912 inclIndx = inclLength = inclDepth = 0;
1913 }
1914
1915
1916 static int
1917 init_stringtab(abfd, offset, objfile)
1918 bfd *abfd;
1919 file_ptr offset;
1920 struct objfile *objfile;
1921 {
1922 long length;
1923 int val;
1924 unsigned char lengthbuf[4];
1925
1926 if (bfd_seek(abfd, offset, L_SET) < 0)
1927 return -1;
1928
1929 val = bfd_read((char *)lengthbuf, 1, sizeof lengthbuf, abfd);
1930 length = bfd_h_get_32(abfd, lengthbuf);
1931
1932 /* If no string table is needed, then the file may end immediately
1933 after the symbols. Just return with `strtbl' set to null. */
1934
1935 if (val != sizeof length || length < sizeof length)
1936 return 0;
1937
1938 /* Allocate string table from symbol_obstack. We will need this table
1939 as long as we have its symbol table around. */
1940
1941 strtbl = (char*) obstack_alloc (&objfile->symbol_obstack, length);
1942 if (strtbl == NULL)
1943 return -1;
1944
1945 memcpy(strtbl, &length, sizeof length);
1946 if (length == sizeof length)
1947 return 0;
1948
1949 val = bfd_read(strtbl + sizeof length, 1, length - sizeof length, abfd);
1950
1951 if (val != length - sizeof length || strtbl[length - 1] != '\0')
1952 return -1;
1953
1954 return 0;
1955 }
1956
1957 static int
1958 init_debugsection(abfd)
1959 bfd *abfd;
1960 {
1961 register sec_ptr secp;
1962 bfd_size_type length;
1963
1964 if (debugsec) {
1965 free(debugsec);
1966 debugsec = NULL;
1967 }
1968
1969 secp = bfd_get_section_by_name(abfd, ".debug");
1970 if (!secp)
1971 return 0;
1972
1973 if (!(length = bfd_section_size(abfd, secp)))
1974 return 0;
1975
1976 debugsec = (char *) xmalloc ((unsigned)length);
1977 if (debugsec == NULL)
1978 return -1;
1979
1980 if (!bfd_get_section_contents(abfd, secp, debugsec, (file_ptr) 0, length)) {
1981 printf ("Can't read .debug section from symbol file\n");
1982 return -1;
1983 }
1984 return 0;
1985 }
1986
1987 static void
1988 free_debugsection()
1989 {
1990 if (debugsec)
1991 free(debugsec);
1992 debugsec = NULL;
1993 }
1994
1995
1996 /* xcoff version of symbol file read. */
1997
1998 static void
1999 xcoff_symfile_read (objfile, section_offset, mainline)
2000 struct objfile *objfile;
2001 struct section_offset *section_offset;
2002 int mainline;
2003 {
2004 int num_symbols; /* # of symbols */
2005 file_ptr symtab_offset; /* symbol table and */
2006 file_ptr stringtab_offset; /* string table file offsets */
2007 int val;
2008 bfd *abfd;
2009 struct coff_symfile_info *info;
2010 char *name;
2011 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2012
2013 info = (struct coff_symfile_info *) objfile -> sym_private;
2014 symfile_bfd = abfd = objfile->obfd;
2015 name = objfile->name;
2016
2017 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2018 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2019 stringtab_offset = symtab_offset +
2020 num_symbols * coff_data(abfd)->local_symesz;
2021
2022 info->min_lineno_offset = 0;
2023 info->max_lineno_offset = 0;
2024 bfd_map_over_sections (abfd, find_linenos, info);
2025
2026 /* FIXME! This stuff should move into symfile_init */
2027 if (info->min_lineno_offset != 0
2028 && info->max_lineno_offset > info->min_lineno_offset) {
2029
2030 /* only read in the line # table if one exists */
2031 make_cleanup (free_linetab, 0);
2032 val = init_lineno(abfd, info->min_lineno_offset,
2033 (int) (info->max_lineno_offset - info->min_lineno_offset));
2034
2035 if (val < 0)
2036 error("\"%s\": error reading line numbers\n", name);
2037 }
2038
2039 if (num_symbols > 0)
2040 {
2041 val = init_stringtab(abfd, stringtab_offset, objfile);
2042 if (val < 0) {
2043 error ("\"%s\": can't get string table", name);
2044 }
2045
2046 if (init_debugsection(abfd) < 0) {
2047 error ("Error reading .debug section of `%s'\n", name);
2048 }
2049 }
2050
2051 /* Position to read the symbol table. Do not read it all at once. */
2052 val = bfd_seek(abfd, symtab_offset, L_SET);
2053 if (val < 0)
2054 perror_with_name(name);
2055
2056 if (bfd_tell(abfd) != symtab_offset)
2057 fatal("bfd? BFD!");
2058
2059 init_minimal_symbol_collection ();
2060 make_cleanup (discard_minimal_symbols, 0);
2061
2062 #ifndef FAKING_RS6000
2063 /* Initialize load info structure. */
2064 if (mainline)
2065 xcoff_init_loadinfo ();
2066 #endif
2067
2068 /* Now that the executable file is positioned at symbol table,
2069 process it and define symbols accordingly. */
2070
2071 read_xcoff_symtab(objfile, num_symbols);
2072
2073 /* Free debug section. */
2074 free_debugsection ();
2075
2076 /* Sort symbols alphabetically within each block. */
2077 sort_all_symtab_syms ();
2078
2079 /* Install any minimal symbols that have been collected as the current
2080 minimal symbols for this objfile. */
2081
2082 install_minimal_symbols (objfile);
2083
2084 do_cleanups (back_to);
2085 }
2086
2087 /* XCOFF-specific parsing routine for section offsets. */
2088
2089 static int largest_section;
2090
2091 static void
2092 note_one_section (abfd, asect, ptr)
2093 bfd *abfd;
2094 asection *asect;
2095 PTR ptr;
2096 {
2097 if (asect->target_index > largest_section)
2098 largest_section = asect->target_index;
2099 }
2100
2101 static
2102 struct section_offsets *
2103 xcoff_symfile_offsets (objfile, addr)
2104 struct objfile *objfile;
2105 CORE_ADDR addr;
2106 {
2107 struct section_offsets *section_offsets;
2108 int i;
2109
2110 largest_section = 0;
2111 bfd_map_over_sections (objfile->obfd, note_one_section, NULL);
2112 objfile->num_sections = largest_section + 1;
2113 section_offsets = (struct section_offsets *)
2114 obstack_alloc
2115 (&objfile -> psymbol_obstack,
2116 sizeof (struct section_offsets)
2117 + sizeof (section_offsets->offsets) * (objfile->num_sections));
2118
2119 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2120 of the .text section. This strikes me as wrong--whether the
2121 offset to be applied to symbol reading is relative to the start
2122 address of the section depends on the symbol format. In any
2123 event, this whole "addr" concept is pretty broken (it doesn't
2124 handle any section but .text sensibly), so just ignore the addr
2125 parameter and use 0. That matches the fact that xcoff_symfile_read
2126 ignores the section_offsets). */
2127 for (i = 0; i < objfile->num_sections; i++)
2128 ANOFFSET (section_offsets, i) = 0;
2129
2130 return section_offsets;
2131 }
2132 /* Register our ability to parse symbols for xcoff BFD files. */
2133
2134 static struct sym_fns xcoff_sym_fns =
2135 {
2136 "aixcoff-rs6000", /* sym_name: name or name prefix of BFD target type */
2137 15, /* sym_namelen: number of significant sym_name chars */
2138 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2139 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2140 xcoff_symfile_read, /* sym_read: read a symbol file into symtab */
2141 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
2142 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
2143 NULL /* next: pointer to next struct sym_fns */
2144 };
2145
2146 void
2147 _initialize_xcoffread ()
2148 {
2149 add_symtab_fns(&xcoff_sym_fns);
2150
2151 /* Initialize symbol template later used for arguments. */
2152 SYMBOL_NAME (&parmsym) = "";
2153 SYMBOL_INIT_LANGUAGE_SPECIFIC (&parmsym, language_c);
2154 SYMBOL_NAMESPACE (&parmsym) = VAR_NAMESPACE;
2155 SYMBOL_CLASS (&parmsym) = LOC_ARG;
2156 /* Its other fields are zero, or are filled in later. */
2157 }