1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009
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 3 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, see <http://www.gnu.org/licenses/>. */
26 #include <sys/types.h>
29 #include "gdb_string.h"
31 #include <sys/param.h>
32 #ifdef HAVE_SYS_FILE_H
37 #include "coff/internal.h"
38 #include "libcoff.h" /* FIXME, internal data from BFD */
39 #include "coff/xcoff.h"
41 #include "coff/rs6000.h"
42 #include "xcoffread.h"
46 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */
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 char *coff_getfilename (union internal_auxent
*, struct objfile
*);
198 static void read_symbol (struct internal_syment
*, int);
200 static int read_symbol_lineno (int);
202 static CORE_ADDR
read_symbol_nvalue (int);
204 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
207 static void read_xcoff_symtab (struct partial_symtab
*);
210 static void add_stab_to_list (char *, struct pending_stabs
**);
213 static int compare_lte (const void *, const void *);
215 static struct linetable
*arrange_linetable (struct linetable
*);
217 static void record_include_end (struct coff_symbol
*);
219 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
222 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
224 static int secnum_to_section (int, struct objfile
*);
225 static asection
*secnum_to_bfd_section (int, struct objfile
*);
227 struct find_targ_sec_arg
232 struct objfile
*objfile
;
235 static void find_targ_sec (bfd
*, asection
*, void *);
238 find_targ_sec (bfd
*abfd
, asection
*sect
, void *obj
)
240 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
241 struct objfile
*objfile
= args
->objfile
;
242 if (sect
->target_index
== args
->targ_index
)
244 /* This is the section. Figure out what SECT_OFF_* code it is. */
245 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
246 *args
->resultp
= SECT_OFF_TEXT (objfile
);
247 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
248 *args
->resultp
= SECT_OFF_DATA (objfile
);
250 *args
->resultp
= sect
->index
;
251 *args
->bfd_sect
= sect
;
255 /* Return the section number (SECT_OFF_*) that CS points to. */
257 secnum_to_section (int secnum
, struct objfile
*objfile
)
259 int off
= SECT_OFF_TEXT (objfile
);
260 asection
*sect
= NULL
;
261 struct find_targ_sec_arg args
;
262 args
.targ_index
= secnum
;
264 args
.bfd_sect
= §
;
265 args
.objfile
= objfile
;
266 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
270 /* Return the BFD section that CS points to. */
272 secnum_to_bfd_section (int secnum
, struct objfile
*objfile
)
274 int off
= SECT_OFF_TEXT (objfile
);
275 asection
*sect
= NULL
;
276 struct find_targ_sec_arg args
;
277 args
.targ_index
= secnum
;
279 args
.bfd_sect
= §
;
280 args
.objfile
= objfile
;
281 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
285 /* add a given stab string into given stab vector. */
290 add_stab_to_list (char *stabname
, struct pending_stabs
**stabvector
)
292 if (*stabvector
== NULL
)
294 *stabvector
= (struct pending_stabs
*)
295 xmalloc (sizeof (struct pending_stabs
) +
296 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
297 (*stabvector
)->count
= 0;
298 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
300 else if ((*stabvector
)->count
>= (*stabvector
)->length
)
302 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
303 *stabvector
= (struct pending_stabs
*)
304 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
305 (*stabvector
)->length
* sizeof (char *));
307 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
312 /* Linenos are processed on a file-by-file basis.
316 1) xlc (IBM's native c compiler) postpones static function code
317 emission to the end of a compilation unit. This way it can
318 determine if those functions (statics) are needed or not, and
319 can do some garbage collection (I think). This makes line
320 numbers and corresponding addresses unordered, and we end up
321 with a line table like:
338 and that breaks gdb's binary search on line numbers, if the
339 above table is not sorted on line numbers. And that sort
340 should be on function based, since gcc can emit line numbers
343 10 0x100 - for the init/test part of a for stmt.
346 10 0x400 - for the increment part of a for stmt.
348 arrange_linetable() will do this sorting.
350 2) aix symbol table might look like:
352 c_file // beginning of a new file
353 .bi // beginning of include file
354 .ei // end of include file
358 basically, .bi/.ei pairs do not necessarily encapsulate
359 their scope. They need to be recorded, and processed later
360 on when we come the end of the compilation unit.
361 Include table (inclTable) and process_linenos() handle
367 /* compare line table entry addresses. */
370 compare_lte (const void *lte1p
, const void *lte2p
)
372 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
373 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
374 return lte1
->pc
- lte2
->pc
;
377 /* Given a line table with function entries are marked, arrange its functions
378 in ascending order and strip off function entry markers and return it in
379 a newly created table. If the old one is good enough, return the old one. */
380 /* FIXME: I think all this stuff can be replaced by just passing
381 sort_linevec = 1 to end_symtab. */
383 static struct linetable
*
384 arrange_linetable (struct linetable
*oldLineTb
)
386 int ii
, jj
, newline
, /* new line count */
387 function_count
; /* # of functions */
389 struct linetable_entry
*fentry
; /* function entry vector */
390 int fentry_size
; /* # of function entries */
391 struct linetable
*newLineTb
; /* new line table */
393 #define NUM_OF_FUNCTIONS 20
395 fentry_size
= NUM_OF_FUNCTIONS
;
396 fentry
= (struct linetable_entry
*)
397 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
399 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
402 if (oldLineTb
->item
[ii
].line
== 0)
403 { /* function entry found. */
405 if (function_count
>= fentry_size
)
406 { /* make sure you have room. */
408 fentry
= (struct linetable_entry
*)
409 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
411 fentry
[function_count
].line
= ii
;
412 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
417 if (function_count
== 0)
422 else if (function_count
> 1)
423 qsort (fentry
, function_count
, sizeof (struct linetable_entry
), compare_lte
);
425 /* allocate a new line table. */
426 newLineTb
= (struct linetable
*)
428 (sizeof (struct linetable
) +
429 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
431 /* if line table does not start with a function beginning, copy up until
435 if (oldLineTb
->item
[0].line
!= 0)
437 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
438 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
440 /* Now copy function lines one by one. */
442 for (ii
= 0; ii
< function_count
; ++ii
)
444 for (jj
= fentry
[ii
].line
+ 1;
445 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
447 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
450 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
454 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
455 following `IncludeChain'. At the end of each symtab (end_symtab),
456 we will determine if we should create additional symtab's to
457 represent if (the include files. */
460 typedef struct _inclTable
462 char *name
; /* include filename */
464 /* Offsets to the line table. end points to the last entry which is
465 part of this include file. */
468 struct subfile
*subfile
;
469 unsigned funStartLine
; /* start line # of its function */
473 #define INITIAL_INCLUDE_TABLE_LENGTH 20
474 static InclTable
*inclTable
; /* global include table */
475 static int inclIndx
; /* last entry to table */
476 static int inclLength
; /* table length */
477 static int inclDepth
; /* nested include depth */
479 static void allocate_include_entry (void);
482 record_include_begin (struct coff_symbol
*cs
)
486 /* In xcoff, we assume include files cannot be nested (not in .c files
487 of course, but in corresponding .s files.). */
489 /* This can happen with old versions of GCC.
490 GCC 2.3.3-930426 does not exhibit this on a test case which
491 a user said produced the message for him. */
492 complaint (&symfile_complaints
, _("Nested C_BINCL symbols"));
496 allocate_include_entry ();
498 inclTable
[inclIndx
].name
= cs
->c_name
;
499 inclTable
[inclIndx
].begin
= cs
->c_value
;
503 record_include_end (struct coff_symbol
*cs
)
509 complaint (&symfile_complaints
, _("Mismatched C_BINCL/C_EINCL pair"));
512 allocate_include_entry ();
514 pTbl
= &inclTable
[inclIndx
];
515 pTbl
->end
= cs
->c_value
;
522 allocate_include_entry (void)
524 if (inclTable
== NULL
)
526 inclTable
= (InclTable
*)
527 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
529 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
530 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
533 else if (inclIndx
>= inclLength
)
535 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
536 inclTable
= (InclTable
*)
537 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
538 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
539 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
543 /* Global variable to pass the psymtab down to all the routines involved
544 in psymtab to symtab processing. */
545 static struct partial_symtab
*this_symtab_psymtab
;
547 /* given the start and end addresses of a compilation unit (or a csect,
548 at times) process its lines and create appropriate line vectors. */
551 process_linenos (CORE_ADDR start
, CORE_ADDR end
)
554 file_ptr max_offset
=
555 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)
558 /* subfile structure for the main compilation unit. */
559 struct subfile main_subfile
;
561 /* In the main source file, any time we see a function entry, we
562 reset this variable to function's absolute starting line number.
563 All the following line numbers in the function are relative to
564 this, and we record absolute line numbers in record_line(). */
566 unsigned int main_source_baseline
= 0;
571 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
573 goto return_after_cleanup
;
575 memset (&main_subfile
, '\0', sizeof (main_subfile
));
578 /* All source lines were in the main source file. None in include files. */
580 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
581 &main_source_baseline
);
585 /* There was source with line numbers in include files. */
588 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
589 main_source_baseline
= 0;
591 for (ii
= 0; ii
< inclIndx
; ++ii
)
593 struct subfile
*tmpSubfile
;
595 /* If there is main file source before include file, enter it. */
596 if (offset
< inclTable
[ii
].begin
)
599 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
600 start
, 0, &main_source_baseline
);
603 if (strcmp (inclTable
[ii
].name
, last_source_file
) == 0)
605 /* The entry in the include table refers to the main source
606 file. Add the lines to the main subfile. */
608 main_source_baseline
= inclTable
[ii
].funStartLine
;
610 (&main_subfile
, inclTable
[ii
].begin
, inclTable
[ii
].end
,
611 start
, 0, &main_source_baseline
);
612 inclTable
[ii
].subfile
= &main_subfile
;
617 /* Have a new subfile for the include file. */
619 tmpSubfile
= inclTable
[ii
].subfile
=
620 (struct subfile
*) xmalloc (sizeof (struct subfile
));
622 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
623 firstLine
= &(inclTable
[ii
].funStartLine
);
625 /* Enter include file's lines now. */
626 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
627 inclTable
[ii
].end
, start
, 0, firstLine
);
630 if (offset
<= inclTable
[ii
].end
)
631 offset
= inclTable
[ii
].end
+ linesz
;
634 /* All the include files' line have been processed at this point. Now,
635 enter remaining lines of the main file, if any left. */
636 if (offset
< max_offset
+ 1 - linesz
)
638 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
639 &main_source_baseline
);
643 /* Process main file's line numbers. */
644 if (main_subfile
.line_vector
)
646 struct linetable
*lineTb
, *lv
;
648 lv
= main_subfile
.line_vector
;
650 /* Line numbers are not necessarily ordered. xlc compilation will
651 put static function to the end. */
653 lineTb
= arrange_linetable (lv
);
656 current_subfile
->line_vector
= (struct linetable
*)
657 xrealloc (lv
, (sizeof (struct linetable
)
658 + lv
->nitems
* sizeof (struct linetable_entry
)));
663 current_subfile
->line_vector
= lineTb
;
666 current_subfile
->line_vector_length
=
667 current_subfile
->line_vector
->nitems
;
670 /* Now, process included files' line numbers. */
672 for (ii
= 0; ii
< inclIndx
; ++ii
)
674 if (inclTable
[ii
].subfile
!= ((struct subfile
*) &main_subfile
)
675 && (inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
677 struct linetable
*lineTb
, *lv
;
679 lv
= (inclTable
[ii
].subfile
)->line_vector
;
681 /* Line numbers are not necessarily ordered. xlc compilation will
682 put static function to the end. */
684 lineTb
= arrange_linetable (lv
);
688 /* For the same include file, we might want to have more than one
689 subfile. This happens if we have something like:
697 while foo.h including code in it. (stupid but possible)
698 Since start_subfile() looks at the name and uses an
699 existing one if finds, we need to provide a fake name and
703 start_subfile (inclTable
[ii
].name
, (char *) 0);
706 /* Pick a fake name that will produce the same results as this
707 one when passed to deduce_language_from_filename. Kludge on
709 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
710 if (fakename
== NULL
)
712 start_subfile (fakename
, (char *) 0);
713 xfree (current_subfile
->name
);
715 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
720 current_subfile
->line_vector
=
721 (struct linetable
*) xrealloc
722 (lv
, (sizeof (struct linetable
)
723 + lv
->nitems
* sizeof (struct linetable_entry
)));
729 current_subfile
->line_vector
= lineTb
;
732 current_subfile
->line_vector_length
=
733 current_subfile
->line_vector
->nitems
;
734 start_subfile (pop_subfile (), (char *) 0);
738 return_after_cleanup
:
740 /* We don't want to keep alloc/free'ing the global include file table. */
743 /* Start with a fresh subfile structure for the next file. */
744 memset (&main_subfile
, '\0', sizeof (struct subfile
));
748 aix_process_linenos (void)
750 /* process line numbers and enter them into line vector */
751 process_linenos (last_source_start_addr
, cur_src_end_addr
);
755 /* Enter a given range of lines into the line vector.
756 can be called in the following two ways:
757 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
758 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
760 endoffset points to the last line table entry that we should pay
764 enter_line_range (struct subfile
*subfile
, unsigned beginoffset
, unsigned endoffset
, /* offsets to line table */
765 CORE_ADDR startaddr
, /* offsets to line table */
766 CORE_ADDR endaddr
, unsigned *firstLine
)
768 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
769 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
770 unsigned int curoffset
;
773 struct internal_lineno int_lnno
;
774 unsigned int limit_offset
;
778 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
780 curoffset
= beginoffset
;
782 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)
787 if (endoffset
>= limit_offset
)
789 complaint (&symfile_complaints
,
790 _("Bad line table offset in C_EINCL directive"));
793 limit_offset
= endoffset
;
798 abfd
= objfile
->obfd
;
799 linesz
= coff_data (abfd
)->local_linesz
;
800 ext_lnno
= alloca (linesz
);
802 while (curoffset
<= limit_offset
)
804 bfd_seek (abfd
, curoffset
, SEEK_SET
);
805 bfd_bread (ext_lnno
, linesz
, abfd
);
806 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
808 /* Find the address this line represents. */
809 addr
= (int_lnno
.l_lnno
810 ? int_lnno
.l_addr
.l_paddr
811 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
812 addr
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
814 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
817 if (int_lnno
.l_lnno
== 0)
819 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
820 record_line (subfile
, 0, gdbarch_addr_bits_remove (gdbarch
, addr
));
824 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
,
825 gdbarch_addr_bits_remove (gdbarch
, addr
));
831 /* Save the vital information for use when closing off the current file.
832 NAME is the file name the symbols came from, START_ADDR is the first
833 text address for the file, and SIZE is the number of bytes of text. */
835 #define complete_symtab(name, start_addr) { \
836 last_source_file = xstrdup (name); \
837 last_source_start_addr = start_addr; \
841 /* Refill the symbol table input buffer
842 and set the variables that control fetching entries from it.
843 Reports an error if no data available.
844 This function can read past the end of the symbol table
845 (into the string table) but this does no harm. */
847 /* Reading symbol table has to be fast! Keep the followings as macros, rather
850 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
854 if (namestr[0] == '.') ++namestr; \
855 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
856 (SECTION), (asection *)NULL, (OBJFILE)); \
857 misc_func_recorded = 1; \
861 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
862 nested. At any given time, a symbol can only be in one static block.
863 This is the base address of current static block, zero if non exists. */
865 static int static_block_base
= 0;
867 /* Section number for the current static block. */
869 static int static_block_section
= -1;
871 /* true if space for symbol name has been allocated. */
873 static int symname_alloced
= 0;
875 /* Next symbol to read. Pointer into raw seething symbol table. */
877 static char *raw_symbol
;
879 /* This is the function which stabsread.c calls to get symbol
883 xcoff_next_symbol_text (struct objfile
*objfile
)
885 struct internal_syment symbol
;
887 /* FIXME: is this the same as the passed arg? */
888 if (this_symtab_psymtab
)
889 objfile
= this_symtab_psymtab
->objfile
;
891 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
894 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
896 /* Return something which points to '\0' and hope the symbol reading
897 code does something reasonable. */
900 else if (symbol
.n_sclass
& 0x80)
903 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
906 coff_data (objfile
->obfd
)->local_symesz
;
911 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
913 /* Return something which points to '\0' and hope the symbol reading
914 code does something reasonable. */
920 /* Read symbols for a given partial symbol table. */
923 read_xcoff_symtab (struct partial_symtab
*pst
)
925 struct objfile
*objfile
= pst
->objfile
;
926 bfd
*abfd
= objfile
->obfd
;
927 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
928 char *strtbl
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
;
930 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
;
931 char *debugfmt
= bfd_xcoff_is_xcoff64 (abfd
) ? "XCOFF64" : "XCOFF";
933 struct internal_syment symbol
[1];
934 union internal_auxent main_aux
;
935 struct coff_symbol cs
[1];
936 CORE_ADDR file_start_addr
= 0;
937 CORE_ADDR file_end_addr
= 0;
939 int next_file_symnum
= -1;
940 unsigned int max_symnum
;
941 int just_started
= 1;
943 int fcn_start_addr
= 0;
945 struct coff_symbol fcn_stab_saved
= { 0 };
947 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
948 union internal_auxent fcn_aux_saved
;
949 struct context_stack
*new;
951 char *filestring
= " _start_ "; /* Name of the current file. */
953 char *last_csect_name
; /* last seen csect's name and value */
954 CORE_ADDR last_csect_val
;
957 this_symtab_psymtab
= pst
;
959 /* Get the appropriate COFF "constants" related to the file we're
961 local_symesz
= coff_data (abfd
)->local_symesz
;
963 last_source_file
= NULL
;
968 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
969 record_debugformat (debugfmt
);
970 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
972 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
973 first_object_file_end
= 0;
976 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
977 + symnum
* local_symesz
;
979 while (symnum
< max_symnum
)
982 QUIT
; /* make this command interruptable. */
984 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
985 /* read one symbol into `cs' structure. After processing the
986 whole symbol table, only string table will be kept in memory,
987 symbol table and debug section of xcoff will be freed. Thus
988 we can mark symbols with names in string table as
993 /* Swap and align the symbol into a reasonable C structure. */
994 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
996 cs
->c_symnum
= symnum
;
997 cs
->c_naux
= symbol
->n_numaux
;
998 if (symbol
->n_zeroes
)
1000 symname_alloced
= 0;
1001 /* We must use the original, unswapped, name here so the name field
1002 pointed to by cs->c_name will persist throughout xcoffread. If
1003 we use the new field, it gets overwritten for each symbol. */
1004 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
1005 /* If it's exactly E_SYMNMLEN characters long it isn't
1007 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1010 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
1011 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1012 p
[E_SYMNMLEN
] = '\0';
1014 symname_alloced
= 1;
1017 else if (symbol
->n_sclass
& 0x80)
1019 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1020 symname_alloced
= 0;
1024 /* in string table */
1025 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1026 symname_alloced
= 1;
1028 cs
->c_value
= symbol
->n_value
;
1029 cs
->c_sclass
= symbol
->n_sclass
;
1030 cs
->c_secnum
= symbol
->n_scnum
;
1031 cs
->c_type
= (unsigned) symbol
->n_type
;
1033 raw_symbol
+= local_symesz
;
1036 /* Save addr of first aux entry. */
1037 raw_auxptr
= raw_symbol
;
1039 /* Skip all the auxents associated with this symbol. */
1040 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1042 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1047 /* if symbol name starts with ".$" or "$", ignore it. */
1048 if (cs
->c_name
[0] == '$'
1049 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1052 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1054 if (last_source_file
)
1057 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1062 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1063 record_debugformat (debugfmt
);
1064 cur_src_end_addr
= first_object_file_end
;
1065 /* done with all files, everything from here on is globals */
1068 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1071 /* Dealing with a symbol with a csect entry. */
1073 #define CSECT(PP) ((PP)->x_csect)
1074 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1075 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1076 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1077 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1079 /* Convert the auxent to something we can access. */
1080 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1081 0, cs
->c_naux
, &main_aux
);
1083 switch (CSECT_SMTYP (&main_aux
))
1087 /* Ignore all external references. */
1091 /* A section description. */
1093 switch (CSECT_SCLAS (&main_aux
))
1099 /* A program csect is seen. We have to allocate one
1100 symbol table for each program csect. Normally gdb
1101 prefers one symtab for each source file. In case
1102 of AIX, one source file might include more than one
1103 [PR] csect, and they don't have to be adjacent in
1104 terms of the space they occupy in memory. Thus, one
1105 single source file might get fragmented in the
1106 memory and gdb's file start and end address
1107 approach does not work! GCC (and I think xlc) seem
1108 to put all the code in the unnamed program csect. */
1110 if (last_csect_name
)
1112 complete_symtab (filestring
, file_start_addr
);
1113 cur_src_end_addr
= file_end_addr
;
1114 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1117 /* Give all csects for this source file the same
1119 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1120 record_debugformat (debugfmt
);
1123 /* If this is the very first csect seen,
1124 basically `__start'. */
1127 first_object_file_end
1128 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1133 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1134 SECT_OFF_TEXT (objfile
));
1135 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1137 if (cs
->c_name
&& (cs
->c_name
[0] == '.'
1138 || cs
->c_name
[0] == '@'))
1140 last_csect_name
= cs
->c_name
;
1141 last_csect_val
= cs
->c_value
;
1142 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1147 /* All other symbols are put into the minimal symbol
1160 /* Ignore the symbol. */
1168 switch (CSECT_SCLAS (&main_aux
))
1171 /* a function entry point. */
1172 function_entry_point
:
1174 fcn_start_addr
= cs
->c_value
;
1176 /* save the function header info, which will be used
1177 when `.bf' is seen. */
1179 fcn_aux_saved
= main_aux
;
1183 /* shared library function trampoline code entry point. */
1187 /* The symbols often have the same names as debug symbols for
1188 functions, and confuse lookup_symbol. */
1192 /* xlc puts each variable in a separate csect, so we get
1193 an XTY_SD for each variable. But gcc puts several
1194 variables in a csect, so that each variable only gets
1195 an XTY_LD. This will typically be XMC_RW; I suspect
1196 XMC_RO and XMC_BS might be possible too.
1197 These variables are put in the minimal symbol table
1204 /* Common symbols are put into the minimal symbol table only. */
1212 /* If explicitly specified as a function, treat is as one. This check
1213 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1214 after the above CSECT check. */
1215 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1217 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1218 0, cs
->c_naux
, &main_aux
);
1219 goto function_entry_point
;
1222 switch (cs
->c_sclass
)
1227 /* c_value field contains symnum of next .file entry in table
1228 or symnum of first global after last .file. */
1230 next_file_symnum
= cs
->c_value
;
1232 /* Complete symbol table for last object file containing
1233 debugging information. */
1235 /* Whether or not there was a csect in the previous file, we
1236 have to call `end_stabs' and `start_stabs' to reset
1237 type_vector, line_vector, etc. structures. */
1239 complete_symtab (filestring
, file_start_addr
);
1240 cur_src_end_addr
= file_end_addr
;
1241 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1244 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1245 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1246 standard COFF way and put it in the auxent. We use the auxent if
1247 the symbol is ".file" and an auxent exists, otherwise use the symbol
1248 itself. Simple enough. */
1249 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1251 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1252 0, cs
->c_naux
, &main_aux
);
1253 filestring
= coff_getfilename (&main_aux
, objfile
);
1256 filestring
= cs
->c_name
;
1259 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1260 record_debugformat (debugfmt
);
1261 last_csect_name
= 0;
1263 /* reset file start and end addresses. A compilation unit with no text
1264 (only data) should have zero file boundaries. */
1265 file_start_addr
= file_end_addr
= 0;
1269 fcn_stab_saved
= *cs
;
1273 if (strcmp (cs
->c_name
, ".bf") == 0)
1275 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1276 SECT_OFF_TEXT (objfile
));
1277 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1278 0, cs
->c_naux
, &main_aux
);
1280 within_function
= 1;
1282 new = push_context (0, fcn_start_addr
+ off
);
1284 new->name
= define_symbol
1285 (fcn_cs_saved
.c_value
+ off
,
1286 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1287 if (new->name
!= NULL
)
1288 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1290 else if (strcmp (cs
->c_name
, ".ef") == 0)
1293 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1294 0, cs
->c_naux
, &main_aux
);
1296 /* The value of .ef is the address of epilogue code;
1297 not useful for gdb. */
1298 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1299 contains number of lines to '}' */
1301 if (context_stack_depth
<= 0)
1302 { /* We attempted to pop an empty context stack */
1303 ef_complaint (cs
->c_symnum
);
1304 within_function
= 0;
1307 new = pop_context ();
1308 /* Stack must be empty now. */
1309 if (context_stack_depth
> 0 || new == NULL
)
1311 ef_complaint (cs
->c_symnum
);
1312 within_function
= 0;
1316 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1318 (fcn_cs_saved
.c_value
1319 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1320 + ANOFFSET (objfile
->section_offsets
,
1321 SECT_OFF_TEXT (objfile
))),
1323 within_function
= 0;
1328 /* Begin static block. */
1330 struct internal_syment symbol
;
1332 read_symbol (&symbol
, cs
->c_value
);
1333 static_block_base
= symbol
.n_value
;
1334 static_block_section
=
1335 secnum_to_section (symbol
.n_scnum
, objfile
);
1340 /* End of static block. */
1341 static_block_base
= 0;
1342 static_block_section
= -1;
1353 complaint (&symfile_complaints
, _("Unrecognized storage class %d."),
1368 /* beginning of include file */
1369 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1370 order. Thus, when wee see them, we might not know enough info
1371 to process them. Thus, we'll be saving them into a table
1372 (inclTable) and postpone their processing. */
1374 record_include_begin (cs
);
1378 /* End of include file. */
1379 /* See the comment after case C_BINCL. */
1380 record_include_end (cs
);
1384 if (strcmp (cs
->c_name
, ".bb") == 0)
1387 new = push_context (depth
,
1389 + ANOFFSET (objfile
->section_offsets
,
1390 SECT_OFF_TEXT (objfile
))));
1392 else if (strcmp (cs
->c_name
, ".eb") == 0)
1394 if (context_stack_depth
<= 0)
1395 { /* We attempted to pop an empty context stack */
1396 eb_complaint (cs
->c_symnum
);
1399 new = pop_context ();
1400 if (depth
-- != new->depth
)
1402 eb_complaint (cs
->c_symnum
);
1405 if (local_symbols
&& context_stack_depth
> 0)
1407 /* Make a block for the local symbols within. */
1408 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1411 + ANOFFSET (objfile
->section_offsets
,
1412 SECT_OFF_TEXT (objfile
))),
1415 local_symbols
= new->locals
;
1420 process_xcoff_symbol (cs
, objfile
);
1425 if (last_source_file
)
1429 complete_symtab (filestring
, file_start_addr
);
1430 cur_src_end_addr
= file_end_addr
;
1431 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1432 /* When reading symbols for the last C_FILE of the objfile, try
1433 to make sure that we set pst->symtab to the symtab for the
1434 file, not to the _globals_ symtab. I'm not sure whether this
1435 actually works right or when/if it comes up. */
1436 if (pst
->symtab
== NULL
)
1442 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1443 (SYMBOL2) = (struct symbol *) \
1444 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1445 *(SYMBOL2) = *(SYMBOL1);
1448 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1449 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->objfile_obstack))
1452 /* process one xcoff symbol. */
1454 static struct symbol
*
1455 process_xcoff_symbol (struct coff_symbol
*cs
, struct objfile
*objfile
)
1457 struct symbol onesymbol
;
1458 struct symbol
*sym
= &onesymbol
;
1459 struct symbol
*sym2
= NULL
;
1465 if (cs
->c_secnum
< 0)
1467 /* The value is a register number, offset within a frame, etc.,
1468 and does not get relocated. */
1474 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1475 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1482 memset (sym
, '\0', sizeof (struct symbol
));
1484 /* default assumptions */
1485 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1486 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1487 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1489 if (ISFCN (cs
->c_type
))
1491 /* At this point, we don't know the type of the function. This
1492 will be patched with the type from its stab entry later on in
1493 patch_block_stabs (), unless the file was compiled without -g. */
1495 SYMBOL_SET_LINKAGE_NAME (sym
, SYMNAME_ALLOC (name
, symname_alloced
));
1496 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_text_symbol
;
1498 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1499 SYMBOL_DUP (sym
, sym2
);
1501 if (cs
->c_sclass
== C_EXT
)
1502 add_symbol_to_list (sym2
, &global_symbols
);
1503 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1504 add_symbol_to_list (sym2
, &file_symbols
);
1508 /* In case we can't figure out the type, provide default. */
1509 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_data_symbol
;
1511 switch (cs
->c_sclass
)
1514 /* The values of functions and global symbols are now resolved
1515 via the global_sym_chain in stabsread.c. */
1517 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1518 add_stab_to_list (name
, &global_stabs
);
1520 add_stab_to_list (name
, &file_stabs
);
1524 add_stab_to_list (name
, &global_stabs
);
1529 common_block_start (cs
->c_name
, objfile
);
1533 common_block_end (objfile
);
1537 complaint (&symfile_complaints
, _("Unexpected storage class: %d"),
1550 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1553 SYMBOL_SECTION (sym
) = sec
;
1560 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1561 all statics and we need to distinguish file-scope versus
1562 function-scope using within_function. We do this by
1563 changing the string we pass to define_symbol to use 'S'
1564 where we need to, which is not necessarily super-clean,
1565 but seems workable enough. */
1567 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1571 if (*pp
== 'V' && !within_function
)
1573 sym
= define_symbol ((cs
->c_value
1574 + ANOFFSET (objfile
->section_offsets
,
1575 static_block_section
)),
1576 cs
->c_name
, 0, 0, objfile
);
1579 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1580 SYMBOL_SECTION (sym
) = static_block_section
;
1589 /* Extract the file name from the aux entry of a C_FILE symbol.
1590 Result is in static storage and is only good for temporary use. */
1593 coff_getfilename (union internal_auxent
*aux_entry
, struct objfile
*objfile
)
1595 static char buffer
[BUFSIZ
];
1597 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1599 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
1600 + aux_entry
->x_file
.x_n
.x_offset
);
1603 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1604 buffer
[FILNMLEN
] = '\0';
1609 /* Set *SYMBOL to symbol number symno in symtbl. */
1611 read_symbol (struct internal_syment
*symbol
, int symno
)
1614 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl_num_syms
;
1616 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl
;
1617 if (symno
< 0 || symno
>= nsyms
)
1619 complaint (&symfile_complaints
, _("Invalid symbol offset"));
1620 symbol
->n_value
= 0;
1621 symbol
->n_scnum
= -1;
1624 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1625 stbl
+ (symno
* local_symesz
),
1629 /* Get value corresponding to symbol number symno in symtbl. */
1632 read_symbol_nvalue (int symno
)
1634 struct internal_syment symbol
[1];
1636 read_symbol (symbol
, symno
);
1637 return symbol
->n_value
;
1641 /* Find the address of the function corresponding to symno, where
1642 symno is the symbol pointed to by the linetable. */
1645 read_symbol_lineno (int symno
)
1647 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1648 int xcoff64
= bfd_xcoff_is_xcoff64 (objfile
->obfd
);
1650 struct coff_symfile_info
*info
=
1651 (struct coff_symfile_info
*)objfile
->deprecated_sym_private
;
1652 int nsyms
= info
->symtbl_num_syms
;
1653 char *stbl
= info
->symtbl
;
1654 char *strtbl
= info
->strtbl
;
1656 struct internal_syment symbol
[1];
1657 union internal_auxent main_aux
[1];
1661 bf_notfound_complaint ();
1665 /* Note that just searching for a short distance (e.g. 50 symbols)
1666 is not enough, at least in the following case.
1669 [many .stabx entries]
1670 [a few functions, referring to foo]
1674 What happens here is that the assembler moves the .stabx entries
1675 to right before the ".bf" for foo, but the symbol for "foo" is before
1676 all the stabx entries. See PR gdb/2222. */
1678 /* Maintaining a table of .bf entries might be preferable to this search.
1679 If I understand things correctly it would need to be done only for
1680 the duration of a single psymtab to symtab conversion. */
1681 while (symno
< nsyms
)
1683 bfd_coff_swap_sym_in (symfile_bfd
,
1684 stbl
+ (symno
* local_symesz
), symbol
);
1685 if (symbol
->n_sclass
== C_FCN
)
1687 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1688 if (strcmp (name
, ".bf") == 0)
1691 symno
+= symbol
->n_numaux
+ 1;
1694 bf_notfound_complaint ();
1698 /* take aux entry and return its lineno */
1700 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1701 symbol
->n_type
, symbol
->n_sclass
,
1702 0, symbol
->n_numaux
, main_aux
);
1704 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1707 /* Support for line number handling */
1709 /* This function is called for every section; it finds the outer limits
1710 * of the line table (minimum and maximum file offset) so that the
1711 * mainline code can read the whole thing for efficiency.
1714 find_linenos (struct bfd
*abfd
, struct bfd_section
*asect
, void *vpinfo
)
1716 struct coff_symfile_info
*info
;
1718 file_ptr offset
, maxoff
;
1720 count
= asect
->lineno_count
;
1722 if (strcmp (asect
->name
, ".text") != 0 || count
== 0)
1725 size
= count
* coff_data (abfd
)->local_linesz
;
1726 info
= (struct coff_symfile_info
*) vpinfo
;
1727 offset
= asect
->line_filepos
;
1728 maxoff
= offset
+ size
;
1730 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1731 info
->min_lineno_offset
= offset
;
1733 if (maxoff
> info
->max_lineno_offset
)
1734 info
->max_lineno_offset
= maxoff
;
1737 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1740 xcoff_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1742 struct cleanup
*old_chain
;
1751 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1756 /* Read in all partial symtabs on which this one is dependent */
1757 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1758 if (!pst
->dependencies
[i
]->readin
)
1760 /* Inform about additional files that need to be read in. */
1763 fputs_filtered (" ", gdb_stdout
);
1765 fputs_filtered ("and ", gdb_stdout
);
1767 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1768 wrap_here (""); /* Flush output */
1769 gdb_flush (gdb_stdout
);
1771 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1774 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1776 /* Init stuff necessary for reading in symbols. */
1779 old_chain
= make_cleanup (really_free_pendings
, 0);
1781 read_xcoff_symtab (pst
);
1783 do_cleanups (old_chain
);
1789 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1791 /* Read in all of the symbols for a given psymtab for real.
1792 Be verbose about it if the user wants that. */
1795 xcoff_psymtab_to_symtab (struct partial_symtab
*pst
)
1805 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1810 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1811 || pst
->number_of_dependencies
)
1813 /* Print the message now, before reading the string table,
1814 to avoid disconcerting pauses. */
1817 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1818 gdb_flush (gdb_stdout
);
1821 sym_bfd
= pst
->objfile
->obfd
;
1823 next_symbol_text_func
= xcoff_next_symbol_text
;
1825 xcoff_psymtab_to_symtab_1 (pst
);
1827 /* Match with global symbols. This only needs to be done once,
1828 after all of the symtabs and dependencies have been read in. */
1829 scan_file_globals (pst
->objfile
);
1831 /* Finish up the debug error message. */
1833 printf_filtered ("done.\n");
1838 xcoff_new_init (struct objfile
*objfile
)
1840 stabsread_new_init ();
1841 buildsym_new_init ();
1844 /* Do initialization in preparation for reading symbols from OBJFILE.
1846 We will only be called if this is an XCOFF or XCOFF-like file.
1847 BFD handles figuring out the format of the file, and code in symfile.c
1848 uses BFD's determination to vector to us. */
1851 xcoff_symfile_init (struct objfile
*objfile
)
1853 /* Allocate struct to keep track of the symfile */
1854 objfile
->deprecated_sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
1856 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1857 find this causes a significant slowdown in gdb then we could
1858 set it in the debug symbol readers only when necessary. */
1859 objfile
->flags
|= OBJF_REORDERED
;
1861 init_entry_point_info (objfile
);
1864 /* Perform any local cleanups required when we are done with a particular
1865 objfile. I.E, we are in the process of discarding all symbol information
1866 for an objfile, freeing up all memory held for it, and unlinking the
1867 objfile struct from the global list of known objfiles. */
1870 xcoff_symfile_finish (struct objfile
*objfile
)
1872 if (objfile
->deprecated_sym_private
!= NULL
)
1874 xfree (objfile
->deprecated_sym_private
);
1877 /* Start with a fresh include table for the next objfile. */
1883 inclIndx
= inclLength
= inclDepth
= 0;
1888 init_stringtab (bfd
*abfd
, file_ptr offset
, struct objfile
*objfile
)
1892 unsigned char lengthbuf
[4];
1895 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
= NULL
;
1897 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1898 error (_("cannot seek to string table in %s: %s"),
1899 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1901 val
= bfd_bread ((char *) lengthbuf
, sizeof lengthbuf
, abfd
);
1902 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1904 /* If no string table is needed, then the file may end immediately
1905 after the symbols. Just return with `strtbl' set to NULL. */
1907 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1910 /* Allocate string table from objfile_obstack. We will need this table
1911 as long as we have its symbol table around. */
1913 strtbl
= (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
1914 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
= strtbl
;
1916 /* Copy length buffer, the first byte is usually zero and is
1917 used for stabs with a name length of zero. */
1918 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1919 if (length
== sizeof lengthbuf
)
1922 val
= bfd_bread (strtbl
+ sizeof lengthbuf
, length
- sizeof lengthbuf
, abfd
);
1924 if (val
!= length
- sizeof lengthbuf
)
1925 error (_("cannot read string table from %s: %s"),
1926 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1927 if (strtbl
[length
- 1] != '\0')
1928 error (_("bad symbol file: string table does not end with null character"));
1933 /* If we have not yet seen a function for this psymtab, this is 0. If we
1934 have seen one, it is the offset in the line numbers of the line numbers
1936 static unsigned int first_fun_line_offset
;
1938 static struct partial_symtab
*xcoff_start_psymtab
1939 (struct objfile
*, char *, int,
1940 struct partial_symbol
**, struct partial_symbol
**);
1942 /* Allocate and partially fill a partial symtab. It will be
1943 completely filled at the end of the symbol list.
1945 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1946 is the address relative to which its symbols are (incremental) or 0
1949 static struct partial_symtab
*
1950 xcoff_start_psymtab (struct objfile
*objfile
, char *filename
, int first_symnum
,
1951 struct partial_symbol
**global_syms
,
1952 struct partial_symbol
**static_syms
)
1954 struct partial_symtab
*result
=
1955 start_psymtab_common (objfile
, objfile
->section_offsets
,
1957 /* We fill in textlow later. */
1959 global_syms
, static_syms
);
1961 result
->read_symtab_private
= (char *)
1962 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct symloc
));
1963 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
1964 result
->read_symtab
= xcoff_psymtab_to_symtab
;
1966 /* Deduce the source language from the filename for this psymtab. */
1967 psymtab_language
= deduce_language_from_filename (filename
);
1972 static struct partial_symtab
*xcoff_end_psymtab
1973 (struct partial_symtab
*, char **, int, int,
1974 struct partial_symtab
**, int, int);
1976 /* Close off the current usage of PST.
1977 Returns PST, or NULL if the partial symtab was empty and thrown away.
1979 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
1981 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
1982 are the information for includes and dependencies. */
1984 static struct partial_symtab
*
1985 xcoff_end_psymtab (struct partial_symtab
*pst
, char **include_list
,
1986 int num_includes
, int capping_symbol_number
,
1987 struct partial_symtab
**dependency_list
,
1988 int number_dependencies
, int textlow_not_set
)
1991 struct objfile
*objfile
= pst
->objfile
;
1993 if (capping_symbol_number
!= -1)
1994 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
1995 capping_symbol_number
1996 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
1997 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
1998 first_fun_line_offset
;
1999 first_fun_line_offset
= 0;
2000 pst
->n_global_syms
=
2001 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2002 pst
->n_static_syms
=
2003 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2005 pst
->number_of_dependencies
= number_dependencies
;
2006 if (number_dependencies
)
2008 pst
->dependencies
= (struct partial_symtab
**)
2009 obstack_alloc (&objfile
->objfile_obstack
,
2010 number_dependencies
* sizeof (struct partial_symtab
*));
2011 memcpy (pst
->dependencies
, dependency_list
,
2012 number_dependencies
* sizeof (struct partial_symtab
*));
2015 pst
->dependencies
= 0;
2017 for (i
= 0; i
< num_includes
; i
++)
2019 struct partial_symtab
*subpst
=
2020 allocate_psymtab (include_list
[i
], objfile
);
2022 subpst
->section_offsets
= pst
->section_offsets
;
2023 subpst
->read_symtab_private
=
2024 (char *) obstack_alloc (&objfile
->objfile_obstack
,
2025 sizeof (struct symloc
));
2026 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2027 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2028 subpst
->textlow
= 0;
2029 subpst
->texthigh
= 0;
2031 /* We could save slight bits of space by only making one of these,
2032 shared by the entire set of include files. FIXME-someday. */
2033 subpst
->dependencies
= (struct partial_symtab
**)
2034 obstack_alloc (&objfile
->objfile_obstack
,
2035 sizeof (struct partial_symtab
*));
2036 subpst
->dependencies
[0] = pst
;
2037 subpst
->number_of_dependencies
= 1;
2039 subpst
->globals_offset
=
2040 subpst
->n_global_syms
=
2041 subpst
->statics_offset
=
2042 subpst
->n_static_syms
= 0;
2046 subpst
->read_symtab
= pst
->read_symtab
;
2049 sort_pst_symbols (pst
);
2051 /* If there is already a psymtab or symtab for a file of this name,
2052 remove it. (If there is a symtab, more drastic things also
2053 happen.) This happens in VxWorks. */
2054 free_named_symtabs (pst
->filename
);
2056 if (num_includes
== 0
2057 && number_dependencies
== 0
2058 && pst
->n_global_syms
== 0
2059 && pst
->n_static_syms
== 0)
2061 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2062 it is on the obstack, but we can forget to chain it on the list. */
2063 /* Empty psymtabs happen as a result of header files which don't have
2064 any symbols in them. There can be a lot of them. */
2066 discard_psymtab (pst
);
2068 /* Indicate that psymtab was thrown away. */
2069 pst
= (struct partial_symtab
*) NULL
;
2074 static void swap_sym (struct internal_syment
*,
2075 union internal_auxent
*, char **, char **,
2076 unsigned int *, struct objfile
*);
2078 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2079 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2080 the symbol and its auxents. */
2083 swap_sym (struct internal_syment
*symbol
, union internal_auxent
*aux
,
2084 char **name
, char **raw
, unsigned int *symnump
,
2085 struct objfile
*objfile
)
2087 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2088 if (symbol
->n_zeroes
)
2090 /* If it's exactly E_SYMNMLEN characters long it isn't
2092 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2094 /* FIXME: wastes memory for symbols which we don't end up putting
2095 into the minimal symbols. */
2097 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
2098 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2099 p
[E_SYMNMLEN
] = '\0';
2103 /* Point to the unswapped name as that persists as long as the
2105 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2107 else if (symbol
->n_sclass
& 0x80)
2109 *name
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
2114 *name
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
2118 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2119 if (symbol
->n_numaux
> 0)
2121 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2122 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2124 *symnump
+= symbol
->n_numaux
;
2125 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2130 function_outside_compilation_unit_complaint (const char *arg1
)
2132 complaint (&symfile_complaints
,
2133 _("function `%s' appears to be defined outside of all compilation units"),
2138 scan_xcoff_symtab (struct objfile
*objfile
)
2140 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2141 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2142 char *filestring
= NULL
;
2145 int past_first_source_file
= 0;
2150 /* Current partial symtab */
2151 struct partial_symtab
*pst
;
2153 /* List of current psymtab's include files */
2154 char **psymtab_include_list
;
2155 int includes_allocated
;
2158 /* Index within current psymtab dependency list */
2159 struct partial_symtab
**dependency_list
;
2160 int dependencies_used
, dependencies_allocated
;
2163 struct internal_syment symbol
;
2164 union internal_auxent main_aux
[5];
2165 unsigned int ssymnum
;
2167 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2168 CORE_ADDR last_csect_val
= 0;
2169 int last_csect_sec
= 0;
2170 int misc_func_recorded
= 0; /* true if any misc. function */
2171 int textlow_not_set
= 1;
2173 pst
= (struct partial_symtab
*) 0;
2175 includes_allocated
= 30;
2177 psymtab_include_list
= (char **) alloca (includes_allocated
*
2180 dependencies_allocated
= 30;
2181 dependencies_used
= 0;
2183 (struct partial_symtab
**) alloca (dependencies_allocated
*
2184 sizeof (struct partial_symtab
*));
2186 last_source_file
= NULL
;
2188 abfd
= objfile
->obfd
;
2189 next_symbol_text_func
= xcoff_next_symbol_text
;
2191 sraw_symbol
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
;
2192 nsyms
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl_num_syms
;
2194 while (ssymnum
< nsyms
)
2200 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2201 sclass
= symbol
.n_sclass
;
2208 /* The CSECT auxent--always the last auxent. */
2209 union internal_auxent csect_aux
;
2210 unsigned int symnum_before
= ssymnum
;
2212 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2214 if (symbol
.n_numaux
> 1)
2216 bfd_coff_swap_aux_in
2218 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2221 symbol
.n_numaux
- 1,
2226 csect_aux
= main_aux
[0];
2228 /* If symbol name starts with ".$" or "$", ignore it. */
2229 if (namestring
[0] == '$'
2230 || (namestring
[0] == '.' && namestring
[1] == '$'))
2233 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2236 switch (csect_aux
.x_csect
.x_smclas
)
2239 if (last_csect_name
)
2241 /* If no misc. function recorded in the last
2242 seen csect, enter it as a function. This
2243 will take care of functions like strcmp()
2246 if (!misc_func_recorded
)
2248 RECORD_MINIMAL_SYMBOL
2249 (last_csect_name
, last_csect_val
,
2250 mst_text
, last_csect_sec
,
2256 /* We have to allocate one psymtab for
2257 each program csect, because their text
2258 sections need not be adjacent. */
2260 (pst
, psymtab_include_list
, includes_used
,
2261 symnum_before
, dependency_list
,
2262 dependencies_used
, textlow_not_set
);
2264 dependencies_used
= 0;
2265 /* Give all psymtabs for this source file the same
2267 pst
= xcoff_start_psymtab
2271 objfile
->global_psymbols
.next
,
2272 objfile
->static_psymbols
.next
);
2275 /* Activate the misc_func_recorded mechanism for
2276 compiler- and linker-generated CSECTs like ".strcmp"
2278 if (namestring
&& (namestring
[0] == '.'
2279 || namestring
[0] == '@'))
2281 last_csect_name
= namestring
;
2282 last_csect_val
= symbol
.n_value
;
2284 secnum_to_section (symbol
.n_scnum
, objfile
);
2289 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2290 if (highval
> pst
->texthigh
)
2291 pst
->texthigh
= highval
;
2292 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2293 pst
->textlow
= symbol
.n_value
;
2295 misc_func_recorded
= 0;
2300 /* Data variables are recorded in the minimal symbol
2301 table, except for section symbols. */
2302 if (*namestring
!= '.')
2303 prim_record_minimal_symbol_and_info
2304 (namestring
, symbol
.n_value
,
2305 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2306 secnum_to_section (symbol
.n_scnum
, objfile
),
2312 warning (_("More than one XMC_TC0 symbol found."));
2313 toc_offset
= symbol
.n_value
;
2315 /* Make TOC offset relative to start address of section. */
2316 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2318 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2322 /* These symbols tell us where the TOC entry for a
2323 variable is, not the variable itself. */
2332 switch (csect_aux
.x_csect
.x_smclas
)
2335 /* A function entry point. */
2337 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2338 first_fun_line_offset
=
2339 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2340 RECORD_MINIMAL_SYMBOL
2341 (namestring
, symbol
.n_value
,
2342 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2343 secnum_to_section (symbol
.n_scnum
, objfile
),
2348 /* shared library function trampoline code entry
2351 /* record trampoline code entries as
2352 mst_solib_trampoline symbol. When we lookup mst
2353 symbols, we will choose mst_text over
2354 mst_solib_trampoline. */
2355 RECORD_MINIMAL_SYMBOL
2356 (namestring
, symbol
.n_value
,
2357 mst_solib_trampoline
,
2358 secnum_to_section (symbol
.n_scnum
, objfile
),
2363 /* The symbols often have the same names as
2364 debug symbols for functions, and confuse
2370 /* xlc puts each variable in a separate csect,
2371 so we get an XTY_SD for each variable. But
2372 gcc puts several variables in a csect, so
2373 that each variable only gets an XTY_LD. We
2374 still need to record them. This will
2375 typically be XMC_RW; I suspect XMC_RO and
2376 XMC_BS might be possible too. */
2377 if (*namestring
!= '.')
2378 prim_record_minimal_symbol_and_info
2379 (namestring
, symbol
.n_value
,
2380 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2381 secnum_to_section (symbol
.n_scnum
, objfile
),
2388 switch (csect_aux
.x_csect
.x_smclas
)
2392 /* Common variables are recorded in the minimal symbol
2393 table, except for section symbols. */
2394 if (*namestring
!= '.')
2395 prim_record_minimal_symbol_and_info
2396 (namestring
, symbol
.n_value
,
2397 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2398 secnum_to_section (symbol
.n_scnum
, objfile
),
2411 unsigned int symnum_before
;
2413 symnum_before
= ssymnum
;
2414 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2417 /* See if the last csect needs to be recorded. */
2419 if (last_csect_name
&& !misc_func_recorded
)
2422 /* If no misc. function recorded in the last seen csect, enter
2423 it as a function. This will take care of functions like
2424 strcmp() compiled by xlc. */
2426 RECORD_MINIMAL_SYMBOL
2427 (last_csect_name
, last_csect_val
,
2428 mst_text
, last_csect_sec
, objfile
);
2433 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2434 symnum_before
, dependency_list
,
2435 dependencies_used
, textlow_not_set
);
2437 dependencies_used
= 0;
2439 first_fun_line_offset
= 0;
2441 /* XCOFF, according to the AIX 3.2 documentation, puts the
2442 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2443 do things the standard COFF way and put it in the auxent.
2444 We use the auxent if the symbol is ".file" and an auxent
2445 exists, otherwise use the symbol itself. */
2446 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2448 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2451 filestring
= namestring
;
2453 pst
= xcoff_start_psymtab (objfile
,
2456 objfile
->global_psymbols
.next
,
2457 objfile
->static_psymbols
.next
);
2458 last_csect_name
= NULL
;
2464 complaint (&symfile_complaints
,
2465 _("Storage class %d not recognized during scan"), sclass
);
2469 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2470 to handle only the C_FUN and C_EXT. */
2485 /* C_EINCL means we are switching back to the main file. But there
2486 is no reason to care; the only thing we want to know about
2487 includes is the names of all the included (.h) files. */
2492 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2496 /* I don't think the name of the common block (as opposed to the
2497 variables within it) is something which is user visible
2505 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2506 so C_LSYM would appear to be only for locals. */
2512 /* We probably could save a few instructions by assuming that
2513 C_LSYM, C_PSYM, etc., never have auxents. */
2514 int naux1
= symbol
.n_numaux
+ 1;
2516 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2522 /* Mark down an include file in the current psymtab */
2523 enum language tmp_language
;
2524 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2527 tmp_language
= deduce_language_from_filename (namestring
);
2529 /* Only change the psymtab's language if we've learned
2530 something useful (eg. tmp_language is not language_unknown).
2531 In addition, to match what start_subfile does, never change
2533 if (tmp_language
!= language_unknown
2534 && (tmp_language
!= language_c
2535 || psymtab_language
!= language_cplus
))
2536 psymtab_language
= tmp_language
;
2538 /* In C++, one may expect the same filename to come round many
2539 times, when code is coming alternately from the main file
2540 and from inline functions in other files. So I check to see
2541 if this is a file we've seen before -- either the main
2542 source file, or a previously included file.
2544 This seems to be a lot of time to be spending on N_SOL, but
2545 things like "break c-exp.y:435" need to work (I
2546 suppose the psymtab_include_list could be hashed or put
2547 in a binary tree, if profiling shows this is a major hog). */
2548 if (pst
&& strcmp (namestring
, pst
->filename
) == 0)
2552 for (i
= 0; i
< includes_used
; i
++)
2553 if (strcmp (namestring
, psymtab_include_list
[i
]) == 0)
2561 psymtab_include_list
[includes_used
++] = namestring
;
2562 if (includes_used
>= includes_allocated
)
2564 char **orig
= psymtab_include_list
;
2566 psymtab_include_list
= (char **)
2567 alloca ((includes_allocated
*= 2) *
2569 memcpy (psymtab_include_list
, orig
,
2570 includes_used
* sizeof (char *));
2575 /* The value of the C_FUN is not the address of the function (it
2576 appears to be the address before linking), but as long as it
2577 is smaller than the actual address, then find_pc_partial_function
2578 will use the minimal symbols instead. I hope. */
2586 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2589 p
= (char *) strchr (namestring
, ':');
2591 continue; /* Not a debugging symbol. */
2593 /* Main processing section for debugging symbols which
2594 the initial read through the symbol tables needs to worry
2595 about. If we reach this point, the symbol which we are
2596 considering is definitely one we are interested in.
2597 p must also contain the (valid) index into the namestring
2598 which indicates the debugging type symbol. */
2603 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2605 if (gdbarch_static_transform_name_p (gdbarch
))
2606 namestring
= gdbarch_static_transform_name
2607 (gdbarch
, namestring
);
2609 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2610 VAR_DOMAIN
, LOC_STATIC
,
2611 &objfile
->static_psymbols
,
2613 psymtab_language
, objfile
);
2617 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2618 /* The addresses in these entries are reported to be
2619 wrong. See the code that reads 'G's for symtabs. */
2620 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2621 VAR_DOMAIN
, LOC_STATIC
,
2622 &objfile
->global_psymbols
,
2624 psymtab_language
, objfile
);
2628 /* When a 'T' entry is defining an anonymous enum, it
2629 may have a name which is the empty string, or a
2630 single space. Since they're not really defining a
2631 symbol, those shouldn't go in the partial symbol
2632 table. We do pick up the elements of such enums at
2633 'check_enum:', below. */
2634 if (p
>= namestring
+ 2
2635 || (p
== namestring
+ 1
2636 && namestring
[0] != ' '))
2638 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2639 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2640 &objfile
->static_psymbols
,
2642 psymtab_language
, objfile
);
2645 /* Also a typedef with the same name. */
2646 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2647 VAR_DOMAIN
, LOC_TYPEDEF
,
2648 &objfile
->static_psymbols
,
2650 psymtab_language
, objfile
);
2657 if (p
!= namestring
) /* a name is there, not just :T... */
2659 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2660 VAR_DOMAIN
, LOC_TYPEDEF
,
2661 &objfile
->static_psymbols
,
2663 psymtab_language
, objfile
);
2666 /* If this is an enumerated type, we need to
2667 add all the enum constants to the partial symbol
2668 table. This does not cover enums without names, e.g.
2669 "enum {a, b} c;" in C, but fortunately those are
2670 rare. There is no way for GDB to find those from the
2671 enum type without spending too much time on it. Thus
2672 to solve this problem, the compiler needs to put out the
2673 enum in a nameless type. GCC2 does this. */
2675 /* We are looking for something of the form
2676 <name> ":" ("t" | "T") [<number> "="] "e"
2677 {<constant> ":" <value> ","} ";". */
2679 /* Skip over the colon and the 't' or 'T'. */
2681 /* This type may be given a number. Also, numbers can come
2682 in pairs like (0,26). Skip over it. */
2683 while ((*p
>= '0' && *p
<= '9')
2684 || *p
== '(' || *p
== ',' || *p
== ')'
2690 /* The aix4 compiler emits extra crud before the members. */
2693 /* Skip over the type (?). */
2697 /* Skip over the colon. */
2701 /* We have found an enumerated type. */
2702 /* According to comments in read_enum_type
2703 a comma could end it instead of a semicolon.
2704 I don't know where that happens.
2706 while (*p
&& *p
!= ';' && *p
!= ',')
2710 /* Check for and handle cretinous dbx symbol name
2712 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
2713 p
= next_symbol_text (objfile
);
2715 /* Point to the character after the name
2716 of the enum constant. */
2717 for (q
= p
; *q
&& *q
!= ':'; q
++)
2719 /* Note that the value doesn't matter for
2720 enum constants in psymtabs, just in symtabs. */
2721 add_psymbol_to_list (p
, q
- p
, 1,
2722 VAR_DOMAIN
, LOC_CONST
,
2723 &objfile
->static_psymbols
, 0,
2724 0, psymtab_language
, objfile
);
2725 /* Point past the name. */
2727 /* Skip over the value. */
2728 while (*p
&& *p
!= ',')
2730 /* Advance past the comma. */
2738 /* Constant, e.g. from "const" in Pascal. */
2739 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2740 VAR_DOMAIN
, LOC_CONST
,
2741 &objfile
->static_psymbols
, symbol
.n_value
,
2742 0, psymtab_language
, objfile
);
2748 int name_len
= p
- namestring
;
2749 char *name
= xmalloc (name_len
+ 1);
2750 memcpy (name
, namestring
, name_len
);
2751 name
[name_len
] = '\0';
2752 function_outside_compilation_unit_complaint (name
);
2755 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2756 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2757 VAR_DOMAIN
, LOC_BLOCK
,
2758 &objfile
->static_psymbols
,
2760 psymtab_language
, objfile
);
2763 /* Global functions were ignored here, but now they
2764 are put into the global psymtab like one would expect.
2765 They're also in the minimal symbol table. */
2769 int name_len
= p
- namestring
;
2770 char *name
= xmalloc (name_len
+ 1);
2771 memcpy (name
, namestring
, name_len
);
2772 name
[name_len
] = '\0';
2773 function_outside_compilation_unit_complaint (name
);
2777 /* We need only the minimal symbols for these
2778 loader-generated definitions. Keeping the global
2779 symbols leads to "in psymbols but not in symbols"
2781 if (strncmp (namestring
, "@FIX", 4) == 0)
2784 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2785 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2786 VAR_DOMAIN
, LOC_BLOCK
,
2787 &objfile
->global_psymbols
,
2789 psymtab_language
, objfile
);
2792 /* Two things show up here (hopefully); static symbols of
2793 local scope (static used inside braces) or extensions
2794 of structure symbols. We can ignore both. */
2808 case '#': /* for symbol identification (used in live ranges) */
2812 /* It is a C++ nested symbol. We don't need to record it
2813 (I don't think); if we try to look up foo::bar::baz,
2814 then symbols for the symtab containing foo should get
2815 read in, I think. */
2816 /* Someone says sun cc puts out symbols like
2817 /foo/baz/maclib::/usr/local/bin/maclib,
2818 which would get here with a symbol type of ':'. */
2822 /* Unexpected symbol descriptor. The second and subsequent stabs
2823 of a continued stab can show up here. The question is
2824 whether they ever can mimic a normal stab--it would be
2825 nice if not, since we certainly don't want to spend the
2826 time searching to the end of every string looking for
2829 complaint (&symfile_complaints
,
2830 _("unknown symbol descriptor `%c'"), p
[1]);
2832 /* Ignore it; perhaps it is an extension that we don't
2842 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2843 ssymnum
, dependency_list
,
2844 dependencies_used
, textlow_not_set
);
2847 /* Record the toc offset value of this symbol table into objfile structure.
2848 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2849 this information would be file auxiliary header. */
2851 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
= toc_offset
;
2854 /* Return the toc offset value for a given objfile. */
2857 xcoff_get_toc_offset (struct objfile
*objfile
)
2860 return ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
;
2864 /* Scan and build partial symbols for a symbol file.
2865 We have been initialized by a call to dbx_symfile_init, which
2866 put all the relevant info into a "struct dbx_symfile_info",
2867 hung off the objfile structure.
2869 SECTION_OFFSETS contains offsets relative to which the symbols in the
2870 various sections are (depending where the sections were actually loaded).
2874 xcoff_initial_scan (struct objfile
*objfile
, int symfile_flags
)
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
->deprecated_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. */
2906 struct bfd_section
*secp
;
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
->objfile_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
->deprecated_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
->deprecated_sym_private
)->symtbl
=
2940 obstack_alloc (&objfile
->objfile_obstack
, size
);
2941 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl_num_syms
=
2944 val
= bfd_bread (((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
,
2947 perror_with_name (_("reading symbol table"));
2949 /* If we are reinitializing, or if we have never loaded syms yet, init */
2950 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2951 /* I'm not sure how how good num_symbols is; the rule of thumb in
2952 init_psymbol_list was developed for a.out. On the one hand,
2953 num_symbols includes auxents. On the other hand, it doesn't
2955 init_psymbol_list (objfile
, num_symbols
);
2957 free_pending_blocks ();
2958 back_to
= make_cleanup (really_free_pendings
, 0);
2960 init_minimal_symbol_collection ();
2961 make_cleanup_discard_minimal_symbols ();
2963 /* Now that the symbol table data of the executable file are all in core,
2964 process them and define symbols accordingly. */
2966 scan_xcoff_symtab (objfile
);
2968 /* Install any minimal symbols that have been collected as the current
2969 minimal symbols for this objfile. */
2971 install_minimal_symbols (objfile
);
2973 do_cleanups (back_to
);
2977 xcoff_symfile_offsets (struct objfile
*objfile
, struct section_addr_info
*addrs
)
2979 asection
*sect
= NULL
;
2982 objfile
->num_sections
= bfd_count_sections (objfile
->obfd
);
2983 objfile
->section_offsets
= (struct section_offsets
*)
2984 obstack_alloc (&objfile
->objfile_obstack
,
2985 SIZEOF_N_SECTION_OFFSETS (objfile
->num_sections
));
2987 /* Initialize the section indexes for future use. */
2988 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
2990 objfile
->sect_index_text
= sect
->index
;
2992 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
2994 objfile
->sect_index_data
= sect
->index
;
2996 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
2998 objfile
->sect_index_bss
= sect
->index
;
3000 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
3002 objfile
->sect_index_rodata
= sect
->index
;
3004 for (i
= 0; i
< objfile
->num_sections
; ++i
)
3006 /* syms_from_objfile kindly subtracts from addr the
3007 bfd_section_vma of the .text section. This strikes me as
3008 wrong--whether the offset to be applied to symbol reading is
3009 relative to the start address of the section depends on the
3010 symbol format. In any event, this whole "addr" concept is
3011 pretty broken (it doesn't handle any section but .text
3012 sensibly), so just ignore the addr parameter and use 0.
3013 rs6000-nat.c will set the correct section offsets via
3014 objfile_relocate. */
3015 (objfile
->section_offsets
)->offsets
[i
] = 0;
3019 /* Register our ability to parse symbols for xcoff BFD files. */
3021 static struct sym_fns xcoff_sym_fns
=
3024 /* It is possible that coff and xcoff should be merged as
3025 they do have fundamental similarities (for example, the extra storage
3026 classes used for stabs could presumably be recognized in any COFF file).
3027 However, in addition to obvious things like all the csect hair, there are
3028 some subtler differences between xcoffread.c and coffread.c, notably
3029 the fact that coffread.c has no need to read in all the symbols, but
3030 xcoffread.c reads all the symbols and does in fact randomly access them
3031 (in C_BSTAT and line number processing). */
3033 bfd_target_xcoff_flavour
,
3035 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3036 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3037 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
3038 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3039 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
3040 default_symfile_segments
, /* sym_segments: Get segment information from
3042 aix_process_linenos
, /* sym_read_linetable */
3043 NULL
/* next: pointer to next struct sym_fns */
3046 /* Provide a prototype to silence -Wmissing-prototypes. */
3047 extern initialize_file_ftype _initialize_xcoffread
;
3050 _initialize_xcoffread (void)
3052 add_symtab_fns (&xcoff_sym_fns
);