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, 2001, 2002, 2003
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/xcoff.h"
43 #include "coff/rs6000.h"
50 #include "stabsread.h"
51 #include "expression.h"
52 #include "complaints.h"
54 #include "gdb-stabs.h"
56 /* For interface with stabsread.c. */
57 #include "aout/stab_gnu.h"
60 /* We put a pointer to this structure in the read_symtab_private field
66 /* First symbol number for this file. */
70 /* Number of symbols in the section of the symbol table devoted to
71 this file's symbols (actually, the section bracketed may contain
72 more than just this file's symbols). If numsyms is 0, the only
73 reason for this thing's existence is the dependency list. Nothing
74 else will happen when it is read in. */
78 /* Position of the start of the line number information for this psymtab. */
79 unsigned int lineno_off
;
82 /* Remember what we deduced to be the source language of this psymtab. */
84 static enum language psymtab_language
= language_unknown
;
87 /* Simplified internal version of coff symbol table information */
92 int c_symnum
; /* symbol number of this entry */
93 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
95 unsigned char c_sclass
;
100 /* last function's saved coff symbol `cs' */
102 static struct coff_symbol fcn_cs_saved
;
104 static bfd
*symfile_bfd
;
106 /* Core address of start and end of text of current source file.
107 This is calculated from the first function seen after a C_FILE
111 static CORE_ADDR cur_src_end_addr
;
113 /* Core address of the end of the first object file. */
115 static CORE_ADDR first_object_file_end
;
117 /* initial symbol-table-debug-string vector length */
119 #define INITIAL_STABVECTOR_LENGTH 40
121 /* Nonzero if within a function (so symbols should be local,
122 if nothing says specifically). */
126 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
127 there is any reason not to just use a #define, but might as well
128 ask BFD for the size and store it here, I guess. */
130 static unsigned local_symesz
;
132 struct coff_symfile_info
134 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
135 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
137 /* Pointer to the string table. */
140 /* Pointer to debug section. */
143 /* Pointer to the a.out symbol table. */
146 /* Number of symbols in symtbl. */
149 /* Offset in data section to TOC anchor. */
150 CORE_ADDR toc_offset
;
154 bf_notfound_complaint (void)
156 complaint (&symfile_complaints
, "line numbers off, `.bf' symbol not found");
160 ef_complaint (int arg1
)
162 complaint (&symfile_complaints
,
163 "Mismatched .ef symbol ignored starting at symnum %d", arg1
);
167 eb_complaint (int arg1
)
169 complaint (&symfile_complaints
,
170 "Mismatched .eb symbol ignored starting at symnum %d", arg1
);
173 static void xcoff_initial_scan (struct objfile
*, int);
175 static void scan_xcoff_symtab (struct objfile
*);
177 static char *xcoff_next_symbol_text (struct objfile
*);
179 static void record_include_begin (struct coff_symbol
*);
182 enter_line_range (struct subfile
*, unsigned, unsigned,
183 CORE_ADDR
, CORE_ADDR
, unsigned *);
185 static void init_stringtab (bfd
*, file_ptr
, struct objfile
*);
187 static void xcoff_symfile_init (struct objfile
*);
189 static void xcoff_new_init (struct objfile
*);
191 static void xcoff_symfile_finish (struct objfile
*);
193 static void xcoff_symfile_offsets (struct objfile
*,
194 struct section_addr_info
*addrs
);
196 static void find_linenos (bfd
*, sec_ptr
, void *);
198 static char *coff_getfilename (union internal_auxent
*, struct objfile
*);
200 static void read_symbol (struct internal_syment
*, int);
202 static int read_symbol_lineno (int);
204 static CORE_ADDR
read_symbol_nvalue (int);
206 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
209 static void read_xcoff_symtab (struct partial_symtab
*);
212 static void add_stab_to_list (char *, struct pending_stabs
**);
215 static int compare_lte (const void *, const void *);
217 static struct linetable
*arrange_linetable (struct linetable
*);
219 static void record_include_end (struct coff_symbol
*);
221 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
224 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
226 static int secnum_to_section (int, struct objfile
*);
227 static asection
*secnum_to_bfd_section (int, struct objfile
*);
229 struct find_targ_sec_arg
234 struct objfile
*objfile
;
237 static void find_targ_sec (bfd
*, asection
*, void *);
240 find_targ_sec (bfd
*abfd
, asection
*sect
, void *obj
)
242 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
243 struct objfile
*objfile
= args
->objfile
;
244 if (sect
->target_index
== args
->targ_index
)
246 /* This is the section. Figure out what SECT_OFF_* code it is. */
247 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
248 *args
->resultp
= SECT_OFF_TEXT (objfile
);
249 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
250 *args
->resultp
= SECT_OFF_DATA (objfile
);
252 *args
->resultp
= sect
->index
;
253 *args
->bfd_sect
= sect
;
257 /* Return the section number (SECT_OFF_*) that CS points to. */
259 secnum_to_section (int secnum
, struct objfile
*objfile
)
261 int off
= SECT_OFF_TEXT (objfile
);
262 asection
*sect
= NULL
;
263 struct find_targ_sec_arg args
;
264 args
.targ_index
= secnum
;
266 args
.bfd_sect
= §
;
267 args
.objfile
= objfile
;
268 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
272 /* Return the BFD section that CS points to. */
274 secnum_to_bfd_section (int secnum
, struct objfile
*objfile
)
276 int off
= SECT_OFF_TEXT (objfile
);
277 asection
*sect
= NULL
;
278 struct find_targ_sec_arg args
;
279 args
.targ_index
= secnum
;
281 args
.bfd_sect
= §
;
282 args
.objfile
= objfile
;
283 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
287 /* add a given stab string into given stab vector. */
292 add_stab_to_list (char *stabname
, struct pending_stabs
**stabvector
)
294 if (*stabvector
== NULL
)
296 *stabvector
= (struct pending_stabs
*)
297 xmalloc (sizeof (struct pending_stabs
) +
298 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
299 (*stabvector
)->count
= 0;
300 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
302 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
;
314 /* Linenos are processed on a file-by-file basis.
318 1) xlc (IBM's native c compiler) postpones static function code
319 emission to the end of a compilation unit. This way it can
320 determine if those functions (statics) are needed or not, and
321 can do some garbage collection (I think). This makes line
322 numbers and corresponding addresses unordered, and we end up
323 with a line table like:
340 and that breaks gdb's binary search on line numbers, if the
341 above table is not sorted on line numbers. And that sort
342 should be on function based, since gcc can emit line numbers
345 10 0x100 - for the init/test part of a for stmt.
348 10 0x400 - for the increment part of a for stmt.
350 arrange_linetable() will do this sorting.
352 2) aix symbol table might look like:
354 c_file // beginning of a new file
355 .bi // beginning of include file
356 .ei // end of include file
360 basically, .bi/.ei pairs do not necessarily encapsulate
361 their scope. They need to be recorded, and processed later
362 on when we come the end of the compilation unit.
363 Include table (inclTable) and process_linenos() handle
369 /* compare line table entry addresses. */
372 compare_lte (const void *lte1p
, const void *lte2p
)
374 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
375 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
376 return lte1
->pc
- lte2
->pc
;
379 /* Given a line table with function entries are marked, arrange its functions
380 in ascending order and strip off function entry markers and return it in
381 a newly created table. If the old one is good enough, return the old one. */
382 /* FIXME: I think all this stuff can be replaced by just passing
383 sort_linevec = 1 to end_symtab. */
385 static struct linetable
*
386 arrange_linetable (struct linetable
*oldLineTb
)
388 int ii
, jj
, newline
, /* new line count */
389 function_count
; /* # of functions */
391 struct linetable_entry
*fentry
; /* function entry vector */
392 int fentry_size
; /* # of function entries */
393 struct linetable
*newLineTb
; /* new line table */
395 #define NUM_OF_FUNCTIONS 20
397 fentry_size
= NUM_OF_FUNCTIONS
;
398 fentry
= (struct linetable_entry
*)
399 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
401 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
404 if (oldLineTb
->item
[ii
].line
== 0)
405 { /* function entry found. */
407 if (function_count
>= fentry_size
)
408 { /* make sure you have room. */
410 fentry
= (struct linetable_entry
*)
411 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
413 fentry
[function_count
].line
= ii
;
414 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
419 if (function_count
== 0)
424 else if (function_count
> 1)
425 qsort (fentry
, function_count
, sizeof (struct linetable_entry
), compare_lte
);
427 /* allocate a new line table. */
428 newLineTb
= (struct linetable
*)
430 (sizeof (struct linetable
) +
431 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
433 /* if line table does not start with a function beginning, copy up until
437 if (oldLineTb
->item
[0].line
!= 0)
439 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
440 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
442 /* Now copy function lines one by one. */
444 for (ii
= 0; ii
< function_count
; ++ii
)
446 for (jj
= fentry
[ii
].line
+ 1;
447 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
449 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
452 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
456 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
457 following `IncludeChain'. At the end of each symtab (end_symtab),
458 we will determine if we should create additional symtab's to
459 represent if (the include files. */
462 typedef struct _inclTable
464 char *name
; /* include filename */
466 /* Offsets to the line table. end points to the last entry which is
467 part of this include file. */
470 struct subfile
*subfile
;
471 unsigned funStartLine
; /* start line # of its function */
475 #define INITIAL_INCLUDE_TABLE_LENGTH 20
476 static InclTable
*inclTable
; /* global include table */
477 static int inclIndx
; /* last entry to table */
478 static int inclLength
; /* table length */
479 static int inclDepth
; /* nested include depth */
481 static void allocate_include_entry (void);
484 record_include_begin (struct coff_symbol
*cs
)
488 /* In xcoff, we assume include files cannot be nested (not in .c files
489 of course, but in corresponding .s files.). */
491 /* This can happen with old versions of GCC.
492 GCC 2.3.3-930426 does not exhibit this on a test case which
493 a user said produced the message for him. */
494 complaint (&symfile_complaints
, "Nested C_BINCL symbols");
498 allocate_include_entry ();
500 inclTable
[inclIndx
].name
= cs
->c_name
;
501 inclTable
[inclIndx
].begin
= cs
->c_value
;
505 record_include_end (struct coff_symbol
*cs
)
511 complaint (&symfile_complaints
, "Mismatched C_BINCL/C_EINCL pair");
514 allocate_include_entry ();
516 pTbl
= &inclTable
[inclIndx
];
517 pTbl
->end
= cs
->c_value
;
524 allocate_include_entry (void)
526 if (inclTable
== NULL
)
528 inclTable
= (InclTable
*)
529 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
531 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
532 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
535 else if (inclIndx
>= inclLength
)
537 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
538 inclTable
= (InclTable
*)
539 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
540 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
541 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
545 /* Global variable to pass the psymtab down to all the routines involved
546 in psymtab to symtab processing. */
547 static struct partial_symtab
*this_symtab_psymtab
;
549 /* given the start and end addresses of a compilation unit (or a csect,
550 at times) process its lines and create appropriate line vectors. */
553 process_linenos (CORE_ADDR start
, CORE_ADDR end
)
556 file_ptr max_offset
=
557 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
560 /* subfile structure for the main compilation unit. */
561 struct subfile main_subfile
;
563 /* In the main source file, any time we see a function entry, we
564 reset this variable to function's absolute starting line number.
565 All the following line numbers in the function are relative to
566 this, and we record absolute line numbers in record_line(). */
568 unsigned int main_source_baseline
= 0;
573 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
575 goto return_after_cleanup
;
577 memset (&main_subfile
, '\0', sizeof (main_subfile
));
580 /* All source lines were in the main source file. None in include files. */
582 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
583 &main_source_baseline
);
587 /* There was source with line numbers in include files. */
590 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
591 main_source_baseline
= 0;
593 for (ii
= 0; ii
< inclIndx
; ++ii
)
595 struct subfile
*tmpSubfile
;
597 /* If there is main file source before include file, enter it. */
598 if (offset
< inclTable
[ii
].begin
)
601 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
602 start
, 0, &main_source_baseline
);
605 /* Have a new subfile for the include file. */
607 tmpSubfile
= inclTable
[ii
].subfile
=
608 (struct subfile
*) xmalloc (sizeof (struct subfile
));
610 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
611 firstLine
= &(inclTable
[ii
].funStartLine
);
613 /* Enter include file's lines now. */
614 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
615 inclTable
[ii
].end
, start
, 0, firstLine
);
617 if (offset
<= inclTable
[ii
].end
)
618 offset
= inclTable
[ii
].end
+ linesz
;
621 /* All the include files' line have been processed at this point. Now,
622 enter remaining lines of the main file, if any left. */
623 if (offset
< max_offset
+ 1 - linesz
)
625 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
626 &main_source_baseline
);
630 /* Process main file's line numbers. */
631 if (main_subfile
.line_vector
)
633 struct linetable
*lineTb
, *lv
;
635 lv
= main_subfile
.line_vector
;
637 /* Line numbers are not necessarily ordered. xlc compilation will
638 put static function to the end. */
640 lineTb
= arrange_linetable (lv
);
643 current_subfile
->line_vector
= (struct linetable
*)
644 xrealloc (lv
, (sizeof (struct linetable
)
645 + lv
->nitems
* sizeof (struct linetable_entry
)));
650 current_subfile
->line_vector
= lineTb
;
653 current_subfile
->line_vector_length
=
654 current_subfile
->line_vector
->nitems
;
657 /* Now, process included files' line numbers. */
659 for (ii
= 0; ii
< inclIndx
; ++ii
)
661 if ((inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
663 struct linetable
*lineTb
, *lv
;
665 lv
= (inclTable
[ii
].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
);
674 /* For the same include file, we might want to have more than one
675 subfile. This happens if we have something like:
683 while foo.h including code in it. (stupid but possible)
684 Since start_subfile() looks at the name and uses an
685 existing one if finds, we need to provide a fake name and
689 start_subfile (inclTable
[ii
].name
, (char *) 0);
692 /* Pick a fake name that will produce the same results as this
693 one when passed to deduce_language_from_filename. Kludge on
695 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
696 if (fakename
== NULL
)
698 start_subfile (fakename
, (char *) 0);
699 xfree (current_subfile
->name
);
701 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
706 current_subfile
->line_vector
=
707 (struct linetable
*) xrealloc
708 (lv
, (sizeof (struct linetable
)
709 + lv
->nitems
* sizeof (struct linetable_entry
)));
715 current_subfile
->line_vector
= lineTb
;
718 current_subfile
->line_vector_length
=
719 current_subfile
->line_vector
->nitems
;
720 start_subfile (pop_subfile (), (char *) 0);
724 return_after_cleanup
:
726 /* We don't want to keep alloc/free'ing the global include file table. */
729 /* Start with a fresh subfile structure for the next file. */
730 memset (&main_subfile
, '\0', sizeof (struct subfile
));
734 aix_process_linenos (void)
736 /* process line numbers and enter them into line vector */
737 process_linenos (last_source_start_addr
, cur_src_end_addr
);
741 /* Enter a given range of lines into the line vector.
742 can be called in the following two ways:
743 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
744 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
746 endoffset points to the last line table entry that we should pay
750 enter_line_range (struct subfile
*subfile
, unsigned beginoffset
, unsigned endoffset
, /* offsets to line table */
751 CORE_ADDR startaddr
, /* offsets to line table */
752 CORE_ADDR endaddr
, unsigned *firstLine
)
754 unsigned int curoffset
;
757 struct internal_lineno int_lnno
;
758 unsigned int limit_offset
;
762 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
764 curoffset
= beginoffset
;
766 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
771 if (endoffset
>= limit_offset
)
773 complaint (&symfile_complaints
,
774 "Bad line table offset in C_EINCL directive");
777 limit_offset
= endoffset
;
782 abfd
= this_symtab_psymtab
->objfile
->obfd
;
783 linesz
= coff_data (abfd
)->local_linesz
;
784 ext_lnno
= alloca (linesz
);
786 while (curoffset
<= limit_offset
)
788 bfd_seek (abfd
, curoffset
, SEEK_SET
);
789 bfd_bread (ext_lnno
, linesz
, abfd
);
790 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
792 /* Find the address this line represents. */
793 addr
= (int_lnno
.l_lnno
794 ? int_lnno
.l_addr
.l_paddr
795 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
796 addr
+= ANOFFSET (this_symtab_psymtab
->objfile
->section_offsets
,
797 SECT_OFF_TEXT (this_symtab_psymtab
->objfile
));
799 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
802 if (int_lnno
.l_lnno
== 0)
804 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
805 record_line (subfile
, 0, addr
);
809 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
, addr
);
815 /* Save the vital information for use when closing off the current file.
816 NAME is the file name the symbols came from, START_ADDR is the first
817 text address for the file, and SIZE is the number of bytes of text. */
819 #define complete_symtab(name, start_addr) { \
820 last_source_file = savestring (name, strlen (name)); \
821 last_source_start_addr = start_addr; \
825 /* Refill the symbol table input buffer
826 and set the variables that control fetching entries from it.
827 Reports an error if no data available.
828 This function can read past the end of the symbol table
829 (into the string table) but this does no harm. */
831 /* Reading symbol table has to be fast! Keep the followings as macros, rather
834 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
838 if (namestr[0] == '.') ++namestr; \
839 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
840 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
841 misc_func_recorded = 1; \
845 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
846 nested. At any given time, a symbol can only be in one static block.
847 This is the base address of current static block, zero if non exists. */
849 static int static_block_base
= 0;
851 /* Section number for the current static block. */
853 static int static_block_section
= -1;
855 /* true if space for symbol name has been allocated. */
857 static int symname_alloced
= 0;
859 /* Next symbol to read. Pointer into raw seething symbol table. */
861 static char *raw_symbol
;
863 /* This is the function which stabsread.c calls to get symbol
867 xcoff_next_symbol_text (struct objfile
*objfile
)
869 struct internal_syment symbol
;
871 /* FIXME: is this the same as the passed arg? */
872 objfile
= this_symtab_psymtab
->objfile
;
874 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
877 complaint (&symfile_complaints
, "Unexpected symbol continuation");
879 /* Return something which points to '\0' and hope the symbol reading
880 code does something reasonable. */
883 else if (symbol
.n_sclass
& 0x80)
886 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
889 coff_data (objfile
->obfd
)->local_symesz
;
894 complaint (&symfile_complaints
, "Unexpected symbol continuation");
896 /* Return something which points to '\0' and hope the symbol reading
897 code does something reasonable. */
903 /* Read symbols for a given partial symbol table. */
906 read_xcoff_symtab (struct partial_symtab
*pst
)
908 struct objfile
*objfile
= pst
->objfile
;
909 bfd
*abfd
= objfile
->obfd
;
910 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
911 char *strtbl
= ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
;
913 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
;
914 char *debugfmt
= bfd_xcoff_is_xcoff64 (abfd
) ? "XCOFF64" : "XCOFF";
916 struct internal_syment symbol
[1];
917 union internal_auxent main_aux
;
918 struct coff_symbol cs
[1];
919 CORE_ADDR file_start_addr
= 0;
920 CORE_ADDR file_end_addr
= 0;
922 int next_file_symnum
= -1;
923 unsigned int max_symnum
;
924 int just_started
= 1;
926 int fcn_start_addr
= 0;
928 struct coff_symbol fcn_stab_saved
;
930 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
931 union internal_auxent fcn_aux_saved
;
932 struct context_stack
*new;
934 char *filestring
= " _start_ "; /* Name of the current file. */
936 char *last_csect_name
; /* last seen csect's name and value */
937 CORE_ADDR last_csect_val
;
940 this_symtab_psymtab
= pst
;
942 /* Get the appropriate COFF "constants" related to the file we're
944 local_symesz
= coff_data (abfd
)->local_symesz
;
946 last_source_file
= NULL
;
951 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
952 record_debugformat (debugfmt
);
953 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
955 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
956 first_object_file_end
= 0;
959 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
960 + symnum
* local_symesz
;
962 while (symnum
< max_symnum
)
965 QUIT
; /* make this command interruptable. */
967 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
968 /* read one symbol into `cs' structure. After processing the
969 whole symbol table, only string table will be kept in memory,
970 symbol table and debug section of xcoff will be freed. Thus
971 we can mark symbols with names in string table as
976 /* Swap and align the symbol into a reasonable C structure. */
977 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
979 cs
->c_symnum
= symnum
;
980 cs
->c_naux
= symbol
->n_numaux
;
981 if (symbol
->n_zeroes
)
984 /* We must use the original, unswapped, name here so the name field
985 pointed to by cs->c_name will persist throughout xcoffread. If
986 we use the new field, it gets overwritten for each symbol. */
987 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
988 /* If it's exactly E_SYMNMLEN characters long it isn't
990 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
993 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
994 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
995 p
[E_SYMNMLEN
] = '\0';
1000 else if (symbol
->n_sclass
& 0x80)
1002 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1003 symname_alloced
= 0;
1007 /* in string table */
1008 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1009 symname_alloced
= 1;
1011 cs
->c_value
= symbol
->n_value
;
1012 cs
->c_sclass
= symbol
->n_sclass
;
1013 cs
->c_secnum
= symbol
->n_scnum
;
1014 cs
->c_type
= (unsigned) symbol
->n_type
;
1016 raw_symbol
+= local_symesz
;
1019 /* Save addr of first aux entry. */
1020 raw_auxptr
= raw_symbol
;
1022 /* Skip all the auxents associated with this symbol. */
1023 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1025 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1030 /* if symbol name starts with ".$" or "$", ignore it. */
1031 if (cs
->c_name
[0] == '$'
1032 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1035 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1037 if (last_source_file
)
1040 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1045 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1046 record_debugformat (debugfmt
);
1047 cur_src_end_addr
= first_object_file_end
;
1048 /* done with all files, everything from here on is globals */
1051 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1054 /* Dealing with a symbol with a csect entry. */
1056 #define CSECT(PP) ((PP)->x_csect)
1057 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1058 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1059 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1060 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1062 /* Convert the auxent to something we can access. */
1063 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1064 0, cs
->c_naux
, &main_aux
);
1066 switch (CSECT_SMTYP (&main_aux
))
1070 /* Ignore all external references. */
1074 /* A section description. */
1076 switch (CSECT_SCLAS (&main_aux
))
1082 /* A program csect is seen. We have to allocate one
1083 symbol table for each program csect. Normally gdb
1084 prefers one symtab for each source file. In case
1085 of AIX, one source file might include more than one
1086 [PR] csect, and they don't have to be adjacent in
1087 terms of the space they occupy in memory. Thus, one
1088 single source file might get fragmented in the
1089 memory and gdb's file start and end address
1090 approach does not work! GCC (and I think xlc) seem
1091 to put all the code in the unnamed program csect. */
1093 if (last_csect_name
)
1095 complete_symtab (filestring
, file_start_addr
);
1096 cur_src_end_addr
= file_end_addr
;
1097 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1100 /* Give all csects for this source file the same
1102 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1103 record_debugformat (debugfmt
);
1106 /* If this is the very first csect seen,
1107 basically `__start'. */
1110 first_object_file_end
1111 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1116 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1117 SECT_OFF_TEXT (objfile
));
1118 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1120 if (cs
->c_name
&& (cs
->c_name
[0] == '.'
1121 || cs
->c_name
[0] == '@'))
1123 last_csect_name
= cs
->c_name
;
1124 last_csect_val
= cs
->c_value
;
1125 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1130 /* All other symbols are put into the minimal symbol
1143 /* Ignore the symbol. */
1151 switch (CSECT_SCLAS (&main_aux
))
1154 /* a function entry point. */
1155 function_entry_point
:
1157 fcn_start_addr
= cs
->c_value
;
1159 /* save the function header info, which will be used
1160 when `.bf' is seen. */
1162 fcn_aux_saved
= main_aux
;
1166 /* shared library function trampoline code entry point. */
1170 /* The symbols often have the same names as debug symbols for
1171 functions, and confuse lookup_symbol. */
1175 /* xlc puts each variable in a separate csect, so we get
1176 an XTY_SD for each variable. But gcc puts several
1177 variables in a csect, so that each variable only gets
1178 an XTY_LD. This will typically be XMC_RW; I suspect
1179 XMC_RO and XMC_BS might be possible too.
1180 These variables are put in the minimal symbol table
1187 /* Common symbols are put into the minimal symbol table only. */
1195 /* If explicitly specified as a function, treat is as one. This check
1196 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1197 after the above CSECT check. */
1198 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1200 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1201 0, cs
->c_naux
, &main_aux
);
1202 goto function_entry_point
;
1205 switch (cs
->c_sclass
)
1210 /* c_value field contains symnum of next .file entry in table
1211 or symnum of first global after last .file. */
1213 next_file_symnum
= cs
->c_value
;
1215 /* Complete symbol table for last object file containing
1216 debugging information. */
1218 /* Whether or not there was a csect in the previous file, we
1219 have to call `end_stabs' and `start_stabs' to reset
1220 type_vector, line_vector, etc. structures. */
1222 complete_symtab (filestring
, file_start_addr
);
1223 cur_src_end_addr
= file_end_addr
;
1224 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1227 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1228 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1229 standard COFF way and put it in the auxent. We use the auxent if
1230 the symbol is ".file" and an auxent exists, otherwise use the symbol
1231 itself. Simple enough. */
1232 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1234 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1235 0, cs
->c_naux
, &main_aux
);
1236 filestring
= coff_getfilename (&main_aux
, objfile
);
1239 filestring
= cs
->c_name
;
1242 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1243 record_debugformat (debugfmt
);
1244 last_csect_name
= 0;
1246 /* reset file start and end addresses. A compilation unit with no text
1247 (only data) should have zero file boundaries. */
1248 file_start_addr
= file_end_addr
= 0;
1252 fcn_stab_saved
= *cs
;
1256 if (STREQ (cs
->c_name
, ".bf"))
1258 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1259 SECT_OFF_TEXT (objfile
));
1260 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1261 0, cs
->c_naux
, &main_aux
);
1263 within_function
= 1;
1265 new = push_context (0, fcn_start_addr
+ off
);
1267 new->name
= define_symbol
1268 (fcn_cs_saved
.c_value
+ off
,
1269 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1270 if (new->name
!= NULL
)
1271 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1273 else if (STREQ (cs
->c_name
, ".ef"))
1276 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1277 0, cs
->c_naux
, &main_aux
);
1279 /* The value of .ef is the address of epilogue code;
1280 not useful for gdb. */
1281 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1282 contains number of lines to '}' */
1284 if (context_stack_depth
<= 0)
1285 { /* We attempted to pop an empty context stack */
1286 ef_complaint (cs
->c_symnum
);
1287 within_function
= 0;
1290 new = pop_context ();
1291 /* Stack must be empty now. */
1292 if (context_stack_depth
> 0 || new == NULL
)
1294 ef_complaint (cs
->c_symnum
);
1295 within_function
= 0;
1299 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1301 (fcn_cs_saved
.c_value
1302 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1303 + ANOFFSET (objfile
->section_offsets
,
1304 SECT_OFF_TEXT (objfile
))),
1306 within_function
= 0;
1311 /* Begin static block. */
1313 struct internal_syment symbol
;
1315 read_symbol (&symbol
, cs
->c_value
);
1316 static_block_base
= symbol
.n_value
;
1317 static_block_section
=
1318 secnum_to_section (symbol
.n_scnum
, objfile
);
1323 /* End of static block. */
1324 static_block_base
= 0;
1325 static_block_section
= -1;
1336 complaint (&symfile_complaints
, "Unrecognized storage class %d.",
1351 /* beginning of include file */
1352 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1353 order. Thus, when wee see them, we might not know enough info
1354 to process them. Thus, we'll be saving them into a table
1355 (inclTable) and postpone their processing. */
1357 record_include_begin (cs
);
1361 /* End of include file. */
1362 /* See the comment after case C_BINCL. */
1363 record_include_end (cs
);
1367 if (STREQ (cs
->c_name
, ".bb"))
1370 new = push_context (depth
,
1372 + ANOFFSET (objfile
->section_offsets
,
1373 SECT_OFF_TEXT (objfile
))));
1375 else if (STREQ (cs
->c_name
, ".eb"))
1377 if (context_stack_depth
<= 0)
1378 { /* We attempted to pop an empty context stack */
1379 eb_complaint (cs
->c_symnum
);
1382 new = pop_context ();
1383 if (depth
-- != new->depth
)
1385 eb_complaint (cs
->c_symnum
);
1388 if (local_symbols
&& context_stack_depth
> 0)
1390 /* Make a block for the local symbols within. */
1391 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1394 + ANOFFSET (objfile
->section_offsets
,
1395 SECT_OFF_TEXT (objfile
))),
1398 local_symbols
= new->locals
;
1403 process_xcoff_symbol (cs
, objfile
);
1408 if (last_source_file
)
1412 complete_symtab (filestring
, file_start_addr
);
1413 cur_src_end_addr
= file_end_addr
;
1414 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1415 /* When reading symbols for the last C_FILE of the objfile, try
1416 to make sure that we set pst->symtab to the symtab for the
1417 file, not to the _globals_ symtab. I'm not sure whether this
1418 actually works right or when/if it comes up. */
1419 if (pst
->symtab
== NULL
)
1425 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1426 (SYMBOL2) = (struct symbol *) \
1427 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1428 *(SYMBOL2) = *(SYMBOL1);
1431 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1432 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1435 static struct type
*func_symbol_type
;
1436 static struct type
*var_symbol_type
;
1438 /* process one xcoff symbol. */
1440 static struct symbol
*
1441 process_xcoff_symbol (register struct coff_symbol
*cs
, struct objfile
*objfile
)
1443 struct symbol onesymbol
;
1444 register struct symbol
*sym
= &onesymbol
;
1445 struct symbol
*sym2
= NULL
;
1451 if (cs
->c_secnum
< 0)
1453 /* The value is a register number, offset within a frame, etc.,
1454 and does not get relocated. */
1460 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1461 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1468 memset (sym
, '\0', sizeof (struct symbol
));
1470 /* default assumptions */
1471 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1472 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1473 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1475 if (ISFCN (cs
->c_type
))
1477 /* At this point, we don't know the type of the function. This
1478 will be patched with the type from its stab entry later on in
1479 patch_block_stabs (), unless the file was compiled without -g. */
1481 DEPRECATED_SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1482 SYMBOL_TYPE (sym
) = func_symbol_type
;
1484 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1485 SYMBOL_DUP (sym
, sym2
);
1487 if (cs
->c_sclass
== C_EXT
)
1488 add_symbol_to_list (sym2
, &global_symbols
);
1489 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1490 add_symbol_to_list (sym2
, &file_symbols
);
1494 /* In case we can't figure out the type, provide default. */
1495 SYMBOL_TYPE (sym
) = var_symbol_type
;
1497 switch (cs
->c_sclass
)
1500 /* The values of functions and global symbols are now resolved
1501 via the global_sym_chain in stabsread.c. */
1503 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1504 add_stab_to_list (name
, &global_stabs
);
1506 add_stab_to_list (name
, &file_stabs
);
1510 add_stab_to_list (name
, &global_stabs
);
1515 common_block_start (cs
->c_name
, objfile
);
1519 common_block_end (objfile
);
1523 complaint (&symfile_complaints
, "Unexpected storage class: %d",
1536 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1539 SYMBOL_SECTION (sym
) = sec
;
1546 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1547 all statics and we need to distinguish file-scope versus
1548 function-scope using within_function. We do this by
1549 changing the string we pass to define_symbol to use 'S'
1550 where we need to, which is not necessarily super-clean,
1551 but seems workable enough. */
1553 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1557 if (*pp
== 'V' && !within_function
)
1559 sym
= define_symbol ((cs
->c_value
1560 + ANOFFSET (objfile
->section_offsets
,
1561 static_block_section
)),
1562 cs
->c_name
, 0, 0, objfile
);
1565 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1566 SYMBOL_SECTION (sym
) = static_block_section
;
1575 /* Extract the file name from the aux entry of a C_FILE symbol.
1576 Result is in static storage and is only good for temporary use. */
1579 coff_getfilename (union internal_auxent
*aux_entry
, struct objfile
*objfile
)
1581 static char buffer
[BUFSIZ
];
1583 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1585 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
1586 + aux_entry
->x_file
.x_n
.x_offset
);
1589 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1590 buffer
[FILNMLEN
] = '\0';
1595 /* Set *SYMBOL to symbol number symno in symtbl. */
1597 read_symbol (struct internal_syment
*symbol
, int symno
)
1600 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
1603 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
1605 if (symno
< 0 || symno
>= nsyms
)
1607 complaint (&symfile_complaints
, "Invalid symbol offset");
1608 symbol
->n_value
= 0;
1609 symbol
->n_scnum
= -1;
1612 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1613 stbl
+ (symno
* local_symesz
),
1617 /* Get value corresponding to symbol number symno in symtbl. */
1620 read_symbol_nvalue (int symno
)
1622 struct internal_syment symbol
[1];
1624 read_symbol (symbol
, symno
);
1625 return symbol
->n_value
;
1629 /* Find the address of the function corresponding to symno, where
1630 symno is the symbol pointed to by the linetable. */
1633 read_symbol_lineno (int symno
)
1635 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1636 int xcoff64
= bfd_xcoff_is_xcoff64 (objfile
->obfd
);
1638 struct coff_symfile_info
*info
=
1639 (struct coff_symfile_info
*)objfile
->sym_private
;
1640 int nsyms
= info
->symtbl_num_syms
;
1641 char *stbl
= info
->symtbl
;
1642 char *strtbl
= info
->strtbl
;
1644 struct internal_syment symbol
[1];
1645 union internal_auxent main_aux
[1];
1649 bf_notfound_complaint ();
1653 /* Note that just searching for a short distance (e.g. 50 symbols)
1654 is not enough, at least in the following case.
1657 [many .stabx entries]
1658 [a few functions, referring to foo]
1662 What happens here is that the assembler moves the .stabx entries
1663 to right before the ".bf" for foo, but the symbol for "foo" is before
1664 all the stabx entries. See PR gdb/2222. */
1666 /* Maintaining a table of .bf entries might be preferable to this search.
1667 If I understand things correctly it would need to be done only for
1668 the duration of a single psymtab to symtab conversion. */
1669 while (symno
< nsyms
)
1671 bfd_coff_swap_sym_in (symfile_bfd
,
1672 stbl
+ (symno
* local_symesz
), symbol
);
1673 if (symbol
->n_sclass
== C_FCN
)
1675 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1676 if (STREQ (name
, ".bf"))
1679 symno
+= symbol
->n_numaux
+ 1;
1682 bf_notfound_complaint ();
1686 /* take aux entry and return its lineno */
1688 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1689 symbol
->n_type
, symbol
->n_sclass
,
1690 0, symbol
->n_numaux
, main_aux
);
1692 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1695 /* Support for line number handling */
1697 /* This function is called for every section; it finds the outer limits
1698 * of the line table (minimum and maximum file offset) so that the
1699 * mainline code can read the whole thing for efficiency.
1702 find_linenos (bfd
*abfd
, sec_ptr asect
, void *vpinfo
)
1704 struct coff_symfile_info
*info
;
1706 file_ptr offset
, maxoff
;
1708 count
= asect
->lineno_count
;
1710 if (!STREQ (asect
->name
, ".text") || count
== 0)
1713 size
= count
* coff_data (abfd
)->local_linesz
;
1714 info
= (struct coff_symfile_info
*) vpinfo
;
1715 offset
= asect
->line_filepos
;
1716 maxoff
= offset
+ size
;
1718 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1719 info
->min_lineno_offset
= offset
;
1721 if (maxoff
> info
->max_lineno_offset
)
1722 info
->max_lineno_offset
= maxoff
;
1725 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1728 xcoff_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1730 struct cleanup
*old_chain
;
1739 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1744 /* Read in all partial symtabs on which this one is dependent */
1745 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1746 if (!pst
->dependencies
[i
]->readin
)
1748 /* Inform about additional files that need to be read in. */
1751 fputs_filtered (" ", gdb_stdout
);
1753 fputs_filtered ("and ", gdb_stdout
);
1755 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1756 wrap_here (""); /* Flush output */
1757 gdb_flush (gdb_stdout
);
1759 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1762 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1764 /* Init stuff necessary for reading in symbols. */
1767 old_chain
= make_cleanup (really_free_pendings
, 0);
1769 read_xcoff_symtab (pst
);
1770 sort_symtab_syms (pst
->symtab
);
1772 do_cleanups (old_chain
);
1778 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1780 /* Read in all of the symbols for a given psymtab for real.
1781 Be verbose about it if the user wants that. */
1784 xcoff_psymtab_to_symtab (struct partial_symtab
*pst
)
1794 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1799 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1800 || pst
->number_of_dependencies
)
1802 /* Print the message now, before reading the string table,
1803 to avoid disconcerting pauses. */
1806 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1807 gdb_flush (gdb_stdout
);
1810 sym_bfd
= pst
->objfile
->obfd
;
1812 next_symbol_text_func
= xcoff_next_symbol_text
;
1814 xcoff_psymtab_to_symtab_1 (pst
);
1816 /* Match with global symbols. This only needs to be done once,
1817 after all of the symtabs and dependencies have been read in. */
1818 scan_file_globals (pst
->objfile
);
1820 /* Finish up the debug error message. */
1822 printf_filtered ("done.\n");
1827 xcoff_new_init (struct objfile
*objfile
)
1829 stabsread_new_init ();
1830 buildsym_new_init ();
1833 /* Do initialization in preparation for reading symbols from OBJFILE.
1835 We will only be called if this is an XCOFF or XCOFF-like file.
1836 BFD handles figuring out the format of the file, and code in symfile.c
1837 uses BFD's determination to vector to us. */
1840 xcoff_symfile_init (struct objfile
*objfile
)
1842 /* Allocate struct to keep track of the symfile */
1843 objfile
->sym_private
= xmmalloc (objfile
->md
,
1844 sizeof (struct coff_symfile_info
));
1846 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1847 find this causes a significant slowdown in gdb then we could
1848 set it in the debug symbol readers only when necessary. */
1849 objfile
->flags
|= OBJF_REORDERED
;
1851 init_entry_point_info (objfile
);
1854 /* Perform any local cleanups required when we are done with a particular
1855 objfile. I.E, we are in the process of discarding all symbol information
1856 for an objfile, freeing up all memory held for it, and unlinking the
1857 objfile struct from the global list of known objfiles. */
1860 xcoff_symfile_finish (struct objfile
*objfile
)
1862 if (objfile
->sym_private
!= NULL
)
1864 xmfree (objfile
->md
, objfile
->sym_private
);
1867 /* Start with a fresh include table for the next objfile. */
1873 inclIndx
= inclLength
= inclDepth
= 0;
1878 init_stringtab (bfd
*abfd
, file_ptr offset
, struct objfile
*objfile
)
1882 unsigned char lengthbuf
[4];
1885 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
= NULL
;
1887 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1888 error ("cannot seek to string table in %s: %s",
1889 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1891 val
= bfd_bread ((char *) lengthbuf
, sizeof lengthbuf
, abfd
);
1892 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1894 /* If no string table is needed, then the file may end immediately
1895 after the symbols. Just return with `strtbl' set to NULL. */
1897 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1900 /* Allocate string table from symbol_obstack. We will need this table
1901 as long as we have its symbol table around. */
1903 strtbl
= (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
1904 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
= strtbl
;
1906 /* Copy length buffer, the first byte is usually zero and is
1907 used for stabs with a name length of zero. */
1908 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1909 if (length
== sizeof lengthbuf
)
1912 val
= bfd_bread (strtbl
+ sizeof lengthbuf
, length
- sizeof lengthbuf
, abfd
);
1914 if (val
!= length
- sizeof lengthbuf
)
1915 error ("cannot read string table from %s: %s",
1916 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1917 if (strtbl
[length
- 1] != '\0')
1918 error ("bad symbol file: string table does not end with null character");
1923 /* If we have not yet seen a function for this psymtab, this is 0. If we
1924 have seen one, it is the offset in the line numbers of the line numbers
1926 static unsigned int first_fun_line_offset
;
1928 static struct partial_symtab
*xcoff_start_psymtab
1929 (struct objfile
*, char *, int,
1930 struct partial_symbol
**, struct partial_symbol
**);
1932 /* Allocate and partially fill a partial symtab. It will be
1933 completely filled at the end of the symbol list.
1935 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1936 is the address relative to which its symbols are (incremental) or 0
1939 static struct partial_symtab
*
1940 xcoff_start_psymtab (struct objfile
*objfile
, char *filename
, int first_symnum
,
1941 struct partial_symbol
**global_syms
,
1942 struct partial_symbol
**static_syms
)
1944 struct partial_symtab
*result
=
1945 start_psymtab_common (objfile
, objfile
->section_offsets
,
1947 /* We fill in textlow later. */
1949 global_syms
, static_syms
);
1951 result
->read_symtab_private
= (char *)
1952 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1953 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
1954 result
->read_symtab
= xcoff_psymtab_to_symtab
;
1956 /* Deduce the source language from the filename for this psymtab. */
1957 psymtab_language
= deduce_language_from_filename (filename
);
1962 static struct partial_symtab
*xcoff_end_psymtab
1963 (struct partial_symtab
*, char **, int, int,
1964 struct partial_symtab
**, int, int);
1966 /* Close off the current usage of PST.
1967 Returns PST, or NULL if the partial symtab was empty and thrown away.
1969 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
1971 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
1972 are the information for includes and dependencies. */
1974 static struct partial_symtab
*
1975 xcoff_end_psymtab (struct partial_symtab
*pst
, char **include_list
,
1976 int num_includes
, int capping_symbol_number
,
1977 struct partial_symtab
**dependency_list
,
1978 int number_dependencies
, int textlow_not_set
)
1981 struct objfile
*objfile
= pst
->objfile
;
1983 if (capping_symbol_number
!= -1)
1984 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
1985 capping_symbol_number
1986 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
1987 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
1988 first_fun_line_offset
;
1989 first_fun_line_offset
= 0;
1990 pst
->n_global_syms
=
1991 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1992 pst
->n_static_syms
=
1993 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1995 pst
->number_of_dependencies
= number_dependencies
;
1996 if (number_dependencies
)
1998 pst
->dependencies
= (struct partial_symtab
**)
1999 obstack_alloc (&objfile
->psymbol_obstack
,
2000 number_dependencies
* sizeof (struct partial_symtab
*));
2001 memcpy (pst
->dependencies
, dependency_list
,
2002 number_dependencies
* sizeof (struct partial_symtab
*));
2005 pst
->dependencies
= 0;
2007 for (i
= 0; i
< num_includes
; i
++)
2009 struct partial_symtab
*subpst
=
2010 allocate_psymtab (include_list
[i
], objfile
);
2012 subpst
->section_offsets
= pst
->section_offsets
;
2013 subpst
->read_symtab_private
=
2014 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
2015 sizeof (struct symloc
));
2016 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2017 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2018 subpst
->textlow
= 0;
2019 subpst
->texthigh
= 0;
2021 /* We could save slight bits of space by only making one of these,
2022 shared by the entire set of include files. FIXME-someday. */
2023 subpst
->dependencies
= (struct partial_symtab
**)
2024 obstack_alloc (&objfile
->psymbol_obstack
,
2025 sizeof (struct partial_symtab
*));
2026 subpst
->dependencies
[0] = pst
;
2027 subpst
->number_of_dependencies
= 1;
2029 subpst
->globals_offset
=
2030 subpst
->n_global_syms
=
2031 subpst
->statics_offset
=
2032 subpst
->n_static_syms
= 0;
2036 subpst
->read_symtab
= pst
->read_symtab
;
2039 sort_pst_symbols (pst
);
2041 /* If there is already a psymtab or symtab for a file of this name,
2042 remove it. (If there is a symtab, more drastic things also
2043 happen.) This happens in VxWorks. */
2044 free_named_symtabs (pst
->filename
);
2046 if (num_includes
== 0
2047 && number_dependencies
== 0
2048 && pst
->n_global_syms
== 0
2049 && pst
->n_static_syms
== 0)
2051 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2052 it is on the obstack, but we can forget to chain it on the list. */
2053 /* Empty psymtabs happen as a result of header files which don't have
2054 any symbols in them. There can be a lot of them. */
2056 discard_psymtab (pst
);
2058 /* Indicate that psymtab was thrown away. */
2059 pst
= (struct partial_symtab
*) NULL
;
2064 static void swap_sym (struct internal_syment
*,
2065 union internal_auxent
*, char **, char **,
2066 unsigned int *, struct objfile
*);
2068 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2069 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2070 the symbol and its auxents. */
2073 swap_sym (struct internal_syment
*symbol
, union internal_auxent
*aux
,
2074 char **name
, char **raw
, unsigned int *symnump
,
2075 struct objfile
*objfile
)
2077 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2078 if (symbol
->n_zeroes
)
2080 /* If it's exactly E_SYMNMLEN characters long it isn't
2082 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2084 /* FIXME: wastes memory for symbols which we don't end up putting
2085 into the minimal symbols. */
2087 p
= obstack_alloc (&objfile
->psymbol_obstack
, E_SYMNMLEN
+ 1);
2088 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2089 p
[E_SYMNMLEN
] = '\0';
2093 /* Point to the unswapped name as that persists as long as the
2095 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2097 else if (symbol
->n_sclass
& 0x80)
2099 *name
= ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
2104 *name
= ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
2108 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2109 if (symbol
->n_numaux
> 0)
2111 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2112 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2114 *symnump
+= symbol
->n_numaux
;
2115 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2120 function_outside_compilation_unit_complaint (const char *arg1
)
2122 complaint (&symfile_complaints
,
2123 "function `%s' appears to be defined outside of all compilation units",
2128 scan_xcoff_symtab (struct objfile
*objfile
)
2130 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2131 char *filestring
= NULL
;
2134 int past_first_source_file
= 0;
2139 /* Current partial symtab */
2140 struct partial_symtab
*pst
;
2142 /* List of current psymtab's include files */
2143 char **psymtab_include_list
;
2144 int includes_allocated
;
2147 /* Index within current psymtab dependency list */
2148 struct partial_symtab
**dependency_list
;
2149 int dependencies_used
, dependencies_allocated
;
2152 struct internal_syment symbol
;
2153 union internal_auxent main_aux
[5];
2154 unsigned int ssymnum
;
2156 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2157 CORE_ADDR last_csect_val
= 0;
2158 int last_csect_sec
= 0;
2159 int misc_func_recorded
= 0; /* true if any misc. function */
2160 int textlow_not_set
= 1;
2162 pst
= (struct partial_symtab
*) 0;
2164 includes_allocated
= 30;
2166 psymtab_include_list
= (char **) alloca (includes_allocated
*
2169 dependencies_allocated
= 30;
2170 dependencies_used
= 0;
2172 (struct partial_symtab
**) alloca (dependencies_allocated
*
2173 sizeof (struct partial_symtab
*));
2175 last_source_file
= NULL
;
2177 abfd
= objfile
->obfd
;
2179 sraw_symbol
= ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
;
2180 nsyms
= ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl_num_syms
;
2182 while (ssymnum
< nsyms
)
2188 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2189 sclass
= symbol
.n_sclass
;
2196 /* The CSECT auxent--always the last auxent. */
2197 union internal_auxent csect_aux
;
2198 unsigned int symnum_before
= ssymnum
;
2200 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2202 if (symbol
.n_numaux
> 1)
2204 bfd_coff_swap_aux_in
2206 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2209 symbol
.n_numaux
- 1,
2214 csect_aux
= main_aux
[0];
2216 /* If symbol name starts with ".$" or "$", ignore it. */
2217 if (namestring
[0] == '$'
2218 || (namestring
[0] == '.' && namestring
[1] == '$'))
2221 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2224 switch (csect_aux
.x_csect
.x_smclas
)
2227 if (last_csect_name
)
2229 /* If no misc. function recorded in the last
2230 seen csect, enter it as a function. This
2231 will take care of functions like strcmp()
2234 if (!misc_func_recorded
)
2236 RECORD_MINIMAL_SYMBOL
2237 (last_csect_name
, last_csect_val
,
2238 mst_text
, last_csect_sec
,
2244 /* We have to allocate one psymtab for
2245 each program csect, because their text
2246 sections need not be adjacent. */
2248 (pst
, psymtab_include_list
, includes_used
,
2249 symnum_before
, dependency_list
,
2250 dependencies_used
, textlow_not_set
);
2252 dependencies_used
= 0;
2253 /* Give all psymtabs for this source file the same
2255 pst
= xcoff_start_psymtab
2259 objfile
->global_psymbols
.next
,
2260 objfile
->static_psymbols
.next
);
2263 /* Activate the misc_func_recorded mechanism for
2264 compiler- and linker-generated CSECTs like ".strcmp"
2266 if (namestring
&& (namestring
[0] == '.'
2267 || namestring
[0] == '@'))
2269 last_csect_name
= namestring
;
2270 last_csect_val
= symbol
.n_value
;
2272 secnum_to_section (symbol
.n_scnum
, objfile
);
2277 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2278 if (highval
> pst
->texthigh
)
2279 pst
->texthigh
= highval
;
2280 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2281 pst
->textlow
= symbol
.n_value
;
2283 misc_func_recorded
= 0;
2288 /* Data variables are recorded in the minimal symbol
2289 table, except for section symbols. */
2290 if (*namestring
!= '.')
2291 prim_record_minimal_symbol_and_info
2292 (namestring
, symbol
.n_value
,
2293 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2294 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2300 warning ("More than one XMC_TC0 symbol found.");
2301 toc_offset
= symbol
.n_value
;
2303 /* Make TOC offset relative to start address of section. */
2304 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2306 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2310 /* These symbols tell us where the TOC entry for a
2311 variable is, not the variable itself. */
2320 switch (csect_aux
.x_csect
.x_smclas
)
2323 /* A function entry point. */
2325 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2326 first_fun_line_offset
=
2327 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2328 RECORD_MINIMAL_SYMBOL
2329 (namestring
, symbol
.n_value
,
2330 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2331 secnum_to_section (symbol
.n_scnum
, objfile
),
2336 /* shared library function trampoline code entry
2339 /* record trampoline code entries as
2340 mst_solib_trampoline symbol. When we lookup mst
2341 symbols, we will choose mst_text over
2342 mst_solib_trampoline. */
2343 RECORD_MINIMAL_SYMBOL
2344 (namestring
, symbol
.n_value
,
2345 mst_solib_trampoline
,
2346 secnum_to_section (symbol
.n_scnum
, objfile
),
2351 /* The symbols often have the same names as
2352 debug symbols for functions, and confuse
2358 /* xlc puts each variable in a separate csect,
2359 so we get an XTY_SD for each variable. But
2360 gcc puts several variables in a csect, so
2361 that each variable only gets an XTY_LD. We
2362 still need to record them. This will
2363 typically be XMC_RW; I suspect XMC_RO and
2364 XMC_BS might be possible too. */
2365 if (*namestring
!= '.')
2366 prim_record_minimal_symbol_and_info
2367 (namestring
, symbol
.n_value
,
2368 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2369 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2376 switch (csect_aux
.x_csect
.x_smclas
)
2380 /* Common variables are recorded in the minimal symbol
2381 table, except for section symbols. */
2382 if (*namestring
!= '.')
2383 prim_record_minimal_symbol_and_info
2384 (namestring
, symbol
.n_value
,
2385 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2386 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2399 unsigned int symnum_before
;
2401 symnum_before
= ssymnum
;
2402 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2405 /* See if the last csect needs to be recorded. */
2407 if (last_csect_name
&& !misc_func_recorded
)
2410 /* If no misc. function recorded in the last seen csect, enter
2411 it as a function. This will take care of functions like
2412 strcmp() compiled by xlc. */
2414 RECORD_MINIMAL_SYMBOL
2415 (last_csect_name
, last_csect_val
,
2416 mst_text
, last_csect_sec
, objfile
);
2421 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2422 symnum_before
, dependency_list
,
2423 dependencies_used
, textlow_not_set
);
2425 dependencies_used
= 0;
2427 first_fun_line_offset
= 0;
2429 /* XCOFF, according to the AIX 3.2 documentation, puts the
2430 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2431 do things the standard COFF way and put it in the auxent.
2432 We use the auxent if the symbol is ".file" and an auxent
2433 exists, otherwise use the symbol itself. */
2434 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2436 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2439 filestring
= namestring
;
2441 pst
= xcoff_start_psymtab (objfile
,
2444 objfile
->global_psymbols
.next
,
2445 objfile
->static_psymbols
.next
);
2446 last_csect_name
= NULL
;
2452 complaint (&symfile_complaints
,
2453 "Storage class %d not recognized during scan", sclass
);
2457 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2458 to handle only the C_FUN and C_EXT. */
2473 /* C_EINCL means we are switching back to the main file. But there
2474 is no reason to care; the only thing we want to know about
2475 includes is the names of all the included (.h) files. */
2480 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2484 /* I don't think the name of the common block (as opposed to the
2485 variables within it) is something which is user visible
2493 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2494 so C_LSYM would appear to be only for locals. */
2500 /* We probably could save a few instructions by assuming that
2501 C_LSYM, C_PSYM, etc., never have auxents. */
2502 int naux1
= symbol
.n_numaux
+ 1;
2504 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2510 /* Mark down an include file in the current psymtab */
2511 enum language tmp_language
;
2512 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2515 tmp_language
= deduce_language_from_filename (namestring
);
2517 /* Only change the psymtab's language if we've learned
2518 something useful (eg. tmp_language is not language_unknown).
2519 In addition, to match what start_subfile does, never change
2521 if (tmp_language
!= language_unknown
2522 && (tmp_language
!= language_c
2523 || psymtab_language
!= language_cplus
))
2524 psymtab_language
= tmp_language
;
2526 /* In C++, one may expect the same filename to come round many
2527 times, when code is coming alternately from the main file
2528 and from inline functions in other files. So I check to see
2529 if this is a file we've seen before -- either the main
2530 source file, or a previously included file.
2532 This seems to be a lot of time to be spending on N_SOL, but
2533 things like "break c-exp.y:435" need to work (I
2534 suppose the psymtab_include_list could be hashed or put
2535 in a binary tree, if profiling shows this is a major hog). */
2536 if (pst
&& STREQ (namestring
, pst
->filename
))
2540 for (i
= 0; i
< includes_used
; i
++)
2541 if (STREQ (namestring
, psymtab_include_list
[i
]))
2549 psymtab_include_list
[includes_used
++] = namestring
;
2550 if (includes_used
>= includes_allocated
)
2552 char **orig
= psymtab_include_list
;
2554 psymtab_include_list
= (char **)
2555 alloca ((includes_allocated
*= 2) *
2557 memcpy (psymtab_include_list
, orig
,
2558 includes_used
* sizeof (char *));
2563 /* The value of the C_FUN is not the address of the function (it
2564 appears to be the address before linking), but as long as it
2565 is smaller than the actual address, then find_pc_partial_function
2566 will use the minimal symbols instead. I hope. */
2574 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2577 p
= (char *) strchr (namestring
, ':');
2579 continue; /* Not a debugging symbol. */
2581 /* Main processing section for debugging symbols which
2582 the initial read through the symbol tables needs to worry
2583 about. If we reach this point, the symbol which we are
2584 considering is definitely one we are interested in.
2585 p must also contain the (valid) index into the namestring
2586 which indicates the debugging type symbol. */
2591 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2592 #ifdef STATIC_TRANSFORM_NAME
2593 namestring
= STATIC_TRANSFORM_NAME (namestring
);
2595 add_psymbol_to_list (namestring
, p
- namestring
,
2596 VAR_DOMAIN
, LOC_STATIC
,
2597 &objfile
->static_psymbols
,
2599 psymtab_language
, objfile
);
2603 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2604 /* The addresses in these entries are reported to be
2605 wrong. See the code that reads 'G's for symtabs. */
2606 add_psymbol_to_list (namestring
, p
- namestring
,
2607 VAR_DOMAIN
, LOC_STATIC
,
2608 &objfile
->global_psymbols
,
2610 psymtab_language
, objfile
);
2614 /* When a 'T' entry is defining an anonymous enum, it
2615 may have a name which is the empty string, or a
2616 single space. Since they're not really defining a
2617 symbol, those shouldn't go in the partial symbol
2618 table. We do pick up the elements of such enums at
2619 'check_enum:', below. */
2620 if (p
>= namestring
+ 2
2621 || (p
== namestring
+ 1
2622 && namestring
[0] != ' '))
2624 add_psymbol_to_list (namestring
, p
- namestring
,
2625 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2626 &objfile
->static_psymbols
,
2628 psymtab_language
, objfile
);
2631 /* Also a typedef with the same name. */
2632 add_psymbol_to_list (namestring
, p
- namestring
,
2633 VAR_DOMAIN
, LOC_TYPEDEF
,
2634 &objfile
->static_psymbols
,
2636 psymtab_language
, objfile
);
2639 #if 0 /* OBSOLETE CFront */
2640 // OBSOLETE /* The semantics of C++ state that "struct foo { ... }"
2641 // OBSOLETE also defines a typedef for "foo". Unfortuantely, cfront
2642 // OBSOLETE never makes the typedef when translating from C++ to C.
2643 // OBSOLETE We make the typedef here so that "ptype foo" works as
2644 // OBSOLETE expected for cfront translated code. */
2645 // OBSOLETE else if (psymtab_language == language_cplus)
2647 // OBSOLETE /* Also a typedef with the same name. */
2648 // OBSOLETE add_psymbol_to_list (namestring, p - namestring,
2649 // OBSOLETE VAR_DOMAIN, LOC_TYPEDEF,
2650 // OBSOLETE &objfile->static_psymbols,
2651 // OBSOLETE symbol.n_value, 0,
2652 // OBSOLETE psymtab_language, objfile);
2654 #endif /* OBSOLETE CFront */
2659 if (p
!= namestring
) /* a name is there, not just :T... */
2661 add_psymbol_to_list (namestring
, p
- namestring
,
2662 VAR_DOMAIN
, LOC_TYPEDEF
,
2663 &objfile
->static_psymbols
,
2665 psymtab_language
, objfile
);
2668 /* If this is an enumerated type, we need to
2669 add all the enum constants to the partial symbol
2670 table. This does not cover enums without names, e.g.
2671 "enum {a, b} c;" in C, but fortunately those are
2672 rare. There is no way for GDB to find those from the
2673 enum type without spending too much time on it. Thus
2674 to solve this problem, the compiler needs to put out the
2675 enum in a nameless type. GCC2 does this. */
2677 /* We are looking for something of the form
2678 <name> ":" ("t" | "T") [<number> "="] "e"
2679 {<constant> ":" <value> ","} ";". */
2681 /* Skip over the colon and the 't' or 'T'. */
2683 /* This type may be given a number. Also, numbers can come
2684 in pairs like (0,26). Skip over it. */
2685 while ((*p
>= '0' && *p
<= '9')
2686 || *p
== '(' || *p
== ',' || *p
== ')'
2692 /* The aix4 compiler emits extra crud before the members. */
2695 /* Skip over the type (?). */
2699 /* Skip over the colon. */
2703 /* We have found an enumerated type. */
2704 /* According to comments in read_enum_type
2705 a comma could end it instead of a semicolon.
2706 I don't know where that happens.
2708 while (*p
&& *p
!= ';' && *p
!= ',')
2712 /* Check for and handle cretinous dbx symbol name
2714 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
2715 p
= next_symbol_text (objfile
);
2717 /* Point to the character after the name
2718 of the enum constant. */
2719 for (q
= p
; *q
&& *q
!= ':'; q
++)
2721 /* Note that the value doesn't matter for
2722 enum constants in psymtabs, just in symtabs. */
2723 add_psymbol_to_list (p
, q
- p
,
2724 VAR_DOMAIN
, LOC_CONST
,
2725 &objfile
->static_psymbols
, 0,
2726 0, psymtab_language
, objfile
);
2727 /* Point past the name. */
2729 /* Skip over the value. */
2730 while (*p
&& *p
!= ',')
2732 /* Advance past the comma. */
2740 /* Constant, e.g. from "const" in Pascal. */
2741 add_psymbol_to_list (namestring
, p
- namestring
,
2742 VAR_DOMAIN
, LOC_CONST
,
2743 &objfile
->static_psymbols
, symbol
.n_value
,
2744 0, psymtab_language
, objfile
);
2750 int name_len
= p
- namestring
;
2751 char *name
= xmalloc (name_len
+ 1);
2752 memcpy (name
, namestring
, name_len
);
2753 name
[name_len
] = '\0';
2754 function_outside_compilation_unit_complaint (name
);
2757 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2758 add_psymbol_to_list (namestring
, p
- namestring
,
2759 VAR_DOMAIN
, LOC_BLOCK
,
2760 &objfile
->static_psymbols
,
2762 psymtab_language
, objfile
);
2765 /* Global functions were ignored here, but now they
2766 are put into the global psymtab like one would expect.
2767 They're also in the minimal symbol table. */
2771 int name_len
= p
- namestring
;
2772 char *name
= xmalloc (name_len
+ 1);
2773 memcpy (name
, namestring
, name_len
);
2774 name
[name_len
] = '\0';
2775 function_outside_compilation_unit_complaint (name
);
2778 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2779 add_psymbol_to_list (namestring
, p
- namestring
,
2780 VAR_DOMAIN
, LOC_BLOCK
,
2781 &objfile
->global_psymbols
,
2783 psymtab_language
, objfile
);
2786 /* Two things show up here (hopefully); static symbols of
2787 local scope (static used inside braces) or extensions
2788 of structure symbols. We can ignore both. */
2802 case '#': /* for symbol identification (used in live ranges) */
2803 #if 0 /* OBSOLETE CFront */
2804 // OBSOLETE /* added to support cfront stabs strings */
2805 // OBSOLETE case 'Z': /* for definition continuations */
2806 // OBSOLETE case 'P': /* for prototypes */
2807 #endif /* OBSOLETE CFront */
2811 /* It is a C++ nested symbol. We don't need to record it
2812 (I don't think); if we try to look up foo::bar::baz,
2813 then symbols for the symtab containing foo should get
2814 read in, I think. */
2815 /* Someone says sun cc puts out symbols like
2816 /foo/baz/maclib::/usr/local/bin/maclib,
2817 which would get here with a symbol type of ':'. */
2821 /* Unexpected symbol descriptor. The second and subsequent stabs
2822 of a continued stab can show up here. The question is
2823 whether they ever can mimic a normal stab--it would be
2824 nice if not, since we certainly don't want to spend the
2825 time searching to the end of every string looking for
2828 complaint (&symfile_complaints
,
2829 "unknown symbol descriptor `%c'", p
[1]);
2831 /* Ignore it; perhaps it is an extension that we don't
2841 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2842 ssymnum
, dependency_list
,
2843 dependencies_used
, textlow_not_set
);
2846 /* Record the toc offset value of this symbol table into objfile structure.
2847 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2848 this information would be file auxiliary header. */
2850 ((struct coff_symfile_info
*) objfile
->sym_private
)->toc_offset
= toc_offset
;
2853 /* Return the toc offset value for a given objfile. */
2856 get_toc_offset (struct objfile
*objfile
)
2859 return ((struct coff_symfile_info
*) objfile
->sym_private
)->toc_offset
;
2863 /* Scan and build partial symbols for a symbol file.
2864 We have been initialized by a call to dbx_symfile_init, which
2865 put all the relevant info into a "struct dbx_symfile_info",
2866 hung off the objfile structure.
2868 SECTION_OFFSETS contains offsets relative to which the symbols in the
2869 various sections are (depending where the sections were actually loaded).
2870 MAINLINE is true if we are reading the main symbol
2871 table (as opposed to a shared lib or dynamically loaded file). */
2874 xcoff_initial_scan (struct objfile
*objfile
, int mainline
)
2878 struct cleanup
*back_to
;
2879 int num_symbols
; /* # of symbols */
2880 file_ptr symtab_offset
; /* symbol table and */
2881 file_ptr stringtab_offset
; /* string table file offsets */
2882 struct coff_symfile_info
*info
;
2886 info
= (struct coff_symfile_info
*) objfile
->sym_private
;
2887 symfile_bfd
= abfd
= objfile
->obfd
;
2888 name
= objfile
->name
;
2890 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2891 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2892 stringtab_offset
= symtab_offset
+
2893 num_symbols
* coff_data (abfd
)->local_symesz
;
2895 info
->min_lineno_offset
= 0;
2896 info
->max_lineno_offset
= 0;
2897 bfd_map_over_sections (abfd
, find_linenos
, info
);
2899 if (num_symbols
> 0)
2901 /* Read the string table. */
2902 init_stringtab (abfd
, stringtab_offset
, objfile
);
2904 /* Read the .debug section, if present. */
2907 bfd_size_type length
;
2908 char *debugsec
= NULL
;
2910 secp
= bfd_get_section_by_name (abfd
, ".debug");
2913 length
= bfd_section_size (abfd
, secp
);
2917 (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
2919 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2920 (file_ptr
) 0, length
))
2922 error ("Error reading .debug section of `%s': %s",
2923 name
, bfd_errmsg (bfd_get_error ()));
2927 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
=
2932 /* Read the symbols. We keep them in core because we will want to
2933 access them randomly in read_symbol*. */
2934 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2936 error ("Error reading symbols from %s: %s",
2937 name
, bfd_errmsg (bfd_get_error ()));
2938 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2939 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
=
2940 obstack_alloc (&objfile
->symbol_obstack
, size
);
2941 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl_num_syms
=
2944 val
= bfd_bread (((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
,
2947 perror_with_name ("reading symbol table");
2949 /* If we are reinitializing, or if we have never loaded syms yet, init */
2951 || (objfile
->global_psymbols
.size
== 0
2952 && objfile
->static_psymbols
.size
== 0))
2953 /* I'm not sure how how good num_symbols is; the rule of thumb in
2954 init_psymbol_list was developed for a.out. On the one hand,
2955 num_symbols includes auxents. On the other hand, it doesn't
2957 init_psymbol_list (objfile
, num_symbols
);
2959 free_pending_blocks ();
2960 back_to
= make_cleanup (really_free_pendings
, 0);
2962 init_minimal_symbol_collection ();
2963 make_cleanup_discard_minimal_symbols ();
2965 /* Now that the symbol table data of the executable file are all in core,
2966 process them and define symbols accordingly. */
2968 scan_xcoff_symtab (objfile
);
2970 /* Install any minimal symbols that have been collected as the current
2971 minimal symbols for this objfile. */
2973 install_minimal_symbols (objfile
);
2975 do_cleanups (back_to
);
2979 xcoff_symfile_offsets (struct objfile
*objfile
, struct section_addr_info
*addrs
)
2981 asection
*sect
= NULL
;
2984 objfile
->num_sections
= SECT_OFF_MAX
;
2985 objfile
->section_offsets
= (struct section_offsets
*)
2986 obstack_alloc (&objfile
->psymbol_obstack
, SIZEOF_SECTION_OFFSETS
);
2988 /* Initialize the section indexes for future use. */
2989 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
2991 objfile
->sect_index_text
= sect
->index
;
2993 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
2995 objfile
->sect_index_data
= sect
->index
;
2997 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
2999 objfile
->sect_index_bss
= sect
->index
;
3001 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
3003 objfile
->sect_index_rodata
= sect
->index
;
3005 for (i
= 0; i
< objfile
->num_sections
; ++i
)
3007 /* syms_from_objfile kindly subtracts from addr the
3008 bfd_section_vma of the .text section. This strikes me as
3009 wrong--whether the offset to be applied to symbol reading is
3010 relative to the start address of the section depends on the
3011 symbol format. In any event, this whole "addr" concept is
3012 pretty broken (it doesn't handle any section but .text
3013 sensibly), so just ignore the addr parameter and use 0.
3014 rs6000-nat.c will set the correct section offsets via
3015 objfile_relocate. */
3016 (objfile
->section_offsets
)->offsets
[i
] = 0;
3020 /* Register our ability to parse symbols for xcoff BFD files. */
3022 static struct sym_fns xcoff_sym_fns
=
3025 /* It is possible that coff and xcoff should be merged as
3026 they do have fundamental similarities (for example, the extra storage
3027 classes used for stabs could presumably be recognized in any COFF file).
3028 However, in addition to obvious things like all the csect hair, there are
3029 some subtler differences between xcoffread.c and coffread.c, notably
3030 the fact that coffread.c has no need to read in all the symbols, but
3031 xcoffread.c reads all the symbols and does in fact randomly access them
3032 (in C_BSTAT and line number processing). */
3034 bfd_target_xcoff_flavour
,
3036 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3037 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3038 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
3039 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3040 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
3041 NULL
/* next: pointer to next struct sym_fns */
3045 _initialize_xcoffread (void)
3047 add_symtab_fns (&xcoff_sym_fns
);
3049 func_symbol_type
= init_type (TYPE_CODE_FUNC
, 1, 0,
3050 "<function, no debug info>", NULL
);
3051 TYPE_TARGET_TYPE (func_symbol_type
) = builtin_type_int
;
3053 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
3054 "<variable, no debug info>", NULL
);