1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-2004, 2007-2012 Free Software Foundation, Inc.
3 Derived from coffread.c, dbxread.c, and a lot of hacking.
4 Contributed by IBM Corporation.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include <sys/types.h>
27 #include "gdb_string.h"
29 #include <sys/param.h>
30 #ifdef HAVE_SYS_FILE_H
35 #include "coff/internal.h"
36 #include "libcoff.h" /* FIXME, internal data from BFD */
37 #include "coff/xcoff.h"
39 #include "coff/rs6000.h"
40 #include "xcoffread.h"
44 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */
48 #include "stabsread.h"
49 #include "expression.h"
50 #include "complaints.h"
53 #include "gdb-stabs.h"
55 /* For interface with stabsread.c. */
56 #include "aout/stab_gnu.h"
59 /* We put a pointer to this structure in the read_symtab_private field
65 /* First symbol number for this file. */
69 /* Number of symbols in the section of the symbol table devoted to
70 this file's symbols (actually, the section bracketed may contain
71 more than just this file's symbols). If numsyms is 0, the only
72 reason for this thing's existence is the dependency list. Nothing
73 else will happen when it is read in. */
77 /* Position of the start of the line number information for this
79 unsigned int lineno_off
;
82 /* Remember what we deduced to be the source language of this psymtab. */
84 static enum language psymtab_language
= language_unknown
;
87 /* Simplified internal version of coff symbol table information. */
92 int c_symnum
; /* Symbol number of this entry. */
93 int c_naux
; /* 0 if syment only, 1 if syment + auxent. */
95 unsigned char c_sclass
;
100 /* Last function's saved coff symbol `cs'. */
102 static struct coff_symbol fcn_cs_saved
;
104 static bfd
*symfile_bfd
;
106 /* Core address of start and end of text of current source file.
107 This is calculated from the first function seen after a C_FILE
111 static CORE_ADDR cur_src_end_addr
;
113 /* Core address of the end of the first object file. */
115 static CORE_ADDR first_object_file_end
;
117 /* Initial symbol-table-debug-string vector length. */
119 #define INITIAL_STABVECTOR_LENGTH 40
121 /* Nonzero if within a function (so symbols should be local,
122 if nothing says specifically). */
126 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
127 there is any reason not to just use a #define, but might as well
128 ask BFD for the size and store it here, I guess. */
130 static unsigned local_symesz
;
132 struct coff_symfile_info
134 file_ptr min_lineno_offset
; /* Where in file lowest line#s are. */
135 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file. */
137 /* Pointer to the string table. */
140 /* Pointer to debug section. */
143 /* Pointer to the a.out symbol table. */
146 /* Number of symbols in symtbl. */
149 /* Offset in data section to TOC anchor. */
150 CORE_ADDR toc_offset
;
153 /* XCOFF names for dwarf sections. There is no compressed sections. */
155 static const struct dwarf2_debug_sections dwarf2_xcoff_names
= {
157 { ".dwabrev", NULL
},
160 { NULL
, NULL
}, /* debug_macinfo */
161 { NULL
, NULL
}, /* debug_macro */
163 { ".dwrnges", NULL
},
164 { NULL
, NULL
}, /* debug_types */
165 { NULL
, NULL
}, /* debug_addr */
166 { ".dwframe", NULL
},
167 { NULL
, NULL
}, /* eh_frame */
168 { NULL
, NULL
}, /* gdb_index */
173 bf_notfound_complaint (void)
175 complaint (&symfile_complaints
,
176 _("line numbers off, `.bf' symbol not found"));
180 ef_complaint (int arg1
)
182 complaint (&symfile_complaints
,
183 _("Mismatched .ef symbol ignored starting at symnum %d"), arg1
);
187 eb_complaint (int arg1
)
189 complaint (&symfile_complaints
,
190 _("Mismatched .eb symbol ignored starting at symnum %d"), arg1
);
193 static void xcoff_initial_scan (struct objfile
*, int);
195 static void scan_xcoff_symtab (struct objfile
*);
197 static char *xcoff_next_symbol_text (struct objfile
*);
199 static void record_include_begin (struct coff_symbol
*);
202 enter_line_range (struct subfile
*, unsigned, unsigned,
203 CORE_ADDR
, CORE_ADDR
, unsigned *);
205 static void init_stringtab (bfd
*, file_ptr
, struct objfile
*);
207 static void xcoff_symfile_init (struct objfile
*);
209 static void xcoff_new_init (struct objfile
*);
211 static void xcoff_symfile_finish (struct objfile
*);
213 static void xcoff_symfile_offsets (struct objfile
*,
214 struct section_addr_info
*addrs
);
216 static char *coff_getfilename (union internal_auxent
*, struct objfile
*);
218 static void read_symbol (struct internal_syment
*, int);
220 static int read_symbol_lineno (int);
222 static CORE_ADDR
read_symbol_nvalue (int);
224 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
227 static void read_xcoff_symtab (struct partial_symtab
*);
230 static void add_stab_to_list (char *, struct pending_stabs
**);
233 static int compare_lte (const void *, const void *);
235 static struct linetable
*arrange_linetable (struct linetable
*);
237 static void record_include_end (struct coff_symbol
*);
239 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
242 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
244 static int secnum_to_section (int, struct objfile
*);
245 static asection
*secnum_to_bfd_section (int, struct objfile
*);
247 struct find_targ_sec_arg
252 struct objfile
*objfile
;
255 static void find_targ_sec (bfd
*, asection
*, void *);
258 find_targ_sec (bfd
*abfd
, asection
*sect
, void *obj
)
260 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
261 struct objfile
*objfile
= args
->objfile
;
263 if (sect
->target_index
== args
->targ_index
)
265 /* This is the section. Figure out what SECT_OFF_* code it is. */
266 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
267 *args
->resultp
= SECT_OFF_TEXT (objfile
);
268 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
269 *args
->resultp
= SECT_OFF_DATA (objfile
);
271 *args
->resultp
= sect
->index
;
272 *args
->bfd_sect
= sect
;
276 /* Search all BFD sections for the section whose target_index is
277 equal to N_SCNUM. Set *BFD_SECT to that section. The section's
278 associated index in the objfile's section_offset table is also
281 If no match is found, *BFD_SECT is set to NULL, and *SECNUM
282 is set to the text section's number. */
285 xcoff_secnum_to_sections (int n_scnum
, struct objfile
*objfile
,
286 asection
**bfd_sect
, int *secnum
)
288 struct find_targ_sec_arg args
;
290 args
.targ_index
= n_scnum
;
291 args
.resultp
= secnum
;
292 args
.bfd_sect
= bfd_sect
;
293 args
.objfile
= objfile
;
296 *secnum
= SECT_OFF_TEXT (objfile
);
298 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
301 /* Return the section number (SECT_OFF_*) that N_SCNUM points to. */
304 secnum_to_section (int n_scnum
, struct objfile
*objfile
)
309 xcoff_secnum_to_sections (n_scnum
, objfile
, &ignored
, &secnum
);
313 /* Return the BFD section that N_SCNUM points to. */
316 secnum_to_bfd_section (int n_scnum
, struct objfile
*objfile
)
321 xcoff_secnum_to_sections (n_scnum
, objfile
, &bfd_sect
, &ignored
);
325 /* add a given stab string into given stab vector. */
330 add_stab_to_list (char *stabname
, struct pending_stabs
**stabvector
)
332 if (*stabvector
== NULL
)
334 *stabvector
= (struct pending_stabs
*)
335 xmalloc (sizeof (struct pending_stabs
) +
336 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
337 (*stabvector
)->count
= 0;
338 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
340 else if ((*stabvector
)->count
>= (*stabvector
)->length
)
342 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
343 *stabvector
= (struct pending_stabs
*)
344 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
345 (*stabvector
)->length
* sizeof (char *));
347 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
352 /* Linenos are processed on a file-by-file basis.
356 1) xlc (IBM's native c compiler) postpones static function code
357 emission to the end of a compilation unit. This way it can
358 determine if those functions (statics) are needed or not, and
359 can do some garbage collection (I think). This makes line
360 numbers and corresponding addresses unordered, and we end up
361 with a line table like:
378 and that breaks gdb's binary search on line numbers, if the
379 above table is not sorted on line numbers. And that sort
380 should be on function based, since gcc can emit line numbers
383 10 0x100 - for the init/test part of a for stmt.
386 10 0x400 - for the increment part of a for stmt.
388 arrange_linetable() will do this sorting.
390 2) aix symbol table might look like:
392 c_file // beginning of a new file
393 .bi // beginning of include file
394 .ei // end of include file
398 basically, .bi/.ei pairs do not necessarily encapsulate
399 their scope. They need to be recorded, and processed later
400 on when we come the end of the compilation unit.
401 Include table (inclTable) and process_linenos() handle
407 /* compare line table entry addresses. */
410 compare_lte (const void *lte1p
, const void *lte2p
)
412 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
413 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
415 return lte1
->pc
- lte2
->pc
;
418 /* Given a line table with function entries are marked, arrange its
419 functions in ascending order and strip off function entry markers
420 and return it in a newly created table. If the old one is good
421 enough, return the old one. */
422 /* FIXME: I think all this stuff can be replaced by just passing
423 sort_linevec = 1 to end_symtab. */
425 static struct linetable
*
426 arrange_linetable (struct linetable
*oldLineTb
)
428 int ii
, jj
, newline
, /* new line count */
429 function_count
; /* # of functions */
431 struct linetable_entry
*fentry
; /* function entry vector */
432 int fentry_size
; /* # of function entries */
433 struct linetable
*newLineTb
; /* new line table */
435 #define NUM_OF_FUNCTIONS 20
437 fentry_size
= NUM_OF_FUNCTIONS
;
438 fentry
= (struct linetable_entry
*)
439 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
441 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
443 if (oldLineTb
->item
[ii
].line
== 0)
444 { /* Function entry found. */
445 if (function_count
>= fentry_size
)
446 { /* Make sure you have room. */
448 fentry
= (struct linetable_entry
*)
450 fentry_size
* sizeof (struct linetable_entry
));
452 fentry
[function_count
].line
= ii
;
453 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
458 if (function_count
== 0)
463 else if (function_count
> 1)
464 qsort (fentry
, function_count
,
465 sizeof (struct linetable_entry
), compare_lte
);
467 /* Allocate a new line table. */
468 newLineTb
= (struct linetable
*)
470 (sizeof (struct linetable
) +
471 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
473 /* If line table does not start with a function beginning, copy up until
477 if (oldLineTb
->item
[0].line
!= 0)
479 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
480 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
482 /* Now copy function lines one by one. */
484 for (ii
= 0; ii
< function_count
; ++ii
)
486 for (jj
= fentry
[ii
].line
+ 1;
487 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
489 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
492 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
496 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
497 following `IncludeChain'. At the end of each symtab (end_symtab),
498 we will determine if we should create additional symtab's to
499 represent if (the include files. */
502 typedef struct _inclTable
504 char *name
; /* include filename */
506 /* Offsets to the line table. end points to the last entry which is
507 part of this include file. */
510 struct subfile
*subfile
;
511 unsigned funStartLine
; /* Start line # of its function. */
515 #define INITIAL_INCLUDE_TABLE_LENGTH 20
516 static InclTable
*inclTable
; /* global include table */
517 static int inclIndx
; /* last entry to table */
518 static int inclLength
; /* table length */
519 static int inclDepth
; /* nested include depth */
521 static void allocate_include_entry (void);
524 record_include_begin (struct coff_symbol
*cs
)
528 /* In xcoff, we assume include files cannot be nested (not in .c files
529 of course, but in corresponding .s files.). */
531 /* This can happen with old versions of GCC.
532 GCC 2.3.3-930426 does not exhibit this on a test case which
533 a user said produced the message for him. */
534 complaint (&symfile_complaints
, _("Nested C_BINCL symbols"));
538 allocate_include_entry ();
540 inclTable
[inclIndx
].name
= cs
->c_name
;
541 inclTable
[inclIndx
].begin
= cs
->c_value
;
545 record_include_end (struct coff_symbol
*cs
)
551 complaint (&symfile_complaints
, _("Mismatched C_BINCL/C_EINCL pair"));
554 allocate_include_entry ();
556 pTbl
= &inclTable
[inclIndx
];
557 pTbl
->end
= cs
->c_value
;
564 allocate_include_entry (void)
566 if (inclTable
== NULL
)
568 inclTable
= (InclTable
*)
569 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
571 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
572 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
575 else if (inclIndx
>= inclLength
)
577 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
578 inclTable
= (InclTable
*)
579 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
580 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
581 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
585 /* Global variable to pass the psymtab down to all the routines involved
586 in psymtab to symtab processing. */
587 static struct partial_symtab
*this_symtab_psymtab
;
589 /* given the start and end addresses of a compilation unit (or a csect,
590 at times) process its lines and create appropriate line vectors. */
593 process_linenos (CORE_ADDR start
, CORE_ADDR end
)
596 file_ptr max_offset
=
597 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
598 ->deprecated_sym_private
)->max_lineno_offset
;
600 /* subfile structure for the main compilation unit. */
601 struct subfile main_subfile
;
603 /* In the main source file, any time we see a function entry, we
604 reset this variable to function's absolute starting line number.
605 All the following line numbers in the function are relative to
606 this, and we record absolute line numbers in record_line(). */
608 unsigned int main_source_baseline
= 0;
613 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
615 goto return_after_cleanup
;
617 memset (&main_subfile
, '\0', sizeof (main_subfile
));
620 /* All source lines were in the main source file. None in include
623 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
624 &main_source_baseline
);
628 /* There was source with line numbers in include files. */
631 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
632 main_source_baseline
= 0;
634 for (ii
= 0; ii
< inclIndx
; ++ii
)
636 struct subfile
*tmpSubfile
;
638 /* If there is main file source before include file, enter it. */
639 if (offset
< inclTable
[ii
].begin
)
642 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
643 start
, 0, &main_source_baseline
);
646 if (strcmp (inclTable
[ii
].name
, last_source_file
) == 0)
648 /* The entry in the include table refers to the main source
649 file. Add the lines to the main subfile. */
651 main_source_baseline
= inclTable
[ii
].funStartLine
;
653 (&main_subfile
, inclTable
[ii
].begin
, inclTable
[ii
].end
,
654 start
, 0, &main_source_baseline
);
655 inclTable
[ii
].subfile
= &main_subfile
;
659 /* Have a new subfile for the include file. */
661 tmpSubfile
= inclTable
[ii
].subfile
=
662 (struct subfile
*) xmalloc (sizeof (struct subfile
));
664 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
665 firstLine
= &(inclTable
[ii
].funStartLine
);
667 /* Enter include file's lines now. */
668 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
669 inclTable
[ii
].end
, start
, 0, firstLine
);
672 if (offset
<= inclTable
[ii
].end
)
673 offset
= inclTable
[ii
].end
+ linesz
;
676 /* All the include files' line have been processed at this point. Now,
677 enter remaining lines of the main file, if any left. */
678 if (offset
< max_offset
+ 1 - linesz
)
680 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
681 &main_source_baseline
);
685 /* Process main file's line numbers. */
686 if (main_subfile
.line_vector
)
688 struct linetable
*lineTb
, *lv
;
690 lv
= main_subfile
.line_vector
;
692 /* Line numbers are not necessarily ordered. xlc compilation will
693 put static function to the end. */
695 lineTb
= arrange_linetable (lv
);
698 current_subfile
->line_vector
= (struct linetable
*)
699 xrealloc (lv
, (sizeof (struct linetable
)
700 + lv
->nitems
* sizeof (struct linetable_entry
)));
705 current_subfile
->line_vector
= lineTb
;
708 current_subfile
->line_vector_length
=
709 current_subfile
->line_vector
->nitems
;
712 /* Now, process included files' line numbers. */
714 for (ii
= 0; ii
< inclIndx
; ++ii
)
716 if (inclTable
[ii
].subfile
!= ((struct subfile
*) &main_subfile
)
717 && (inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!!
720 struct linetable
*lineTb
, *lv
;
722 lv
= (inclTable
[ii
].subfile
)->line_vector
;
724 /* Line numbers are not necessarily ordered. xlc compilation will
725 put static function to the end. */
727 lineTb
= arrange_linetable (lv
);
731 /* For the same include file, we might want to have more than one
732 subfile. This happens if we have something like:
740 while foo.h including code in it. (stupid but possible)
741 Since start_subfile() looks at the name and uses an
742 existing one if finds, we need to provide a fake name and
746 start_subfile (inclTable
[ii
].name
, (char *) 0);
749 /* Pick a fake name that will produce the same results as this
750 one when passed to deduce_language_from_filename. Kludge on
752 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
754 if (fakename
== NULL
)
756 start_subfile (fakename
, (char *) 0);
757 xfree (current_subfile
->name
);
759 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
764 current_subfile
->line_vector
=
765 (struct linetable
*) xrealloc
766 (lv
, (sizeof (struct linetable
)
767 + lv
->nitems
* sizeof (struct linetable_entry
)));
773 current_subfile
->line_vector
= lineTb
;
776 current_subfile
->line_vector_length
=
777 current_subfile
->line_vector
->nitems
;
778 start_subfile (pop_subfile (), (char *) 0);
782 return_after_cleanup
:
784 /* We don't want to keep alloc/free'ing the global include file table. */
787 /* Start with a fresh subfile structure for the next file. */
788 memset (&main_subfile
, '\0', sizeof (struct subfile
));
792 aix_process_linenos (void)
794 /* There is no linenos to read if there are only dwarf info. */
795 if (this_symtab_psymtab
== NULL
)
798 /* Process line numbers and enter them into line vector. */
799 process_linenos (last_source_start_addr
, cur_src_end_addr
);
803 /* Enter a given range of lines into the line vector.
804 can be called in the following two ways:
805 enter_line_range (subfile, beginoffset, endoffset,
806 startaddr, 0, firstLine) or
807 enter_line_range (subfile, beginoffset, 0,
808 startaddr, endaddr, firstLine)
810 endoffset points to the last line table entry that we should pay
814 enter_line_range (struct subfile
*subfile
, unsigned beginoffset
,
815 unsigned endoffset
, /* offsets to line table */
816 CORE_ADDR startaddr
, /* offsets to line table */
817 CORE_ADDR endaddr
, unsigned *firstLine
)
819 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
820 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
821 unsigned int curoffset
;
824 struct internal_lineno int_lnno
;
825 unsigned int limit_offset
;
829 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
831 curoffset
= beginoffset
;
833 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)
838 if (endoffset
>= limit_offset
)
840 complaint (&symfile_complaints
,
841 _("Bad line table offset in C_EINCL directive"));
844 limit_offset
= endoffset
;
849 abfd
= objfile
->obfd
;
850 linesz
= coff_data (abfd
)->local_linesz
;
851 ext_lnno
= alloca (linesz
);
853 while (curoffset
<= limit_offset
)
855 bfd_seek (abfd
, curoffset
, SEEK_SET
);
856 bfd_bread (ext_lnno
, linesz
, abfd
);
857 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
859 /* Find the address this line represents. */
860 addr
= (int_lnno
.l_lnno
861 ? int_lnno
.l_addr
.l_paddr
862 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
863 addr
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
865 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
868 if (int_lnno
.l_lnno
== 0)
870 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
871 record_line (subfile
, 0, gdbarch_addr_bits_remove (gdbarch
, addr
));
875 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
,
876 gdbarch_addr_bits_remove (gdbarch
, addr
));
882 /* Save the vital information for use when closing off the current file.
883 NAME is the file name the symbols came from, START_ADDR is the first
884 text address for the file, and SIZE is the number of bytes of text. */
886 #define complete_symtab(name, start_addr) { \
887 last_source_file = xstrdup (name); \
888 last_source_start_addr = start_addr; \
892 /* Refill the symbol table input buffer
893 and set the variables that control fetching entries from it.
894 Reports an error if no data available.
895 This function can read past the end of the symbol table
896 (into the string table) but this does no harm. */
898 /* Create a new minimal symbol (using prim_record_minimal_symbol_and_info).
902 NAME - the symbol's name (but if NAME starts with a period, that
903 leading period is discarded).
904 ADDRESS - the symbol's address.
905 MS_TYPE - the symbol's type.
906 N_SCNUM - the symbol's XCOFF section number.
907 OBJFILE - the objfile associated with the minimal symbol. */
910 record_minimal_symbol (const char *name
, CORE_ADDR address
,
911 enum minimal_symbol_type ms_type
,
913 struct objfile
*objfile
)
915 struct find_targ_sec_arg args
;
922 xcoff_secnum_to_sections (n_scnum
, objfile
, &bfd_sect
, &secnum
);
923 prim_record_minimal_symbol_and_info (name
, address
, ms_type
,
924 secnum
, bfd_sect
, objfile
);
927 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
928 nested. At any given time, a symbol can only be in one static block.
929 This is the base address of current static block, zero if non exists. */
931 static int static_block_base
= 0;
933 /* Section number for the current static block. */
935 static int static_block_section
= -1;
937 /* true if space for symbol name has been allocated. */
939 static int symname_alloced
= 0;
941 /* Next symbol to read. Pointer into raw seething symbol table. */
943 static char *raw_symbol
;
945 /* This is the function which stabsread.c calls to get symbol
949 xcoff_next_symbol_text (struct objfile
*objfile
)
951 struct internal_syment symbol
;
954 /* FIXME: is this the same as the passed arg? */
955 if (this_symtab_psymtab
)
956 objfile
= this_symtab_psymtab
->objfile
;
958 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
961 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
963 /* Return something which points to '\0' and hope the symbol reading
964 code does something reasonable. */
967 else if (symbol
.n_sclass
& 0x80)
969 retval
= ((struct coff_symfile_info
*)
970 objfile
->deprecated_sym_private
)->debugsec
972 raw_symbol
+= coff_data (objfile
->obfd
)->local_symesz
;
977 complaint (&symfile_complaints
, _("Unexpected symbol continuation"));
979 /* Return something which points to '\0' and hope the symbol reading
980 code does something reasonable. */
986 /* Read symbols for a given partial symbol table. */
989 read_xcoff_symtab (struct partial_symtab
*pst
)
991 struct objfile
*objfile
= pst
->objfile
;
992 bfd
*abfd
= objfile
->obfd
;
993 char *raw_auxptr
; /* Pointer to first raw aux entry for sym. */
995 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
;
997 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->debugsec
;
998 const char *debugfmt
= bfd_xcoff_is_xcoff64 (abfd
) ? "XCOFF64" : "XCOFF";
1000 struct internal_syment symbol
[1];
1001 union internal_auxent main_aux
;
1002 struct coff_symbol cs
[1];
1003 CORE_ADDR file_start_addr
= 0;
1004 CORE_ADDR file_end_addr
= 0;
1006 int next_file_symnum
= -1;
1007 unsigned int max_symnum
;
1008 int just_started
= 1;
1010 int fcn_start_addr
= 0;
1012 struct coff_symbol fcn_stab_saved
= { 0 };
1014 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1015 union internal_auxent fcn_aux_saved
= main_aux
;
1016 struct context_stack
*new;
1018 char *filestring
= " _start_ "; /* Name of the current file. */
1020 const char *last_csect_name
; /* Last seen csect's name. */
1022 this_symtab_psymtab
= pst
;
1024 /* Get the appropriate COFF "constants" related to the file we're
1026 local_symesz
= coff_data (abfd
)->local_symesz
;
1028 last_source_file
= NULL
;
1029 last_csect_name
= 0;
1032 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
1033 record_debugformat (debugfmt
);
1034 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
1036 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
1037 first_object_file_end
= 0;
1040 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
1041 + symnum
* local_symesz
;
1043 while (symnum
< max_symnum
)
1045 QUIT
; /* make this command interruptable. */
1047 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1048 /* read one symbol into `cs' structure. After processing the
1049 whole symbol table, only string table will be kept in memory,
1050 symbol table and debug section of xcoff will be freed. Thus
1051 we can mark symbols with names in string table as
1056 /* Swap and align the symbol into a reasonable C structure. */
1057 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1059 cs
->c_symnum
= symnum
;
1060 cs
->c_naux
= symbol
->n_numaux
;
1061 if (symbol
->n_zeroes
)
1063 symname_alloced
= 0;
1064 /* We must use the original, unswapped, name here so the name field
1065 pointed to by cs->c_name will persist throughout xcoffread. If
1066 we use the new field, it gets overwritten for each symbol. */
1067 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
1068 /* If it's exactly E_SYMNMLEN characters long it isn't
1070 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1074 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
1075 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1076 p
[E_SYMNMLEN
] = '\0';
1078 symname_alloced
= 1;
1081 else if (symbol
->n_sclass
& 0x80)
1083 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1084 symname_alloced
= 0;
1088 /* in string table */
1089 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1090 symname_alloced
= 1;
1092 cs
->c_value
= symbol
->n_value
;
1093 cs
->c_sclass
= symbol
->n_sclass
;
1094 cs
->c_secnum
= symbol
->n_scnum
;
1095 cs
->c_type
= (unsigned) symbol
->n_type
;
1097 raw_symbol
+= local_symesz
;
1100 /* Save addr of first aux entry. */
1101 raw_auxptr
= raw_symbol
;
1103 /* Skip all the auxents associated with this symbol. */
1104 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1106 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1111 /* if symbol name starts with ".$" or "$", ignore it. */
1112 if (cs
->c_name
[0] == '$'
1113 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1116 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1118 if (last_source_file
)
1120 pst
->symtab
= end_symtab (cur_src_end_addr
, objfile
,
1121 SECT_OFF_TEXT (objfile
));
1126 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1127 record_debugformat (debugfmt
);
1128 cur_src_end_addr
= first_object_file_end
;
1129 /* Done with all files, everything from here on is globals. */
1132 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1135 /* Dealing with a symbol with a csect entry. */
1137 #define CSECT(PP) ((PP)->x_csect)
1138 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1139 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1140 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1141 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1143 /* Convert the auxent to something we can access. */
1144 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1145 0, cs
->c_naux
, &main_aux
);
1147 switch (CSECT_SMTYP (&main_aux
))
1151 /* Ignore all external references. */
1155 /* A section description. */
1157 switch (CSECT_SCLAS (&main_aux
))
1163 /* A program csect is seen. We have to allocate one
1164 symbol table for each program csect. Normally gdb
1165 prefers one symtab for each source file. In case
1166 of AIX, one source file might include more than one
1167 [PR] csect, and they don't have to be adjacent in
1168 terms of the space they occupy in memory. Thus, one
1169 single source file might get fragmented in the
1170 memory and gdb's file start and end address
1171 approach does not work! GCC (and I think xlc) seem
1172 to put all the code in the unnamed program csect. */
1174 if (last_csect_name
)
1176 complete_symtab (filestring
, file_start_addr
);
1177 cur_src_end_addr
= file_end_addr
;
1178 end_symtab (file_end_addr
, objfile
,
1179 SECT_OFF_TEXT (objfile
));
1182 /* Give all csects for this source file the same
1184 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1185 record_debugformat (debugfmt
);
1188 /* If this is the very first csect seen,
1189 basically `__start'. */
1192 first_object_file_end
1193 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1198 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1199 SECT_OFF_TEXT (objfile
));
1200 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1202 if (cs
->c_name
&& (cs
->c_name
[0] == '.' || cs
->c_name
[0] == '@'))
1203 last_csect_name
= cs
->c_name
;
1207 /* All other symbols are put into the minimal symbol
1220 /* Ignore the symbol. */
1228 switch (CSECT_SCLAS (&main_aux
))
1231 /* a function entry point. */
1232 function_entry_point
:
1234 fcn_start_addr
= cs
->c_value
;
1236 /* save the function header info, which will be used
1237 when `.bf' is seen. */
1239 fcn_aux_saved
= main_aux
;
1243 /* shared library function trampoline code entry point. */
1247 /* The symbols often have the same names as debug symbols for
1248 functions, and confuse lookup_symbol. */
1252 /* xlc puts each variable in a separate csect, so we get
1253 an XTY_SD for each variable. But gcc puts several
1254 variables in a csect, so that each variable only gets
1255 an XTY_LD. This will typically be XMC_RW; I suspect
1256 XMC_RO and XMC_BS might be possible too.
1257 These variables are put in the minimal symbol table
1264 /* Common symbols are put into the minimal symbol table only. */
1272 /* If explicitly specified as a function, treat is as one. This check
1273 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1274 after the above CSECT check. */
1275 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1277 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1278 0, cs
->c_naux
, &main_aux
);
1279 goto function_entry_point
;
1282 switch (cs
->c_sclass
)
1286 /* c_value field contains symnum of next .file entry in table
1287 or symnum of first global after last .file. */
1289 next_file_symnum
= cs
->c_value
;
1291 /* Complete symbol table for last object file containing
1292 debugging information. */
1294 /* Whether or not there was a csect in the previous file, we
1295 have to call `end_stabs' and `start_stabs' to reset
1296 type_vector, line_vector, etc. structures. */
1298 complete_symtab (filestring
, file_start_addr
);
1299 cur_src_end_addr
= file_end_addr
;
1300 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1303 /* XCOFF, according to the AIX 3.2 documentation, puts the
1304 filename in cs->c_name. But xlc 1.3.0.2 has decided to
1305 do things the standard COFF way and put it in the auxent.
1306 We use the auxent if the symbol is ".file" and an auxent
1307 exists, otherwise use the symbol itself. Simple
1309 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1311 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1312 0, cs
->c_naux
, &main_aux
);
1313 filestring
= coff_getfilename (&main_aux
, objfile
);
1316 filestring
= cs
->c_name
;
1319 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1320 record_debugformat (debugfmt
);
1321 last_csect_name
= 0;
1323 /* reset file start and end addresses. A compilation unit
1324 with no text (only data) should have zero file
1326 file_start_addr
= file_end_addr
= 0;
1330 fcn_stab_saved
= *cs
;
1334 if (strcmp (cs
->c_name
, ".bf") == 0)
1336 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1337 SECT_OFF_TEXT (objfile
));
1339 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1340 0, cs
->c_naux
, &main_aux
);
1342 within_function
= 1;
1344 new = push_context (0, fcn_start_addr
+ off
);
1346 new->name
= define_symbol
1347 (fcn_cs_saved
.c_value
+ off
,
1348 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1349 if (new->name
!= NULL
)
1350 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1352 else if (strcmp (cs
->c_name
, ".ef") == 0)
1354 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1355 0, cs
->c_naux
, &main_aux
);
1357 /* The value of .ef is the address of epilogue code;
1358 not useful for gdb. */
1359 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1360 contains number of lines to '}' */
1362 if (context_stack_depth
<= 0)
1363 { /* We attempted to pop an empty context stack. */
1364 ef_complaint (cs
->c_symnum
);
1365 within_function
= 0;
1368 new = pop_context ();
1369 /* Stack must be empty now. */
1370 if (context_stack_depth
> 0 || new == NULL
)
1372 ef_complaint (cs
->c_symnum
);
1373 within_function
= 0;
1377 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1379 (fcn_cs_saved
.c_value
1380 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1381 + ANOFFSET (objfile
->section_offsets
,
1382 SECT_OFF_TEXT (objfile
))),
1384 within_function
= 0;
1389 /* Begin static block. */
1391 struct internal_syment symbol
;
1393 read_symbol (&symbol
, cs
->c_value
);
1394 static_block_base
= symbol
.n_value
;
1395 static_block_section
=
1396 secnum_to_section (symbol
.n_scnum
, objfile
);
1401 /* End of static block. */
1402 static_block_base
= 0;
1403 static_block_section
= -1;
1414 complaint (&symfile_complaints
,
1415 _("Unrecognized storage class %d."),
1430 /* beginning of include file */
1431 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1432 order. Thus, when wee see them, we might not know enough info
1433 to process them. Thus, we'll be saving them into a table
1434 (inclTable) and postpone their processing. */
1436 record_include_begin (cs
);
1440 /* End of include file. */
1441 /* See the comment after case C_BINCL. */
1442 record_include_end (cs
);
1446 if (strcmp (cs
->c_name
, ".bb") == 0)
1449 new = push_context (depth
,
1451 + ANOFFSET (objfile
->section_offsets
,
1452 SECT_OFF_TEXT (objfile
))));
1454 else if (strcmp (cs
->c_name
, ".eb") == 0)
1456 if (context_stack_depth
<= 0)
1457 { /* We attempted to pop an empty context stack. */
1458 eb_complaint (cs
->c_symnum
);
1461 new = pop_context ();
1462 if (depth
-- != new->depth
)
1464 eb_complaint (cs
->c_symnum
);
1467 if (local_symbols
&& context_stack_depth
> 0)
1469 /* Make a block for the local symbols within. */
1470 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1473 + ANOFFSET (objfile
->section_offsets
,
1474 SECT_OFF_TEXT (objfile
))),
1477 local_symbols
= new->locals
;
1482 process_xcoff_symbol (cs
, objfile
);
1487 if (last_source_file
)
1491 complete_symtab (filestring
, file_start_addr
);
1492 cur_src_end_addr
= file_end_addr
;
1493 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1494 /* When reading symbols for the last C_FILE of the objfile, try
1495 to make sure that we set pst->symtab to the symtab for the
1496 file, not to the _globals_ symtab. I'm not sure whether this
1497 actually works right or when/if it comes up. */
1498 if (pst
->symtab
== NULL
)
1504 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1505 (SYMBOL2) = (struct symbol *) \
1506 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1507 *(SYMBOL2) = *(SYMBOL1);
1510 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1511 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), \
1512 &objfile->objfile_obstack))
1515 /* process one xcoff symbol. */
1517 static struct symbol
*
1518 process_xcoff_symbol (struct coff_symbol
*cs
, struct objfile
*objfile
)
1520 struct symbol onesymbol
;
1521 struct symbol
*sym
= &onesymbol
;
1522 struct symbol
*sym2
= NULL
;
1528 if (cs
->c_secnum
< 0)
1530 /* The value is a register number, offset within a frame, etc.,
1531 and does not get relocated. */
1537 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1538 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1545 memset (sym
, '\0', sizeof (struct symbol
));
1547 /* default assumptions */
1548 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1549 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1550 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1552 if (ISFCN (cs
->c_type
))
1554 /* At this point, we don't know the type of the function. This
1555 will be patched with the type from its stab entry later on in
1556 patch_block_stabs (), unless the file was compiled without -g. */
1558 SYMBOL_SET_LINKAGE_NAME (sym
, SYMNAME_ALLOC (name
, symname_alloced
));
1559 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_text_symbol
;
1561 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1562 SYMBOL_DUP (sym
, sym2
);
1564 if (cs
->c_sclass
== C_EXT
)
1565 add_symbol_to_list (sym2
, &global_symbols
);
1566 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1567 add_symbol_to_list (sym2
, &file_symbols
);
1571 /* In case we can't figure out the type, provide default. */
1572 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->nodebug_data_symbol
;
1574 switch (cs
->c_sclass
)
1577 /* The values of functions and global symbols are now resolved
1578 via the global_sym_chain in stabsread.c. */
1580 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1581 add_stab_to_list (name
, &global_stabs
);
1583 add_stab_to_list (name
, &file_stabs
);
1587 add_stab_to_list (name
, &global_stabs
);
1592 common_block_start (cs
->c_name
, objfile
);
1596 common_block_end (objfile
);
1600 complaint (&symfile_complaints
, _("Unexpected storage class: %d"),
1613 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1616 SYMBOL_SECTION (sym
) = sec
;
1623 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1624 all statics and we need to distinguish file-scope versus
1625 function-scope using within_function. We do this by
1626 changing the string we pass to define_symbol to use 'S'
1627 where we need to, which is not necessarily super-clean,
1628 but seems workable enough. */
1633 pp
= strchr (name
, ':');
1638 if (*pp
== 'V' && !within_function
)
1640 sym
= define_symbol ((cs
->c_value
1641 + ANOFFSET (objfile
->section_offsets
,
1642 static_block_section
)),
1643 cs
->c_name
, 0, 0, objfile
);
1646 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1647 SYMBOL_SECTION (sym
) = static_block_section
;
1656 /* Extract the file name from the aux entry of a C_FILE symbol.
1657 Result is in static storage and is only good for temporary use. */
1660 coff_getfilename (union internal_auxent
*aux_entry
, struct objfile
*objfile
)
1662 static char buffer
[BUFSIZ
];
1664 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1665 strcpy (buffer
, ((struct coff_symfile_info
*)
1666 objfile
->deprecated_sym_private
)->strtbl
1667 + aux_entry
->x_file
.x_n
.x_offset
);
1670 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1671 buffer
[FILNMLEN
] = '\0';
1676 /* Set *SYMBOL to symbol number symno in symtbl. */
1678 read_symbol (struct internal_syment
*symbol
, int symno
)
1681 = ((struct coff_symfile_info
*)
1682 this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl_num_syms
;
1683 char *stbl
= ((struct coff_symfile_info
*)
1684 this_symtab_psymtab
->objfile
->deprecated_sym_private
)->symtbl
;
1686 if (symno
< 0 || symno
>= nsyms
)
1688 complaint (&symfile_complaints
, _("Invalid symbol offset"));
1689 symbol
->n_value
= 0;
1690 symbol
->n_scnum
= -1;
1693 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1694 stbl
+ (symno
* local_symesz
),
1698 /* Get value corresponding to symbol number symno in symtbl. */
1701 read_symbol_nvalue (int symno
)
1703 struct internal_syment symbol
[1];
1705 read_symbol (symbol
, symno
);
1706 return symbol
->n_value
;
1710 /* Find the address of the function corresponding to symno, where
1711 symno is the symbol pointed to by the linetable. */
1714 read_symbol_lineno (int symno
)
1716 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1717 int xcoff64
= bfd_xcoff_is_xcoff64 (objfile
->obfd
);
1719 struct coff_symfile_info
*info
=
1720 (struct coff_symfile_info
*)objfile
->deprecated_sym_private
;
1721 int nsyms
= info
->symtbl_num_syms
;
1722 char *stbl
= info
->symtbl
;
1723 char *strtbl
= info
->strtbl
;
1725 struct internal_syment symbol
[1];
1726 union internal_auxent main_aux
[1];
1730 bf_notfound_complaint ();
1734 /* Note that just searching for a short distance (e.g. 50 symbols)
1735 is not enough, at least in the following case.
1738 [many .stabx entries]
1739 [a few functions, referring to foo]
1743 What happens here is that the assembler moves the .stabx entries
1744 to right before the ".bf" for foo, but the symbol for "foo" is before
1745 all the stabx entries. See PR gdb/2222. */
1747 /* Maintaining a table of .bf entries might be preferable to this search.
1748 If I understand things correctly it would need to be done only for
1749 the duration of a single psymtab to symtab conversion. */
1750 while (symno
< nsyms
)
1752 bfd_coff_swap_sym_in (symfile_bfd
,
1753 stbl
+ (symno
* local_symesz
), symbol
);
1754 if (symbol
->n_sclass
== C_FCN
)
1756 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1758 if (strcmp (name
, ".bf") == 0)
1761 symno
+= symbol
->n_numaux
+ 1;
1764 bf_notfound_complaint ();
1768 /* Take aux entry and return its lineno. */
1770 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1771 symbol
->n_type
, symbol
->n_sclass
,
1772 0, symbol
->n_numaux
, main_aux
);
1774 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1777 /* Support for line number handling. */
1779 /* This function is called for every section; it finds the outer limits
1780 * of the line table (minimum and maximum file offset) so that the
1781 * mainline code can read the whole thing for efficiency.
1784 find_linenos (struct bfd
*abfd
, struct bfd_section
*asect
, void *vpinfo
)
1786 struct coff_symfile_info
*info
;
1788 file_ptr offset
, maxoff
;
1790 count
= asect
->lineno_count
;
1792 if (strcmp (asect
->name
, ".text") != 0 || count
== 0)
1795 size
= count
* coff_data (abfd
)->local_linesz
;
1796 info
= (struct coff_symfile_info
*) vpinfo
;
1797 offset
= asect
->line_filepos
;
1798 maxoff
= offset
+ size
;
1800 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1801 info
->min_lineno_offset
= offset
;
1803 if (maxoff
> info
->max_lineno_offset
)
1804 info
->max_lineno_offset
= maxoff
;
1807 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1810 xcoff_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1812 struct cleanup
*old_chain
;
1821 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1826 /* Read in all partial symtabs on which this one is dependent. */
1827 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1828 if (!pst
->dependencies
[i
]->readin
)
1830 /* Inform about additional files that need to be read in. */
1833 fputs_filtered (" ", gdb_stdout
);
1835 fputs_filtered ("and ", gdb_stdout
);
1837 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1838 wrap_here (""); /* Flush output */
1839 gdb_flush (gdb_stdout
);
1841 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1844 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1846 /* Init stuff necessary for reading in symbols. */
1849 old_chain
= make_cleanup (really_free_pendings
, 0);
1851 read_xcoff_symtab (pst
);
1853 do_cleanups (old_chain
);
1859 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1861 /* Read in all of the symbols for a given psymtab for real.
1862 Be verbose about it if the user wants that. */
1865 xcoff_psymtab_to_symtab (struct partial_symtab
*pst
)
1875 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1880 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1881 || pst
->number_of_dependencies
)
1883 /* Print the message now, before reading the string table,
1884 to avoid disconcerting pauses. */
1887 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1888 gdb_flush (gdb_stdout
);
1891 sym_bfd
= pst
->objfile
->obfd
;
1893 next_symbol_text_func
= xcoff_next_symbol_text
;
1895 xcoff_psymtab_to_symtab_1 (pst
);
1897 /* Match with global symbols. This only needs to be done once,
1898 after all of the symtabs and dependencies have been read in. */
1899 scan_file_globals (pst
->objfile
);
1901 /* Finish up the debug error message. */
1903 printf_filtered ("done.\n");
1908 xcoff_new_init (struct objfile
*objfile
)
1910 stabsread_new_init ();
1911 buildsym_new_init ();
1914 /* Do initialization in preparation for reading symbols from OBJFILE.
1916 We will only be called if this is an XCOFF or XCOFF-like file.
1917 BFD handles figuring out the format of the file, and code in symfile.c
1918 uses BFD's determination to vector to us. */
1921 xcoff_symfile_init (struct objfile
*objfile
)
1923 /* Allocate struct to keep track of the symfile. */
1924 objfile
->deprecated_sym_private
1925 = xmalloc (sizeof (struct coff_symfile_info
));
1927 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1928 find this causes a significant slowdown in gdb then we could
1929 set it in the debug symbol readers only when necessary. */
1930 objfile
->flags
|= OBJF_REORDERED
;
1932 init_entry_point_info (objfile
);
1935 /* Perform any local cleanups required when we are done with a particular
1936 objfile. I.E, we are in the process of discarding all symbol information
1937 for an objfile, freeing up all memory held for it, and unlinking the
1938 objfile struct from the global list of known objfiles. */
1941 xcoff_symfile_finish (struct objfile
*objfile
)
1943 if (objfile
->deprecated_sym_private
!= NULL
)
1945 xfree (objfile
->deprecated_sym_private
);
1948 /* Start with a fresh include table for the next objfile. */
1954 inclIndx
= inclLength
= inclDepth
= 0;
1956 dwarf2_free_objfile (objfile
);
1961 init_stringtab (bfd
*abfd
, file_ptr offset
, struct objfile
*objfile
)
1965 unsigned char lengthbuf
[4];
1968 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
1971 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1972 error (_("cannot seek to string table in %s: %s"),
1973 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1975 val
= bfd_bread ((char *) lengthbuf
, sizeof lengthbuf
, abfd
);
1976 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1978 /* If no string table is needed, then the file may end immediately
1979 after the symbols. Just return with `strtbl' set to NULL. */
1981 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1984 /* Allocate string table from objfile_obstack. We will need this table
1985 as long as we have its symbol table around. */
1987 strtbl
= (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
1988 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->strtbl
1991 /* Copy length buffer, the first byte is usually zero and is
1992 used for stabs with a name length of zero. */
1993 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1994 if (length
== sizeof lengthbuf
)
1997 val
= bfd_bread (strtbl
+ sizeof lengthbuf
, length
- sizeof lengthbuf
, abfd
);
1999 if (val
!= length
- sizeof lengthbuf
)
2000 error (_("cannot read string table from %s: %s"),
2001 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
2002 if (strtbl
[length
- 1] != '\0')
2003 error (_("bad symbol file: string table "
2004 "does not end with null character"));
2009 /* If we have not yet seen a function for this psymtab, this is 0. If we
2010 have seen one, it is the offset in the line numbers of the line numbers
2012 static unsigned int first_fun_line_offset
;
2014 /* Allocate and partially fill a partial symtab. It will be
2015 completely filled at the end of the symbol list.
2017 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2018 is the address relative to which its symbols are (incremental) or 0
2021 static struct partial_symtab
*
2022 xcoff_start_psymtab (struct objfile
*objfile
,
2023 const char *filename
, int first_symnum
,
2024 struct partial_symbol
**global_syms
,
2025 struct partial_symbol
**static_syms
)
2027 struct partial_symtab
*result
=
2028 start_psymtab_common (objfile
, objfile
->section_offsets
,
2030 /* We fill in textlow later. */
2032 global_syms
, static_syms
);
2034 result
->read_symtab_private
= obstack_alloc (&objfile
->objfile_obstack
,
2035 sizeof (struct symloc
));
2036 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
2037 result
->read_symtab
= xcoff_psymtab_to_symtab
;
2039 /* Deduce the source language from the filename for this psymtab. */
2040 psymtab_language
= deduce_language_from_filename (filename
);
2045 /* Close off the current usage of PST.
2046 Returns PST, or NULL if the partial symtab was empty and thrown away.
2048 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2050 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2051 are the information for includes and dependencies. */
2053 static struct partial_symtab
*
2054 xcoff_end_psymtab (struct partial_symtab
*pst
, const char **include_list
,
2055 int num_includes
, int capping_symbol_number
,
2056 struct partial_symtab
**dependency_list
,
2057 int number_dependencies
, int textlow_not_set
)
2060 struct objfile
*objfile
= pst
->objfile
;
2062 if (capping_symbol_number
!= -1)
2063 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
2064 capping_symbol_number
2065 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
2066 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
2067 first_fun_line_offset
;
2068 first_fun_line_offset
= 0;
2069 pst
->n_global_syms
= objfile
->global_psymbols
.next
2070 - (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2071 pst
->n_static_syms
= objfile
->static_psymbols
.next
2072 - (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2074 pst
->number_of_dependencies
= number_dependencies
;
2075 if (number_dependencies
)
2077 pst
->dependencies
= (struct partial_symtab
**)
2078 obstack_alloc (&objfile
->objfile_obstack
,
2079 number_dependencies
* sizeof (struct partial_symtab
*));
2080 memcpy (pst
->dependencies
, dependency_list
,
2081 number_dependencies
* sizeof (struct partial_symtab
*));
2084 pst
->dependencies
= 0;
2086 for (i
= 0; i
< num_includes
; i
++)
2088 struct partial_symtab
*subpst
=
2089 allocate_psymtab (include_list
[i
], objfile
);
2091 subpst
->section_offsets
= pst
->section_offsets
;
2092 subpst
->read_symtab_private
= obstack_alloc (&objfile
->objfile_obstack
,
2093 sizeof (struct symloc
));
2094 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2095 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2096 subpst
->textlow
= 0;
2097 subpst
->texthigh
= 0;
2099 /* We could save slight bits of space by only making one of these,
2100 shared by the entire set of include files. FIXME-someday. */
2101 subpst
->dependencies
= (struct partial_symtab
**)
2102 obstack_alloc (&objfile
->objfile_obstack
,
2103 sizeof (struct partial_symtab
*));
2104 subpst
->dependencies
[0] = pst
;
2105 subpst
->number_of_dependencies
= 1;
2107 subpst
->globals_offset
=
2108 subpst
->n_global_syms
=
2109 subpst
->statics_offset
=
2110 subpst
->n_static_syms
= 0;
2114 subpst
->read_symtab
= pst
->read_symtab
;
2117 sort_pst_symbols (pst
);
2119 if (num_includes
== 0
2120 && number_dependencies
== 0
2121 && pst
->n_global_syms
== 0
2122 && pst
->n_static_syms
== 0)
2124 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2125 it is on the obstack, but we can forget to chain it on the list. */
2126 /* Empty psymtabs happen as a result of header files which don't have
2127 any symbols in them. There can be a lot of them. */
2129 discard_psymtab (pst
);
2131 /* Indicate that psymtab was thrown away. */
2132 pst
= (struct partial_symtab
*) NULL
;
2137 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2138 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2139 the symbol and its auxents. */
2142 swap_sym (struct internal_syment
*symbol
, union internal_auxent
*aux
,
2143 const char **name
, char **raw
, unsigned int *symnump
,
2144 struct objfile
*objfile
)
2146 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2147 if (symbol
->n_zeroes
)
2149 /* If it's exactly E_SYMNMLEN characters long it isn't
2151 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2153 /* FIXME: wastes memory for symbols which we don't end up putting
2154 into the minimal symbols. */
2157 p
= obstack_alloc (&objfile
->objfile_obstack
, E_SYMNMLEN
+ 1);
2158 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2159 p
[E_SYMNMLEN
] = '\0';
2163 /* Point to the unswapped name as that persists as long as the
2165 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2167 else if (symbol
->n_sclass
& 0x80)
2169 *name
= ((struct coff_symfile_info
*)
2170 objfile
->deprecated_sym_private
)->debugsec
+ symbol
->n_offset
;
2174 *name
= ((struct coff_symfile_info
*)
2175 objfile
->deprecated_sym_private
)->strtbl
+ symbol
->n_offset
;
2178 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2179 if (symbol
->n_numaux
> 0)
2181 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2182 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2184 *symnump
+= symbol
->n_numaux
;
2185 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2190 function_outside_compilation_unit_complaint (const char *arg1
)
2192 complaint (&symfile_complaints
,
2193 _("function `%s' appears to be defined "
2194 "outside of all compilation units"),
2199 scan_xcoff_symtab (struct objfile
*objfile
)
2201 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2202 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2203 const char *filestring
= NULL
;
2205 const char *namestring
;
2206 int past_first_source_file
= 0;
2211 /* Current partial symtab */
2212 struct partial_symtab
*pst
;
2214 /* List of current psymtab's include files. */
2215 const char **psymtab_include_list
;
2216 int includes_allocated
;
2219 /* Index within current psymtab dependency list. */
2220 struct partial_symtab
**dependency_list
;
2221 int dependencies_used
, dependencies_allocated
;
2224 struct internal_syment symbol
;
2225 union internal_auxent main_aux
[5];
2226 unsigned int ssymnum
;
2228 const char *last_csect_name
= NULL
; /* Last seen csect's name and value. */
2229 CORE_ADDR last_csect_val
= 0;
2230 int last_csect_sec
= 0;
2231 int misc_func_recorded
= 0; /* true if any misc. function. */
2232 int textlow_not_set
= 1;
2234 pst
= (struct partial_symtab
*) 0;
2236 includes_allocated
= 30;
2238 psymtab_include_list
= (const char **) alloca (includes_allocated
*
2239 sizeof (const char *));
2241 dependencies_allocated
= 30;
2242 dependencies_used
= 0;
2244 (struct partial_symtab
**) alloca (dependencies_allocated
*
2245 sizeof (struct partial_symtab
*));
2247 last_source_file
= NULL
;
2249 abfd
= objfile
->obfd
;
2250 next_symbol_text_func
= xcoff_next_symbol_text
;
2252 sraw_symbol
= ((struct coff_symfile_info
*)
2253 objfile
->deprecated_sym_private
)->symtbl
;
2254 nsyms
= ((struct coff_symfile_info
*)
2255 objfile
->deprecated_sym_private
)->symtbl_num_syms
;
2257 while (ssymnum
< nsyms
)
2263 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2264 sclass
= symbol
.n_sclass
;
2271 /* The CSECT auxent--always the last auxent. */
2272 union internal_auxent csect_aux
;
2273 unsigned int symnum_before
= ssymnum
;
2275 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2277 if (symbol
.n_numaux
> 1)
2279 bfd_coff_swap_aux_in
2281 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2284 symbol
.n_numaux
- 1,
2289 csect_aux
= main_aux
[0];
2291 /* If symbol name starts with ".$" or "$", ignore it. */
2292 if (namestring
[0] == '$'
2293 || (namestring
[0] == '.' && namestring
[1] == '$'))
2296 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2299 switch (csect_aux
.x_csect
.x_smclas
)
2302 if (last_csect_name
)
2304 /* If no misc. function recorded in the last
2305 seen csect, enter it as a function. This
2306 will take care of functions like strcmp()
2309 if (!misc_func_recorded
)
2311 record_minimal_symbol
2312 (last_csect_name
, last_csect_val
,
2313 mst_text
, last_csect_sec
, objfile
);
2314 misc_func_recorded
= 1;
2319 /* We have to allocate one psymtab for
2320 each program csect, because their text
2321 sections need not be adjacent. */
2323 (pst
, psymtab_include_list
, includes_used
,
2324 symnum_before
, dependency_list
,
2325 dependencies_used
, textlow_not_set
);
2327 dependencies_used
= 0;
2328 /* Give all psymtabs for this source file the same
2330 pst
= xcoff_start_psymtab
2334 objfile
->global_psymbols
.next
,
2335 objfile
->static_psymbols
.next
);
2338 /* Activate the misc_func_recorded mechanism for
2339 compiler- and linker-generated CSECTs like ".strcmp"
2341 if (namestring
&& (namestring
[0] == '.'
2342 || namestring
[0] == '@'))
2344 last_csect_name
= namestring
;
2345 last_csect_val
= symbol
.n_value
;
2346 last_csect_sec
= symbol
.n_scnum
;
2351 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2353 if (highval
> pst
->texthigh
)
2354 pst
->texthigh
= highval
;
2355 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2356 pst
->textlow
= symbol
.n_value
;
2358 misc_func_recorded
= 0;
2363 /* Data variables are recorded in the minimal symbol
2364 table, except for section symbols. */
2365 if (*namestring
!= '.')
2366 prim_record_minimal_symbol_and_info
2367 (namestring
, symbol
.n_value
,
2368 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2369 secnum_to_section (symbol
.n_scnum
, objfile
),
2370 secnum_to_bfd_section (symbol
.n_scnum
, objfile
),
2376 warning (_("More than one XMC_TC0 symbol found."));
2377 toc_offset
= symbol
.n_value
;
2379 /* Make TOC offset relative to start address of
2381 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2383 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2387 /* These symbols tell us where the TOC entry for a
2388 variable is, not the variable itself. */
2397 switch (csect_aux
.x_csect
.x_smclas
)
2400 /* A function entry point. */
2402 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2403 first_fun_line_offset
=
2404 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2406 record_minimal_symbol
2407 (namestring
, symbol
.n_value
,
2408 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2409 symbol
.n_scnum
, objfile
);
2410 misc_func_recorded
= 1;
2415 /* shared library function trampoline code entry
2418 /* record trampoline code entries as
2419 mst_solib_trampoline symbol. When we lookup mst
2420 symbols, we will choose mst_text over
2421 mst_solib_trampoline. */
2422 record_minimal_symbol
2423 (namestring
, symbol
.n_value
,
2424 mst_solib_trampoline
, symbol
.n_scnum
, objfile
);
2425 misc_func_recorded
= 1;
2429 /* The symbols often have the same names as
2430 debug symbols for functions, and confuse
2436 /* xlc puts each variable in a separate csect,
2437 so we get an XTY_SD for each variable. But
2438 gcc puts several variables in a csect, so
2439 that each variable only gets an XTY_LD. We
2440 still need to record them. This will
2441 typically be XMC_RW; I suspect XMC_RO and
2442 XMC_BS might be possible too. */
2443 if (*namestring
!= '.')
2444 prim_record_minimal_symbol_and_info
2445 (namestring
, symbol
.n_value
,
2446 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2447 secnum_to_section (symbol
.n_scnum
, objfile
),
2448 secnum_to_bfd_section (symbol
.n_scnum
, objfile
),
2455 switch (csect_aux
.x_csect
.x_smclas
)
2459 /* Common variables are recorded in the minimal symbol
2460 table, except for section symbols. */
2461 if (*namestring
!= '.')
2462 prim_record_minimal_symbol_and_info
2463 (namestring
, symbol
.n_value
,
2464 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2465 secnum_to_section (symbol
.n_scnum
, objfile
),
2466 secnum_to_bfd_section (symbol
.n_scnum
, objfile
),
2479 unsigned int symnum_before
;
2481 symnum_before
= ssymnum
;
2482 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2485 /* See if the last csect needs to be recorded. */
2487 if (last_csect_name
&& !misc_func_recorded
)
2489 /* If no misc. function recorded in the last seen csect, enter
2490 it as a function. This will take care of functions like
2491 strcmp() compiled by xlc. */
2493 record_minimal_symbol (last_csect_name
, last_csect_val
,
2494 mst_text
, last_csect_sec
, objfile
);
2495 misc_func_recorded
= 1;
2500 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2501 symnum_before
, dependency_list
,
2502 dependencies_used
, textlow_not_set
);
2504 dependencies_used
= 0;
2506 first_fun_line_offset
= 0;
2508 /* XCOFF, according to the AIX 3.2 documentation, puts the
2509 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2510 do things the standard COFF way and put it in the auxent.
2511 We use the auxent if the symbol is ".file" and an auxent
2512 exists, otherwise use the symbol itself. */
2513 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2515 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2518 filestring
= namestring
;
2520 pst
= xcoff_start_psymtab (objfile
,
2523 objfile
->global_psymbols
.next
,
2524 objfile
->static_psymbols
.next
);
2525 last_csect_name
= NULL
;
2531 complaint (&symfile_complaints
,
2532 _("Storage class %d not recognized during scan"),
2537 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2538 to handle only the C_FUN and C_EXT. */
2553 /* C_EINCL means we are switching back to the main file. But there
2554 is no reason to care; the only thing we want to know about
2555 includes is the names of all the included (.h) files. */
2560 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2564 /* I don't think the name of the common block (as opposed to the
2565 variables within it) is something which is user visible
2573 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2574 so C_LSYM would appear to be only for locals. */
2580 /* We probably could save a few instructions by assuming that
2581 C_LSYM, C_PSYM, etc., never have auxents. */
2582 int naux1
= symbol
.n_numaux
+ 1;
2585 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2591 /* Mark down an include file in the current psymtab. */
2592 enum language tmp_language
;
2594 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2597 tmp_language
= deduce_language_from_filename (namestring
);
2599 /* Only change the psymtab's language if we've learned
2600 something useful (eg. tmp_language is not language_unknown).
2601 In addition, to match what start_subfile does, never change
2603 if (tmp_language
!= language_unknown
2604 && (tmp_language
!= language_c
2605 || psymtab_language
!= language_cplus
))
2606 psymtab_language
= tmp_language
;
2608 /* In C++, one may expect the same filename to come round many
2609 times, when code is coming alternately from the main file
2610 and from inline functions in other files. So I check to see
2611 if this is a file we've seen before -- either the main
2612 source file, or a previously included file.
2614 This seems to be a lot of time to be spending on N_SOL, but
2615 things like "break c-exp.y:435" need to work (I
2616 suppose the psymtab_include_list could be hashed or put
2617 in a binary tree, if profiling shows this is a major hog). */
2618 if (pst
&& strcmp (namestring
, pst
->filename
) == 0)
2624 for (i
= 0; i
< includes_used
; i
++)
2625 if (strcmp (namestring
, psymtab_include_list
[i
]) == 0)
2633 psymtab_include_list
[includes_used
++] = namestring
;
2634 if (includes_used
>= includes_allocated
)
2636 const char **orig
= psymtab_include_list
;
2638 psymtab_include_list
= (const char **)
2639 alloca ((includes_allocated
*= 2) *
2640 sizeof (const char *));
2641 memcpy (psymtab_include_list
, orig
,
2642 includes_used
* sizeof (const char *));
2647 /* The value of the C_FUN is not the address of the function (it
2648 appears to be the address before linking), but as long as it
2649 is smaller than the actual address, then find_pc_partial_function
2650 will use the minimal symbols instead. I hope. */
2659 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2662 p
= strchr (namestring
, ':');
2664 continue; /* Not a debugging symbol. */
2666 /* Main processing section for debugging symbols which
2667 the initial read through the symbol tables needs to worry
2668 about. If we reach this point, the symbol which we are
2669 considering is definitely one we are interested in.
2670 p must also contain the (valid) index into the namestring
2671 which indicates the debugging type symbol. */
2676 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
,
2677 SECT_OFF_DATA (objfile
));
2679 if (gdbarch_static_transform_name_p (gdbarch
))
2680 namestring
= gdbarch_static_transform_name
2681 (gdbarch
, namestring
);
2683 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2684 VAR_DOMAIN
, LOC_STATIC
,
2685 &objfile
->static_psymbols
,
2687 psymtab_language
, objfile
);
2691 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
,
2692 SECT_OFF_DATA (objfile
));
2693 /* The addresses in these entries are reported to be
2694 wrong. See the code that reads 'G's for symtabs. */
2695 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2696 VAR_DOMAIN
, LOC_STATIC
,
2697 &objfile
->global_psymbols
,
2699 psymtab_language
, objfile
);
2703 /* When a 'T' entry is defining an anonymous enum, it
2704 may have a name which is the empty string, or a
2705 single space. Since they're not really defining a
2706 symbol, those shouldn't go in the partial symbol
2707 table. We do pick up the elements of such enums at
2708 'check_enum:', below. */
2709 if (p
>= namestring
+ 2
2710 || (p
== namestring
+ 1
2711 && namestring
[0] != ' '))
2713 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2714 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2715 &objfile
->static_psymbols
,
2717 psymtab_language
, objfile
);
2720 /* Also a typedef with the same name. */
2721 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2722 VAR_DOMAIN
, LOC_TYPEDEF
,
2723 &objfile
->static_psymbols
,
2725 psymtab_language
, objfile
);
2732 if (p
!= namestring
) /* a name is there, not just :T... */
2734 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2735 VAR_DOMAIN
, LOC_TYPEDEF
,
2736 &objfile
->static_psymbols
,
2738 psymtab_language
, objfile
);
2741 /* If this is an enumerated type, we need to
2742 add all the enum constants to the partial symbol
2743 table. This does not cover enums without names, e.g.
2744 "enum {a, b} c;" in C, but fortunately those are
2745 rare. There is no way for GDB to find those from the
2746 enum type without spending too much time on it. Thus
2747 to solve this problem, the compiler needs to put out the
2748 enum in a nameless type. GCC2 does this. */
2750 /* We are looking for something of the form
2751 <name> ":" ("t" | "T") [<number> "="] "e"
2752 {<constant> ":" <value> ","} ";". */
2754 /* Skip over the colon and the 't' or 'T'. */
2756 /* This type may be given a number. Also, numbers can come
2757 in pairs like (0,26). Skip over it. */
2758 while ((*p
>= '0' && *p
<= '9')
2759 || *p
== '(' || *p
== ',' || *p
== ')'
2765 /* The aix4 compiler emits extra crud before the
2769 /* Skip over the type (?). */
2773 /* Skip over the colon. */
2777 /* We have found an enumerated type. */
2778 /* According to comments in read_enum_type
2779 a comma could end it instead of a semicolon.
2780 I don't know where that happens.
2782 while (*p
&& *p
!= ';' && *p
!= ',')
2786 /* Check for and handle cretinous dbx symbol name
2788 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
2789 p
= next_symbol_text (objfile
);
2791 /* Point to the character after the name
2792 of the enum constant. */
2793 for (q
= p
; *q
&& *q
!= ':'; q
++)
2795 /* Note that the value doesn't matter for
2796 enum constants in psymtabs, just in symtabs. */
2797 add_psymbol_to_list (p
, q
- p
, 1,
2798 VAR_DOMAIN
, LOC_CONST
,
2799 &objfile
->static_psymbols
, 0,
2800 0, psymtab_language
, objfile
);
2801 /* Point past the name. */
2803 /* Skip over the value. */
2804 while (*p
&& *p
!= ',')
2806 /* Advance past the comma. */
2814 /* Constant, e.g. from "const" in Pascal. */
2815 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2816 VAR_DOMAIN
, LOC_CONST
,
2817 &objfile
->static_psymbols
, symbol
.n_value
,
2818 0, psymtab_language
, objfile
);
2824 int name_len
= p
- namestring
;
2825 char *name
= xmalloc (name_len
+ 1);
2827 memcpy (name
, namestring
, name_len
);
2828 name
[name_len
] = '\0';
2829 function_outside_compilation_unit_complaint (name
);
2832 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
,
2833 SECT_OFF_TEXT (objfile
));
2834 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2835 VAR_DOMAIN
, LOC_BLOCK
,
2836 &objfile
->static_psymbols
,
2838 psymtab_language
, objfile
);
2841 /* Global functions were ignored here, but now they
2842 are put into the global psymtab like one would expect.
2843 They're also in the minimal symbol table. */
2847 int name_len
= p
- namestring
;
2848 char *name
= xmalloc (name_len
+ 1);
2850 memcpy (name
, namestring
, name_len
);
2851 name
[name_len
] = '\0';
2852 function_outside_compilation_unit_complaint (name
);
2856 /* We need only the minimal symbols for these
2857 loader-generated definitions. Keeping the global
2858 symbols leads to "in psymbols but not in symbols"
2860 if (strncmp (namestring
, "@FIX", 4) == 0)
2863 symbol
.n_value
+= ANOFFSET (objfile
->section_offsets
,
2864 SECT_OFF_TEXT (objfile
));
2865 add_psymbol_to_list (namestring
, p
- namestring
, 1,
2866 VAR_DOMAIN
, LOC_BLOCK
,
2867 &objfile
->global_psymbols
,
2869 psymtab_language
, objfile
);
2872 /* Two things show up here (hopefully); static symbols of
2873 local scope (static used inside braces) or extensions
2874 of structure symbols. We can ignore both. */
2888 case '#': /* For symbol identification (used in
2893 /* It is a C++ nested symbol. We don't need to record it
2894 (I don't think); if we try to look up foo::bar::baz,
2895 then symbols for the symtab containing foo should get
2896 read in, I think. */
2897 /* Someone says sun cc puts out symbols like
2898 /foo/baz/maclib::/usr/local/bin/maclib,
2899 which would get here with a symbol type of ':'. */
2903 /* Unexpected symbol descriptor. The second and
2904 subsequent stabs of a continued stab can show up
2905 here. The question is whether they ever can mimic
2906 a normal stab--it would be nice if not, since we
2907 certainly don't want to spend the time searching to
2908 the end of every string looking for a
2911 complaint (&symfile_complaints
,
2912 _("unknown symbol descriptor `%c'"), p
[1]);
2914 /* Ignore it; perhaps it is an extension that we don't
2924 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2925 ssymnum
, dependency_list
,
2926 dependencies_used
, textlow_not_set
);
2929 /* Record the toc offset value of this symbol table into objfile
2930 structure. If no XMC_TC0 is found, toc_offset should be zero.
2931 Another place to obtain this information would be file auxiliary
2934 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->toc_offset
2938 /* Return the toc offset value for a given objfile. */
2941 xcoff_get_toc_offset (struct objfile
*objfile
)
2944 return ((struct coff_symfile_info
*)
2945 objfile
->deprecated_sym_private
)->toc_offset
;
2949 /* Scan and build partial symbols for a symbol file.
2950 We have been initialized by a call to dbx_symfile_init, which
2951 put all the relevant info into a "struct dbx_symfile_info",
2952 hung off the objfile structure.
2954 SECTION_OFFSETS contains offsets relative to which the symbols in the
2955 various sections are (depending where the sections were actually
2959 xcoff_initial_scan (struct objfile
*objfile
, int symfile_flags
)
2963 struct cleanup
*back_to
;
2964 int num_symbols
; /* # of symbols */
2965 file_ptr symtab_offset
; /* symbol table and */
2966 file_ptr stringtab_offset
; /* string table file offsets */
2967 struct coff_symfile_info
*info
;
2971 info
= (struct coff_symfile_info
*) objfile
->deprecated_sym_private
;
2972 symfile_bfd
= abfd
= objfile
->obfd
;
2973 name
= objfile
->name
;
2975 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2976 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2977 stringtab_offset
= symtab_offset
+
2978 num_symbols
* coff_data (abfd
)->local_symesz
;
2980 info
->min_lineno_offset
= 0;
2981 info
->max_lineno_offset
= 0;
2982 bfd_map_over_sections (abfd
, find_linenos
, info
);
2984 if (num_symbols
> 0)
2986 /* Read the string table. */
2987 init_stringtab (abfd
, stringtab_offset
, objfile
);
2989 /* Read the .debug section, if present. */
2991 struct bfd_section
*secp
;
2992 bfd_size_type length
;
2993 char *debugsec
= NULL
;
2995 secp
= bfd_get_section_by_name (abfd
, ".debug");
2998 length
= bfd_section_size (abfd
, secp
);
3002 (char *) obstack_alloc (&objfile
->objfile_obstack
, length
);
3004 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
3005 (file_ptr
) 0, length
))
3007 error (_("Error reading .debug section of `%s': %s"),
3008 name
, bfd_errmsg (bfd_get_error ()));
3012 ((struct coff_symfile_info
*)
3013 objfile
->deprecated_sym_private
)->debugsec
3018 /* Read the symbols. We keep them in core because we will want to
3019 access them randomly in read_symbol*. */
3020 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
3022 error (_("Error reading symbols from %s: %s"),
3023 name
, bfd_errmsg (bfd_get_error ()));
3024 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
3025 ((struct coff_symfile_info
*) objfile
->deprecated_sym_private
)->symtbl
=
3026 obstack_alloc (&objfile
->objfile_obstack
, size
);
3027 ((struct coff_symfile_info
*)
3028 objfile
->deprecated_sym_private
)->symtbl_num_syms
3031 val
= bfd_bread (((struct coff_symfile_info
*)
3032 objfile
->deprecated_sym_private
)->symtbl
,
3035 perror_with_name (_("reading symbol table"));
3037 /* If we are reinitializing, or if we have never loaded syms yet, init. */
3038 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3039 /* I'm not sure how how good num_symbols is; the rule of thumb in
3040 init_psymbol_list was developed for a.out. On the one hand,
3041 num_symbols includes auxents. On the other hand, it doesn't
3043 init_psymbol_list (objfile
, num_symbols
);
3045 free_pending_blocks ();
3046 back_to
= make_cleanup (really_free_pendings
, 0);
3048 init_minimal_symbol_collection ();
3049 make_cleanup_discard_minimal_symbols ();
3051 /* Now that the symbol table data of the executable file are all in core,
3052 process them and define symbols accordingly. */
3054 scan_xcoff_symtab (objfile
);
3056 /* Install any minimal symbols that have been collected as the current
3057 minimal symbols for this objfile. */
3059 install_minimal_symbols (objfile
);
3061 /* DWARF2 sections. */
3063 if (dwarf2_has_info (objfile
, &dwarf2_xcoff_names
))
3064 dwarf2_build_psymtabs (objfile
);
3066 dwarf2_build_frame_info (objfile
);
3068 do_cleanups (back_to
);
3072 xcoff_symfile_offsets (struct objfile
*objfile
,
3073 struct section_addr_info
*addrs
)
3075 asection
*sect
= NULL
;
3078 objfile
->num_sections
= bfd_count_sections (objfile
->obfd
);
3079 objfile
->section_offsets
= (struct section_offsets
*)
3080 obstack_alloc (&objfile
->objfile_obstack
,
3081 SIZEOF_N_SECTION_OFFSETS (objfile
->num_sections
));
3083 /* Initialize the section indexes for future use. */
3084 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
3086 objfile
->sect_index_text
= sect
->index
;
3088 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
3090 objfile
->sect_index_data
= sect
->index
;
3092 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
3094 objfile
->sect_index_bss
= sect
->index
;
3096 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
3098 objfile
->sect_index_rodata
= sect
->index
;
3100 for (i
= 0; i
< objfile
->num_sections
; ++i
)
3102 /* syms_from_objfile kindly subtracts from addr the
3103 bfd_section_vma of the .text section. This strikes me as
3104 wrong--whether the offset to be applied to symbol reading is
3105 relative to the start address of the section depends on the
3106 symbol format. In any event, this whole "addr" concept is
3107 pretty broken (it doesn't handle any section but .text
3108 sensibly), so just ignore the addr parameter and use 0.
3109 rs6000-nat.c will set the correct section offsets via
3110 objfile_relocate. */
3111 (objfile
->section_offsets
)->offsets
[i
] = 0;
3115 /* Register our ability to parse symbols for xcoff BFD files. */
3117 static const struct sym_fns xcoff_sym_fns
=
3120 /* It is possible that coff and xcoff should be merged as
3121 they do have fundamental similarities (for example, the extra storage
3122 classes used for stabs could presumably be recognized in any COFF file).
3123 However, in addition to obvious things like all the csect hair, there are
3124 some subtler differences between xcoffread.c and coffread.c, notably
3125 the fact that coffread.c has no need to read in all the symbols, but
3126 xcoffread.c reads all the symbols and does in fact randomly access them
3127 (in C_BSTAT and line number processing). */
3129 bfd_target_xcoff_flavour
,
3131 xcoff_new_init
, /* init anything gbl to entire symtab */
3132 xcoff_symfile_init
, /* read initial info, setup for sym_read() */
3133 xcoff_initial_scan
, /* read a symbol file into symtab */
3134 NULL
, /* sym_read_psymbols */
3135 xcoff_symfile_finish
, /* finished with file, cleanup */
3136 xcoff_symfile_offsets
, /* xlate offsets ext->int form */
3137 default_symfile_segments
, /* Get segment information from a file. */
3138 aix_process_linenos
,
3139 default_symfile_relocate
, /* Relocate a debug section. */
3140 NULL
, /* sym_probe_fns */
3144 /* Provide a prototype to silence -Wmissing-prototypes. */
3145 extern initialize_file_ftype _initialize_xcoffread
;
3148 _initialize_xcoffread (void)
3150 add_symtab_fns (&xcoff_sym_fns
);