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 1996, 1997, 1998, 1999, 2000
4 Free Software Foundation, Inc.
5 Derived from coffread.c, dbxread.c, and a lot of hacking.
6 Contributed by IBM Corporation.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
28 #include <sys/types.h>
31 #include "gdb_string.h"
33 #include <sys/param.h>
39 #include "coff/internal.h"
40 #include "libcoff.h" /* FIXME, internal data from BFD */
41 #include "coff/rs6000.h"
48 #include "stabsread.h"
49 #include "expression.h"
50 #include "language.h" /* Needed inside partial-stab.h */
51 #include "complaints.h"
53 #include "gdb-stabs.h"
55 /* For interface with stabsread.c. */
56 #include "aout/stab_gnu.h"
58 /* For interface with partial-stab.h. */
59 #define N_UNDF 0 /* Undefined symbol */
62 #define N_TEXT 4 /* Text sym -- defined at offset in text seg */
63 #define N_DATA 6 /* Data sym -- defined at offset in data seg */
64 #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
65 #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
66 #define N_FN 0x1f /* File name of .o file */
67 #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
68 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
69 N_DATA, or N_BSS. When the low-order bit of other types is set,
70 (e.g. N_WARNING versus N_FN), they are two different types. */
71 #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
74 /* The following symbols refer to set elements.
75 All the N_SET[ATDB] symbols with the same name form one set.
76 Space is allocated for the set in the text section, and each set
77 elements value is stored into one word of the space.
78 The first word of the space is the length of the set (number of elements).
80 The address of the set is made into an N_SETV symbol
81 whose name is the same as the name of the set.
82 This symbol acts like a N_DATA global symbol
83 in that it can satisfy undefined external references. */
85 /* These appear as input to LD, in a .o file. */
86 #define N_SETA 0x14 /* Absolute set element symbol */
87 #define N_SETT 0x16 /* Text set element symbol */
88 #define N_SETD 0x18 /* Data set element symbol */
89 #define N_SETB 0x1A /* Bss set element symbol */
91 /* This is output from LD. */
92 #define N_SETV 0x1C /* Pointer to set vector in data area. */
94 /* We put a pointer to this structure in the read_symtab_private field
100 /* First symbol number for this file. */
104 /* Number of symbols in the section of the symbol table devoted to
105 this file's symbols (actually, the section bracketed may contain
106 more than just this file's symbols). If numsyms is 0, the only
107 reason for this thing's existence is the dependency list. Nothing
108 else will happen when it is read in. */
112 /* Position of the start of the line number information for this psymtab. */
113 unsigned int lineno_off
;
116 /* Remember what we deduced to be the source language of this psymtab. */
118 static enum language psymtab_language
= language_unknown
;
121 /* Simplified internal version of coff symbol table information */
126 int c_symnum
; /* symbol number of this entry */
127 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
129 unsigned char c_sclass
;
134 /* last function's saved coff symbol `cs' */
136 static struct coff_symbol fcn_cs_saved
;
138 static bfd
*symfile_bfd
;
140 /* Core address of start and end of text of current source file.
141 This is calculated from the first function seen after a C_FILE
145 static CORE_ADDR cur_src_end_addr
;
147 /* Core address of the end of the first object file. */
149 static CORE_ADDR first_object_file_end
;
151 /* initial symbol-table-debug-string vector length */
153 #define INITIAL_STABVECTOR_LENGTH 40
155 /* Nonzero if within a function (so symbols should be local,
156 if nothing says specifically). */
160 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
161 there is any reason not to just use a #define, but might as well
162 ask BFD for the size and store it here, I guess. */
164 static unsigned local_symesz
;
166 struct coff_symfile_info
168 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
169 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
171 /* Pointer to the string table. */
174 /* Pointer to debug section. */
177 /* Pointer to the a.out symbol table. */
180 /* Number of symbols in symtbl. */
183 /* Offset in data section to TOC anchor. */
184 CORE_ADDR toc_offset
;
187 static struct complaint storclass_complaint
=
188 {"Unexpected storage class: %d", 0, 0};
190 static struct complaint bf_notfound_complaint
=
191 {"line numbers off, `.bf' symbol not found", 0, 0};
193 static struct complaint ef_complaint
=
194 {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
196 static struct complaint eb_complaint
=
197 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
199 static void xcoff_initial_scan (struct objfile
*, int);
201 static void scan_xcoff_symtab (struct objfile
*);
203 static char *xcoff_next_symbol_text (struct objfile
*);
205 static void record_include_begin (struct coff_symbol
*);
208 enter_line_range (struct subfile
*, unsigned, unsigned,
209 CORE_ADDR
, CORE_ADDR
, unsigned *);
211 static void init_stringtab (bfd
*, file_ptr
, struct objfile
*);
213 static void xcoff_symfile_init (struct objfile
*);
215 static void xcoff_new_init (struct objfile
*);
217 static void xcoff_symfile_finish (struct objfile
*);
220 xcoff_symfile_offsets (struct objfile
*, struct section_addr_info
*addrs
);
222 static void find_linenos (bfd
*, sec_ptr
, PTR
);
224 static char *coff_getfilename (union internal_auxent
*, struct objfile
*);
226 static void read_symbol (struct internal_syment
*, int);
228 static int read_symbol_lineno (int);
230 static CORE_ADDR
read_symbol_nvalue (int);
232 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
235 static void read_xcoff_symtab (struct partial_symtab
*);
238 static void add_stab_to_list (char *, struct pending_stabs
**);
241 static int compare_lte (const void *, const void *);
243 static struct linetable
*arrange_linetable (struct linetable
*);
245 static void record_include_end (struct coff_symbol
*);
247 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
250 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
252 static int secnum_to_section (int, struct objfile
*);
253 static asection
*secnum_to_bfd_section (int, struct objfile
*);
255 struct find_targ_sec_arg
260 struct objfile
*objfile
;
263 static void find_targ_sec (bfd
*, asection
*, void *);
266 find_targ_sec (bfd
*abfd
, asection
*sect
, PTR obj
)
268 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
269 struct objfile
*objfile
= args
->objfile
;
270 if (sect
->target_index
== args
->targ_index
)
272 /* This is the section. Figure out what SECT_OFF_* code it is. */
273 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
274 *args
->resultp
= SECT_OFF_TEXT (objfile
);
275 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
276 *args
->resultp
= SECT_OFF_DATA (objfile
);
278 *args
->resultp
= sect
->index
;
279 *args
->bfd_sect
= sect
;
283 /* Return the section number (SECT_OFF_*) that CS points to. */
285 secnum_to_section (int secnum
, struct objfile
*objfile
)
287 int off
= SECT_OFF_TEXT (objfile
);
288 asection
*sect
= NULL
;
289 struct find_targ_sec_arg args
;
290 args
.targ_index
= secnum
;
292 args
.bfd_sect
= §
;
293 args
.objfile
= objfile
;
294 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
298 /* Return the BFD section that CS points to. */
300 secnum_to_bfd_section (int secnum
, struct objfile
*objfile
)
302 int off
= SECT_OFF_TEXT (objfile
);
303 asection
*sect
= NULL
;
304 struct find_targ_sec_arg args
;
305 args
.targ_index
= secnum
;
307 args
.bfd_sect
= §
;
308 args
.objfile
= objfile
;
309 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
313 /* add a given stab string into given stab vector. */
318 add_stab_to_list (char *stabname
, struct pending_stabs
**stabvector
)
320 if (*stabvector
== NULL
)
322 *stabvector
= (struct pending_stabs
*)
323 xmalloc (sizeof (struct pending_stabs
) +
324 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
325 (*stabvector
)->count
= 0;
326 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
328 else if ((*stabvector
)->count
>= (*stabvector
)->length
)
330 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
331 *stabvector
= (struct pending_stabs
*)
332 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
333 (*stabvector
)->length
* sizeof (char *));
335 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
340 /* Linenos are processed on a file-by-file basis.
344 1) xlc (IBM's native c compiler) postpones static function code
345 emission to the end of a compilation unit. This way it can
346 determine if those functions (statics) are needed or not, and
347 can do some garbage collection (I think). This makes line
348 numbers and corresponding addresses unordered, and we end up
349 with a line table like:
366 and that breaks gdb's binary search on line numbers, if the
367 above table is not sorted on line numbers. And that sort
368 should be on function based, since gcc can emit line numbers
371 10 0x100 - for the init/test part of a for stmt.
374 10 0x400 - for the increment part of a for stmt.
376 arrange_linetable() will do this sorting.
378 2) aix symbol table might look like:
380 c_file // beginning of a new file
381 .bi // beginning of include file
382 .ei // end of include file
386 basically, .bi/.ei pairs do not necessarily encapsulate
387 their scope. They need to be recorded, and processed later
388 on when we come the end of the compilation unit.
389 Include table (inclTable) and process_linenos() handle
395 /* compare line table entry addresses. */
398 compare_lte (const void *lte1p
, const void *lte2p
)
400 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
401 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
402 return lte1
->pc
- lte2
->pc
;
405 /* Given a line table with function entries are marked, arrange its functions
406 in ascending order and strip off function entry markers and return it in
407 a newly created table. If the old one is good enough, return the old one. */
408 /* FIXME: I think all this stuff can be replaced by just passing
409 sort_linevec = 1 to end_symtab. */
411 static struct linetable
*
412 arrange_linetable (struct linetable
*oldLineTb
)
414 int ii
, jj
, newline
, /* new line count */
415 function_count
; /* # of functions */
417 struct linetable_entry
*fentry
; /* function entry vector */
418 int fentry_size
; /* # of function entries */
419 struct linetable
*newLineTb
; /* new line table */
421 #define NUM_OF_FUNCTIONS 20
423 fentry_size
= NUM_OF_FUNCTIONS
;
424 fentry
= (struct linetable_entry
*)
425 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
427 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
430 if (oldLineTb
->item
[ii
].line
== 0)
431 { /* function entry found. */
433 if (function_count
>= fentry_size
)
434 { /* make sure you have room. */
436 fentry
= (struct linetable_entry
*)
437 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
439 fentry
[function_count
].line
= ii
;
440 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
445 if (function_count
== 0)
450 else if (function_count
> 1)
451 qsort (fentry
, function_count
, sizeof (struct linetable_entry
), compare_lte
);
453 /* allocate a new line table. */
454 newLineTb
= (struct linetable
*)
456 (sizeof (struct linetable
) +
457 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
459 /* if line table does not start with a function beginning, copy up until
463 if (oldLineTb
->item
[0].line
!= 0)
465 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
466 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
468 /* Now copy function lines one by one. */
470 for (ii
= 0; ii
< function_count
; ++ii
)
472 for (jj
= fentry
[ii
].line
+ 1;
473 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
475 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
478 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
482 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
483 following `IncludeChain'. At the end of each symtab (end_symtab),
484 we will determine if we should create additional symtab's to
485 represent if (the include files. */
488 typedef struct _inclTable
490 char *name
; /* include filename */
492 /* Offsets to the line table. end points to the last entry which is
493 part of this include file. */
496 struct subfile
*subfile
;
497 unsigned funStartLine
; /* start line # of its function */
501 #define INITIAL_INCLUDE_TABLE_LENGTH 20
502 static InclTable
*inclTable
; /* global include table */
503 static int inclIndx
; /* last entry to table */
504 static int inclLength
; /* table length */
505 static int inclDepth
; /* nested include depth */
507 static void allocate_include_entry (void);
510 record_include_begin (struct coff_symbol
*cs
)
514 /* In xcoff, we assume include files cannot be nested (not in .c files
515 of course, but in corresponding .s files.). */
517 /* This can happen with old versions of GCC.
518 GCC 2.3.3-930426 does not exhibit this on a test case which
519 a user said produced the message for him. */
520 static struct complaint msg
=
521 {"Nested C_BINCL symbols", 0, 0};
526 allocate_include_entry ();
528 inclTable
[inclIndx
].name
= cs
->c_name
;
529 inclTable
[inclIndx
].begin
= cs
->c_value
;
533 record_include_end (struct coff_symbol
*cs
)
539 static struct complaint msg
=
540 {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
544 allocate_include_entry ();
546 pTbl
= &inclTable
[inclIndx
];
547 pTbl
->end
= cs
->c_value
;
554 allocate_include_entry (void)
556 if (inclTable
== NULL
)
558 inclTable
= (InclTable
*)
559 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
561 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
562 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
565 else if (inclIndx
>= inclLength
)
567 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
568 inclTable
= (InclTable
*)
569 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
570 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
571 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
575 /* Global variable to pass the psymtab down to all the routines involved
576 in psymtab to symtab processing. */
577 static struct partial_symtab
*this_symtab_psymtab
;
579 /* given the start and end addresses of a compilation unit (or a csect,
580 at times) process its lines and create appropriate line vectors. */
583 process_linenos (CORE_ADDR start
, CORE_ADDR end
)
586 file_ptr max_offset
=
587 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
590 /* subfile structure for the main compilation unit. */
591 struct subfile main_subfile
;
593 /* In the main source file, any time we see a function entry, we
594 reset this variable to function's absolute starting line number.
595 All the following line numbers in the function are relative to
596 this, and we record absolute line numbers in record_line(). */
598 unsigned int main_source_baseline
= 0;
603 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
605 goto return_after_cleanup
;
607 memset (&main_subfile
, '\0', sizeof (main_subfile
));
610 /* All source lines were in the main source file. None in include files. */
612 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
613 &main_source_baseline
);
617 /* There was source with line numbers in include files. */
620 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
621 main_source_baseline
= 0;
623 for (ii
= 0; ii
< inclIndx
; ++ii
)
625 struct subfile
*tmpSubfile
;
627 /* If there is main file source before include file, enter it. */
628 if (offset
< inclTable
[ii
].begin
)
631 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
632 start
, 0, &main_source_baseline
);
635 /* Have a new subfile for the include file. */
637 tmpSubfile
= inclTable
[ii
].subfile
=
638 (struct subfile
*) xmalloc (sizeof (struct subfile
));
640 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
641 firstLine
= &(inclTable
[ii
].funStartLine
);
643 /* Enter include file's lines now. */
644 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
645 inclTable
[ii
].end
, start
, 0, firstLine
);
647 if (offset
<= inclTable
[ii
].end
)
648 offset
= inclTable
[ii
].end
+ linesz
;
651 /* All the include files' line have been processed at this point. Now,
652 enter remaining lines of the main file, if any left. */
653 if (offset
< max_offset
+ 1 - linesz
)
655 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
656 &main_source_baseline
);
660 /* Process main file's line numbers. */
661 if (main_subfile
.line_vector
)
663 struct linetable
*lineTb
, *lv
;
665 lv
= main_subfile
.line_vector
;
667 /* Line numbers are not necessarily ordered. xlc compilation will
668 put static function to the end. */
670 lineTb
= arrange_linetable (lv
);
673 current_subfile
->line_vector
= (struct linetable
*)
674 xrealloc (lv
, (sizeof (struct linetable
)
675 + lv
->nitems
* sizeof (struct linetable_entry
)));
680 current_subfile
->line_vector
= lineTb
;
683 current_subfile
->line_vector_length
=
684 current_subfile
->line_vector
->nitems
;
687 /* Now, process included files' line numbers. */
689 for (ii
= 0; ii
< inclIndx
; ++ii
)
691 if ((inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
693 struct linetable
*lineTb
, *lv
;
695 lv
= (inclTable
[ii
].subfile
)->line_vector
;
697 /* Line numbers are not necessarily ordered. xlc compilation will
698 put static function to the end. */
700 lineTb
= arrange_linetable (lv
);
704 /* For the same include file, we might want to have more than one
705 subfile. This happens if we have something like:
713 while foo.h including code in it. (stupid but possible)
714 Since start_subfile() looks at the name and uses an
715 existing one if finds, we need to provide a fake name and
719 start_subfile (inclTable
[ii
].name
, (char *) 0);
722 /* Pick a fake name that will produce the same results as this
723 one when passed to deduce_language_from_filename. Kludge on
725 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
726 if (fakename
== NULL
)
728 start_subfile (fakename
, (char *) 0);
729 xfree (current_subfile
->name
);
731 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
736 current_subfile
->line_vector
=
737 (struct linetable
*) xrealloc
738 (lv
, (sizeof (struct linetable
)
739 + lv
->nitems
* sizeof (struct linetable_entry
)));
745 current_subfile
->line_vector
= lineTb
;
748 current_subfile
->line_vector_length
=
749 current_subfile
->line_vector
->nitems
;
750 start_subfile (pop_subfile (), (char *) 0);
754 return_after_cleanup
:
756 /* We don't want to keep alloc/free'ing the global include file table. */
759 /* Start with a fresh subfile structure for the next file. */
760 memset (&main_subfile
, '\0', sizeof (struct subfile
));
764 aix_process_linenos (void)
766 /* process line numbers and enter them into line vector */
767 process_linenos (last_source_start_addr
, cur_src_end_addr
);
771 /* Enter a given range of lines into the line vector.
772 can be called in the following two ways:
773 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
774 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
776 endoffset points to the last line table entry that we should pay
780 enter_line_range (struct subfile
*subfile
, unsigned beginoffset
, unsigned endoffset
, /* offsets to line table */
781 CORE_ADDR startaddr
, /* offsets to line table */
782 CORE_ADDR endaddr
, unsigned *firstLine
)
784 unsigned int curoffset
;
787 struct internal_lineno int_lnno
;
788 unsigned int limit_offset
;
792 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
794 curoffset
= beginoffset
;
796 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
801 if (endoffset
>= limit_offset
)
803 static struct complaint msg
=
804 {"Bad line table offset in C_EINCL directive", 0, 0};
808 limit_offset
= endoffset
;
813 abfd
= this_symtab_psymtab
->objfile
->obfd
;
814 linesz
= coff_data (abfd
)->local_linesz
;
815 ext_lnno
= alloca (linesz
);
817 while (curoffset
<= limit_offset
)
819 bfd_seek (abfd
, curoffset
, SEEK_SET
);
820 bfd_read (ext_lnno
, linesz
, 1, abfd
);
821 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
823 /* Find the address this line represents. */
824 addr
= (int_lnno
.l_lnno
825 ? int_lnno
.l_addr
.l_paddr
826 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
827 addr
+= ANOFFSET (this_symtab_psymtab
->objfile
->section_offsets
,
828 SECT_OFF_TEXT (this_symtab_psymtab
->objfile
));
830 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
833 if (int_lnno
.l_lnno
== 0)
835 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
836 record_line (subfile
, 0, addr
);
840 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
, addr
);
846 /* Save the vital information for use when closing off the current file.
847 NAME is the file name the symbols came from, START_ADDR is the first
848 text address for the file, and SIZE is the number of bytes of text. */
850 #define complete_symtab(name, start_addr) { \
851 last_source_file = savestring (name, strlen (name)); \
852 last_source_start_addr = start_addr; \
856 /* Refill the symbol table input buffer
857 and set the variables that control fetching entries from it.
858 Reports an error if no data available.
859 This function can read past the end of the symbol table
860 (into the string table) but this does no harm. */
862 /* Reading symbol table has to be fast! Keep the followings as macros, rather
865 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
869 if (namestr[0] == '.') ++namestr; \
870 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
871 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
872 misc_func_recorded = 1; \
876 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
877 nested. At any given time, a symbol can only be in one static block.
878 This is the base address of current static block, zero if non exists. */
880 static int static_block_base
= 0;
882 /* Section number for the current static block. */
884 static int static_block_section
= -1;
886 /* true if space for symbol name has been allocated. */
888 static int symname_alloced
= 0;
890 /* Next symbol to read. Pointer into raw seething symbol table. */
892 static char *raw_symbol
;
894 /* This is the function which stabsread.c calls to get symbol
898 xcoff_next_symbol_text (struct objfile
*objfile
)
900 struct internal_syment symbol
;
901 static struct complaint msg
=
902 {"Unexpected symbol continuation", 0, 0};
904 /* FIXME: is this the same as the passed arg? */
905 objfile
= this_symtab_psymtab
->objfile
;
907 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
912 /* Return something which points to '\0' and hope the symbol reading
913 code does something reasonable. */
916 else if (symbol
.n_sclass
& 0x80)
919 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
922 coff_data (objfile
->obfd
)->local_symesz
;
929 /* Return something which points to '\0' and hope the symbol reading
930 code does something reasonable. */
936 /* Read symbols for a given partial symbol table. */
939 read_xcoff_symtab (struct partial_symtab
*pst
)
941 struct objfile
*objfile
= pst
->objfile
;
942 bfd
*abfd
= objfile
->obfd
;
943 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
944 char *strtbl
= ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
;
946 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
;
947 char *debugfmt
= xcoff_data (abfd
)->xcoff64
? "XCOFF64" : "XCOFF";
949 struct internal_syment symbol
[1];
950 union internal_auxent main_aux
;
951 struct coff_symbol cs
[1];
952 CORE_ADDR file_start_addr
= 0;
953 CORE_ADDR file_end_addr
= 0;
955 int next_file_symnum
= -1;
956 unsigned int max_symnum
;
957 int just_started
= 1;
959 int fcn_start_addr
= 0;
961 struct coff_symbol fcn_stab_saved
;
963 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
964 union internal_auxent fcn_aux_saved
;
965 struct context_stack
*new;
967 char *filestring
= " _start_ "; /* Name of the current file. */
969 char *last_csect_name
; /* last seen csect's name and value */
970 CORE_ADDR last_csect_val
;
973 this_symtab_psymtab
= pst
;
975 /* Get the appropriate COFF "constants" related to the file we're
977 local_symesz
= coff_data (abfd
)->local_symesz
;
979 last_source_file
= NULL
;
984 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
985 record_debugformat (debugfmt
);
986 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
988 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
989 first_object_file_end
= 0;
992 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
993 + symnum
* local_symesz
;
995 while (symnum
< max_symnum
)
998 QUIT
; /* make this command interruptable. */
1000 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1001 /* read one symbol into `cs' structure. After processing the
1002 whole symbol table, only string table will be kept in memory,
1003 symbol table and debug section of xcoff will be freed. Thus
1004 we can mark symbols with names in string table as
1009 /* Swap and align the symbol into a reasonable C structure. */
1010 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1012 cs
->c_symnum
= symnum
;
1013 cs
->c_naux
= symbol
->n_numaux
;
1014 if (symbol
->n_zeroes
)
1016 symname_alloced
= 0;
1017 /* We must use the original, unswapped, name here so the name field
1018 pointed to by cs->c_name will persist throughout xcoffread. If
1019 we use the new field, it gets overwritten for each symbol. */
1020 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
1021 /* If it's exactly E_SYMNMLEN characters long it isn't
1023 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1026 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
1027 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1028 p
[E_SYMNMLEN
] = '\0';
1030 symname_alloced
= 1;
1033 else if (symbol
->n_sclass
& 0x80)
1035 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1036 symname_alloced
= 0;
1040 /* in string table */
1041 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1042 symname_alloced
= 1;
1044 cs
->c_value
= symbol
->n_value
;
1045 cs
->c_sclass
= symbol
->n_sclass
;
1046 cs
->c_secnum
= symbol
->n_scnum
;
1047 cs
->c_type
= (unsigned) symbol
->n_type
;
1049 raw_symbol
+= local_symesz
;
1052 /* Save addr of first aux entry. */
1053 raw_auxptr
= raw_symbol
;
1055 /* Skip all the auxents associated with this symbol. */
1056 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1058 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1063 /* if symbol name starts with ".$" or "$", ignore it. */
1064 if (cs
->c_name
[0] == '$'
1065 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1068 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1070 if (last_source_file
)
1073 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1078 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1079 record_debugformat (debugfmt
);
1080 cur_src_end_addr
= first_object_file_end
;
1081 /* done with all files, everything from here on is globals */
1084 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1087 /* Dealing with a symbol with a csect entry. */
1089 #define CSECT(PP) ((PP)->x_csect)
1090 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1091 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1092 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1093 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1095 /* Convert the auxent to something we can access. */
1096 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1097 0, cs
->c_naux
, &main_aux
);
1099 switch (CSECT_SMTYP (&main_aux
))
1103 /* Ignore all external references. */
1107 /* A section description. */
1109 switch (CSECT_SCLAS (&main_aux
))
1115 /* A program csect is seen. We have to allocate one
1116 symbol table for each program csect. Normally gdb
1117 prefers one symtab for each source file. In case
1118 of AIX, one source file might include more than one
1119 [PR] csect, and they don't have to be adjacent in
1120 terms of the space they occupy in memory. Thus, one
1121 single source file might get fragmented in the
1122 memory and gdb's file start and end address
1123 approach does not work! GCC (and I think xlc) seem
1124 to put all the code in the unnamed program csect. */
1126 if (last_csect_name
)
1128 complete_symtab (filestring
, file_start_addr
);
1129 cur_src_end_addr
= file_end_addr
;
1130 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1133 /* Give all csects for this source file the same
1135 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1136 record_debugformat (debugfmt
);
1139 /* If this is the very first csect seen,
1140 basically `__start'. */
1143 first_object_file_end
1144 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1149 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1150 SECT_OFF_TEXT (objfile
));
1151 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1153 if (cs
->c_name
&& (cs
->c_name
[0] == '.'
1154 || cs
->c_name
[0] == '@'))
1156 last_csect_name
= cs
->c_name
;
1157 last_csect_val
= cs
->c_value
;
1158 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1163 /* All other symbols are put into the minimal symbol
1176 /* Ignore the symbol. */
1184 switch (CSECT_SCLAS (&main_aux
))
1187 /* a function entry point. */
1188 function_entry_point
:
1190 fcn_start_addr
= cs
->c_value
;
1192 /* save the function header info, which will be used
1193 when `.bf' is seen. */
1195 fcn_aux_saved
= main_aux
;
1199 /* shared library function trampoline code entry point. */
1203 /* The symbols often have the same names as debug symbols for
1204 functions, and confuse lookup_symbol. */
1208 /* xlc puts each variable in a separate csect, so we get
1209 an XTY_SD for each variable. But gcc puts several
1210 variables in a csect, so that each variable only gets
1211 an XTY_LD. This will typically be XMC_RW; I suspect
1212 XMC_RO and XMC_BS might be possible too.
1213 These variables are put in the minimal symbol table
1220 /* Common symbols are put into the minimal symbol table only. */
1228 /* If explicitly specified as a function, treat is as one. This check
1229 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1230 after the above CSECT check. */
1231 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1233 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1234 0, cs
->c_naux
, &main_aux
);
1235 goto function_entry_point
;
1238 switch (cs
->c_sclass
)
1243 /* c_value field contains symnum of next .file entry in table
1244 or symnum of first global after last .file. */
1246 next_file_symnum
= cs
->c_value
;
1248 /* Complete symbol table for last object file containing
1249 debugging information. */
1251 /* Whether or not there was a csect in the previous file, we
1252 have to call `end_stabs' and `start_stabs' to reset
1253 type_vector, line_vector, etc. structures. */
1255 complete_symtab (filestring
, file_start_addr
);
1256 cur_src_end_addr
= file_end_addr
;
1257 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1260 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1261 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1262 standard COFF way and put it in the auxent. We use the auxent if
1263 the symbol is ".file" and an auxent exists, otherwise use the symbol
1264 itself. Simple enough. */
1265 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1267 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1268 0, cs
->c_naux
, &main_aux
);
1269 filestring
= coff_getfilename (&main_aux
, objfile
);
1272 filestring
= cs
->c_name
;
1275 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1276 record_debugformat (debugfmt
);
1277 last_csect_name
= 0;
1279 /* reset file start and end addresses. A compilation unit with no text
1280 (only data) should have zero file boundaries. */
1281 file_start_addr
= file_end_addr
= 0;
1285 fcn_stab_saved
= *cs
;
1289 if (STREQ (cs
->c_name
, ".bf"))
1291 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1292 SECT_OFF_TEXT (objfile
));
1293 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1294 0, cs
->c_naux
, &main_aux
);
1296 within_function
= 1;
1298 new = push_context (0, fcn_start_addr
+ off
);
1300 new->name
= define_symbol
1301 (fcn_cs_saved
.c_value
+ off
,
1302 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1303 if (new->name
!= NULL
)
1304 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1306 else if (STREQ (cs
->c_name
, ".ef"))
1309 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1310 0, cs
->c_naux
, &main_aux
);
1312 /* The value of .ef is the address of epilogue code;
1313 not useful for gdb. */
1314 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1315 contains number of lines to '}' */
1317 if (context_stack_depth
<= 0)
1318 { /* We attempted to pop an empty context stack */
1319 complain (&ef_complaint
, cs
->c_symnum
);
1320 within_function
= 0;
1323 new = pop_context ();
1324 /* Stack must be empty now. */
1325 if (context_stack_depth
> 0 || new == NULL
)
1327 complain (&ef_complaint
, cs
->c_symnum
);
1328 within_function
= 0;
1332 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1334 (fcn_cs_saved
.c_value
1335 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1336 + ANOFFSET (objfile
->section_offsets
,
1337 SECT_OFF_TEXT (objfile
))),
1339 within_function
= 0;
1344 /* Begin static block. */
1346 struct internal_syment symbol
;
1348 read_symbol (&symbol
, cs
->c_value
);
1349 static_block_base
= symbol
.n_value
;
1350 static_block_section
=
1351 secnum_to_section (symbol
.n_scnum
, objfile
);
1356 /* End of static block. */
1357 static_block_base
= 0;
1358 static_block_section
= -1;
1369 static struct complaint msg
=
1370 {"Unrecognized storage class %d.", 0, 0};
1371 complain (&msg
, cs
->c_sclass
);
1385 /* beginning of include file */
1386 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1387 order. Thus, when wee see them, we might not know enough info
1388 to process them. Thus, we'll be saving them into a table
1389 (inclTable) and postpone their processing. */
1391 record_include_begin (cs
);
1395 /* End of include file. */
1396 /* See the comment after case C_BINCL. */
1397 record_include_end (cs
);
1401 if (STREQ (cs
->c_name
, ".bb"))
1404 new = push_context (depth
,
1406 + ANOFFSET (objfile
->section_offsets
,
1407 SECT_OFF_TEXT (objfile
))));
1409 else if (STREQ (cs
->c_name
, ".eb"))
1411 if (context_stack_depth
<= 0)
1412 { /* We attempted to pop an empty context stack */
1413 complain (&eb_complaint
, cs
->c_symnum
);
1416 new = pop_context ();
1417 if (depth
-- != new->depth
)
1419 complain (&eb_complaint
, cs
->c_symnum
);
1422 if (local_symbols
&& context_stack_depth
> 0)
1424 /* Make a block for the local symbols within. */
1425 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1428 + ANOFFSET (objfile
->section_offsets
,
1429 SECT_OFF_TEXT (objfile
))),
1432 local_symbols
= new->locals
;
1437 process_xcoff_symbol (cs
, objfile
);
1442 if (last_source_file
)
1446 complete_symtab (filestring
, file_start_addr
);
1447 cur_src_end_addr
= file_end_addr
;
1448 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1449 /* When reading symbols for the last C_FILE of the objfile, try
1450 to make sure that we set pst->symtab to the symtab for the
1451 file, not to the _globals_ symtab. I'm not sure whether this
1452 actually works right or when/if it comes up. */
1453 if (pst
->symtab
== NULL
)
1459 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1460 (SYMBOL2) = (struct symbol *) \
1461 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1462 *(SYMBOL2) = *(SYMBOL1);
1465 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1466 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1469 static struct type
*func_symbol_type
;
1470 static struct type
*var_symbol_type
;
1472 /* process one xcoff symbol. */
1474 static struct symbol
*
1475 process_xcoff_symbol (register struct coff_symbol
*cs
, struct objfile
*objfile
)
1477 struct symbol onesymbol
;
1478 register struct symbol
*sym
= &onesymbol
;
1479 struct symbol
*sym2
= NULL
;
1485 if (cs
->c_secnum
< 0)
1487 /* The value is a register number, offset within a frame, etc.,
1488 and does not get relocated. */
1494 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1495 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1502 memset (sym
, '\0', sizeof (struct symbol
));
1504 /* default assumptions */
1505 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1506 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1507 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1509 if (ISFCN (cs
->c_type
))
1511 /* At this point, we don't know the type of the function. This
1512 will be patched with the type from its stab entry later on in
1513 patch_block_stabs (), unless the file was compiled without -g. */
1515 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1516 SYMBOL_TYPE (sym
) = func_symbol_type
;
1518 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1519 SYMBOL_DUP (sym
, sym2
);
1521 if (cs
->c_sclass
== C_EXT
)
1522 add_symbol_to_list (sym2
, &global_symbols
);
1523 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1524 add_symbol_to_list (sym2
, &file_symbols
);
1528 /* In case we can't figure out the type, provide default. */
1529 SYMBOL_TYPE (sym
) = var_symbol_type
;
1531 switch (cs
->c_sclass
)
1534 /* The values of functions and global symbols are now resolved
1535 via the global_sym_chain in stabsread.c. */
1537 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1538 add_stab_to_list (name
, &global_stabs
);
1540 add_stab_to_list (name
, &file_stabs
);
1544 add_stab_to_list (name
, &global_stabs
);
1549 common_block_start (cs
->c_name
, objfile
);
1553 common_block_end (objfile
);
1557 complain (&storclass_complaint
, cs
->c_sclass
);
1569 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1572 SYMBOL_SECTION (sym
) = sec
;
1579 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1580 all statics and we need to distinguish file-scope versus
1581 function-scope using within_function. We do this by
1582 changing the string we pass to define_symbol to use 'S'
1583 where we need to, which is not necessarily super-clean,
1584 but seems workable enough. */
1586 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1590 if (*pp
== 'V' && !within_function
)
1592 sym
= define_symbol ((cs
->c_value
1593 + ANOFFSET (objfile
->section_offsets
,
1594 static_block_section
)),
1595 cs
->c_name
, 0, 0, objfile
);
1598 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1599 SYMBOL_SECTION (sym
) = static_block_section
;
1608 /* Extract the file name from the aux entry of a C_FILE symbol.
1609 Result is in static storage and is only good for temporary use. */
1612 coff_getfilename (union internal_auxent
*aux_entry
, struct objfile
*objfile
)
1614 static char buffer
[BUFSIZ
];
1616 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1618 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
1619 + aux_entry
->x_file
.x_n
.x_offset
);
1622 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1623 buffer
[FILNMLEN
] = '\0';
1628 /* Set *SYMBOL to symbol number symno in symtbl. */
1630 read_symbol (struct internal_syment
*symbol
, int symno
)
1633 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
1636 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
1638 if (symno
< 0 || symno
>= nsyms
)
1640 static struct complaint msg
=
1641 {"Invalid symbol offset", 0, 0};
1643 symbol
->n_value
= 0;
1644 symbol
->n_scnum
= -1;
1647 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1648 stbl
+ (symno
* local_symesz
),
1652 /* Get value corresponding to symbol number symno in symtbl. */
1655 read_symbol_nvalue (int symno
)
1657 struct internal_syment symbol
[1];
1659 read_symbol (symbol
, symno
);
1660 return symbol
->n_value
;
1664 /* Find the address of the function corresponding to symno, where
1665 symno is the symbol pointed to by the linetable. */
1668 read_symbol_lineno (int symno
)
1670 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1671 boolean xcoff64
= xcoff_data (objfile
->obfd
)->xcoff64
;
1673 struct coff_symfile_info
*info
=
1674 (struct coff_symfile_info
*)objfile
->sym_private
;
1675 int nsyms
= info
->symtbl_num_syms
;
1676 char *stbl
= info
->symtbl
;
1677 char *strtbl
= info
->strtbl
;
1679 struct internal_syment symbol
[1];
1680 union internal_auxent main_aux
[1];
1684 complain (&bf_notfound_complaint
);
1688 /* Note that just searching for a short distance (e.g. 50 symbols)
1689 is not enough, at least in the following case.
1692 [many .stabx entries]
1693 [a few functions, referring to foo]
1697 What happens here is that the assembler moves the .stabx entries
1698 to right before the ".bf" for foo, but the symbol for "foo" is before
1699 all the stabx entries. See PR gdb/2222. */
1701 /* Maintaining a table of .bf entries might be preferable to this search.
1702 If I understand things correctly it would need to be done only for
1703 the duration of a single psymtab to symtab conversion. */
1704 while (symno
< nsyms
)
1706 bfd_coff_swap_sym_in (symfile_bfd
,
1707 stbl
+ (symno
* local_symesz
), symbol
);
1708 if (symbol
->n_sclass
== C_FCN
)
1710 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1711 if (STREQ (name
, ".bf"))
1714 symno
+= symbol
->n_numaux
+ 1;
1717 complain (&bf_notfound_complaint
);
1721 /* take aux entry and return its lineno */
1723 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1724 symbol
->n_type
, symbol
->n_sclass
,
1725 0, symbol
->n_numaux
, main_aux
);
1727 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1730 /* Support for line number handling */
1732 /* This function is called for every section; it finds the outer limits
1733 * of the line table (minimum and maximum file offset) so that the
1734 * mainline code can read the whole thing for efficiency.
1737 find_linenos (bfd
*abfd
, sec_ptr asect
, PTR vpinfo
)
1739 struct coff_symfile_info
*info
;
1741 file_ptr offset
, maxoff
;
1743 count
= asect
->lineno_count
;
1745 if (!STREQ (asect
->name
, ".text") || count
== 0)
1748 size
= count
* coff_data (abfd
)->local_linesz
;
1749 info
= (struct coff_symfile_info
*) vpinfo
;
1750 offset
= asect
->line_filepos
;
1751 maxoff
= offset
+ size
;
1753 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1754 info
->min_lineno_offset
= offset
;
1756 if (maxoff
> info
->max_lineno_offset
)
1757 info
->max_lineno_offset
= maxoff
;
1760 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1763 xcoff_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1765 struct cleanup
*old_chain
;
1774 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1779 /* Read in all partial symtabs on which this one is dependent */
1780 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1781 if (!pst
->dependencies
[i
]->readin
)
1783 /* Inform about additional files that need to be read in. */
1786 fputs_filtered (" ", gdb_stdout
);
1788 fputs_filtered ("and ", gdb_stdout
);
1790 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1791 wrap_here (""); /* Flush output */
1792 gdb_flush (gdb_stdout
);
1794 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1797 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1799 /* Init stuff necessary for reading in symbols. */
1802 old_chain
= make_cleanup (really_free_pendings
, 0);
1804 read_xcoff_symtab (pst
);
1805 sort_symtab_syms (pst
->symtab
);
1807 do_cleanups (old_chain
);
1813 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1815 /* Read in all of the symbols for a given psymtab for real.
1816 Be verbose about it if the user wants that. */
1819 xcoff_psymtab_to_symtab (struct partial_symtab
*pst
)
1829 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1834 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1835 || pst
->number_of_dependencies
)
1837 /* Print the message now, before reading the string table,
1838 to avoid disconcerting pauses. */
1841 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1842 gdb_flush (gdb_stdout
);
1845 sym_bfd
= pst
->objfile
->obfd
;
1847 next_symbol_text_func
= xcoff_next_symbol_text
;
1849 xcoff_psymtab_to_symtab_1 (pst
);
1851 /* Match with global symbols. This only needs to be done once,
1852 after all of the symtabs and dependencies have been read in. */
1853 scan_file_globals (pst
->objfile
);
1855 /* Finish up the debug error message. */
1857 printf_filtered ("done.\n");
1862 xcoff_new_init (struct objfile
*objfile
)
1864 stabsread_new_init ();
1865 buildsym_new_init ();
1868 /* Do initialization in preparation for reading symbols from OBJFILE.
1870 We will only be called if this is an XCOFF or XCOFF-like file.
1871 BFD handles figuring out the format of the file, and code in symfile.c
1872 uses BFD's determination to vector to us. */
1875 xcoff_symfile_init (struct objfile
*objfile
)
1877 /* Allocate struct to keep track of the symfile */
1878 objfile
->sym_private
= xmmalloc (objfile
->md
,
1879 sizeof (struct coff_symfile_info
));
1881 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1882 find this causes a significant slowdown in gdb then we could
1883 set it in the debug symbol readers only when necessary. */
1884 objfile
->flags
|= OBJF_REORDERED
;
1886 init_entry_point_info (objfile
);
1889 /* Perform any local cleanups required when we are done with a particular
1890 objfile. I.E, we are in the process of discarding all symbol information
1891 for an objfile, freeing up all memory held for it, and unlinking the
1892 objfile struct from the global list of known objfiles. */
1895 xcoff_symfile_finish (struct objfile
*objfile
)
1897 if (objfile
->sym_private
!= NULL
)
1899 mfree (objfile
->md
, objfile
->sym_private
);
1902 /* Start with a fresh include table for the next objfile. */
1908 inclIndx
= inclLength
= inclDepth
= 0;
1913 init_stringtab (bfd
*abfd
, file_ptr offset
, struct objfile
*objfile
)
1917 unsigned char lengthbuf
[4];
1920 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
= NULL
;
1922 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1923 error ("cannot seek to string table in %s: %s",
1924 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1926 val
= bfd_read ((char *) lengthbuf
, 1, sizeof lengthbuf
, abfd
);
1927 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1929 /* If no string table is needed, then the file may end immediately
1930 after the symbols. Just return with `strtbl' set to NULL. */
1932 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1935 /* Allocate string table from symbol_obstack. We will need this table
1936 as long as we have its symbol table around. */
1938 strtbl
= (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
1939 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
= strtbl
;
1941 /* Copy length buffer, the first byte is usually zero and is
1942 used for stabs with a name length of zero. */
1943 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1944 if (length
== sizeof lengthbuf
)
1947 val
= bfd_read (strtbl
+ sizeof lengthbuf
, 1, length
- sizeof lengthbuf
,
1950 if (val
!= length
- sizeof lengthbuf
)
1951 error ("cannot read string table from %s: %s",
1952 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1953 if (strtbl
[length
- 1] != '\0')
1954 error ("bad symbol file: string table does not end with null character");
1959 /* If we have not yet seen a function for this psymtab, this is 0. If we
1960 have seen one, it is the offset in the line numbers of the line numbers
1962 static unsigned int first_fun_line_offset
;
1964 static struct partial_symtab
*xcoff_start_psymtab
1965 (struct objfile
*, char *, int,
1966 struct partial_symbol
**, struct partial_symbol
**);
1968 /* Allocate and partially fill a partial symtab. It will be
1969 completely filled at the end of the symbol list.
1971 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1972 is the address relative to which its symbols are (incremental) or 0
1975 static struct partial_symtab
*
1976 xcoff_start_psymtab (struct objfile
*objfile
, char *filename
, int first_symnum
,
1977 struct partial_symbol
**global_syms
,
1978 struct partial_symbol
**static_syms
)
1980 struct partial_symtab
*result
=
1981 start_psymtab_common (objfile
, objfile
->section_offsets
,
1983 /* We fill in textlow later. */
1985 global_syms
, static_syms
);
1987 result
->read_symtab_private
= (char *)
1988 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1989 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
1990 result
->read_symtab
= xcoff_psymtab_to_symtab
;
1992 /* Deduce the source language from the filename for this psymtab. */
1993 psymtab_language
= deduce_language_from_filename (filename
);
1998 static struct partial_symtab
*xcoff_end_psymtab
1999 (struct partial_symtab
*, char **, int, int,
2000 struct partial_symtab
**, int, int);
2002 /* Close off the current usage of PST.
2003 Returns PST, or NULL if the partial symtab was empty and thrown away.
2005 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2007 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2008 are the information for includes and dependencies. */
2010 static struct partial_symtab
*
2011 xcoff_end_psymtab (struct partial_symtab
*pst
, char **include_list
,
2012 int num_includes
, int capping_symbol_number
,
2013 struct partial_symtab
**dependency_list
,
2014 int number_dependencies
, int textlow_not_set
)
2017 struct objfile
*objfile
= pst
->objfile
;
2019 if (capping_symbol_number
!= -1)
2020 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
2021 capping_symbol_number
2022 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
2023 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
2024 first_fun_line_offset
;
2025 first_fun_line_offset
= 0;
2026 pst
->n_global_syms
=
2027 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2028 pst
->n_static_syms
=
2029 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2031 pst
->number_of_dependencies
= number_dependencies
;
2032 if (number_dependencies
)
2034 pst
->dependencies
= (struct partial_symtab
**)
2035 obstack_alloc (&objfile
->psymbol_obstack
,
2036 number_dependencies
* sizeof (struct partial_symtab
*));
2037 memcpy (pst
->dependencies
, dependency_list
,
2038 number_dependencies
* sizeof (struct partial_symtab
*));
2041 pst
->dependencies
= 0;
2043 for (i
= 0; i
< num_includes
; i
++)
2045 struct partial_symtab
*subpst
=
2046 allocate_psymtab (include_list
[i
], objfile
);
2048 subpst
->section_offsets
= pst
->section_offsets
;
2049 subpst
->read_symtab_private
=
2050 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
2051 sizeof (struct symloc
));
2052 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2053 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2054 subpst
->textlow
= 0;
2055 subpst
->texthigh
= 0;
2057 /* We could save slight bits of space by only making one of these,
2058 shared by the entire set of include files. FIXME-someday. */
2059 subpst
->dependencies
= (struct partial_symtab
**)
2060 obstack_alloc (&objfile
->psymbol_obstack
,
2061 sizeof (struct partial_symtab
*));
2062 subpst
->dependencies
[0] = pst
;
2063 subpst
->number_of_dependencies
= 1;
2065 subpst
->globals_offset
=
2066 subpst
->n_global_syms
=
2067 subpst
->statics_offset
=
2068 subpst
->n_static_syms
= 0;
2072 subpst
->read_symtab
= pst
->read_symtab
;
2075 sort_pst_symbols (pst
);
2077 /* If there is already a psymtab or symtab for a file of this name,
2078 remove it. (If there is a symtab, more drastic things also
2079 happen.) This happens in VxWorks. */
2080 free_named_symtabs (pst
->filename
);
2082 if (num_includes
== 0
2083 && number_dependencies
== 0
2084 && pst
->n_global_syms
== 0
2085 && pst
->n_static_syms
== 0)
2087 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2088 it is on the obstack, but we can forget to chain it on the list. */
2089 /* Empty psymtabs happen as a result of header files which don't have
2090 any symbols in them. There can be a lot of them. */
2092 discard_psymtab (pst
);
2094 /* Indicate that psymtab was thrown away. */
2095 pst
= (struct partial_symtab
*) NULL
;
2100 static void swap_sym (struct internal_syment
*,
2101 union internal_auxent
*, char **, char **,
2102 unsigned int *, struct objfile
*);
2104 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2105 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2106 the symbol and its auxents. */
2109 swap_sym (struct internal_syment
*symbol
, union internal_auxent
*aux
,
2110 char **name
, char **raw
, unsigned int *symnump
,
2111 struct objfile
*objfile
)
2113 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2114 if (symbol
->n_zeroes
)
2116 /* If it's exactly E_SYMNMLEN characters long it isn't
2118 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2120 /* FIXME: wastes memory for symbols which we don't end up putting
2121 into the minimal symbols. */
2123 p
= obstack_alloc (&objfile
->psymbol_obstack
, E_SYMNMLEN
+ 1);
2124 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2125 p
[E_SYMNMLEN
] = '\0';
2129 /* Point to the unswapped name as that persists as long as the
2131 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2133 else if (symbol
->n_sclass
& 0x80)
2135 *name
= ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
2140 *name
= ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
2144 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2145 if (symbol
->n_numaux
> 0)
2147 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2148 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2150 *symnump
+= symbol
->n_numaux
;
2151 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2156 scan_xcoff_symtab (struct objfile
*objfile
)
2158 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2159 char *filestring
= NULL
;
2162 int past_first_source_file
= 0;
2167 /* Current partial symtab */
2168 struct partial_symtab
*pst
;
2170 /* List of current psymtab's include files */
2171 char **psymtab_include_list
;
2172 int includes_allocated
;
2175 /* Index within current psymtab dependency list */
2176 struct partial_symtab
**dependency_list
;
2177 int dependencies_used
, dependencies_allocated
;
2180 struct internal_syment symbol
;
2181 union internal_auxent main_aux
[5];
2182 unsigned int ssymnum
;
2184 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2185 CORE_ADDR last_csect_val
= 0;
2186 int last_csect_sec
= 0;
2187 int misc_func_recorded
= 0; /* true if any misc. function */
2188 int textlow_not_set
= 1;
2190 pst
= (struct partial_symtab
*) 0;
2192 includes_allocated
= 30;
2194 psymtab_include_list
= (char **) alloca (includes_allocated
*
2197 dependencies_allocated
= 30;
2198 dependencies_used
= 0;
2200 (struct partial_symtab
**) alloca (dependencies_allocated
*
2201 sizeof (struct partial_symtab
*));
2203 last_source_file
= NULL
;
2205 abfd
= objfile
->obfd
;
2207 sraw_symbol
= ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
;
2208 nsyms
= ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl_num_syms
;
2210 while (ssymnum
< nsyms
)
2213 /* This is the type we pass to partial-stab.h. A less kludgy solution
2214 would be to break out partial-stab.h into its various parts--shuffle
2215 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2216 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2221 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2222 sclass
= symbol
.n_sclass
;
2229 /* The CSECT auxent--always the last auxent. */
2230 union internal_auxent csect_aux
;
2231 unsigned int symnum_before
= ssymnum
;
2233 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2235 if (symbol
.n_numaux
> 1)
2237 bfd_coff_swap_aux_in
2239 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2242 symbol
.n_numaux
- 1,
2247 csect_aux
= main_aux
[0];
2249 /* If symbol name starts with ".$" or "$", ignore it. */
2250 if (namestring
[0] == '$'
2251 || (namestring
[0] == '.' && namestring
[1] == '$'))
2254 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2257 switch (csect_aux
.x_csect
.x_smclas
)
2260 if (last_csect_name
)
2262 /* If no misc. function recorded in the last
2263 seen csect, enter it as a function. This
2264 will take care of functions like strcmp()
2267 if (!misc_func_recorded
)
2269 RECORD_MINIMAL_SYMBOL
2270 (last_csect_name
, last_csect_val
,
2271 mst_text
, last_csect_sec
,
2277 /* We have to allocate one psymtab for
2278 each program csect, because their text
2279 sections need not be adjacent. */
2281 (pst
, psymtab_include_list
, includes_used
,
2282 symnum_before
, dependency_list
,
2283 dependencies_used
, textlow_not_set
);
2285 dependencies_used
= 0;
2286 /* Give all psymtabs for this source file the same
2288 pst
= xcoff_start_psymtab
2292 objfile
->global_psymbols
.next
,
2293 objfile
->static_psymbols
.next
);
2296 /* Activate the misc_func_recorded mechanism for
2297 compiler- and linker-generated CSECTs like ".strcmp"
2299 if (namestring
&& (namestring
[0] == '.'
2300 || namestring
[0] == '@'))
2302 last_csect_name
= namestring
;
2303 last_csect_val
= symbol
.n_value
;
2305 secnum_to_section (symbol
.n_scnum
, objfile
);
2310 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2311 if (highval
> pst
->texthigh
)
2312 pst
->texthigh
= highval
;
2313 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2314 pst
->textlow
= symbol
.n_value
;
2316 misc_func_recorded
= 0;
2320 /* Data variables are recorded in the minimal symbol
2321 table, except for section symbols. */
2322 if (*namestring
!= '.')
2323 prim_record_minimal_symbol_and_info
2324 (namestring
, symbol
.n_value
,
2325 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2326 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2332 warning ("More than one XMC_TC0 symbol found.");
2333 toc_offset
= symbol
.n_value
;
2335 /* Make TOC offset relative to start address of section. */
2336 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2338 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2342 /* These symbols tell us where the TOC entry for a
2343 variable is, not the variable itself. */
2352 switch (csect_aux
.x_csect
.x_smclas
)
2355 /* A function entry point. */
2357 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2358 first_fun_line_offset
=
2359 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2360 RECORD_MINIMAL_SYMBOL
2361 (namestring
, symbol
.n_value
,
2362 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2363 secnum_to_section (symbol
.n_scnum
, objfile
),
2368 /* shared library function trampoline code entry
2371 /* record trampoline code entries as
2372 mst_solib_trampoline symbol. When we lookup mst
2373 symbols, we will choose mst_text over
2374 mst_solib_trampoline. */
2375 RECORD_MINIMAL_SYMBOL
2376 (namestring
, symbol
.n_value
,
2377 mst_solib_trampoline
,
2378 secnum_to_section (symbol
.n_scnum
, objfile
),
2383 /* The symbols often have the same names as
2384 debug symbols for functions, and confuse
2390 /* xlc puts each variable in a separate csect,
2391 so we get an XTY_SD for each variable. But
2392 gcc puts several variables in a csect, so
2393 that each variable only gets an XTY_LD. We
2394 still need to record them. This will
2395 typically be XMC_RW; I suspect XMC_RO and
2396 XMC_BS might be possible too. */
2397 if (*namestring
!= '.')
2398 prim_record_minimal_symbol_and_info
2399 (namestring
, symbol
.n_value
,
2400 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2401 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2408 switch (csect_aux
.x_csect
.x_smclas
)
2412 /* Common variables are recorded in the minimal symbol
2413 table, except for section symbols. */
2414 if (*namestring
!= '.')
2415 prim_record_minimal_symbol_and_info
2416 (namestring
, symbol
.n_value
,
2417 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2418 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2431 unsigned int symnum_before
;
2433 symnum_before
= ssymnum
;
2434 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2437 /* See if the last csect needs to be recorded. */
2439 if (last_csect_name
&& !misc_func_recorded
)
2442 /* If no misc. function recorded in the last seen csect, enter
2443 it as a function. This will take care of functions like
2444 strcmp() compiled by xlc. */
2446 RECORD_MINIMAL_SYMBOL
2447 (last_csect_name
, last_csect_val
,
2448 mst_text
, last_csect_sec
, objfile
);
2453 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2454 symnum_before
, dependency_list
,
2455 dependencies_used
, textlow_not_set
);
2457 dependencies_used
= 0;
2459 first_fun_line_offset
= 0;
2461 /* XCOFF, according to the AIX 3.2 documentation, puts the
2462 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2463 do things the standard COFF way and put it in the auxent.
2464 We use the auxent if the symbol is ".file" and an auxent
2465 exists, otherwise use the symbol itself. */
2466 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2468 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2471 filestring
= namestring
;
2473 pst
= xcoff_start_psymtab (objfile
,
2476 objfile
->global_psymbols
.next
,
2477 objfile
->static_psymbols
.next
);
2478 last_csect_name
= NULL
;
2484 static struct complaint msg
=
2485 {"Storage class %d not recognized during scan", 0, 0};
2486 complain (&msg
, sclass
);
2490 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2491 to handle only the C_FUN and C_EXT. */
2506 /* C_EINCL means we are switching back to the main file. But there
2507 is no reason to care; the only thing we want to know about
2508 includes is the names of all the included (.h) files. */
2513 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2517 /* I don't think the name of the common block (as opposed to the
2518 variables within it) is something which is user visible
2526 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2527 so C_LSYM would appear to be only for locals. */
2533 /* We probably could save a few instructions by assuming that
2534 C_LSYM, C_PSYM, etc., never have auxents. */
2535 int naux1
= symbol
.n_numaux
+ 1;
2537 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2546 /* The value of the C_FUN is not the address of the function (it
2547 appears to be the address before linking), but as long as it
2548 is smaller than the actual address, then find_pc_partial_function
2549 will use the minimal symbols instead. I hope. */
2557 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2559 #define CUR_SYMBOL_TYPE stype
2560 #define CUR_SYMBOL_VALUE symbol.n_value
2562 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2563 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2565 #define START_PSYMTAB(ofile,fname,low,symoff,global_syms,static_syms) 0
2566 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
2568 /* We have already set the namestring. */
2569 #define SET_NAMESTRING() /* */
2571 #include "partial-stab.h"
2577 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2578 ssymnum
, dependency_list
,
2579 dependencies_used
, textlow_not_set
);
2582 /* Record the toc offset value of this symbol table into objfile structure.
2583 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2584 this information would be file auxiliary header. */
2586 ((struct coff_symfile_info
*) objfile
->sym_private
)->toc_offset
= toc_offset
;
2589 /* Return the toc offset value for a given objfile. */
2592 get_toc_offset (struct objfile
*objfile
)
2595 return ((struct coff_symfile_info
*) objfile
->sym_private
)->toc_offset
;
2599 /* Scan and build partial symbols for a symbol file.
2600 We have been initialized by a call to dbx_symfile_init, which
2601 put all the relevant info into a "struct dbx_symfile_info",
2602 hung off the objfile structure.
2604 SECTION_OFFSETS contains offsets relative to which the symbols in the
2605 various sections are (depending where the sections were actually loaded).
2606 MAINLINE is true if we are reading the main symbol
2607 table (as opposed to a shared lib or dynamically loaded file). */
2610 xcoff_initial_scan (struct objfile
*objfile
, int mainline
)
2614 struct cleanup
*back_to
;
2615 int num_symbols
; /* # of symbols */
2616 file_ptr symtab_offset
; /* symbol table and */
2617 file_ptr stringtab_offset
; /* string table file offsets */
2618 struct coff_symfile_info
*info
;
2622 info
= (struct coff_symfile_info
*) objfile
->sym_private
;
2623 symfile_bfd
= abfd
= objfile
->obfd
;
2624 name
= objfile
->name
;
2626 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2627 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2628 stringtab_offset
= symtab_offset
+
2629 num_symbols
* coff_data (abfd
)->local_symesz
;
2631 info
->min_lineno_offset
= 0;
2632 info
->max_lineno_offset
= 0;
2633 bfd_map_over_sections (abfd
, find_linenos
, info
);
2635 if (num_symbols
> 0)
2637 /* Read the string table. */
2638 init_stringtab (abfd
, stringtab_offset
, objfile
);
2640 /* Read the .debug section, if present. */
2643 bfd_size_type length
;
2644 char *debugsec
= NULL
;
2646 secp
= bfd_get_section_by_name (abfd
, ".debug");
2649 length
= bfd_section_size (abfd
, secp
);
2653 (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
2655 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2656 (file_ptr
) 0, length
))
2658 error ("Error reading .debug section of `%s': %s",
2659 name
, bfd_errmsg (bfd_get_error ()));
2663 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
=
2668 /* Read the symbols. We keep them in core because we will want to
2669 access them randomly in read_symbol*. */
2670 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2672 error ("Error reading symbols from %s: %s",
2673 name
, bfd_errmsg (bfd_get_error ()));
2674 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2675 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
=
2676 obstack_alloc (&objfile
->symbol_obstack
, size
);
2677 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl_num_syms
=
2680 val
= bfd_read (((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
,
2683 perror_with_name ("reading symbol table");
2685 /* If we are reinitializing, or if we have never loaded syms yet, init */
2687 || objfile
->global_psymbols
.size
== 0
2688 || objfile
->static_psymbols
.size
== 0)
2689 /* I'm not sure how how good num_symbols is; the rule of thumb in
2690 init_psymbol_list was developed for a.out. On the one hand,
2691 num_symbols includes auxents. On the other hand, it doesn't
2693 init_psymbol_list (objfile
, num_symbols
);
2695 free_pending_blocks ();
2696 back_to
= make_cleanup (really_free_pendings
, 0);
2698 init_minimal_symbol_collection ();
2699 make_cleanup_discard_minimal_symbols ();
2701 /* Now that the symbol table data of the executable file are all in core,
2702 process them and define symbols accordingly. */
2704 scan_xcoff_symtab (objfile
);
2706 /* Install any minimal symbols that have been collected as the current
2707 minimal symbols for this objfile. */
2709 install_minimal_symbols (objfile
);
2711 do_cleanups (back_to
);
2715 xcoff_symfile_offsets (struct objfile
*objfile
, struct section_addr_info
*addrs
)
2717 asection
*sect
= NULL
;
2720 objfile
->num_sections
= SECT_OFF_MAX
;
2721 objfile
->section_offsets
= (struct section_offsets
*)
2722 obstack_alloc (&objfile
->psymbol_obstack
, SIZEOF_SECTION_OFFSETS
);
2724 /* Initialize the section indexes for future use. */
2725 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
2727 objfile
->sect_index_text
= sect
->index
;
2729 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
2731 objfile
->sect_index_data
= sect
->index
;
2733 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
2735 objfile
->sect_index_bss
= sect
->index
;
2737 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
2739 objfile
->sect_index_rodata
= sect
->index
;
2741 for (i
= 0; i
< objfile
->num_sections
; ++i
)
2743 /* syms_from_objfile kindly subtracts from addr the
2744 bfd_section_vma of the .text section. This strikes me as
2745 wrong--whether the offset to be applied to symbol reading is
2746 relative to the start address of the section depends on the
2747 symbol format. In any event, this whole "addr" concept is
2748 pretty broken (it doesn't handle any section but .text
2749 sensibly), so just ignore the addr parameter and use 0.
2750 rs6000-nat.c will set the correct section offsets via
2751 objfile_relocate. */
2752 (objfile
->section_offsets
)->offsets
[i
] = 0;
2756 /* Register our ability to parse symbols for xcoff BFD files. */
2758 static struct sym_fns xcoff_sym_fns
=
2761 /* It is possible that coff and xcoff should be merged as
2762 they do have fundamental similarities (for example, the extra storage
2763 classes used for stabs could presumably be recognized in any COFF file).
2764 However, in addition to obvious things like all the csect hair, there are
2765 some subtler differences between xcoffread.c and coffread.c, notably
2766 the fact that coffread.c has no need to read in all the symbols, but
2767 xcoffread.c reads all the symbols and does in fact randomly access them
2768 (in C_BSTAT and line number processing). */
2770 bfd_target_xcoff_flavour
,
2772 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2773 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
2774 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
2775 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
2776 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
2777 NULL
/* next: pointer to next struct sym_fns */
2781 _initialize_xcoffread (void)
2783 add_symtab_fns (&xcoff_sym_fns
);
2785 func_symbol_type
= init_type (TYPE_CODE_FUNC
, 1, 0,
2786 "<function, no debug info>", NULL
);
2787 TYPE_TARGET_TYPE (func_symbol_type
) = builtin_type_int
;
2789 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
2790 "<variable, no debug info>", NULL
);