1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009,
4 2010, 2011 Free Software Foundation, Inc.
5 Derived from coffread.c, dbxread.c, and a lot of hacking.
6 Contributed by IBM Corporation.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include <sys/types.h>
29 #include "gdb_string.h"
31 #include <sys/param.h>
32 #ifdef HAVE_SYS_FILE_H
37 #include "coff/internal.h"
38 #include "libcoff.h" /* FIXME, internal data from BFD */
39 #include "coff/xcoff.h"
41 #include "coff/rs6000.h"
42 #include "xcoffread.h"
46 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */
50 #include "stabsread.h"
51 #include "expression.h"
52 #include "complaints.h"
55 #include "gdb-stabs.h"
57 /* For interface with stabsread.c. */
58 #include "aout/stab_gnu.h"
61 /* We put a pointer to this structure in the read_symtab_private field
67 /* First symbol number for this file. */
71 /* Number of symbols in the section of the symbol table devoted to
72 this file's symbols (actually, the section bracketed may contain
73 more than just this file's symbols). If numsyms is 0, the only
74 reason for this thing's existence is the dependency list. Nothing
75 else will happen when it is read in. */
79 /* Position of the start of the line number information for this
81 unsigned int lineno_off
;
84 /* Remember what we deduced to be the source language of this psymtab. */
86 static enum language psymtab_language
= language_unknown
;
89 /* Simplified internal version of coff symbol table information. */
94 int c_symnum
; /* Symbol number of this entry. */
95 int c_naux
; /* 0 if syment only, 1 if syment + auxent. */
97 unsigned char c_sclass
;
102 /* Last function's saved coff symbol `cs'. */
104 static struct coff_symbol fcn_cs_saved
;
106 static bfd
*symfile_bfd
;
108 /* Core address of start and end of text of current source file.
109 This is calculated from the first function seen after a C_FILE
113 static CORE_ADDR cur_src_end_addr
;
115 /* Core address of the end of the first object file. */
117 static CORE_ADDR first_object_file_end
;
119 /* Initial symbol-table-debug-string vector length. */
121 #define INITIAL_STABVECTOR_LENGTH 40
123 /* Nonzero if within a function (so symbols should be local,
124 if nothing says specifically). */
128 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
129 there is any reason not to just use a #define, but might as well
130 ask BFD for the size and store it here, I guess. */
132 static unsigned local_symesz
;
134 struct coff_symfile_info
136 file_ptr min_lineno_offset
; /* Where in file lowest line#s are. */
137 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file. */
139 /* Pointer to the string table. */
142 /* Pointer to debug section. */
145 /* Pointer to the a.out symbol table. */
148 /* Number of symbols in symtbl. */
151 /* Offset in data section to TOC anchor. */
152 CORE_ADDR toc_offset
;
156 bf_notfound_complaint (void)
158 complaint (&symfile_complaints
,
159 _("line numbers off, `.bf' symbol not found"));
163 ef_complaint (int arg1
)
165 complaint (&symfile_complaints
,
166 _("Mismatched .ef symbol ignored starting at symnum %d"), arg1
);
170 eb_complaint (int arg1
)
172 complaint (&symfile_complaints
,
173 _("Mismatched .eb symbol ignored starting at symnum %d"), arg1
);
176 static void xcoff_initial_scan (struct objfile
*, int);
178 static void scan_xcoff_symtab (struct objfile
*);
180 static char *xcoff_next_symbol_text (struct objfile
*);
182 static void record_include_begin (struct coff_symbol
*);
185 enter_line_range (struct subfile
*, unsigned, unsigned,
186 CORE_ADDR
, CORE_ADDR
, unsigned *);
188 static void init_stringtab (bfd
*, file_ptr
, struct objfile
*);
190 static void xcoff_symfile_init (struct objfile
*);
192 static void xcoff_new_init (struct objfile
*);
194 static void xcoff_symfile_finish (struct objfile
*);
196 static void xcoff_symfile_offsets (struct objfile
*,
197 struct section_addr_info
*addrs
);
199 static char *coff_getfilename (union internal_auxent
*, struct objfile
*);
201 static void read_symbol (struct internal_syment
*, int);
203 static int read_symbol_lineno (int);
205 static CORE_ADDR
read_symbol_nvalue (int);
207 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
210 static void read_xcoff_symtab (struct partial_symtab
*);
213 static void add_stab_to_list (char *, struct pending_stabs
**);
216 static int compare_lte (const void *, const void *);
218 static struct linetable
*arrange_linetable (struct linetable
*);
220 static void record_include_end (struct coff_symbol
*);
222 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
225 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
227 static int secnum_to_section (int, struct objfile
*);
228 static asection
*secnum_to_bfd_section (int, struct objfile
*);
230 struct find_targ_sec_arg
235 struct objfile
*objfile
;
238 static void find_targ_sec (bfd
*, asection
*, void *);
241 find_targ_sec (bfd
*abfd
, asection
*sect
, void *obj
)
243 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
244 struct objfile
*objfile
= args
->objfile
;
246 if (sect
->target_index
== args
->targ_index
)
248 /* This is the section. Figure out what SECT_OFF_* code it is. */
249 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
250 *args
->resultp
= SECT_OFF_TEXT (objfile
);
251 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
252 *args
->resultp
= SECT_OFF_DATA (objfile
);
254 *args
->resultp
= sect
->index
;
255 *args
->bfd_sect
= sect
;
259 /* Return the section number (SECT_OFF_*) that CS points to. */
261 secnum_to_section (int secnum
, struct objfile
*objfile
)
263 int off
= SECT_OFF_TEXT (objfile
);
265 asection
*sect
= NULL
;
266 struct find_targ_sec_arg args
;
267 args
.targ_index
= secnum
;
269 args
.bfd_sect
= §
;
270 args
.objfile
= objfile
;
271 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
275 /* Return the BFD section that CS points to. */
277 secnum_to_bfd_section (int secnum
, struct objfile
*objfile
)
279 int off
= SECT_OFF_TEXT (objfile
);
281 asection
*sect
= NULL
;
282 struct find_targ_sec_arg args
;
283 args
.targ_index
= secnum
;
285 args
.bfd_sect
= §
;
286 args
.objfile
= objfile
;
287 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
291 /* add a given stab string into given stab vector. */
296 add_stab_to_list (char *stabname
, struct pending_stabs
**stabvector
)
298 if (*stabvector
== NULL
)
300 *stabvector
= (struct pending_stabs
*)
301 xmalloc (sizeof (struct pending_stabs
) +
302 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
303 (*stabvector
)->count
= 0;
304 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
306 else if ((*stabvector
)->count
>= (*stabvector
)->length
)
308 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
309 *stabvector
= (struct pending_stabs
*)
310 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
311 (*stabvector
)->length
* sizeof (char *));
313 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
318 /* Linenos are processed on a file-by-file basis.
322 1) xlc (IBM's native c compiler) postpones static function code
323 emission to the end of a compilation unit. This way it can
324 determine if those functions (statics) are needed or not, and
325 can do some garbage collection (I think). This makes line
326 numbers and corresponding addresses unordered, and we end up
327 with a line table like:
344 and that breaks gdb's binary search on line numbers, if the
345 above table is not sorted on line numbers. And that sort
346 should be on function based, since gcc can emit line numbers
349 10 0x100 - for the init/test part of a for stmt.
352 10 0x400 - for the increment part of a for stmt.
354 arrange_linetable() will do this sorting.
356 2) aix symbol table might look like:
358 c_file // beginning of a new file
359 .bi // beginning of include file
360 .ei // end of include file
364 basically, .bi/.ei pairs do not necessarily encapsulate
365 their scope. They need to be recorded, and processed later
366 on when we come the end of the compilation unit.
367 Include table (inclTable) and process_linenos() handle
373 /* compare line table entry addresses. */
376 compare_lte (const void *lte1p
, const void *lte2p
)
378 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
379 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
381 return lte1
->pc
- lte2
->pc
;
384 /* Given a line table with function entries are marked, arrange its
385 functions in ascending order and strip off function entry markers
386 and return it in a newly created table. If the old one is good
387 enough, return the old one. */
388 /* FIXME: I think all this stuff can be replaced by just passing
389 sort_linevec = 1 to end_symtab. */
391 static struct linetable
*
392 arrange_linetable (struct linetable
*oldLineTb
)
394 int ii
, jj
, newline
, /* new line count */
395 function_count
; /* # of functions */
397 struct linetable_entry
*fentry
; /* function entry vector */
398 int fentry_size
; /* # of function entries */
399 struct linetable
*newLineTb
; /* new line table */
401 #define NUM_OF_FUNCTIONS 20
403 fentry_size
= NUM_OF_FUNCTIONS
;
404 fentry
= (struct linetable_entry
*)
405 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
407 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
409 if (oldLineTb
->item
[ii
].line
== 0)
410 { /* Function entry found. */
411 if (function_count
>= fentry_size
)
412 { /* Make sure you have room. */
414 fentry
= (struct linetable_entry
*)
416 fentry_size
* sizeof (struct linetable_entry
));
418 fentry
[function_count
].line
= ii
;
419 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
424 if (function_count
== 0)
429 else if (function_count
> 1)
430 qsort (fentry
, function_count
,
431 sizeof (struct linetable_entry
), compare_lte
);
433 /* Allocate a new line table. */
434 newLineTb
= (struct linetable
*)
436 (sizeof (struct linetable
) +
437 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
439 /* If line table does not start with a function beginning, copy up until
443 if (oldLineTb
->item
[0].line
!= 0)
445 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
446 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
448 /* Now copy function lines one by one. */
450 for (ii
= 0; ii
< function_count
; ++ii
)
452 for (jj
= fentry
[ii
].line
+ 1;
453 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
455 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
458 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
462 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
463 following `IncludeChain'. At the end of each symtab (end_symtab),
464 we will determine if we should create additional symtab's to
465 represent if (the include files. */
468 typedef struct _inclTable
470 char *name
; /* include filename */
472 /* Offsets to the line table. end points to the last entry which is
473 part of this include file. */
476 struct subfile
*subfile
;
477 unsigned funStartLine
; /* Start line # of its function. */
481 #define INITIAL_INCLUDE_TABLE_LENGTH 20
482 static InclTable
*inclTable
; /* global include table */
483 static int inclIndx
; /* last entry to table */
484 static int inclLength
; /* table length */
485 static int inclDepth
; /* nested include depth */
487 static void allocate_include_entry (void);
490 record_include_begin (struct coff_symbol
*cs
)
494 /* In xcoff, we assume include files cannot be nested (not in .c files
495 of course, but in corresponding .s files.). */
497 /* This can happen with old versions of GCC.
498 GCC 2.3.3-930426 does not exhibit this on a test case which
499 a user said produced the message for him. */
500 complaint (&symfile_complaints
, _("Nested C_BINCL symbols"));
504 allocate_include_entry ();
506 inclTable
[inclIndx
].name
= cs
->c_name
;
507 inclTable
[inclIndx
].begin
= cs
->c_value
;
511 record_include_end (struct coff_symbol
*cs
)
517 complaint (&symfile_complaints
, _("Mismatched C_BINCL/C_EINCL pair"));
520 allocate_include_entry ();
522 pTbl
= &inclTable
[inclIndx
];
523 pTbl
->end
= cs
->c_value
;
530 allocate_include_entry (void)
532 if (inclTable
== NULL
)
534 inclTable
= (InclTable
*)
535 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
537 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
538 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
541 else if (inclIndx
>= inclLength
)
543 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
544 inclTable
= (InclTable
*)
545 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
546 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
547 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
551 /* Global variable to pass the psymtab down to all the routines involved
552 in psymtab to symtab processing. */
553 static struct partial_symtab
*this_symtab_psymtab
;
555 /* given the start and end addresses of a compilation unit (or a csect,
556 at times) process its lines and create appropriate line vectors. */
559 process_linenos (CORE_ADDR start
, CORE_ADDR end
)
562 file_ptr max_offset
=
563 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
564 ->deprecated_sym_private
)->max_lineno_offset
;
566 /* subfile structure for the main compilation unit. */
567 struct subfile main_subfile
;
569 /* In the main source file, any time we see a function entry, we
570 reset this variable to function's absolute starting line number.
571 All the following line numbers in the function are relative to
572 this, and we record absolute line numbers in record_line(). */
574 unsigned int main_source_baseline
= 0;
579 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
581 goto return_after_cleanup
;
583 memset (&main_subfile
, '\0', sizeof (main_subfile
));
586 /* All source lines were in the main source file. None in include
589 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
590 &main_source_baseline
);
594 /* There was source with line numbers in include files. */
597 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
598 main_source_baseline
= 0;
600 for (ii
= 0; ii
< inclIndx
; ++ii
)
602 struct subfile
*tmpSubfile
;
604 /* If there is main file source before include file, enter it. */
605 if (offset
< inclTable
[ii
].begin
)
608 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
609 start
, 0, &main_source_baseline
);
612 if (strcmp (inclTable
[ii
].name
, last_source_file
) == 0)
614 /* The entry in the include table refers to the main source
615 file. Add the lines to the main subfile. */
617 main_source_baseline
= inclTable
[ii
].funStartLine
;
619 (&main_subfile
, inclTable
[ii
].begin
, inclTable
[ii
].end
,
620 start
, 0, &main_source_baseline
);
621 inclTable
[ii
].subfile
= &main_subfile
;
625 /* Have a new subfile for the include file. */
627 tmpSubfile
= inclTable
[ii
].subfile
=
628 (struct subfile
*) xmalloc (sizeof (struct subfile
));
630 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
631 firstLine
= &(inclTable
[ii
].funStartLine
);
633 /* Enter include file's lines now. */
634 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
635 inclTable
[ii
].end
, start
, 0, firstLine
);
638 if (offset
<= inclTable
[ii
].end
)
639 offset
= inclTable
[ii
].end
+ linesz
;
642 /* All the include files' line have been processed at this point. Now,
643 enter remaining lines of the main file, if any left. */
644 if (offset
< max_offset
+ 1 - linesz
)
646 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
647 &main_source_baseline
);
651 /* Process main file's line numbers. */
652 if (main_subfile
.line_vector
)
654 struct linetable
*lineTb
, *lv
;
656 lv
= main_subfile
.line_vector
;
658 /* Line numbers are not necessarily ordered. xlc compilation will
659 put static function to the end. */
661 lineTb
= arrange_linetable (lv
);
664 current_subfile
->line_vector
= (struct linetable
*)
665 xrealloc (lv
, (sizeof (struct linetable
)
666 + lv
->nitems
* sizeof (struct linetable_entry
)));
671 current_subfile
->line_vector
= lineTb
;
674 current_subfile
->line_vector_length
=
675 current_subfile
->line_vector
->nitems
;
678 /* Now, process included files' line numbers. */
680 for (ii
= 0; ii
< inclIndx
; ++ii
)
682 if (inclTable
[ii
].subfile
!= ((struct subfile
*) &main_subfile
)
683 && (inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!!
686 struct linetable
*lineTb
, *lv
;
688 lv
= (inclTable
[ii
].subfile
)->line_vector
;
690 /* Line numbers are not necessarily ordered. xlc compilation will
691 put static function to the end. */
693 lineTb
= arrange_linetable (lv
);
697 /* For the same include file, we might want to have more than one
698 subfile. This happens if we have something like:
706 while foo.h including code in it. (stupid but possible)
707 Since start_subfile() looks at the name and uses an
708 existing one if finds, we need to provide a fake name and
712 start_subfile (inclTable
[ii
].name
, (char *) 0);
715 /* Pick a fake name that will produce the same results as this
716 one when passed to deduce_language_from_filename. Kludge on
718 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
720 if (fakename
== NULL
)
722 start_subfile (fakename
, (char *) 0);
723 xfree (current_subfile
->name
);
725 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
730 current_subfile
->line_vector
=
731 (struct linetable
*) xrealloc
732 (lv
, (sizeof (struct linetable
)
733 + lv
->nitems
* sizeof (struct linetable_entry
)));
739 current_subfile
->line_vector
= lineTb
;
742 current_subfile
->line_vector_length
=
743 current_subfile
->line_vector
->nitems
;
744 start_subfile (pop_subfile (), (char *) 0);
748 return_after_cleanup
:
750 /* We don't want to keep alloc/free'ing the global include file table. */
753 /* Start with a fresh subfile structure for the next file. */
754 memset (&main_subfile
, '\0', sizeof (struct subfile
));
758 aix_process_linenos (void)
760 /* Process line numbers and enter them into line vector. */
761 process_linenos (last_source_start_addr
, cur_src_end_addr
);
765 /* Enter a given range of lines into the line vector.
766 can be called in the following two ways:
767 enter_line_range (subfile, beginoffset, endoffset,
768 startaddr, 0, firstLine) or
769 enter_line_range (subfile, beginoffset, 0,
770 startaddr, endaddr, firstLine)
772 endoffset points to the last line table entry that we should pay
776 enter_line_range (struct subfile
*subfile
, unsigned beginoffset
,
777 unsigned endoffset
, /* offsets to line table */
778 CORE_ADDR startaddr
, /* offsets to line table */
779 CORE_ADDR endaddr
, unsigned *firstLine
)
781 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
782 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
783 unsigned int curoffset
;
786 struct internal_lineno int_lnno
;
787 unsigned int limit_offset
;
791 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
793 curoffset
= beginoffset
;
795 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)
800 if (endoffset
>= limit_offset
)
802 complaint (&symfile_complaints
,
803 _("Bad line table offset in C_EINCL directive"));
806 limit_offset
= endoffset
;
811 abfd
= objfile
->obfd
;
812 linesz
= coff_data (abfd
)->local_linesz
;
813 ext_lnno
= alloca (linesz
);
815 while (curoffset
<= limit_offset
)
817 bfd_seek (abfd
, curoffset
, SEEK_SET
);
818 bfd_bread (ext_lnno
, linesz
, abfd
);
819 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
821 /* Find the address this line represents. */
822 addr
= (int_lnno
.l_lnno
823 ? int_lnno
.l_addr
.l_paddr
824 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
825 addr
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
827 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
830 if (int_lnno
.l_lnno
== 0)
832 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
833 record_line (subfile
, 0, gdbarch_addr_bits_remove (gdbarch
, addr
));
837 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
,
838 gdbarch_addr_bits_remove (gdbarch
, addr
));
844 /* Save the vital information for use when closing off the current file.
845 NAME is the file name the symbols came from, START_ADDR is the first
846 text address for the file, and SIZE is the number of bytes of text. */
848 #define complete_symtab(name, start_addr) { \
849 last_source_file = xstrdup (name); \
850 last_source_start_addr = start_addr; \
854 /* Refill the symbol table input buffer
855 and set the variables that control fetching entries from it.
856 Reports an error if no data available.
857 This function can read past the end of the symbol table
858 (into the string table) but this does no harm. */
860 /* Reading symbol table has to be fast! Keep the followings as macros, rather
863 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
868 if (namestr[0] == '.') ++namestr; \
869 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
870 (SECTION), (asection *)NULL, \
872 misc_func_recorded = 1; \
876 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
877 nested. At any given time, a symbol can only be in one static block.
878 This is the base address of current static block, zero if non exists. */
880 static int static_block_base
= 0;
882 /* Section number for the current static block. */
884 static int static_block_section
= -1;
886 /* true if space for symbol name has been allocated. */
888 static int symname_alloced
= 0;
890 /* Next symbol to read. Pointer into raw seething symbol table. */
892 static char *raw_symbol
;
894 /* This is the function which stabsread.c calls to get symbol
898 xcoff_next_symbol_text (struct objfile
*objfile
)
900 struct internal_syment symbol
;
903 /* FIXME: is this the same as the passed arg? */
904 if (this_symtab_psymtab
)
905 objfile
= this_symtab_psymtab
->objfile
;
907 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
910 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
912 /* Return something which points to '\0' and hope the symbol reading
913 code does something reasonable. */
916 else if (symbol
.n_sclass
& 0x80)
918 retval
= ((struct coff_symfile_info
*)
919 objfile
->deprecated_sym_private
)->debugsec
921 raw_symbol
+= coff_data (objfile
->obfd
)->local_symesz
;
926 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
928 /* Return something which points to '\0' and hope the symbol reading
929 code does something reasonable. */
935 /* Read symbols for a given partial symbol table. */
938 read_xcoff_symtab (struct partial_symtab
*pst
)
940 struct objfile
*objfile
= pst
->objfile
;
941 bfd
*abfd
= objfile
->obfd
;
942 char *raw_auxptr
; /* Pointer to first raw aux entry for sym. */
944 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
;
946 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
;
947 char *debugfmt
= bfd_xcoff_is_xcoff64 (abfd
) ? "XCOFF64" : "XCOFF";
949 struct internal_syment symbol
[1];
950 union internal_auxent main_aux
;
951 struct coff_symbol cs
[1];
952 CORE_ADDR file_start_addr
= 0;
953 CORE_ADDR file_end_addr
= 0;
955 int next_file_symnum
= -1;
956 unsigned int max_symnum
;
957 int just_started
= 1;
959 int fcn_start_addr
= 0;
961 struct coff_symbol fcn_stab_saved
= { 0 };
963 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
964 union internal_auxent fcn_aux_saved
;
965 struct context_stack
*new;
967 char *filestring
= " _start_ "; /* Name of the current file. */
969 char *last_csect_name
; /* Last seen csect's name and value. */
970 CORE_ADDR last_csect_val
;
973 this_symtab_psymtab
= pst
;
975 /* Get the appropriate COFF "constants" related to the file we're
977 local_symesz
= coff_data (abfd
)->local_symesz
;
979 last_source_file
= NULL
;
984 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
985 record_debugformat (debugfmt
);
986 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
988 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
989 first_object_file_end
= 0;
992 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
993 + symnum
* local_symesz
;
995 while (symnum
< max_symnum
)
997 QUIT
; /* make this command interruptable. */
999 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1000 /* read one symbol into `cs' structure. After processing the
1001 whole symbol table, only string table will be kept in memory,
1002 symbol table and debug section of xcoff will be freed. Thus
1003 we can mark symbols with names in string table as
1008 /* Swap and align the symbol into a reasonable C structure. */
1009 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1011 cs
->c_symnum
= symnum
;
1012 cs
->c_naux
= symbol
->n_numaux
;
1013 if (symbol
->n_zeroes
)
1015 symname_alloced
= 0;
1016 /* We must use the original, unswapped, name here so the name field
1017 pointed to by cs->c_name will persist throughout xcoffread. If
1018 we use the new field, it gets overwritten for each symbol. */
1019 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
1020 /* If it's exactly E_SYMNMLEN characters long it isn't
1022 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1026 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
1027 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1028 p
[E_SYMNMLEN
] = '\0';
1030 symname_alloced
= 1;
1033 else if (symbol
->n_sclass
& 0x80)
1035 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1036 symname_alloced
= 0;
1040 /* in string table */
1041 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1042 symname_alloced
= 1;
1044 cs
->c_value
= symbol
->n_value
;
1045 cs
->c_sclass
= symbol
->n_sclass
;
1046 cs
->c_secnum
= symbol
->n_scnum
;
1047 cs
->c_type
= (unsigned) symbol
->n_type
;
1049 raw_symbol
+= local_symesz
;
1052 /* Save addr of first aux entry. */
1053 raw_auxptr
= raw_symbol
;
1055 /* Skip all the auxents associated with this symbol. */
1056 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1058 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1063 /* if symbol name starts with ".$" or "$", ignore it. */
1064 if (cs
->c_name
[0] == '$'
1065 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1068 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1070 if (last_source_file
)
1072 pst
->symtab
= end_symtab (cur_src_end_addr
, objfile
,
1073 SECT_OFF_TEXT (objfile
));
1078 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1079 record_debugformat (debugfmt
);
1080 cur_src_end_addr
= first_object_file_end
;
1081 /* Done with all files, everything from here on is globals. */
1084 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1087 /* Dealing with a symbol with a csect entry. */
1089 #define CSECT(PP) ((PP)->x_csect)
1090 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1091 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1092 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1093 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1095 /* Convert the auxent to something we can access. */
1096 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1097 0, cs
->c_naux
, &main_aux
);
1099 switch (CSECT_SMTYP (&main_aux
))
1103 /* Ignore all external references. */
1107 /* A section description. */
1109 switch (CSECT_SCLAS (&main_aux
))
1115 /* A program csect is seen. We have to allocate one
1116 symbol table for each program csect. Normally gdb
1117 prefers one symtab for each source file. In case
1118 of AIX, one source file might include more than one
1119 [PR] csect, and they don't have to be adjacent in
1120 terms of the space they occupy in memory. Thus, one
1121 single source file might get fragmented in the
1122 memory and gdb's file start and end address
1123 approach does not work! GCC (and I think xlc) seem
1124 to put all the code in the unnamed program csect. */
1126 if (last_csect_name
)
1128 complete_symtab (filestring
, file_start_addr
);
1129 cur_src_end_addr
= file_end_addr
;
1130 end_symtab (file_end_addr
, objfile
,
1131 SECT_OFF_TEXT (objfile
));
1134 /* Give all csects for this source file the same
1136 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1137 record_debugformat (debugfmt
);
1140 /* If this is the very first csect seen,
1141 basically `__start'. */
1144 first_object_file_end
1145 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1150 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1151 SECT_OFF_TEXT (objfile
));
1152 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1154 if (cs
->c_name
&& (cs
->c_name
[0] == '.'
1155 || cs
->c_name
[0] == '@'))
1157 last_csect_name
= cs
->c_name
;
1158 last_csect_val
= cs
->c_value
;
1159 last_csect_sec
= secnum_to_section (cs
->c_secnum
,
1165 /* All other symbols are put into the minimal symbol
1178 /* Ignore the symbol. */
1186 switch (CSECT_SCLAS (&main_aux
))
1189 /* a function entry point. */
1190 function_entry_point
:
1192 fcn_start_addr
= cs
->c_value
;
1194 /* save the function header info, which will be used
1195 when `.bf' is seen. */
1197 fcn_aux_saved
= main_aux
;
1201 /* shared library function trampoline code entry point. */
1205 /* The symbols often have the same names as debug symbols for
1206 functions, and confuse lookup_symbol. */
1210 /* xlc puts each variable in a separate csect, so we get
1211 an XTY_SD for each variable. But gcc puts several
1212 variables in a csect, so that each variable only gets
1213 an XTY_LD. This will typically be XMC_RW; I suspect
1214 XMC_RO and XMC_BS might be possible too.
1215 These variables are put in the minimal symbol table
1222 /* Common symbols are put into the minimal symbol table only. */
1230 /* If explicitly specified as a function, treat is as one. This check
1231 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1232 after the above CSECT check. */
1233 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1235 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1236 0, cs
->c_naux
, &main_aux
);
1237 goto function_entry_point
;
1240 switch (cs
->c_sclass
)
1244 /* c_value field contains symnum of next .file entry in table
1245 or symnum of first global after last .file. */
1247 next_file_symnum
= cs
->c_value
;
1249 /* Complete symbol table for last object file containing
1250 debugging information. */
1252 /* Whether or not there was a csect in the previous file, we
1253 have to call `end_stabs' and `start_stabs' to reset
1254 type_vector, line_vector, etc. structures. */
1256 complete_symtab (filestring
, file_start_addr
);
1257 cur_src_end_addr
= file_end_addr
;
1258 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1261 /* XCOFF, according to the AIX 3.2 documentation, puts the
1262 filename in cs->c_name. But xlc 1.3.0.2 has decided to
1263 do things the standard COFF way and put it in the auxent.
1264 We use the auxent if the symbol is ".file" and an auxent
1265 exists, otherwise use the symbol itself. Simple
1267 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1269 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1270 0, cs
->c_naux
, &main_aux
);
1271 filestring
= coff_getfilename (&main_aux
, objfile
);
1274 filestring
= cs
->c_name
;
1277 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1278 record_debugformat (debugfmt
);
1279 last_csect_name
= 0;
1281 /* reset file start and end addresses. A compilation unit
1282 with no text (only data) should have zero file
1284 file_start_addr
= file_end_addr
= 0;
1288 fcn_stab_saved
= *cs
;
1292 if (strcmp (cs
->c_name
, ".bf") == 0)
1294 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1295 SECT_OFF_TEXT (objfile
));
1297 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1298 0, cs
->c_naux
, &main_aux
);
1300 within_function
= 1;
1302 new = push_context (0, fcn_start_addr
+ off
);
1304 new->name
= define_symbol
1305 (fcn_cs_saved
.c_value
+ off
,
1306 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1307 if (new->name
!= NULL
)
1308 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1310 else if (strcmp (cs
->c_name
, ".ef") == 0)
1312 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1313 0, cs
->c_naux
, &main_aux
);
1315 /* The value of .ef is the address of epilogue code;
1316 not useful for gdb. */
1317 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1318 contains number of lines to '}' */
1320 if (context_stack_depth
<= 0)
1321 { /* We attempted to pop an empty context stack. */
1322 ef_complaint (cs
->c_symnum
);
1323 within_function
= 0;
1326 new = pop_context ();
1327 /* Stack must be empty now. */
1328 if (context_stack_depth
> 0 || new == NULL
)
1330 ef_complaint (cs
->c_symnum
);
1331 within_function
= 0;
1335 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1337 (fcn_cs_saved
.c_value
1338 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1339 + ANOFFSET (objfile
->section_offsets
,
1340 SECT_OFF_TEXT (objfile
))),
1342 within_function
= 0;
1347 /* Begin static block. */
1349 struct internal_syment symbol
;
1351 read_symbol (&symbol
, cs
->c_value
);
1352 static_block_base
= symbol
.n_value
;
1353 static_block_section
=
1354 secnum_to_section (symbol
.n_scnum
, objfile
);
1359 /* End of static block. */
1360 static_block_base
= 0;
1361 static_block_section
= -1;
1372 complaint (&symfile_complaints
,
1373 _("Unrecognized storage class %d."),
1388 /* beginning of include file */
1389 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1390 order. Thus, when wee see them, we might not know enough info
1391 to process them. Thus, we'll be saving them into a table
1392 (inclTable) and postpone their processing. */
1394 record_include_begin (cs
);
1398 /* End of include file. */
1399 /* See the comment after case C_BINCL. */
1400 record_include_end (cs
);
1404 if (strcmp (cs
->c_name
, ".bb") == 0)
1407 new = push_context (depth
,
1409 + ANOFFSET (objfile
->section_offsets
,
1410 SECT_OFF_TEXT (objfile
))));
1412 else if (strcmp (cs
->c_name
, ".eb") == 0)
1414 if (context_stack_depth
<= 0)
1415 { /* We attempted to pop an empty context stack. */
1416 eb_complaint (cs
->c_symnum
);
1419 new = pop_context ();
1420 if (depth
-- != new->depth
)
1422 eb_complaint (cs
->c_symnum
);
1425 if (local_symbols
&& context_stack_depth
> 0)
1427 /* Make a block for the local symbols within. */
1428 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1431 + ANOFFSET (objfile
->section_offsets
,
1432 SECT_OFF_TEXT (objfile
))),
1435 local_symbols
= new->locals
;
1440 process_xcoff_symbol (cs
, objfile
);
1445 if (last_source_file
)
1449 complete_symtab (filestring
, file_start_addr
);
1450 cur_src_end_addr
= file_end_addr
;
1451 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1452 /* When reading symbols for the last C_FILE of the objfile, try
1453 to make sure that we set pst->symtab to the symtab for the
1454 file, not to the _globals_ symtab. I'm not sure whether this
1455 actually works right or when/if it comes up. */
1456 if (pst
->symtab
== NULL
)
1462 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1463 (SYMBOL2) = (struct symbol *) \
1464 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1465 *(SYMBOL2) = *(SYMBOL1);
1468 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1469 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), \
1470 &objfile->objfile_obstack))
1473 /* process one xcoff symbol. */
1475 static struct symbol
*
1476 process_xcoff_symbol (struct coff_symbol
*cs
, struct objfile
*objfile
)
1478 struct symbol onesymbol
;
1479 struct symbol
*sym
= &onesymbol
;
1480 struct symbol
*sym2
= NULL
;
1486 if (cs
->c_secnum
< 0)
1488 /* The value is a register number, offset within a frame, etc.,
1489 and does not get relocated. */
1495 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1496 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1503 memset (sym
, '\0', sizeof (struct symbol
));
1505 /* default assumptions */
1506 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1507 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1508 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1510 if (ISFCN (cs
->c_type
))
1512 /* At this point, we don't know the type of the function. This
1513 will be patched with the type from its stab entry later on in
1514 patch_block_stabs (), unless the file was compiled without -g. */
1516 SYMBOL_SET_LINKAGE_NAME (sym
, SYMNAME_ALLOC (name
, symname_alloced
));
1517 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_text_symbol
;
1519 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1520 SYMBOL_DUP (sym
, sym2
);
1522 if (cs
->c_sclass
== C_EXT
)
1523 add_symbol_to_list (sym2
, &global_symbols
);
1524 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1525 add_symbol_to_list (sym2
, &file_symbols
);
1529 /* In case we can't figure out the type, provide default. */
1530 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_data_symbol
;
1532 switch (cs
->c_sclass
)
1535 /* The values of functions and global symbols are now resolved
1536 via the global_sym_chain in stabsread.c. */
1538 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1539 add_stab_to_list (name
, &global_stabs
);
1541 add_stab_to_list (name
, &file_stabs
);
1545 add_stab_to_list (name
, &global_stabs
);
1550 common_block_start (cs
->c_name
, objfile
);
1554 common_block_end (objfile
);
1558 complaint (&symfile_complaints
, _("Unexpected storage class: %d"),
1571 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1574 SYMBOL_SECTION (sym
) = sec
;
1581 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1582 all statics and we need to distinguish file-scope versus
1583 function-scope using within_function. We do this by
1584 changing the string we pass to define_symbol to use 'S'
1585 where we need to, which is not necessarily super-clean,
1586 but seems workable enough. */
1588 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1592 if (*pp
== 'V' && !within_function
)
1594 sym
= define_symbol ((cs
->c_value
1595 + ANOFFSET (objfile
->section_offsets
,
1596 static_block_section
)),
1597 cs
->c_name
, 0, 0, objfile
);
1600 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1601 SYMBOL_SECTION (sym
) = static_block_section
;
1610 /* Extract the file name from the aux entry of a C_FILE symbol.
1611 Result is in static storage and is only good for temporary use. */
1614 coff_getfilename (union internal_auxent
*aux_entry
, struct objfile
*objfile
)
1616 static char buffer
[BUFSIZ
];
1618 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1619 strcpy (buffer
, ((struct coff_symfile_info
*)
1620 objfile
->deprecated_sym_private
)->strtbl
1621 + aux_entry
->x_file
.x_n
.x_offset
);
1624 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1625 buffer
[FILNMLEN
] = '\0';
1630 /* Set *SYMBOL to symbol number symno in symtbl. */
1632 read_symbol (struct internal_syment
*symbol
, int symno
)
1635 = ((struct coff_symfile_info
*)
1636 this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl_num_syms
;
1637 char *stbl
= ((struct coff_symfile_info
*)
1638 this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl
;
1640 if (symno
< 0 || symno
>= nsyms
)
1642 complaint (&symfile_complaints
, _("Invalid symbol offset"));
1643 symbol
->n_value
= 0;
1644 symbol
->n_scnum
= -1;
1647 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1648 stbl
+ (symno
* local_symesz
),
1652 /* Get value corresponding to symbol number symno in symtbl. */
1655 read_symbol_nvalue (int symno
)
1657 struct internal_syment symbol
[1];
1659 read_symbol (symbol
, symno
);
1660 return symbol
->n_value
;
1664 /* Find the address of the function corresponding to symno, where
1665 symno is the symbol pointed to by the linetable. */
1668 read_symbol_lineno (int symno
)
1670 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1671 int xcoff64
= bfd_xcoff_is_xcoff64 (objfile
->obfd
);
1673 struct coff_symfile_info
*info
=
1674 (struct coff_symfile_info
*)objfile
->deprecated_sym_private
;
1675 int nsyms
= info
->symtbl_num_syms
;
1676 char *stbl
= info
->symtbl
;
1677 char *strtbl
= info
->strtbl
;
1679 struct internal_syment symbol
[1];
1680 union internal_auxent main_aux
[1];
1684 bf_notfound_complaint ();
1688 /* Note that just searching for a short distance (e.g. 50 symbols)
1689 is not enough, at least in the following case.
1692 [many .stabx entries]
1693 [a few functions, referring to foo]
1697 What happens here is that the assembler moves the .stabx entries
1698 to right before the ".bf" for foo, but the symbol for "foo" is before
1699 all the stabx entries. See PR gdb/2222. */
1701 /* Maintaining a table of .bf entries might be preferable to this search.
1702 If I understand things correctly it would need to be done only for
1703 the duration of a single psymtab to symtab conversion. */
1704 while (symno
< nsyms
)
1706 bfd_coff_swap_sym_in (symfile_bfd
,
1707 stbl
+ (symno
* local_symesz
), symbol
);
1708 if (symbol
->n_sclass
== C_FCN
)
1710 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1712 if (strcmp (name
, ".bf") == 0)
1715 symno
+= symbol
->n_numaux
+ 1;
1718 bf_notfound_complaint ();
1722 /* Take aux entry and return its lineno. */
1724 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1725 symbol
->n_type
, symbol
->n_sclass
,
1726 0, symbol
->n_numaux
, main_aux
);
1728 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1731 /* Support for line number handling. */
1733 /* This function is called for every section; it finds the outer limits
1734 * of the line table (minimum and maximum file offset) so that the
1735 * mainline code can read the whole thing for efficiency.
1738 find_linenos (struct bfd
*abfd
, struct bfd_section
*asect
, void *vpinfo
)
1740 struct coff_symfile_info
*info
;
1742 file_ptr offset
, maxoff
;
1744 count
= asect
->lineno_count
;
1746 if (strcmp (asect
->name
, ".text") != 0 || count
== 0)
1749 size
= count
* coff_data (abfd
)->local_linesz
;
1750 info
= (struct coff_symfile_info
*) vpinfo
;
1751 offset
= asect
->line_filepos
;
1752 maxoff
= offset
+ size
;
1754 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1755 info
->min_lineno_offset
= offset
;
1757 if (maxoff
> info
->max_lineno_offset
)
1758 info
->max_lineno_offset
= maxoff
;
1761 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1764 xcoff_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1766 struct cleanup
*old_chain
;
1775 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1780 /* Read in all partial symtabs on which this one is dependent. */
1781 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1782 if (!pst
->dependencies
[i
]->readin
)
1784 /* Inform about additional files that need to be read in. */
1787 fputs_filtered (" ", gdb_stdout
);
1789 fputs_filtered ("and ", gdb_stdout
);
1791 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1792 wrap_here (""); /* Flush output */
1793 gdb_flush (gdb_stdout
);
1795 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1798 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1800 /* Init stuff necessary for reading in symbols. */
1803 old_chain
= make_cleanup (really_free_pendings
, 0);
1805 read_xcoff_symtab (pst
);
1807 do_cleanups (old_chain
);
1813 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1815 /* Read in all of the symbols for a given psymtab for real.
1816 Be verbose about it if the user wants that. */
1819 xcoff_psymtab_to_symtab (struct partial_symtab
*pst
)
1829 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1834 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1835 || pst
->number_of_dependencies
)
1837 /* Print the message now, before reading the string table,
1838 to avoid disconcerting pauses. */
1841 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1842 gdb_flush (gdb_stdout
);
1845 sym_bfd
= pst
->objfile
->obfd
;
1847 next_symbol_text_func
= xcoff_next_symbol_text
;
1849 xcoff_psymtab_to_symtab_1 (pst
);
1851 /* Match with global symbols. This only needs to be done once,
1852 after all of the symtabs and dependencies have been read in. */
1853 scan_file_globals (pst
->objfile
);
1855 /* Finish up the debug error message. */
1857 printf_filtered ("done.\n");
1862 xcoff_new_init (struct objfile
*objfile
)
1864 stabsread_new_init ();
1865 buildsym_new_init ();
1868 /* Do initialization in preparation for reading symbols from OBJFILE.
1870 We will only be called if this is an XCOFF or XCOFF-like file.
1871 BFD handles figuring out the format of the file, and code in symfile.c
1872 uses BFD's determination to vector to us. */
1875 xcoff_symfile_init (struct objfile
*objfile
)
1877 /* Allocate struct to keep track of the symfile. */
1878 objfile
->deprecated_sym_private
1879 = xmalloc (sizeof (struct coff_symfile_info
));
1881 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1882 find this causes a significant slowdown in gdb then we could
1883 set it in the debug symbol readers only when necessary. */
1884 objfile
->flags
|= OBJF_REORDERED
;
1886 init_entry_point_info (objfile
);
1889 /* Perform any local cleanups required when we are done with a particular
1890 objfile. I.E, we are in the process of discarding all symbol information
1891 for an objfile, freeing up all memory held for it, and unlinking the
1892 objfile struct from the global list of known objfiles. */
1895 xcoff_symfile_finish (struct objfile
*objfile
)
1897 if (objfile
->deprecated_sym_private
!= NULL
)
1899 xfree (objfile
->deprecated_sym_private
);
1902 /* Start with a fresh include table for the next objfile. */
1908 inclIndx
= inclLength
= inclDepth
= 0;
1913 init_stringtab (bfd
*abfd
, file_ptr offset
, struct objfile
*objfile
)
1917 unsigned char lengthbuf
[4];
1920 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
1923 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1924 error (_("cannot seek to string table in %s: %s"),
1925 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1927 val
= bfd_bread ((char *) lengthbuf
, sizeof lengthbuf
, abfd
);
1928 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1930 /* If no string table is needed, then the file may end immediately
1931 after the symbols. Just return with `strtbl' set to NULL. */
1933 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1936 /* Allocate string table from objfile_obstack. We will need this table
1937 as long as we have its symbol table around. */
1939 strtbl
= (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
1940 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
1943 /* Copy length buffer, the first byte is usually zero and is
1944 used for stabs with a name length of zero. */
1945 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1946 if (length
== sizeof lengthbuf
)
1949 val
= bfd_bread (strtbl
+ sizeof lengthbuf
, length
- sizeof lengthbuf
, abfd
);
1951 if (val
!= length
- sizeof lengthbuf
)
1952 error (_("cannot read string table from %s: %s"),
1953 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1954 if (strtbl
[length
- 1] != '\0')
1955 error (_("bad symbol file: string table "
1956 "does not end with null character"));
1961 /* If we have not yet seen a function for this psymtab, this is 0. If we
1962 have seen one, it is the offset in the line numbers of the line numbers
1964 static unsigned int first_fun_line_offset
;
1966 static struct partial_symtab
*xcoff_start_psymtab
1967 (struct objfile
*, char *, int,
1968 struct partial_symbol
**, struct partial_symbol
**);
1970 /* Allocate and partially fill a partial symtab. It will be
1971 completely filled at the end of the symbol list.
1973 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1974 is the address relative to which its symbols are (incremental) or 0
1977 static struct partial_symtab
*
1978 xcoff_start_psymtab (struct objfile
*objfile
, char *filename
, int first_symnum
,
1979 struct partial_symbol
**global_syms
,
1980 struct partial_symbol
**static_syms
)
1982 struct partial_symtab
*result
=
1983 start_psymtab_common (objfile
, objfile
->section_offsets
,
1985 /* We fill in textlow later. */
1987 global_syms
, static_syms
);
1989 result
->read_symtab_private
= obstack_alloc (&objfile
->objfile_obstack
,
1990 sizeof (struct symloc
));
1991 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
1992 result
->read_symtab
= xcoff_psymtab_to_symtab
;
1994 /* Deduce the source language from the filename for this psymtab. */
1995 psymtab_language
= deduce_language_from_filename (filename
);
2000 static struct partial_symtab
*xcoff_end_psymtab
2001 (struct partial_symtab
*, char **, int, int,
2002 struct partial_symtab
**, int, int);
2004 /* Close off the current usage of PST.
2005 Returns PST, or NULL if the partial symtab was empty and thrown away.
2007 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2009 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2010 are the information for includes and dependencies. */
2012 static struct partial_symtab
*
2013 xcoff_end_psymtab (struct partial_symtab
*pst
, char **include_list
,
2014 int num_includes
, int capping_symbol_number
,
2015 struct partial_symtab
**dependency_list
,
2016 int number_dependencies
, int textlow_not_set
)
2019 struct objfile
*objfile
= pst
->objfile
;
2021 if (capping_symbol_number
!= -1)
2022 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
2023 capping_symbol_number
2024 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
2025 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
2026 first_fun_line_offset
;
2027 first_fun_line_offset
= 0;
2028 pst
->n_global_syms
= objfile
->global_psymbols
.next
2029 - (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2030 pst
->n_static_syms
= objfile
->static_psymbols
.next
2031 - (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2033 pst
->number_of_dependencies
= number_dependencies
;
2034 if (number_dependencies
)
2036 pst
->dependencies
= (struct partial_symtab
**)
2037 obstack_alloc (&objfile
->objfile_obstack
,
2038 number_dependencies
* sizeof (struct partial_symtab
*));
2039 memcpy (pst
->dependencies
, dependency_list
,
2040 number_dependencies
* sizeof (struct partial_symtab
*));
2043 pst
->dependencies
= 0;
2045 for (i
= 0; i
< num_includes
; i
++)
2047 struct partial_symtab
*subpst
=
2048 allocate_psymtab (include_list
[i
], objfile
);
2050 subpst
->section_offsets
= pst
->section_offsets
;
2051 subpst
->read_symtab_private
= obstack_alloc (&objfile
->objfile_obstack
,
2052 sizeof (struct symloc
));
2053 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2054 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2055 subpst
->textlow
= 0;
2056 subpst
->texthigh
= 0;
2058 /* We could save slight bits of space by only making one of these,
2059 shared by the entire set of include files. FIXME-someday. */
2060 subpst
->dependencies
= (struct partial_symtab
**)
2061 obstack_alloc (&objfile
->objfile_obstack
,
2062 sizeof (struct partial_symtab
*));
2063 subpst
->dependencies
[0] = pst
;
2064 subpst
->number_of_dependencies
= 1;
2066 subpst
->globals_offset
=
2067 subpst
->n_global_syms
=
2068 subpst
->statics_offset
=
2069 subpst
->n_static_syms
= 0;
2073 subpst
->read_symtab
= pst
->read_symtab
;
2076 sort_pst_symbols (pst
);
2078 if (num_includes
== 0
2079 && number_dependencies
== 0
2080 && pst
->n_global_syms
== 0
2081 && pst
->n_static_syms
== 0)
2083 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2084 it is on the obstack, but we can forget to chain it on the list. */
2085 /* Empty psymtabs happen as a result of header files which don't have
2086 any symbols in them. There can be a lot of them. */
2088 discard_psymtab (pst
);
2090 /* Indicate that psymtab was thrown away. */
2091 pst
= (struct partial_symtab
*) NULL
;
2096 static void swap_sym (struct internal_syment
*,
2097 union internal_auxent
*, char **, char **,
2098 unsigned int *, struct objfile
*);
2100 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2101 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2102 the symbol and its auxents. */
2105 swap_sym (struct internal_syment
*symbol
, union internal_auxent
*aux
,
2106 char **name
, char **raw
, unsigned int *symnump
,
2107 struct objfile
*objfile
)
2109 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2110 if (symbol
->n_zeroes
)
2112 /* If it's exactly E_SYMNMLEN characters long it isn't
2114 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2116 /* FIXME: wastes memory for symbols which we don't end up putting
2117 into the minimal symbols. */
2120 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
2121 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2122 p
[E_SYMNMLEN
] = '\0';
2126 /* Point to the unswapped name as that persists as long as the
2128 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2130 else if (symbol
->n_sclass
& 0x80)
2132 *name
= ((struct coff_symfile_info
*)
2133 objfile
->deprecated_sym_private
)->debugsec
+ symbol
->n_offset
;
2137 *name
= ((struct coff_symfile_info
*)
2138 objfile
->deprecated_sym_private
)->strtbl
+ symbol
->n_offset
;
2141 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2142 if (symbol
->n_numaux
> 0)
2144 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2145 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2147 *symnump
+= symbol
->n_numaux
;
2148 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2153 function_outside_compilation_unit_complaint (const char *arg1
)
2155 complaint (&symfile_complaints
,
2156 _("function `%s' appears to be defined "
2157 "outside of all compilation units"),
2162 scan_xcoff_symtab (struct objfile
*objfile
)
2164 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2165 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2166 char *filestring
= NULL
;
2169 int past_first_source_file
= 0;
2174 /* Current partial symtab */
2175 struct partial_symtab
*pst
;
2177 /* List of current psymtab's include files. */
2178 char **psymtab_include_list
;
2179 int includes_allocated
;
2182 /* Index within current psymtab dependency list. */
2183 struct partial_symtab
**dependency_list
;
2184 int dependencies_used
, dependencies_allocated
;
2187 struct internal_syment symbol
;
2188 union internal_auxent main_aux
[5];
2189 unsigned int ssymnum
;
2191 char *last_csect_name
= NULL
; /* Last seen csect's name and value. */
2192 CORE_ADDR last_csect_val
= 0;
2193 int last_csect_sec
= 0;
2194 int misc_func_recorded
= 0; /* true if any misc. function. */
2195 int textlow_not_set
= 1;
2197 pst
= (struct partial_symtab
*) 0;
2199 includes_allocated
= 30;
2201 psymtab_include_list
= (char **) alloca (includes_allocated
*
2204 dependencies_allocated
= 30;
2205 dependencies_used
= 0;
2207 (struct partial_symtab
**) alloca (dependencies_allocated
*
2208 sizeof (struct partial_symtab
*));
2210 last_source_file
= NULL
;
2212 abfd
= objfile
->obfd
;
2213 next_symbol_text_func
= xcoff_next_symbol_text
;
2215 sraw_symbol
= ((struct coff_symfile_info
*)
2216 objfile
->deprecated_sym_private
)->symtbl
;
2217 nsyms
= ((struct coff_symfile_info
*)
2218 objfile
->deprecated_sym_private
)->symtbl_num_syms
;
2220 while (ssymnum
< nsyms
)
2226 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2227 sclass
= symbol
.n_sclass
;
2234 /* The CSECT auxent--always the last auxent. */
2235 union internal_auxent csect_aux
;
2236 unsigned int symnum_before
= ssymnum
;
2238 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2240 if (symbol
.n_numaux
> 1)
2242 bfd_coff_swap_aux_in
2244 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2247 symbol
.n_numaux
- 1,
2252 csect_aux
= main_aux
[0];
2254 /* If symbol name starts with ".$" or "$", ignore it. */
2255 if (namestring
[0] == '$'
2256 || (namestring
[0] == '.' && namestring
[1] == '$'))
2259 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2262 switch (csect_aux
.x_csect
.x_smclas
)
2265 if (last_csect_name
)
2267 /* If no misc. function recorded in the last
2268 seen csect, enter it as a function. This
2269 will take care of functions like strcmp()
2272 if (!misc_func_recorded
)
2274 RECORD_MINIMAL_SYMBOL
2275 (last_csect_name
, last_csect_val
,
2276 mst_text
, last_csect_sec
,
2282 /* We have to allocate one psymtab for
2283 each program csect, because their text
2284 sections need not be adjacent. */
2286 (pst
, psymtab_include_list
, includes_used
,
2287 symnum_before
, dependency_list
,
2288 dependencies_used
, textlow_not_set
);
2290 dependencies_used
= 0;
2291 /* Give all psymtabs for this source file the same
2293 pst
= xcoff_start_psymtab
2297 objfile
->global_psymbols
.next
,
2298 objfile
->static_psymbols
.next
);
2301 /* Activate the misc_func_recorded mechanism for
2302 compiler- and linker-generated CSECTs like ".strcmp"
2304 if (namestring
&& (namestring
[0] == '.'
2305 || namestring
[0] == '@'))
2307 last_csect_name
= namestring
;
2308 last_csect_val
= symbol
.n_value
;
2310 secnum_to_section (symbol
.n_scnum
, objfile
);
2315 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2317 if (highval
> pst
->texthigh
)
2318 pst
->texthigh
= highval
;
2319 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2320 pst
->textlow
= symbol
.n_value
;
2322 misc_func_recorded
= 0;
2327 /* Data variables are recorded in the minimal symbol
2328 table, except for section symbols. */
2329 if (*namestring
!= '.')
2330 prim_record_minimal_symbol_and_info
2331 (namestring
, symbol
.n_value
,
2332 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2333 secnum_to_section (symbol
.n_scnum
, objfile
),
2339 warning (_("More than one XMC_TC0 symbol found."));
2340 toc_offset
= symbol
.n_value
;
2342 /* Make TOC offset relative to start address of
2344 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2346 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2350 /* These symbols tell us where the TOC entry for a
2351 variable is, not the variable itself. */
2360 switch (csect_aux
.x_csect
.x_smclas
)
2363 /* A function entry point. */
2365 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2366 first_fun_line_offset
=
2367 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2368 RECORD_MINIMAL_SYMBOL
2369 (namestring
, symbol
.n_value
,
2370 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2371 secnum_to_section (symbol
.n_scnum
, objfile
),
2376 /* shared library function trampoline code entry
2379 /* record trampoline code entries as
2380 mst_solib_trampoline symbol. When we lookup mst
2381 symbols, we will choose mst_text over
2382 mst_solib_trampoline. */
2383 RECORD_MINIMAL_SYMBOL
2384 (namestring
, symbol
.n_value
,
2385 mst_solib_trampoline
,
2386 secnum_to_section (symbol
.n_scnum
, objfile
),
2391 /* The symbols often have the same names as
2392 debug symbols for functions, and confuse
2398 /* xlc puts each variable in a separate csect,
2399 so we get an XTY_SD for each variable. But
2400 gcc puts several variables in a csect, so
2401 that each variable only gets an XTY_LD. We
2402 still need to record them. This will
2403 typically be XMC_RW; I suspect XMC_RO and
2404 XMC_BS might be possible too. */
2405 if (*namestring
!= '.')
2406 prim_record_minimal_symbol_and_info
2407 (namestring
, symbol
.n_value
,
2408 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2409 secnum_to_section (symbol
.n_scnum
, objfile
),
2416 switch (csect_aux
.x_csect
.x_smclas
)
2420 /* Common variables are recorded in the minimal symbol
2421 table, except for section symbols. */
2422 if (*namestring
!= '.')
2423 prim_record_minimal_symbol_and_info
2424 (namestring
, symbol
.n_value
,
2425 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2426 secnum_to_section (symbol
.n_scnum
, objfile
),
2439 unsigned int symnum_before
;
2441 symnum_before
= ssymnum
;
2442 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2445 /* See if the last csect needs to be recorded. */
2447 if (last_csect_name
&& !misc_func_recorded
)
2449 /* If no misc. function recorded in the last seen csect, enter
2450 it as a function. This will take care of functions like
2451 strcmp() compiled by xlc. */
2453 RECORD_MINIMAL_SYMBOL
2454 (last_csect_name
, last_csect_val
,
2455 mst_text
, last_csect_sec
, objfile
);
2460 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2461 symnum_before
, dependency_list
,
2462 dependencies_used
, textlow_not_set
);
2464 dependencies_used
= 0;
2466 first_fun_line_offset
= 0;
2468 /* XCOFF, according to the AIX 3.2 documentation, puts the
2469 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2470 do things the standard COFF way and put it in the auxent.
2471 We use the auxent if the symbol is ".file" and an auxent
2472 exists, otherwise use the symbol itself. */
2473 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2475 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2478 filestring
= namestring
;
2480 pst
= xcoff_start_psymtab (objfile
,
2483 objfile
->global_psymbols
.next
,
2484 objfile
->static_psymbols
.next
);
2485 last_csect_name
= NULL
;
2491 complaint (&symfile_complaints
,
2492 _("Storage class %d not recognized during scan"),
2497 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2498 to handle only the C_FUN and C_EXT. */
2513 /* C_EINCL means we are switching back to the main file. But there
2514 is no reason to care; the only thing we want to know about
2515 includes is the names of all the included (.h) files. */
2520 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2524 /* I don't think the name of the common block (as opposed to the
2525 variables within it) is something which is user visible
2533 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2534 so C_LSYM would appear to be only for locals. */
2540 /* We probably could save a few instructions by assuming that
2541 C_LSYM, C_PSYM, etc., never have auxents. */
2542 int naux1
= symbol
.n_numaux
+ 1;
2545 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2551 /* Mark down an include file in the current psymtab. */
2552 enum language tmp_language
;
2554 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2557 tmp_language
= deduce_language_from_filename (namestring
);
2559 /* Only change the psymtab's language if we've learned
2560 something useful (eg. tmp_language is not language_unknown).
2561 In addition, to match what start_subfile does, never change
2563 if (tmp_language
!= language_unknown
2564 && (tmp_language
!= language_c
2565 || psymtab_language
!= language_cplus
))
2566 psymtab_language
= tmp_language
;
2568 /* In C++, one may expect the same filename to come round many
2569 times, when code is coming alternately from the main file
2570 and from inline functions in other files. So I check to see
2571 if this is a file we've seen before -- either the main
2572 source file, or a previously included file.
2574 This seems to be a lot of time to be spending on N_SOL, but
2575 things like "break c-exp.y:435" need to work (I
2576 suppose the psymtab_include_list could be hashed or put
2577 in a binary tree, if profiling shows this is a major hog). */
2578 if (pst
&& strcmp (namestring
, pst
->filename
) == 0)
2584 for (i
= 0; i
< includes_used
; i
++)
2585 if (strcmp (namestring
, psymtab_include_list
[i
]) == 0)
2593 psymtab_include_list
[includes_used
++] = namestring
;
2594 if (includes_used
>= includes_allocated
)
2596 char **orig
= psymtab_include_list
;
2598 psymtab_include_list
= (char **)
2599 alloca ((includes_allocated
*= 2) *
2601 memcpy (psymtab_include_list
, orig
,
2602 includes_used
* sizeof (char *));
2607 /* The value of the C_FUN is not the address of the function (it
2608 appears to be the address before linking), but as long as it
2609 is smaller than the actual address, then find_pc_partial_function
2610 will use the minimal symbols instead. I hope. */
2619 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2622 p
= (char *) strchr (namestring
, ':');
2624 continue; /* Not a debugging symbol. */
2626 /* Main processing section for debugging symbols which
2627 the initial read through the symbol tables needs to worry
2628 about. If we reach this point, the symbol which we are
2629 considering is definitely one we are interested in.
2630 p must also contain the (valid) index into the namestring
2631 which indicates the debugging type symbol. */
2636 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
,
2637 SECT_OFF_DATA (objfile
));
2639 if (gdbarch_static_transform_name_p (gdbarch
))
2640 namestring
= gdbarch_static_transform_name
2641 (gdbarch
, namestring
);
2643 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2644 VAR_DOMAIN
, LOC_STATIC
,
2645 &objfile
->static_psymbols
,
2647 psymtab_language
, objfile
);
2651 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
,
2652 SECT_OFF_DATA (objfile
));
2653 /* The addresses in these entries are reported to be
2654 wrong. See the code that reads 'G's for symtabs. */
2655 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2656 VAR_DOMAIN
, LOC_STATIC
,
2657 &objfile
->global_psymbols
,
2659 psymtab_language
, objfile
);
2663 /* When a 'T' entry is defining an anonymous enum, it
2664 may have a name which is the empty string, or a
2665 single space. Since they're not really defining a
2666 symbol, those shouldn't go in the partial symbol
2667 table. We do pick up the elements of such enums at
2668 'check_enum:', below. */
2669 if (p
>= namestring
+ 2
2670 || (p
== namestring
+ 1
2671 && namestring
[0] != ' '))
2673 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2674 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2675 &objfile
->static_psymbols
,
2677 psymtab_language
, objfile
);
2680 /* Also a typedef with the same name. */
2681 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2682 VAR_DOMAIN
, LOC_TYPEDEF
,
2683 &objfile
->static_psymbols
,
2685 psymtab_language
, objfile
);
2692 if (p
!= namestring
) /* a name is there, not just :T... */
2694 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2695 VAR_DOMAIN
, LOC_TYPEDEF
,
2696 &objfile
->static_psymbols
,
2698 psymtab_language
, objfile
);
2701 /* If this is an enumerated type, we need to
2702 add all the enum constants to the partial symbol
2703 table. This does not cover enums without names, e.g.
2704 "enum {a, b} c;" in C, but fortunately those are
2705 rare. There is no way for GDB to find those from the
2706 enum type without spending too much time on it. Thus
2707 to solve this problem, the compiler needs to put out the
2708 enum in a nameless type. GCC2 does this. */
2710 /* We are looking for something of the form
2711 <name> ":" ("t" | "T") [<number> "="] "e"
2712 {<constant> ":" <value> ","} ";". */
2714 /* Skip over the colon and the 't' or 'T'. */
2716 /* This type may be given a number. Also, numbers can come
2717 in pairs like (0,26). Skip over it. */
2718 while ((*p
>= '0' && *p
<= '9')
2719 || *p
== '(' || *p
== ',' || *p
== ')'
2725 /* The aix4 compiler emits extra crud before the
2729 /* Skip over the type (?). */
2733 /* Skip over the colon. */
2737 /* We have found an enumerated type. */
2738 /* According to comments in read_enum_type
2739 a comma could end it instead of a semicolon.
2740 I don't know where that happens.
2742 while (*p
&& *p
!= ';' && *p
!= ',')
2746 /* Check for and handle cretinous dbx symbol name
2748 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
2749 p
= next_symbol_text (objfile
);
2751 /* Point to the character after the name
2752 of the enum constant. */
2753 for (q
= p
; *q
&& *q
!= ':'; q
++)
2755 /* Note that the value doesn't matter for
2756 enum constants in psymtabs, just in symtabs. */
2757 add_psymbol_to_list (p
, q
- p
, 1,
2758 VAR_DOMAIN
, LOC_CONST
,
2759 &objfile
->static_psymbols
, 0,
2760 0, psymtab_language
, objfile
);
2761 /* Point past the name. */
2763 /* Skip over the value. */
2764 while (*p
&& *p
!= ',')
2766 /* Advance past the comma. */
2774 /* Constant, e.g. from "const" in Pascal. */
2775 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2776 VAR_DOMAIN
, LOC_CONST
,
2777 &objfile
->static_psymbols
, symbol
.n_value
,
2778 0, psymtab_language
, objfile
);
2784 int name_len
= p
- namestring
;
2785 char *name
= xmalloc (name_len
+ 1);
2787 memcpy (name
, namestring
, name_len
);
2788 name
[name_len
] = '\0';
2789 function_outside_compilation_unit_complaint (name
);
2792 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
,
2793 SECT_OFF_TEXT (objfile
));
2794 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2795 VAR_DOMAIN
, LOC_BLOCK
,
2796 &objfile
->static_psymbols
,
2798 psymtab_language
, objfile
);
2801 /* Global functions were ignored here, but now they
2802 are put into the global psymtab like one would expect.
2803 They're also in the minimal symbol table. */
2807 int name_len
= p
- namestring
;
2808 char *name
= xmalloc (name_len
+ 1);
2810 memcpy (name
, namestring
, name_len
);
2811 name
[name_len
] = '\0';
2812 function_outside_compilation_unit_complaint (name
);
2816 /* We need only the minimal symbols for these
2817 loader-generated definitions. Keeping the global
2818 symbols leads to "in psymbols but not in symbols"
2820 if (strncmp (namestring
, "@FIX", 4) == 0)
2823 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
,
2824 SECT_OFF_TEXT (objfile
));
2825 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2826 VAR_DOMAIN
, LOC_BLOCK
,
2827 &objfile
->global_psymbols
,
2829 psymtab_language
, objfile
);
2832 /* Two things show up here (hopefully); static symbols of
2833 local scope (static used inside braces) or extensions
2834 of structure symbols. We can ignore both. */
2848 case '#': /* For symbol identification (used in
2853 /* It is a C++ nested symbol. We don't need to record it
2854 (I don't think); if we try to look up foo::bar::baz,
2855 then symbols for the symtab containing foo should get
2856 read in, I think. */
2857 /* Someone says sun cc puts out symbols like
2858 /foo/baz/maclib::/usr/local/bin/maclib,
2859 which would get here with a symbol type of ':'. */
2863 /* Unexpected symbol descriptor. The second and
2864 subsequent stabs of a continued stab can show up
2865 here. The question is whether they ever can mimic
2866 a normal stab--it would be nice if not, since we
2867 certainly don't want to spend the time searching to
2868 the end of every string looking for a
2871 complaint (&symfile_complaints
,
2872 _("unknown symbol descriptor `%c'"), p
[1]);
2874 /* Ignore it; perhaps it is an extension that we don't
2884 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2885 ssymnum
, dependency_list
,
2886 dependencies_used
, textlow_not_set
);
2889 /* Record the toc offset value of this symbol table into objfile
2890 structure. If no XMC_TC0 is found, toc_offset should be zero.
2891 Another place to obtain this information would be file auxiliary
2894 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
2898 /* Return the toc offset value for a given objfile. */
2901 xcoff_get_toc_offset (struct objfile
*objfile
)
2904 return ((struct coff_symfile_info
*)
2905 objfile
->deprecated_sym_private
)->toc_offset
;
2909 /* Scan and build partial symbols for a symbol file.
2910 We have been initialized by a call to dbx_symfile_init, which
2911 put all the relevant info into a "struct dbx_symfile_info",
2912 hung off the objfile structure.
2914 SECTION_OFFSETS contains offsets relative to which the symbols in the
2915 various sections are (depending where the sections were actually
2919 xcoff_initial_scan (struct objfile
*objfile
, int symfile_flags
)
2923 struct cleanup
*back_to
;
2924 int num_symbols
; /* # of symbols */
2925 file_ptr symtab_offset
; /* symbol table and */
2926 file_ptr stringtab_offset
; /* string table file offsets */
2927 struct coff_symfile_info
*info
;
2931 info
= (struct coff_symfile_info
*) objfile
->deprecated_sym_private
;
2932 symfile_bfd
= abfd
= objfile
->obfd
;
2933 name
= objfile
->name
;
2935 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2936 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2937 stringtab_offset
= symtab_offset
+
2938 num_symbols
* coff_data (abfd
)->local_symesz
;
2940 info
->min_lineno_offset
= 0;
2941 info
->max_lineno_offset
= 0;
2942 bfd_map_over_sections (abfd
, find_linenos
, info
);
2944 if (num_symbols
> 0)
2946 /* Read the string table. */
2947 init_stringtab (abfd
, stringtab_offset
, objfile
);
2949 /* Read the .debug section, if present. */
2951 struct bfd_section
*secp
;
2952 bfd_size_type length
;
2953 char *debugsec
= NULL
;
2955 secp
= bfd_get_section_by_name (abfd
, ".debug");
2958 length
= bfd_section_size (abfd
, secp
);
2962 (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
2964 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2965 (file_ptr
) 0, length
))
2967 error (_("Error reading .debug section of `%s': %s"),
2968 name
, bfd_errmsg (bfd_get_error ()));
2972 ((struct coff_symfile_info
*)
2973 objfile
->deprecated_sym_private
)->debugsec
2978 /* Read the symbols. We keep them in core because we will want to
2979 access them randomly in read_symbol*. */
2980 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2982 error (_("Error reading symbols from %s: %s"),
2983 name
, bfd_errmsg (bfd_get_error ()));
2984 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2985 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
=
2986 obstack_alloc (&objfile
->objfile_obstack
, size
);
2987 ((struct coff_symfile_info
*)
2988 objfile
->deprecated_sym_private
)->symtbl_num_syms
2991 val
= bfd_bread (((struct coff_symfile_info
*)
2992 objfile
->deprecated_sym_private
)->symtbl
,
2995 perror_with_name (_("reading symbol table"));
2997 /* If we are reinitializing, or if we have never loaded syms yet, init. */
2998 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2999 /* I'm not sure how how good num_symbols is; the rule of thumb in
3000 init_psymbol_list was developed for a.out. On the one hand,
3001 num_symbols includes auxents. On the other hand, it doesn't
3003 init_psymbol_list (objfile
, num_symbols
);
3005 free_pending_blocks ();
3006 back_to
= make_cleanup (really_free_pendings
, 0);
3008 init_minimal_symbol_collection ();
3009 make_cleanup_discard_minimal_symbols ();
3011 /* Now that the symbol table data of the executable file are all in core,
3012 process them and define symbols accordingly. */
3014 scan_xcoff_symtab (objfile
);
3016 /* Install any minimal symbols that have been collected as the current
3017 minimal symbols for this objfile. */
3019 install_minimal_symbols (objfile
);
3021 do_cleanups (back_to
);
3025 xcoff_symfile_offsets (struct objfile
*objfile
,
3026 struct section_addr_info
*addrs
)
3028 asection
*sect
= NULL
;
3031 objfile
->num_sections
= bfd_count_sections (objfile
->obfd
);
3032 objfile
->section_offsets
= (struct section_offsets
*)
3033 obstack_alloc (&objfile
->objfile_obstack
,
3034 SIZEOF_N_SECTION_OFFSETS (objfile
->num_sections
));
3036 /* Initialize the section indexes for future use. */
3037 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
3039 objfile
->sect_index_text
= sect
->index
;
3041 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
3043 objfile
->sect_index_data
= sect
->index
;
3045 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
3047 objfile
->sect_index_bss
= sect
->index
;
3049 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
3051 objfile
->sect_index_rodata
= sect
->index
;
3053 for (i
= 0; i
< objfile
->num_sections
; ++i
)
3055 /* syms_from_objfile kindly subtracts from addr the
3056 bfd_section_vma of the .text section. This strikes me as
3057 wrong--whether the offset to be applied to symbol reading is
3058 relative to the start address of the section depends on the
3059 symbol format. In any event, this whole "addr" concept is
3060 pretty broken (it doesn't handle any section but .text
3061 sensibly), so just ignore the addr parameter and use 0.
3062 rs6000-nat.c will set the correct section offsets via
3063 objfile_relocate. */
3064 (objfile
->section_offsets
)->offsets
[i
] = 0;
3068 /* Register our ability to parse symbols for xcoff BFD files. */
3070 static const struct sym_fns xcoff_sym_fns
=
3073 /* It is possible that coff and xcoff should be merged as
3074 they do have fundamental similarities (for example, the extra storage
3075 classes used for stabs could presumably be recognized in any COFF file).
3076 However, in addition to obvious things like all the csect hair, there are
3077 some subtler differences between xcoffread.c and coffread.c, notably
3078 the fact that coffread.c has no need to read in all the symbols, but
3079 xcoffread.c reads all the symbols and does in fact randomly access them
3080 (in C_BSTAT and line number processing). */
3082 bfd_target_xcoff_flavour
,
3084 xcoff_new_init
, /* init anything gbl to entire symtab */
3085 xcoff_symfile_init
, /* read initial info, setup for sym_read() */
3086 xcoff_initial_scan
, /* read a symbol file into symtab */
3087 NULL
, /* sym_read_psymbols */
3088 xcoff_symfile_finish
, /* finished with file, cleanup */
3089 xcoff_symfile_offsets
, /* xlate offsets ext->int form */
3090 default_symfile_segments
, /* Get segment information from a file. */
3091 aix_process_linenos
,
3092 default_symfile_relocate
, /* Relocate a debug section. */
3096 /* Provide a prototype to silence -Wmissing-prototypes. */
3097 extern initialize_file_ftype _initialize_xcoffread
;
3100 _initialize_xcoffread (void)
3102 add_symtab_fns (&xcoff_sym_fns
);