1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
3 Free Software Foundation, Inc.
4 Derived from coffread.c, dbxread.c, and a lot of hacking.
5 Contributed by IBM Corporation.
7 This file is part of GDB.
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.
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.
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. */
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. */
32 #include <sys/types.h>
38 #include <sys/param.h>
43 #include <sys/debug.h>
45 #include "coff/internal.h"
46 #include "libcoff.h" /* FIXME, internal data from BFD */
47 #include "coff/rs6000.h"
54 #include "stabsread.h"
55 #include "complaints.h"
57 #include "gdb-stabs.h"
59 /* For interface with stabsread.c. */
60 #include "aout/stab_gnu.h"
62 /* For interface with partial-stab.h. */
63 #define N_UNDF 0 /* Undefined symbol */
66 #define N_TEXT 4 /* Text sym -- defined at offset in text seg */
67 #define N_DATA 6 /* Data sym -- defined at offset in data seg */
68 #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
69 #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
70 #define N_FN 0x1f /* File name of .o file */
71 #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
72 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
73 N_DATA, or N_BSS. When the low-order bit of other types is set,
74 (e.g. N_WARNING versus N_FN), they are two different types. */
75 #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
78 /* The following symbols refer to set elements.
79 All the N_SET[ATDB] symbols with the same name form one set.
80 Space is allocated for the set in the text section, and each set
81 elements value is stored into one word of the space.
82 The first word of the space is the length of the set (number of elements).
84 The address of the set is made into an N_SETV symbol
85 whose name is the same as the name of the set.
86 This symbol acts like a N_DATA global symbol
87 in that it can satisfy undefined external references. */
89 /* These appear as input to LD, in a .o file. */
90 #define N_SETA 0x14 /* Absolute set element symbol */
91 #define N_SETT 0x16 /* Text set element symbol */
92 #define N_SETD 0x18 /* Data set element symbol */
93 #define N_SETB 0x1A /* Bss set element symbol */
95 /* This is output from LD. */
96 #define N_SETV 0x1C /* Pointer to set vector in data area. */
98 /* We put a pointer to this structure in the read_symtab_private field
103 /* First symbol number for this file. */
107 /* Number of symbols in the section of the symbol table devoted to
108 this file's symbols (actually, the section bracketed may contain
109 more than just this file's symbols). If numsyms is 0, the only
110 reason for this thing's existence is the dependency list. Nothing
111 else will happen when it is read in. */
115 /* Position of the start of the line number information for this psymtab. */
116 unsigned int lineno_off
;
119 /* Remember what we deduced to be the source language of this psymtab. */
121 static enum language psymtab_language
= language_unknown
;
124 /* Simplified internal version of coff symbol table information */
128 int c_symnum
; /* symbol number of this entry */
129 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
131 unsigned char c_sclass
;
136 /* The COFF line table, in raw form. */
137 static char *linetab
= NULL
; /* Its actual contents */
138 static long linetab_offset
; /* Its offset in the file */
139 static unsigned long linetab_size
; /* Its size */
141 /* last function's saved coff symbol `cs' */
143 static struct coff_symbol fcn_cs_saved
;
145 static bfd
*symfile_bfd
;
147 /* Core address of start and end of text of current source file.
148 This is calculated from the first function seen after a C_FILE
152 static CORE_ADDR cur_src_end_addr
;
154 /* Core address of the end of the first object file. */
156 static CORE_ADDR first_object_file_end
;
158 /* initial symbol-table-debug-string vector length */
160 #define INITIAL_STABVECTOR_LENGTH 40
162 /* Nonzero if within a function (so symbols should be local,
163 if nothing says specifically). */
167 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
168 there is any reason not to just use a #define, but might as well
169 ask BFD for the size and store it here, I guess. */
171 static unsigned local_symesz
;
173 struct coff_symfile_info
{
174 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
175 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
177 /* Pointer to the string table. */
180 /* Pointer to debug section. */
183 /* Pointer to the a.out symbol table. */
186 /* Number of symbols in symtbl. */
190 static struct complaint rsym_complaint
=
191 {"Non-stab C_RSYM `%s' needs special handling", 0, 0};
193 static struct complaint storclass_complaint
=
194 {"Unexpected storage class: %d", 0, 0};
196 static struct complaint bf_notfound_complaint
=
197 {"line numbers off, `.bf' symbol not found", 0, 0};
199 extern struct complaint ef_complaint
;
200 extern struct complaint eb_complaint
;
203 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned,
204 CORE_ADDR
, CORE_ADDR
, unsigned *));
207 init_stringtab
PARAMS ((bfd
*, file_ptr
, struct objfile
*));
210 xcoff_symfile_init
PARAMS ((struct objfile
*));
213 xcoff_new_init
PARAMS ((struct objfile
*));
216 xcoff_symfile_finish
PARAMS ((struct objfile
*));
218 static struct section_offsets
*
219 xcoff_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
222 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
225 coff_getfilename
PARAMS ((union internal_auxent
*, struct objfile
*));
228 read_symbol
PARAMS ((struct internal_syment
*, int));
231 read_symbol_lineno
PARAMS ((int));
234 read_symbol_nvalue
PARAMS ((int));
236 static struct symbol
*
237 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
240 read_xcoff_symtab
PARAMS ((struct partial_symtab
*));
243 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
246 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
248 static int secnum_to_section
PARAMS ((int, struct objfile
*));
250 struct find_targ_sec_arg
{
255 static void find_targ_sec
PARAMS ((bfd
*, asection
*, void *));
257 static void find_targ_sec (abfd
, sect
, obj
)
262 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*)obj
;
263 if (sect
->target_index
== args
->targ_index
)
265 /* This is the section. Figure out what SECT_OFF_* code it is. */
266 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
267 *args
->resultp
= SECT_OFF_TEXT
;
268 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
269 *args
->resultp
= SECT_OFF_DATA
;
271 *args
->resultp
= SECT_OFF_BSS
;
275 /* Return the section number (SECT_OFF_*) that CS points to. */
277 secnum_to_section (secnum
, objfile
)
279 struct objfile
*objfile
;
281 int off
= SECT_OFF_TEXT
;
282 struct find_targ_sec_arg args
;
283 args
.targ_index
= secnum
;
285 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
289 /* add a given stab string into given stab vector. */
292 add_stab_to_list (stabname
, stabvector
)
294 struct pending_stabs
**stabvector
;
296 if ( *stabvector
== NULL
) {
297 *stabvector
= (struct pending_stabs
*)
298 xmalloc (sizeof (struct pending_stabs
) +
299 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
300 (*stabvector
)->count
= 0;
301 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
303 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
304 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
305 *stabvector
= (struct pending_stabs
*)
306 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
307 (*stabvector
)->length
* sizeof (char*));
309 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
312 /* Linenos are processed on a file-by-file basis.
316 1) xlc (IBM's native c compiler) postpones static function code
317 emission to the end of a compilation unit. This way it can
318 determine if those functions (statics) are needed or not, and
319 can do some garbage collection (I think). This makes line
320 numbers and corresponding addresses unordered, and we end up
321 with a line table like:
338 and that breaks gdb's binary search on line numbers, if the
339 above table is not sorted on line numbers. And that sort
340 should be on function based, since gcc can emit line numbers
343 10 0x100 - for the init/test part of a for stmt.
346 10 0x400 - for the increment part of a for stmt.
348 arrange_linetable() will do this sorting.
350 2) aix symbol table might look like:
352 c_file // beginning of a new file
353 .bi // beginning of include file
354 .ei // end of include file
358 basically, .bi/.ei pairs do not necessarily encapsulate
359 their scope. They need to be recorded, and processed later
360 on when we come the end of the compilation unit.
361 Include table (inclTable) and process_linenos() handle
364 /* compare line table entry addresses. */
367 compare_lte (lte1
, lte2
)
368 struct linetable_entry
*lte1
, *lte2
;
370 return lte1
->pc
- lte2
->pc
;
373 /* Give a line table with function entries are marked, arrange its functions
374 in assending order and strip off function entry markers and return it in
375 a newly created table. If the old one is good enough, return the old one. */
376 /* FIXME: I think all this stuff can be replaced by just passing
377 sort_linevec = 1 to end_symtab. */
379 static struct linetable
*
380 arrange_linetable (oldLineTb
)
381 struct linetable
*oldLineTb
; /* old linetable */
384 newline
, /* new line count */
385 function_count
; /* # of functions */
387 struct linetable_entry
*fentry
; /* function entry vector */
388 int fentry_size
; /* # of function entries */
389 struct linetable
*newLineTb
; /* new line table */
391 #define NUM_OF_FUNCTIONS 20
393 fentry_size
= NUM_OF_FUNCTIONS
;
394 fentry
= (struct linetable_entry
*)
395 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
397 for (function_count
=0, ii
=0; ii
<oldLineTb
->nitems
; ++ii
) {
399 if (oldLineTb
->item
[ii
].line
== 0) { /* function entry found. */
401 if (function_count
>= fentry_size
) { /* make sure you have room. */
403 fentry
= (struct linetable_entry
*)
404 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
406 fentry
[function_count
].line
= ii
;
407 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
412 if (function_count
== 0) {
416 else if (function_count
> 1)
417 qsort (fentry
, function_count
, sizeof(struct linetable_entry
), compare_lte
);
419 /* allocate a new line table. */
420 newLineTb
= (struct linetable
*)
422 (sizeof (struct linetable
) +
423 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
425 /* if line table does not start with a function beginning, copy up until
429 if (oldLineTb
->item
[0].line
!= 0)
431 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
432 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
434 /* Now copy function lines one by one. */
436 for (ii
=0; ii
< function_count
; ++ii
) {
437 for (jj
= fentry
[ii
].line
+ 1;
438 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
440 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
443 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
447 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
448 following `IncludeChain'. At the end of each symtab (end_symtab),
449 we will determine if we should create additional symtab's to
450 represent if (the include files. */
453 typedef struct _inclTable
{
454 char *name
; /* include filename */
456 /* Offsets to the line table. end points to the last entry which is
457 part of this include file. */
460 struct subfile
*subfile
;
461 unsigned funStartLine
; /* start line # of its function */
464 #define INITIAL_INCLUDE_TABLE_LENGTH 20
465 static InclTable
*inclTable
; /* global include table */
466 static int inclIndx
; /* last entry to table */
467 static int inclLength
; /* table length */
468 static int inclDepth
; /* nested include depth */
470 static void allocate_include_entry
PARAMS ((void));
473 record_include_begin (cs
)
474 struct coff_symbol
*cs
;
478 /* In xcoff, we assume include files cannot be nested (not in .c files
479 of course, but in corresponding .s files.). */
481 /* This can happen with old versions of GCC.
482 GCC 2.3.3-930426 does not exhibit this on a test case which
483 a user said produced the message for him. */
484 static struct complaint msg
= {"Nested C_BINCL symbols", 0, 0};
489 allocate_include_entry ();
491 inclTable
[inclIndx
].name
= cs
->c_name
;
492 inclTable
[inclIndx
].begin
= cs
->c_value
;
496 record_include_end (cs
)
497 struct coff_symbol
*cs
;
503 static struct complaint msg
= {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
507 allocate_include_entry ();
509 pTbl
= &inclTable
[inclIndx
];
510 pTbl
->end
= cs
->c_value
;
517 allocate_include_entry ()
519 if (inclTable
== NULL
)
521 inclTable
= (InclTable
*)
522 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
524 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
525 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
528 else if (inclIndx
>= inclLength
)
530 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
531 inclTable
= (InclTable
*)
532 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
533 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
534 '\0', sizeof (InclTable
)*INITIAL_INCLUDE_TABLE_LENGTH
);
538 /* Global variable to pass the psymtab down to all the routines involved
539 in psymtab to symtab processing. */
540 static struct partial_symtab
*this_symtab_psymtab
;
542 /* given the start and end addresses of a compilation unit (or a csect,
543 at times) process its lines and create appropriate line vectors. */
546 process_linenos (start
, end
)
547 CORE_ADDR start
, end
;
551 file_ptr max_offset
=
552 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
555 /* subfile structure for the main compilation unit. */
556 struct subfile main_subfile
;
558 /* In the main source file, any time we see a function entry, we
559 reset this variable to function's absolute starting line number.
560 All the following line numbers in the function are relative to
561 this, and we record absolute line numbers in record_line(). */
563 int main_source_baseline
= 0;
569 ((struct symloc
*)this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
571 goto return_after_cleanup
;
573 memset (&main_subfile
, '\0', sizeof (main_subfile
));
576 /* All source lines were in the main source file. None in include files. */
578 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
579 &main_source_baseline
);
583 /* There was source with line numbers in include files. */
584 main_source_baseline
= 0;
585 for (ii
=0; ii
< inclIndx
; ++ii
)
587 struct subfile
*tmpSubfile
;
589 /* If there is main file source before include file, enter it. */
590 if (offset
< inclTable
[ii
].begin
)
593 (&main_subfile
, offset
, inclTable
[ii
].begin
- LINESZ
,
594 start
, 0, &main_source_baseline
);
597 /* Have a new subfile for the include file. */
599 tmpSubfile
= inclTable
[ii
].subfile
=
600 (struct subfile
*) xmalloc (sizeof (struct subfile
));
602 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
603 firstLine
= &(inclTable
[ii
].funStartLine
);
605 /* Enter include file's lines now. */
606 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
607 inclTable
[ii
].end
, start
, 0, firstLine
);
609 offset
= inclTable
[ii
].end
+ LINESZ
;
612 /* All the include files' line have been processed at this point. Now,
613 enter remaining lines of the main file, if any left. */
614 if (offset
< max_offset
+ 1 - LINESZ
)
616 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
617 &main_source_baseline
);
621 /* Process main file's line numbers. */
622 if (main_subfile
.line_vector
)
624 struct linetable
*lineTb
, *lv
;
626 lv
= main_subfile
.line_vector
;
628 /* Line numbers are not necessarily ordered. xlc compilation will
629 put static function to the end. */
631 lineTb
= arrange_linetable (lv
);
634 current_subfile
->line_vector
= (struct linetable
*)
635 xrealloc (lv
, (sizeof (struct linetable
)
636 + lv
->nitems
* sizeof (struct linetable_entry
)));
641 current_subfile
->line_vector
= lineTb
;
644 current_subfile
->line_vector_length
=
645 current_subfile
->line_vector
->nitems
;
648 /* Now, process included files' line numbers. */
650 for (ii
=0; ii
< inclIndx
; ++ii
)
652 if ((inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
654 struct linetable
*lineTb
, *lv
;
656 lv
= (inclTable
[ii
].subfile
)->line_vector
;
658 /* Line numbers are not necessarily ordered. xlc compilation will
659 put static function to the end. */
661 lineTb
= arrange_linetable (lv
);
665 /* For the same include file, we might want to have more than one
666 subfile. This happens if we have something like:
674 while foo.h including code in it. (stupid but possible)
675 Since start_subfile() looks at the name and uses an
676 existing one if finds, we need to provide a fake name and
680 start_subfile (inclTable
[ii
].name
, (char*)0);
683 /* Pick a fake name that will produce the same results as this
684 one when passed to deduce_language_from_filename. Kludge on
686 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
687 if (fakename
== NULL
)
689 start_subfile (fakename
, (char*)0);
690 free (current_subfile
->name
);
692 current_subfile
->name
= strdup (inclTable
[ii
].name
);
697 current_subfile
->line_vector
=
698 (struct linetable
*) xrealloc
699 (lv
, (sizeof (struct linetable
)
700 + lv
->nitems
* sizeof (struct linetable_entry
)));
706 current_subfile
->line_vector
= lineTb
;
709 current_subfile
->line_vector_length
=
710 current_subfile
->line_vector
->nitems
;
711 start_subfile (pop_subfile (), (char*)0);
715 return_after_cleanup
:
717 /* We don't want to keep alloc/free'ing the global include file table. */
720 /* Start with a fresh subfile structure for the next file. */
721 memset (&main_subfile
, '\0', sizeof (struct subfile
));
725 aix_process_linenos ()
727 /* process line numbers and enter them into line vector */
728 process_linenos (last_source_start_addr
, cur_src_end_addr
);
732 /* Enter a given range of lines into the line vector.
733 can be called in the following two ways:
734 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
735 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
737 endoffset points to the last line table entry that we should pay
741 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
,
743 struct subfile
*subfile
;
744 unsigned beginoffset
, endoffset
; /* offsets to line table */
745 CORE_ADDR startaddr
, endaddr
;
748 unsigned int curoffset
;
750 struct external_lineno ext_lnno
;
751 struct internal_lineno int_lnno
;
752 unsigned int limit_offset
;
755 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
757 curoffset
= beginoffset
;
759 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
764 if (endoffset
>= limit_offset
)
766 static struct complaint msg
=
767 {"Bad line table offset in C_EINCL directive", 0, 0};
771 limit_offset
= endoffset
;
775 abfd
= this_symtab_psymtab
->objfile
->obfd
;
777 while (curoffset
<= limit_offset
)
779 bfd_seek (abfd
, curoffset
, SEEK_SET
);
780 bfd_read (&ext_lnno
, sizeof (struct external_lineno
), 1, abfd
);
781 bfd_coff_swap_lineno_in (abfd
, &ext_lnno
, &int_lnno
);
783 /* Find the address this line represents. */
784 addr
= (int_lnno
.l_lnno
785 ? int_lnno
.l_addr
.l_paddr
786 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
787 addr
+= ANOFFSET (this_symtab_psymtab
->objfile
->section_offsets
,
790 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
793 if (int_lnno
.l_lnno
== 0)
795 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
796 record_line (subfile
, 0, addr
);
800 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
, addr
);
806 int fsize
; /* file size */
807 int fixedparms
; /* number of fixed parms */
808 int floatparms
; /* number of float parms */
809 unsigned int parminfo
; /* parameter info.
810 See /usr/include/sys/debug.h
811 tbtable_ext.parminfo */
812 int framesize
; /* function frame size */
815 static TracebackInfo
*retrieve_tracebackinfo
816 PARAMS ((bfd
*, struct coff_symbol
*));
818 /* Given a function symbol, return its traceback information. */
820 static TracebackInfo
*
821 retrieve_tracebackinfo (abfd
, cs
)
823 struct coff_symbol
*cs
;
825 #define TBTABLE_BUFSIZ 2000
827 static TracebackInfo tbInfo
;
830 static char buffer
[TBTABLE_BUFSIZ
];
833 int bytesread
=0; /* total # of bytes read so far */
834 int bufferbytes
; /* number of bytes in the buffer */
839 /* FIXME: Should be looking through all sections, based on the
840 address we are considering. Just using ".text" loses if more
841 than one section has code in it. */
842 textsec
= bfd_get_section_by_name (abfd
, ".text");
846 /* If there is only data, no text, that is OK. */
847 printf_unfiltered ("Unable to locate text section!\n");
852 functionstart
= cs
->c_value
- textsec
->vma
;
854 memset (&tbInfo
, '\0', sizeof (tbInfo
));
856 /* keep reading blocks of data from the text section, until finding a zero
857 word and a traceback table. */
859 /* Note: The logical thing way to write this code would be to assign
860 to bufferbytes within the while condition. But that triggers a
861 compiler (xlc in AIX 3.2) bug, so simplify it... */
863 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
) ?
864 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
));
866 && (bfd_get_section_contents
867 (abfd
, textsec
, buffer
,
868 (file_ptr
)(functionstart
+ bytesread
), bufferbytes
)))
870 bytesread
+= bufferbytes
;
871 pinsn
= (int*) buffer
;
873 /* If this is the first time we filled the buffer, retrieve function
876 if (bytesread
== bufferbytes
) {
878 /* skip over unrelated instructions */
880 if (*pinsn
== 0x7c0802a6) /* mflr r0 */
882 if ((*pinsn
& 0xfc00003e) == 0x7c000026) /* mfcr Rx */
884 if ((*pinsn
& 0xfc000000) == 0x48000000) /* bl foo, save fprs */
886 if ((*pinsn
& 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
890 int tmp
= (*pinsn
>> 16) & 0xffff;
892 if (tmp
== 0x9421) { /* stu r1, NUM(r1) */
893 tbInfo
.framesize
= 0x10000 - (*pinsn
& 0xffff);
896 else if ((*pinsn
== 0x93e1fffc) || /* st r31,-4(r1) */
897 (tmp
== 0x9001)) /* st r0, NUM(r1) */
899 /* else, could not find a frame size. */
903 } while (++pinsn
&& *pinsn
);
905 if (!tbInfo
.framesize
)
910 /* look for a zero word. */
912 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
915 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
920 /* function size is the amount of bytes we have skipped so far. */
921 tbInfo
.fsize
= bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
);
925 /* if we don't have the whole traceback table in the buffer, re-read
928 /* This is how much to read to get the traceback table.
929 8 bytes of the traceback table are always present, plus we
931 #define MIN_TBTABSIZ 12
933 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
935 /* In case if we are *very* close to the end of the text section
936 and cannot read properly from that point on, abort by returning
939 This could happen if the traceback table is only 8 bytes,
940 but we try to read 12 bytes of it.
941 Handle this case more graciously -- FIXME */
943 if (!bfd_get_section_contents (
944 abfd
, textsec
, buffer
,
945 (file_ptr
)(functionstart
+
946 bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
)),MIN_TBTABSIZ
))
947 { printf_unfiltered ("Abnormal return!..\n"); return NULL
; }
949 ptb
= (struct tbtable
*)buffer
;
952 ptb
= (struct tbtable
*)pinsn
;
954 tbInfo
.fixedparms
= ptb
->tb
.fixedparms
;
955 tbInfo
.floatparms
= ptb
->tb
.floatparms
;
956 tbInfo
.parminfo
= ptb
->tb_ext
.parminfo
;
960 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
) ?
961 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
));
966 /* Save the vital information for use when closing off the current file.
967 NAME is the file name the symbols came from, START_ADDR is the first
968 text address for the file, and SIZE is the number of bytes of text. */
970 #define complete_symtab(name, start_addr) { \
971 last_source_file = savestring (name, strlen (name)); \
972 last_source_start_addr = start_addr; \
976 /* Refill the symbol table input buffer
977 and set the variables that control fetching entries from it.
978 Reports an error if no data available.
979 This function can read past the end of the symbol table
980 (into the string table) but this does no harm. */
982 /* Reading symbol table has to be fast! Keep the followings as macros, rather
985 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
989 if (namestr[0] == '.') ++namestr; \
990 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
991 (char *)NULL, (SECTION), (OBJFILE)); \
992 misc_func_recorded = 1; \
996 /* A parameter template, used by ADD_PARM_TO_PENDING. It is initialized
997 in our initializer function at the bottom of the file, to avoid
998 dependencies on the exact "struct symbol" format. */
1000 static struct symbol parmsym
;
1002 /* Add a parameter to a given pending symbol list. */
1004 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
1006 PARM = (struct symbol *) \
1007 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1008 *(PARM) = parmsym; \
1009 SYMBOL_TYPE (PARM) = PTYPE; \
1010 SYMBOL_VALUE (PARM) = VALUE; \
1011 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
1015 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
1016 nested. At any given time, a symbol can only be in one static block.
1017 This is the base address of current static block, zero if non exists. */
1019 static int static_block_base
= 0;
1021 /* Section number for the current static block. */
1023 static int static_block_section
= -1;
1025 /* true if space for symbol name has been allocated. */
1027 static int symname_alloced
= 0;
1029 /* Next symbol to read. Pointer into raw seething symbol table. */
1031 static char *raw_symbol
;
1033 /* This is the function which stabsread.c calls to get symbol
1036 xcoff_next_symbol_text ()
1038 struct internal_syment symbol
;
1039 static struct complaint msg
=
1040 {"Unexpected symbol continuation", 0, 0};
1042 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1044 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
1045 if (symbol
.n_zeroes
)
1049 /* Return something which points to '\0' and hope the symbol reading
1050 code does something reasonable. */
1053 else if (symbol
.n_sclass
& 0x80)
1056 ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
1059 coff_data (objfile
->obfd
)->local_symesz
;
1066 /* Return something which points to '\0' and hope the symbol reading
1067 code does something reasonable. */
1073 /* Read symbols for a given partial symbol table. */
1076 read_xcoff_symtab (pst
)
1077 struct partial_symtab
*pst
;
1079 struct objfile
*objfile
= pst
->objfile
;
1080 bfd
*abfd
= objfile
->obfd
;
1081 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
1082 TracebackInfo
*ptb
; /* Pointer to traceback table */
1083 char *strtbl
= ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
;
1085 ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
;
1087 struct internal_syment symbol
[1];
1088 union internal_auxent main_aux
;
1089 struct coff_symbol cs
[1];
1090 CORE_ADDR file_start_addr
= 0;
1091 CORE_ADDR file_end_addr
= 0;
1093 int next_file_symnum
= -1;
1094 unsigned int max_symnum
;
1095 int just_started
= 1;
1101 struct coff_symbol fcn_stab_saved
;
1103 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1104 union internal_auxent fcn_aux_saved
;
1105 struct type
*fcn_type_saved
= NULL
;
1106 struct context_stack
*new;
1108 char *filestring
= " _start_ "; /* Name of the current file. */
1110 char *last_csect_name
; /* last seen csect's name and value */
1111 CORE_ADDR last_csect_val
;
1113 int misc_func_recorded
; /* true if any misc. function */
1115 this_symtab_psymtab
= pst
;
1117 /* Get the appropriate COFF "constants" related to the file we're
1119 local_symesz
= coff_data (abfd
)->local_symesz
;
1121 last_source_file
= NULL
;
1122 last_csect_name
= 0;
1124 misc_func_recorded
= 0;
1127 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
1128 symnum
= ((struct symloc
*)pst
->read_symtab_private
)->first_symnum
;
1130 symnum
+ ((struct symloc
*)pst
->read_symtab_private
)->numsyms
;
1131 first_object_file_end
= 0;
1134 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
1135 + symnum
* local_symesz
;
1137 while (symnum
< max_symnum
)
1140 QUIT
; /* make this command interruptable. */
1142 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1143 /* read one symbol into `cs' structure. After processing the
1144 whole symbol table, only string table will be kept in memory,
1145 symbol table and debug section of xcoff will be freed. Thus
1146 we can mark symbols with names in string table as
1151 /* Swap and align the symbol into a reasonable C structure. */
1152 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1154 cs
->c_symnum
= symnum
;
1155 cs
->c_naux
= symbol
->n_numaux
;
1156 if (symbol
->n_zeroes
)
1158 symname_alloced
= 0;
1159 /* We must use the original, unswapped, name here so the name field
1160 pointed to by cs->c_name will persist throughout xcoffread. If
1161 we use the new field, it gets overwritten for each symbol. */
1162 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
1163 /* If it's exactly E_SYMNMLEN characters long it isn't
1165 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1168 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
1169 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1170 p
[E_SYMNMLEN
] = '\0';
1172 symname_alloced
= 1;
1175 else if (symbol
->n_sclass
& 0x80)
1177 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1178 symname_alloced
= 0;
1182 /* in string table */
1183 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
1184 symname_alloced
= 1;
1186 cs
->c_value
= symbol
->n_value
;
1187 cs
->c_sclass
= symbol
->n_sclass
;
1188 cs
->c_secnum
= symbol
->n_scnum
;
1189 cs
->c_type
= (unsigned)symbol
->n_type
;
1191 raw_symbol
+= coff_data (abfd
)->local_symesz
;
1194 /* Save addr of first aux entry. */
1195 raw_auxptr
= raw_symbol
;
1197 /* Skip all the auxents associated with this symbol. */
1198 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1200 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1205 /* if symbol name starts with ".$" or "$", ignore it. */
1206 if (cs
->c_name
[0] == '$'
1207 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1210 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1212 if (last_source_file
)
1215 end_symtab (cur_src_end_addr
, 1, 0, objfile
, SECT_OFF_TEXT
);
1220 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
1221 cur_src_end_addr
= first_object_file_end
;
1222 /* done with all files, everything from here on is globals */
1225 /* if explicitly specified as a function, treat is as one. */
1226 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1228 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1229 0, cs
->c_naux
, &main_aux
);
1230 goto function_entry_point
;
1233 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1236 /* Dealing with a symbol with a csect entry. */
1238 #define CSECT(PP) ((PP)->x_csect)
1239 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1240 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1241 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1242 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1244 /* Convert the auxent to something we can access. */
1245 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1246 0, cs
->c_naux
, &main_aux
);
1248 switch (CSECT_SMTYP (&main_aux
))
1252 /* Ignore all external references. */
1256 /* A section description. */
1258 switch (CSECT_SCLAS (&main_aux
))
1264 /* A program csect is seen. We have to allocate one
1265 symbol table for each program csect. Normally gdb
1266 prefers one symtab for each source file. In case
1267 of AIX, one source file might include more than one
1268 [PR] csect, and they don't have to be adjacent in
1269 terms of the space they occupy in memory. Thus, one
1270 single source file might get fragmented in the
1271 memory and gdb's file start and end address
1272 approach does not work! GCC (and I think xlc) seem
1273 to put all the code in the unnamed program csect. */
1275 if (last_csect_name
)
1277 complete_symtab (filestring
, file_start_addr
);
1278 cur_src_end_addr
= file_end_addr
;
1279 end_symtab (file_end_addr
, 1, 0, objfile
,
1283 /* Give all csects for this source file the same
1285 start_symtab (filestring
, NULL
, (CORE_ADDR
)0);
1288 /* If this is the very first csect seen,
1289 basically `__start'. */
1292 first_object_file_end
1293 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1298 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1300 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1302 if (cs
->c_name
&& cs
->c_name
[0] == '.')
1304 last_csect_name
= cs
->c_name
;
1305 last_csect_val
= cs
->c_value
;
1306 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1309 misc_func_recorded
= 0;
1315 /* If the section is not a data description,
1316 ignore it. Note that uninitialized data will
1317 show up as XTY_CM/XMC_RW pair. */
1326 /* Ignore the symbol. */
1334 switch (CSECT_SCLAS (&main_aux
))
1337 /* a function entry point. */
1338 function_entry_point
:
1340 fcn_start_addr
= cs
->c_value
;
1342 /* save the function header info, which will be used
1343 when `.bf' is seen. */
1345 fcn_aux_saved
= main_aux
;
1349 /* If function has two auxent, then debugging information is
1350 already available for it. Process traceback table for
1351 functions with only one auxent. */
1353 if (cs
->c_naux
== 1)
1354 ptb
= retrieve_tracebackinfo (abfd
, cs
);
1356 else if (cs
->c_naux
!= 2)
1358 static struct complaint msg
=
1359 {"Expected one or two auxents for function", 0, 0};
1363 /* If there is traceback info, create and add parameters
1366 if (ptb
&& (ptb
->fixedparms
|| ptb
->floatparms
))
1369 int parmcnt
= ptb
->fixedparms
+ ptb
->floatparms
;
1370 char *parmcode
= (char*) &ptb
->parminfo
;
1372 /* The link area is 0x18 bytes. */
1373 int parmvalue
= ptb
->framesize
+ 0x18;
1374 unsigned int ii
, mask
;
1376 for (ii
=0, mask
= 0x80000000; ii
<parmcnt
; ++ii
)
1378 struct symbol
*parm
;
1380 if (ptb
->parminfo
& mask
)
1382 /* float or double */
1384 if (ptb
->parminfo
& mask
)
1388 (parm
, parmvalue
, builtin_type_double
,
1390 parmvalue
+= sizeof (double);
1396 (parm
, parmvalue
, builtin_type_float
,
1398 parmvalue
+= sizeof (float);
1403 static struct type
*intparm_type
;
1404 if (intparm_type
== NULL
)
1407 /* Create a type, which is a pointer
1408 type (a kludge to make it print
1409 in hex), but which has a name
1410 indicating we don't know the real
1416 TARGET_PTR_BIT
/ HOST_CHAR_BIT
,
1418 "<non-float parameter>",
1420 TYPE_TARGET_TYPE (intparm_type
) =
1427 parmvalue
+= sizeof (int);
1432 /* Fake this as a function. Needed in
1433 process_xcoff_symbol(). */
1437 (process_xcoff_symbol (cs
, objfile
), &local_symbols
,
1438 pending_blocks
, cs
->c_value
,
1439 cs
->c_value
+ ptb
->fsize
, objfile
);
1444 /* shared library function trampoline code entry point. */
1448 /* The symbols often have the same names as debug symbols for
1449 functions, and confuse lookup_symbol. */
1453 /* xlc puts each variable in a separate csect, so we get
1454 an XTY_SD for each variable. But gcc puts several
1455 variables in a csect, so that each variable only gets
1456 an XTY_LD. We still need to record them. This will
1457 typically be XMC_RW; I suspect XMC_RO and XMC_BS might
1467 switch (cs
->c_sclass
)
1472 /* c_value field contains symnum of next .file entry in table
1473 or symnum of first global after last .file. */
1475 next_file_symnum
= cs
->c_value
;
1477 /* Complete symbol table for last object file containing
1478 debugging information. */
1480 /* Whether or not there was a csect in the previous file, we
1481 have to call `end_stabs' and `start_stabs' to reset
1482 type_vector, line_vector, etc. structures. */
1484 complete_symtab (filestring
, file_start_addr
);
1485 cur_src_end_addr
= file_end_addr
;
1486 end_symtab (file_end_addr
, 1, 0, objfile
, SECT_OFF_TEXT
);
1489 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1490 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1491 standard COFF way and put it in the auxent. We use the auxent if
1492 the symbol is ".file" and an auxent exists, otherwise use the symbol
1493 itself. Simple enough. */
1494 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1496 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1497 0, cs
->c_naux
, &main_aux
);
1498 filestring
= coff_getfilename (&main_aux
, objfile
);
1501 filestring
= cs
->c_name
;
1504 start_symtab (filestring
, (char *)NULL
, (CORE_ADDR
)0);
1505 last_csect_name
= 0;
1507 /* reset file start and end addresses. A compilation unit with no text
1508 (only data) should have zero file boundaries. */
1509 file_start_addr
= file_end_addr
= 0;
1513 fcn_stab_saved
= *cs
;
1517 if (STREQ (cs
->c_name
, ".bf"))
1519 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1521 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1522 0, cs
->c_naux
, &main_aux
);
1524 within_function
= 1;
1526 new = push_context (0, fcn_start_addr
+ off
);
1528 new->name
= define_symbol
1529 (fcn_cs_saved
.c_value
+ off
,
1530 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1531 if (new->name
!= NULL
)
1532 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT
;
1534 else if (STREQ (cs
->c_name
, ".ef"))
1537 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1538 0, cs
->c_naux
, &main_aux
);
1540 /* The value of .ef is the address of epilogue code;
1541 not useful for gdb. */
1542 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1543 contains number of lines to '}' */
1545 new = pop_context ();
1546 /* Stack must be empty now. */
1547 if (context_stack_depth
> 0 || new == NULL
)
1549 complain (&ef_complaint
, cs
->c_symnum
);
1550 within_function
= 0;
1554 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1556 (fcn_cs_saved
.c_value
1557 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1558 + ANOFFSET (objfile
->section_offsets
,
1561 within_function
= 0;
1566 /* Begin static block. */
1568 struct internal_syment symbol
;
1570 read_symbol (&symbol
, cs
->c_value
);
1571 static_block_base
= symbol
.n_value
;
1572 static_block_section
=
1573 secnum_to_section (symbol
.n_scnum
, objfile
);
1578 /* End of static block. */
1579 static_block_base
= 0;
1580 static_block_section
= -1;
1591 static struct complaint msg
=
1592 {"Unrecognized storage class %d.", 0, 0};
1593 complain (&msg
, cs
->c_sclass
);
1606 /* beginning of include file */
1607 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1608 order. Thus, when wee see them, we might not know enough info
1609 to process them. Thus, we'll be saving them into a table
1610 (inclTable) and postpone their processing. */
1612 record_include_begin (cs
);
1616 /* End of include file. */
1617 /* See the comment after case C_BINCL. */
1618 record_include_end (cs
);
1622 if (STREQ (cs
->c_name
, ".bb"))
1625 new = push_context (depth
,
1627 + ANOFFSET (objfile
->section_offsets
,
1630 else if (STREQ (cs
->c_name
, ".eb"))
1632 new = pop_context ();
1633 if (depth
-- != new->depth
)
1635 complain (&eb_complaint
, symnum
);
1638 if (local_symbols
&& context_stack_depth
> 0)
1640 /* Make a block for the local symbols within. */
1641 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1644 + ANOFFSET (objfile
->section_offsets
,
1648 local_symbols
= new->locals
;
1653 process_xcoff_symbol (cs
, objfile
);
1658 if (last_source_file
)
1662 complete_symtab (filestring
, file_start_addr
);
1663 cur_src_end_addr
= file_end_addr
;
1664 s
= end_symtab (file_end_addr
, 1, 0, objfile
, SECT_OFF_TEXT
);
1665 /* When reading symbols for the last C_FILE of the objfile, try
1666 to make sure that we set pst->symtab to the symtab for the
1667 file, not to the _globals_ symtab. I'm not sure whether this
1668 actually works right or when/if it comes up. */
1669 if (pst
->symtab
== NULL
)
1675 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1676 (SYMBOL2) = (struct symbol *) \
1677 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1678 *(SYMBOL2) = *(SYMBOL1);
1681 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1682 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1685 static struct type
*func_symbol_type
;
1686 static struct type
*var_symbol_type
;
1688 /* process one xcoff symbol. */
1690 static struct symbol
*
1691 process_xcoff_symbol (cs
, objfile
)
1692 register struct coff_symbol
*cs
;
1693 struct objfile
*objfile
;
1695 struct symbol onesymbol
;
1696 register struct symbol
*sym
= &onesymbol
;
1697 struct symbol
*sym2
= NULL
;
1699 char *name
, *pp
, *qq
;
1700 int struct_and_type_combined
;
1706 if (cs
->c_secnum
< 0)
1708 /* The value is a register number, offset within a frame, etc.,
1709 and does not get relocated. */
1715 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1716 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1723 memset (sym
, '\0', sizeof (struct symbol
));
1725 /* default assumptions */
1726 SYMBOL_VALUE (sym
) = cs
->c_value
+ off
;
1727 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1728 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1730 if (ISFCN (cs
->c_type
))
1732 /* At this point, we don't know the type of the function. This
1733 will be patched with the type from its stab entry later on in
1734 patch_block_stabs (), unless the file was compiled without -g. */
1736 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1737 SYMBOL_TYPE (sym
) = func_symbol_type
;
1739 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1740 SYMBOL_DUP (sym
, sym2
);
1742 if (cs
->c_sclass
== C_EXT
)
1743 add_symbol_to_list (sym2
, &global_symbols
);
1744 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1745 add_symbol_to_list (sym2
, &file_symbols
);
1749 /* In case we can't figure out the type, provide default. */
1750 SYMBOL_TYPE (sym
) = var_symbol_type
;
1752 switch (cs
->c_sclass
)
1756 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1757 add_stab_to_list (name
, &global_stabs
);
1759 add_stab_to_list (name
, &file_stabs
);
1764 add_stab_to_list (name
, &global_stabs
);
1768 common_block_start (cs
->c_name
, objfile
);
1772 common_block_end (objfile
);
1776 complain (&storclass_complaint
, cs
->c_sclass
);
1787 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1790 SYMBOL_SECTION (sym
) = sec
;
1797 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1798 all statics and we need to distinguish file-scope versus
1799 function-scope using within_function. We do this by
1800 changing the string we pass to define_symbol to use 'S'
1801 where we need to, which is not necessarily super-clean,
1802 but seems workable enough. */
1804 if (*name
== ':' || (pp
= (char *) strchr(name
, ':')) == NULL
)
1808 if (*pp
== 'V' && !within_function
)
1810 sym
= define_symbol ((cs
->c_value
1811 + ANOFFSET (objfile
->section_offsets
,
1812 static_block_section
)),
1813 cs
->c_name
, 0, 0, objfile
);
1816 SYMBOL_VALUE (sym
) += static_block_base
;
1817 SYMBOL_SECTION (sym
) = static_block_section
;
1822 /* These appear to be vestigial remnants of coffread.c; I don't
1823 think any of them are used for xcoff. */
1826 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1827 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1828 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1829 SYMBOL_DUP (sym
, sym2
);
1830 add_symbol_to_list (sym2
, &local_symbols
);
1834 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1835 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1836 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1837 SYMBOL_DUP (sym
, sym2
);
1839 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1843 pp
= (char*) strchr (name
, ':');
1846 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1848 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1853 complain (&rsym_complaint
, name
);
1858 /* I think this one is used (dubious, I think, shouldn't
1859 it go into the msyms only?). */
1861 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1862 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1863 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1864 SYMBOL_DUP (sym
, sym2
);
1865 add_symbol_to_list (sym2
, &global_symbols
);
1873 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1874 only the last component of the name. Result is in static storage and
1875 is only good for temporary use. */
1878 coff_getfilename (aux_entry
, objfile
)
1879 union internal_auxent
*aux_entry
;
1880 struct objfile
*objfile
;
1882 static char buffer
[BUFSIZ
];
1883 register char *temp
;
1886 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1888 ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
1889 + aux_entry
->x_file
.x_n
.x_offset
);
1892 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1893 buffer
[FILNMLEN
] = '\0';
1897 /* FIXME: We should not be throwing away the information about what
1898 directory. It should go into dirname of the symtab, or some such
1900 if ((temp
= strrchr (result
, '/')) != NULL
)
1905 /* Set *SYMBOL to symbol number symno in symtbl. */
1907 read_symbol (symbol
, symno
)
1908 struct internal_syment
*symbol
;
1912 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1915 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1917 if (symno
< 0 || symno
>= nsyms
)
1919 static struct complaint msg
=
1920 {"Invalid symbol offset", 0, 0};
1922 symbol
->n_value
= 0;
1923 symbol
->n_scnum
= -1;
1926 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1927 stbl
+ (symno
*local_symesz
),
1931 /* Get value corresponding to symbol number symno in symtbl. */
1934 read_symbol_nvalue (symno
)
1937 struct internal_syment symbol
[1];
1939 read_symbol (symbol
, symno
);
1940 return symbol
->n_value
;
1944 /* Find the address of the function corresponding to symno, where
1945 symno is the symbol pointed to by the linetable. */
1948 read_symbol_lineno (symno
)
1952 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1955 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1957 struct internal_syment symbol
[1];
1958 union internal_auxent main_aux
[1];
1962 complain (&bf_notfound_complaint
);
1966 /* Note that just searching for a short distance (e.g. 50 symbols)
1967 is not enough, at least in the following case.
1970 [many .stabx entries]
1971 [a few functions, referring to foo]
1975 What happens here is that the assembler moves the .stabx entries
1976 to right before the ".bf" for foo, but the symbol for "foo" is before
1977 all the stabx entries. See PR gdb/2222. */
1979 /* Maintaining a table of .bf entries might be preferable to this search.
1980 If I understand things correctly it would need to be done only for
1981 the duration of a single psymtab to symtab conversion. */
1982 while (symno
< nsyms
)
1984 bfd_coff_swap_sym_in (symfile_bfd
,
1985 stbl
+ (symno
* local_symesz
), symbol
);
1986 if (symbol
->n_sclass
== C_FCN
&& STREQ (symbol
->n_name
, ".bf"))
1988 symno
+= symbol
->n_numaux
+ 1;
1991 complain (&bf_notfound_complaint
);
1995 /* take aux entry and return its lineno */
1997 bfd_coff_swap_aux_in (this_symtab_psymtab
->objfile
->obfd
,
1998 stbl
+ symno
* local_symesz
,
1999 symbol
->n_type
, symbol
->n_sclass
,
2000 0, symbol
->n_numaux
, main_aux
);
2002 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
2005 /* Support for line number handling */
2007 /* This function is called for every section; it finds the outer limits
2008 * of the line table (minimum and maximum file offset) so that the
2009 * mainline code can read the whole thing for efficiency.
2012 find_linenos (abfd
, asect
, vpinfo
)
2017 struct coff_symfile_info
*info
;
2019 file_ptr offset
, maxoff
;
2021 count
= asect
->lineno_count
;
2023 if (!STREQ (asect
->name
, ".text") || count
== 0)
2026 size
= count
* coff_data (abfd
)->local_linesz
;
2027 info
= (struct coff_symfile_info
*)vpinfo
;
2028 offset
= asect
->line_filepos
;
2029 maxoff
= offset
+ size
;
2031 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
2032 info
->min_lineno_offset
= offset
;
2034 if (maxoff
> info
->max_lineno_offset
)
2035 info
->max_lineno_offset
= maxoff
;
2038 static void xcoff_psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
2041 xcoff_psymtab_to_symtab_1 (pst
)
2042 struct partial_symtab
*pst
;
2044 struct cleanup
*old_chain
;
2053 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2058 /* Read in all partial symtabs on which this one is dependent */
2059 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2060 if (!pst
->dependencies
[i
]->readin
)
2062 /* Inform about additional files that need to be read in. */
2065 fputs_filtered (" ", gdb_stdout
);
2067 fputs_filtered ("and ", gdb_stdout
);
2069 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2070 wrap_here (""); /* Flush output */
2071 gdb_flush (gdb_stdout
);
2073 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2076 if (((struct symloc
*)pst
->read_symtab_private
)->numsyms
!= 0)
2078 /* Init stuff necessary for reading in symbols. */
2081 old_chain
= make_cleanup (really_free_pendings
, 0);
2083 read_xcoff_symtab (pst
);
2084 sort_symtab_syms (pst
->symtab
);
2086 do_cleanups (old_chain
);
2092 static void xcoff_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
2094 /* Read in all of the symbols for a given psymtab for real.
2095 Be verbose about it if the user wants that. */
2098 xcoff_psymtab_to_symtab (pst
)
2099 struct partial_symtab
*pst
;
2109 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2114 if (((struct symloc
*)pst
->read_symtab_private
)->numsyms
!= 0
2115 || pst
->number_of_dependencies
)
2117 /* Print the message now, before reading the string table,
2118 to avoid disconcerting pauses. */
2121 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2122 gdb_flush (gdb_stdout
);
2125 sym_bfd
= pst
->objfile
->obfd
;
2127 next_symbol_text_func
= xcoff_next_symbol_text
;
2129 xcoff_psymtab_to_symtab_1 (pst
);
2131 /* Match with global symbols. This only needs to be done once,
2132 after all of the symtabs and dependencies have been read in. */
2133 scan_file_globals (pst
->objfile
);
2135 /* Finish up the debug error message. */
2137 printf_filtered ("done.\n");
2142 xcoff_new_init (objfile
)
2143 struct objfile
*objfile
;
2147 /* Do initialization in preparation for reading symbols from OBJFILE.
2149 We will only be called if this is an XCOFF or XCOFF-like file.
2150 BFD handles figuring out the format of the file, and code in symfile.c
2151 uses BFD's determination to vector to us. */
2154 xcoff_symfile_init (objfile
)
2155 struct objfile
*objfile
;
2157 /* Allocate struct to keep track of the symfile */
2158 objfile
-> sym_private
= xmmalloc (objfile
-> md
,
2159 sizeof (struct coff_symfile_info
));
2160 init_entry_point_info (objfile
);
2163 /* Perform any local cleanups required when we are done with a particular
2164 objfile. I.E, we are in the process of discarding all symbol information
2165 for an objfile, freeing up all memory held for it, and unlinking the
2166 objfile struct from the global list of known objfiles. */
2169 xcoff_symfile_finish (objfile
)
2170 struct objfile
*objfile
;
2172 if (objfile
-> sym_private
!= NULL
)
2174 mfree (objfile
-> md
, objfile
-> sym_private
);
2177 /* Start with a fresh include table for the next objfile. */
2183 inclIndx
= inclLength
= inclDepth
= 0;
2188 init_stringtab (abfd
, offset
, objfile
)
2191 struct objfile
*objfile
;
2195 unsigned char lengthbuf
[4];
2198 ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
= NULL
;
2200 if (bfd_seek (abfd
, offset
, L_SET
) < 0)
2201 error ("cannot seek to string table in %s: %s",
2202 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
2204 val
= bfd_read ((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
2205 length
= bfd_h_get_32 (abfd
, lengthbuf
);
2207 /* If no string table is needed, then the file may end immediately
2208 after the symbols. Just return with `strtbl' set to NULL. */
2210 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
2213 /* Allocate string table from symbol_obstack. We will need this table
2214 as long as we have its symbol table around. */
2216 strtbl
= (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
2217 ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
= strtbl
;
2219 if (length
== sizeof lengthbuf
)
2222 val
= bfd_read (strtbl
+ sizeof lengthbuf
, 1, length
- sizeof lengthbuf
,
2225 if (val
!= length
- sizeof lengthbuf
)
2226 error ("cannot read string table from %s: %s",
2227 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
2228 if (strtbl
[length
- 1] != '\0')
2229 error ("bad symbol file: string table does not end with null character");
2234 /* If we have not yet seen a function for this psymtab, this is 0. If we
2235 have seen one, it is the offset in the line numbers of the line numbers
2237 static unsigned int first_fun_line_offset
;
2239 static struct partial_symtab
*xcoff_start_psymtab
2240 PARAMS ((struct objfile
*, struct section_offsets
*, char *, int,
2241 struct partial_symbol
*, struct partial_symbol
*));
2243 /* Allocate and partially fill a partial symtab. It will be
2244 completely filled at the end of the symbol list.
2246 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2247 is the address relative to which its symbols are (incremental) or 0
2250 static struct partial_symtab
*
2251 xcoff_start_psymtab (objfile
, section_offsets
,
2252 filename
, first_symnum
, global_syms
, static_syms
)
2253 struct objfile
*objfile
;
2254 struct section_offsets
*section_offsets
;
2257 struct partial_symbol
*global_syms
;
2258 struct partial_symbol
*static_syms
;
2260 struct partial_symtab
*result
=
2261 start_psymtab_common (objfile
, section_offsets
,
2263 /* We fill in textlow later. */
2265 global_syms
, static_syms
);
2267 result
->read_symtab_private
= (char *)
2268 obstack_alloc (&objfile
-> psymbol_obstack
, sizeof (struct symloc
));
2269 ((struct symloc
*)result
->read_symtab_private
)->first_symnum
= first_symnum
;
2270 result
->read_symtab
= xcoff_psymtab_to_symtab
;
2272 /* Deduce the source language from the filename for this psymtab. */
2273 psymtab_language
= deduce_language_from_filename (filename
);
2278 static struct partial_symtab
*xcoff_end_psymtab
2279 PARAMS ((struct partial_symtab
*, char **, int, int,
2280 struct partial_symtab
**, int));
2282 /* Close off the current usage of PST.
2283 Returns PST, or NULL if the partial symtab was empty and thrown away.
2285 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2287 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2288 are the information for includes and dependencies. */
2290 static struct partial_symtab
*
2291 xcoff_end_psymtab (pst
, include_list
, num_includes
, capping_symbol_number
,
2292 dependency_list
, number_dependencies
)
2293 struct partial_symtab
*pst
;
2294 char **include_list
;
2296 int capping_symbol_number
;
2297 struct partial_symtab
**dependency_list
;
2298 int number_dependencies
;
2301 struct objfile
*objfile
= pst
-> objfile
;
2303 if (capping_symbol_number
!= -1)
2304 ((struct symloc
*)pst
->read_symtab_private
)->numsyms
=
2305 capping_symbol_number
2306 - ((struct symloc
*)pst
->read_symtab_private
)->first_symnum
;
2307 ((struct symloc
*)pst
->read_symtab_private
)->lineno_off
=
2308 first_fun_line_offset
;
2309 first_fun_line_offset
= 0;
2310 pst
->n_global_syms
=
2311 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2312 pst
->n_static_syms
=
2313 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2315 pst
->number_of_dependencies
= number_dependencies
;
2316 if (number_dependencies
)
2318 pst
->dependencies
= (struct partial_symtab
**)
2319 obstack_alloc (&objfile
->psymbol_obstack
,
2320 number_dependencies
* sizeof (struct partial_symtab
*));
2321 memcpy (pst
->dependencies
, dependency_list
,
2322 number_dependencies
* sizeof (struct partial_symtab
*));
2325 pst
->dependencies
= 0;
2327 for (i
= 0; i
< num_includes
; i
++)
2329 struct partial_symtab
*subpst
=
2330 allocate_psymtab (include_list
[i
], objfile
);
2332 subpst
->section_offsets
= pst
->section_offsets
;
2333 subpst
->read_symtab_private
=
2334 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
2335 sizeof (struct symloc
));
2336 ((struct symloc
*)subpst
->read_symtab_private
)->first_symnum
= 0;
2337 ((struct symloc
*)subpst
->read_symtab_private
)->numsyms
= 0;
2338 subpst
->textlow
= 0;
2339 subpst
->texthigh
= 0;
2341 /* We could save slight bits of space by only making one of these,
2342 shared by the entire set of include files. FIXME-someday. */
2343 subpst
->dependencies
= (struct partial_symtab
**)
2344 obstack_alloc (&objfile
->psymbol_obstack
,
2345 sizeof (struct partial_symtab
*));
2346 subpst
->dependencies
[0] = pst
;
2347 subpst
->number_of_dependencies
= 1;
2349 subpst
->globals_offset
=
2350 subpst
->n_global_syms
=
2351 subpst
->statics_offset
=
2352 subpst
->n_static_syms
= 0;
2356 subpst
->read_symtab
= pst
->read_symtab
;
2359 sort_pst_symbols (pst
);
2361 /* If there is already a psymtab or symtab for a file of this name,
2362 remove it. (If there is a symtab, more drastic things also
2363 happen.) This happens in VxWorks. */
2364 free_named_symtabs (pst
->filename
);
2366 if (num_includes
== 0
2367 && number_dependencies
== 0
2368 && pst
->n_global_syms
== 0
2369 && pst
->n_static_syms
== 0)
2371 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2372 it is on the obstack, but we can forget to chain it on the list. */
2373 /* Empty psymtabs happen as a result of header files which don't have
2374 any symbols in them. There can be a lot of them. But this check
2375 is wrong, in that a psymtab with N_SLINE entries but nothing else
2376 is not empty, but we don't realize that. Fixing that without slowing
2377 things down might be tricky. (FIXME: For XCOFF, it shouldn't be
2379 struct partial_symtab
*prev_pst
;
2381 /* First, snip it out of the psymtab chain */
2383 if (pst
->objfile
->psymtabs
== pst
)
2384 pst
->objfile
->psymtabs
= pst
->next
;
2386 for (prev_pst
= pst
->objfile
->psymtabs
; prev_pst
; prev_pst
= pst
->next
)
2387 if (prev_pst
->next
== pst
)
2388 prev_pst
->next
= pst
->next
;
2390 /* Next, put it on a free list for recycling */
2392 pst
->next
= pst
->objfile
->free_psymtabs
;
2393 pst
->objfile
->free_psymtabs
= pst
;
2395 /* Indicate that psymtab was thrown away. */
2396 pst
= (struct partial_symtab
*)NULL
;
2401 static void swap_sym
PARAMS ((struct internal_syment
*,
2402 union internal_auxent
*, char **, char **,
2406 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2407 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2408 the symbol and its auxents. */
2411 swap_sym (symbol
, aux
, name
, raw
, symnump
, objfile
)
2412 struct internal_syment
*symbol
;
2413 union internal_auxent
*aux
;
2416 unsigned int *symnump
;
2417 struct objfile
*objfile
;
2419 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2420 if (symbol
->n_zeroes
)
2422 /* If it's exactly E_SYMNMLEN characters long it isn't
2424 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2426 /* FIXME: wastes memory for symbols which we don't end up putting
2427 into the minimal symbols. */
2429 p
= obstack_alloc (&objfile
->psymbol_obstack
, E_SYMNMLEN
+ 1);
2430 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2431 p
[E_SYMNMLEN
] = '\0';
2435 /* Point to the unswapped name as that persists as long as the
2437 *name
= ((struct external_syment
*)*raw
)->e
.e_name
;
2439 else if (symbol
->n_sclass
& 0x80)
2441 *name
= ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
2446 *name
= ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
2450 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2451 if (symbol
->n_numaux
> 0)
2453 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2454 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2456 *symnump
+= symbol
->n_numaux
;
2457 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2462 scan_xcoff_symtab (section_offsets
, objfile
)
2463 struct section_offsets
*section_offsets
;
2464 struct objfile
*objfile
;
2466 int toc_offset
= 0; /* toc offset value in data section. */
2471 int past_first_source_file
= 0;
2472 CORE_ADDR last_o_file_start
= 0;
2473 struct cleanup
*back_to
;
2477 /* Current partial symtab */
2478 struct partial_symtab
*pst
;
2480 /* List of current psymtab's include files */
2481 char **psymtab_include_list
;
2482 int includes_allocated
;
2485 /* Index within current psymtab dependency list */
2486 struct partial_symtab
**dependency_list
;
2487 int dependencies_used
, dependencies_allocated
;
2490 struct internal_syment symbol
;
2491 union internal_auxent main_aux
;
2492 unsigned int ssymnum
;
2494 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2495 CORE_ADDR last_csect_val
;
2497 int misc_func_recorded
; /* true if any misc. function */
2499 pst
= (struct partial_symtab
*) 0;
2501 includes_allocated
= 30;
2503 psymtab_include_list
= (char **) alloca (includes_allocated
*
2506 dependencies_allocated
= 30;
2507 dependencies_used
= 0;
2509 (struct partial_symtab
**) alloca (dependencies_allocated
*
2510 sizeof (struct partial_symtab
*));
2512 last_source_file
= NULL
;
2514 abfd
= objfile
->obfd
;
2516 sraw_symbol
= ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl
;
2517 nsyms
= ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl_num_syms
;
2519 while (ssymnum
< nsyms
)
2521 int sclass
= ((struct external_syment
*)sraw_symbol
)->e_sclass
[0];
2522 /* This is the type we pass to partial-stab.h. A less kludgy solution
2523 would be to break out partial-stab.h into its various parts--shuffle
2524 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2525 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2535 /* The CSECT auxent--always the last auxent. */
2536 union internal_auxent csect_aux
;
2537 unsigned int symnum_before
= ssymnum
;
2539 swap_sym (&symbol
, &main_aux
, &namestring
, &sraw_symbol
,
2541 if (symbol
.n_numaux
> 1)
2543 bfd_coff_swap_aux_in
2545 sraw_symbol
- coff_data(abfd
)->local_symesz
,
2548 symbol
.n_numaux
- 1,
2553 csect_aux
= main_aux
;
2555 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2558 switch (csect_aux
.x_csect
.x_smclas
)
2561 if (last_csect_name
)
2563 /* If no misc. function recorded in the last
2564 seen csect, enter it as a function. This
2565 will take care of functions like strcmp()
2568 if (!misc_func_recorded
)
2570 RECORD_MINIMAL_SYMBOL
2571 (last_csect_name
, last_csect_val
,
2572 mst_text
, last_csect_sec
,
2578 /* We have to allocate one psymtab for
2579 each program csect, because their text
2580 sections need not be adjacent. */
2582 (pst
, psymtab_include_list
,
2585 dependency_list
, dependencies_used
);
2587 dependencies_used
= 0;
2588 /* Give all psymtabs for this source file the same
2590 pst
= xcoff_start_psymtab
2591 (objfile
, section_offsets
,
2594 objfile
->global_psymbols
.next
,
2595 objfile
->static_psymbols
.next
);
2598 if (namestring
&& namestring
[0] == '.')
2600 last_csect_name
= namestring
;
2601 last_csect_val
= symbol
.n_value
;
2603 secnum_to_section (symbol
.n_scnum
, objfile
);
2608 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2609 if (highval
> pst
->texthigh
)
2610 pst
->texthigh
= highval
;
2611 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2612 pst
->textlow
= symbol
.n_value
;
2614 misc_func_recorded
= 0;
2620 warning ("More than one XMC_TC0 symbol found.");
2621 toc_offset
= symbol
.n_value
;
2624 /* These symbols tell us where the TOC entry for a
2625 variable is, not the variable itself. */
2633 switch (csect_aux
.x_csect
.x_smclas
)
2637 /* A function entry point. */
2638 char *namestr
= namestring
;
2640 if (first_fun_line_offset
== 0)
2641 first_fun_line_offset
=
2642 main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2643 if (namestr
[0] == '.')
2645 prim_record_minimal_symbol_and_info
2646 (namestr
, symbol
.n_value
, mst_text
,
2647 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2649 misc_func_recorded
= 1;
2651 /* We also create full symbols for these, so
2652 better make a partial symbol. This seems bogus
2653 to me, but I'm not going to try to fix it now.
2654 (Note that allocate_space_in_inferior can't
2655 yet deal with a minimal symbol for malloc on xcoff
2656 because it doesn't understand the fact that
2657 function pointers don't just contain the address of
2659 ADD_PSYMBOL_ADDR_TO_LIST (namestr
, strlen (namestr
),
2660 VAR_NAMESPACE
, LOC_BLOCK
,
2661 objfile
->global_psymbols
,
2663 psymtab_language
, objfile
);
2667 /* shared library function trampoline code entry
2670 /* record trampoline code entries as
2671 mst_solib_trampoline symbol. When we lookup mst
2672 symbols, we will choose mst_text over
2673 mst_solib_trampoline. */
2674 RECORD_MINIMAL_SYMBOL
2675 (namestring
, symbol
.n_value
,
2676 mst_solib_trampoline
,
2677 secnum_to_section (symbol
.n_scnum
, objfile
),
2682 /* The symbols often have the same names as
2683 debug symbols for functions, and confuse
2689 /* xlc puts each variable in a separate csect,
2690 so we get an XTY_SD for each variable. But
2691 gcc puts several variables in a csect, so
2692 that each variable only gets an XTY_LD. We
2693 still need to record them. This will
2694 typically be XMC_RW; I suspect XMC_RO and
2695 XMC_BS might be possible too. */
2697 /* FIXME: Shouldn't these be going into the minimal
2698 symbols instead of partial/full symbols? */
2700 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, strlen (namestring
),
2701 VAR_NAMESPACE
, LOC_STATIC
,
2702 objfile
->global_psymbols
,
2704 psymtab_language
, objfile
);
2714 unsigned int symnum_before
;
2716 symnum_before
= ssymnum
;
2717 swap_sym (&symbol
, &main_aux
, &namestring
, &sraw_symbol
,
2720 /* See if the last csect needs to be recorded. */
2722 if (last_csect_name
&& !misc_func_recorded
)
2725 /* If no misc. function recorded in the last seen csect, enter
2726 it as a function. This will take care of functions like
2727 strcmp() compiled by xlc. */
2729 RECORD_MINIMAL_SYMBOL
2730 (last_csect_name
, last_csect_val
,
2731 mst_text
, last_csect_sec
, objfile
);
2736 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2738 dependency_list
, dependencies_used
);
2740 dependencies_used
= 0;
2742 first_fun_line_offset
= 0;
2744 /* XCOFF, according to the AIX 3.2 documentation, puts the
2745 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2746 do things the standard COFF way and put it in the auxent.
2747 We use the auxent if the symbol is ".file" and an auxent
2748 exists, otherwise use the symbol itself. */
2749 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2751 filestring
= coff_getfilename (&main_aux
, objfile
);
2754 filestring
= namestring
;
2756 pst
= xcoff_start_psymtab (objfile
, section_offsets
,
2759 objfile
->global_psymbols
.next
,
2760 objfile
->static_psymbols
.next
);
2761 last_csect_name
= NULL
;
2767 static struct complaint msg
=
2768 {"Storage class %d not recognized during scan", 0, 0};
2769 complain (&msg
, sclass
);
2773 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2774 to handle only the C_FUN and C_EXT. */
2789 /* C_EINCL means we are switching back to the main file. But there
2790 is no reason to care; the only thing we want to know about
2791 includes is the names of all the included (.h) files. */
2796 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2800 /* I don't think the name of the common block (as opposed to the
2801 variables within it) is something which is user visible
2809 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2810 so C_LSYM would appear to be only for locals. */
2816 /* We probably could save a few instructions by assuming that
2817 C_LSYM, C_PSYM, etc., never have auxents. */
2819 ((struct external_syment
*)sraw_symbol
)->e_numaux
[0] + 1;
2821 sraw_symbol
+= sizeof (struct external_syment
) * naux1
;
2830 /* The value of the C_FUN is not the address of the function (it
2831 appears to be the address before linking), but as long as it
2832 is smaller than the actual address, then find_pc_partial_function
2833 will use the minimal symbols instead. I hope. */
2841 swap_sym (&symbol
, &main_aux
, &namestring
, &sraw_symbol
,
2843 #define CUR_SYMBOL_TYPE stype
2844 #define CUR_SYMBOL_VALUE symbol.n_value
2846 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2847 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2849 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms) 0
2850 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)\
2852 /* We have already set the namestring. */
2853 #define SET_NAMESTRING() 0
2855 #include "partial-stab.h"
2860 /* If there's stuff to be cleaned up, clean it up. */
2861 if (DBX_SYMCOUNT (objfile
) > 0 /* We have some syms */
2862 /*FIXME, does this have a bug at start address 0? */
2863 && last_o_file_start
2864 && objfile
-> ei
.entry_point
< bufp
->n_value
2865 && objfile
-> ei
.entry_point
>= last_o_file_start
)
2867 objfile
-> ei
.entry_file_lowpc
= last_o_file_start
;
2868 objfile
-> ei
.entry_file_highpc
= bufp
->n_value
;
2874 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2876 dependency_list
, dependencies_used
);
2879 /* Record the toc offset value of this symbol table into ldinfo structure.
2880 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2881 this information would be file auxiliary header. */
2883 #ifndef FAKING_RS6000
2884 xcoff_add_toc_to_loadinfo (toc_offset
);
2888 /* Scan and build partial symbols for a symbol file.
2889 We have been initialized by a call to dbx_symfile_init, which
2890 put all the relevant info into a "struct dbx_symfile_info",
2891 hung off the objfile structure.
2893 SECTION_OFFSETS contains offsets relative to which the symbols in the
2894 various sections are (depending where the sections were actually loaded).
2895 MAINLINE is true if we are reading the main symbol
2896 table (as opposed to a shared lib or dynamically loaded file). */
2899 xcoff_initial_scan (objfile
, section_offsets
, mainline
)
2900 struct objfile
*objfile
;
2901 struct section_offsets
*section_offsets
;
2902 int mainline
; /* FIXME comments above */
2906 struct cleanup
*back_to
;
2907 int num_symbols
; /* # of symbols */
2908 file_ptr symtab_offset
; /* symbol table and */
2909 file_ptr stringtab_offset
; /* string table file offsets */
2910 struct coff_symfile_info
*info
;
2914 #ifndef FAKING_RS6000
2915 /* Initialize load info structure. */
2917 xcoff_init_loadinfo ();
2920 info
= (struct coff_symfile_info
*) objfile
-> sym_private
;
2921 symfile_bfd
= abfd
= objfile
->obfd
;
2922 name
= objfile
->name
;
2924 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2925 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2926 stringtab_offset
= symtab_offset
+
2927 num_symbols
* coff_data(abfd
)->local_symesz
;
2929 info
->min_lineno_offset
= 0;
2930 info
->max_lineno_offset
= 0;
2931 bfd_map_over_sections (abfd
, find_linenos
, info
);
2933 if (num_symbols
> 0)
2935 /* Read the string table. */
2936 init_stringtab (abfd
, stringtab_offset
, objfile
);
2938 /* Read the .debug section, if present. */
2941 bfd_size_type length
;
2942 char *debugsec
= NULL
;
2944 secp
= bfd_get_section_by_name (abfd
, ".debug");
2947 length
= bfd_section_size (abfd
, secp
);
2951 (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
2953 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2954 (file_ptr
) 0, length
))
2956 error ("Error reading .debug section of `%s': %s",
2957 name
, bfd_errmsg (bfd_get_error ()));
2961 ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
=
2966 /* Read the symbols. We keep them in core because we will want to
2967 access them randomly in read_symbol*. */
2968 val
= bfd_seek (abfd
, symtab_offset
, L_SET
);
2970 error ("Error reading symbols from %s: %s",
2971 name
, bfd_errmsg (bfd_get_error ()));
2972 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2973 ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl
=
2974 obstack_alloc (&objfile
->symbol_obstack
, size
);
2975 ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl_num_syms
=
2978 val
= bfd_read (((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl
,
2981 perror_with_name ("reading symbol table");
2983 /* If we are reinitializing, or if we have never loaded syms yet, init */
2985 || objfile
->global_psymbols
.size
== 0
2986 || objfile
->static_psymbols
.size
== 0)
2987 /* I'm not sure how how good num_symbols is; the rule of thumb in
2988 init_psymbol_list was developed for a.out. On the one hand,
2989 num_symbols includes auxents. On the other hand, it doesn't
2991 init_psymbol_list (objfile
, num_symbols
);
2994 back_to
= make_cleanup (really_free_pendings
, 0);
2996 init_minimal_symbol_collection ();
2997 make_cleanup (discard_minimal_symbols
, 0);
2999 /* Now that the symbol table data of the executable file are all in core,
3000 process them and define symbols accordingly. */
3002 scan_xcoff_symtab (section_offsets
, objfile
);
3004 /* Install any minimal symbols that have been collected as the current
3005 minimal symbols for this objfile. */
3007 install_minimal_symbols (objfile
);
3009 do_cleanups (back_to
);
3012 static struct section_offsets
*
3013 xcoff_symfile_offsets (objfile
, addr
)
3014 struct objfile
*objfile
;
3017 struct section_offsets
*section_offsets
;
3020 objfile
->num_sections
= SECT_OFF_MAX
;
3021 section_offsets
= (struct section_offsets
*)
3023 (&objfile
-> psymbol_obstack
,
3024 sizeof (struct section_offsets
)
3025 + sizeof (section_offsets
->offsets
) * objfile
->num_sections
);
3027 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
3028 of the .text section. This strikes me as wrong--whether the
3029 offset to be applied to symbol reading is relative to the start
3030 address of the section depends on the symbol format. In any
3031 event, this whole "addr" concept is pretty broken (it doesn't
3032 handle any section but .text sensibly), so just ignore the addr
3033 parameter and use 0. rs6000-nat.c will set the correct section
3034 offsets via objfile_relocate. */
3035 for (i
= 0; i
< objfile
->num_sections
; ++i
)
3036 ANOFFSET (section_offsets
, i
) = 0;
3038 return section_offsets
;
3041 /* Register our ability to parse symbols for xcoff BFD files. */
3043 static struct sym_fns xcoff_sym_fns
=
3046 /* Because the bfd uses coff_flavour, we need to specially kludge
3047 the flavour. It is possible that coff and xcoff should be merged as
3048 they do have fundamental similarities (for example, the extra storage
3049 classes used for stabs could presumably be recognized in any COFF file).
3050 However, in addition to obvious things like all the csect hair, there are
3051 some subtler differences between xcoffread.c and coffread.c, notably
3052 the fact that coffread.c has no need to read in all the symbols, but
3053 xcoffread.c reads all the symbols and does in fact randomly access them
3054 (in C_BSTAT and line number processing). */
3056 (enum bfd_flavour
)-1,
3058 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3059 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3060 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
3061 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3062 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
3063 NULL
/* next: pointer to next struct sym_fns */
3067 _initialize_xcoffread ()
3069 add_symtab_fns(&xcoff_sym_fns
);
3071 /* Initialize symbol template later used for arguments. Its other
3072 fields are zero, or are filled in later. */
3073 SYMBOL_NAME (&parmsym
) = "";
3074 SYMBOL_INIT_LANGUAGE_SPECIFIC (&parmsym
, language_c
);
3075 SYMBOL_NAMESPACE (&parmsym
) = VAR_NAMESPACE
;
3076 SYMBOL_CLASS (&parmsym
) = LOC_ARG
;
3078 func_symbol_type
= init_type (TYPE_CODE_FUNC
, 1, 0,
3079 "<function, no debug info>", NULL
);
3080 TYPE_TARGET_TYPE (func_symbol_type
) = builtin_type_int
;
3082 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
3083 "<variable, no debug info>", NULL
);