1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
5 Derived from coffread.c, dbxread.c, and a lot of hacking.
6 Contributed by IBM Corporation.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include <sys/types.h>
29 #include "gdb_string.h"
31 #include <sys/param.h>
32 #ifdef HAVE_SYS_FILE_H
37 #include "coff/internal.h"
38 #include "libcoff.h" /* FIXME, internal data from BFD */
39 #include "coff/xcoff.h"
41 #include "coff/rs6000.h"
42 #include "xcoffread.h"
46 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */
50 #include "stabsread.h"
51 #include "expression.h"
52 #include "complaints.h"
55 #include "gdb-stabs.h"
57 /* For interface with stabsread.c. */
58 #include "aout/stab_gnu.h"
61 /* We put a pointer to this structure in the read_symtab_private field
67 /* First symbol number for this file. */
71 /* Number of symbols in the section of the symbol table devoted to
72 this file's symbols (actually, the section bracketed may contain
73 more than just this file's symbols). If numsyms is 0, the only
74 reason for this thing's existence is the dependency list. Nothing
75 else will happen when it is read in. */
79 /* Position of the start of the line number information for this psymtab. */
80 unsigned int lineno_off
;
83 /* Remember what we deduced to be the source language of this psymtab. */
85 static enum language psymtab_language
= language_unknown
;
88 /* Simplified internal version of coff symbol table information */
93 int c_symnum
; /* symbol number of this entry */
94 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
96 unsigned char c_sclass
;
101 /* last function's saved coff symbol `cs' */
103 static struct coff_symbol fcn_cs_saved
;
105 static bfd
*symfile_bfd
;
107 /* Core address of start and end of text of current source file.
108 This is calculated from the first function seen after a C_FILE
112 static CORE_ADDR cur_src_end_addr
;
114 /* Core address of the end of the first object file. */
116 static CORE_ADDR first_object_file_end
;
118 /* initial symbol-table-debug-string vector length */
120 #define INITIAL_STABVECTOR_LENGTH 40
122 /* Nonzero if within a function (so symbols should be local,
123 if nothing says specifically). */
127 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
128 there is any reason not to just use a #define, but might as well
129 ask BFD for the size and store it here, I guess. */
131 static unsigned local_symesz
;
133 struct coff_symfile_info
135 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
136 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
138 /* Pointer to the string table. */
141 /* Pointer to debug section. */
144 /* Pointer to the a.out symbol table. */
147 /* Number of symbols in symtbl. */
150 /* Offset in data section to TOC anchor. */
151 CORE_ADDR toc_offset
;
155 bf_notfound_complaint (void)
157 complaint (&symfile_complaints
, _("line numbers off, `.bf' symbol not found"));
161 ef_complaint (int arg1
)
163 complaint (&symfile_complaints
,
164 _("Mismatched .ef symbol ignored starting at symnum %d"), arg1
);
168 eb_complaint (int arg1
)
170 complaint (&symfile_complaints
,
171 _("Mismatched .eb symbol ignored starting at symnum %d"), arg1
);
174 static void xcoff_initial_scan (struct objfile
*, int);
176 static void scan_xcoff_symtab (struct objfile
*);
178 static char *xcoff_next_symbol_text (struct objfile
*);
180 static void record_include_begin (struct coff_symbol
*);
183 enter_line_range (struct subfile
*, unsigned, unsigned,
184 CORE_ADDR
, CORE_ADDR
, unsigned *);
186 static void init_stringtab (bfd
*, file_ptr
, struct objfile
*);
188 static void xcoff_symfile_init (struct objfile
*);
190 static void xcoff_new_init (struct objfile
*);
192 static void xcoff_symfile_finish (struct objfile
*);
194 static void xcoff_symfile_offsets (struct objfile
*,
195 struct section_addr_info
*addrs
);
197 static char *coff_getfilename (union internal_auxent
*, struct objfile
*);
199 static void read_symbol (struct internal_syment
*, int);
201 static int read_symbol_lineno (int);
203 static CORE_ADDR
read_symbol_nvalue (int);
205 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
208 static void read_xcoff_symtab (struct partial_symtab
*);
211 static void add_stab_to_list (char *, struct pending_stabs
**);
214 static int compare_lte (const void *, const void *);
216 static struct linetable
*arrange_linetable (struct linetable
*);
218 static void record_include_end (struct coff_symbol
*);
220 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
223 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
225 static int secnum_to_section (int, struct objfile
*);
226 static asection
*secnum_to_bfd_section (int, struct objfile
*);
228 struct find_targ_sec_arg
233 struct objfile
*objfile
;
236 static void find_targ_sec (bfd
*, asection
*, void *);
239 find_targ_sec (bfd
*abfd
, asection
*sect
, void *obj
)
241 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
242 struct objfile
*objfile
= args
->objfile
;
243 if (sect
->target_index
== args
->targ_index
)
245 /* This is the section. Figure out what SECT_OFF_* code it is. */
246 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
247 *args
->resultp
= SECT_OFF_TEXT (objfile
);
248 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
249 *args
->resultp
= SECT_OFF_DATA (objfile
);
251 *args
->resultp
= sect
->index
;
252 *args
->bfd_sect
= sect
;
256 /* Return the section number (SECT_OFF_*) that CS points to. */
258 secnum_to_section (int secnum
, struct objfile
*objfile
)
260 int off
= SECT_OFF_TEXT (objfile
);
261 asection
*sect
= NULL
;
262 struct find_targ_sec_arg args
;
263 args
.targ_index
= secnum
;
265 args
.bfd_sect
= §
;
266 args
.objfile
= objfile
;
267 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
271 /* Return the BFD section that CS points to. */
273 secnum_to_bfd_section (int secnum
, struct objfile
*objfile
)
275 int off
= SECT_OFF_TEXT (objfile
);
276 asection
*sect
= NULL
;
277 struct find_targ_sec_arg args
;
278 args
.targ_index
= secnum
;
280 args
.bfd_sect
= §
;
281 args
.objfile
= objfile
;
282 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
286 /* add a given stab string into given stab vector. */
291 add_stab_to_list (char *stabname
, struct pending_stabs
**stabvector
)
293 if (*stabvector
== NULL
)
295 *stabvector
= (struct pending_stabs
*)
296 xmalloc (sizeof (struct pending_stabs
) +
297 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
298 (*stabvector
)->count
= 0;
299 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
301 else if ((*stabvector
)->count
>= (*stabvector
)->length
)
303 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
304 *stabvector
= (struct pending_stabs
*)
305 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
306 (*stabvector
)->length
* sizeof (char *));
308 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
313 /* Linenos are processed on a file-by-file basis.
317 1) xlc (IBM's native c compiler) postpones static function code
318 emission to the end of a compilation unit. This way it can
319 determine if those functions (statics) are needed or not, and
320 can do some garbage collection (I think). This makes line
321 numbers and corresponding addresses unordered, and we end up
322 with a line table like:
339 and that breaks gdb's binary search on line numbers, if the
340 above table is not sorted on line numbers. And that sort
341 should be on function based, since gcc can emit line numbers
344 10 0x100 - for the init/test part of a for stmt.
347 10 0x400 - for the increment part of a for stmt.
349 arrange_linetable() will do this sorting.
351 2) aix symbol table might look like:
353 c_file // beginning of a new file
354 .bi // beginning of include file
355 .ei // end of include file
359 basically, .bi/.ei pairs do not necessarily encapsulate
360 their scope. They need to be recorded, and processed later
361 on when we come the end of the compilation unit.
362 Include table (inclTable) and process_linenos() handle
368 /* compare line table entry addresses. */
371 compare_lte (const void *lte1p
, const void *lte2p
)
373 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
374 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
375 return lte1
->pc
- lte2
->pc
;
378 /* Given a line table with function entries are marked, arrange its functions
379 in ascending order and strip off function entry markers and return it in
380 a newly created table. If the old one is good enough, return the old one. */
381 /* FIXME: I think all this stuff can be replaced by just passing
382 sort_linevec = 1 to end_symtab. */
384 static struct linetable
*
385 arrange_linetable (struct linetable
*oldLineTb
)
387 int ii
, jj
, newline
, /* new line count */
388 function_count
; /* # of functions */
390 struct linetable_entry
*fentry
; /* function entry vector */
391 int fentry_size
; /* # of function entries */
392 struct linetable
*newLineTb
; /* new line table */
394 #define NUM_OF_FUNCTIONS 20
396 fentry_size
= NUM_OF_FUNCTIONS
;
397 fentry
= (struct linetable_entry
*)
398 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
400 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
403 if (oldLineTb
->item
[ii
].line
== 0)
404 { /* function entry found. */
406 if (function_count
>= fentry_size
)
407 { /* make sure you have room. */
409 fentry
= (struct linetable_entry
*)
410 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
412 fentry
[function_count
].line
= ii
;
413 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
418 if (function_count
== 0)
423 else if (function_count
> 1)
424 qsort (fentry
, function_count
, sizeof (struct linetable_entry
), compare_lte
);
426 /* allocate a new line table. */
427 newLineTb
= (struct linetable
*)
429 (sizeof (struct linetable
) +
430 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
432 /* if line table does not start with a function beginning, copy up until
436 if (oldLineTb
->item
[0].line
!= 0)
438 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
439 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
441 /* Now copy function lines one by one. */
443 for (ii
= 0; ii
< function_count
; ++ii
)
445 for (jj
= fentry
[ii
].line
+ 1;
446 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
448 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
451 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
455 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
456 following `IncludeChain'. At the end of each symtab (end_symtab),
457 we will determine if we should create additional symtab's to
458 represent if (the include files. */
461 typedef struct _inclTable
463 char *name
; /* include filename */
465 /* Offsets to the line table. end points to the last entry which is
466 part of this include file. */
469 struct subfile
*subfile
;
470 unsigned funStartLine
; /* start line # of its function */
474 #define INITIAL_INCLUDE_TABLE_LENGTH 20
475 static InclTable
*inclTable
; /* global include table */
476 static int inclIndx
; /* last entry to table */
477 static int inclLength
; /* table length */
478 static int inclDepth
; /* nested include depth */
480 static void allocate_include_entry (void);
483 record_include_begin (struct coff_symbol
*cs
)
487 /* In xcoff, we assume include files cannot be nested (not in .c files
488 of course, but in corresponding .s files.). */
490 /* This can happen with old versions of GCC.
491 GCC 2.3.3-930426 does not exhibit this on a test case which
492 a user said produced the message for him. */
493 complaint (&symfile_complaints
, _("Nested C_BINCL symbols"));
497 allocate_include_entry ();
499 inclTable
[inclIndx
].name
= cs
->c_name
;
500 inclTable
[inclIndx
].begin
= cs
->c_value
;
504 record_include_end (struct coff_symbol
*cs
)
510 complaint (&symfile_complaints
, _("Mismatched C_BINCL/C_EINCL pair"));
513 allocate_include_entry ();
515 pTbl
= &inclTable
[inclIndx
];
516 pTbl
->end
= cs
->c_value
;
523 allocate_include_entry (void)
525 if (inclTable
== NULL
)
527 inclTable
= (InclTable
*)
528 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
530 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
531 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
534 else if (inclIndx
>= inclLength
)
536 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
537 inclTable
= (InclTable
*)
538 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
539 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
540 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
544 /* Global variable to pass the psymtab down to all the routines involved
545 in psymtab to symtab processing. */
546 static struct partial_symtab
*this_symtab_psymtab
;
548 /* given the start and end addresses of a compilation unit (or a csect,
549 at times) process its lines and create appropriate line vectors. */
552 process_linenos (CORE_ADDR start
, CORE_ADDR end
)
555 file_ptr max_offset
=
556 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)
559 /* subfile structure for the main compilation unit. */
560 struct subfile main_subfile
;
562 /* In the main source file, any time we see a function entry, we
563 reset this variable to function's absolute starting line number.
564 All the following line numbers in the function are relative to
565 this, and we record absolute line numbers in record_line(). */
567 unsigned int main_source_baseline
= 0;
572 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
574 goto return_after_cleanup
;
576 memset (&main_subfile
, '\0', sizeof (main_subfile
));
579 /* All source lines were in the main source file. None in include files. */
581 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
582 &main_source_baseline
);
586 /* There was source with line numbers in include files. */
589 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
590 main_source_baseline
= 0;
592 for (ii
= 0; ii
< inclIndx
; ++ii
)
594 struct subfile
*tmpSubfile
;
596 /* If there is main file source before include file, enter it. */
597 if (offset
< inclTable
[ii
].begin
)
600 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
601 start
, 0, &main_source_baseline
);
604 if (strcmp (inclTable
[ii
].name
, last_source_file
) == 0)
606 /* The entry in the include table refers to the main source
607 file. Add the lines to the main subfile. */
609 main_source_baseline
= inclTable
[ii
].funStartLine
;
611 (&main_subfile
, inclTable
[ii
].begin
, inclTable
[ii
].end
,
612 start
, 0, &main_source_baseline
);
613 inclTable
[ii
].subfile
= &main_subfile
;
618 /* Have a new subfile for the include file. */
620 tmpSubfile
= inclTable
[ii
].subfile
=
621 (struct subfile
*) xmalloc (sizeof (struct subfile
));
623 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
624 firstLine
= &(inclTable
[ii
].funStartLine
);
626 /* Enter include file's lines now. */
627 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
628 inclTable
[ii
].end
, start
, 0, firstLine
);
631 if (offset
<= inclTable
[ii
].end
)
632 offset
= inclTable
[ii
].end
+ linesz
;
635 /* All the include files' line have been processed at this point. Now,
636 enter remaining lines of the main file, if any left. */
637 if (offset
< max_offset
+ 1 - linesz
)
639 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
640 &main_source_baseline
);
644 /* Process main file's line numbers. */
645 if (main_subfile
.line_vector
)
647 struct linetable
*lineTb
, *lv
;
649 lv
= main_subfile
.line_vector
;
651 /* Line numbers are not necessarily ordered. xlc compilation will
652 put static function to the end. */
654 lineTb
= arrange_linetable (lv
);
657 current_subfile
->line_vector
= (struct linetable
*)
658 xrealloc (lv
, (sizeof (struct linetable
)
659 + lv
->nitems
* sizeof (struct linetable_entry
)));
664 current_subfile
->line_vector
= lineTb
;
667 current_subfile
->line_vector_length
=
668 current_subfile
->line_vector
->nitems
;
671 /* Now, process included files' line numbers. */
673 for (ii
= 0; ii
< inclIndx
; ++ii
)
675 if (inclTable
[ii
].subfile
!= ((struct subfile
*) &main_subfile
)
676 && (inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
678 struct linetable
*lineTb
, *lv
;
680 lv
= (inclTable
[ii
].subfile
)->line_vector
;
682 /* Line numbers are not necessarily ordered. xlc compilation will
683 put static function to the end. */
685 lineTb
= arrange_linetable (lv
);
689 /* For the same include file, we might want to have more than one
690 subfile. This happens if we have something like:
698 while foo.h including code in it. (stupid but possible)
699 Since start_subfile() looks at the name and uses an
700 existing one if finds, we need to provide a fake name and
704 start_subfile (inclTable
[ii
].name
, (char *) 0);
707 /* Pick a fake name that will produce the same results as this
708 one when passed to deduce_language_from_filename. Kludge on
710 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
711 if (fakename
== NULL
)
713 start_subfile (fakename
, (char *) 0);
714 xfree (current_subfile
->name
);
716 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
721 current_subfile
->line_vector
=
722 (struct linetable
*) xrealloc
723 (lv
, (sizeof (struct linetable
)
724 + lv
->nitems
* sizeof (struct linetable_entry
)));
730 current_subfile
->line_vector
= lineTb
;
733 current_subfile
->line_vector_length
=
734 current_subfile
->line_vector
->nitems
;
735 start_subfile (pop_subfile (), (char *) 0);
739 return_after_cleanup
:
741 /* We don't want to keep alloc/free'ing the global include file table. */
744 /* Start with a fresh subfile structure for the next file. */
745 memset (&main_subfile
, '\0', sizeof (struct subfile
));
749 aix_process_linenos (void)
751 /* process line numbers and enter them into line vector */
752 process_linenos (last_source_start_addr
, cur_src_end_addr
);
756 /* Enter a given range of lines into the line vector.
757 can be called in the following two ways:
758 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
759 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
761 endoffset points to the last line table entry that we should pay
765 enter_line_range (struct subfile
*subfile
, unsigned beginoffset
, unsigned endoffset
, /* offsets to line table */
766 CORE_ADDR startaddr
, /* offsets to line table */
767 CORE_ADDR endaddr
, unsigned *firstLine
)
769 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
770 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
771 unsigned int curoffset
;
774 struct internal_lineno int_lnno
;
775 unsigned int limit_offset
;
779 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
781 curoffset
= beginoffset
;
783 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)
788 if (endoffset
>= limit_offset
)
790 complaint (&symfile_complaints
,
791 _("Bad line table offset in C_EINCL directive"));
794 limit_offset
= endoffset
;
799 abfd
= objfile
->obfd
;
800 linesz
= coff_data (abfd
)->local_linesz
;
801 ext_lnno
= alloca (linesz
);
803 while (curoffset
<= limit_offset
)
805 bfd_seek (abfd
, curoffset
, SEEK_SET
);
806 bfd_bread (ext_lnno
, linesz
, abfd
);
807 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
809 /* Find the address this line represents. */
810 addr
= (int_lnno
.l_lnno
811 ? int_lnno
.l_addr
.l_paddr
812 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
813 addr
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
815 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
818 if (int_lnno
.l_lnno
== 0)
820 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
821 record_line (subfile
, 0, gdbarch_addr_bits_remove (gdbarch
, addr
));
825 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
,
826 gdbarch_addr_bits_remove (gdbarch
, addr
));
832 /* Save the vital information for use when closing off the current file.
833 NAME is the file name the symbols came from, START_ADDR is the first
834 text address for the file, and SIZE is the number of bytes of text. */
836 #define complete_symtab(name, start_addr) { \
837 last_source_file = xstrdup (name); \
838 last_source_start_addr = start_addr; \
842 /* Refill the symbol table input buffer
843 and set the variables that control fetching entries from it.
844 Reports an error if no data available.
845 This function can read past the end of the symbol table
846 (into the string table) but this does no harm. */
848 /* Reading symbol table has to be fast! Keep the followings as macros, rather
851 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
855 if (namestr[0] == '.') ++namestr; \
856 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
857 (SECTION), (asection *)NULL, (OBJFILE)); \
858 misc_func_recorded = 1; \
862 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
863 nested. At any given time, a symbol can only be in one static block.
864 This is the base address of current static block, zero if non exists. */
866 static int static_block_base
= 0;
868 /* Section number for the current static block. */
870 static int static_block_section
= -1;
872 /* true if space for symbol name has been allocated. */
874 static int symname_alloced
= 0;
876 /* Next symbol to read. Pointer into raw seething symbol table. */
878 static char *raw_symbol
;
880 /* This is the function which stabsread.c calls to get symbol
884 xcoff_next_symbol_text (struct objfile
*objfile
)
886 struct internal_syment symbol
;
888 /* FIXME: is this the same as the passed arg? */
889 if (this_symtab_psymtab
)
890 objfile
= this_symtab_psymtab
->objfile
;
892 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
895 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
897 /* Return something which points to '\0' and hope the symbol reading
898 code does something reasonable. */
901 else if (symbol
.n_sclass
& 0x80)
904 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
907 coff_data (objfile
->obfd
)->local_symesz
;
912 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
914 /* Return something which points to '\0' and hope the symbol reading
915 code does something reasonable. */
921 /* Read symbols for a given partial symbol table. */
924 read_xcoff_symtab (struct partial_symtab
*pst
)
926 struct objfile
*objfile
= pst
->objfile
;
927 bfd
*abfd
= objfile
->obfd
;
928 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
929 char *strtbl
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
;
931 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
;
932 char *debugfmt
= bfd_xcoff_is_xcoff64 (abfd
) ? "XCOFF64" : "XCOFF";
934 struct internal_syment symbol
[1];
935 union internal_auxent main_aux
;
936 struct coff_symbol cs
[1];
937 CORE_ADDR file_start_addr
= 0;
938 CORE_ADDR file_end_addr
= 0;
940 int next_file_symnum
= -1;
941 unsigned int max_symnum
;
942 int just_started
= 1;
944 int fcn_start_addr
= 0;
946 struct coff_symbol fcn_stab_saved
= { 0 };
948 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
949 union internal_auxent fcn_aux_saved
;
950 struct context_stack
*new;
952 char *filestring
= " _start_ "; /* Name of the current file. */
954 char *last_csect_name
; /* last seen csect's name and value */
955 CORE_ADDR last_csect_val
;
958 this_symtab_psymtab
= pst
;
960 /* Get the appropriate COFF "constants" related to the file we're
962 local_symesz
= coff_data (abfd
)->local_symesz
;
964 last_source_file
= NULL
;
969 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
970 record_debugformat (debugfmt
);
971 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
973 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
974 first_object_file_end
= 0;
977 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
978 + symnum
* local_symesz
;
980 while (symnum
< max_symnum
)
983 QUIT
; /* make this command interruptable. */
985 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
986 /* read one symbol into `cs' structure. After processing the
987 whole symbol table, only string table will be kept in memory,
988 symbol table and debug section of xcoff will be freed. Thus
989 we can mark symbols with names in string table as
994 /* Swap and align the symbol into a reasonable C structure. */
995 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
997 cs
->c_symnum
= symnum
;
998 cs
->c_naux
= symbol
->n_numaux
;
999 if (symbol
->n_zeroes
)
1001 symname_alloced
= 0;
1002 /* We must use the original, unswapped, name here so the name field
1003 pointed to by cs->c_name will persist throughout xcoffread. If
1004 we use the new field, it gets overwritten for each symbol. */
1005 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
1006 /* If it's exactly E_SYMNMLEN characters long it isn't
1008 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1011 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
1012 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1013 p
[E_SYMNMLEN
] = '\0';
1015 symname_alloced
= 1;
1018 else if (symbol
->n_sclass
& 0x80)
1020 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1021 symname_alloced
= 0;
1025 /* in string table */
1026 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1027 symname_alloced
= 1;
1029 cs
->c_value
= symbol
->n_value
;
1030 cs
->c_sclass
= symbol
->n_sclass
;
1031 cs
->c_secnum
= symbol
->n_scnum
;
1032 cs
->c_type
= (unsigned) symbol
->n_type
;
1034 raw_symbol
+= local_symesz
;
1037 /* Save addr of first aux entry. */
1038 raw_auxptr
= raw_symbol
;
1040 /* Skip all the auxents associated with this symbol. */
1041 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1043 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1048 /* if symbol name starts with ".$" or "$", ignore it. */
1049 if (cs
->c_name
[0] == '$'
1050 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1053 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1055 if (last_source_file
)
1058 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1063 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1064 record_debugformat (debugfmt
);
1065 cur_src_end_addr
= first_object_file_end
;
1066 /* done with all files, everything from here on is globals */
1069 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1072 /* Dealing with a symbol with a csect entry. */
1074 #define CSECT(PP) ((PP)->x_csect)
1075 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1076 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1077 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1078 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1080 /* Convert the auxent to something we can access. */
1081 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1082 0, cs
->c_naux
, &main_aux
);
1084 switch (CSECT_SMTYP (&main_aux
))
1088 /* Ignore all external references. */
1092 /* A section description. */
1094 switch (CSECT_SCLAS (&main_aux
))
1100 /* A program csect is seen. We have to allocate one
1101 symbol table for each program csect. Normally gdb
1102 prefers one symtab for each source file. In case
1103 of AIX, one source file might include more than one
1104 [PR] csect, and they don't have to be adjacent in
1105 terms of the space they occupy in memory. Thus, one
1106 single source file might get fragmented in the
1107 memory and gdb's file start and end address
1108 approach does not work! GCC (and I think xlc) seem
1109 to put all the code in the unnamed program csect. */
1111 if (last_csect_name
)
1113 complete_symtab (filestring
, file_start_addr
);
1114 cur_src_end_addr
= file_end_addr
;
1115 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1118 /* Give all csects for this source file the same
1120 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1121 record_debugformat (debugfmt
);
1124 /* If this is the very first csect seen,
1125 basically `__start'. */
1128 first_object_file_end
1129 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1134 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1135 SECT_OFF_TEXT (objfile
));
1136 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1138 if (cs
->c_name
&& (cs
->c_name
[0] == '.'
1139 || cs
->c_name
[0] == '@'))
1141 last_csect_name
= cs
->c_name
;
1142 last_csect_val
= cs
->c_value
;
1143 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1148 /* All other symbols are put into the minimal symbol
1161 /* Ignore the symbol. */
1169 switch (CSECT_SCLAS (&main_aux
))
1172 /* a function entry point. */
1173 function_entry_point
:
1175 fcn_start_addr
= cs
->c_value
;
1177 /* save the function header info, which will be used
1178 when `.bf' is seen. */
1180 fcn_aux_saved
= main_aux
;
1184 /* shared library function trampoline code entry point. */
1188 /* The symbols often have the same names as debug symbols for
1189 functions, and confuse lookup_symbol. */
1193 /* xlc puts each variable in a separate csect, so we get
1194 an XTY_SD for each variable. But gcc puts several
1195 variables in a csect, so that each variable only gets
1196 an XTY_LD. This will typically be XMC_RW; I suspect
1197 XMC_RO and XMC_BS might be possible too.
1198 These variables are put in the minimal symbol table
1205 /* Common symbols are put into the minimal symbol table only. */
1213 /* If explicitly specified as a function, treat is as one. This check
1214 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1215 after the above CSECT check. */
1216 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1218 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1219 0, cs
->c_naux
, &main_aux
);
1220 goto function_entry_point
;
1223 switch (cs
->c_sclass
)
1228 /* c_value field contains symnum of next .file entry in table
1229 or symnum of first global after last .file. */
1231 next_file_symnum
= cs
->c_value
;
1233 /* Complete symbol table for last object file containing
1234 debugging information. */
1236 /* Whether or not there was a csect in the previous file, we
1237 have to call `end_stabs' and `start_stabs' to reset
1238 type_vector, line_vector, etc. structures. */
1240 complete_symtab (filestring
, file_start_addr
);
1241 cur_src_end_addr
= file_end_addr
;
1242 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1245 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1246 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1247 standard COFF way and put it in the auxent. We use the auxent if
1248 the symbol is ".file" and an auxent exists, otherwise use the symbol
1249 itself. Simple enough. */
1250 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1252 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1253 0, cs
->c_naux
, &main_aux
);
1254 filestring
= coff_getfilename (&main_aux
, objfile
);
1257 filestring
= cs
->c_name
;
1260 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1261 record_debugformat (debugfmt
);
1262 last_csect_name
= 0;
1264 /* reset file start and end addresses. A compilation unit with no text
1265 (only data) should have zero file boundaries. */
1266 file_start_addr
= file_end_addr
= 0;
1270 fcn_stab_saved
= *cs
;
1274 if (strcmp (cs
->c_name
, ".bf") == 0)
1276 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1277 SECT_OFF_TEXT (objfile
));
1278 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1279 0, cs
->c_naux
, &main_aux
);
1281 within_function
= 1;
1283 new = push_context (0, fcn_start_addr
+ off
);
1285 new->name
= define_symbol
1286 (fcn_cs_saved
.c_value
+ off
,
1287 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1288 if (new->name
!= NULL
)
1289 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1291 else if (strcmp (cs
->c_name
, ".ef") == 0)
1294 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1295 0, cs
->c_naux
, &main_aux
);
1297 /* The value of .ef is the address of epilogue code;
1298 not useful for gdb. */
1299 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1300 contains number of lines to '}' */
1302 if (context_stack_depth
<= 0)
1303 { /* We attempted to pop an empty context stack */
1304 ef_complaint (cs
->c_symnum
);
1305 within_function
= 0;
1308 new = pop_context ();
1309 /* Stack must be empty now. */
1310 if (context_stack_depth
> 0 || new == NULL
)
1312 ef_complaint (cs
->c_symnum
);
1313 within_function
= 0;
1317 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1319 (fcn_cs_saved
.c_value
1320 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1321 + ANOFFSET (objfile
->section_offsets
,
1322 SECT_OFF_TEXT (objfile
))),
1324 within_function
= 0;
1329 /* Begin static block. */
1331 struct internal_syment symbol
;
1333 read_symbol (&symbol
, cs
->c_value
);
1334 static_block_base
= symbol
.n_value
;
1335 static_block_section
=
1336 secnum_to_section (symbol
.n_scnum
, objfile
);
1341 /* End of static block. */
1342 static_block_base
= 0;
1343 static_block_section
= -1;
1354 complaint (&symfile_complaints
, _("Unrecognized storage class %d."),
1369 /* beginning of include file */
1370 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1371 order. Thus, when wee see them, we might not know enough info
1372 to process them. Thus, we'll be saving them into a table
1373 (inclTable) and postpone their processing. */
1375 record_include_begin (cs
);
1379 /* End of include file. */
1380 /* See the comment after case C_BINCL. */
1381 record_include_end (cs
);
1385 if (strcmp (cs
->c_name
, ".bb") == 0)
1388 new = push_context (depth
,
1390 + ANOFFSET (objfile
->section_offsets
,
1391 SECT_OFF_TEXT (objfile
))));
1393 else if (strcmp (cs
->c_name
, ".eb") == 0)
1395 if (context_stack_depth
<= 0)
1396 { /* We attempted to pop an empty context stack */
1397 eb_complaint (cs
->c_symnum
);
1400 new = pop_context ();
1401 if (depth
-- != new->depth
)
1403 eb_complaint (cs
->c_symnum
);
1406 if (local_symbols
&& context_stack_depth
> 0)
1408 /* Make a block for the local symbols within. */
1409 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1412 + ANOFFSET (objfile
->section_offsets
,
1413 SECT_OFF_TEXT (objfile
))),
1416 local_symbols
= new->locals
;
1421 process_xcoff_symbol (cs
, objfile
);
1426 if (last_source_file
)
1430 complete_symtab (filestring
, file_start_addr
);
1431 cur_src_end_addr
= file_end_addr
;
1432 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1433 /* When reading symbols for the last C_FILE of the objfile, try
1434 to make sure that we set pst->symtab to the symtab for the
1435 file, not to the _globals_ symtab. I'm not sure whether this
1436 actually works right or when/if it comes up. */
1437 if (pst
->symtab
== NULL
)
1443 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1444 (SYMBOL2) = (struct symbol *) \
1445 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1446 *(SYMBOL2) = *(SYMBOL1);
1449 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1450 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->objfile_obstack))
1453 /* process one xcoff symbol. */
1455 static struct symbol
*
1456 process_xcoff_symbol (struct coff_symbol
*cs
, struct objfile
*objfile
)
1458 struct symbol onesymbol
;
1459 struct symbol
*sym
= &onesymbol
;
1460 struct symbol
*sym2
= NULL
;
1466 if (cs
->c_secnum
< 0)
1468 /* The value is a register number, offset within a frame, etc.,
1469 and does not get relocated. */
1475 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1476 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1483 memset (sym
, '\0', sizeof (struct symbol
));
1485 /* default assumptions */
1486 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1487 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1488 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1490 if (ISFCN (cs
->c_type
))
1492 /* At this point, we don't know the type of the function. This
1493 will be patched with the type from its stab entry later on in
1494 patch_block_stabs (), unless the file was compiled without -g. */
1496 SYMBOL_SET_LINKAGE_NAME (sym
, SYMNAME_ALLOC (name
, symname_alloced
));
1497 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_text_symbol
;
1499 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1500 SYMBOL_DUP (sym
, sym2
);
1502 if (cs
->c_sclass
== C_EXT
)
1503 add_symbol_to_list (sym2
, &global_symbols
);
1504 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1505 add_symbol_to_list (sym2
, &file_symbols
);
1509 /* In case we can't figure out the type, provide default. */
1510 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_data_symbol
;
1512 switch (cs
->c_sclass
)
1515 /* The values of functions and global symbols are now resolved
1516 via the global_sym_chain in stabsread.c. */
1518 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1519 add_stab_to_list (name
, &global_stabs
);
1521 add_stab_to_list (name
, &file_stabs
);
1525 add_stab_to_list (name
, &global_stabs
);
1530 common_block_start (cs
->c_name
, objfile
);
1534 common_block_end (objfile
);
1538 complaint (&symfile_complaints
, _("Unexpected storage class: %d"),
1551 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1554 SYMBOL_SECTION (sym
) = sec
;
1561 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1562 all statics and we need to distinguish file-scope versus
1563 function-scope using within_function. We do this by
1564 changing the string we pass to define_symbol to use 'S'
1565 where we need to, which is not necessarily super-clean,
1566 but seems workable enough. */
1568 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1572 if (*pp
== 'V' && !within_function
)
1574 sym
= define_symbol ((cs
->c_value
1575 + ANOFFSET (objfile
->section_offsets
,
1576 static_block_section
)),
1577 cs
->c_name
, 0, 0, objfile
);
1580 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1581 SYMBOL_SECTION (sym
) = static_block_section
;
1590 /* Extract the file name from the aux entry of a C_FILE symbol.
1591 Result is in static storage and is only good for temporary use. */
1594 coff_getfilename (union internal_auxent
*aux_entry
, struct objfile
*objfile
)
1596 static char buffer
[BUFSIZ
];
1598 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1600 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
1601 + aux_entry
->x_file
.x_n
.x_offset
);
1604 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1605 buffer
[FILNMLEN
] = '\0';
1610 /* Set *SYMBOL to symbol number symno in symtbl. */
1612 read_symbol (struct internal_syment
*symbol
, int symno
)
1615 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl_num_syms
;
1617 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl
;
1618 if (symno
< 0 || symno
>= nsyms
)
1620 complaint (&symfile_complaints
, _("Invalid symbol offset"));
1621 symbol
->n_value
= 0;
1622 symbol
->n_scnum
= -1;
1625 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1626 stbl
+ (symno
* local_symesz
),
1630 /* Get value corresponding to symbol number symno in symtbl. */
1633 read_symbol_nvalue (int symno
)
1635 struct internal_syment symbol
[1];
1637 read_symbol (symbol
, symno
);
1638 return symbol
->n_value
;
1642 /* Find the address of the function corresponding to symno, where
1643 symno is the symbol pointed to by the linetable. */
1646 read_symbol_lineno (int symno
)
1648 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1649 int xcoff64
= bfd_xcoff_is_xcoff64 (objfile
->obfd
);
1651 struct coff_symfile_info
*info
=
1652 (struct coff_symfile_info
*)objfile
->deprecated_sym_private
;
1653 int nsyms
= info
->symtbl_num_syms
;
1654 char *stbl
= info
->symtbl
;
1655 char *strtbl
= info
->strtbl
;
1657 struct internal_syment symbol
[1];
1658 union internal_auxent main_aux
[1];
1662 bf_notfound_complaint ();
1666 /* Note that just searching for a short distance (e.g. 50 symbols)
1667 is not enough, at least in the following case.
1670 [many .stabx entries]
1671 [a few functions, referring to foo]
1675 What happens here is that the assembler moves the .stabx entries
1676 to right before the ".bf" for foo, but the symbol for "foo" is before
1677 all the stabx entries. See PR gdb/2222. */
1679 /* Maintaining a table of .bf entries might be preferable to this search.
1680 If I understand things correctly it would need to be done only for
1681 the duration of a single psymtab to symtab conversion. */
1682 while (symno
< nsyms
)
1684 bfd_coff_swap_sym_in (symfile_bfd
,
1685 stbl
+ (symno
* local_symesz
), symbol
);
1686 if (symbol
->n_sclass
== C_FCN
)
1688 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1689 if (strcmp (name
, ".bf") == 0)
1692 symno
+= symbol
->n_numaux
+ 1;
1695 bf_notfound_complaint ();
1699 /* take aux entry and return its lineno */
1701 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1702 symbol
->n_type
, symbol
->n_sclass
,
1703 0, symbol
->n_numaux
, main_aux
);
1705 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1708 /* Support for line number handling */
1710 /* This function is called for every section; it finds the outer limits
1711 * of the line table (minimum and maximum file offset) so that the
1712 * mainline code can read the whole thing for efficiency.
1715 find_linenos (struct bfd
*abfd
, struct bfd_section
*asect
, void *vpinfo
)
1717 struct coff_symfile_info
*info
;
1719 file_ptr offset
, maxoff
;
1721 count
= asect
->lineno_count
;
1723 if (strcmp (asect
->name
, ".text") != 0 || count
== 0)
1726 size
= count
* coff_data (abfd
)->local_linesz
;
1727 info
= (struct coff_symfile_info
*) vpinfo
;
1728 offset
= asect
->line_filepos
;
1729 maxoff
= offset
+ size
;
1731 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1732 info
->min_lineno_offset
= offset
;
1734 if (maxoff
> info
->max_lineno_offset
)
1735 info
->max_lineno_offset
= maxoff
;
1738 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1741 xcoff_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1743 struct cleanup
*old_chain
;
1752 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1757 /* Read in all partial symtabs on which this one is dependent */
1758 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1759 if (!pst
->dependencies
[i
]->readin
)
1761 /* Inform about additional files that need to be read in. */
1764 fputs_filtered (" ", gdb_stdout
);
1766 fputs_filtered ("and ", gdb_stdout
);
1768 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1769 wrap_here (""); /* Flush output */
1770 gdb_flush (gdb_stdout
);
1772 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1775 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1777 /* Init stuff necessary for reading in symbols. */
1780 old_chain
= make_cleanup (really_free_pendings
, 0);
1782 read_xcoff_symtab (pst
);
1784 do_cleanups (old_chain
);
1790 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1792 /* Read in all of the symbols for a given psymtab for real.
1793 Be verbose about it if the user wants that. */
1796 xcoff_psymtab_to_symtab (struct partial_symtab
*pst
)
1806 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1811 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1812 || pst
->number_of_dependencies
)
1814 /* Print the message now, before reading the string table,
1815 to avoid disconcerting pauses. */
1818 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1819 gdb_flush (gdb_stdout
);
1822 sym_bfd
= pst
->objfile
->obfd
;
1824 next_symbol_text_func
= xcoff_next_symbol_text
;
1826 xcoff_psymtab_to_symtab_1 (pst
);
1828 /* Match with global symbols. This only needs to be done once,
1829 after all of the symtabs and dependencies have been read in. */
1830 scan_file_globals (pst
->objfile
);
1832 /* Finish up the debug error message. */
1834 printf_filtered ("done.\n");
1839 xcoff_new_init (struct objfile
*objfile
)
1841 stabsread_new_init ();
1842 buildsym_new_init ();
1845 /* Do initialization in preparation for reading symbols from OBJFILE.
1847 We will only be called if this is an XCOFF or XCOFF-like file.
1848 BFD handles figuring out the format of the file, and code in symfile.c
1849 uses BFD's determination to vector to us. */
1852 xcoff_symfile_init (struct objfile
*objfile
)
1854 /* Allocate struct to keep track of the symfile */
1855 objfile
->deprecated_sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
1857 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1858 find this causes a significant slowdown in gdb then we could
1859 set it in the debug symbol readers only when necessary. */
1860 objfile
->flags
|= OBJF_REORDERED
;
1862 init_entry_point_info (objfile
);
1865 /* Perform any local cleanups required when we are done with a particular
1866 objfile. I.E, we are in the process of discarding all symbol information
1867 for an objfile, freeing up all memory held for it, and unlinking the
1868 objfile struct from the global list of known objfiles. */
1871 xcoff_symfile_finish (struct objfile
*objfile
)
1873 if (objfile
->deprecated_sym_private
!= NULL
)
1875 xfree (objfile
->deprecated_sym_private
);
1878 /* Start with a fresh include table for the next objfile. */
1884 inclIndx
= inclLength
= inclDepth
= 0;
1889 init_stringtab (bfd
*abfd
, file_ptr offset
, struct objfile
*objfile
)
1893 unsigned char lengthbuf
[4];
1896 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
= NULL
;
1898 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1899 error (_("cannot seek to string table in %s: %s"),
1900 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1902 val
= bfd_bread ((char *) lengthbuf
, sizeof lengthbuf
, abfd
);
1903 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1905 /* If no string table is needed, then the file may end immediately
1906 after the symbols. Just return with `strtbl' set to NULL. */
1908 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1911 /* Allocate string table from objfile_obstack. We will need this table
1912 as long as we have its symbol table around. */
1914 strtbl
= (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
1915 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
= strtbl
;
1917 /* Copy length buffer, the first byte is usually zero and is
1918 used for stabs with a name length of zero. */
1919 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1920 if (length
== sizeof lengthbuf
)
1923 val
= bfd_bread (strtbl
+ sizeof lengthbuf
, length
- sizeof lengthbuf
, abfd
);
1925 if (val
!= length
- sizeof lengthbuf
)
1926 error (_("cannot read string table from %s: %s"),
1927 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1928 if (strtbl
[length
- 1] != '\0')
1929 error (_("bad symbol file: string table does not end with null character"));
1934 /* If we have not yet seen a function for this psymtab, this is 0. If we
1935 have seen one, it is the offset in the line numbers of the line numbers
1937 static unsigned int first_fun_line_offset
;
1939 static struct partial_symtab
*xcoff_start_psymtab
1940 (struct objfile
*, char *, int,
1941 struct partial_symbol
**, struct partial_symbol
**);
1943 /* Allocate and partially fill a partial symtab. It will be
1944 completely filled at the end of the symbol list.
1946 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1947 is the address relative to which its symbols are (incremental) or 0
1950 static struct partial_symtab
*
1951 xcoff_start_psymtab (struct objfile
*objfile
, char *filename
, int first_symnum
,
1952 struct partial_symbol
**global_syms
,
1953 struct partial_symbol
**static_syms
)
1955 struct partial_symtab
*result
=
1956 start_psymtab_common (objfile
, objfile
->section_offsets
,
1958 /* We fill in textlow later. */
1960 global_syms
, static_syms
);
1962 result
->read_symtab_private
= obstack_alloc (&objfile
->objfile_obstack
,
1963 sizeof (struct symloc
));
1964 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
1965 result
->read_symtab
= xcoff_psymtab_to_symtab
;
1967 /* Deduce the source language from the filename for this psymtab. */
1968 psymtab_language
= deduce_language_from_filename (filename
);
1973 static struct partial_symtab
*xcoff_end_psymtab
1974 (struct partial_symtab
*, char **, int, int,
1975 struct partial_symtab
**, int, int);
1977 /* Close off the current usage of PST.
1978 Returns PST, or NULL if the partial symtab was empty and thrown away.
1980 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
1982 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
1983 are the information for includes and dependencies. */
1985 static struct partial_symtab
*
1986 xcoff_end_psymtab (struct partial_symtab
*pst
, char **include_list
,
1987 int num_includes
, int capping_symbol_number
,
1988 struct partial_symtab
**dependency_list
,
1989 int number_dependencies
, int textlow_not_set
)
1992 struct objfile
*objfile
= pst
->objfile
;
1994 if (capping_symbol_number
!= -1)
1995 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
1996 capping_symbol_number
1997 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
1998 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
1999 first_fun_line_offset
;
2000 first_fun_line_offset
= 0;
2001 pst
->n_global_syms
=
2002 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2003 pst
->n_static_syms
=
2004 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2006 pst
->number_of_dependencies
= number_dependencies
;
2007 if (number_dependencies
)
2009 pst
->dependencies
= (struct partial_symtab
**)
2010 obstack_alloc (&objfile
->objfile_obstack
,
2011 number_dependencies
* sizeof (struct partial_symtab
*));
2012 memcpy (pst
->dependencies
, dependency_list
,
2013 number_dependencies
* sizeof (struct partial_symtab
*));
2016 pst
->dependencies
= 0;
2018 for (i
= 0; i
< num_includes
; i
++)
2020 struct partial_symtab
*subpst
=
2021 allocate_psymtab (include_list
[i
], objfile
);
2023 subpst
->section_offsets
= pst
->section_offsets
;
2024 subpst
->read_symtab_private
= obstack_alloc (&objfile
->objfile_obstack
,
2025 sizeof (struct symloc
));
2026 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2027 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2028 subpst
->textlow
= 0;
2029 subpst
->texthigh
= 0;
2031 /* We could save slight bits of space by only making one of these,
2032 shared by the entire set of include files. FIXME-someday. */
2033 subpst
->dependencies
= (struct partial_symtab
**)
2034 obstack_alloc (&objfile
->objfile_obstack
,
2035 sizeof (struct partial_symtab
*));
2036 subpst
->dependencies
[0] = pst
;
2037 subpst
->number_of_dependencies
= 1;
2039 subpst
->globals_offset
=
2040 subpst
->n_global_syms
=
2041 subpst
->statics_offset
=
2042 subpst
->n_static_syms
= 0;
2046 subpst
->read_symtab
= pst
->read_symtab
;
2049 sort_pst_symbols (pst
);
2051 if (num_includes
== 0
2052 && number_dependencies
== 0
2053 && pst
->n_global_syms
== 0
2054 && pst
->n_static_syms
== 0)
2056 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2057 it is on the obstack, but we can forget to chain it on the list. */
2058 /* Empty psymtabs happen as a result of header files which don't have
2059 any symbols in them. There can be a lot of them. */
2061 discard_psymtab (pst
);
2063 /* Indicate that psymtab was thrown away. */
2064 pst
= (struct partial_symtab
*) NULL
;
2069 static void swap_sym (struct internal_syment
*,
2070 union internal_auxent
*, char **, char **,
2071 unsigned int *, struct objfile
*);
2073 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2074 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2075 the symbol and its auxents. */
2078 swap_sym (struct internal_syment
*symbol
, union internal_auxent
*aux
,
2079 char **name
, char **raw
, unsigned int *symnump
,
2080 struct objfile
*objfile
)
2082 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2083 if (symbol
->n_zeroes
)
2085 /* If it's exactly E_SYMNMLEN characters long it isn't
2087 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2089 /* FIXME: wastes memory for symbols which we don't end up putting
2090 into the minimal symbols. */
2092 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
2093 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2094 p
[E_SYMNMLEN
] = '\0';
2098 /* Point to the unswapped name as that persists as long as the
2100 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2102 else if (symbol
->n_sclass
& 0x80)
2104 *name
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
2109 *name
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
2113 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2114 if (symbol
->n_numaux
> 0)
2116 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2117 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2119 *symnump
+= symbol
->n_numaux
;
2120 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2125 function_outside_compilation_unit_complaint (const char *arg1
)
2127 complaint (&symfile_complaints
,
2128 _("function `%s' appears to be defined outside of all compilation units"),
2133 scan_xcoff_symtab (struct objfile
*objfile
)
2135 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2136 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2137 char *filestring
= NULL
;
2140 int past_first_source_file
= 0;
2145 /* Current partial symtab */
2146 struct partial_symtab
*pst
;
2148 /* List of current psymtab's include files */
2149 char **psymtab_include_list
;
2150 int includes_allocated
;
2153 /* Index within current psymtab dependency list */
2154 struct partial_symtab
**dependency_list
;
2155 int dependencies_used
, dependencies_allocated
;
2158 struct internal_syment symbol
;
2159 union internal_auxent main_aux
[5];
2160 unsigned int ssymnum
;
2162 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2163 CORE_ADDR last_csect_val
= 0;
2164 int last_csect_sec
= 0;
2165 int misc_func_recorded
= 0; /* true if any misc. function */
2166 int textlow_not_set
= 1;
2168 pst
= (struct partial_symtab
*) 0;
2170 includes_allocated
= 30;
2172 psymtab_include_list
= (char **) alloca (includes_allocated
*
2175 dependencies_allocated
= 30;
2176 dependencies_used
= 0;
2178 (struct partial_symtab
**) alloca (dependencies_allocated
*
2179 sizeof (struct partial_symtab
*));
2181 last_source_file
= NULL
;
2183 abfd
= objfile
->obfd
;
2184 next_symbol_text_func
= xcoff_next_symbol_text
;
2186 sraw_symbol
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
;
2187 nsyms
= ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl_num_syms
;
2189 while (ssymnum
< nsyms
)
2195 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2196 sclass
= symbol
.n_sclass
;
2203 /* The CSECT auxent--always the last auxent. */
2204 union internal_auxent csect_aux
;
2205 unsigned int symnum_before
= ssymnum
;
2207 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2209 if (symbol
.n_numaux
> 1)
2211 bfd_coff_swap_aux_in
2213 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2216 symbol
.n_numaux
- 1,
2221 csect_aux
= main_aux
[0];
2223 /* If symbol name starts with ".$" or "$", ignore it. */
2224 if (namestring
[0] == '$'
2225 || (namestring
[0] == '.' && namestring
[1] == '$'))
2228 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2231 switch (csect_aux
.x_csect
.x_smclas
)
2234 if (last_csect_name
)
2236 /* If no misc. function recorded in the last
2237 seen csect, enter it as a function. This
2238 will take care of functions like strcmp()
2241 if (!misc_func_recorded
)
2243 RECORD_MINIMAL_SYMBOL
2244 (last_csect_name
, last_csect_val
,
2245 mst_text
, last_csect_sec
,
2251 /* We have to allocate one psymtab for
2252 each program csect, because their text
2253 sections need not be adjacent. */
2255 (pst
, psymtab_include_list
, includes_used
,
2256 symnum_before
, dependency_list
,
2257 dependencies_used
, textlow_not_set
);
2259 dependencies_used
= 0;
2260 /* Give all psymtabs for this source file the same
2262 pst
= xcoff_start_psymtab
2266 objfile
->global_psymbols
.next
,
2267 objfile
->static_psymbols
.next
);
2270 /* Activate the misc_func_recorded mechanism for
2271 compiler- and linker-generated CSECTs like ".strcmp"
2273 if (namestring
&& (namestring
[0] == '.'
2274 || namestring
[0] == '@'))
2276 last_csect_name
= namestring
;
2277 last_csect_val
= symbol
.n_value
;
2279 secnum_to_section (symbol
.n_scnum
, objfile
);
2284 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2285 if (highval
> pst
->texthigh
)
2286 pst
->texthigh
= highval
;
2287 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2288 pst
->textlow
= symbol
.n_value
;
2290 misc_func_recorded
= 0;
2295 /* Data variables are recorded in the minimal symbol
2296 table, except for section symbols. */
2297 if (*namestring
!= '.')
2298 prim_record_minimal_symbol_and_info
2299 (namestring
, symbol
.n_value
,
2300 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2301 secnum_to_section (symbol
.n_scnum
, objfile
),
2307 warning (_("More than one XMC_TC0 symbol found."));
2308 toc_offset
= symbol
.n_value
;
2310 /* Make TOC offset relative to start address of section. */
2311 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2313 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2317 /* These symbols tell us where the TOC entry for a
2318 variable is, not the variable itself. */
2327 switch (csect_aux
.x_csect
.x_smclas
)
2330 /* A function entry point. */
2332 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2333 first_fun_line_offset
=
2334 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2335 RECORD_MINIMAL_SYMBOL
2336 (namestring
, symbol
.n_value
,
2337 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2338 secnum_to_section (symbol
.n_scnum
, objfile
),
2343 /* shared library function trampoline code entry
2346 /* record trampoline code entries as
2347 mst_solib_trampoline symbol. When we lookup mst
2348 symbols, we will choose mst_text over
2349 mst_solib_trampoline. */
2350 RECORD_MINIMAL_SYMBOL
2351 (namestring
, symbol
.n_value
,
2352 mst_solib_trampoline
,
2353 secnum_to_section (symbol
.n_scnum
, objfile
),
2358 /* The symbols often have the same names as
2359 debug symbols for functions, and confuse
2365 /* xlc puts each variable in a separate csect,
2366 so we get an XTY_SD for each variable. But
2367 gcc puts several variables in a csect, so
2368 that each variable only gets an XTY_LD. We
2369 still need to record them. This will
2370 typically be XMC_RW; I suspect XMC_RO and
2371 XMC_BS might be possible too. */
2372 if (*namestring
!= '.')
2373 prim_record_minimal_symbol_and_info
2374 (namestring
, symbol
.n_value
,
2375 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2376 secnum_to_section (symbol
.n_scnum
, objfile
),
2383 switch (csect_aux
.x_csect
.x_smclas
)
2387 /* Common variables are recorded in the minimal symbol
2388 table, except for section symbols. */
2389 if (*namestring
!= '.')
2390 prim_record_minimal_symbol_and_info
2391 (namestring
, symbol
.n_value
,
2392 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2393 secnum_to_section (symbol
.n_scnum
, objfile
),
2406 unsigned int symnum_before
;
2408 symnum_before
= ssymnum
;
2409 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2412 /* See if the last csect needs to be recorded. */
2414 if (last_csect_name
&& !misc_func_recorded
)
2417 /* If no misc. function recorded in the last seen csect, enter
2418 it as a function. This will take care of functions like
2419 strcmp() compiled by xlc. */
2421 RECORD_MINIMAL_SYMBOL
2422 (last_csect_name
, last_csect_val
,
2423 mst_text
, last_csect_sec
, objfile
);
2428 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2429 symnum_before
, dependency_list
,
2430 dependencies_used
, textlow_not_set
);
2432 dependencies_used
= 0;
2434 first_fun_line_offset
= 0;
2436 /* XCOFF, according to the AIX 3.2 documentation, puts the
2437 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2438 do things the standard COFF way and put it in the auxent.
2439 We use the auxent if the symbol is ".file" and an auxent
2440 exists, otherwise use the symbol itself. */
2441 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2443 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2446 filestring
= namestring
;
2448 pst
= xcoff_start_psymtab (objfile
,
2451 objfile
->global_psymbols
.next
,
2452 objfile
->static_psymbols
.next
);
2453 last_csect_name
= NULL
;
2459 complaint (&symfile_complaints
,
2460 _("Storage class %d not recognized during scan"), sclass
);
2464 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2465 to handle only the C_FUN and C_EXT. */
2480 /* C_EINCL means we are switching back to the main file. But there
2481 is no reason to care; the only thing we want to know about
2482 includes is the names of all the included (.h) files. */
2487 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2491 /* I don't think the name of the common block (as opposed to the
2492 variables within it) is something which is user visible
2500 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2501 so C_LSYM would appear to be only for locals. */
2507 /* We probably could save a few instructions by assuming that
2508 C_LSYM, C_PSYM, etc., never have auxents. */
2509 int naux1
= symbol
.n_numaux
+ 1;
2511 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2517 /* Mark down an include file in the current psymtab */
2518 enum language tmp_language
;
2519 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2522 tmp_language
= deduce_language_from_filename (namestring
);
2524 /* Only change the psymtab's language if we've learned
2525 something useful (eg. tmp_language is not language_unknown).
2526 In addition, to match what start_subfile does, never change
2528 if (tmp_language
!= language_unknown
2529 && (tmp_language
!= language_c
2530 || psymtab_language
!= language_cplus
))
2531 psymtab_language
= tmp_language
;
2533 /* In C++, one may expect the same filename to come round many
2534 times, when code is coming alternately from the main file
2535 and from inline functions in other files. So I check to see
2536 if this is a file we've seen before -- either the main
2537 source file, or a previously included file.
2539 This seems to be a lot of time to be spending on N_SOL, but
2540 things like "break c-exp.y:435" need to work (I
2541 suppose the psymtab_include_list could be hashed or put
2542 in a binary tree, if profiling shows this is a major hog). */
2543 if (pst
&& strcmp (namestring
, pst
->filename
) == 0)
2547 for (i
= 0; i
< includes_used
; i
++)
2548 if (strcmp (namestring
, psymtab_include_list
[i
]) == 0)
2556 psymtab_include_list
[includes_used
++] = namestring
;
2557 if (includes_used
>= includes_allocated
)
2559 char **orig
= psymtab_include_list
;
2561 psymtab_include_list
= (char **)
2562 alloca ((includes_allocated
*= 2) *
2564 memcpy (psymtab_include_list
, orig
,
2565 includes_used
* sizeof (char *));
2570 /* The value of the C_FUN is not the address of the function (it
2571 appears to be the address before linking), but as long as it
2572 is smaller than the actual address, then find_pc_partial_function
2573 will use the minimal symbols instead. I hope. */
2581 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2584 p
= (char *) strchr (namestring
, ':');
2586 continue; /* Not a debugging symbol. */
2588 /* Main processing section for debugging symbols which
2589 the initial read through the symbol tables needs to worry
2590 about. If we reach this point, the symbol which we are
2591 considering is definitely one we are interested in.
2592 p must also contain the (valid) index into the namestring
2593 which indicates the debugging type symbol. */
2598 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2600 if (gdbarch_static_transform_name_p (gdbarch
))
2601 namestring
= gdbarch_static_transform_name
2602 (gdbarch
, namestring
);
2604 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2605 VAR_DOMAIN
, LOC_STATIC
,
2606 &objfile
->static_psymbols
,
2608 psymtab_language
, objfile
);
2612 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2613 /* The addresses in these entries are reported to be
2614 wrong. See the code that reads 'G's for symtabs. */
2615 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2616 VAR_DOMAIN
, LOC_STATIC
,
2617 &objfile
->global_psymbols
,
2619 psymtab_language
, objfile
);
2623 /* When a 'T' entry is defining an anonymous enum, it
2624 may have a name which is the empty string, or a
2625 single space. Since they're not really defining a
2626 symbol, those shouldn't go in the partial symbol
2627 table. We do pick up the elements of such enums at
2628 'check_enum:', below. */
2629 if (p
>= namestring
+ 2
2630 || (p
== namestring
+ 1
2631 && namestring
[0] != ' '))
2633 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2634 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2635 &objfile
->static_psymbols
,
2637 psymtab_language
, objfile
);
2640 /* Also a typedef with the same name. */
2641 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2642 VAR_DOMAIN
, LOC_TYPEDEF
,
2643 &objfile
->static_psymbols
,
2645 psymtab_language
, objfile
);
2652 if (p
!= namestring
) /* a name is there, not just :T... */
2654 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2655 VAR_DOMAIN
, LOC_TYPEDEF
,
2656 &objfile
->static_psymbols
,
2658 psymtab_language
, objfile
);
2661 /* If this is an enumerated type, we need to
2662 add all the enum constants to the partial symbol
2663 table. This does not cover enums without names, e.g.
2664 "enum {a, b} c;" in C, but fortunately those are
2665 rare. There is no way for GDB to find those from the
2666 enum type without spending too much time on it. Thus
2667 to solve this problem, the compiler needs to put out the
2668 enum in a nameless type. GCC2 does this. */
2670 /* We are looking for something of the form
2671 <name> ":" ("t" | "T") [<number> "="] "e"
2672 {<constant> ":" <value> ","} ";". */
2674 /* Skip over the colon and the 't' or 'T'. */
2676 /* This type may be given a number. Also, numbers can come
2677 in pairs like (0,26). Skip over it. */
2678 while ((*p
>= '0' && *p
<= '9')
2679 || *p
== '(' || *p
== ',' || *p
== ')'
2685 /* The aix4 compiler emits extra crud before the members. */
2688 /* Skip over the type (?). */
2692 /* Skip over the colon. */
2696 /* We have found an enumerated type. */
2697 /* According to comments in read_enum_type
2698 a comma could end it instead of a semicolon.
2699 I don't know where that happens.
2701 while (*p
&& *p
!= ';' && *p
!= ',')
2705 /* Check for and handle cretinous dbx symbol name
2707 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
2708 p
= next_symbol_text (objfile
);
2710 /* Point to the character after the name
2711 of the enum constant. */
2712 for (q
= p
; *q
&& *q
!= ':'; q
++)
2714 /* Note that the value doesn't matter for
2715 enum constants in psymtabs, just in symtabs. */
2716 add_psymbol_to_list (p
, q
- p
, 1,
2717 VAR_DOMAIN
, LOC_CONST
,
2718 &objfile
->static_psymbols
, 0,
2719 0, psymtab_language
, objfile
);
2720 /* Point past the name. */
2722 /* Skip over the value. */
2723 while (*p
&& *p
!= ',')
2725 /* Advance past the comma. */
2733 /* Constant, e.g. from "const" in Pascal. */
2734 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2735 VAR_DOMAIN
, LOC_CONST
,
2736 &objfile
->static_psymbols
, symbol
.n_value
,
2737 0, psymtab_language
, objfile
);
2743 int name_len
= p
- namestring
;
2744 char *name
= xmalloc (name_len
+ 1);
2745 memcpy (name
, namestring
, name_len
);
2746 name
[name_len
] = '\0';
2747 function_outside_compilation_unit_complaint (name
);
2750 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2751 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2752 VAR_DOMAIN
, LOC_BLOCK
,
2753 &objfile
->static_psymbols
,
2755 psymtab_language
, objfile
);
2758 /* Global functions were ignored here, but now they
2759 are put into the global psymtab like one would expect.
2760 They're also in the minimal symbol table. */
2764 int name_len
= p
- namestring
;
2765 char *name
= xmalloc (name_len
+ 1);
2766 memcpy (name
, namestring
, name_len
);
2767 name
[name_len
] = '\0';
2768 function_outside_compilation_unit_complaint (name
);
2772 /* We need only the minimal symbols for these
2773 loader-generated definitions. Keeping the global
2774 symbols leads to "in psymbols but not in symbols"
2776 if (strncmp (namestring
, "@FIX", 4) == 0)
2779 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2780 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2781 VAR_DOMAIN
, LOC_BLOCK
,
2782 &objfile
->global_psymbols
,
2784 psymtab_language
, objfile
);
2787 /* Two things show up here (hopefully); static symbols of
2788 local scope (static used inside braces) or extensions
2789 of structure symbols. We can ignore both. */
2803 case '#': /* for symbol identification (used in live ranges) */
2807 /* It is a C++ nested symbol. We don't need to record it
2808 (I don't think); if we try to look up foo::bar::baz,
2809 then symbols for the symtab containing foo should get
2810 read in, I think. */
2811 /* Someone says sun cc puts out symbols like
2812 /foo/baz/maclib::/usr/local/bin/maclib,
2813 which would get here with a symbol type of ':'. */
2817 /* Unexpected symbol descriptor. The second and subsequent stabs
2818 of a continued stab can show up here. The question is
2819 whether they ever can mimic a normal stab--it would be
2820 nice if not, since we certainly don't want to spend the
2821 time searching to the end of every string looking for
2824 complaint (&symfile_complaints
,
2825 _("unknown symbol descriptor `%c'"), p
[1]);
2827 /* Ignore it; perhaps it is an extension that we don't
2837 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2838 ssymnum
, dependency_list
,
2839 dependencies_used
, textlow_not_set
);
2842 /* Record the toc offset value of this symbol table into objfile structure.
2843 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2844 this information would be file auxiliary header. */
2846 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
= toc_offset
;
2849 /* Return the toc offset value for a given objfile. */
2852 xcoff_get_toc_offset (struct objfile
*objfile
)
2855 return ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
;
2859 /* Scan and build partial symbols for a symbol file.
2860 We have been initialized by a call to dbx_symfile_init, which
2861 put all the relevant info into a "struct dbx_symfile_info",
2862 hung off the objfile structure.
2864 SECTION_OFFSETS contains offsets relative to which the symbols in the
2865 various sections are (depending where the sections were actually loaded).
2869 xcoff_initial_scan (struct objfile
*objfile
, int symfile_flags
)
2873 struct cleanup
*back_to
;
2874 int num_symbols
; /* # of symbols */
2875 file_ptr symtab_offset
; /* symbol table and */
2876 file_ptr stringtab_offset
; /* string table file offsets */
2877 struct coff_symfile_info
*info
;
2881 info
= (struct coff_symfile_info
*) objfile
->deprecated_sym_private
;
2882 symfile_bfd
= abfd
= objfile
->obfd
;
2883 name
= objfile
->name
;
2885 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2886 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2887 stringtab_offset
= symtab_offset
+
2888 num_symbols
* coff_data (abfd
)->local_symesz
;
2890 info
->min_lineno_offset
= 0;
2891 info
->max_lineno_offset
= 0;
2892 bfd_map_over_sections (abfd
, find_linenos
, info
);
2894 if (num_symbols
> 0)
2896 /* Read the string table. */
2897 init_stringtab (abfd
, stringtab_offset
, objfile
);
2899 /* Read the .debug section, if present. */
2901 struct bfd_section
*secp
;
2902 bfd_size_type length
;
2903 char *debugsec
= NULL
;
2905 secp
= bfd_get_section_by_name (abfd
, ".debug");
2908 length
= bfd_section_size (abfd
, secp
);
2912 (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
2914 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2915 (file_ptr
) 0, length
))
2917 error (_("Error reading .debug section of `%s': %s"),
2918 name
, bfd_errmsg (bfd_get_error ()));
2922 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
=
2927 /* Read the symbols. We keep them in core because we will want to
2928 access them randomly in read_symbol*. */
2929 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2931 error (_("Error reading symbols from %s: %s"),
2932 name
, bfd_errmsg (bfd_get_error ()));
2933 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2934 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
=
2935 obstack_alloc (&objfile
->objfile_obstack
, size
);
2936 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl_num_syms
=
2939 val
= bfd_bread (((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
,
2942 perror_with_name (_("reading symbol table"));
2944 /* If we are reinitializing, or if we have never loaded syms yet, init */
2945 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2946 /* I'm not sure how how good num_symbols is; the rule of thumb in
2947 init_psymbol_list was developed for a.out. On the one hand,
2948 num_symbols includes auxents. On the other hand, it doesn't
2950 init_psymbol_list (objfile
, num_symbols
);
2952 free_pending_blocks ();
2953 back_to
= make_cleanup (really_free_pendings
, 0);
2955 init_minimal_symbol_collection ();
2956 make_cleanup_discard_minimal_symbols ();
2958 /* Now that the symbol table data of the executable file are all in core,
2959 process them and define symbols accordingly. */
2961 scan_xcoff_symtab (objfile
);
2963 /* Install any minimal symbols that have been collected as the current
2964 minimal symbols for this objfile. */
2966 install_minimal_symbols (objfile
);
2968 do_cleanups (back_to
);
2972 xcoff_symfile_offsets (struct objfile
*objfile
, struct section_addr_info
*addrs
)
2974 asection
*sect
= NULL
;
2977 objfile
->num_sections
= bfd_count_sections (objfile
->obfd
);
2978 objfile
->section_offsets
= (struct section_offsets
*)
2979 obstack_alloc (&objfile
->objfile_obstack
,
2980 SIZEOF_N_SECTION_OFFSETS (objfile
->num_sections
));
2982 /* Initialize the section indexes for future use. */
2983 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
2985 objfile
->sect_index_text
= sect
->index
;
2987 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
2989 objfile
->sect_index_data
= sect
->index
;
2991 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
2993 objfile
->sect_index_bss
= sect
->index
;
2995 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
2997 objfile
->sect_index_rodata
= sect
->index
;
2999 for (i
= 0; i
< objfile
->num_sections
; ++i
)
3001 /* syms_from_objfile kindly subtracts from addr the
3002 bfd_section_vma of the .text section. This strikes me as
3003 wrong--whether the offset to be applied to symbol reading is
3004 relative to the start address of the section depends on the
3005 symbol format. In any event, this whole "addr" concept is
3006 pretty broken (it doesn't handle any section but .text
3007 sensibly), so just ignore the addr parameter and use 0.
3008 rs6000-nat.c will set the correct section offsets via
3009 objfile_relocate. */
3010 (objfile
->section_offsets
)->offsets
[i
] = 0;
3014 /* Register our ability to parse symbols for xcoff BFD files. */
3016 static struct sym_fns xcoff_sym_fns
=
3019 /* It is possible that coff and xcoff should be merged as
3020 they do have fundamental similarities (for example, the extra storage
3021 classes used for stabs could presumably be recognized in any COFF file).
3022 However, in addition to obvious things like all the csect hair, there are
3023 some subtler differences between xcoffread.c and coffread.c, notably
3024 the fact that coffread.c has no need to read in all the symbols, but
3025 xcoffread.c reads all the symbols and does in fact randomly access them
3026 (in C_BSTAT and line number processing). */
3028 bfd_target_xcoff_flavour
,
3030 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3031 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3032 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
3033 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3034 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
3035 default_symfile_segments
, /* sym_segments: Get segment information from
3037 aix_process_linenos
, /* sym_read_linetable */
3038 default_symfile_relocate
, /* sym_relocate: Relocate a debug section. */
3040 NULL
/* next: pointer to next struct sym_fns */
3043 /* Provide a prototype to silence -Wmissing-prototypes. */
3044 extern initialize_file_ftype _initialize_xcoffread
;
3047 _initialize_xcoffread (void)
3049 add_symtab_fns (&xcoff_sym_fns
);