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
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"
45 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */
49 #include "stabsread.h"
50 #include "expression.h"
51 #include "complaints.h"
53 #include "gdb-stabs.h"
55 /* For interface with stabsread.c. */
56 #include "aout/stab_gnu.h"
59 /* We put a pointer to this structure in the read_symtab_private field
65 /* First symbol number for this file. */
69 /* Number of symbols in the section of the symbol table devoted to
70 this file's symbols (actually, the section bracketed may contain
71 more than just this file's symbols). If numsyms is 0, the only
72 reason for this thing's existence is the dependency list. Nothing
73 else will happen when it is read in. */
77 /* Position of the start of the line number information for this psymtab. */
78 unsigned int lineno_off
;
81 /* Remember what we deduced to be the source language of this psymtab. */
83 static enum language psymtab_language
= language_unknown
;
86 /* Simplified internal version of coff symbol table information */
91 int c_symnum
; /* symbol number of this entry */
92 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
94 unsigned char c_sclass
;
99 /* last function's saved coff symbol `cs' */
101 static struct coff_symbol fcn_cs_saved
;
103 static bfd
*symfile_bfd
;
105 /* Core address of start and end of text of current source file.
106 This is calculated from the first function seen after a C_FILE
110 static CORE_ADDR cur_src_end_addr
;
112 /* Core address of the end of the first object file. */
114 static CORE_ADDR first_object_file_end
;
116 /* initial symbol-table-debug-string vector length */
118 #define INITIAL_STABVECTOR_LENGTH 40
120 /* Nonzero if within a function (so symbols should be local,
121 if nothing says specifically). */
125 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
126 there is any reason not to just use a #define, but might as well
127 ask BFD for the size and store it here, I guess. */
129 static unsigned local_symesz
;
131 struct coff_symfile_info
133 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
134 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
136 /* Pointer to the string table. */
139 /* Pointer to debug section. */
142 /* Pointer to the a.out symbol table. */
145 /* Number of symbols in symtbl. */
148 /* Offset in data section to TOC anchor. */
149 CORE_ADDR toc_offset
;
153 bf_notfound_complaint (void)
155 complaint (&symfile_complaints
, _("line numbers off, `.bf' symbol not found"));
159 ef_complaint (int arg1
)
161 complaint (&symfile_complaints
,
162 _("Mismatched .ef symbol ignored starting at symnum %d"), arg1
);
166 eb_complaint (int arg1
)
168 complaint (&symfile_complaints
,
169 _("Mismatched .eb symbol ignored starting at symnum %d"), arg1
);
172 static void xcoff_initial_scan (struct objfile
*, int);
174 static void scan_xcoff_symtab (struct objfile
*);
176 static char *xcoff_next_symbol_text (struct objfile
*);
178 static void record_include_begin (struct coff_symbol
*);
181 enter_line_range (struct subfile
*, unsigned, unsigned,
182 CORE_ADDR
, CORE_ADDR
, unsigned *);
184 static void init_stringtab (bfd
*, file_ptr
, struct objfile
*);
186 static void xcoff_symfile_init (struct objfile
*);
188 static void xcoff_new_init (struct objfile
*);
190 static void xcoff_symfile_finish (struct objfile
*);
192 static void xcoff_symfile_offsets (struct objfile
*,
193 struct section_addr_info
*addrs
);
195 static char *coff_getfilename (union internal_auxent
*, struct objfile
*);
197 static void read_symbol (struct internal_syment
*, int);
199 static int read_symbol_lineno (int);
201 static CORE_ADDR
read_symbol_nvalue (int);
203 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
206 static void read_xcoff_symtab (struct partial_symtab
*);
209 static void add_stab_to_list (char *, struct pending_stabs
**);
212 static int compare_lte (const void *, const void *);
214 static struct linetable
*arrange_linetable (struct linetable
*);
216 static void record_include_end (struct coff_symbol
*);
218 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
221 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
223 static int secnum_to_section (int, struct objfile
*);
224 static asection
*secnum_to_bfd_section (int, struct objfile
*);
226 struct find_targ_sec_arg
231 struct objfile
*objfile
;
234 static void find_targ_sec (bfd
*, asection
*, void *);
237 find_targ_sec (bfd
*abfd
, asection
*sect
, void *obj
)
239 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
240 struct objfile
*objfile
= args
->objfile
;
241 if (sect
->target_index
== args
->targ_index
)
243 /* This is the section. Figure out what SECT_OFF_* code it is. */
244 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
245 *args
->resultp
= SECT_OFF_TEXT (objfile
);
246 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
247 *args
->resultp
= SECT_OFF_DATA (objfile
);
249 *args
->resultp
= sect
->index
;
250 *args
->bfd_sect
= sect
;
254 /* Return the section number (SECT_OFF_*) that CS points to. */
256 secnum_to_section (int secnum
, struct objfile
*objfile
)
258 int off
= SECT_OFF_TEXT (objfile
);
259 asection
*sect
= NULL
;
260 struct find_targ_sec_arg args
;
261 args
.targ_index
= secnum
;
263 args
.bfd_sect
= §
;
264 args
.objfile
= objfile
;
265 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
269 /* Return the BFD section that CS points to. */
271 secnum_to_bfd_section (int secnum
, struct objfile
*objfile
)
273 int off
= SECT_OFF_TEXT (objfile
);
274 asection
*sect
= NULL
;
275 struct find_targ_sec_arg args
;
276 args
.targ_index
= secnum
;
278 args
.bfd_sect
= §
;
279 args
.objfile
= objfile
;
280 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
284 /* add a given stab string into given stab vector. */
289 add_stab_to_list (char *stabname
, struct pending_stabs
**stabvector
)
291 if (*stabvector
== NULL
)
293 *stabvector
= (struct pending_stabs
*)
294 xmalloc (sizeof (struct pending_stabs
) +
295 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
296 (*stabvector
)->count
= 0;
297 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
299 else if ((*stabvector
)->count
>= (*stabvector
)->length
)
301 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
302 *stabvector
= (struct pending_stabs
*)
303 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
304 (*stabvector
)->length
* sizeof (char *));
306 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
311 /* Linenos are processed on a file-by-file basis.
315 1) xlc (IBM's native c compiler) postpones static function code
316 emission to the end of a compilation unit. This way it can
317 determine if those functions (statics) are needed or not, and
318 can do some garbage collection (I think). This makes line
319 numbers and corresponding addresses unordered, and we end up
320 with a line table like:
337 and that breaks gdb's binary search on line numbers, if the
338 above table is not sorted on line numbers. And that sort
339 should be on function based, since gcc can emit line numbers
342 10 0x100 - for the init/test part of a for stmt.
345 10 0x400 - for the increment part of a for stmt.
347 arrange_linetable() will do this sorting.
349 2) aix symbol table might look like:
351 c_file // beginning of a new file
352 .bi // beginning of include file
353 .ei // end of include file
357 basically, .bi/.ei pairs do not necessarily encapsulate
358 their scope. They need to be recorded, and processed later
359 on when we come the end of the compilation unit.
360 Include table (inclTable) and process_linenos() handle
366 /* compare line table entry addresses. */
369 compare_lte (const void *lte1p
, const void *lte2p
)
371 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
372 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
373 return lte1
->pc
- lte2
->pc
;
376 /* Given a line table with function entries are marked, arrange its functions
377 in ascending order and strip off function entry markers and return it in
378 a newly created table. If the old one is good enough, return the old one. */
379 /* FIXME: I think all this stuff can be replaced by just passing
380 sort_linevec = 1 to end_symtab. */
382 static struct linetable
*
383 arrange_linetable (struct linetable
*oldLineTb
)
385 int ii
, jj
, newline
, /* new line count */
386 function_count
; /* # of functions */
388 struct linetable_entry
*fentry
; /* function entry vector */
389 int fentry_size
; /* # of function entries */
390 struct linetable
*newLineTb
; /* new line table */
392 #define NUM_OF_FUNCTIONS 20
394 fentry_size
= NUM_OF_FUNCTIONS
;
395 fentry
= (struct linetable_entry
*)
396 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
398 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
401 if (oldLineTb
->item
[ii
].line
== 0)
402 { /* function entry found. */
404 if (function_count
>= fentry_size
)
405 { /* make sure you have room. */
407 fentry
= (struct linetable_entry
*)
408 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
410 fentry
[function_count
].line
= ii
;
411 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
416 if (function_count
== 0)
421 else if (function_count
> 1)
422 qsort (fentry
, function_count
, sizeof (struct linetable_entry
), compare_lte
);
424 /* allocate a new line table. */
425 newLineTb
= (struct linetable
*)
427 (sizeof (struct linetable
) +
428 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
430 /* if line table does not start with a function beginning, copy up until
434 if (oldLineTb
->item
[0].line
!= 0)
436 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
437 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
439 /* Now copy function lines one by one. */
441 for (ii
= 0; ii
< function_count
; ++ii
)
443 for (jj
= fentry
[ii
].line
+ 1;
444 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
446 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
449 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
453 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
454 following `IncludeChain'. At the end of each symtab (end_symtab),
455 we will determine if we should create additional symtab's to
456 represent if (the include files. */
459 typedef struct _inclTable
461 char *name
; /* include filename */
463 /* Offsets to the line table. end points to the last entry which is
464 part of this include file. */
467 struct subfile
*subfile
;
468 unsigned funStartLine
; /* start line # of its function */
472 #define INITIAL_INCLUDE_TABLE_LENGTH 20
473 static InclTable
*inclTable
; /* global include table */
474 static int inclIndx
; /* last entry to table */
475 static int inclLength
; /* table length */
476 static int inclDepth
; /* nested include depth */
478 static void allocate_include_entry (void);
481 record_include_begin (struct coff_symbol
*cs
)
485 /* In xcoff, we assume include files cannot be nested (not in .c files
486 of course, but in corresponding .s files.). */
488 /* This can happen with old versions of GCC.
489 GCC 2.3.3-930426 does not exhibit this on a test case which
490 a user said produced the message for him. */
491 complaint (&symfile_complaints
, _("Nested C_BINCL symbols"));
495 allocate_include_entry ();
497 inclTable
[inclIndx
].name
= cs
->c_name
;
498 inclTable
[inclIndx
].begin
= cs
->c_value
;
502 record_include_end (struct coff_symbol
*cs
)
508 complaint (&symfile_complaints
, _("Mismatched C_BINCL/C_EINCL pair"));
511 allocate_include_entry ();
513 pTbl
= &inclTable
[inclIndx
];
514 pTbl
->end
= cs
->c_value
;
521 allocate_include_entry (void)
523 if (inclTable
== NULL
)
525 inclTable
= (InclTable
*)
526 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
528 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
529 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
532 else if (inclIndx
>= inclLength
)
534 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
535 inclTable
= (InclTable
*)
536 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
537 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
538 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
542 /* Global variable to pass the psymtab down to all the routines involved
543 in psymtab to symtab processing. */
544 static struct partial_symtab
*this_symtab_psymtab
;
546 /* given the start and end addresses of a compilation unit (or a csect,
547 at times) process its lines and create appropriate line vectors. */
550 process_linenos (CORE_ADDR start
, CORE_ADDR end
)
553 file_ptr max_offset
=
554 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)
557 /* subfile structure for the main compilation unit. */
558 struct subfile main_subfile
;
560 /* In the main source file, any time we see a function entry, we
561 reset this variable to function's absolute starting line number.
562 All the following line numbers in the function are relative to
563 this, and we record absolute line numbers in record_line(). */
565 unsigned int main_source_baseline
= 0;
570 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
572 goto return_after_cleanup
;
574 memset (&main_subfile
, '\0', sizeof (main_subfile
));
577 /* All source lines were in the main source file. None in include files. */
579 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
580 &main_source_baseline
);
584 /* There was source with line numbers in include files. */
587 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
588 main_source_baseline
= 0;
590 for (ii
= 0; ii
< inclIndx
; ++ii
)
592 struct subfile
*tmpSubfile
;
594 /* If there is main file source before include file, enter it. */
595 if (offset
< inclTable
[ii
].begin
)
598 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
599 start
, 0, &main_source_baseline
);
602 /* Have a new subfile for the include file. */
604 tmpSubfile
= inclTable
[ii
].subfile
=
605 (struct subfile
*) xmalloc (sizeof (struct subfile
));
607 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
608 firstLine
= &(inclTable
[ii
].funStartLine
);
610 /* Enter include file's lines now. */
611 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
612 inclTable
[ii
].end
, start
, 0, firstLine
);
614 if (offset
<= inclTable
[ii
].end
)
615 offset
= inclTable
[ii
].end
+ linesz
;
618 /* All the include files' line have been processed at this point. Now,
619 enter remaining lines of the main file, if any left. */
620 if (offset
< max_offset
+ 1 - linesz
)
622 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
623 &main_source_baseline
);
627 /* Process main file's line numbers. */
628 if (main_subfile
.line_vector
)
630 struct linetable
*lineTb
, *lv
;
632 lv
= main_subfile
.line_vector
;
634 /* Line numbers are not necessarily ordered. xlc compilation will
635 put static function to the end. */
637 lineTb
= arrange_linetable (lv
);
640 current_subfile
->line_vector
= (struct linetable
*)
641 xrealloc (lv
, (sizeof (struct linetable
)
642 + lv
->nitems
* sizeof (struct linetable_entry
)));
647 current_subfile
->line_vector
= lineTb
;
650 current_subfile
->line_vector_length
=
651 current_subfile
->line_vector
->nitems
;
654 /* Now, process included files' line numbers. */
656 for (ii
= 0; ii
< inclIndx
; ++ii
)
658 if ((inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
660 struct linetable
*lineTb
, *lv
;
662 lv
= (inclTable
[ii
].subfile
)->line_vector
;
664 /* Line numbers are not necessarily ordered. xlc compilation will
665 put static function to the end. */
667 lineTb
= arrange_linetable (lv
);
671 /* For the same include file, we might want to have more than one
672 subfile. This happens if we have something like:
680 while foo.h including code in it. (stupid but possible)
681 Since start_subfile() looks at the name and uses an
682 existing one if finds, we need to provide a fake name and
686 start_subfile (inclTable
[ii
].name
, (char *) 0);
689 /* Pick a fake name that will produce the same results as this
690 one when passed to deduce_language_from_filename. Kludge on
692 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
693 if (fakename
== NULL
)
695 start_subfile (fakename
, (char *) 0);
696 xfree (current_subfile
->name
);
698 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
703 current_subfile
->line_vector
=
704 (struct linetable
*) xrealloc
705 (lv
, (sizeof (struct linetable
)
706 + lv
->nitems
* sizeof (struct linetable_entry
)));
712 current_subfile
->line_vector
= lineTb
;
715 current_subfile
->line_vector_length
=
716 current_subfile
->line_vector
->nitems
;
717 start_subfile (pop_subfile (), (char *) 0);
721 return_after_cleanup
:
723 /* We don't want to keep alloc/free'ing the global include file table. */
726 /* Start with a fresh subfile structure for the next file. */
727 memset (&main_subfile
, '\0', sizeof (struct subfile
));
731 aix_process_linenos (void)
733 /* process line numbers and enter them into line vector */
734 process_linenos (last_source_start_addr
, cur_src_end_addr
);
738 /* Enter a given range of lines into the line vector.
739 can be called in the following two ways:
740 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
741 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
743 endoffset points to the last line table entry that we should pay
747 enter_line_range (struct subfile
*subfile
, unsigned beginoffset
, unsigned endoffset
, /* offsets to line table */
748 CORE_ADDR startaddr
, /* offsets to line table */
749 CORE_ADDR endaddr
, unsigned *firstLine
)
751 unsigned int curoffset
;
754 struct internal_lineno int_lnno
;
755 unsigned int limit_offset
;
759 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
761 curoffset
= beginoffset
;
763 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)
768 if (endoffset
>= limit_offset
)
770 complaint (&symfile_complaints
,
771 _("Bad line table offset in C_EINCL directive"));
774 limit_offset
= endoffset
;
779 abfd
= this_symtab_psymtab
->objfile
->obfd
;
780 linesz
= coff_data (abfd
)->local_linesz
;
781 ext_lnno
= alloca (linesz
);
783 while (curoffset
<= limit_offset
)
785 bfd_seek (abfd
, curoffset
, SEEK_SET
);
786 bfd_bread (ext_lnno
, linesz
, abfd
);
787 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
789 /* Find the address this line represents. */
790 addr
= (int_lnno
.l_lnno
791 ? int_lnno
.l_addr
.l_paddr
792 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
793 addr
+= ANOFFSET (this_symtab_psymtab
->objfile
->section_offsets
,
794 SECT_OFF_TEXT (this_symtab_psymtab
->objfile
));
796 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
799 if (int_lnno
.l_lnno
== 0)
801 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
802 record_line (subfile
, 0, addr
);
806 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
, addr
);
812 /* Save the vital information for use when closing off the current file.
813 NAME is the file name the symbols came from, START_ADDR is the first
814 text address for the file, and SIZE is the number of bytes of text. */
816 #define complete_symtab(name, start_addr) { \
817 last_source_file = savestring (name, strlen (name)); \
818 last_source_start_addr = start_addr; \
822 /* Refill the symbol table input buffer
823 and set the variables that control fetching entries from it.
824 Reports an error if no data available.
825 This function can read past the end of the symbol table
826 (into the string table) but this does no harm. */
828 /* Reading symbol table has to be fast! Keep the followings as macros, rather
831 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
835 if (namestr[0] == '.') ++namestr; \
836 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
837 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
838 misc_func_recorded = 1; \
842 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
843 nested. At any given time, a symbol can only be in one static block.
844 This is the base address of current static block, zero if non exists. */
846 static int static_block_base
= 0;
848 /* Section number for the current static block. */
850 static int static_block_section
= -1;
852 /* true if space for symbol name has been allocated. */
854 static int symname_alloced
= 0;
856 /* Next symbol to read. Pointer into raw seething symbol table. */
858 static char *raw_symbol
;
860 /* This is the function which stabsread.c calls to get symbol
864 xcoff_next_symbol_text (struct objfile
*objfile
)
866 struct internal_syment symbol
;
868 /* FIXME: is this the same as the passed arg? */
869 if (this_symtab_psymtab
)
870 objfile
= this_symtab_psymtab
->objfile
;
872 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
875 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
877 /* Return something which points to '\0' and hope the symbol reading
878 code does something reasonable. */
881 else if (symbol
.n_sclass
& 0x80)
884 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
887 coff_data (objfile
->obfd
)->local_symesz
;
892 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
894 /* Return something which points to '\0' and hope the symbol reading
895 code does something reasonable. */
901 /* Read symbols for a given partial symbol table. */
904 read_xcoff_symtab (struct partial_symtab
*pst
)
906 struct objfile
*objfile
= pst
->objfile
;
907 bfd
*abfd
= objfile
->obfd
;
908 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
909 char *strtbl
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
;
911 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
;
912 char *debugfmt
= bfd_xcoff_is_xcoff64 (abfd
) ? "XCOFF64" : "XCOFF";
914 struct internal_syment symbol
[1];
915 union internal_auxent main_aux
;
916 struct coff_symbol cs
[1];
917 CORE_ADDR file_start_addr
= 0;
918 CORE_ADDR file_end_addr
= 0;
920 int next_file_symnum
= -1;
921 unsigned int max_symnum
;
922 int just_started
= 1;
924 int fcn_start_addr
= 0;
926 struct coff_symbol fcn_stab_saved
= { 0 };
928 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
929 union internal_auxent fcn_aux_saved
;
930 struct context_stack
*new;
932 char *filestring
= " _start_ "; /* Name of the current file. */
934 char *last_csect_name
; /* last seen csect's name and value */
935 CORE_ADDR last_csect_val
;
938 this_symtab_psymtab
= pst
;
940 /* Get the appropriate COFF "constants" related to the file we're
942 local_symesz
= coff_data (abfd
)->local_symesz
;
944 last_source_file
= NULL
;
949 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
950 record_debugformat (debugfmt
);
951 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
953 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
954 first_object_file_end
= 0;
957 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
958 + symnum
* local_symesz
;
960 while (symnum
< max_symnum
)
963 QUIT
; /* make this command interruptable. */
965 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
966 /* read one symbol into `cs' structure. After processing the
967 whole symbol table, only string table will be kept in memory,
968 symbol table and debug section of xcoff will be freed. Thus
969 we can mark symbols with names in string table as
974 /* Swap and align the symbol into a reasonable C structure. */
975 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
977 cs
->c_symnum
= symnum
;
978 cs
->c_naux
= symbol
->n_numaux
;
979 if (symbol
->n_zeroes
)
982 /* We must use the original, unswapped, name here so the name field
983 pointed to by cs->c_name will persist throughout xcoffread. If
984 we use the new field, it gets overwritten for each symbol. */
985 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
986 /* If it's exactly E_SYMNMLEN characters long it isn't
988 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
991 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
992 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
993 p
[E_SYMNMLEN
] = '\0';
998 else if (symbol
->n_sclass
& 0x80)
1000 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1001 symname_alloced
= 0;
1005 /* in string table */
1006 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1007 symname_alloced
= 1;
1009 cs
->c_value
= symbol
->n_value
;
1010 cs
->c_sclass
= symbol
->n_sclass
;
1011 cs
->c_secnum
= symbol
->n_scnum
;
1012 cs
->c_type
= (unsigned) symbol
->n_type
;
1014 raw_symbol
+= local_symesz
;
1017 /* Save addr of first aux entry. */
1018 raw_auxptr
= raw_symbol
;
1020 /* Skip all the auxents associated with this symbol. */
1021 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1023 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1028 /* if symbol name starts with ".$" or "$", ignore it. */
1029 if (cs
->c_name
[0] == '$'
1030 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1033 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1035 if (last_source_file
)
1038 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1043 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1044 record_debugformat (debugfmt
);
1045 cur_src_end_addr
= first_object_file_end
;
1046 /* done with all files, everything from here on is globals */
1049 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1052 /* Dealing with a symbol with a csect entry. */
1054 #define CSECT(PP) ((PP)->x_csect)
1055 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1056 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1057 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1058 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1060 /* Convert the auxent to something we can access. */
1061 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1062 0, cs
->c_naux
, &main_aux
);
1064 switch (CSECT_SMTYP (&main_aux
))
1068 /* Ignore all external references. */
1072 /* A section description. */
1074 switch (CSECT_SCLAS (&main_aux
))
1080 /* A program csect is seen. We have to allocate one
1081 symbol table for each program csect. Normally gdb
1082 prefers one symtab for each source file. In case
1083 of AIX, one source file might include more than one
1084 [PR] csect, and they don't have to be adjacent in
1085 terms of the space they occupy in memory. Thus, one
1086 single source file might get fragmented in the
1087 memory and gdb's file start and end address
1088 approach does not work! GCC (and I think xlc) seem
1089 to put all the code in the unnamed program csect. */
1091 if (last_csect_name
)
1093 complete_symtab (filestring
, file_start_addr
);
1094 cur_src_end_addr
= file_end_addr
;
1095 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1098 /* Give all csects for this source file the same
1100 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1101 record_debugformat (debugfmt
);
1104 /* If this is the very first csect seen,
1105 basically `__start'. */
1108 first_object_file_end
1109 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1114 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1115 SECT_OFF_TEXT (objfile
));
1116 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1118 if (cs
->c_name
&& (cs
->c_name
[0] == '.'
1119 || cs
->c_name
[0] == '@'))
1121 last_csect_name
= cs
->c_name
;
1122 last_csect_val
= cs
->c_value
;
1123 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1128 /* All other symbols are put into the minimal symbol
1141 /* Ignore the symbol. */
1149 switch (CSECT_SCLAS (&main_aux
))
1152 /* a function entry point. */
1153 function_entry_point
:
1155 fcn_start_addr
= cs
->c_value
;
1157 /* save the function header info, which will be used
1158 when `.bf' is seen. */
1160 fcn_aux_saved
= main_aux
;
1164 /* shared library function trampoline code entry point. */
1168 /* The symbols often have the same names as debug symbols for
1169 functions, and confuse lookup_symbol. */
1173 /* xlc puts each variable in a separate csect, so we get
1174 an XTY_SD for each variable. But gcc puts several
1175 variables in a csect, so that each variable only gets
1176 an XTY_LD. This will typically be XMC_RW; I suspect
1177 XMC_RO and XMC_BS might be possible too.
1178 These variables are put in the minimal symbol table
1185 /* Common symbols are put into the minimal symbol table only. */
1193 /* If explicitly specified as a function, treat is as one. This check
1194 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1195 after the above CSECT check. */
1196 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1198 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1199 0, cs
->c_naux
, &main_aux
);
1200 goto function_entry_point
;
1203 switch (cs
->c_sclass
)
1208 /* c_value field contains symnum of next .file entry in table
1209 or symnum of first global after last .file. */
1211 next_file_symnum
= cs
->c_value
;
1213 /* Complete symbol table for last object file containing
1214 debugging information. */
1216 /* Whether or not there was a csect in the previous file, we
1217 have to call `end_stabs' and `start_stabs' to reset
1218 type_vector, line_vector, etc. structures. */
1220 complete_symtab (filestring
, file_start_addr
);
1221 cur_src_end_addr
= file_end_addr
;
1222 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1225 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1226 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1227 standard COFF way and put it in the auxent. We use the auxent if
1228 the symbol is ".file" and an auxent exists, otherwise use the symbol
1229 itself. Simple enough. */
1230 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1232 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1233 0, cs
->c_naux
, &main_aux
);
1234 filestring
= coff_getfilename (&main_aux
, objfile
);
1237 filestring
= cs
->c_name
;
1240 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1241 record_debugformat (debugfmt
);
1242 last_csect_name
= 0;
1244 /* reset file start and end addresses. A compilation unit with no text
1245 (only data) should have zero file boundaries. */
1246 file_start_addr
= file_end_addr
= 0;
1250 fcn_stab_saved
= *cs
;
1254 if (strcmp (cs
->c_name
, ".bf") == 0)
1256 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1257 SECT_OFF_TEXT (objfile
));
1258 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1259 0, cs
->c_naux
, &main_aux
);
1261 within_function
= 1;
1263 new = push_context (0, fcn_start_addr
+ off
);
1265 new->name
= define_symbol
1266 (fcn_cs_saved
.c_value
+ off
,
1267 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1268 if (new->name
!= NULL
)
1269 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1271 else if (strcmp (cs
->c_name
, ".ef") == 0)
1274 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1275 0, cs
->c_naux
, &main_aux
);
1277 /* The value of .ef is the address of epilogue code;
1278 not useful for gdb. */
1279 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1280 contains number of lines to '}' */
1282 if (context_stack_depth
<= 0)
1283 { /* We attempted to pop an empty context stack */
1284 ef_complaint (cs
->c_symnum
);
1285 within_function
= 0;
1288 new = pop_context ();
1289 /* Stack must be empty now. */
1290 if (context_stack_depth
> 0 || new == NULL
)
1292 ef_complaint (cs
->c_symnum
);
1293 within_function
= 0;
1297 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1299 (fcn_cs_saved
.c_value
1300 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1301 + ANOFFSET (objfile
->section_offsets
,
1302 SECT_OFF_TEXT (objfile
))),
1304 within_function
= 0;
1309 /* Begin static block. */
1311 struct internal_syment symbol
;
1313 read_symbol (&symbol
, cs
->c_value
);
1314 static_block_base
= symbol
.n_value
;
1315 static_block_section
=
1316 secnum_to_section (symbol
.n_scnum
, objfile
);
1321 /* End of static block. */
1322 static_block_base
= 0;
1323 static_block_section
= -1;
1334 complaint (&symfile_complaints
, _("Unrecognized storage class %d."),
1349 /* beginning of include file */
1350 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1351 order. Thus, when wee see them, we might not know enough info
1352 to process them. Thus, we'll be saving them into a table
1353 (inclTable) and postpone their processing. */
1355 record_include_begin (cs
);
1359 /* End of include file. */
1360 /* See the comment after case C_BINCL. */
1361 record_include_end (cs
);
1365 if (strcmp (cs
->c_name
, ".bb") == 0)
1368 new = push_context (depth
,
1370 + ANOFFSET (objfile
->section_offsets
,
1371 SECT_OFF_TEXT (objfile
))));
1373 else if (strcmp (cs
->c_name
, ".eb") == 0)
1375 if (context_stack_depth
<= 0)
1376 { /* We attempted to pop an empty context stack */
1377 eb_complaint (cs
->c_symnum
);
1380 new = pop_context ();
1381 if (depth
-- != new->depth
)
1383 eb_complaint (cs
->c_symnum
);
1386 if (local_symbols
&& context_stack_depth
> 0)
1388 /* Make a block for the local symbols within. */
1389 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1392 + ANOFFSET (objfile
->section_offsets
,
1393 SECT_OFF_TEXT (objfile
))),
1396 local_symbols
= new->locals
;
1401 process_xcoff_symbol (cs
, objfile
);
1406 if (last_source_file
)
1410 complete_symtab (filestring
, file_start_addr
);
1411 cur_src_end_addr
= file_end_addr
;
1412 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1413 /* When reading symbols for the last C_FILE of the objfile, try
1414 to make sure that we set pst->symtab to the symtab for the
1415 file, not to the _globals_ symtab. I'm not sure whether this
1416 actually works right or when/if it comes up. */
1417 if (pst
->symtab
== NULL
)
1423 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1424 (SYMBOL2) = (struct symbol *) \
1425 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1426 *(SYMBOL2) = *(SYMBOL1);
1429 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1430 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->objfile_obstack))
1433 /* process one xcoff symbol. */
1435 static struct symbol
*
1436 process_xcoff_symbol (struct coff_symbol
*cs
, struct objfile
*objfile
)
1438 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1439 struct symbol onesymbol
;
1440 struct symbol
*sym
= &onesymbol
;
1441 struct symbol
*sym2
= NULL
;
1447 if (cs
->c_secnum
< 0)
1449 /* The value is a register number, offset within a frame, etc.,
1450 and does not get relocated. */
1456 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1457 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1464 memset (sym
, '\0', sizeof (struct symbol
));
1466 /* default assumptions */
1467 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1468 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1469 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1471 if (ISFCN (cs
->c_type
))
1473 /* At this point, we don't know the type of the function. This
1474 will be patched with the type from its stab entry later on in
1475 patch_block_stabs (), unless the file was compiled without -g. */
1477 SYMBOL_SET_LINKAGE_NAME (sym
, SYMNAME_ALLOC (name
, symname_alloced
));
1478 SYMBOL_TYPE (sym
) = builtin_type (gdbarch
)->nodebug_text_symbol
;
1480 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1481 SYMBOL_DUP (sym
, sym2
);
1483 if (cs
->c_sclass
== C_EXT
)
1484 add_symbol_to_list (sym2
, &global_symbols
);
1485 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1486 add_symbol_to_list (sym2
, &file_symbols
);
1490 /* In case we can't figure out the type, provide default. */
1491 SYMBOL_TYPE (sym
) = builtin_type (gdbarch
)->nodebug_data_symbol
;
1493 switch (cs
->c_sclass
)
1496 /* The values of functions and global symbols are now resolved
1497 via the global_sym_chain in stabsread.c. */
1499 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1500 add_stab_to_list (name
, &global_stabs
);
1502 add_stab_to_list (name
, &file_stabs
);
1506 add_stab_to_list (name
, &global_stabs
);
1511 common_block_start (cs
->c_name
, objfile
);
1515 common_block_end (objfile
);
1519 complaint (&symfile_complaints
, _("Unexpected storage class: %d"),
1532 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1535 SYMBOL_SECTION (sym
) = sec
;
1542 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1543 all statics and we need to distinguish file-scope versus
1544 function-scope using within_function. We do this by
1545 changing the string we pass to define_symbol to use 'S'
1546 where we need to, which is not necessarily super-clean,
1547 but seems workable enough. */
1549 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1553 if (*pp
== 'V' && !within_function
)
1555 sym
= define_symbol ((cs
->c_value
1556 + ANOFFSET (objfile
->section_offsets
,
1557 static_block_section
)),
1558 cs
->c_name
, 0, 0, objfile
);
1561 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1562 SYMBOL_SECTION (sym
) = static_block_section
;
1571 /* Extract the file name from the aux entry of a C_FILE symbol.
1572 Result is in static storage and is only good for temporary use. */
1575 coff_getfilename (union internal_auxent
*aux_entry
, struct objfile
*objfile
)
1577 static char buffer
[BUFSIZ
];
1579 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1581 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
1582 + aux_entry
->x_file
.x_n
.x_offset
);
1585 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1586 buffer
[FILNMLEN
] = '\0';
1591 /* Set *SYMBOL to symbol number symno in symtbl. */
1593 read_symbol (struct internal_syment
*symbol
, int symno
)
1596 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl_num_syms
;
1598 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl
;
1599 if (symno
< 0 || symno
>= nsyms
)
1601 complaint (&symfile_complaints
, _("Invalid symbol offset"));
1602 symbol
->n_value
= 0;
1603 symbol
->n_scnum
= -1;
1606 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1607 stbl
+ (symno
* local_symesz
),
1611 /* Get value corresponding to symbol number symno in symtbl. */
1614 read_symbol_nvalue (int symno
)
1616 struct internal_syment symbol
[1];
1618 read_symbol (symbol
, symno
);
1619 return symbol
->n_value
;
1623 /* Find the address of the function corresponding to symno, where
1624 symno is the symbol pointed to by the linetable. */
1627 read_symbol_lineno (int symno
)
1629 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1630 int xcoff64
= bfd_xcoff_is_xcoff64 (objfile
->obfd
);
1632 struct coff_symfile_info
*info
=
1633 (struct coff_symfile_info
*)objfile
->deprecated_sym_private
;
1634 int nsyms
= info
->symtbl_num_syms
;
1635 char *stbl
= info
->symtbl
;
1636 char *strtbl
= info
->strtbl
;
1638 struct internal_syment symbol
[1];
1639 union internal_auxent main_aux
[1];
1643 bf_notfound_complaint ();
1647 /* Note that just searching for a short distance (e.g. 50 symbols)
1648 is not enough, at least in the following case.
1651 [many .stabx entries]
1652 [a few functions, referring to foo]
1656 What happens here is that the assembler moves the .stabx entries
1657 to right before the ".bf" for foo, but the symbol for "foo" is before
1658 all the stabx entries. See PR gdb/2222. */
1660 /* Maintaining a table of .bf entries might be preferable to this search.
1661 If I understand things correctly it would need to be done only for
1662 the duration of a single psymtab to symtab conversion. */
1663 while (symno
< nsyms
)
1665 bfd_coff_swap_sym_in (symfile_bfd
,
1666 stbl
+ (symno
* local_symesz
), symbol
);
1667 if (symbol
->n_sclass
== C_FCN
)
1669 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1670 if (strcmp (name
, ".bf") == 0)
1673 symno
+= symbol
->n_numaux
+ 1;
1676 bf_notfound_complaint ();
1680 /* take aux entry and return its lineno */
1682 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1683 symbol
->n_type
, symbol
->n_sclass
,
1684 0, symbol
->n_numaux
, main_aux
);
1686 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1689 /* Support for line number handling */
1691 /* This function is called for every section; it finds the outer limits
1692 * of the line table (minimum and maximum file offset) so that the
1693 * mainline code can read the whole thing for efficiency.
1696 find_linenos (struct bfd
*abfd
, struct bfd_section
*asect
, void *vpinfo
)
1698 struct coff_symfile_info
*info
;
1700 file_ptr offset
, maxoff
;
1702 count
= asect
->lineno_count
;
1704 if (strcmp (asect
->name
, ".text") != 0 || count
== 0)
1707 size
= count
* coff_data (abfd
)->local_linesz
;
1708 info
= (struct coff_symfile_info
*) vpinfo
;
1709 offset
= asect
->line_filepos
;
1710 maxoff
= offset
+ size
;
1712 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1713 info
->min_lineno_offset
= offset
;
1715 if (maxoff
> info
->max_lineno_offset
)
1716 info
->max_lineno_offset
= maxoff
;
1719 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1722 xcoff_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1724 struct cleanup
*old_chain
;
1733 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1738 /* Read in all partial symtabs on which this one is dependent */
1739 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1740 if (!pst
->dependencies
[i
]->readin
)
1742 /* Inform about additional files that need to be read in. */
1745 fputs_filtered (" ", gdb_stdout
);
1747 fputs_filtered ("and ", gdb_stdout
);
1749 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1750 wrap_here (""); /* Flush output */
1751 gdb_flush (gdb_stdout
);
1753 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1756 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1758 /* Init stuff necessary for reading in symbols. */
1761 old_chain
= make_cleanup (really_free_pendings
, 0);
1763 read_xcoff_symtab (pst
);
1765 do_cleanups (old_chain
);
1771 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1773 /* Read in all of the symbols for a given psymtab for real.
1774 Be verbose about it if the user wants that. */
1777 xcoff_psymtab_to_symtab (struct partial_symtab
*pst
)
1787 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1792 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1793 || pst
->number_of_dependencies
)
1795 /* Print the message now, before reading the string table,
1796 to avoid disconcerting pauses. */
1799 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1800 gdb_flush (gdb_stdout
);
1803 sym_bfd
= pst
->objfile
->obfd
;
1805 next_symbol_text_func
= xcoff_next_symbol_text
;
1807 xcoff_psymtab_to_symtab_1 (pst
);
1809 /* Match with global symbols. This only needs to be done once,
1810 after all of the symtabs and dependencies have been read in. */
1811 scan_file_globals (pst
->objfile
);
1813 /* Finish up the debug error message. */
1815 printf_filtered ("done.\n");
1820 xcoff_new_init (struct objfile
*objfile
)
1822 stabsread_new_init ();
1823 buildsym_new_init ();
1826 /* Do initialization in preparation for reading symbols from OBJFILE.
1828 We will only be called if this is an XCOFF or XCOFF-like file.
1829 BFD handles figuring out the format of the file, and code in symfile.c
1830 uses BFD's determination to vector to us. */
1833 xcoff_symfile_init (struct objfile
*objfile
)
1835 /* Allocate struct to keep track of the symfile */
1836 objfile
->deprecated_sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
1838 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1839 find this causes a significant slowdown in gdb then we could
1840 set it in the debug symbol readers only when necessary. */
1841 objfile
->flags
|= OBJF_REORDERED
;
1843 init_entry_point_info (objfile
);
1846 /* Perform any local cleanups required when we are done with a particular
1847 objfile. I.E, we are in the process of discarding all symbol information
1848 for an objfile, freeing up all memory held for it, and unlinking the
1849 objfile struct from the global list of known objfiles. */
1852 xcoff_symfile_finish (struct objfile
*objfile
)
1854 if (objfile
->deprecated_sym_private
!= NULL
)
1856 xfree (objfile
->deprecated_sym_private
);
1859 /* Start with a fresh include table for the next objfile. */
1865 inclIndx
= inclLength
= inclDepth
= 0;
1870 init_stringtab (bfd
*abfd
, file_ptr offset
, struct objfile
*objfile
)
1874 unsigned char lengthbuf
[4];
1877 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
= NULL
;
1879 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1880 error (_("cannot seek to string table in %s: %s"),
1881 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1883 val
= bfd_bread ((char *) lengthbuf
, sizeof lengthbuf
, abfd
);
1884 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1886 /* If no string table is needed, then the file may end immediately
1887 after the symbols. Just return with `strtbl' set to NULL. */
1889 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1892 /* Allocate string table from objfile_obstack. We will need this table
1893 as long as we have its symbol table around. */
1895 strtbl
= (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
1896 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
= strtbl
;
1898 /* Copy length buffer, the first byte is usually zero and is
1899 used for stabs with a name length of zero. */
1900 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1901 if (length
== sizeof lengthbuf
)
1904 val
= bfd_bread (strtbl
+ sizeof lengthbuf
, length
- sizeof lengthbuf
, abfd
);
1906 if (val
!= length
- sizeof lengthbuf
)
1907 error (_("cannot read string table from %s: %s"),
1908 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1909 if (strtbl
[length
- 1] != '\0')
1910 error (_("bad symbol file: string table does not end with null character"));
1915 /* If we have not yet seen a function for this psymtab, this is 0. If we
1916 have seen one, it is the offset in the line numbers of the line numbers
1918 static unsigned int first_fun_line_offset
;
1920 static struct partial_symtab
*xcoff_start_psymtab
1921 (struct objfile
*, char *, int,
1922 struct partial_symbol
**, struct partial_symbol
**);
1924 /* Allocate and partially fill a partial symtab. It will be
1925 completely filled at the end of the symbol list.
1927 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1928 is the address relative to which its symbols are (incremental) or 0
1931 static struct partial_symtab
*
1932 xcoff_start_psymtab (struct objfile
*objfile
, char *filename
, int first_symnum
,
1933 struct partial_symbol
**global_syms
,
1934 struct partial_symbol
**static_syms
)
1936 struct partial_symtab
*result
=
1937 start_psymtab_common (objfile
, objfile
->section_offsets
,
1939 /* We fill in textlow later. */
1941 global_syms
, static_syms
);
1943 result
->read_symtab_private
= (char *)
1944 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct symloc
));
1945 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
1946 result
->read_symtab
= xcoff_psymtab_to_symtab
;
1948 /* Deduce the source language from the filename for this psymtab. */
1949 psymtab_language
= deduce_language_from_filename (filename
);
1954 static struct partial_symtab
*xcoff_end_psymtab
1955 (struct partial_symtab
*, char **, int, int,
1956 struct partial_symtab
**, int, int);
1958 /* Close off the current usage of PST.
1959 Returns PST, or NULL if the partial symtab was empty and thrown away.
1961 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
1963 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
1964 are the information for includes and dependencies. */
1966 static struct partial_symtab
*
1967 xcoff_end_psymtab (struct partial_symtab
*pst
, char **include_list
,
1968 int num_includes
, int capping_symbol_number
,
1969 struct partial_symtab
**dependency_list
,
1970 int number_dependencies
, int textlow_not_set
)
1973 struct objfile
*objfile
= pst
->objfile
;
1975 if (capping_symbol_number
!= -1)
1976 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
1977 capping_symbol_number
1978 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
1979 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
1980 first_fun_line_offset
;
1981 first_fun_line_offset
= 0;
1982 pst
->n_global_syms
=
1983 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1984 pst
->n_static_syms
=
1985 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1987 pst
->number_of_dependencies
= number_dependencies
;
1988 if (number_dependencies
)
1990 pst
->dependencies
= (struct partial_symtab
**)
1991 obstack_alloc (&objfile
->objfile_obstack
,
1992 number_dependencies
* sizeof (struct partial_symtab
*));
1993 memcpy (pst
->dependencies
, dependency_list
,
1994 number_dependencies
* sizeof (struct partial_symtab
*));
1997 pst
->dependencies
= 0;
1999 for (i
= 0; i
< num_includes
; i
++)
2001 struct partial_symtab
*subpst
=
2002 allocate_psymtab (include_list
[i
], objfile
);
2004 subpst
->section_offsets
= pst
->section_offsets
;
2005 subpst
->read_symtab_private
=
2006 (char *) obstack_alloc (&objfile
->objfile_obstack
,
2007 sizeof (struct symloc
));
2008 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2009 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2010 subpst
->textlow
= 0;
2011 subpst
->texthigh
= 0;
2013 /* We could save slight bits of space by only making one of these,
2014 shared by the entire set of include files. FIXME-someday. */
2015 subpst
->dependencies
= (struct partial_symtab
**)
2016 obstack_alloc (&objfile
->objfile_obstack
,
2017 sizeof (struct partial_symtab
*));
2018 subpst
->dependencies
[0] = pst
;
2019 subpst
->number_of_dependencies
= 1;
2021 subpst
->globals_offset
=
2022 subpst
->n_global_syms
=
2023 subpst
->statics_offset
=
2024 subpst
->n_static_syms
= 0;
2028 subpst
->read_symtab
= pst
->read_symtab
;
2031 sort_pst_symbols (pst
);
2033 /* If there is already a psymtab or symtab for a file of this name,
2034 remove it. (If there is a symtab, more drastic things also
2035 happen.) This happens in VxWorks. */
2036 free_named_symtabs (pst
->filename
);
2038 if (num_includes
== 0
2039 && number_dependencies
== 0
2040 && pst
->n_global_syms
== 0
2041 && pst
->n_static_syms
== 0)
2043 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2044 it is on the obstack, but we can forget to chain it on the list. */
2045 /* Empty psymtabs happen as a result of header files which don't have
2046 any symbols in them. There can be a lot of them. */
2048 discard_psymtab (pst
);
2050 /* Indicate that psymtab was thrown away. */
2051 pst
= (struct partial_symtab
*) NULL
;
2056 static void swap_sym (struct internal_syment
*,
2057 union internal_auxent
*, char **, char **,
2058 unsigned int *, struct objfile
*);
2060 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2061 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2062 the symbol and its auxents. */
2065 swap_sym (struct internal_syment
*symbol
, union internal_auxent
*aux
,
2066 char **name
, char **raw
, unsigned int *symnump
,
2067 struct objfile
*objfile
)
2069 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2070 if (symbol
->n_zeroes
)
2072 /* If it's exactly E_SYMNMLEN characters long it isn't
2074 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2076 /* FIXME: wastes memory for symbols which we don't end up putting
2077 into the minimal symbols. */
2079 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
2080 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2081 p
[E_SYMNMLEN
] = '\0';
2085 /* Point to the unswapped name as that persists as long as the
2087 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2089 else if (symbol
->n_sclass
& 0x80)
2091 *name
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
2096 *name
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
2100 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2101 if (symbol
->n_numaux
> 0)
2103 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2104 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2106 *symnump
+= symbol
->n_numaux
;
2107 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2112 function_outside_compilation_unit_complaint (const char *arg1
)
2114 complaint (&symfile_complaints
,
2115 _("function `%s' appears to be defined outside of all compilation units"),
2120 scan_xcoff_symtab (struct objfile
*objfile
)
2122 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2123 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2124 char *filestring
= NULL
;
2127 int past_first_source_file
= 0;
2132 /* Current partial symtab */
2133 struct partial_symtab
*pst
;
2135 /* List of current psymtab's include files */
2136 char **psymtab_include_list
;
2137 int includes_allocated
;
2140 /* Index within current psymtab dependency list */
2141 struct partial_symtab
**dependency_list
;
2142 int dependencies_used
, dependencies_allocated
;
2145 struct internal_syment symbol
;
2146 union internal_auxent main_aux
[5];
2147 unsigned int ssymnum
;
2149 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2150 CORE_ADDR last_csect_val
= 0;
2151 int last_csect_sec
= 0;
2152 int misc_func_recorded
= 0; /* true if any misc. function */
2153 int textlow_not_set
= 1;
2155 pst
= (struct partial_symtab
*) 0;
2157 includes_allocated
= 30;
2159 psymtab_include_list
= (char **) alloca (includes_allocated
*
2162 dependencies_allocated
= 30;
2163 dependencies_used
= 0;
2165 (struct partial_symtab
**) alloca (dependencies_allocated
*
2166 sizeof (struct partial_symtab
*));
2168 last_source_file
= NULL
;
2170 abfd
= objfile
->obfd
;
2171 next_symbol_text_func
= xcoff_next_symbol_text
;
2173 sraw_symbol
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
;
2174 nsyms
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl_num_syms
;
2176 while (ssymnum
< nsyms
)
2182 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2183 sclass
= symbol
.n_sclass
;
2190 /* The CSECT auxent--always the last auxent. */
2191 union internal_auxent csect_aux
;
2192 unsigned int symnum_before
= ssymnum
;
2194 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2196 if (symbol
.n_numaux
> 1)
2198 bfd_coff_swap_aux_in
2200 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2203 symbol
.n_numaux
- 1,
2208 csect_aux
= main_aux
[0];
2210 /* If symbol name starts with ".$" or "$", ignore it. */
2211 if (namestring
[0] == '$'
2212 || (namestring
[0] == '.' && namestring
[1] == '$'))
2215 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2218 switch (csect_aux
.x_csect
.x_smclas
)
2221 if (last_csect_name
)
2223 /* If no misc. function recorded in the last
2224 seen csect, enter it as a function. This
2225 will take care of functions like strcmp()
2228 if (!misc_func_recorded
)
2230 RECORD_MINIMAL_SYMBOL
2231 (last_csect_name
, last_csect_val
,
2232 mst_text
, last_csect_sec
,
2238 /* We have to allocate one psymtab for
2239 each program csect, because their text
2240 sections need not be adjacent. */
2242 (pst
, psymtab_include_list
, includes_used
,
2243 symnum_before
, dependency_list
,
2244 dependencies_used
, textlow_not_set
);
2246 dependencies_used
= 0;
2247 /* Give all psymtabs for this source file the same
2249 pst
= xcoff_start_psymtab
2253 objfile
->global_psymbols
.next
,
2254 objfile
->static_psymbols
.next
);
2257 /* Activate the misc_func_recorded mechanism for
2258 compiler- and linker-generated CSECTs like ".strcmp"
2260 if (namestring
&& (namestring
[0] == '.'
2261 || namestring
[0] == '@'))
2263 last_csect_name
= namestring
;
2264 last_csect_val
= symbol
.n_value
;
2266 secnum_to_section (symbol
.n_scnum
, objfile
);
2271 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2272 if (highval
> pst
->texthigh
)
2273 pst
->texthigh
= highval
;
2274 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2275 pst
->textlow
= symbol
.n_value
;
2277 misc_func_recorded
= 0;
2282 /* Data variables are recorded in the minimal symbol
2283 table, except for section symbols. */
2284 if (*namestring
!= '.')
2285 prim_record_minimal_symbol_and_info
2286 (namestring
, symbol
.n_value
,
2287 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2288 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2294 warning (_("More than one XMC_TC0 symbol found."));
2295 toc_offset
= symbol
.n_value
;
2297 /* Make TOC offset relative to start address of section. */
2298 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2300 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2304 /* These symbols tell us where the TOC entry for a
2305 variable is, not the variable itself. */
2314 switch (csect_aux
.x_csect
.x_smclas
)
2317 /* A function entry point. */
2319 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2320 first_fun_line_offset
=
2321 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2322 RECORD_MINIMAL_SYMBOL
2323 (namestring
, symbol
.n_value
,
2324 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2325 secnum_to_section (symbol
.n_scnum
, objfile
),
2330 /* shared library function trampoline code entry
2333 /* record trampoline code entries as
2334 mst_solib_trampoline symbol. When we lookup mst
2335 symbols, we will choose mst_text over
2336 mst_solib_trampoline. */
2337 RECORD_MINIMAL_SYMBOL
2338 (namestring
, symbol
.n_value
,
2339 mst_solib_trampoline
,
2340 secnum_to_section (symbol
.n_scnum
, objfile
),
2345 /* The symbols often have the same names as
2346 debug symbols for functions, and confuse
2352 /* xlc puts each variable in a separate csect,
2353 so we get an XTY_SD for each variable. But
2354 gcc puts several variables in a csect, so
2355 that each variable only gets an XTY_LD. We
2356 still need to record them. This will
2357 typically be XMC_RW; I suspect XMC_RO and
2358 XMC_BS might be possible too. */
2359 if (*namestring
!= '.')
2360 prim_record_minimal_symbol_and_info
2361 (namestring
, symbol
.n_value
,
2362 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2363 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2370 switch (csect_aux
.x_csect
.x_smclas
)
2374 /* Common variables are recorded in the minimal symbol
2375 table, except for section symbols. */
2376 if (*namestring
!= '.')
2377 prim_record_minimal_symbol_and_info
2378 (namestring
, symbol
.n_value
,
2379 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2380 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2393 unsigned int symnum_before
;
2395 symnum_before
= ssymnum
;
2396 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2399 /* See if the last csect needs to be recorded. */
2401 if (last_csect_name
&& !misc_func_recorded
)
2404 /* If no misc. function recorded in the last seen csect, enter
2405 it as a function. This will take care of functions like
2406 strcmp() compiled by xlc. */
2408 RECORD_MINIMAL_SYMBOL
2409 (last_csect_name
, last_csect_val
,
2410 mst_text
, last_csect_sec
, objfile
);
2415 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2416 symnum_before
, dependency_list
,
2417 dependencies_used
, textlow_not_set
);
2419 dependencies_used
= 0;
2421 first_fun_line_offset
= 0;
2423 /* XCOFF, according to the AIX 3.2 documentation, puts the
2424 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2425 do things the standard COFF way and put it in the auxent.
2426 We use the auxent if the symbol is ".file" and an auxent
2427 exists, otherwise use the symbol itself. */
2428 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2430 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2433 filestring
= namestring
;
2435 pst
= xcoff_start_psymtab (objfile
,
2438 objfile
->global_psymbols
.next
,
2439 objfile
->static_psymbols
.next
);
2440 last_csect_name
= NULL
;
2446 complaint (&symfile_complaints
,
2447 _("Storage class %d not recognized during scan"), sclass
);
2451 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2452 to handle only the C_FUN and C_EXT. */
2467 /* C_EINCL means we are switching back to the main file. But there
2468 is no reason to care; the only thing we want to know about
2469 includes is the names of all the included (.h) files. */
2474 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2478 /* I don't think the name of the common block (as opposed to the
2479 variables within it) is something which is user visible
2487 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2488 so C_LSYM would appear to be only for locals. */
2494 /* We probably could save a few instructions by assuming that
2495 C_LSYM, C_PSYM, etc., never have auxents. */
2496 int naux1
= symbol
.n_numaux
+ 1;
2498 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2504 /* Mark down an include file in the current psymtab */
2505 enum language tmp_language
;
2506 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2509 tmp_language
= deduce_language_from_filename (namestring
);
2511 /* Only change the psymtab's language if we've learned
2512 something useful (eg. tmp_language is not language_unknown).
2513 In addition, to match what start_subfile does, never change
2515 if (tmp_language
!= language_unknown
2516 && (tmp_language
!= language_c
2517 || psymtab_language
!= language_cplus
))
2518 psymtab_language
= tmp_language
;
2520 /* In C++, one may expect the same filename to come round many
2521 times, when code is coming alternately from the main file
2522 and from inline functions in other files. So I check to see
2523 if this is a file we've seen before -- either the main
2524 source file, or a previously included file.
2526 This seems to be a lot of time to be spending on N_SOL, but
2527 things like "break c-exp.y:435" need to work (I
2528 suppose the psymtab_include_list could be hashed or put
2529 in a binary tree, if profiling shows this is a major hog). */
2530 if (pst
&& strcmp (namestring
, pst
->filename
) == 0)
2534 for (i
= 0; i
< includes_used
; i
++)
2535 if (strcmp (namestring
, psymtab_include_list
[i
]) == 0)
2543 psymtab_include_list
[includes_used
++] = namestring
;
2544 if (includes_used
>= includes_allocated
)
2546 char **orig
= psymtab_include_list
;
2548 psymtab_include_list
= (char **)
2549 alloca ((includes_allocated
*= 2) *
2551 memcpy (psymtab_include_list
, orig
,
2552 includes_used
* sizeof (char *));
2557 /* The value of the C_FUN is not the address of the function (it
2558 appears to be the address before linking), but as long as it
2559 is smaller than the actual address, then find_pc_partial_function
2560 will use the minimal symbols instead. I hope. */
2568 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2571 p
= (char *) strchr (namestring
, ':');
2573 continue; /* Not a debugging symbol. */
2575 /* Main processing section for debugging symbols which
2576 the initial read through the symbol tables needs to worry
2577 about. If we reach this point, the symbol which we are
2578 considering is definitely one we are interested in.
2579 p must also contain the (valid) index into the namestring
2580 which indicates the debugging type symbol. */
2585 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2587 if (gdbarch_static_transform_name_p (gdbarch
))
2588 namestring
= gdbarch_static_transform_name
2589 (gdbarch
, namestring
);
2591 add_psymbol_to_list (namestring
, p
- namestring
,
2592 VAR_DOMAIN
, LOC_STATIC
,
2593 &objfile
->static_psymbols
,
2595 psymtab_language
, objfile
);
2599 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2600 /* The addresses in these entries are reported to be
2601 wrong. See the code that reads 'G's for symtabs. */
2602 add_psymbol_to_list (namestring
, p
- namestring
,
2603 VAR_DOMAIN
, LOC_STATIC
,
2604 &objfile
->global_psymbols
,
2606 psymtab_language
, objfile
);
2610 /* When a 'T' entry is defining an anonymous enum, it
2611 may have a name which is the empty string, or a
2612 single space. Since they're not really defining a
2613 symbol, those shouldn't go in the partial symbol
2614 table. We do pick up the elements of such enums at
2615 'check_enum:', below. */
2616 if (p
>= namestring
+ 2
2617 || (p
== namestring
+ 1
2618 && namestring
[0] != ' '))
2620 add_psymbol_to_list (namestring
, p
- namestring
,
2621 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2622 &objfile
->static_psymbols
,
2624 psymtab_language
, objfile
);
2627 /* Also a typedef with the same name. */
2628 add_psymbol_to_list (namestring
, p
- namestring
,
2629 VAR_DOMAIN
, LOC_TYPEDEF
,
2630 &objfile
->static_psymbols
,
2632 psymtab_language
, objfile
);
2639 if (p
!= namestring
) /* a name is there, not just :T... */
2641 add_psymbol_to_list (namestring
, p
- namestring
,
2642 VAR_DOMAIN
, LOC_TYPEDEF
,
2643 &objfile
->static_psymbols
,
2645 psymtab_language
, objfile
);
2648 /* If this is an enumerated type, we need to
2649 add all the enum constants to the partial symbol
2650 table. This does not cover enums without names, e.g.
2651 "enum {a, b} c;" in C, but fortunately those are
2652 rare. There is no way for GDB to find those from the
2653 enum type without spending too much time on it. Thus
2654 to solve this problem, the compiler needs to put out the
2655 enum in a nameless type. GCC2 does this. */
2657 /* We are looking for something of the form
2658 <name> ":" ("t" | "T") [<number> "="] "e"
2659 {<constant> ":" <value> ","} ";". */
2661 /* Skip over the colon and the 't' or 'T'. */
2663 /* This type may be given a number. Also, numbers can come
2664 in pairs like (0,26). Skip over it. */
2665 while ((*p
>= '0' && *p
<= '9')
2666 || *p
== '(' || *p
== ',' || *p
== ')'
2672 /* The aix4 compiler emits extra crud before the members. */
2675 /* Skip over the type (?). */
2679 /* Skip over the colon. */
2683 /* We have found an enumerated type. */
2684 /* According to comments in read_enum_type
2685 a comma could end it instead of a semicolon.
2686 I don't know where that happens.
2688 while (*p
&& *p
!= ';' && *p
!= ',')
2692 /* Check for and handle cretinous dbx symbol name
2694 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
2695 p
= next_symbol_text (objfile
);
2697 /* Point to the character after the name
2698 of the enum constant. */
2699 for (q
= p
; *q
&& *q
!= ':'; q
++)
2701 /* Note that the value doesn't matter for
2702 enum constants in psymtabs, just in symtabs. */
2703 add_psymbol_to_list (p
, q
- p
,
2704 VAR_DOMAIN
, LOC_CONST
,
2705 &objfile
->static_psymbols
, 0,
2706 0, psymtab_language
, objfile
);
2707 /* Point past the name. */
2709 /* Skip over the value. */
2710 while (*p
&& *p
!= ',')
2712 /* Advance past the comma. */
2720 /* Constant, e.g. from "const" in Pascal. */
2721 add_psymbol_to_list (namestring
, p
- namestring
,
2722 VAR_DOMAIN
, LOC_CONST
,
2723 &objfile
->static_psymbols
, symbol
.n_value
,
2724 0, psymtab_language
, objfile
);
2730 int name_len
= p
- namestring
;
2731 char *name
= xmalloc (name_len
+ 1);
2732 memcpy (name
, namestring
, name_len
);
2733 name
[name_len
] = '\0';
2734 function_outside_compilation_unit_complaint (name
);
2737 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2738 add_psymbol_to_list (namestring
, p
- namestring
,
2739 VAR_DOMAIN
, LOC_BLOCK
,
2740 &objfile
->static_psymbols
,
2742 psymtab_language
, objfile
);
2745 /* Global functions were ignored here, but now they
2746 are put into the global psymtab like one would expect.
2747 They're also in the minimal symbol table. */
2751 int name_len
= p
- namestring
;
2752 char *name
= xmalloc (name_len
+ 1);
2753 memcpy (name
, namestring
, name_len
);
2754 name
[name_len
] = '\0';
2755 function_outside_compilation_unit_complaint (name
);
2759 /* We need only the minimal symbols for these
2760 loader-generated definitions. Keeping the global
2761 symbols leads to "in psymbols but not in symbols"
2763 if (strncmp (namestring
, "@FIX", 4) == 0)
2766 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2767 add_psymbol_to_list (namestring
, p
- namestring
,
2768 VAR_DOMAIN
, LOC_BLOCK
,
2769 &objfile
->global_psymbols
,
2771 psymtab_language
, objfile
);
2774 /* Two things show up here (hopefully); static symbols of
2775 local scope (static used inside braces) or extensions
2776 of structure symbols. We can ignore both. */
2790 case '#': /* for symbol identification (used in live ranges) */
2794 /* It is a C++ nested symbol. We don't need to record it
2795 (I don't think); if we try to look up foo::bar::baz,
2796 then symbols for the symtab containing foo should get
2797 read in, I think. */
2798 /* Someone says sun cc puts out symbols like
2799 /foo/baz/maclib::/usr/local/bin/maclib,
2800 which would get here with a symbol type of ':'. */
2804 /* Unexpected symbol descriptor. The second and subsequent stabs
2805 of a continued stab can show up here. The question is
2806 whether they ever can mimic a normal stab--it would be
2807 nice if not, since we certainly don't want to spend the
2808 time searching to the end of every string looking for
2811 complaint (&symfile_complaints
,
2812 _("unknown symbol descriptor `%c'"), p
[1]);
2814 /* Ignore it; perhaps it is an extension that we don't
2824 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2825 ssymnum
, dependency_list
,
2826 dependencies_used
, textlow_not_set
);
2829 /* Record the toc offset value of this symbol table into objfile structure.
2830 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2831 this information would be file auxiliary header. */
2833 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
= toc_offset
;
2836 /* Return the toc offset value for a given objfile. */
2839 get_toc_offset (struct objfile
*objfile
)
2842 return ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
;
2846 /* Scan and build partial symbols for a symbol file.
2847 We have been initialized by a call to dbx_symfile_init, which
2848 put all the relevant info into a "struct dbx_symfile_info",
2849 hung off the objfile structure.
2851 SECTION_OFFSETS contains offsets relative to which the symbols in the
2852 various sections are (depending where the sections were actually loaded).
2853 MAINLINE is true if we are reading the main symbol
2854 table (as opposed to a shared lib or dynamically loaded file). */
2857 xcoff_initial_scan (struct objfile
*objfile
, int mainline
)
2861 struct cleanup
*back_to
;
2862 int num_symbols
; /* # of symbols */
2863 file_ptr symtab_offset
; /* symbol table and */
2864 file_ptr stringtab_offset
; /* string table file offsets */
2865 struct coff_symfile_info
*info
;
2869 info
= (struct coff_symfile_info
*) objfile
->deprecated_sym_private
;
2870 symfile_bfd
= abfd
= objfile
->obfd
;
2871 name
= objfile
->name
;
2873 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2874 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2875 stringtab_offset
= symtab_offset
+
2876 num_symbols
* coff_data (abfd
)->local_symesz
;
2878 info
->min_lineno_offset
= 0;
2879 info
->max_lineno_offset
= 0;
2880 bfd_map_over_sections (abfd
, find_linenos
, info
);
2882 if (num_symbols
> 0)
2884 /* Read the string table. */
2885 init_stringtab (abfd
, stringtab_offset
, objfile
);
2887 /* Read the .debug section, if present. */
2889 struct bfd_section
*secp
;
2890 bfd_size_type length
;
2891 char *debugsec
= NULL
;
2893 secp
= bfd_get_section_by_name (abfd
, ".debug");
2896 length
= bfd_section_size (abfd
, secp
);
2900 (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
2902 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2903 (file_ptr
) 0, length
))
2905 error (_("Error reading .debug section of `%s': %s"),
2906 name
, bfd_errmsg (bfd_get_error ()));
2910 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
=
2915 /* Read the symbols. We keep them in core because we will want to
2916 access them randomly in read_symbol*. */
2917 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2919 error (_("Error reading symbols from %s: %s"),
2920 name
, bfd_errmsg (bfd_get_error ()));
2921 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2922 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
=
2923 obstack_alloc (&objfile
->objfile_obstack
, size
);
2924 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl_num_syms
=
2927 val
= bfd_bread (((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
,
2930 perror_with_name (_("reading symbol table"));
2932 /* If we are reinitializing, or if we have never loaded syms yet, init */
2934 || (objfile
->global_psymbols
.size
== 0
2935 && objfile
->static_psymbols
.size
== 0))
2936 /* I'm not sure how how good num_symbols is; the rule of thumb in
2937 init_psymbol_list was developed for a.out. On the one hand,
2938 num_symbols includes auxents. On the other hand, it doesn't
2940 init_psymbol_list (objfile
, num_symbols
);
2942 free_pending_blocks ();
2943 back_to
= make_cleanup (really_free_pendings
, 0);
2945 init_minimal_symbol_collection ();
2946 make_cleanup_discard_minimal_symbols ();
2948 /* Now that the symbol table data of the executable file are all in core,
2949 process them and define symbols accordingly. */
2951 scan_xcoff_symtab (objfile
);
2953 /* Install any minimal symbols that have been collected as the current
2954 minimal symbols for this objfile. */
2956 install_minimal_symbols (objfile
);
2958 do_cleanups (back_to
);
2962 xcoff_symfile_offsets (struct objfile
*objfile
, struct section_addr_info
*addrs
)
2964 asection
*sect
= NULL
;
2967 objfile
->num_sections
= bfd_count_sections (objfile
->obfd
);
2968 objfile
->section_offsets
= (struct section_offsets
*)
2969 obstack_alloc (&objfile
->objfile_obstack
,
2970 SIZEOF_N_SECTION_OFFSETS (objfile
->num_sections
));
2972 /* Initialize the section indexes for future use. */
2973 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
2975 objfile
->sect_index_text
= sect
->index
;
2977 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
2979 objfile
->sect_index_data
= sect
->index
;
2981 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
2983 objfile
->sect_index_bss
= sect
->index
;
2985 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
2987 objfile
->sect_index_rodata
= sect
->index
;
2989 for (i
= 0; i
< objfile
->num_sections
; ++i
)
2991 /* syms_from_objfile kindly subtracts from addr the
2992 bfd_section_vma of the .text section. This strikes me as
2993 wrong--whether the offset to be applied to symbol reading is
2994 relative to the start address of the section depends on the
2995 symbol format. In any event, this whole "addr" concept is
2996 pretty broken (it doesn't handle any section but .text
2997 sensibly), so just ignore the addr parameter and use 0.
2998 rs6000-nat.c will set the correct section offsets via
2999 objfile_relocate. */
3000 (objfile
->section_offsets
)->offsets
[i
] = 0;
3004 /* Register our ability to parse symbols for xcoff BFD files. */
3006 static struct sym_fns xcoff_sym_fns
=
3009 /* It is possible that coff and xcoff should be merged as
3010 they do have fundamental similarities (for example, the extra storage
3011 classes used for stabs could presumably be recognized in any COFF file).
3012 However, in addition to obvious things like all the csect hair, there are
3013 some subtler differences between xcoffread.c and coffread.c, notably
3014 the fact that coffread.c has no need to read in all the symbols, but
3015 xcoffread.c reads all the symbols and does in fact randomly access them
3016 (in C_BSTAT and line number processing). */
3018 bfd_target_xcoff_flavour
,
3020 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3021 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3022 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
3023 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3024 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
3025 default_symfile_segments
, /* sym_segments: Get segment information from
3027 aix_process_linenos
, /* sym_read_linetable */
3028 NULL
/* next: pointer to next struct sym_fns */
3032 _initialize_xcoffread (void)
3034 add_symtab_fns (&xcoff_sym_fns
);