1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001
4 Free Software Foundation, Inc.
5 Derived from coffread.c, dbxread.c, and a lot of hacking.
6 Contributed by IBM Corporation.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
28 #include <sys/types.h>
31 #include "gdb_string.h"
33 #include <sys/param.h>
39 #include "coff/internal.h"
40 #include "libcoff.h" /* FIXME, internal data from BFD */
41 #include "coff/rs6000.h"
48 #include "stabsread.h"
49 #include "expression.h"
50 #include "complaints.h"
52 #include "gdb-stabs.h"
54 /* For interface with stabsread.c. */
55 #include "aout/stab_gnu.h"
58 /* We put a pointer to this structure in the read_symtab_private field
64 /* First symbol number for this file. */
68 /* Number of symbols in the section of the symbol table devoted to
69 this file's symbols (actually, the section bracketed may contain
70 more than just this file's symbols). If numsyms is 0, the only
71 reason for this thing's existence is the dependency list. Nothing
72 else will happen when it is read in. */
76 /* Position of the start of the line number information for this psymtab. */
77 unsigned int lineno_off
;
80 /* Remember what we deduced to be the source language of this psymtab. */
82 static enum language psymtab_language
= language_unknown
;
85 /* Simplified internal version of coff symbol table information */
90 int c_symnum
; /* symbol number of this entry */
91 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
93 unsigned char c_sclass
;
98 /* last function's saved coff symbol `cs' */
100 static struct coff_symbol fcn_cs_saved
;
102 static bfd
*symfile_bfd
;
104 /* Core address of start and end of text of current source file.
105 This is calculated from the first function seen after a C_FILE
109 static CORE_ADDR cur_src_end_addr
;
111 /* Core address of the end of the first object file. */
113 static CORE_ADDR first_object_file_end
;
115 /* initial symbol-table-debug-string vector length */
117 #define INITIAL_STABVECTOR_LENGTH 40
119 /* Nonzero if within a function (so symbols should be local,
120 if nothing says specifically). */
124 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
125 there is any reason not to just use a #define, but might as well
126 ask BFD for the size and store it here, I guess. */
128 static unsigned local_symesz
;
130 struct coff_symfile_info
132 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
133 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
135 /* Pointer to the string table. */
138 /* Pointer to debug section. */
141 /* Pointer to the a.out symbol table. */
144 /* Number of symbols in symtbl. */
147 /* Offset in data section to TOC anchor. */
148 CORE_ADDR toc_offset
;
151 static struct complaint storclass_complaint
=
152 {"Unexpected storage class: %d", 0, 0};
154 static struct complaint bf_notfound_complaint
=
155 {"line numbers off, `.bf' symbol not found", 0, 0};
157 static struct complaint ef_complaint
=
158 {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
160 static struct complaint eb_complaint
=
161 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
163 static void xcoff_initial_scan (struct objfile
*, int);
165 static void scan_xcoff_symtab (struct objfile
*);
167 static char *xcoff_next_symbol_text (struct objfile
*);
169 static void record_include_begin (struct coff_symbol
*);
172 enter_line_range (struct subfile
*, unsigned, unsigned,
173 CORE_ADDR
, CORE_ADDR
, unsigned *);
175 static void init_stringtab (bfd
*, file_ptr
, struct objfile
*);
177 static void xcoff_symfile_init (struct objfile
*);
179 static void xcoff_new_init (struct objfile
*);
181 static void xcoff_symfile_finish (struct objfile
*);
184 xcoff_symfile_offsets (struct objfile
*, struct section_addr_info
*addrs
);
186 static void find_linenos (bfd
*, sec_ptr
, PTR
);
188 static char *coff_getfilename (union internal_auxent
*, struct objfile
*);
190 static void read_symbol (struct internal_syment
*, int);
192 static int read_symbol_lineno (int);
194 static CORE_ADDR
read_symbol_nvalue (int);
196 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
199 static void read_xcoff_symtab (struct partial_symtab
*);
202 static void add_stab_to_list (char *, struct pending_stabs
**);
205 static int compare_lte (const void *, const void *);
207 static struct linetable
*arrange_linetable (struct linetable
*);
209 static void record_include_end (struct coff_symbol
*);
211 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
214 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
216 static int secnum_to_section (int, struct objfile
*);
217 static asection
*secnum_to_bfd_section (int, struct objfile
*);
219 struct find_targ_sec_arg
224 struct objfile
*objfile
;
227 static void find_targ_sec (bfd
*, asection
*, void *);
230 find_targ_sec (bfd
*abfd
, asection
*sect
, PTR obj
)
232 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
233 struct objfile
*objfile
= args
->objfile
;
234 if (sect
->target_index
== args
->targ_index
)
236 /* This is the section. Figure out what SECT_OFF_* code it is. */
237 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
238 *args
->resultp
= SECT_OFF_TEXT (objfile
);
239 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
240 *args
->resultp
= SECT_OFF_DATA (objfile
);
242 *args
->resultp
= sect
->index
;
243 *args
->bfd_sect
= sect
;
247 /* Return the section number (SECT_OFF_*) that CS points to. */
249 secnum_to_section (int secnum
, struct objfile
*objfile
)
251 int off
= SECT_OFF_TEXT (objfile
);
252 asection
*sect
= NULL
;
253 struct find_targ_sec_arg args
;
254 args
.targ_index
= secnum
;
256 args
.bfd_sect
= §
;
257 args
.objfile
= objfile
;
258 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
262 /* Return the BFD section that CS points to. */
264 secnum_to_bfd_section (int secnum
, struct objfile
*objfile
)
266 int off
= SECT_OFF_TEXT (objfile
);
267 asection
*sect
= NULL
;
268 struct find_targ_sec_arg args
;
269 args
.targ_index
= secnum
;
271 args
.bfd_sect
= §
;
272 args
.objfile
= objfile
;
273 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
277 /* add a given stab string into given stab vector. */
282 add_stab_to_list (char *stabname
, struct pending_stabs
**stabvector
)
284 if (*stabvector
== NULL
)
286 *stabvector
= (struct pending_stabs
*)
287 xmalloc (sizeof (struct pending_stabs
) +
288 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
289 (*stabvector
)->count
= 0;
290 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
292 else if ((*stabvector
)->count
>= (*stabvector
)->length
)
294 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
295 *stabvector
= (struct pending_stabs
*)
296 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
297 (*stabvector
)->length
* sizeof (char *));
299 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
304 /* Linenos are processed on a file-by-file basis.
308 1) xlc (IBM's native c compiler) postpones static function code
309 emission to the end of a compilation unit. This way it can
310 determine if those functions (statics) are needed or not, and
311 can do some garbage collection (I think). This makes line
312 numbers and corresponding addresses unordered, and we end up
313 with a line table like:
330 and that breaks gdb's binary search on line numbers, if the
331 above table is not sorted on line numbers. And that sort
332 should be on function based, since gcc can emit line numbers
335 10 0x100 - for the init/test part of a for stmt.
338 10 0x400 - for the increment part of a for stmt.
340 arrange_linetable() will do this sorting.
342 2) aix symbol table might look like:
344 c_file // beginning of a new file
345 .bi // beginning of include file
346 .ei // end of include file
350 basically, .bi/.ei pairs do not necessarily encapsulate
351 their scope. They need to be recorded, and processed later
352 on when we come the end of the compilation unit.
353 Include table (inclTable) and process_linenos() handle
359 /* compare line table entry addresses. */
362 compare_lte (const void *lte1p
, const void *lte2p
)
364 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
365 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
366 return lte1
->pc
- lte2
->pc
;
369 /* Given a line table with function entries are marked, arrange its functions
370 in ascending order and strip off function entry markers and return it in
371 a newly created table. If the old one is good enough, return the old one. */
372 /* FIXME: I think all this stuff can be replaced by just passing
373 sort_linevec = 1 to end_symtab. */
375 static struct linetable
*
376 arrange_linetable (struct linetable
*oldLineTb
)
378 int ii
, jj
, newline
, /* new line count */
379 function_count
; /* # of functions */
381 struct linetable_entry
*fentry
; /* function entry vector */
382 int fentry_size
; /* # of function entries */
383 struct linetable
*newLineTb
; /* new line table */
385 #define NUM_OF_FUNCTIONS 20
387 fentry_size
= NUM_OF_FUNCTIONS
;
388 fentry
= (struct linetable_entry
*)
389 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
391 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
394 if (oldLineTb
->item
[ii
].line
== 0)
395 { /* function entry found. */
397 if (function_count
>= fentry_size
)
398 { /* make sure you have room. */
400 fentry
= (struct linetable_entry
*)
401 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
403 fentry
[function_count
].line
= ii
;
404 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
409 if (function_count
== 0)
414 else if (function_count
> 1)
415 qsort (fentry
, function_count
, sizeof (struct linetable_entry
), compare_lte
);
417 /* allocate a new line table. */
418 newLineTb
= (struct linetable
*)
420 (sizeof (struct linetable
) +
421 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
423 /* if line table does not start with a function beginning, copy up until
427 if (oldLineTb
->item
[0].line
!= 0)
429 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
430 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
432 /* Now copy function lines one by one. */
434 for (ii
= 0; ii
< function_count
; ++ii
)
436 for (jj
= fentry
[ii
].line
+ 1;
437 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
439 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
442 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
446 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
447 following `IncludeChain'. At the end of each symtab (end_symtab),
448 we will determine if we should create additional symtab's to
449 represent if (the include files. */
452 typedef struct _inclTable
454 char *name
; /* include filename */
456 /* Offsets to the line table. end points to the last entry which is
457 part of this include file. */
460 struct subfile
*subfile
;
461 unsigned funStartLine
; /* start line # of its function */
465 #define INITIAL_INCLUDE_TABLE_LENGTH 20
466 static InclTable
*inclTable
; /* global include table */
467 static int inclIndx
; /* last entry to table */
468 static int inclLength
; /* table length */
469 static int inclDepth
; /* nested include depth */
471 static void allocate_include_entry (void);
474 record_include_begin (struct coff_symbol
*cs
)
478 /* In xcoff, we assume include files cannot be nested (not in .c files
479 of course, but in corresponding .s files.). */
481 /* This can happen with old versions of GCC.
482 GCC 2.3.3-930426 does not exhibit this on a test case which
483 a user said produced the message for him. */
484 static struct complaint msg
=
485 {"Nested C_BINCL symbols", 0, 0};
490 allocate_include_entry ();
492 inclTable
[inclIndx
].name
= cs
->c_name
;
493 inclTable
[inclIndx
].begin
= cs
->c_value
;
497 record_include_end (struct coff_symbol
*cs
)
503 static struct complaint msg
=
504 {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
508 allocate_include_entry ();
510 pTbl
= &inclTable
[inclIndx
];
511 pTbl
->end
= cs
->c_value
;
518 allocate_include_entry (void)
520 if (inclTable
== NULL
)
522 inclTable
= (InclTable
*)
523 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
525 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
526 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
529 else if (inclIndx
>= inclLength
)
531 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
532 inclTable
= (InclTable
*)
533 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
534 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
535 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
539 /* Global variable to pass the psymtab down to all the routines involved
540 in psymtab to symtab processing. */
541 static struct partial_symtab
*this_symtab_psymtab
;
543 /* given the start and end addresses of a compilation unit (or a csect,
544 at times) process its lines and create appropriate line vectors. */
547 process_linenos (CORE_ADDR start
, CORE_ADDR end
)
550 file_ptr max_offset
=
551 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
554 /* subfile structure for the main compilation unit. */
555 struct subfile main_subfile
;
557 /* In the main source file, any time we see a function entry, we
558 reset this variable to function's absolute starting line number.
559 All the following line numbers in the function are relative to
560 this, and we record absolute line numbers in record_line(). */
562 unsigned int main_source_baseline
= 0;
567 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
569 goto return_after_cleanup
;
571 memset (&main_subfile
, '\0', sizeof (main_subfile
));
574 /* All source lines were in the main source file. None in include files. */
576 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
577 &main_source_baseline
);
581 /* There was source with line numbers in include files. */
584 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
585 main_source_baseline
= 0;
587 for (ii
= 0; ii
< inclIndx
; ++ii
)
589 struct subfile
*tmpSubfile
;
591 /* If there is main file source before include file, enter it. */
592 if (offset
< inclTable
[ii
].begin
)
595 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
596 start
, 0, &main_source_baseline
);
599 /* Have a new subfile for the include file. */
601 tmpSubfile
= inclTable
[ii
].subfile
=
602 (struct subfile
*) xmalloc (sizeof (struct subfile
));
604 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
605 firstLine
= &(inclTable
[ii
].funStartLine
);
607 /* Enter include file's lines now. */
608 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
609 inclTable
[ii
].end
, start
, 0, firstLine
);
611 if (offset
<= inclTable
[ii
].end
)
612 offset
= inclTable
[ii
].end
+ linesz
;
615 /* All the include files' line have been processed at this point. Now,
616 enter remaining lines of the main file, if any left. */
617 if (offset
< max_offset
+ 1 - linesz
)
619 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
620 &main_source_baseline
);
624 /* Process main file's line numbers. */
625 if (main_subfile
.line_vector
)
627 struct linetable
*lineTb
, *lv
;
629 lv
= main_subfile
.line_vector
;
631 /* Line numbers are not necessarily ordered. xlc compilation will
632 put static function to the end. */
634 lineTb
= arrange_linetable (lv
);
637 current_subfile
->line_vector
= (struct linetable
*)
638 xrealloc (lv
, (sizeof (struct linetable
)
639 + lv
->nitems
* sizeof (struct linetable_entry
)));
644 current_subfile
->line_vector
= lineTb
;
647 current_subfile
->line_vector_length
=
648 current_subfile
->line_vector
->nitems
;
651 /* Now, process included files' line numbers. */
653 for (ii
= 0; ii
< inclIndx
; ++ii
)
655 if ((inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
657 struct linetable
*lineTb
, *lv
;
659 lv
= (inclTable
[ii
].subfile
)->line_vector
;
661 /* Line numbers are not necessarily ordered. xlc compilation will
662 put static function to the end. */
664 lineTb
= arrange_linetable (lv
);
668 /* For the same include file, we might want to have more than one
669 subfile. This happens if we have something like:
677 while foo.h including code in it. (stupid but possible)
678 Since start_subfile() looks at the name and uses an
679 existing one if finds, we need to provide a fake name and
683 start_subfile (inclTable
[ii
].name
, (char *) 0);
686 /* Pick a fake name that will produce the same results as this
687 one when passed to deduce_language_from_filename. Kludge on
689 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
690 if (fakename
== NULL
)
692 start_subfile (fakename
, (char *) 0);
693 xfree (current_subfile
->name
);
695 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
700 current_subfile
->line_vector
=
701 (struct linetable
*) xrealloc
702 (lv
, (sizeof (struct linetable
)
703 + lv
->nitems
* sizeof (struct linetable_entry
)));
709 current_subfile
->line_vector
= lineTb
;
712 current_subfile
->line_vector_length
=
713 current_subfile
->line_vector
->nitems
;
714 start_subfile (pop_subfile (), (char *) 0);
718 return_after_cleanup
:
720 /* We don't want to keep alloc/free'ing the global include file table. */
723 /* Start with a fresh subfile structure for the next file. */
724 memset (&main_subfile
, '\0', sizeof (struct subfile
));
728 aix_process_linenos (void)
730 /* process line numbers and enter them into line vector */
731 process_linenos (last_source_start_addr
, cur_src_end_addr
);
735 /* Enter a given range of lines into the line vector.
736 can be called in the following two ways:
737 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
738 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
740 endoffset points to the last line table entry that we should pay
744 enter_line_range (struct subfile
*subfile
, unsigned beginoffset
, unsigned endoffset
, /* offsets to line table */
745 CORE_ADDR startaddr
, /* offsets to line table */
746 CORE_ADDR endaddr
, unsigned *firstLine
)
748 unsigned int curoffset
;
751 struct internal_lineno int_lnno
;
752 unsigned int limit_offset
;
756 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
758 curoffset
= beginoffset
;
760 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
765 if (endoffset
>= limit_offset
)
767 static struct complaint msg
=
768 {"Bad line table offset in C_EINCL directive", 0, 0};
772 limit_offset
= endoffset
;
777 abfd
= this_symtab_psymtab
->objfile
->obfd
;
778 linesz
= coff_data (abfd
)->local_linesz
;
779 ext_lnno
= alloca (linesz
);
781 while (curoffset
<= limit_offset
)
783 bfd_seek (abfd
, curoffset
, SEEK_SET
);
784 bfd_bread (ext_lnno
, linesz
, abfd
);
785 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
787 /* Find the address this line represents. */
788 addr
= (int_lnno
.l_lnno
789 ? int_lnno
.l_addr
.l_paddr
790 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
791 addr
+= ANOFFSET (this_symtab_psymtab
->objfile
->section_offsets
,
792 SECT_OFF_TEXT (this_symtab_psymtab
->objfile
));
794 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
797 if (int_lnno
.l_lnno
== 0)
799 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
800 record_line (subfile
, 0, addr
);
804 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
, addr
);
810 /* Save the vital information for use when closing off the current file.
811 NAME is the file name the symbols came from, START_ADDR is the first
812 text address for the file, and SIZE is the number of bytes of text. */
814 #define complete_symtab(name, start_addr) { \
815 last_source_file = savestring (name, strlen (name)); \
816 last_source_start_addr = start_addr; \
820 /* Refill the symbol table input buffer
821 and set the variables that control fetching entries from it.
822 Reports an error if no data available.
823 This function can read past the end of the symbol table
824 (into the string table) but this does no harm. */
826 /* Reading symbol table has to be fast! Keep the followings as macros, rather
829 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
833 if (namestr[0] == '.') ++namestr; \
834 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
835 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
836 misc_func_recorded = 1; \
840 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
841 nested. At any given time, a symbol can only be in one static block.
842 This is the base address of current static block, zero if non exists. */
844 static int static_block_base
= 0;
846 /* Section number for the current static block. */
848 static int static_block_section
= -1;
850 /* true if space for symbol name has been allocated. */
852 static int symname_alloced
= 0;
854 /* Next symbol to read. Pointer into raw seething symbol table. */
856 static char *raw_symbol
;
858 /* This is the function which stabsread.c calls to get symbol
862 xcoff_next_symbol_text (struct objfile
*objfile
)
864 struct internal_syment symbol
;
865 static struct complaint msg
=
866 {"Unexpected symbol continuation", 0, 0};
868 /* FIXME: is this the same as the passed arg? */
869 objfile
= this_symtab_psymtab
->objfile
;
871 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
876 /* Return something which points to '\0' and hope the symbol reading
877 code does something reasonable. */
880 else if (symbol
.n_sclass
& 0x80)
883 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
886 coff_data (objfile
->obfd
)->local_symesz
;
893 /* Return something which points to '\0' and hope the symbol reading
894 code does something reasonable. */
900 /* Read symbols for a given partial symbol table. */
903 read_xcoff_symtab (struct partial_symtab
*pst
)
905 struct objfile
*objfile
= pst
->objfile
;
906 bfd
*abfd
= objfile
->obfd
;
907 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
908 char *strtbl
= ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
;
910 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
;
911 char *debugfmt
= xcoff_data (abfd
)->xcoff64
? "XCOFF64" : "XCOFF";
913 struct internal_syment symbol
[1];
914 union internal_auxent main_aux
;
915 struct coff_symbol cs
[1];
916 CORE_ADDR file_start_addr
= 0;
917 CORE_ADDR file_end_addr
= 0;
919 int next_file_symnum
= -1;
920 unsigned int max_symnum
;
921 int just_started
= 1;
923 int fcn_start_addr
= 0;
925 struct coff_symbol fcn_stab_saved
;
927 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
928 union internal_auxent fcn_aux_saved
;
929 struct context_stack
*new;
931 char *filestring
= " _start_ "; /* Name of the current file. */
933 char *last_csect_name
; /* last seen csect's name and value */
934 CORE_ADDR last_csect_val
;
937 this_symtab_psymtab
= pst
;
939 /* Get the appropriate COFF "constants" related to the file we're
941 local_symesz
= coff_data (abfd
)->local_symesz
;
943 last_source_file
= NULL
;
948 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
949 record_debugformat (debugfmt
);
950 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
952 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
953 first_object_file_end
= 0;
956 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
957 + symnum
* local_symesz
;
959 while (symnum
< max_symnum
)
962 QUIT
; /* make this command interruptable. */
964 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
965 /* read one symbol into `cs' structure. After processing the
966 whole symbol table, only string table will be kept in memory,
967 symbol table and debug section of xcoff will be freed. Thus
968 we can mark symbols with names in string table as
973 /* Swap and align the symbol into a reasonable C structure. */
974 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
976 cs
->c_symnum
= symnum
;
977 cs
->c_naux
= symbol
->n_numaux
;
978 if (symbol
->n_zeroes
)
981 /* We must use the original, unswapped, name here so the name field
982 pointed to by cs->c_name will persist throughout xcoffread. If
983 we use the new field, it gets overwritten for each symbol. */
984 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
985 /* If it's exactly E_SYMNMLEN characters long it isn't
987 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
990 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
991 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
992 p
[E_SYMNMLEN
] = '\0';
997 else if (symbol
->n_sclass
& 0x80)
999 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1000 symname_alloced
= 0;
1004 /* in string table */
1005 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1006 symname_alloced
= 1;
1008 cs
->c_value
= symbol
->n_value
;
1009 cs
->c_sclass
= symbol
->n_sclass
;
1010 cs
->c_secnum
= symbol
->n_scnum
;
1011 cs
->c_type
= (unsigned) symbol
->n_type
;
1013 raw_symbol
+= local_symesz
;
1016 /* Save addr of first aux entry. */
1017 raw_auxptr
= raw_symbol
;
1019 /* Skip all the auxents associated with this symbol. */
1020 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1022 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1027 /* if symbol name starts with ".$" or "$", ignore it. */
1028 if (cs
->c_name
[0] == '$'
1029 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1032 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1034 if (last_source_file
)
1037 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1042 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1043 record_debugformat (debugfmt
);
1044 cur_src_end_addr
= first_object_file_end
;
1045 /* done with all files, everything from here on is globals */
1048 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1051 /* Dealing with a symbol with a csect entry. */
1053 #define CSECT(PP) ((PP)->x_csect)
1054 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1055 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1056 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1057 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1059 /* Convert the auxent to something we can access. */
1060 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1061 0, cs
->c_naux
, &main_aux
);
1063 switch (CSECT_SMTYP (&main_aux
))
1067 /* Ignore all external references. */
1071 /* A section description. */
1073 switch (CSECT_SCLAS (&main_aux
))
1079 /* A program csect is seen. We have to allocate one
1080 symbol table for each program csect. Normally gdb
1081 prefers one symtab for each source file. In case
1082 of AIX, one source file might include more than one
1083 [PR] csect, and they don't have to be adjacent in
1084 terms of the space they occupy in memory. Thus, one
1085 single source file might get fragmented in the
1086 memory and gdb's file start and end address
1087 approach does not work! GCC (and I think xlc) seem
1088 to put all the code in the unnamed program csect. */
1090 if (last_csect_name
)
1092 complete_symtab (filestring
, file_start_addr
);
1093 cur_src_end_addr
= file_end_addr
;
1094 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1097 /* Give all csects for this source file the same
1099 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1100 record_debugformat (debugfmt
);
1103 /* If this is the very first csect seen,
1104 basically `__start'. */
1107 first_object_file_end
1108 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1113 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1114 SECT_OFF_TEXT (objfile
));
1115 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1117 if (cs
->c_name
&& (cs
->c_name
[0] == '.'
1118 || cs
->c_name
[0] == '@'))
1120 last_csect_name
= cs
->c_name
;
1121 last_csect_val
= cs
->c_value
;
1122 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1127 /* All other symbols are put into the minimal symbol
1140 /* Ignore the symbol. */
1148 switch (CSECT_SCLAS (&main_aux
))
1151 /* a function entry point. */
1152 function_entry_point
:
1154 fcn_start_addr
= cs
->c_value
;
1156 /* save the function header info, which will be used
1157 when `.bf' is seen. */
1159 fcn_aux_saved
= main_aux
;
1163 /* shared library function trampoline code entry point. */
1167 /* The symbols often have the same names as debug symbols for
1168 functions, and confuse lookup_symbol. */
1172 /* xlc puts each variable in a separate csect, so we get
1173 an XTY_SD for each variable. But gcc puts several
1174 variables in a csect, so that each variable only gets
1175 an XTY_LD. This will typically be XMC_RW; I suspect
1176 XMC_RO and XMC_BS might be possible too.
1177 These variables are put in the minimal symbol table
1184 /* Common symbols are put into the minimal symbol table only. */
1192 /* If explicitly specified as a function, treat is as one. This check
1193 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1194 after the above CSECT check. */
1195 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1197 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1198 0, cs
->c_naux
, &main_aux
);
1199 goto function_entry_point
;
1202 switch (cs
->c_sclass
)
1207 /* c_value field contains symnum of next .file entry in table
1208 or symnum of first global after last .file. */
1210 next_file_symnum
= cs
->c_value
;
1212 /* Complete symbol table for last object file containing
1213 debugging information. */
1215 /* Whether or not there was a csect in the previous file, we
1216 have to call `end_stabs' and `start_stabs' to reset
1217 type_vector, line_vector, etc. structures. */
1219 complete_symtab (filestring
, file_start_addr
);
1220 cur_src_end_addr
= file_end_addr
;
1221 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1224 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1225 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1226 standard COFF way and put it in the auxent. We use the auxent if
1227 the symbol is ".file" and an auxent exists, otherwise use the symbol
1228 itself. Simple enough. */
1229 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1231 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1232 0, cs
->c_naux
, &main_aux
);
1233 filestring
= coff_getfilename (&main_aux
, objfile
);
1236 filestring
= cs
->c_name
;
1239 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1240 record_debugformat (debugfmt
);
1241 last_csect_name
= 0;
1243 /* reset file start and end addresses. A compilation unit with no text
1244 (only data) should have zero file boundaries. */
1245 file_start_addr
= file_end_addr
= 0;
1249 fcn_stab_saved
= *cs
;
1253 if (STREQ (cs
->c_name
, ".bf"))
1255 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1256 SECT_OFF_TEXT (objfile
));
1257 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1258 0, cs
->c_naux
, &main_aux
);
1260 within_function
= 1;
1262 new = push_context (0, fcn_start_addr
+ off
);
1264 new->name
= define_symbol
1265 (fcn_cs_saved
.c_value
+ off
,
1266 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1267 if (new->name
!= NULL
)
1268 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1270 else if (STREQ (cs
->c_name
, ".ef"))
1273 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1274 0, cs
->c_naux
, &main_aux
);
1276 /* The value of .ef is the address of epilogue code;
1277 not useful for gdb. */
1278 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1279 contains number of lines to '}' */
1281 if (context_stack_depth
<= 0)
1282 { /* We attempted to pop an empty context stack */
1283 complain (&ef_complaint
, cs
->c_symnum
);
1284 within_function
= 0;
1287 new = pop_context ();
1288 /* Stack must be empty now. */
1289 if (context_stack_depth
> 0 || new == NULL
)
1291 complain (&ef_complaint
, cs
->c_symnum
);
1292 within_function
= 0;
1296 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1298 (fcn_cs_saved
.c_value
1299 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1300 + ANOFFSET (objfile
->section_offsets
,
1301 SECT_OFF_TEXT (objfile
))),
1303 within_function
= 0;
1308 /* Begin static block. */
1310 struct internal_syment symbol
;
1312 read_symbol (&symbol
, cs
->c_value
);
1313 static_block_base
= symbol
.n_value
;
1314 static_block_section
=
1315 secnum_to_section (symbol
.n_scnum
, objfile
);
1320 /* End of static block. */
1321 static_block_base
= 0;
1322 static_block_section
= -1;
1333 static struct complaint msg
=
1334 {"Unrecognized storage class %d.", 0, 0};
1335 complain (&msg
, cs
->c_sclass
);
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 (STREQ (cs
->c_name
, ".bb"))
1368 new = push_context (depth
,
1370 + ANOFFSET (objfile
->section_offsets
,
1371 SECT_OFF_TEXT (objfile
))));
1373 else if (STREQ (cs
->c_name
, ".eb"))
1375 if (context_stack_depth
<= 0)
1376 { /* We attempted to pop an empty context stack */
1377 complain (&eb_complaint
, cs
->c_symnum
);
1380 new = pop_context ();
1381 if (depth
-- != new->depth
)
1383 complain (&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->symbol_obstack, sizeof (struct symbol)); \
1426 *(SYMBOL2) = *(SYMBOL1);
1429 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1430 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1433 static struct type
*func_symbol_type
;
1434 static struct type
*var_symbol_type
;
1436 /* process one xcoff symbol. */
1438 static struct symbol
*
1439 process_xcoff_symbol (register struct coff_symbol
*cs
, struct objfile
*objfile
)
1441 struct symbol onesymbol
;
1442 register struct symbol
*sym
= &onesymbol
;
1443 struct symbol
*sym2
= NULL
;
1449 if (cs
->c_secnum
< 0)
1451 /* The value is a register number, offset within a frame, etc.,
1452 and does not get relocated. */
1458 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1459 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1466 memset (sym
, '\0', sizeof (struct symbol
));
1468 /* default assumptions */
1469 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1470 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1471 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1473 if (ISFCN (cs
->c_type
))
1475 /* At this point, we don't know the type of the function. This
1476 will be patched with the type from its stab entry later on in
1477 patch_block_stabs (), unless the file was compiled without -g. */
1479 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1480 SYMBOL_TYPE (sym
) = func_symbol_type
;
1482 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1483 SYMBOL_DUP (sym
, sym2
);
1485 if (cs
->c_sclass
== C_EXT
)
1486 add_symbol_to_list (sym2
, &global_symbols
);
1487 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1488 add_symbol_to_list (sym2
, &file_symbols
);
1492 /* In case we can't figure out the type, provide default. */
1493 SYMBOL_TYPE (sym
) = var_symbol_type
;
1495 switch (cs
->c_sclass
)
1498 /* The values of functions and global symbols are now resolved
1499 via the global_sym_chain in stabsread.c. */
1501 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1502 add_stab_to_list (name
, &global_stabs
);
1504 add_stab_to_list (name
, &file_stabs
);
1508 add_stab_to_list (name
, &global_stabs
);
1513 common_block_start (cs
->c_name
, objfile
);
1517 common_block_end (objfile
);
1521 complain (&storclass_complaint
, cs
->c_sclass
);
1533 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1536 SYMBOL_SECTION (sym
) = sec
;
1543 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1544 all statics and we need to distinguish file-scope versus
1545 function-scope using within_function. We do this by
1546 changing the string we pass to define_symbol to use 'S'
1547 where we need to, which is not necessarily super-clean,
1548 but seems workable enough. */
1550 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1554 if (*pp
== 'V' && !within_function
)
1556 sym
= define_symbol ((cs
->c_value
1557 + ANOFFSET (objfile
->section_offsets
,
1558 static_block_section
)),
1559 cs
->c_name
, 0, 0, objfile
);
1562 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1563 SYMBOL_SECTION (sym
) = static_block_section
;
1572 /* Extract the file name from the aux entry of a C_FILE symbol.
1573 Result is in static storage and is only good for temporary use. */
1576 coff_getfilename (union internal_auxent
*aux_entry
, struct objfile
*objfile
)
1578 static char buffer
[BUFSIZ
];
1580 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1582 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
1583 + aux_entry
->x_file
.x_n
.x_offset
);
1586 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1587 buffer
[FILNMLEN
] = '\0';
1592 /* Set *SYMBOL to symbol number symno in symtbl. */
1594 read_symbol (struct internal_syment
*symbol
, int symno
)
1597 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
1600 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
1602 if (symno
< 0 || symno
>= nsyms
)
1604 static struct complaint msg
=
1605 {"Invalid symbol offset", 0, 0};
1607 symbol
->n_value
= 0;
1608 symbol
->n_scnum
= -1;
1611 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1612 stbl
+ (symno
* local_symesz
),
1616 /* Get value corresponding to symbol number symno in symtbl. */
1619 read_symbol_nvalue (int symno
)
1621 struct internal_syment symbol
[1];
1623 read_symbol (symbol
, symno
);
1624 return symbol
->n_value
;
1628 /* Find the address of the function corresponding to symno, where
1629 symno is the symbol pointed to by the linetable. */
1632 read_symbol_lineno (int symno
)
1634 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1635 boolean xcoff64
= xcoff_data (objfile
->obfd
)->xcoff64
;
1637 struct coff_symfile_info
*info
=
1638 (struct coff_symfile_info
*)objfile
->sym_private
;
1639 int nsyms
= info
->symtbl_num_syms
;
1640 char *stbl
= info
->symtbl
;
1641 char *strtbl
= info
->strtbl
;
1643 struct internal_syment symbol
[1];
1644 union internal_auxent main_aux
[1];
1648 complain (&bf_notfound_complaint
);
1652 /* Note that just searching for a short distance (e.g. 50 symbols)
1653 is not enough, at least in the following case.
1656 [many .stabx entries]
1657 [a few functions, referring to foo]
1661 What happens here is that the assembler moves the .stabx entries
1662 to right before the ".bf" for foo, but the symbol for "foo" is before
1663 all the stabx entries. See PR gdb/2222. */
1665 /* Maintaining a table of .bf entries might be preferable to this search.
1666 If I understand things correctly it would need to be done only for
1667 the duration of a single psymtab to symtab conversion. */
1668 while (symno
< nsyms
)
1670 bfd_coff_swap_sym_in (symfile_bfd
,
1671 stbl
+ (symno
* local_symesz
), symbol
);
1672 if (symbol
->n_sclass
== C_FCN
)
1674 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1675 if (STREQ (name
, ".bf"))
1678 symno
+= symbol
->n_numaux
+ 1;
1681 complain (&bf_notfound_complaint
);
1685 /* take aux entry and return its lineno */
1687 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1688 symbol
->n_type
, symbol
->n_sclass
,
1689 0, symbol
->n_numaux
, main_aux
);
1691 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1694 /* Support for line number handling */
1696 /* This function is called for every section; it finds the outer limits
1697 * of the line table (minimum and maximum file offset) so that the
1698 * mainline code can read the whole thing for efficiency.
1701 find_linenos (bfd
*abfd
, sec_ptr asect
, PTR vpinfo
)
1703 struct coff_symfile_info
*info
;
1705 file_ptr offset
, maxoff
;
1707 count
= asect
->lineno_count
;
1709 if (!STREQ (asect
->name
, ".text") || count
== 0)
1712 size
= count
* coff_data (abfd
)->local_linesz
;
1713 info
= (struct coff_symfile_info
*) vpinfo
;
1714 offset
= asect
->line_filepos
;
1715 maxoff
= offset
+ size
;
1717 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1718 info
->min_lineno_offset
= offset
;
1720 if (maxoff
> info
->max_lineno_offset
)
1721 info
->max_lineno_offset
= maxoff
;
1724 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1727 xcoff_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1729 struct cleanup
*old_chain
;
1738 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1743 /* Read in all partial symtabs on which this one is dependent */
1744 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1745 if (!pst
->dependencies
[i
]->readin
)
1747 /* Inform about additional files that need to be read in. */
1750 fputs_filtered (" ", gdb_stdout
);
1752 fputs_filtered ("and ", gdb_stdout
);
1754 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1755 wrap_here (""); /* Flush output */
1756 gdb_flush (gdb_stdout
);
1758 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1761 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1763 /* Init stuff necessary for reading in symbols. */
1766 old_chain
= make_cleanup (really_free_pendings
, 0);
1768 read_xcoff_symtab (pst
);
1769 sort_symtab_syms (pst
->symtab
);
1771 do_cleanups (old_chain
);
1777 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1779 /* Read in all of the symbols for a given psymtab for real.
1780 Be verbose about it if the user wants that. */
1783 xcoff_psymtab_to_symtab (struct partial_symtab
*pst
)
1793 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1798 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1799 || pst
->number_of_dependencies
)
1801 /* Print the message now, before reading the string table,
1802 to avoid disconcerting pauses. */
1805 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1806 gdb_flush (gdb_stdout
);
1809 sym_bfd
= pst
->objfile
->obfd
;
1811 next_symbol_text_func
= xcoff_next_symbol_text
;
1813 xcoff_psymtab_to_symtab_1 (pst
);
1815 /* Match with global symbols. This only needs to be done once,
1816 after all of the symtabs and dependencies have been read in. */
1817 scan_file_globals (pst
->objfile
);
1819 /* Finish up the debug error message. */
1821 printf_filtered ("done.\n");
1826 xcoff_new_init (struct objfile
*objfile
)
1828 stabsread_new_init ();
1829 buildsym_new_init ();
1832 /* Do initialization in preparation for reading symbols from OBJFILE.
1834 We will only be called if this is an XCOFF or XCOFF-like file.
1835 BFD handles figuring out the format of the file, and code in symfile.c
1836 uses BFD's determination to vector to us. */
1839 xcoff_symfile_init (struct objfile
*objfile
)
1841 /* Allocate struct to keep track of the symfile */
1842 objfile
->sym_private
= xmmalloc (objfile
->md
,
1843 sizeof (struct coff_symfile_info
));
1845 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1846 find this causes a significant slowdown in gdb then we could
1847 set it in the debug symbol readers only when necessary. */
1848 objfile
->flags
|= OBJF_REORDERED
;
1850 init_entry_point_info (objfile
);
1853 /* Perform any local cleanups required when we are done with a particular
1854 objfile. I.E, we are in the process of discarding all symbol information
1855 for an objfile, freeing up all memory held for it, and unlinking the
1856 objfile struct from the global list of known objfiles. */
1859 xcoff_symfile_finish (struct objfile
*objfile
)
1861 if (objfile
->sym_private
!= NULL
)
1863 mfree (objfile
->md
, objfile
->sym_private
);
1866 /* Start with a fresh include table for the next objfile. */
1872 inclIndx
= inclLength
= inclDepth
= 0;
1877 init_stringtab (bfd
*abfd
, file_ptr offset
, struct objfile
*objfile
)
1881 unsigned char lengthbuf
[4];
1884 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
= NULL
;
1886 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1887 error ("cannot seek to string table in %s: %s",
1888 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1890 val
= bfd_bread ((char *) lengthbuf
, sizeof lengthbuf
, abfd
);
1891 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1893 /* If no string table is needed, then the file may end immediately
1894 after the symbols. Just return with `strtbl' set to NULL. */
1896 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1899 /* Allocate string table from symbol_obstack. We will need this table
1900 as long as we have its symbol table around. */
1902 strtbl
= (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
1903 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
= strtbl
;
1905 /* Copy length buffer, the first byte is usually zero and is
1906 used for stabs with a name length of zero. */
1907 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1908 if (length
== sizeof lengthbuf
)
1911 val
= bfd_bread (strtbl
+ sizeof lengthbuf
, length
- sizeof lengthbuf
, abfd
);
1913 if (val
!= length
- sizeof lengthbuf
)
1914 error ("cannot read string table from %s: %s",
1915 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1916 if (strtbl
[length
- 1] != '\0')
1917 error ("bad symbol file: string table does not end with null character");
1922 /* If we have not yet seen a function for this psymtab, this is 0. If we
1923 have seen one, it is the offset in the line numbers of the line numbers
1925 static unsigned int first_fun_line_offset
;
1927 static struct partial_symtab
*xcoff_start_psymtab
1928 (struct objfile
*, char *, int,
1929 struct partial_symbol
**, struct partial_symbol
**);
1931 /* Allocate and partially fill a partial symtab. It will be
1932 completely filled at the end of the symbol list.
1934 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1935 is the address relative to which its symbols are (incremental) or 0
1938 static struct partial_symtab
*
1939 xcoff_start_psymtab (struct objfile
*objfile
, char *filename
, int first_symnum
,
1940 struct partial_symbol
**global_syms
,
1941 struct partial_symbol
**static_syms
)
1943 struct partial_symtab
*result
=
1944 start_psymtab_common (objfile
, objfile
->section_offsets
,
1946 /* We fill in textlow later. */
1948 global_syms
, static_syms
);
1950 result
->read_symtab_private
= (char *)
1951 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1952 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
1953 result
->read_symtab
= xcoff_psymtab_to_symtab
;
1955 /* Deduce the source language from the filename for this psymtab. */
1956 psymtab_language
= deduce_language_from_filename (filename
);
1961 static struct partial_symtab
*xcoff_end_psymtab
1962 (struct partial_symtab
*, char **, int, int,
1963 struct partial_symtab
**, int, int);
1965 /* Close off the current usage of PST.
1966 Returns PST, or NULL if the partial symtab was empty and thrown away.
1968 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
1970 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
1971 are the information for includes and dependencies. */
1973 static struct partial_symtab
*
1974 xcoff_end_psymtab (struct partial_symtab
*pst
, char **include_list
,
1975 int num_includes
, int capping_symbol_number
,
1976 struct partial_symtab
**dependency_list
,
1977 int number_dependencies
, int textlow_not_set
)
1980 struct objfile
*objfile
= pst
->objfile
;
1982 if (capping_symbol_number
!= -1)
1983 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
1984 capping_symbol_number
1985 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
1986 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
1987 first_fun_line_offset
;
1988 first_fun_line_offset
= 0;
1989 pst
->n_global_syms
=
1990 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1991 pst
->n_static_syms
=
1992 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1994 pst
->number_of_dependencies
= number_dependencies
;
1995 if (number_dependencies
)
1997 pst
->dependencies
= (struct partial_symtab
**)
1998 obstack_alloc (&objfile
->psymbol_obstack
,
1999 number_dependencies
* sizeof (struct partial_symtab
*));
2000 memcpy (pst
->dependencies
, dependency_list
,
2001 number_dependencies
* sizeof (struct partial_symtab
*));
2004 pst
->dependencies
= 0;
2006 for (i
= 0; i
< num_includes
; i
++)
2008 struct partial_symtab
*subpst
=
2009 allocate_psymtab (include_list
[i
], objfile
);
2011 subpst
->section_offsets
= pst
->section_offsets
;
2012 subpst
->read_symtab_private
=
2013 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
2014 sizeof (struct symloc
));
2015 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2016 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2017 subpst
->textlow
= 0;
2018 subpst
->texthigh
= 0;
2020 /* We could save slight bits of space by only making one of these,
2021 shared by the entire set of include files. FIXME-someday. */
2022 subpst
->dependencies
= (struct partial_symtab
**)
2023 obstack_alloc (&objfile
->psymbol_obstack
,
2024 sizeof (struct partial_symtab
*));
2025 subpst
->dependencies
[0] = pst
;
2026 subpst
->number_of_dependencies
= 1;
2028 subpst
->globals_offset
=
2029 subpst
->n_global_syms
=
2030 subpst
->statics_offset
=
2031 subpst
->n_static_syms
= 0;
2035 subpst
->read_symtab
= pst
->read_symtab
;
2038 sort_pst_symbols (pst
);
2040 /* If there is already a psymtab or symtab for a file of this name,
2041 remove it. (If there is a symtab, more drastic things also
2042 happen.) This happens in VxWorks. */
2043 free_named_symtabs (pst
->filename
);
2045 if (num_includes
== 0
2046 && number_dependencies
== 0
2047 && pst
->n_global_syms
== 0
2048 && pst
->n_static_syms
== 0)
2050 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2051 it is on the obstack, but we can forget to chain it on the list. */
2052 /* Empty psymtabs happen as a result of header files which don't have
2053 any symbols in them. There can be a lot of them. */
2055 discard_psymtab (pst
);
2057 /* Indicate that psymtab was thrown away. */
2058 pst
= (struct partial_symtab
*) NULL
;
2063 static void swap_sym (struct internal_syment
*,
2064 union internal_auxent
*, char **, char **,
2065 unsigned int *, struct objfile
*);
2067 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2068 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2069 the symbol and its auxents. */
2072 swap_sym (struct internal_syment
*symbol
, union internal_auxent
*aux
,
2073 char **name
, char **raw
, unsigned int *symnump
,
2074 struct objfile
*objfile
)
2076 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2077 if (symbol
->n_zeroes
)
2079 /* If it's exactly E_SYMNMLEN characters long it isn't
2081 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2083 /* FIXME: wastes memory for symbols which we don't end up putting
2084 into the minimal symbols. */
2086 p
= obstack_alloc (&objfile
->psymbol_obstack
, E_SYMNMLEN
+ 1);
2087 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2088 p
[E_SYMNMLEN
] = '\0';
2092 /* Point to the unswapped name as that persists as long as the
2094 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2096 else if (symbol
->n_sclass
& 0x80)
2098 *name
= ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
2103 *name
= ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
2107 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2108 if (symbol
->n_numaux
> 0)
2110 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2111 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2113 *symnump
+= symbol
->n_numaux
;
2114 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2119 scan_xcoff_symtab (struct objfile
*objfile
)
2121 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2122 char *filestring
= NULL
;
2125 int past_first_source_file
= 0;
2130 /* Current partial symtab */
2131 struct partial_symtab
*pst
;
2133 /* List of current psymtab's include files */
2134 char **psymtab_include_list
;
2135 int includes_allocated
;
2138 /* Index within current psymtab dependency list */
2139 struct partial_symtab
**dependency_list
;
2140 int dependencies_used
, dependencies_allocated
;
2143 struct internal_syment symbol
;
2144 union internal_auxent main_aux
[5];
2145 unsigned int ssymnum
;
2147 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2148 CORE_ADDR last_csect_val
= 0;
2149 int last_csect_sec
= 0;
2150 int misc_func_recorded
= 0; /* true if any misc. function */
2151 int textlow_not_set
= 1;
2153 pst
= (struct partial_symtab
*) 0;
2155 includes_allocated
= 30;
2157 psymtab_include_list
= (char **) alloca (includes_allocated
*
2160 dependencies_allocated
= 30;
2161 dependencies_used
= 0;
2163 (struct partial_symtab
**) alloca (dependencies_allocated
*
2164 sizeof (struct partial_symtab
*));
2166 last_source_file
= NULL
;
2168 abfd
= objfile
->obfd
;
2170 sraw_symbol
= ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
;
2171 nsyms
= ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl_num_syms
;
2173 while (ssymnum
< nsyms
)
2179 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2180 sclass
= symbol
.n_sclass
;
2187 /* The CSECT auxent--always the last auxent. */
2188 union internal_auxent csect_aux
;
2189 unsigned int symnum_before
= ssymnum
;
2191 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2193 if (symbol
.n_numaux
> 1)
2195 bfd_coff_swap_aux_in
2197 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2200 symbol
.n_numaux
- 1,
2205 csect_aux
= main_aux
[0];
2207 /* If symbol name starts with ".$" or "$", ignore it. */
2208 if (namestring
[0] == '$'
2209 || (namestring
[0] == '.' && namestring
[1] == '$'))
2212 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2215 switch (csect_aux
.x_csect
.x_smclas
)
2218 if (last_csect_name
)
2220 /* If no misc. function recorded in the last
2221 seen csect, enter it as a function. This
2222 will take care of functions like strcmp()
2225 if (!misc_func_recorded
)
2227 RECORD_MINIMAL_SYMBOL
2228 (last_csect_name
, last_csect_val
,
2229 mst_text
, last_csect_sec
,
2235 /* We have to allocate one psymtab for
2236 each program csect, because their text
2237 sections need not be adjacent. */
2239 (pst
, psymtab_include_list
, includes_used
,
2240 symnum_before
, dependency_list
,
2241 dependencies_used
, textlow_not_set
);
2243 dependencies_used
= 0;
2244 /* Give all psymtabs for this source file the same
2246 pst
= xcoff_start_psymtab
2250 objfile
->global_psymbols
.next
,
2251 objfile
->static_psymbols
.next
);
2254 /* Activate the misc_func_recorded mechanism for
2255 compiler- and linker-generated CSECTs like ".strcmp"
2257 if (namestring
&& (namestring
[0] == '.'
2258 || namestring
[0] == '@'))
2260 last_csect_name
= namestring
;
2261 last_csect_val
= symbol
.n_value
;
2263 secnum_to_section (symbol
.n_scnum
, objfile
);
2268 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2269 if (highval
> pst
->texthigh
)
2270 pst
->texthigh
= highval
;
2271 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2272 pst
->textlow
= symbol
.n_value
;
2274 misc_func_recorded
= 0;
2278 /* Data variables are recorded in the minimal symbol
2279 table, except for section symbols. */
2280 if (*namestring
!= '.')
2281 prim_record_minimal_symbol_and_info
2282 (namestring
, symbol
.n_value
,
2283 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2284 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2290 warning ("More than one XMC_TC0 symbol found.");
2291 toc_offset
= symbol
.n_value
;
2293 /* Make TOC offset relative to start address of section. */
2294 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2296 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2300 /* These symbols tell us where the TOC entry for a
2301 variable is, not the variable itself. */
2310 switch (csect_aux
.x_csect
.x_smclas
)
2313 /* A function entry point. */
2315 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2316 first_fun_line_offset
=
2317 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2318 RECORD_MINIMAL_SYMBOL
2319 (namestring
, symbol
.n_value
,
2320 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2321 secnum_to_section (symbol
.n_scnum
, objfile
),
2326 /* shared library function trampoline code entry
2329 /* record trampoline code entries as
2330 mst_solib_trampoline symbol. When we lookup mst
2331 symbols, we will choose mst_text over
2332 mst_solib_trampoline. */
2333 RECORD_MINIMAL_SYMBOL
2334 (namestring
, symbol
.n_value
,
2335 mst_solib_trampoline
,
2336 secnum_to_section (symbol
.n_scnum
, objfile
),
2341 /* The symbols often have the same names as
2342 debug symbols for functions, and confuse
2348 /* xlc puts each variable in a separate csect,
2349 so we get an XTY_SD for each variable. But
2350 gcc puts several variables in a csect, so
2351 that each variable only gets an XTY_LD. We
2352 still need to record them. This will
2353 typically be XMC_RW; I suspect XMC_RO and
2354 XMC_BS might be possible too. */
2355 if (*namestring
!= '.')
2356 prim_record_minimal_symbol_and_info
2357 (namestring
, symbol
.n_value
,
2358 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2359 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2366 switch (csect_aux
.x_csect
.x_smclas
)
2370 /* Common variables are recorded in the minimal symbol
2371 table, except for section symbols. */
2372 if (*namestring
!= '.')
2373 prim_record_minimal_symbol_and_info
2374 (namestring
, symbol
.n_value
,
2375 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2376 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2389 unsigned int symnum_before
;
2391 symnum_before
= ssymnum
;
2392 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2395 /* See if the last csect needs to be recorded. */
2397 if (last_csect_name
&& !misc_func_recorded
)
2400 /* If no misc. function recorded in the last seen csect, enter
2401 it as a function. This will take care of functions like
2402 strcmp() compiled by xlc. */
2404 RECORD_MINIMAL_SYMBOL
2405 (last_csect_name
, last_csect_val
,
2406 mst_text
, last_csect_sec
, objfile
);
2411 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2412 symnum_before
, dependency_list
,
2413 dependencies_used
, textlow_not_set
);
2415 dependencies_used
= 0;
2417 first_fun_line_offset
= 0;
2419 /* XCOFF, according to the AIX 3.2 documentation, puts the
2420 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2421 do things the standard COFF way and put it in the auxent.
2422 We use the auxent if the symbol is ".file" and an auxent
2423 exists, otherwise use the symbol itself. */
2424 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2426 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2429 filestring
= namestring
;
2431 pst
= xcoff_start_psymtab (objfile
,
2434 objfile
->global_psymbols
.next
,
2435 objfile
->static_psymbols
.next
);
2436 last_csect_name
= NULL
;
2442 static struct complaint msg
=
2443 {"Storage class %d not recognized during scan", 0, 0};
2444 complain (&msg
, sclass
);
2448 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2449 to handle only the C_FUN and C_EXT. */
2464 /* C_EINCL means we are switching back to the main file. But there
2465 is no reason to care; the only thing we want to know about
2466 includes is the names of all the included (.h) files. */
2471 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2475 /* I don't think the name of the common block (as opposed to the
2476 variables within it) is something which is user visible
2484 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2485 so C_LSYM would appear to be only for locals. */
2491 /* We probably could save a few instructions by assuming that
2492 C_LSYM, C_PSYM, etc., never have auxents. */
2493 int naux1
= symbol
.n_numaux
+ 1;
2495 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2501 /* Mark down an include file in the current psymtab */
2502 enum language tmp_language
;
2503 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2506 tmp_language
= deduce_language_from_filename (namestring
);
2508 /* Only change the psymtab's language if we've learned
2509 something useful (eg. tmp_language is not language_unknown).
2510 In addition, to match what start_subfile does, never change
2512 if (tmp_language
!= language_unknown
2513 && (tmp_language
!= language_c
2514 || psymtab_language
!= language_cplus
))
2515 psymtab_language
= tmp_language
;
2517 /* In C++, one may expect the same filename to come round many
2518 times, when code is coming alternately from the main file
2519 and from inline functions in other files. So I check to see
2520 if this is a file we've seen before -- either the main
2521 source file, or a previously included file.
2523 This seems to be a lot of time to be spending on N_SOL, but
2524 things like "break c-exp.y:435" need to work (I
2525 suppose the psymtab_include_list could be hashed or put
2526 in a binary tree, if profiling shows this is a major hog). */
2527 if (pst
&& STREQ (namestring
, pst
->filename
))
2531 for (i
= 0; i
< includes_used
; i
++)
2532 if (STREQ (namestring
, psymtab_include_list
[i
]))
2540 psymtab_include_list
[includes_used
++] = namestring
;
2541 if (includes_used
>= includes_allocated
)
2543 char **orig
= psymtab_include_list
;
2545 psymtab_include_list
= (char **)
2546 alloca ((includes_allocated
*= 2) *
2548 memcpy ((PTR
) psymtab_include_list
, (PTR
) orig
,
2549 includes_used
* sizeof (char *));
2554 /* The value of the C_FUN is not the address of the function (it
2555 appears to be the address before linking), but as long as it
2556 is smaller than the actual address, then find_pc_partial_function
2557 will use the minimal symbols instead. I hope. */
2565 static struct complaint function_outside_compilation_unit
= {
2566 "function `%s' appears to be defined outside of all compilation units", 0, 0
2570 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2573 p
= (char *) strchr (namestring
, ':');
2575 continue; /* Not a debugging symbol. */
2577 /* Main processing section for debugging symbols which
2578 the initial read through the symbol tables needs to worry
2579 about. If we reach this point, the symbol which we are
2580 considering is definitely one we are interested in.
2581 p must also contain the (valid) index into the namestring
2582 which indicates the debugging type symbol. */
2587 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2588 #ifdef STATIC_TRANSFORM_NAME
2589 namestring
= STATIC_TRANSFORM_NAME (namestring
);
2591 add_psymbol_to_list (namestring
, p
- namestring
,
2592 VAR_NAMESPACE
, 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_NAMESPACE
, 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_NAMESPACE
, 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_NAMESPACE
, LOC_TYPEDEF
,
2630 &objfile
->static_psymbols
,
2632 psymtab_language
, objfile
);
2635 /* The semantics of C++ state that "struct foo { ... }"
2636 also defines a typedef for "foo". Unfortuantely, cfront
2637 never makes the typedef when translating from C++ to C.
2638 We make the typedef here so that "ptype foo" works as
2639 expected for cfront translated code. */
2640 else if (psymtab_language
== language_cplus
)
2642 /* Also a typedef with the same name. */
2643 add_psymbol_to_list (namestring
, p
- namestring
,
2644 VAR_NAMESPACE
, LOC_TYPEDEF
,
2645 &objfile
->static_psymbols
,
2647 psymtab_language
, objfile
);
2653 if (p
!= namestring
) /* a name is there, not just :T... */
2655 add_psymbol_to_list (namestring
, p
- namestring
,
2656 VAR_NAMESPACE
, LOC_TYPEDEF
,
2657 &objfile
->static_psymbols
,
2659 psymtab_language
, objfile
);
2662 /* If this is an enumerated type, we need to
2663 add all the enum constants to the partial symbol
2664 table. This does not cover enums without names, e.g.
2665 "enum {a, b} c;" in C, but fortunately those are
2666 rare. There is no way for GDB to find those from the
2667 enum type without spending too much time on it. Thus
2668 to solve this problem, the compiler needs to put out the
2669 enum in a nameless type. GCC2 does this. */
2671 /* We are looking for something of the form
2672 <name> ":" ("t" | "T") [<number> "="] "e"
2673 {<constant> ":" <value> ","} ";". */
2675 /* Skip over the colon and the 't' or 'T'. */
2677 /* This type may be given a number. Also, numbers can come
2678 in pairs like (0,26). Skip over it. */
2679 while ((*p
>= '0' && *p
<= '9')
2680 || *p
== '(' || *p
== ',' || *p
== ')'
2686 /* The aix4 compiler emits extra crud before the members. */
2689 /* Skip over the type (?). */
2693 /* Skip over the colon. */
2697 /* We have found an enumerated type. */
2698 /* According to comments in read_enum_type
2699 a comma could end it instead of a semicolon.
2700 I don't know where that happens.
2702 while (*p
&& *p
!= ';' && *p
!= ',')
2706 /* Check for and handle cretinous dbx symbol name
2708 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
2709 p
= next_symbol_text (objfile
);
2711 /* Point to the character after the name
2712 of the enum constant. */
2713 for (q
= p
; *q
&& *q
!= ':'; q
++)
2715 /* Note that the value doesn't matter for
2716 enum constants in psymtabs, just in symtabs. */
2717 add_psymbol_to_list (p
, q
- p
,
2718 VAR_NAMESPACE
, LOC_CONST
,
2719 &objfile
->static_psymbols
, 0,
2720 0, psymtab_language
, objfile
);
2721 /* Point past the name. */
2723 /* Skip over the value. */
2724 while (*p
&& *p
!= ',')
2726 /* Advance past the comma. */
2734 /* Constant, e.g. from "const" in Pascal. */
2735 add_psymbol_to_list (namestring
, p
- namestring
,
2736 VAR_NAMESPACE
, LOC_CONST
,
2737 &objfile
->static_psymbols
, symbol
.n_value
,
2738 0, psymtab_language
, objfile
);
2744 int name_len
= p
- namestring
;
2745 char *name
= xmalloc (name_len
+ 1);
2746 memcpy (name
, namestring
, name_len
);
2747 name
[name_len
] = '\0';
2748 complain (&function_outside_compilation_unit
, name
);
2751 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2752 add_psymbol_to_list (namestring
, p
- namestring
,
2753 VAR_NAMESPACE
, LOC_BLOCK
,
2754 &objfile
->static_psymbols
,
2756 psymtab_language
, objfile
);
2759 /* Global functions were ignored here, but now they
2760 are put into the global psymtab like one would expect.
2761 They're also in the minimal symbol table. */
2765 int name_len
= p
- namestring
;
2766 char *name
= xmalloc (name_len
+ 1);
2767 memcpy (name
, namestring
, name_len
);
2768 name
[name_len
] = '\0';
2769 complain (&function_outside_compilation_unit
, name
);
2772 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2773 add_psymbol_to_list (namestring
, p
- namestring
,
2774 VAR_NAMESPACE
, LOC_BLOCK
,
2775 &objfile
->global_psymbols
,
2777 psymtab_language
, objfile
);
2780 /* Two things show up here (hopefully); static symbols of
2781 local scope (static used inside braces) or extensions
2782 of structure symbols. We can ignore both. */
2796 case '#': /* for symbol identification (used in live ranges) */
2797 /* added to support cfront stabs strings */
2798 case 'Z': /* for definition continuations */
2799 case 'P': /* for prototypes */
2803 /* It is a C++ nested symbol. We don't need to record it
2804 (I don't think); if we try to look up foo::bar::baz,
2805 then symbols for the symtab containing foo should get
2806 read in, I think. */
2807 /* Someone says sun cc puts out symbols like
2808 /foo/baz/maclib::/usr/local/bin/maclib,
2809 which would get here with a symbol type of ':'. */
2813 /* Unexpected symbol descriptor. The second and subsequent stabs
2814 of a continued stab can show up here. The question is
2815 whether they ever can mimic a normal stab--it would be
2816 nice if not, since we certainly don't want to spend the
2817 time searching to the end of every string looking for
2820 complain (&unknown_symchar_complaint
, p
[1]);
2822 /* Ignore it; perhaps it is an extension that we don't
2832 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2833 ssymnum
, dependency_list
,
2834 dependencies_used
, textlow_not_set
);
2837 /* Record the toc offset value of this symbol table into objfile structure.
2838 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2839 this information would be file auxiliary header. */
2841 ((struct coff_symfile_info
*) objfile
->sym_private
)->toc_offset
= toc_offset
;
2844 /* Return the toc offset value for a given objfile. */
2847 get_toc_offset (struct objfile
*objfile
)
2850 return ((struct coff_symfile_info
*) objfile
->sym_private
)->toc_offset
;
2854 /* Scan and build partial symbols for a symbol file.
2855 We have been initialized by a call to dbx_symfile_init, which
2856 put all the relevant info into a "struct dbx_symfile_info",
2857 hung off the objfile structure.
2859 SECTION_OFFSETS contains offsets relative to which the symbols in the
2860 various sections are (depending where the sections were actually loaded).
2861 MAINLINE is true if we are reading the main symbol
2862 table (as opposed to a shared lib or dynamically loaded file). */
2865 xcoff_initial_scan (struct objfile
*objfile
, int mainline
)
2869 struct cleanup
*back_to
;
2870 int num_symbols
; /* # of symbols */
2871 file_ptr symtab_offset
; /* symbol table and */
2872 file_ptr stringtab_offset
; /* string table file offsets */
2873 struct coff_symfile_info
*info
;
2877 info
= (struct coff_symfile_info
*) objfile
->sym_private
;
2878 symfile_bfd
= abfd
= objfile
->obfd
;
2879 name
= objfile
->name
;
2881 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2882 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2883 stringtab_offset
= symtab_offset
+
2884 num_symbols
* coff_data (abfd
)->local_symesz
;
2886 info
->min_lineno_offset
= 0;
2887 info
->max_lineno_offset
= 0;
2888 bfd_map_over_sections (abfd
, find_linenos
, info
);
2890 if (num_symbols
> 0)
2892 /* Read the string table. */
2893 init_stringtab (abfd
, stringtab_offset
, objfile
);
2895 /* Read the .debug section, if present. */
2898 bfd_size_type length
;
2899 char *debugsec
= NULL
;
2901 secp
= bfd_get_section_by_name (abfd
, ".debug");
2904 length
= bfd_section_size (abfd
, secp
);
2908 (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
2910 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2911 (file_ptr
) 0, length
))
2913 error ("Error reading .debug section of `%s': %s",
2914 name
, bfd_errmsg (bfd_get_error ()));
2918 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
=
2923 /* Read the symbols. We keep them in core because we will want to
2924 access them randomly in read_symbol*. */
2925 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2927 error ("Error reading symbols from %s: %s",
2928 name
, bfd_errmsg (bfd_get_error ()));
2929 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2930 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
=
2931 obstack_alloc (&objfile
->symbol_obstack
, size
);
2932 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl_num_syms
=
2935 val
= bfd_bread (((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
,
2938 perror_with_name ("reading symbol table");
2940 /* If we are reinitializing, or if we have never loaded syms yet, init */
2942 || (objfile
->global_psymbols
.size
== 0
2943 && objfile
->static_psymbols
.size
== 0))
2944 /* I'm not sure how how good num_symbols is; the rule of thumb in
2945 init_psymbol_list was developed for a.out. On the one hand,
2946 num_symbols includes auxents. On the other hand, it doesn't
2948 init_psymbol_list (objfile
, num_symbols
);
2950 free_pending_blocks ();
2951 back_to
= make_cleanup (really_free_pendings
, 0);
2953 init_minimal_symbol_collection ();
2954 make_cleanup_discard_minimal_symbols ();
2956 /* Now that the symbol table data of the executable file are all in core,
2957 process them and define symbols accordingly. */
2959 scan_xcoff_symtab (objfile
);
2961 /* Install any minimal symbols that have been collected as the current
2962 minimal symbols for this objfile. */
2964 install_minimal_symbols (objfile
);
2966 do_cleanups (back_to
);
2970 xcoff_symfile_offsets (struct objfile
*objfile
, struct section_addr_info
*addrs
)
2972 asection
*sect
= NULL
;
2975 objfile
->num_sections
= SECT_OFF_MAX
;
2976 objfile
->section_offsets
= (struct section_offsets
*)
2977 obstack_alloc (&objfile
->psymbol_obstack
, SIZEOF_SECTION_OFFSETS
);
2979 /* Initialize the section indexes for future use. */
2980 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
2982 objfile
->sect_index_text
= sect
->index
;
2984 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
2986 objfile
->sect_index_data
= sect
->index
;
2988 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
2990 objfile
->sect_index_bss
= sect
->index
;
2992 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
2994 objfile
->sect_index_rodata
= sect
->index
;
2996 for (i
= 0; i
< objfile
->num_sections
; ++i
)
2998 /* syms_from_objfile kindly subtracts from addr the
2999 bfd_section_vma of the .text section. This strikes me as
3000 wrong--whether the offset to be applied to symbol reading is
3001 relative to the start address of the section depends on the
3002 symbol format. In any event, this whole "addr" concept is
3003 pretty broken (it doesn't handle any section but .text
3004 sensibly), so just ignore the addr parameter and use 0.
3005 rs6000-nat.c will set the correct section offsets via
3006 objfile_relocate. */
3007 (objfile
->section_offsets
)->offsets
[i
] = 0;
3011 /* Register our ability to parse symbols for xcoff BFD files. */
3013 static struct sym_fns xcoff_sym_fns
=
3016 /* It is possible that coff and xcoff should be merged as
3017 they do have fundamental similarities (for example, the extra storage
3018 classes used for stabs could presumably be recognized in any COFF file).
3019 However, in addition to obvious things like all the csect hair, there are
3020 some subtler differences between xcoffread.c and coffread.c, notably
3021 the fact that coffread.c has no need to read in all the symbols, but
3022 xcoffread.c reads all the symbols and does in fact randomly access them
3023 (in C_BSTAT and line number processing). */
3025 bfd_target_xcoff_flavour
,
3027 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3028 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3029 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
3030 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3031 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
3032 NULL
/* next: pointer to next struct sym_fns */
3036 _initialize_xcoffread (void)
3038 add_symtab_fns (&xcoff_sym_fns
);
3040 func_symbol_type
= init_type (TYPE_CODE_FUNC
, 1, 0,
3041 "<function, no debug info>", NULL
);
3042 TYPE_TARGET_TYPE (func_symbol_type
) = builtin_type_int
;
3044 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
3045 "<variable, no debug info>", NULL
);