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 2010 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"
55 #include "gdb-stabs.h"
57 /* For interface with stabsread.c. */
58 #include "aout/stab_gnu.h"
61 /* We put a pointer to this structure in the read_symtab_private field
67 /* First symbol number for this file. */
71 /* Number of symbols in the section of the symbol table devoted to
72 this file's symbols (actually, the section bracketed may contain
73 more than just this file's symbols). If numsyms is 0, the only
74 reason for this thing's existence is the dependency list. Nothing
75 else will happen when it is read in. */
79 /* Position of the start of the line number information for this psymtab. */
80 unsigned int lineno_off
;
83 /* Remember what we deduced to be the source language of this psymtab. */
85 static enum language psymtab_language
= language_unknown
;
88 /* Simplified internal version of coff symbol table information */
93 int c_symnum
; /* symbol number of this entry */
94 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
96 unsigned char c_sclass
;
101 /* last function's saved coff symbol `cs' */
103 static struct coff_symbol fcn_cs_saved
;
105 static bfd
*symfile_bfd
;
107 /* Core address of start and end of text of current source file.
108 This is calculated from the first function seen after a C_FILE
112 static CORE_ADDR cur_src_end_addr
;
114 /* Core address of the end of the first object file. */
116 static CORE_ADDR first_object_file_end
;
118 /* initial symbol-table-debug-string vector length */
120 #define INITIAL_STABVECTOR_LENGTH 40
122 /* Nonzero if within a function (so symbols should be local,
123 if nothing says specifically). */
127 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
128 there is any reason not to just use a #define, but might as well
129 ask BFD for the size and store it here, I guess. */
131 static unsigned local_symesz
;
133 struct coff_symfile_info
135 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
136 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
138 /* Pointer to the string table. */
141 /* Pointer to debug section. */
144 /* Pointer to the a.out symbol table. */
147 /* Number of symbols in symtbl. */
150 /* Offset in data section to TOC anchor. */
151 CORE_ADDR toc_offset
;
155 bf_notfound_complaint (void)
157 complaint (&symfile_complaints
, _("line numbers off, `.bf' symbol not found"));
161 ef_complaint (int arg1
)
163 complaint (&symfile_complaints
,
164 _("Mismatched .ef symbol ignored starting at symnum %d"), arg1
);
168 eb_complaint (int arg1
)
170 complaint (&symfile_complaints
,
171 _("Mismatched .eb symbol ignored starting at symnum %d"), arg1
);
174 static void xcoff_initial_scan (struct objfile
*, int);
176 static void scan_xcoff_symtab (struct objfile
*);
178 static char *xcoff_next_symbol_text (struct objfile
*);
180 static void record_include_begin (struct coff_symbol
*);
183 enter_line_range (struct subfile
*, unsigned, unsigned,
184 CORE_ADDR
, CORE_ADDR
, unsigned *);
186 static void init_stringtab (bfd
*, file_ptr
, struct objfile
*);
188 static void xcoff_symfile_init (struct objfile
*);
190 static void xcoff_new_init (struct objfile
*);
192 static void xcoff_symfile_finish (struct objfile
*);
194 static void xcoff_symfile_offsets (struct objfile
*,
195 struct section_addr_info
*addrs
);
197 static char *coff_getfilename (union internal_auxent
*, struct objfile
*);
199 static void read_symbol (struct internal_syment
*, int);
201 static int read_symbol_lineno (int);
203 static CORE_ADDR
read_symbol_nvalue (int);
205 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
208 static void read_xcoff_symtab (struct partial_symtab
*);
211 static void add_stab_to_list (char *, struct pending_stabs
**);
214 static int compare_lte (const void *, const void *);
216 static struct linetable
*arrange_linetable (struct linetable
*);
218 static void record_include_end (struct coff_symbol
*);
220 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
223 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
225 static int secnum_to_section (int, struct objfile
*);
226 static asection
*secnum_to_bfd_section (int, struct objfile
*);
228 struct find_targ_sec_arg
233 struct objfile
*objfile
;
236 static void find_targ_sec (bfd
*, asection
*, void *);
239 find_targ_sec (bfd
*abfd
, asection
*sect
, void *obj
)
241 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
242 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
);
263 asection
*sect
= NULL
;
264 struct find_targ_sec_arg args
;
265 args
.targ_index
= secnum
;
267 args
.bfd_sect
= §
;
268 args
.objfile
= objfile
;
269 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
273 /* Return the BFD section that CS points to. */
275 secnum_to_bfd_section (int secnum
, struct objfile
*objfile
)
277 int off
= SECT_OFF_TEXT (objfile
);
279 asection
*sect
= NULL
;
280 struct find_targ_sec_arg args
;
281 args
.targ_index
= secnum
;
283 args
.bfd_sect
= §
;
284 args
.objfile
= objfile
;
285 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
289 /* add a given stab string into given stab vector. */
294 add_stab_to_list (char *stabname
, struct pending_stabs
**stabvector
)
296 if (*stabvector
== NULL
)
298 *stabvector
= (struct pending_stabs
*)
299 xmalloc (sizeof (struct pending_stabs
) +
300 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
301 (*stabvector
)->count
= 0;
302 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
304 else if ((*stabvector
)->count
>= (*stabvector
)->length
)
306 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
307 *stabvector
= (struct pending_stabs
*)
308 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
309 (*stabvector
)->length
* sizeof (char *));
311 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
316 /* Linenos are processed on a file-by-file basis.
320 1) xlc (IBM's native c compiler) postpones static function code
321 emission to the end of a compilation unit. This way it can
322 determine if those functions (statics) are needed or not, and
323 can do some garbage collection (I think). This makes line
324 numbers and corresponding addresses unordered, and we end up
325 with a line table like:
342 and that breaks gdb's binary search on line numbers, if the
343 above table is not sorted on line numbers. And that sort
344 should be on function based, since gcc can emit line numbers
347 10 0x100 - for the init/test part of a for stmt.
350 10 0x400 - for the increment part of a for stmt.
352 arrange_linetable() will do this sorting.
354 2) aix symbol table might look like:
356 c_file // beginning of a new file
357 .bi // beginning of include file
358 .ei // end of include file
362 basically, .bi/.ei pairs do not necessarily encapsulate
363 their scope. They need to be recorded, and processed later
364 on when we come the end of the compilation unit.
365 Include table (inclTable) and process_linenos() handle
371 /* compare line table entry addresses. */
374 compare_lte (const void *lte1p
, const void *lte2p
)
376 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
377 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
379 return lte1
->pc
- lte2
->pc
;
382 /* Given a line table with function entries are marked, arrange its functions
383 in ascending order and strip off function entry markers and return it in
384 a newly created table. If the old one is good enough, return the old one. */
385 /* FIXME: I think all this stuff can be replaced by just passing
386 sort_linevec = 1 to end_symtab. */
388 static struct linetable
*
389 arrange_linetable (struct linetable
*oldLineTb
)
391 int ii
, jj
, newline
, /* new line count */
392 function_count
; /* # of functions */
394 struct linetable_entry
*fentry
; /* function entry vector */
395 int fentry_size
; /* # of function entries */
396 struct linetable
*newLineTb
; /* new line table */
398 #define NUM_OF_FUNCTIONS 20
400 fentry_size
= NUM_OF_FUNCTIONS
;
401 fentry
= (struct linetable_entry
*)
402 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
404 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
406 if (oldLineTb
->item
[ii
].line
== 0)
407 { /* function entry found. */
408 if (function_count
>= fentry_size
)
409 { /* make sure you have room. */
411 fentry
= (struct linetable_entry
*)
412 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
414 fentry
[function_count
].line
= ii
;
415 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
420 if (function_count
== 0)
425 else if (function_count
> 1)
426 qsort (fentry
, function_count
, sizeof (struct linetable_entry
), compare_lte
);
428 /* allocate a new line table. */
429 newLineTb
= (struct linetable
*)
431 (sizeof (struct linetable
) +
432 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
434 /* if line table does not start with a function beginning, copy up until
438 if (oldLineTb
->item
[0].line
!= 0)
440 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
441 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
443 /* Now copy function lines one by one. */
445 for (ii
= 0; ii
< function_count
; ++ii
)
447 for (jj
= fentry
[ii
].line
+ 1;
448 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
450 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
453 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
457 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
458 following `IncludeChain'. At the end of each symtab (end_symtab),
459 we will determine if we should create additional symtab's to
460 represent if (the include files. */
463 typedef struct _inclTable
465 char *name
; /* include filename */
467 /* Offsets to the line table. end points to the last entry which is
468 part of this include file. */
471 struct subfile
*subfile
;
472 unsigned funStartLine
; /* start line # of its function */
476 #define INITIAL_INCLUDE_TABLE_LENGTH 20
477 static InclTable
*inclTable
; /* global include table */
478 static int inclIndx
; /* last entry to table */
479 static int inclLength
; /* table length */
480 static int inclDepth
; /* nested include depth */
482 static void allocate_include_entry (void);
485 record_include_begin (struct coff_symbol
*cs
)
489 /* In xcoff, we assume include files cannot be nested (not in .c files
490 of course, but in corresponding .s files.). */
492 /* This can happen with old versions of GCC.
493 GCC 2.3.3-930426 does not exhibit this on a test case which
494 a user said produced the message for him. */
495 complaint (&symfile_complaints
, _("Nested C_BINCL symbols"));
499 allocate_include_entry ();
501 inclTable
[inclIndx
].name
= cs
->c_name
;
502 inclTable
[inclIndx
].begin
= cs
->c_value
;
506 record_include_end (struct coff_symbol
*cs
)
512 complaint (&symfile_complaints
, _("Mismatched C_BINCL/C_EINCL pair"));
515 allocate_include_entry ();
517 pTbl
= &inclTable
[inclIndx
];
518 pTbl
->end
= cs
->c_value
;
525 allocate_include_entry (void)
527 if (inclTable
== NULL
)
529 inclTable
= (InclTable
*)
530 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
532 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
533 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
536 else if (inclIndx
>= inclLength
)
538 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
539 inclTable
= (InclTable
*)
540 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
541 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
542 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
546 /* Global variable to pass the psymtab down to all the routines involved
547 in psymtab to symtab processing. */
548 static struct partial_symtab
*this_symtab_psymtab
;
550 /* given the start and end addresses of a compilation unit (or a csect,
551 at times) process its lines and create appropriate line vectors. */
554 process_linenos (CORE_ADDR start
, CORE_ADDR end
)
557 file_ptr max_offset
=
558 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
559 ->deprecated_sym_private
)->max_lineno_offset
;
561 /* subfile structure for the main compilation unit. */
562 struct subfile main_subfile
;
564 /* In the main source file, any time we see a function entry, we
565 reset this variable to function's absolute starting line number.
566 All the following line numbers in the function are relative to
567 this, and we record absolute line numbers in record_line(). */
569 unsigned int main_source_baseline
= 0;
574 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
576 goto return_after_cleanup
;
578 memset (&main_subfile
, '\0', sizeof (main_subfile
));
581 /* All source lines were in the main source file. None in include files. */
583 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
584 &main_source_baseline
);
588 /* There was source with line numbers in include files. */
591 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
592 main_source_baseline
= 0;
594 for (ii
= 0; ii
< inclIndx
; ++ii
)
596 struct subfile
*tmpSubfile
;
598 /* If there is main file source before include file, enter it. */
599 if (offset
< inclTable
[ii
].begin
)
602 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
603 start
, 0, &main_source_baseline
);
606 if (strcmp (inclTable
[ii
].name
, last_source_file
) == 0)
608 /* The entry in the include table refers to the main source
609 file. Add the lines to the main subfile. */
611 main_source_baseline
= inclTable
[ii
].funStartLine
;
613 (&main_subfile
, inclTable
[ii
].begin
, inclTable
[ii
].end
,
614 start
, 0, &main_source_baseline
);
615 inclTable
[ii
].subfile
= &main_subfile
;
619 /* Have a new subfile for the include file. */
621 tmpSubfile
= inclTable
[ii
].subfile
=
622 (struct subfile
*) xmalloc (sizeof (struct subfile
));
624 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
625 firstLine
= &(inclTable
[ii
].funStartLine
);
627 /* Enter include file's lines now. */
628 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
629 inclTable
[ii
].end
, start
, 0, firstLine
);
632 if (offset
<= inclTable
[ii
].end
)
633 offset
= inclTable
[ii
].end
+ linesz
;
636 /* All the include files' line have been processed at this point. Now,
637 enter remaining lines of the main file, if any left. */
638 if (offset
< max_offset
+ 1 - linesz
)
640 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
641 &main_source_baseline
);
645 /* Process main file's line numbers. */
646 if (main_subfile
.line_vector
)
648 struct linetable
*lineTb
, *lv
;
650 lv
= main_subfile
.line_vector
;
652 /* Line numbers are not necessarily ordered. xlc compilation will
653 put static function to the end. */
655 lineTb
= arrange_linetable (lv
);
658 current_subfile
->line_vector
= (struct linetable
*)
659 xrealloc (lv
, (sizeof (struct linetable
)
660 + lv
->nitems
* sizeof (struct linetable_entry
)));
665 current_subfile
->line_vector
= lineTb
;
668 current_subfile
->line_vector_length
=
669 current_subfile
->line_vector
->nitems
;
672 /* Now, process included files' line numbers. */
674 for (ii
= 0; ii
< inclIndx
; ++ii
)
676 if (inclTable
[ii
].subfile
!= ((struct subfile
*) &main_subfile
)
677 && (inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
679 struct linetable
*lineTb
, *lv
;
681 lv
= (inclTable
[ii
].subfile
)->line_vector
;
683 /* Line numbers are not necessarily ordered. xlc compilation will
684 put static function to the end. */
686 lineTb
= arrange_linetable (lv
);
690 /* For the same include file, we might want to have more than one
691 subfile. This happens if we have something like:
699 while foo.h including code in it. (stupid but possible)
700 Since start_subfile() looks at the name and uses an
701 existing one if finds, we need to provide a fake name and
705 start_subfile (inclTable
[ii
].name
, (char *) 0);
708 /* Pick a fake name that will produce the same results as this
709 one when passed to deduce_language_from_filename. Kludge on
711 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
713 if (fakename
== NULL
)
715 start_subfile (fakename
, (char *) 0);
716 xfree (current_subfile
->name
);
718 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
723 current_subfile
->line_vector
=
724 (struct linetable
*) xrealloc
725 (lv
, (sizeof (struct linetable
)
726 + lv
->nitems
* sizeof (struct linetable_entry
)));
732 current_subfile
->line_vector
= lineTb
;
735 current_subfile
->line_vector_length
=
736 current_subfile
->line_vector
->nitems
;
737 start_subfile (pop_subfile (), (char *) 0);
741 return_after_cleanup
:
743 /* We don't want to keep alloc/free'ing the global include file table. */
746 /* Start with a fresh subfile structure for the next file. */
747 memset (&main_subfile
, '\0', sizeof (struct subfile
));
751 aix_process_linenos (void)
753 /* process line numbers and enter them into line vector */
754 process_linenos (last_source_start_addr
, cur_src_end_addr
);
758 /* Enter a given range of lines into the line vector.
759 can be called in the following two ways:
760 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
761 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
763 endoffset points to the last line table entry that we should pay
767 enter_line_range (struct subfile
*subfile
, unsigned beginoffset
, unsigned endoffset
, /* offsets to line table */
768 CORE_ADDR startaddr
, /* offsets to line table */
769 CORE_ADDR endaddr
, unsigned *firstLine
)
771 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
772 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
773 unsigned int curoffset
;
776 struct internal_lineno int_lnno
;
777 unsigned int limit_offset
;
781 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
783 curoffset
= beginoffset
;
785 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)
790 if (endoffset
>= limit_offset
)
792 complaint (&symfile_complaints
,
793 _("Bad line table offset in C_EINCL directive"));
796 limit_offset
= endoffset
;
801 abfd
= objfile
->obfd
;
802 linesz
= coff_data (abfd
)->local_linesz
;
803 ext_lnno
= alloca (linesz
);
805 while (curoffset
<= limit_offset
)
807 bfd_seek (abfd
, curoffset
, SEEK_SET
);
808 bfd_bread (ext_lnno
, linesz
, abfd
);
809 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
811 /* Find the address this line represents. */
812 addr
= (int_lnno
.l_lnno
813 ? int_lnno
.l_addr
.l_paddr
814 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
815 addr
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
817 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
820 if (int_lnno
.l_lnno
== 0)
822 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
823 record_line (subfile
, 0, gdbarch_addr_bits_remove (gdbarch
, addr
));
827 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
,
828 gdbarch_addr_bits_remove (gdbarch
, addr
));
834 /* Save the vital information for use when closing off the current file.
835 NAME is the file name the symbols came from, START_ADDR is the first
836 text address for the file, and SIZE is the number of bytes of text. */
838 #define complete_symtab(name, start_addr) { \
839 last_source_file = xstrdup (name); \
840 last_source_start_addr = start_addr; \
844 /* Refill the symbol table input buffer
845 and set the variables that control fetching entries from it.
846 Reports an error if no data available.
847 This function can read past the end of the symbol table
848 (into the string table) but this does no harm. */
850 /* Reading symbol table has to be fast! Keep the followings as macros, rather
853 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
858 if (namestr[0] == '.') ++namestr; \
859 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
860 (SECTION), (asection *)NULL, \
862 misc_func_recorded = 1; \
866 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
867 nested. At any given time, a symbol can only be in one static block.
868 This is the base address of current static block, zero if non exists. */
870 static int static_block_base
= 0;
872 /* Section number for the current static block. */
874 static int static_block_section
= -1;
876 /* true if space for symbol name has been allocated. */
878 static int symname_alloced
= 0;
880 /* Next symbol to read. Pointer into raw seething symbol table. */
882 static char *raw_symbol
;
884 /* This is the function which stabsread.c calls to get symbol
888 xcoff_next_symbol_text (struct objfile
*objfile
)
890 struct internal_syment symbol
;
893 /* FIXME: is this the same as the passed arg? */
894 if (this_symtab_psymtab
)
895 objfile
= this_symtab_psymtab
->objfile
;
897 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
900 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
902 /* Return something which points to '\0' and hope the symbol reading
903 code does something reasonable. */
906 else if (symbol
.n_sclass
& 0x80)
909 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
912 coff_data (objfile
->obfd
)->local_symesz
;
917 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
919 /* Return something which points to '\0' and hope the symbol reading
920 code does something reasonable. */
926 /* Read symbols for a given partial symbol table. */
929 read_xcoff_symtab (struct partial_symtab
*pst
)
931 struct objfile
*objfile
= pst
->objfile
;
932 bfd
*abfd
= objfile
->obfd
;
933 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
935 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
;
937 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
;
938 char *debugfmt
= bfd_xcoff_is_xcoff64 (abfd
) ? "XCOFF64" : "XCOFF";
940 struct internal_syment symbol
[1];
941 union internal_auxent main_aux
;
942 struct coff_symbol cs
[1];
943 CORE_ADDR file_start_addr
= 0;
944 CORE_ADDR file_end_addr
= 0;
946 int next_file_symnum
= -1;
947 unsigned int max_symnum
;
948 int just_started
= 1;
950 int fcn_start_addr
= 0;
952 struct coff_symbol fcn_stab_saved
= { 0 };
954 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
955 union internal_auxent fcn_aux_saved
;
956 struct context_stack
*new;
958 char *filestring
= " _start_ "; /* Name of the current file. */
960 char *last_csect_name
; /* last seen csect's name and value */
961 CORE_ADDR last_csect_val
;
964 this_symtab_psymtab
= pst
;
966 /* Get the appropriate COFF "constants" related to the file we're
968 local_symesz
= coff_data (abfd
)->local_symesz
;
970 last_source_file
= NULL
;
975 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
976 record_debugformat (debugfmt
);
977 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
979 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
980 first_object_file_end
= 0;
983 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
984 + symnum
* local_symesz
;
986 while (symnum
< max_symnum
)
988 QUIT
; /* make this command interruptable. */
990 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
991 /* read one symbol into `cs' structure. After processing the
992 whole symbol table, only string table will be kept in memory,
993 symbol table and debug section of xcoff will be freed. Thus
994 we can mark symbols with names in string table as
999 /* Swap and align the symbol into a reasonable C structure. */
1000 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1002 cs
->c_symnum
= symnum
;
1003 cs
->c_naux
= symbol
->n_numaux
;
1004 if (symbol
->n_zeroes
)
1006 symname_alloced
= 0;
1007 /* We must use the original, unswapped, name here so the name field
1008 pointed to by cs->c_name will persist throughout xcoffread. If
1009 we use the new field, it gets overwritten for each symbol. */
1010 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
1011 /* If it's exactly E_SYMNMLEN characters long it isn't
1013 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1017 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
1018 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1019 p
[E_SYMNMLEN
] = '\0';
1021 symname_alloced
= 1;
1024 else if (symbol
->n_sclass
& 0x80)
1026 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1027 symname_alloced
= 0;
1031 /* in string table */
1032 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1033 symname_alloced
= 1;
1035 cs
->c_value
= symbol
->n_value
;
1036 cs
->c_sclass
= symbol
->n_sclass
;
1037 cs
->c_secnum
= symbol
->n_scnum
;
1038 cs
->c_type
= (unsigned) symbol
->n_type
;
1040 raw_symbol
+= local_symesz
;
1043 /* Save addr of first aux entry. */
1044 raw_auxptr
= raw_symbol
;
1046 /* Skip all the auxents associated with this symbol. */
1047 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1049 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1054 /* if symbol name starts with ".$" or "$", ignore it. */
1055 if (cs
->c_name
[0] == '$'
1056 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1059 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1061 if (last_source_file
)
1064 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1069 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1070 record_debugformat (debugfmt
);
1071 cur_src_end_addr
= first_object_file_end
;
1072 /* done with all files, everything from here on is globals */
1075 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1078 /* Dealing with a symbol with a csect entry. */
1080 #define CSECT(PP) ((PP)->x_csect)
1081 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1082 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1083 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1084 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1086 /* Convert the auxent to something we can access. */
1087 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1088 0, cs
->c_naux
, &main_aux
);
1090 switch (CSECT_SMTYP (&main_aux
))
1094 /* Ignore all external references. */
1098 /* A section description. */
1100 switch (CSECT_SCLAS (&main_aux
))
1106 /* A program csect is seen. We have to allocate one
1107 symbol table for each program csect. Normally gdb
1108 prefers one symtab for each source file. In case
1109 of AIX, one source file might include more than one
1110 [PR] csect, and they don't have to be adjacent in
1111 terms of the space they occupy in memory. Thus, one
1112 single source file might get fragmented in the
1113 memory and gdb's file start and end address
1114 approach does not work! GCC (and I think xlc) seem
1115 to put all the code in the unnamed program csect. */
1117 if (last_csect_name
)
1119 complete_symtab (filestring
, file_start_addr
);
1120 cur_src_end_addr
= file_end_addr
;
1121 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1124 /* Give all csects for this source file the same
1126 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1127 record_debugformat (debugfmt
);
1130 /* If this is the very first csect seen,
1131 basically `__start'. */
1134 first_object_file_end
1135 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1140 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1141 SECT_OFF_TEXT (objfile
));
1142 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1144 if (cs
->c_name
&& (cs
->c_name
[0] == '.'
1145 || cs
->c_name
[0] == '@'))
1147 last_csect_name
= cs
->c_name
;
1148 last_csect_val
= cs
->c_value
;
1149 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1154 /* All other symbols are put into the minimal symbol
1167 /* Ignore the symbol. */
1175 switch (CSECT_SCLAS (&main_aux
))
1178 /* a function entry point. */
1179 function_entry_point
:
1181 fcn_start_addr
= cs
->c_value
;
1183 /* save the function header info, which will be used
1184 when `.bf' is seen. */
1186 fcn_aux_saved
= main_aux
;
1190 /* shared library function trampoline code entry point. */
1194 /* The symbols often have the same names as debug symbols for
1195 functions, and confuse lookup_symbol. */
1199 /* xlc puts each variable in a separate csect, so we get
1200 an XTY_SD for each variable. But gcc puts several
1201 variables in a csect, so that each variable only gets
1202 an XTY_LD. This will typically be XMC_RW; I suspect
1203 XMC_RO and XMC_BS might be possible too.
1204 These variables are put in the minimal symbol table
1211 /* Common symbols are put into the minimal symbol table only. */
1219 /* If explicitly specified as a function, treat is as one. This check
1220 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1221 after the above CSECT check. */
1222 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1224 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1225 0, cs
->c_naux
, &main_aux
);
1226 goto function_entry_point
;
1229 switch (cs
->c_sclass
)
1233 /* c_value field contains symnum of next .file entry in table
1234 or symnum of first global after last .file. */
1236 next_file_symnum
= cs
->c_value
;
1238 /* Complete symbol table for last object file containing
1239 debugging information. */
1241 /* Whether or not there was a csect in the previous file, we
1242 have to call `end_stabs' and `start_stabs' to reset
1243 type_vector, line_vector, etc. structures. */
1245 complete_symtab (filestring
, file_start_addr
);
1246 cur_src_end_addr
= file_end_addr
;
1247 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1250 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1251 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1252 standard COFF way and put it in the auxent. We use the auxent if
1253 the symbol is ".file" and an auxent exists, otherwise use the symbol
1254 itself. Simple enough. */
1255 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1257 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1258 0, cs
->c_naux
, &main_aux
);
1259 filestring
= coff_getfilename (&main_aux
, objfile
);
1262 filestring
= cs
->c_name
;
1265 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1266 record_debugformat (debugfmt
);
1267 last_csect_name
= 0;
1269 /* reset file start and end addresses. A compilation unit with no text
1270 (only data) should have zero file boundaries. */
1271 file_start_addr
= file_end_addr
= 0;
1275 fcn_stab_saved
= *cs
;
1279 if (strcmp (cs
->c_name
, ".bf") == 0)
1281 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1282 SECT_OFF_TEXT (objfile
));
1284 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1285 0, cs
->c_naux
, &main_aux
);
1287 within_function
= 1;
1289 new = push_context (0, fcn_start_addr
+ off
);
1291 new->name
= define_symbol
1292 (fcn_cs_saved
.c_value
+ off
,
1293 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1294 if (new->name
!= NULL
)
1295 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1297 else if (strcmp (cs
->c_name
, ".ef") == 0)
1299 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1300 0, cs
->c_naux
, &main_aux
);
1302 /* The value of .ef is the address of epilogue code;
1303 not useful for gdb. */
1304 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1305 contains number of lines to '}' */
1307 if (context_stack_depth
<= 0)
1308 { /* We attempted to pop an empty context stack */
1309 ef_complaint (cs
->c_symnum
);
1310 within_function
= 0;
1313 new = pop_context ();
1314 /* Stack must be empty now. */
1315 if (context_stack_depth
> 0 || new == NULL
)
1317 ef_complaint (cs
->c_symnum
);
1318 within_function
= 0;
1322 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1324 (fcn_cs_saved
.c_value
1325 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1326 + ANOFFSET (objfile
->section_offsets
,
1327 SECT_OFF_TEXT (objfile
))),
1329 within_function
= 0;
1334 /* Begin static block. */
1336 struct internal_syment symbol
;
1338 read_symbol (&symbol
, cs
->c_value
);
1339 static_block_base
= symbol
.n_value
;
1340 static_block_section
=
1341 secnum_to_section (symbol
.n_scnum
, objfile
);
1346 /* End of static block. */
1347 static_block_base
= 0;
1348 static_block_section
= -1;
1359 complaint (&symfile_complaints
, _("Unrecognized storage class %d."),
1374 /* beginning of include file */
1375 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1376 order. Thus, when wee see them, we might not know enough info
1377 to process them. Thus, we'll be saving them into a table
1378 (inclTable) and postpone their processing. */
1380 record_include_begin (cs
);
1384 /* End of include file. */
1385 /* See the comment after case C_BINCL. */
1386 record_include_end (cs
);
1390 if (strcmp (cs
->c_name
, ".bb") == 0)
1393 new = push_context (depth
,
1395 + ANOFFSET (objfile
->section_offsets
,
1396 SECT_OFF_TEXT (objfile
))));
1398 else if (strcmp (cs
->c_name
, ".eb") == 0)
1400 if (context_stack_depth
<= 0)
1401 { /* We attempted to pop an empty context stack */
1402 eb_complaint (cs
->c_symnum
);
1405 new = pop_context ();
1406 if (depth
-- != new->depth
)
1408 eb_complaint (cs
->c_symnum
);
1411 if (local_symbols
&& context_stack_depth
> 0)
1413 /* Make a block for the local symbols within. */
1414 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1417 + ANOFFSET (objfile
->section_offsets
,
1418 SECT_OFF_TEXT (objfile
))),
1421 local_symbols
= new->locals
;
1426 process_xcoff_symbol (cs
, objfile
);
1431 if (last_source_file
)
1435 complete_symtab (filestring
, file_start_addr
);
1436 cur_src_end_addr
= file_end_addr
;
1437 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1438 /* When reading symbols for the last C_FILE of the objfile, try
1439 to make sure that we set pst->symtab to the symtab for the
1440 file, not to the _globals_ symtab. I'm not sure whether this
1441 actually works right or when/if it comes up. */
1442 if (pst
->symtab
== NULL
)
1448 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1449 (SYMBOL2) = (struct symbol *) \
1450 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1451 *(SYMBOL2) = *(SYMBOL1);
1454 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1455 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->objfile_obstack))
1458 /* process one xcoff symbol. */
1460 static struct symbol
*
1461 process_xcoff_symbol (struct coff_symbol
*cs
, struct objfile
*objfile
)
1463 struct symbol onesymbol
;
1464 struct symbol
*sym
= &onesymbol
;
1465 struct symbol
*sym2
= NULL
;
1471 if (cs
->c_secnum
< 0)
1473 /* The value is a register number, offset within a frame, etc.,
1474 and does not get relocated. */
1480 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1481 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1488 memset (sym
, '\0', sizeof (struct symbol
));
1490 /* default assumptions */
1491 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1492 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1493 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1495 if (ISFCN (cs
->c_type
))
1497 /* At this point, we don't know the type of the function. This
1498 will be patched with the type from its stab entry later on in
1499 patch_block_stabs (), unless the file was compiled without -g. */
1501 SYMBOL_SET_LINKAGE_NAME (sym
, SYMNAME_ALLOC (name
, symname_alloced
));
1502 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_text_symbol
;
1504 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1505 SYMBOL_DUP (sym
, sym2
);
1507 if (cs
->c_sclass
== C_EXT
)
1508 add_symbol_to_list (sym2
, &global_symbols
);
1509 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1510 add_symbol_to_list (sym2
, &file_symbols
);
1514 /* In case we can't figure out the type, provide default. */
1515 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_data_symbol
;
1517 switch (cs
->c_sclass
)
1520 /* The values of functions and global symbols are now resolved
1521 via the global_sym_chain in stabsread.c. */
1523 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1524 add_stab_to_list (name
, &global_stabs
);
1526 add_stab_to_list (name
, &file_stabs
);
1530 add_stab_to_list (name
, &global_stabs
);
1535 common_block_start (cs
->c_name
, objfile
);
1539 common_block_end (objfile
);
1543 complaint (&symfile_complaints
, _("Unexpected storage class: %d"),
1556 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1559 SYMBOL_SECTION (sym
) = sec
;
1566 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1567 all statics and we need to distinguish file-scope versus
1568 function-scope using within_function. We do this by
1569 changing the string we pass to define_symbol to use 'S'
1570 where we need to, which is not necessarily super-clean,
1571 but seems workable enough. */
1573 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1577 if (*pp
== 'V' && !within_function
)
1579 sym
= define_symbol ((cs
->c_value
1580 + ANOFFSET (objfile
->section_offsets
,
1581 static_block_section
)),
1582 cs
->c_name
, 0, 0, objfile
);
1585 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1586 SYMBOL_SECTION (sym
) = static_block_section
;
1595 /* Extract the file name from the aux entry of a C_FILE symbol.
1596 Result is in static storage and is only good for temporary use. */
1599 coff_getfilename (union internal_auxent
*aux_entry
, struct objfile
*objfile
)
1601 static char buffer
[BUFSIZ
];
1603 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1605 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
1606 + aux_entry
->x_file
.x_n
.x_offset
);
1609 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1610 buffer
[FILNMLEN
] = '\0';
1615 /* Set *SYMBOL to symbol number symno in symtbl. */
1617 read_symbol (struct internal_syment
*symbol
, int symno
)
1620 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl_num_syms
;
1622 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl
;
1624 if (symno
< 0 || symno
>= nsyms
)
1626 complaint (&symfile_complaints
, _("Invalid symbol offset"));
1627 symbol
->n_value
= 0;
1628 symbol
->n_scnum
= -1;
1631 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1632 stbl
+ (symno
* local_symesz
),
1636 /* Get value corresponding to symbol number symno in symtbl. */
1639 read_symbol_nvalue (int symno
)
1641 struct internal_syment symbol
[1];
1643 read_symbol (symbol
, symno
);
1644 return symbol
->n_value
;
1648 /* Find the address of the function corresponding to symno, where
1649 symno is the symbol pointed to by the linetable. */
1652 read_symbol_lineno (int symno
)
1654 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1655 int xcoff64
= bfd_xcoff_is_xcoff64 (objfile
->obfd
);
1657 struct coff_symfile_info
*info
=
1658 (struct coff_symfile_info
*)objfile
->deprecated_sym_private
;
1659 int nsyms
= info
->symtbl_num_syms
;
1660 char *stbl
= info
->symtbl
;
1661 char *strtbl
= info
->strtbl
;
1663 struct internal_syment symbol
[1];
1664 union internal_auxent main_aux
[1];
1668 bf_notfound_complaint ();
1672 /* Note that just searching for a short distance (e.g. 50 symbols)
1673 is not enough, at least in the following case.
1676 [many .stabx entries]
1677 [a few functions, referring to foo]
1681 What happens here is that the assembler moves the .stabx entries
1682 to right before the ".bf" for foo, but the symbol for "foo" is before
1683 all the stabx entries. See PR gdb/2222. */
1685 /* Maintaining a table of .bf entries might be preferable to this search.
1686 If I understand things correctly it would need to be done only for
1687 the duration of a single psymtab to symtab conversion. */
1688 while (symno
< nsyms
)
1690 bfd_coff_swap_sym_in (symfile_bfd
,
1691 stbl
+ (symno
* local_symesz
), symbol
);
1692 if (symbol
->n_sclass
== C_FCN
)
1694 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1696 if (strcmp (name
, ".bf") == 0)
1699 symno
+= symbol
->n_numaux
+ 1;
1702 bf_notfound_complaint ();
1706 /* take aux entry and return its lineno */
1708 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1709 symbol
->n_type
, symbol
->n_sclass
,
1710 0, symbol
->n_numaux
, main_aux
);
1712 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1715 /* Support for line number handling */
1717 /* This function is called for every section; it finds the outer limits
1718 * of the line table (minimum and maximum file offset) so that the
1719 * mainline code can read the whole thing for efficiency.
1722 find_linenos (struct bfd
*abfd
, struct bfd_section
*asect
, void *vpinfo
)
1724 struct coff_symfile_info
*info
;
1726 file_ptr offset
, maxoff
;
1728 count
= asect
->lineno_count
;
1730 if (strcmp (asect
->name
, ".text") != 0 || count
== 0)
1733 size
= count
* coff_data (abfd
)->local_linesz
;
1734 info
= (struct coff_symfile_info
*) vpinfo
;
1735 offset
= asect
->line_filepos
;
1736 maxoff
= offset
+ size
;
1738 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1739 info
->min_lineno_offset
= offset
;
1741 if (maxoff
> info
->max_lineno_offset
)
1742 info
->max_lineno_offset
= maxoff
;
1745 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1748 xcoff_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1750 struct cleanup
*old_chain
;
1759 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1764 /* Read in all partial symtabs on which this one is dependent */
1765 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1766 if (!pst
->dependencies
[i
]->readin
)
1768 /* Inform about additional files that need to be read in. */
1771 fputs_filtered (" ", gdb_stdout
);
1773 fputs_filtered ("and ", gdb_stdout
);
1775 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1776 wrap_here (""); /* Flush output */
1777 gdb_flush (gdb_stdout
);
1779 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1782 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1784 /* Init stuff necessary for reading in symbols. */
1787 old_chain
= make_cleanup (really_free_pendings
, 0);
1789 read_xcoff_symtab (pst
);
1791 do_cleanups (old_chain
);
1797 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1799 /* Read in all of the symbols for a given psymtab for real.
1800 Be verbose about it if the user wants that. */
1803 xcoff_psymtab_to_symtab (struct partial_symtab
*pst
)
1813 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1818 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1819 || pst
->number_of_dependencies
)
1821 /* Print the message now, before reading the string table,
1822 to avoid disconcerting pauses. */
1825 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1826 gdb_flush (gdb_stdout
);
1829 sym_bfd
= pst
->objfile
->obfd
;
1831 next_symbol_text_func
= xcoff_next_symbol_text
;
1833 xcoff_psymtab_to_symtab_1 (pst
);
1835 /* Match with global symbols. This only needs to be done once,
1836 after all of the symtabs and dependencies have been read in. */
1837 scan_file_globals (pst
->objfile
);
1839 /* Finish up the debug error message. */
1841 printf_filtered ("done.\n");
1846 xcoff_new_init (struct objfile
*objfile
)
1848 stabsread_new_init ();
1849 buildsym_new_init ();
1852 /* Do initialization in preparation for reading symbols from OBJFILE.
1854 We will only be called if this is an XCOFF or XCOFF-like file.
1855 BFD handles figuring out the format of the file, and code in symfile.c
1856 uses BFD's determination to vector to us. */
1859 xcoff_symfile_init (struct objfile
*objfile
)
1861 /* Allocate struct to keep track of the symfile */
1862 objfile
->deprecated_sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
1864 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1865 find this causes a significant slowdown in gdb then we could
1866 set it in the debug symbol readers only when necessary. */
1867 objfile
->flags
|= OBJF_REORDERED
;
1869 init_entry_point_info (objfile
);
1872 /* Perform any local cleanups required when we are done with a particular
1873 objfile. I.E, we are in the process of discarding all symbol information
1874 for an objfile, freeing up all memory held for it, and unlinking the
1875 objfile struct from the global list of known objfiles. */
1878 xcoff_symfile_finish (struct objfile
*objfile
)
1880 if (objfile
->deprecated_sym_private
!= NULL
)
1882 xfree (objfile
->deprecated_sym_private
);
1885 /* Start with a fresh include table for the next objfile. */
1891 inclIndx
= inclLength
= inclDepth
= 0;
1896 init_stringtab (bfd
*abfd
, file_ptr offset
, struct objfile
*objfile
)
1900 unsigned char lengthbuf
[4];
1903 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
= NULL
;
1905 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1906 error (_("cannot seek to string table in %s: %s"),
1907 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1909 val
= bfd_bread ((char *) lengthbuf
, sizeof lengthbuf
, abfd
);
1910 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1912 /* If no string table is needed, then the file may end immediately
1913 after the symbols. Just return with `strtbl' set to NULL. */
1915 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1918 /* Allocate string table from objfile_obstack. We will need this table
1919 as long as we have its symbol table around. */
1921 strtbl
= (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
1922 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
= strtbl
;
1924 /* Copy length buffer, the first byte is usually zero and is
1925 used for stabs with a name length of zero. */
1926 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1927 if (length
== sizeof lengthbuf
)
1930 val
= bfd_bread (strtbl
+ sizeof lengthbuf
, length
- sizeof lengthbuf
, abfd
);
1932 if (val
!= length
- sizeof lengthbuf
)
1933 error (_("cannot read string table from %s: %s"),
1934 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1935 if (strtbl
[length
- 1] != '\0')
1936 error (_("bad symbol file: string table does not end with null character"));
1941 /* If we have not yet seen a function for this psymtab, this is 0. If we
1942 have seen one, it is the offset in the line numbers of the line numbers
1944 static unsigned int first_fun_line_offset
;
1946 static struct partial_symtab
*xcoff_start_psymtab
1947 (struct objfile
*, char *, int,
1948 struct partial_symbol
**, struct partial_symbol
**);
1950 /* Allocate and partially fill a partial symtab. It will be
1951 completely filled at the end of the symbol list.
1953 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1954 is the address relative to which its symbols are (incremental) or 0
1957 static struct partial_symtab
*
1958 xcoff_start_psymtab (struct objfile
*objfile
, char *filename
, int first_symnum
,
1959 struct partial_symbol
**global_syms
,
1960 struct partial_symbol
**static_syms
)
1962 struct partial_symtab
*result
=
1963 start_psymtab_common (objfile
, objfile
->section_offsets
,
1965 /* We fill in textlow later. */
1967 global_syms
, static_syms
);
1969 result
->read_symtab_private
= obstack_alloc (&objfile
->objfile_obstack
,
1970 sizeof (struct symloc
));
1971 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
1972 result
->read_symtab
= xcoff_psymtab_to_symtab
;
1974 /* Deduce the source language from the filename for this psymtab. */
1975 psymtab_language
= deduce_language_from_filename (filename
);
1980 static struct partial_symtab
*xcoff_end_psymtab
1981 (struct partial_symtab
*, char **, int, int,
1982 struct partial_symtab
**, int, int);
1984 /* Close off the current usage of PST.
1985 Returns PST, or NULL if the partial symtab was empty and thrown away.
1987 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
1989 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
1990 are the information for includes and dependencies. */
1992 static struct partial_symtab
*
1993 xcoff_end_psymtab (struct partial_symtab
*pst
, char **include_list
,
1994 int num_includes
, int capping_symbol_number
,
1995 struct partial_symtab
**dependency_list
,
1996 int number_dependencies
, int textlow_not_set
)
1999 struct objfile
*objfile
= pst
->objfile
;
2001 if (capping_symbol_number
!= -1)
2002 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
2003 capping_symbol_number
2004 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
2005 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
2006 first_fun_line_offset
;
2007 first_fun_line_offset
= 0;
2008 pst
->n_global_syms
=
2009 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2010 pst
->n_static_syms
=
2011 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2013 pst
->number_of_dependencies
= number_dependencies
;
2014 if (number_dependencies
)
2016 pst
->dependencies
= (struct partial_symtab
**)
2017 obstack_alloc (&objfile
->objfile_obstack
,
2018 number_dependencies
* sizeof (struct partial_symtab
*));
2019 memcpy (pst
->dependencies
, dependency_list
,
2020 number_dependencies
* sizeof (struct partial_symtab
*));
2023 pst
->dependencies
= 0;
2025 for (i
= 0; i
< num_includes
; i
++)
2027 struct partial_symtab
*subpst
=
2028 allocate_psymtab (include_list
[i
], objfile
);
2030 subpst
->section_offsets
= pst
->section_offsets
;
2031 subpst
->read_symtab_private
= obstack_alloc (&objfile
->objfile_obstack
,
2032 sizeof (struct symloc
));
2033 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2034 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2035 subpst
->textlow
= 0;
2036 subpst
->texthigh
= 0;
2038 /* We could save slight bits of space by only making one of these,
2039 shared by the entire set of include files. FIXME-someday. */
2040 subpst
->dependencies
= (struct partial_symtab
**)
2041 obstack_alloc (&objfile
->objfile_obstack
,
2042 sizeof (struct partial_symtab
*));
2043 subpst
->dependencies
[0] = pst
;
2044 subpst
->number_of_dependencies
= 1;
2046 subpst
->globals_offset
=
2047 subpst
->n_global_syms
=
2048 subpst
->statics_offset
=
2049 subpst
->n_static_syms
= 0;
2053 subpst
->read_symtab
= pst
->read_symtab
;
2056 sort_pst_symbols (pst
);
2058 if (num_includes
== 0
2059 && number_dependencies
== 0
2060 && pst
->n_global_syms
== 0
2061 && pst
->n_static_syms
== 0)
2063 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2064 it is on the obstack, but we can forget to chain it on the list. */
2065 /* Empty psymtabs happen as a result of header files which don't have
2066 any symbols in them. There can be a lot of them. */
2068 discard_psymtab (pst
);
2070 /* Indicate that psymtab was thrown away. */
2071 pst
= (struct partial_symtab
*) NULL
;
2076 static void swap_sym (struct internal_syment
*,
2077 union internal_auxent
*, char **, char **,
2078 unsigned int *, struct objfile
*);
2080 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2081 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2082 the symbol and its auxents. */
2085 swap_sym (struct internal_syment
*symbol
, union internal_auxent
*aux
,
2086 char **name
, char **raw
, unsigned int *symnump
,
2087 struct objfile
*objfile
)
2089 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2090 if (symbol
->n_zeroes
)
2092 /* If it's exactly E_SYMNMLEN characters long it isn't
2094 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2096 /* FIXME: wastes memory for symbols which we don't end up putting
2097 into the minimal symbols. */
2100 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
2101 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2102 p
[E_SYMNMLEN
] = '\0';
2106 /* Point to the unswapped name as that persists as long as the
2108 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2110 else if (symbol
->n_sclass
& 0x80)
2112 *name
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
2117 *name
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
2121 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2122 if (symbol
->n_numaux
> 0)
2124 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2125 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2127 *symnump
+= symbol
->n_numaux
;
2128 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2133 function_outside_compilation_unit_complaint (const char *arg1
)
2135 complaint (&symfile_complaints
,
2136 _("function `%s' appears to be defined outside of all compilation units"),
2141 scan_xcoff_symtab (struct objfile
*objfile
)
2143 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2144 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2145 char *filestring
= NULL
;
2148 int past_first_source_file
= 0;
2153 /* Current partial symtab */
2154 struct partial_symtab
*pst
;
2156 /* List of current psymtab's include files */
2157 char **psymtab_include_list
;
2158 int includes_allocated
;
2161 /* Index within current psymtab dependency list */
2162 struct partial_symtab
**dependency_list
;
2163 int dependencies_used
, dependencies_allocated
;
2166 struct internal_syment symbol
;
2167 union internal_auxent main_aux
[5];
2168 unsigned int ssymnum
;
2170 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2171 CORE_ADDR last_csect_val
= 0;
2172 int last_csect_sec
= 0;
2173 int misc_func_recorded
= 0; /* true if any misc. function */
2174 int textlow_not_set
= 1;
2176 pst
= (struct partial_symtab
*) 0;
2178 includes_allocated
= 30;
2180 psymtab_include_list
= (char **) alloca (includes_allocated
*
2183 dependencies_allocated
= 30;
2184 dependencies_used
= 0;
2186 (struct partial_symtab
**) alloca (dependencies_allocated
*
2187 sizeof (struct partial_symtab
*));
2189 last_source_file
= NULL
;
2191 abfd
= objfile
->obfd
;
2192 next_symbol_text_func
= xcoff_next_symbol_text
;
2194 sraw_symbol
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
;
2195 nsyms
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl_num_syms
;
2197 while (ssymnum
< nsyms
)
2203 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2204 sclass
= symbol
.n_sclass
;
2211 /* The CSECT auxent--always the last auxent. */
2212 union internal_auxent csect_aux
;
2213 unsigned int symnum_before
= ssymnum
;
2215 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2217 if (symbol
.n_numaux
> 1)
2219 bfd_coff_swap_aux_in
2221 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2224 symbol
.n_numaux
- 1,
2229 csect_aux
= main_aux
[0];
2231 /* If symbol name starts with ".$" or "$", ignore it. */
2232 if (namestring
[0] == '$'
2233 || (namestring
[0] == '.' && namestring
[1] == '$'))
2236 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2239 switch (csect_aux
.x_csect
.x_smclas
)
2242 if (last_csect_name
)
2244 /* If no misc. function recorded in the last
2245 seen csect, enter it as a function. This
2246 will take care of functions like strcmp()
2249 if (!misc_func_recorded
)
2251 RECORD_MINIMAL_SYMBOL
2252 (last_csect_name
, last_csect_val
,
2253 mst_text
, last_csect_sec
,
2259 /* We have to allocate one psymtab for
2260 each program csect, because their text
2261 sections need not be adjacent. */
2263 (pst
, psymtab_include_list
, includes_used
,
2264 symnum_before
, dependency_list
,
2265 dependencies_used
, textlow_not_set
);
2267 dependencies_used
= 0;
2268 /* Give all psymtabs for this source file the same
2270 pst
= xcoff_start_psymtab
2274 objfile
->global_psymbols
.next
,
2275 objfile
->static_psymbols
.next
);
2278 /* Activate the misc_func_recorded mechanism for
2279 compiler- and linker-generated CSECTs like ".strcmp"
2281 if (namestring
&& (namestring
[0] == '.'
2282 || namestring
[0] == '@'))
2284 last_csect_name
= namestring
;
2285 last_csect_val
= symbol
.n_value
;
2287 secnum_to_section (symbol
.n_scnum
, objfile
);
2292 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2294 if (highval
> pst
->texthigh
)
2295 pst
->texthigh
= highval
;
2296 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2297 pst
->textlow
= symbol
.n_value
;
2299 misc_func_recorded
= 0;
2304 /* Data variables are recorded in the minimal symbol
2305 table, except for section symbols. */
2306 if (*namestring
!= '.')
2307 prim_record_minimal_symbol_and_info
2308 (namestring
, symbol
.n_value
,
2309 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2310 secnum_to_section (symbol
.n_scnum
, objfile
),
2316 warning (_("More than one XMC_TC0 symbol found."));
2317 toc_offset
= symbol
.n_value
;
2319 /* Make TOC offset relative to start address of section. */
2320 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2322 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2326 /* These symbols tell us where the TOC entry for a
2327 variable is, not the variable itself. */
2336 switch (csect_aux
.x_csect
.x_smclas
)
2339 /* A function entry point. */
2341 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2342 first_fun_line_offset
=
2343 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2344 RECORD_MINIMAL_SYMBOL
2345 (namestring
, symbol
.n_value
,
2346 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2347 secnum_to_section (symbol
.n_scnum
, objfile
),
2352 /* shared library function trampoline code entry
2355 /* record trampoline code entries as
2356 mst_solib_trampoline symbol. When we lookup mst
2357 symbols, we will choose mst_text over
2358 mst_solib_trampoline. */
2359 RECORD_MINIMAL_SYMBOL
2360 (namestring
, symbol
.n_value
,
2361 mst_solib_trampoline
,
2362 secnum_to_section (symbol
.n_scnum
, objfile
),
2367 /* The symbols often have the same names as
2368 debug symbols for functions, and confuse
2374 /* xlc puts each variable in a separate csect,
2375 so we get an XTY_SD for each variable. But
2376 gcc puts several variables in a csect, so
2377 that each variable only gets an XTY_LD. We
2378 still need to record them. This will
2379 typically be XMC_RW; I suspect XMC_RO and
2380 XMC_BS might be possible too. */
2381 if (*namestring
!= '.')
2382 prim_record_minimal_symbol_and_info
2383 (namestring
, symbol
.n_value
,
2384 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2385 secnum_to_section (symbol
.n_scnum
, objfile
),
2392 switch (csect_aux
.x_csect
.x_smclas
)
2396 /* Common variables are recorded in the minimal symbol
2397 table, except for section symbols. */
2398 if (*namestring
!= '.')
2399 prim_record_minimal_symbol_and_info
2400 (namestring
, symbol
.n_value
,
2401 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2402 secnum_to_section (symbol
.n_scnum
, objfile
),
2415 unsigned int symnum_before
;
2417 symnum_before
= ssymnum
;
2418 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2421 /* See if the last csect needs to be recorded. */
2423 if (last_csect_name
&& !misc_func_recorded
)
2425 /* If no misc. function recorded in the last seen csect, enter
2426 it as a function. This will take care of functions like
2427 strcmp() compiled by xlc. */
2429 RECORD_MINIMAL_SYMBOL
2430 (last_csect_name
, last_csect_val
,
2431 mst_text
, last_csect_sec
, objfile
);
2436 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2437 symnum_before
, dependency_list
,
2438 dependencies_used
, textlow_not_set
);
2440 dependencies_used
= 0;
2442 first_fun_line_offset
= 0;
2444 /* XCOFF, according to the AIX 3.2 documentation, puts the
2445 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2446 do things the standard COFF way and put it in the auxent.
2447 We use the auxent if the symbol is ".file" and an auxent
2448 exists, otherwise use the symbol itself. */
2449 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2451 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2454 filestring
= namestring
;
2456 pst
= xcoff_start_psymtab (objfile
,
2459 objfile
->global_psymbols
.next
,
2460 objfile
->static_psymbols
.next
);
2461 last_csect_name
= NULL
;
2467 complaint (&symfile_complaints
,
2468 _("Storage class %d not recognized during scan"), sclass
);
2472 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2473 to handle only the C_FUN and C_EXT. */
2488 /* C_EINCL means we are switching back to the main file. But there
2489 is no reason to care; the only thing we want to know about
2490 includes is the names of all the included (.h) files. */
2495 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2499 /* I don't think the name of the common block (as opposed to the
2500 variables within it) is something which is user visible
2508 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2509 so C_LSYM would appear to be only for locals. */
2515 /* We probably could save a few instructions by assuming that
2516 C_LSYM, C_PSYM, etc., never have auxents. */
2517 int naux1
= symbol
.n_numaux
+ 1;
2520 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2526 /* Mark down an include file in the current psymtab */
2527 enum language tmp_language
;
2529 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2532 tmp_language
= deduce_language_from_filename (namestring
);
2534 /* Only change the psymtab's language if we've learned
2535 something useful (eg. tmp_language is not language_unknown).
2536 In addition, to match what start_subfile does, never change
2538 if (tmp_language
!= language_unknown
2539 && (tmp_language
!= language_c
2540 || psymtab_language
!= language_cplus
))
2541 psymtab_language
= tmp_language
;
2543 /* In C++, one may expect the same filename to come round many
2544 times, when code is coming alternately from the main file
2545 and from inline functions in other files. So I check to see
2546 if this is a file we've seen before -- either the main
2547 source file, or a previously included file.
2549 This seems to be a lot of time to be spending on N_SOL, but
2550 things like "break c-exp.y:435" need to work (I
2551 suppose the psymtab_include_list could be hashed or put
2552 in a binary tree, if profiling shows this is a major hog). */
2553 if (pst
&& strcmp (namestring
, pst
->filename
) == 0)
2559 for (i
= 0; i
< includes_used
; i
++)
2560 if (strcmp (namestring
, psymtab_include_list
[i
]) == 0)
2568 psymtab_include_list
[includes_used
++] = namestring
;
2569 if (includes_used
>= includes_allocated
)
2571 char **orig
= psymtab_include_list
;
2573 psymtab_include_list
= (char **)
2574 alloca ((includes_allocated
*= 2) *
2576 memcpy (psymtab_include_list
, orig
,
2577 includes_used
* sizeof (char *));
2582 /* The value of the C_FUN is not the address of the function (it
2583 appears to be the address before linking), but as long as it
2584 is smaller than the actual address, then find_pc_partial_function
2585 will use the minimal symbols instead. I hope. */
2594 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2597 p
= (char *) strchr (namestring
, ':');
2599 continue; /* Not a debugging symbol. */
2601 /* Main processing section for debugging symbols which
2602 the initial read through the symbol tables needs to worry
2603 about. If we reach this point, the symbol which we are
2604 considering is definitely one we are interested in.
2605 p must also contain the (valid) index into the namestring
2606 which indicates the debugging type symbol. */
2611 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2613 if (gdbarch_static_transform_name_p (gdbarch
))
2614 namestring
= gdbarch_static_transform_name
2615 (gdbarch
, namestring
);
2617 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2618 VAR_DOMAIN
, LOC_STATIC
,
2619 &objfile
->static_psymbols
,
2621 psymtab_language
, objfile
);
2625 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2626 /* The addresses in these entries are reported to be
2627 wrong. See the code that reads 'G's for symtabs. */
2628 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2629 VAR_DOMAIN
, LOC_STATIC
,
2630 &objfile
->global_psymbols
,
2632 psymtab_language
, objfile
);
2636 /* When a 'T' entry is defining an anonymous enum, it
2637 may have a name which is the empty string, or a
2638 single space. Since they're not really defining a
2639 symbol, those shouldn't go in the partial symbol
2640 table. We do pick up the elements of such enums at
2641 'check_enum:', below. */
2642 if (p
>= namestring
+ 2
2643 || (p
== namestring
+ 1
2644 && namestring
[0] != ' '))
2646 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2647 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2648 &objfile
->static_psymbols
,
2650 psymtab_language
, objfile
);
2653 /* Also a typedef with the same name. */
2654 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2655 VAR_DOMAIN
, LOC_TYPEDEF
,
2656 &objfile
->static_psymbols
,
2658 psymtab_language
, objfile
);
2665 if (p
!= namestring
) /* a name is there, not just :T... */
2667 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2668 VAR_DOMAIN
, LOC_TYPEDEF
,
2669 &objfile
->static_psymbols
,
2671 psymtab_language
, objfile
);
2674 /* If this is an enumerated type, we need to
2675 add all the enum constants to the partial symbol
2676 table. This does not cover enums without names, e.g.
2677 "enum {a, b} c;" in C, but fortunately those are
2678 rare. There is no way for GDB to find those from the
2679 enum type without spending too much time on it. Thus
2680 to solve this problem, the compiler needs to put out the
2681 enum in a nameless type. GCC2 does this. */
2683 /* We are looking for something of the form
2684 <name> ":" ("t" | "T") [<number> "="] "e"
2685 {<constant> ":" <value> ","} ";". */
2687 /* Skip over the colon and the 't' or 'T'. */
2689 /* This type may be given a number. Also, numbers can come
2690 in pairs like (0,26). Skip over it. */
2691 while ((*p
>= '0' && *p
<= '9')
2692 || *p
== '(' || *p
== ',' || *p
== ')'
2698 /* The aix4 compiler emits extra crud before the members. */
2701 /* Skip over the type (?). */
2705 /* Skip over the colon. */
2709 /* We have found an enumerated type. */
2710 /* According to comments in read_enum_type
2711 a comma could end it instead of a semicolon.
2712 I don't know where that happens.
2714 while (*p
&& *p
!= ';' && *p
!= ',')
2718 /* Check for and handle cretinous dbx symbol name
2720 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
2721 p
= next_symbol_text (objfile
);
2723 /* Point to the character after the name
2724 of the enum constant. */
2725 for (q
= p
; *q
&& *q
!= ':'; q
++)
2727 /* Note that the value doesn't matter for
2728 enum constants in psymtabs, just in symtabs. */
2729 add_psymbol_to_list (p
, q
- p
, 1,
2730 VAR_DOMAIN
, LOC_CONST
,
2731 &objfile
->static_psymbols
, 0,
2732 0, psymtab_language
, objfile
);
2733 /* Point past the name. */
2735 /* Skip over the value. */
2736 while (*p
&& *p
!= ',')
2738 /* Advance past the comma. */
2746 /* Constant, e.g. from "const" in Pascal. */
2747 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2748 VAR_DOMAIN
, LOC_CONST
,
2749 &objfile
->static_psymbols
, symbol
.n_value
,
2750 0, psymtab_language
, objfile
);
2756 int name_len
= p
- namestring
;
2757 char *name
= xmalloc (name_len
+ 1);
2759 memcpy (name
, namestring
, name_len
);
2760 name
[name_len
] = '\0';
2761 function_outside_compilation_unit_complaint (name
);
2764 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2765 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2766 VAR_DOMAIN
, LOC_BLOCK
,
2767 &objfile
->static_psymbols
,
2769 psymtab_language
, objfile
);
2772 /* Global functions were ignored here, but now they
2773 are put into the global psymtab like one would expect.
2774 They're also in the minimal symbol table. */
2778 int name_len
= p
- namestring
;
2779 char *name
= xmalloc (name_len
+ 1);
2781 memcpy (name
, namestring
, name_len
);
2782 name
[name_len
] = '\0';
2783 function_outside_compilation_unit_complaint (name
);
2787 /* We need only the minimal symbols for these
2788 loader-generated definitions. Keeping the global
2789 symbols leads to "in psymbols but not in symbols"
2791 if (strncmp (namestring
, "@FIX", 4) == 0)
2794 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2795 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2796 VAR_DOMAIN
, LOC_BLOCK
,
2797 &objfile
->global_psymbols
,
2799 psymtab_language
, objfile
);
2802 /* Two things show up here (hopefully); static symbols of
2803 local scope (static used inside braces) or extensions
2804 of structure symbols. We can ignore both. */
2818 case '#': /* for symbol identification (used in live ranges) */
2822 /* It is a C++ nested symbol. We don't need to record it
2823 (I don't think); if we try to look up foo::bar::baz,
2824 then symbols for the symtab containing foo should get
2825 read in, I think. */
2826 /* Someone says sun cc puts out symbols like
2827 /foo/baz/maclib::/usr/local/bin/maclib,
2828 which would get here with a symbol type of ':'. */
2832 /* Unexpected symbol descriptor. The second and subsequent stabs
2833 of a continued stab can show up here. The question is
2834 whether they ever can mimic a normal stab--it would be
2835 nice if not, since we certainly don't want to spend the
2836 time searching to the end of every string looking for
2839 complaint (&symfile_complaints
,
2840 _("unknown symbol descriptor `%c'"), p
[1]);
2842 /* Ignore it; perhaps it is an extension that we don't
2852 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2853 ssymnum
, dependency_list
,
2854 dependencies_used
, textlow_not_set
);
2857 /* Record the toc offset value of this symbol table into objfile structure.
2858 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2859 this information would be file auxiliary header. */
2861 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
= toc_offset
;
2864 /* Return the toc offset value for a given objfile. */
2867 xcoff_get_toc_offset (struct objfile
*objfile
)
2870 return ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
;
2874 /* Scan and build partial symbols for a symbol file.
2875 We have been initialized by a call to dbx_symfile_init, which
2876 put all the relevant info into a "struct dbx_symfile_info",
2877 hung off the objfile structure.
2879 SECTION_OFFSETS contains offsets relative to which the symbols in the
2880 various sections are (depending where the sections were actually loaded).
2884 xcoff_initial_scan (struct objfile
*objfile
, int symfile_flags
)
2888 struct cleanup
*back_to
;
2889 int num_symbols
; /* # of symbols */
2890 file_ptr symtab_offset
; /* symbol table and */
2891 file_ptr stringtab_offset
; /* string table file offsets */
2892 struct coff_symfile_info
*info
;
2896 info
= (struct coff_symfile_info
*) objfile
->deprecated_sym_private
;
2897 symfile_bfd
= abfd
= objfile
->obfd
;
2898 name
= objfile
->name
;
2900 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2901 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2902 stringtab_offset
= symtab_offset
+
2903 num_symbols
* coff_data (abfd
)->local_symesz
;
2905 info
->min_lineno_offset
= 0;
2906 info
->max_lineno_offset
= 0;
2907 bfd_map_over_sections (abfd
, find_linenos
, info
);
2909 if (num_symbols
> 0)
2911 /* Read the string table. */
2912 init_stringtab (abfd
, stringtab_offset
, objfile
);
2914 /* Read the .debug section, if present. */
2916 struct bfd_section
*secp
;
2917 bfd_size_type length
;
2918 char *debugsec
= NULL
;
2920 secp
= bfd_get_section_by_name (abfd
, ".debug");
2923 length
= bfd_section_size (abfd
, secp
);
2927 (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
2929 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2930 (file_ptr
) 0, length
))
2932 error (_("Error reading .debug section of `%s': %s"),
2933 name
, bfd_errmsg (bfd_get_error ()));
2937 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
=
2942 /* Read the symbols. We keep them in core because we will want to
2943 access them randomly in read_symbol*. */
2944 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2946 error (_("Error reading symbols from %s: %s"),
2947 name
, bfd_errmsg (bfd_get_error ()));
2948 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2949 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
=
2950 obstack_alloc (&objfile
->objfile_obstack
, size
);
2951 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl_num_syms
=
2954 val
= bfd_bread (((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
,
2957 perror_with_name (_("reading symbol table"));
2959 /* If we are reinitializing, or if we have never loaded syms yet, init */
2960 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2961 /* I'm not sure how how good num_symbols is; the rule of thumb in
2962 init_psymbol_list was developed for a.out. On the one hand,
2963 num_symbols includes auxents. On the other hand, it doesn't
2965 init_psymbol_list (objfile
, num_symbols
);
2967 free_pending_blocks ();
2968 back_to
= make_cleanup (really_free_pendings
, 0);
2970 init_minimal_symbol_collection ();
2971 make_cleanup_discard_minimal_symbols ();
2973 /* Now that the symbol table data of the executable file are all in core,
2974 process them and define symbols accordingly. */
2976 scan_xcoff_symtab (objfile
);
2978 /* Install any minimal symbols that have been collected as the current
2979 minimal symbols for this objfile. */
2981 install_minimal_symbols (objfile
);
2983 do_cleanups (back_to
);
2987 xcoff_symfile_offsets (struct objfile
*objfile
, struct section_addr_info
*addrs
)
2989 asection
*sect
= NULL
;
2992 objfile
->num_sections
= bfd_count_sections (objfile
->obfd
);
2993 objfile
->section_offsets
= (struct section_offsets
*)
2994 obstack_alloc (&objfile
->objfile_obstack
,
2995 SIZEOF_N_SECTION_OFFSETS (objfile
->num_sections
));
2997 /* Initialize the section indexes for future use. */
2998 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
3000 objfile
->sect_index_text
= sect
->index
;
3002 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
3004 objfile
->sect_index_data
= sect
->index
;
3006 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
3008 objfile
->sect_index_bss
= sect
->index
;
3010 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
3012 objfile
->sect_index_rodata
= sect
->index
;
3014 for (i
= 0; i
< objfile
->num_sections
; ++i
)
3016 /* syms_from_objfile kindly subtracts from addr the
3017 bfd_section_vma of the .text section. This strikes me as
3018 wrong--whether the offset to be applied to symbol reading is
3019 relative to the start address of the section depends on the
3020 symbol format. In any event, this whole "addr" concept is
3021 pretty broken (it doesn't handle any section but .text
3022 sensibly), so just ignore the addr parameter and use 0.
3023 rs6000-nat.c will set the correct section offsets via
3024 objfile_relocate. */
3025 (objfile
->section_offsets
)->offsets
[i
] = 0;
3029 /* Register our ability to parse symbols for xcoff BFD files. */
3031 static const struct sym_fns xcoff_sym_fns
=
3034 /* It is possible that coff and xcoff should be merged as
3035 they do have fundamental similarities (for example, the extra storage
3036 classes used for stabs could presumably be recognized in any COFF file).
3037 However, in addition to obvious things like all the csect hair, there are
3038 some subtler differences between xcoffread.c and coffread.c, notably
3039 the fact that coffread.c has no need to read in all the symbols, but
3040 xcoffread.c reads all the symbols and does in fact randomly access them
3041 (in C_BSTAT and line number processing). */
3043 bfd_target_xcoff_flavour
,
3045 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3046 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3047 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
3048 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3049 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
3050 default_symfile_segments
, /* sym_segments: Get segment information from
3052 aix_process_linenos
, /* sym_read_linetable */
3053 default_symfile_relocate
, /* sym_relocate: Relocate a debug section. */
3057 /* Provide a prototype to silence -Wmissing-prototypes. */
3058 extern initialize_file_ftype _initialize_xcoffread
;
3061 _initialize_xcoffread (void)
3063 add_symtab_fns (&xcoff_sym_fns
);