1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
4 Derived from coffread.c, dbxread.c, and a lot of hacking.
5 Contributed by IBM Corporation.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include <sys/types.h>
29 #include "gdb_string.h"
31 #include <sys/param.h>
37 #include "coff/internal.h"
38 #include "libcoff.h" /* FIXME, internal data from BFD */
39 #include "coff/rs6000.h"
46 #include "stabsread.h"
47 #include "expression.h"
48 #include "language.h" /* Needed inside partial-stab.h */
49 #include "complaints.h"
51 #include "gdb-stabs.h"
53 /* For interface with stabsread.c. */
54 #include "aout/stab_gnu.h"
56 /* For interface with partial-stab.h. */
57 #define N_UNDF 0 /* Undefined symbol */
60 #define N_TEXT 4 /* Text sym -- defined at offset in text seg */
61 #define N_DATA 6 /* Data sym -- defined at offset in data seg */
62 #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
63 #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
64 #define N_FN 0x1f /* File name of .o file */
65 #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
66 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
67 N_DATA, or N_BSS. When the low-order bit of other types is set,
68 (e.g. N_WARNING versus N_FN), they are two different types. */
69 #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
72 /* The following symbols refer to set elements.
73 All the N_SET[ATDB] symbols with the same name form one set.
74 Space is allocated for the set in the text section, and each set
75 elements value is stored into one word of the space.
76 The first word of the space is the length of the set (number of elements).
78 The address of the set is made into an N_SETV symbol
79 whose name is the same as the name of the set.
80 This symbol acts like a N_DATA global symbol
81 in that it can satisfy undefined external references. */
83 /* These appear as input to LD, in a .o file. */
84 #define N_SETA 0x14 /* Absolute set element symbol */
85 #define N_SETT 0x16 /* Text set element symbol */
86 #define N_SETD 0x18 /* Data set element symbol */
87 #define N_SETB 0x1A /* Bss set element symbol */
89 /* This is output from LD. */
90 #define N_SETV 0x1C /* Pointer to set vector in data area. */
92 /* Hook for recording the toc offset value of a symbol table into
93 the ldinfo structure. */
95 void (*xcoff_add_toc_to_loadinfo_hook
) PARAMS ((unsigned long)) = NULL
;
97 /* Hook for recording how to call xcoff_init_loadinfo for a native
98 rs6000 config only. */
100 void (*xcoff_init_loadinfo_hook
) PARAMS ((void)) = NULL
;
103 /* We put a pointer to this structure in the read_symtab_private field
108 /* First symbol number for this file. */
112 /* Number of symbols in the section of the symbol table devoted to
113 this file's symbols (actually, the section bracketed may contain
114 more than just this file's symbols). If numsyms is 0, the only
115 reason for this thing's existence is the dependency list. Nothing
116 else will happen when it is read in. */
120 /* Position of the start of the line number information for this psymtab. */
121 unsigned int lineno_off
;
124 /* Remember what we deduced to be the source language of this psymtab. */
126 static enum language psymtab_language
= language_unknown
;
129 /* Simplified internal version of coff symbol table information */
133 int c_symnum
; /* symbol number of this entry */
134 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
136 unsigned char c_sclass
;
141 /* last function's saved coff symbol `cs' */
143 static struct coff_symbol fcn_cs_saved
;
145 static bfd
*symfile_bfd
;
147 /* Core address of start and end of text of current source file.
148 This is calculated from the first function seen after a C_FILE
152 static CORE_ADDR cur_src_end_addr
;
154 /* Core address of the end of the first object file. */
156 static CORE_ADDR first_object_file_end
;
158 /* initial symbol-table-debug-string vector length */
160 #define INITIAL_STABVECTOR_LENGTH 40
162 /* Nonzero if within a function (so symbols should be local,
163 if nothing says specifically). */
167 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
168 there is any reason not to just use a #define, but might as well
169 ask BFD for the size and store it here, I guess. */
171 static unsigned local_symesz
;
173 struct coff_symfile_info
{
174 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
175 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
177 /* Pointer to the string table. */
180 /* Pointer to debug section. */
183 /* Pointer to the a.out symbol table. */
186 /* Number of symbols in symtbl. */
190 static struct complaint storclass_complaint
=
191 {"Unexpected storage class: %d", 0, 0};
193 static struct complaint bf_notfound_complaint
=
194 {"line numbers off, `.bf' symbol not found", 0, 0};
196 static struct complaint ef_complaint
=
197 {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
199 static struct complaint eb_complaint
=
200 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
203 xcoff_initial_scan
PARAMS ((struct objfile
*, struct section_offsets
*, int));
206 scan_xcoff_symtab
PARAMS ((struct section_offsets
*, struct objfile
*));
209 xcoff_next_symbol_text
PARAMS ((struct objfile
*));
212 record_include_begin
PARAMS ((struct coff_symbol
*));
215 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned,
216 CORE_ADDR
, CORE_ADDR
, unsigned *));
219 init_stringtab
PARAMS ((bfd
*, file_ptr
, struct objfile
*));
222 xcoff_symfile_init
PARAMS ((struct objfile
*));
225 xcoff_new_init
PARAMS ((struct objfile
*));
228 xcoff_symfile_finish
PARAMS ((struct objfile
*));
230 static struct section_offsets
*
231 xcoff_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
234 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
237 coff_getfilename
PARAMS ((union internal_auxent
*, struct objfile
*));
240 read_symbol
PARAMS ((struct internal_syment
*, int));
243 read_symbol_lineno
PARAMS ((int));
246 read_symbol_nvalue
PARAMS ((int));
248 static struct symbol
*
249 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
252 read_xcoff_symtab
PARAMS ((struct partial_symtab
*));
256 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
260 compare_lte
PARAMS ((const void *, const void *));
262 static struct linetable
*
263 arrange_linetable
PARAMS ((struct linetable
*));
266 record_include_end
PARAMS ((struct coff_symbol
*));
269 process_linenos
PARAMS ((CORE_ADDR
, CORE_ADDR
));
272 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
274 static int secnum_to_section
PARAMS ((int, struct objfile
*));
275 static asection
* secnum_to_bfd_section
PARAMS ((int, struct objfile
*));
277 struct find_targ_sec_arg
{
283 static void find_targ_sec
PARAMS ((bfd
*, asection
*, void *));
285 static void find_targ_sec (abfd
, sect
, obj
)
290 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*)obj
;
291 if (sect
->target_index
== args
->targ_index
)
293 /* This is the section. Figure out what SECT_OFF_* code it is. */
294 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
295 *args
->resultp
= SECT_OFF_TEXT
;
296 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
297 *args
->resultp
= SECT_OFF_DATA
;
299 *args
->resultp
= SECT_OFF_BSS
;
300 *args
->bfd_sect
= sect
;
304 /* Return the section number (SECT_OFF_*) that CS points to. */
306 secnum_to_section (secnum
, objfile
)
308 struct objfile
*objfile
;
310 int off
= SECT_OFF_TEXT
;
311 asection
*sect
= NULL
;
312 struct find_targ_sec_arg args
;
313 args
.targ_index
= secnum
;
315 args
.bfd_sect
= §
;
316 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
320 /* Return the BFD section that CS points to. */
322 secnum_to_bfd_section (secnum
, objfile
)
324 struct objfile
*objfile
;
326 int off
= SECT_OFF_TEXT
;
327 asection
*sect
= NULL
;
328 struct find_targ_sec_arg args
;
329 args
.targ_index
= secnum
;
331 args
.bfd_sect
= §
;
332 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
336 /* add a given stab string into given stab vector. */
341 add_stab_to_list (stabname
, stabvector
)
343 struct pending_stabs
**stabvector
;
345 if ( *stabvector
== NULL
) {
346 *stabvector
= (struct pending_stabs
*)
347 xmalloc (sizeof (struct pending_stabs
) +
348 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
349 (*stabvector
)->count
= 0;
350 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
352 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
353 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
354 *stabvector
= (struct pending_stabs
*)
355 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
356 (*stabvector
)->length
* sizeof (char*));
358 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
364 /* Linenos are processed on a file-by-file basis.
368 1) xlc (IBM's native c compiler) postpones static function code
369 emission to the end of a compilation unit. This way it can
370 determine if those functions (statics) are needed or not, and
371 can do some garbage collection (I think). This makes line
372 numbers and corresponding addresses unordered, and we end up
373 with a line table like:
390 and that breaks gdb's binary search on line numbers, if the
391 above table is not sorted on line numbers. And that sort
392 should be on function based, since gcc can emit line numbers
395 10 0x100 - for the init/test part of a for stmt.
398 10 0x400 - for the increment part of a for stmt.
400 arrange_linetable() will do this sorting.
402 2) aix symbol table might look like:
404 c_file // beginning of a new file
405 .bi // beginning of include file
406 .ei // end of include file
410 basically, .bi/.ei pairs do not necessarily encapsulate
411 their scope. They need to be recorded, and processed later
412 on when we come the end of the compilation unit.
413 Include table (inclTable) and process_linenos() handle
416 /* compare line table entry addresses. */
419 compare_lte (lte1p
, lte2p
)
423 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
424 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
425 return lte1
->pc
- lte2
->pc
;
428 /* Given a line table with function entries are marked, arrange its functions
429 in ascending order and strip off function entry markers and return it in
430 a newly created table. If the old one is good enough, return the old one. */
431 /* FIXME: I think all this stuff can be replaced by just passing
432 sort_linevec = 1 to end_symtab. */
434 static struct linetable
*
435 arrange_linetable (oldLineTb
)
436 struct linetable
*oldLineTb
; /* old linetable */
439 newline
, /* new line count */
440 function_count
; /* # of functions */
442 struct linetable_entry
*fentry
; /* function entry vector */
443 int fentry_size
; /* # of function entries */
444 struct linetable
*newLineTb
; /* new line table */
446 #define NUM_OF_FUNCTIONS 20
448 fentry_size
= NUM_OF_FUNCTIONS
;
449 fentry
= (struct linetable_entry
*)
450 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
452 for (function_count
=0, ii
=0; ii
<oldLineTb
->nitems
; ++ii
) {
454 if (oldLineTb
->item
[ii
].line
== 0) { /* function entry found. */
456 if (function_count
>= fentry_size
) { /* make sure you have room. */
458 fentry
= (struct linetable_entry
*)
459 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
461 fentry
[function_count
].line
= ii
;
462 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
467 if (function_count
== 0) {
471 else if (function_count
> 1)
472 qsort (fentry
, function_count
, sizeof(struct linetable_entry
), compare_lte
);
474 /* allocate a new line table. */
475 newLineTb
= (struct linetable
*)
477 (sizeof (struct linetable
) +
478 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
480 /* if line table does not start with a function beginning, copy up until
484 if (oldLineTb
->item
[0].line
!= 0)
486 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
487 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
489 /* Now copy function lines one by one. */
491 for (ii
=0; ii
< function_count
; ++ii
) {
492 for (jj
= fentry
[ii
].line
+ 1;
493 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
495 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
498 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
502 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
503 following `IncludeChain'. At the end of each symtab (end_symtab),
504 we will determine if we should create additional symtab's to
505 represent if (the include files. */
508 typedef struct _inclTable
{
509 char *name
; /* include filename */
511 /* Offsets to the line table. end points to the last entry which is
512 part of this include file. */
515 struct subfile
*subfile
;
516 unsigned funStartLine
; /* start line # of its function */
519 #define INITIAL_INCLUDE_TABLE_LENGTH 20
520 static InclTable
*inclTable
; /* global include table */
521 static int inclIndx
; /* last entry to table */
522 static int inclLength
; /* table length */
523 static int inclDepth
; /* nested include depth */
525 static void allocate_include_entry
PARAMS ((void));
528 record_include_begin (cs
)
529 struct coff_symbol
*cs
;
533 /* In xcoff, we assume include files cannot be nested (not in .c files
534 of course, but in corresponding .s files.). */
536 /* This can happen with old versions of GCC.
537 GCC 2.3.3-930426 does not exhibit this on a test case which
538 a user said produced the message for him. */
539 static struct complaint msg
= {"Nested C_BINCL symbols", 0, 0};
544 allocate_include_entry ();
546 inclTable
[inclIndx
].name
= cs
->c_name
;
547 inclTable
[inclIndx
].begin
= cs
->c_value
;
551 record_include_end (cs
)
552 struct coff_symbol
*cs
;
558 static struct complaint msg
= {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
562 allocate_include_entry ();
564 pTbl
= &inclTable
[inclIndx
];
565 pTbl
->end
= cs
->c_value
;
572 allocate_include_entry ()
574 if (inclTable
== NULL
)
576 inclTable
= (InclTable
*)
577 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
579 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
580 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
583 else if (inclIndx
>= inclLength
)
585 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
586 inclTable
= (InclTable
*)
587 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
588 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
589 '\0', sizeof (InclTable
)*INITIAL_INCLUDE_TABLE_LENGTH
);
593 /* Global variable to pass the psymtab down to all the routines involved
594 in psymtab to symtab processing. */
595 static struct partial_symtab
*this_symtab_psymtab
;
597 /* given the start and end addresses of a compilation unit (or a csect,
598 at times) process its lines and create appropriate line vectors. */
601 process_linenos (start
, end
)
602 CORE_ADDR start
, end
;
605 file_ptr max_offset
=
606 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
609 /* subfile structure for the main compilation unit. */
610 struct subfile main_subfile
;
612 /* In the main source file, any time we see a function entry, we
613 reset this variable to function's absolute starting line number.
614 All the following line numbers in the function are relative to
615 this, and we record absolute line numbers in record_line(). */
617 unsigned int main_source_baseline
= 0;
622 ((struct symloc
*)this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
624 goto return_after_cleanup
;
626 memset (&main_subfile
, '\0', sizeof (main_subfile
));
629 /* All source lines were in the main source file. None in include files. */
631 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
632 &main_source_baseline
);
636 /* There was source with line numbers in include files. */
637 main_source_baseline
= 0;
638 for (ii
=0; ii
< inclIndx
; ++ii
)
640 struct subfile
*tmpSubfile
;
642 /* If there is main file source before include file, enter it. */
643 if (offset
< inclTable
[ii
].begin
)
646 (&main_subfile
, offset
, inclTable
[ii
].begin
- LINESZ
,
647 start
, 0, &main_source_baseline
);
650 /* Have a new subfile for the include file. */
652 tmpSubfile
= inclTable
[ii
].subfile
=
653 (struct subfile
*) xmalloc (sizeof (struct subfile
));
655 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
656 firstLine
= &(inclTable
[ii
].funStartLine
);
658 /* Enter include file's lines now. */
659 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
660 inclTable
[ii
].end
, start
, 0, firstLine
);
662 if (offset
<= inclTable
[ii
].end
)
663 offset
= inclTable
[ii
].end
+ LINESZ
;
666 /* All the include files' line have been processed at this point. Now,
667 enter remaining lines of the main file, if any left. */
668 if (offset
< max_offset
+ 1 - LINESZ
)
670 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
671 &main_source_baseline
);
675 /* Process main file's line numbers. */
676 if (main_subfile
.line_vector
)
678 struct linetable
*lineTb
, *lv
;
680 lv
= main_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
);
688 current_subfile
->line_vector
= (struct linetable
*)
689 xrealloc (lv
, (sizeof (struct linetable
)
690 + lv
->nitems
* sizeof (struct linetable_entry
)));
695 current_subfile
->line_vector
= lineTb
;
698 current_subfile
->line_vector_length
=
699 current_subfile
->line_vector
->nitems
;
702 /* Now, process included files' line numbers. */
704 for (ii
=0; ii
< inclIndx
; ++ii
)
706 if ((inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
708 struct linetable
*lineTb
, *lv
;
710 lv
= (inclTable
[ii
].subfile
)->line_vector
;
712 /* Line numbers are not necessarily ordered. xlc compilation will
713 put static function to the end. */
715 lineTb
= arrange_linetable (lv
);
719 /* For the same include file, we might want to have more than one
720 subfile. This happens if we have something like:
728 while foo.h including code in it. (stupid but possible)
729 Since start_subfile() looks at the name and uses an
730 existing one if finds, we need to provide a fake name and
734 start_subfile (inclTable
[ii
].name
, (char*)0);
737 /* Pick a fake name that will produce the same results as this
738 one when passed to deduce_language_from_filename. Kludge on
740 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
741 if (fakename
== NULL
)
743 start_subfile (fakename
, (char*)0);
744 free (current_subfile
->name
);
746 current_subfile
->name
= strdup (inclTable
[ii
].name
);
751 current_subfile
->line_vector
=
752 (struct linetable
*) xrealloc
753 (lv
, (sizeof (struct linetable
)
754 + lv
->nitems
* sizeof (struct linetable_entry
)));
760 current_subfile
->line_vector
= lineTb
;
763 current_subfile
->line_vector_length
=
764 current_subfile
->line_vector
->nitems
;
765 start_subfile (pop_subfile (), (char*)0);
769 return_after_cleanup
:
771 /* We don't want to keep alloc/free'ing the global include file table. */
774 /* Start with a fresh subfile structure for the next file. */
775 memset (&main_subfile
, '\0', sizeof (struct subfile
));
779 aix_process_linenos ()
781 /* process line numbers and enter them into line vector */
782 process_linenos (last_source_start_addr
, cur_src_end_addr
);
786 /* Enter a given range of lines into the line vector.
787 can be called in the following two ways:
788 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
789 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
791 endoffset points to the last line table entry that we should pay
795 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
,
797 struct subfile
*subfile
;
798 unsigned beginoffset
, endoffset
; /* offsets to line table */
799 CORE_ADDR startaddr
, endaddr
;
802 unsigned int curoffset
;
804 struct external_lineno ext_lnno
;
805 struct internal_lineno int_lnno
;
806 unsigned int limit_offset
;
809 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
811 curoffset
= beginoffset
;
813 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
818 if (endoffset
>= limit_offset
)
820 static struct complaint msg
=
821 {"Bad line table offset in C_EINCL directive", 0, 0};
825 limit_offset
= endoffset
;
829 abfd
= this_symtab_psymtab
->objfile
->obfd
;
831 while (curoffset
<= limit_offset
)
833 bfd_seek (abfd
, curoffset
, SEEK_SET
);
834 bfd_read (&ext_lnno
, sizeof (struct external_lineno
), 1, abfd
);
835 bfd_coff_swap_lineno_in (abfd
, &ext_lnno
, &int_lnno
);
837 /* Find the address this line represents. */
838 addr
= (int_lnno
.l_lnno
839 ? int_lnno
.l_addr
.l_paddr
840 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
841 addr
+= ANOFFSET (this_symtab_psymtab
->objfile
->section_offsets
,
844 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
847 if (int_lnno
.l_lnno
== 0)
849 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
850 record_line (subfile
, 0, addr
);
854 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
, addr
);
860 /* Save the vital information for use when closing off the current file.
861 NAME is the file name the symbols came from, START_ADDR is the first
862 text address for the file, and SIZE is the number of bytes of text. */
864 #define complete_symtab(name, start_addr) { \
865 last_source_file = savestring (name, strlen (name)); \
866 last_source_start_addr = start_addr; \
870 /* Refill the symbol table input buffer
871 and set the variables that control fetching entries from it.
872 Reports an error if no data available.
873 This function can read past the end of the symbol table
874 (into the string table) but this does no harm. */
876 /* Reading symbol table has to be fast! Keep the followings as macros, rather
879 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
883 if (namestr[0] == '.') ++namestr; \
884 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
885 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
886 misc_func_recorded = 1; \
890 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
891 nested. At any given time, a symbol can only be in one static block.
892 This is the base address of current static block, zero if non exists. */
894 static int static_block_base
= 0;
896 /* Section number for the current static block. */
898 static int static_block_section
= -1;
900 /* true if space for symbol name has been allocated. */
902 static int symname_alloced
= 0;
904 /* Next symbol to read. Pointer into raw seething symbol table. */
906 static char *raw_symbol
;
908 /* This is the function which stabsread.c calls to get symbol
912 xcoff_next_symbol_text (objfile
)
913 struct objfile
*objfile
;
915 struct internal_syment symbol
;
916 static struct complaint msg
=
917 {"Unexpected symbol continuation", 0, 0};
919 /* FIXME: is this the same as the passed arg? */
920 objfile
= this_symtab_psymtab
->objfile
;
922 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
927 /* Return something which points to '\0' and hope the symbol reading
928 code does something reasonable. */
931 else if (symbol
.n_sclass
& 0x80)
934 ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
937 coff_data (objfile
->obfd
)->local_symesz
;
944 /* Return something which points to '\0' and hope the symbol reading
945 code does something reasonable. */
951 /* Read symbols for a given partial symbol table. */
954 read_xcoff_symtab (pst
)
955 struct partial_symtab
*pst
;
957 struct objfile
*objfile
= pst
->objfile
;
958 bfd
*abfd
= objfile
->obfd
;
959 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
960 char *strtbl
= ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
;
962 ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
;
964 struct internal_syment symbol
[1];
965 union internal_auxent main_aux
;
966 struct coff_symbol cs
[1];
967 CORE_ADDR file_start_addr
= 0;
968 CORE_ADDR file_end_addr
= 0;
970 int next_file_symnum
= -1;
971 unsigned int max_symnum
;
972 int just_started
= 1;
974 int fcn_start_addr
= 0;
976 struct coff_symbol fcn_stab_saved
;
978 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
979 union internal_auxent fcn_aux_saved
;
980 struct context_stack
*new;
982 char *filestring
= " _start_ "; /* Name of the current file. */
984 char *last_csect_name
; /* last seen csect's name and value */
985 CORE_ADDR last_csect_val
;
988 this_symtab_psymtab
= pst
;
990 /* Get the appropriate COFF "constants" related to the file we're
992 local_symesz
= coff_data (abfd
)->local_symesz
;
994 last_source_file
= NULL
;
999 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
1000 symnum
= ((struct symloc
*)pst
->read_symtab_private
)->first_symnum
;
1002 symnum
+ ((struct symloc
*)pst
->read_symtab_private
)->numsyms
;
1003 first_object_file_end
= 0;
1006 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
1007 + symnum
* local_symesz
;
1009 while (symnum
< max_symnum
)
1012 QUIT
; /* make this command interruptable. */
1014 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1015 /* read one symbol into `cs' structure. After processing the
1016 whole symbol table, only string table will be kept in memory,
1017 symbol table and debug section of xcoff will be freed. Thus
1018 we can mark symbols with names in string table as
1023 /* Swap and align the symbol into a reasonable C structure. */
1024 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1026 cs
->c_symnum
= symnum
;
1027 cs
->c_naux
= symbol
->n_numaux
;
1028 if (symbol
->n_zeroes
)
1030 symname_alloced
= 0;
1031 /* We must use the original, unswapped, name here so the name field
1032 pointed to by cs->c_name will persist throughout xcoffread. If
1033 we use the new field, it gets overwritten for each symbol. */
1034 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
1035 /* If it's exactly E_SYMNMLEN characters long it isn't
1037 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1040 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
1041 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1042 p
[E_SYMNMLEN
] = '\0';
1044 symname_alloced
= 1;
1047 else if (symbol
->n_sclass
& 0x80)
1049 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1050 symname_alloced
= 0;
1054 /* in string table */
1055 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
1056 symname_alloced
= 1;
1058 cs
->c_value
= symbol
->n_value
;
1059 cs
->c_sclass
= symbol
->n_sclass
;
1060 cs
->c_secnum
= symbol
->n_scnum
;
1061 cs
->c_type
= (unsigned)symbol
->n_type
;
1063 raw_symbol
+= coff_data (abfd
)->local_symesz
;
1066 /* Save addr of first aux entry. */
1067 raw_auxptr
= raw_symbol
;
1069 /* Skip all the auxents associated with this symbol. */
1070 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1072 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1077 /* if symbol name starts with ".$" or "$", ignore it. */
1078 if (cs
->c_name
[0] == '$'
1079 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1082 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1084 if (last_source_file
)
1087 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT
);
1092 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
1093 cur_src_end_addr
= first_object_file_end
;
1094 /* done with all files, everything from here on is globals */
1097 /* if explicitly specified as a function, treat is as one. */
1098 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1100 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1101 0, cs
->c_naux
, &main_aux
);
1102 goto function_entry_point
;
1105 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1108 /* Dealing with a symbol with a csect entry. */
1110 #define CSECT(PP) ((PP)->x_csect)
1111 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1112 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1113 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1114 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1116 /* Convert the auxent to something we can access. */
1117 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1118 0, cs
->c_naux
, &main_aux
);
1120 switch (CSECT_SMTYP (&main_aux
))
1124 /* Ignore all external references. */
1128 /* A section description. */
1130 switch (CSECT_SCLAS (&main_aux
))
1136 /* A program csect is seen. We have to allocate one
1137 symbol table for each program csect. Normally gdb
1138 prefers one symtab for each source file. In case
1139 of AIX, one source file might include more than one
1140 [PR] csect, and they don't have to be adjacent in
1141 terms of the space they occupy in memory. Thus, one
1142 single source file might get fragmented in the
1143 memory and gdb's file start and end address
1144 approach does not work! GCC (and I think xlc) seem
1145 to put all the code in the unnamed program csect. */
1147 if (last_csect_name
)
1149 complete_symtab (filestring
, file_start_addr
);
1150 cur_src_end_addr
= file_end_addr
;
1151 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT
);
1154 /* Give all csects for this source file the same
1156 start_symtab (filestring
, NULL
, (CORE_ADDR
)0);
1159 /* If this is the very first csect seen,
1160 basically `__start'. */
1163 first_object_file_end
1164 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1169 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1171 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1173 if (cs
->c_name
&& cs
->c_name
[0] == '.')
1175 last_csect_name
= cs
->c_name
;
1176 last_csect_val
= cs
->c_value
;
1177 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1182 /* All other symbols are put into the minimal symbol
1195 /* Ignore the symbol. */
1203 switch (CSECT_SCLAS (&main_aux
))
1206 /* a function entry point. */
1207 function_entry_point
:
1209 fcn_start_addr
= cs
->c_value
;
1211 /* save the function header info, which will be used
1212 when `.bf' is seen. */
1214 fcn_aux_saved
= main_aux
;
1218 /* shared library function trampoline code entry point. */
1222 /* The symbols often have the same names as debug symbols for
1223 functions, and confuse lookup_symbol. */
1227 /* xlc puts each variable in a separate csect, so we get
1228 an XTY_SD for each variable. But gcc puts several
1229 variables in a csect, so that each variable only gets
1230 an XTY_LD. This will typically be XMC_RW; I suspect
1231 XMC_RO and XMC_BS might be possible too.
1232 These variables are put in the minimal symbol table
1239 /* Common symbols are put into the minimal symbol table only. */
1247 switch (cs
->c_sclass
)
1252 /* c_value field contains symnum of next .file entry in table
1253 or symnum of first global after last .file. */
1255 next_file_symnum
= cs
->c_value
;
1257 /* Complete symbol table for last object file containing
1258 debugging information. */
1260 /* Whether or not there was a csect in the previous file, we
1261 have to call `end_stabs' and `start_stabs' to reset
1262 type_vector, line_vector, etc. structures. */
1264 complete_symtab (filestring
, file_start_addr
);
1265 cur_src_end_addr
= file_end_addr
;
1266 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT
);
1269 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1270 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1271 standard COFF way and put it in the auxent. We use the auxent if
1272 the symbol is ".file" and an auxent exists, otherwise use the symbol
1273 itself. Simple enough. */
1274 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1276 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1277 0, cs
->c_naux
, &main_aux
);
1278 filestring
= coff_getfilename (&main_aux
, objfile
);
1281 filestring
= cs
->c_name
;
1284 start_symtab (filestring
, (char *)NULL
, (CORE_ADDR
)0);
1285 last_csect_name
= 0;
1287 /* reset file start and end addresses. A compilation unit with no text
1288 (only data) should have zero file boundaries. */
1289 file_start_addr
= file_end_addr
= 0;
1293 fcn_stab_saved
= *cs
;
1297 if (STREQ (cs
->c_name
, ".bf"))
1299 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1301 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1302 0, cs
->c_naux
, &main_aux
);
1304 within_function
= 1;
1306 new = push_context (0, fcn_start_addr
+ off
);
1308 new->name
= define_symbol
1309 (fcn_cs_saved
.c_value
+ off
,
1310 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1311 if (new->name
!= NULL
)
1312 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT
;
1314 else if (STREQ (cs
->c_name
, ".ef"))
1317 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1318 0, cs
->c_naux
, &main_aux
);
1320 /* The value of .ef is the address of epilogue code;
1321 not useful for gdb. */
1322 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1323 contains number of lines to '}' */
1325 if (context_stack_depth
<= 0)
1326 { /* We attempted to pop an empty context stack */
1327 complain (&ef_complaint
, cs
->c_symnum
);
1328 within_function
= 0;
1331 new = pop_context ();
1332 /* Stack must be empty now. */
1333 if (context_stack_depth
> 0 || new == NULL
)
1335 complain (&ef_complaint
, cs
->c_symnum
);
1336 within_function
= 0;
1340 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1342 (fcn_cs_saved
.c_value
1343 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1344 + ANOFFSET (objfile
->section_offsets
,
1347 within_function
= 0;
1352 /* Begin static block. */
1354 struct internal_syment symbol
;
1356 read_symbol (&symbol
, cs
->c_value
);
1357 static_block_base
= symbol
.n_value
;
1358 static_block_section
=
1359 secnum_to_section (symbol
.n_scnum
, objfile
);
1364 /* End of static block. */
1365 static_block_base
= 0;
1366 static_block_section
= -1;
1377 static struct complaint msg
=
1378 {"Unrecognized storage class %d.", 0, 0};
1379 complain (&msg
, cs
->c_sclass
);
1393 /* beginning of include file */
1394 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1395 order. Thus, when wee see them, we might not know enough info
1396 to process them. Thus, we'll be saving them into a table
1397 (inclTable) and postpone their processing. */
1399 record_include_begin (cs
);
1403 /* End of include file. */
1404 /* See the comment after case C_BINCL. */
1405 record_include_end (cs
);
1409 if (STREQ (cs
->c_name
, ".bb"))
1412 new = push_context (depth
,
1414 + ANOFFSET (objfile
->section_offsets
,
1417 else if (STREQ (cs
->c_name
, ".eb"))
1419 if (context_stack_depth
<= 0)
1420 { /* We attempted to pop an empty context stack */
1421 complain (&eb_complaint
, cs
->c_symnum
);
1424 new = pop_context ();
1425 if (depth
-- != new->depth
)
1427 complain (&eb_complaint
, cs
->c_symnum
);
1430 if (local_symbols
&& context_stack_depth
> 0)
1432 /* Make a block for the local symbols within. */
1433 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1436 + ANOFFSET (objfile
->section_offsets
,
1440 local_symbols
= new->locals
;
1445 process_xcoff_symbol (cs
, objfile
);
1450 if (last_source_file
)
1454 complete_symtab (filestring
, file_start_addr
);
1455 cur_src_end_addr
= file_end_addr
;
1456 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT
);
1457 /* When reading symbols for the last C_FILE of the objfile, try
1458 to make sure that we set pst->symtab to the symtab for the
1459 file, not to the _globals_ symtab. I'm not sure whether this
1460 actually works right or when/if it comes up. */
1461 if (pst
->symtab
== NULL
)
1467 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1468 (SYMBOL2) = (struct symbol *) \
1469 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1470 *(SYMBOL2) = *(SYMBOL1);
1473 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1474 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1477 static struct type
*func_symbol_type
;
1478 static struct type
*var_symbol_type
;
1480 /* process one xcoff symbol. */
1482 static struct symbol
*
1483 process_xcoff_symbol (cs
, objfile
)
1484 register struct coff_symbol
*cs
;
1485 struct objfile
*objfile
;
1487 struct symbol onesymbol
;
1488 register struct symbol
*sym
= &onesymbol
;
1489 struct symbol
*sym2
= NULL
;
1495 if (cs
->c_secnum
< 0)
1497 /* The value is a register number, offset within a frame, etc.,
1498 and does not get relocated. */
1504 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1505 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1512 memset (sym
, '\0', sizeof (struct symbol
));
1514 /* default assumptions */
1515 SYMBOL_VALUE (sym
) = cs
->c_value
+ off
;
1516 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1517 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1519 if (ISFCN (cs
->c_type
))
1521 /* At this point, we don't know the type of the function. This
1522 will be patched with the type from its stab entry later on in
1523 patch_block_stabs (), unless the file was compiled without -g. */
1525 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1526 SYMBOL_TYPE (sym
) = func_symbol_type
;
1528 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1529 SYMBOL_DUP (sym
, sym2
);
1531 if (cs
->c_sclass
== C_EXT
)
1532 add_symbol_to_list (sym2
, &global_symbols
);
1533 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1534 add_symbol_to_list (sym2
, &file_symbols
);
1538 /* In case we can't figure out the type, provide default. */
1539 SYMBOL_TYPE (sym
) = var_symbol_type
;
1541 switch (cs
->c_sclass
)
1544 /* The values of functions and global symbols are now resolved
1545 via the global_sym_chain in stabsread.c. */
1547 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1548 add_stab_to_list (name
, &global_stabs
);
1550 add_stab_to_list (name
, &file_stabs
);
1554 add_stab_to_list (name
, &global_stabs
);
1559 common_block_start (cs
->c_name
, objfile
);
1563 common_block_end (objfile
);
1567 complain (&storclass_complaint
, cs
->c_sclass
);
1579 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1582 SYMBOL_SECTION (sym
) = sec
;
1589 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1590 all statics and we need to distinguish file-scope versus
1591 function-scope using within_function. We do this by
1592 changing the string we pass to define_symbol to use 'S'
1593 where we need to, which is not necessarily super-clean,
1594 but seems workable enough. */
1596 if (*name
== ':' || (pp
= (char *) strchr(name
, ':')) == NULL
)
1600 if (*pp
== 'V' && !within_function
)
1602 sym
= define_symbol ((cs
->c_value
1603 + ANOFFSET (objfile
->section_offsets
,
1604 static_block_section
)),
1605 cs
->c_name
, 0, 0, objfile
);
1608 SYMBOL_VALUE (sym
) += static_block_base
;
1609 SYMBOL_SECTION (sym
) = static_block_section
;
1618 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1619 only the last component of the name. Result is in static storage and
1620 is only good for temporary use. */
1623 coff_getfilename (aux_entry
, objfile
)
1624 union internal_auxent
*aux_entry
;
1625 struct objfile
*objfile
;
1627 static char buffer
[BUFSIZ
];
1628 register char *temp
;
1631 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1633 ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
1634 + aux_entry
->x_file
.x_n
.x_offset
);
1637 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1638 buffer
[FILNMLEN
] = '\0';
1642 /* FIXME: We should not be throwing away the information about what
1643 directory. It should go into dirname of the symtab, or some such
1645 if ((temp
= strrchr (result
, '/')) != NULL
)
1650 /* Set *SYMBOL to symbol number symno in symtbl. */
1652 read_symbol (symbol
, symno
)
1653 struct internal_syment
*symbol
;
1657 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1660 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1662 if (symno
< 0 || symno
>= nsyms
)
1664 static struct complaint msg
=
1665 {"Invalid symbol offset", 0, 0};
1667 symbol
->n_value
= 0;
1668 symbol
->n_scnum
= -1;
1671 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1672 stbl
+ (symno
*local_symesz
),
1676 /* Get value corresponding to symbol number symno in symtbl. */
1679 read_symbol_nvalue (symno
)
1682 struct internal_syment symbol
[1];
1684 read_symbol (symbol
, symno
);
1685 return symbol
->n_value
;
1689 /* Find the address of the function corresponding to symno, where
1690 symno is the symbol pointed to by the linetable. */
1693 read_symbol_lineno (symno
)
1697 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1700 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1702 struct internal_syment symbol
[1];
1703 union internal_auxent main_aux
[1];
1707 complain (&bf_notfound_complaint
);
1711 /* Note that just searching for a short distance (e.g. 50 symbols)
1712 is not enough, at least in the following case.
1715 [many .stabx entries]
1716 [a few functions, referring to foo]
1720 What happens here is that the assembler moves the .stabx entries
1721 to right before the ".bf" for foo, but the symbol for "foo" is before
1722 all the stabx entries. See PR gdb/2222. */
1724 /* Maintaining a table of .bf entries might be preferable to this search.
1725 If I understand things correctly it would need to be done only for
1726 the duration of a single psymtab to symtab conversion. */
1727 while (symno
< nsyms
)
1729 bfd_coff_swap_sym_in (symfile_bfd
,
1730 stbl
+ (symno
* local_symesz
), symbol
);
1731 if (symbol
->n_sclass
== C_FCN
&& STREQ (symbol
->n_name
, ".bf"))
1733 symno
+= symbol
->n_numaux
+ 1;
1736 complain (&bf_notfound_complaint
);
1740 /* take aux entry and return its lineno */
1742 bfd_coff_swap_aux_in (this_symtab_psymtab
->objfile
->obfd
,
1743 stbl
+ symno
* local_symesz
,
1744 symbol
->n_type
, symbol
->n_sclass
,
1745 0, symbol
->n_numaux
, main_aux
);
1747 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1750 /* Support for line number handling */
1752 /* This function is called for every section; it finds the outer limits
1753 * of the line table (minimum and maximum file offset) so that the
1754 * mainline code can read the whole thing for efficiency.
1757 find_linenos (abfd
, asect
, vpinfo
)
1762 struct coff_symfile_info
*info
;
1764 file_ptr offset
, maxoff
;
1766 count
= asect
->lineno_count
;
1768 if (!STREQ (asect
->name
, ".text") || count
== 0)
1771 size
= count
* coff_data (abfd
)->local_linesz
;
1772 info
= (struct coff_symfile_info
*)vpinfo
;
1773 offset
= asect
->line_filepos
;
1774 maxoff
= offset
+ size
;
1776 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1777 info
->min_lineno_offset
= offset
;
1779 if (maxoff
> info
->max_lineno_offset
)
1780 info
->max_lineno_offset
= maxoff
;
1783 static void xcoff_psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
1786 xcoff_psymtab_to_symtab_1 (pst
)
1787 struct partial_symtab
*pst
;
1789 struct cleanup
*old_chain
;
1798 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1803 /* Read in all partial symtabs on which this one is dependent */
1804 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1805 if (!pst
->dependencies
[i
]->readin
)
1807 /* Inform about additional files that need to be read in. */
1810 fputs_filtered (" ", gdb_stdout
);
1812 fputs_filtered ("and ", gdb_stdout
);
1814 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1815 wrap_here (""); /* Flush output */
1816 gdb_flush (gdb_stdout
);
1818 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1821 if (((struct symloc
*)pst
->read_symtab_private
)->numsyms
!= 0)
1823 /* Init stuff necessary for reading in symbols. */
1826 old_chain
= make_cleanup (really_free_pendings
, 0);
1828 read_xcoff_symtab (pst
);
1829 sort_symtab_syms (pst
->symtab
);
1831 do_cleanups (old_chain
);
1837 static void xcoff_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
1839 /* Read in all of the symbols for a given psymtab for real.
1840 Be verbose about it if the user wants that. */
1843 xcoff_psymtab_to_symtab (pst
)
1844 struct partial_symtab
*pst
;
1854 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1859 if (((struct symloc
*)pst
->read_symtab_private
)->numsyms
!= 0
1860 || pst
->number_of_dependencies
)
1862 /* Print the message now, before reading the string table,
1863 to avoid disconcerting pauses. */
1866 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1867 gdb_flush (gdb_stdout
);
1870 sym_bfd
= pst
->objfile
->obfd
;
1872 next_symbol_text_func
= xcoff_next_symbol_text
;
1874 xcoff_psymtab_to_symtab_1 (pst
);
1876 /* Match with global symbols. This only needs to be done once,
1877 after all of the symtabs and dependencies have been read in. */
1878 scan_file_globals (pst
->objfile
);
1880 /* Finish up the debug error message. */
1882 printf_filtered ("done.\n");
1887 xcoff_new_init (objfile
)
1888 struct objfile
*objfile
;
1890 stabsread_new_init ();
1891 buildsym_new_init ();
1894 /* Do initialization in preparation for reading symbols from OBJFILE.
1896 We will only be called if this is an XCOFF or XCOFF-like file.
1897 BFD handles figuring out the format of the file, and code in symfile.c
1898 uses BFD's determination to vector to us. */
1901 xcoff_symfile_init (objfile
)
1902 struct objfile
*objfile
;
1904 /* Allocate struct to keep track of the symfile */
1905 objfile
-> sym_private
= xmmalloc (objfile
-> md
,
1906 sizeof (struct coff_symfile_info
));
1908 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1909 find this causes a significant slowdown in gdb then we could
1910 set it in the debug symbol readers only when necessary. */
1911 objfile
->flags
|= OBJF_REORDERED
;
1913 init_entry_point_info (objfile
);
1916 /* Perform any local cleanups required when we are done with a particular
1917 objfile. I.E, we are in the process of discarding all symbol information
1918 for an objfile, freeing up all memory held for it, and unlinking the
1919 objfile struct from the global list of known objfiles. */
1922 xcoff_symfile_finish (objfile
)
1923 struct objfile
*objfile
;
1925 if (objfile
-> sym_private
!= NULL
)
1927 mfree (objfile
-> md
, objfile
-> sym_private
);
1930 /* Start with a fresh include table for the next objfile. */
1936 inclIndx
= inclLength
= inclDepth
= 0;
1941 init_stringtab (abfd
, offset
, objfile
)
1944 struct objfile
*objfile
;
1948 unsigned char lengthbuf
[4];
1951 ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
= NULL
;
1953 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1954 error ("cannot seek to string table in %s: %s",
1955 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1957 val
= bfd_read ((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
1958 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1960 /* If no string table is needed, then the file may end immediately
1961 after the symbols. Just return with `strtbl' set to NULL. */
1963 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1966 /* Allocate string table from symbol_obstack. We will need this table
1967 as long as we have its symbol table around. */
1969 strtbl
= (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
1970 ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
= strtbl
;
1972 /* Copy length buffer, the first byte is usually zero and is
1973 used for stabs with a name length of zero. */
1974 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1975 if (length
== sizeof lengthbuf
)
1978 val
= bfd_read (strtbl
+ sizeof lengthbuf
, 1, length
- sizeof lengthbuf
,
1981 if (val
!= length
- sizeof lengthbuf
)
1982 error ("cannot read string table from %s: %s",
1983 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1984 if (strtbl
[length
- 1] != '\0')
1985 error ("bad symbol file: string table does not end with null character");
1990 /* If we have not yet seen a function for this psymtab, this is 0. If we
1991 have seen one, it is the offset in the line numbers of the line numbers
1993 static unsigned int first_fun_line_offset
;
1995 static struct partial_symtab
*xcoff_start_psymtab
1996 PARAMS ((struct objfile
*, struct section_offsets
*, char *, int,
1997 struct partial_symbol
**, struct partial_symbol
**));
1999 /* Allocate and partially fill a partial symtab. It will be
2000 completely filled at the end of the symbol list.
2002 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2003 is the address relative to which its symbols are (incremental) or 0
2006 static struct partial_symtab
*
2007 xcoff_start_psymtab (objfile
, section_offsets
,
2008 filename
, first_symnum
, global_syms
, static_syms
)
2009 struct objfile
*objfile
;
2010 struct section_offsets
*section_offsets
;
2013 struct partial_symbol
**global_syms
;
2014 struct partial_symbol
**static_syms
;
2016 struct partial_symtab
*result
=
2017 start_psymtab_common (objfile
, section_offsets
,
2019 /* We fill in textlow later. */
2021 global_syms
, static_syms
);
2023 result
->read_symtab_private
= (char *)
2024 obstack_alloc (&objfile
-> psymbol_obstack
, sizeof (struct symloc
));
2025 ((struct symloc
*)result
->read_symtab_private
)->first_symnum
= first_symnum
;
2026 result
->read_symtab
= xcoff_psymtab_to_symtab
;
2028 /* Deduce the source language from the filename for this psymtab. */
2029 psymtab_language
= deduce_language_from_filename (filename
);
2034 static struct partial_symtab
*xcoff_end_psymtab
2035 PARAMS ((struct partial_symtab
*, char **, int, int,
2036 struct partial_symtab
**, int, int));
2038 /* Close off the current usage of PST.
2039 Returns PST, or NULL if the partial symtab was empty and thrown away.
2041 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2043 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2044 are the information for includes and dependencies. */
2046 static struct partial_symtab
*
2047 xcoff_end_psymtab (pst
, include_list
, num_includes
, capping_symbol_number
,
2048 dependency_list
, number_dependencies
, textlow_not_set
)
2049 struct partial_symtab
*pst
;
2050 char **include_list
;
2052 int capping_symbol_number
;
2053 struct partial_symtab
**dependency_list
;
2054 int number_dependencies
;
2055 int textlow_not_set
;
2058 struct objfile
*objfile
= pst
-> objfile
;
2060 if (capping_symbol_number
!= -1)
2061 ((struct symloc
*)pst
->read_symtab_private
)->numsyms
=
2062 capping_symbol_number
2063 - ((struct symloc
*)pst
->read_symtab_private
)->first_symnum
;
2064 ((struct symloc
*)pst
->read_symtab_private
)->lineno_off
=
2065 first_fun_line_offset
;
2066 first_fun_line_offset
= 0;
2067 pst
->n_global_syms
=
2068 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2069 pst
->n_static_syms
=
2070 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2072 pst
->number_of_dependencies
= number_dependencies
;
2073 if (number_dependencies
)
2075 pst
->dependencies
= (struct partial_symtab
**)
2076 obstack_alloc (&objfile
->psymbol_obstack
,
2077 number_dependencies
* sizeof (struct partial_symtab
*));
2078 memcpy (pst
->dependencies
, dependency_list
,
2079 number_dependencies
* sizeof (struct partial_symtab
*));
2082 pst
->dependencies
= 0;
2084 for (i
= 0; i
< num_includes
; i
++)
2086 struct partial_symtab
*subpst
=
2087 allocate_psymtab (include_list
[i
], objfile
);
2089 subpst
->section_offsets
= pst
->section_offsets
;
2090 subpst
->read_symtab_private
=
2091 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
2092 sizeof (struct symloc
));
2093 ((struct symloc
*)subpst
->read_symtab_private
)->first_symnum
= 0;
2094 ((struct symloc
*)subpst
->read_symtab_private
)->numsyms
= 0;
2095 subpst
->textlow
= 0;
2096 subpst
->texthigh
= 0;
2098 /* We could save slight bits of space by only making one of these,
2099 shared by the entire set of include files. FIXME-someday. */
2100 subpst
->dependencies
= (struct partial_symtab
**)
2101 obstack_alloc (&objfile
->psymbol_obstack
,
2102 sizeof (struct partial_symtab
*));
2103 subpst
->dependencies
[0] = pst
;
2104 subpst
->number_of_dependencies
= 1;
2106 subpst
->globals_offset
=
2107 subpst
->n_global_syms
=
2108 subpst
->statics_offset
=
2109 subpst
->n_static_syms
= 0;
2113 subpst
->read_symtab
= pst
->read_symtab
;
2116 sort_pst_symbols (pst
);
2118 /* If there is already a psymtab or symtab for a file of this name,
2119 remove it. (If there is a symtab, more drastic things also
2120 happen.) This happens in VxWorks. */
2121 free_named_symtabs (pst
->filename
);
2123 if (num_includes
== 0
2124 && number_dependencies
== 0
2125 && pst
->n_global_syms
== 0
2126 && pst
->n_static_syms
== 0)
2128 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2129 it is on the obstack, but we can forget to chain it on the list. */
2130 /* Empty psymtabs happen as a result of header files which don't have
2131 any symbols in them. There can be a lot of them. */
2132 struct partial_symtab
*prev_pst
;
2134 /* First, snip it out of the psymtab chain */
2136 if (pst
->objfile
->psymtabs
== pst
)
2137 pst
->objfile
->psymtabs
= pst
->next
;
2139 for (prev_pst
= pst
->objfile
->psymtabs
; prev_pst
; prev_pst
= pst
->next
)
2140 if (prev_pst
->next
== pst
)
2141 prev_pst
->next
= pst
->next
;
2143 /* Next, put it on a free list for recycling */
2145 pst
->next
= pst
->objfile
->free_psymtabs
;
2146 pst
->objfile
->free_psymtabs
= pst
;
2148 /* Indicate that psymtab was thrown away. */
2149 pst
= (struct partial_symtab
*)NULL
;
2154 static void swap_sym
PARAMS ((struct internal_syment
*,
2155 union internal_auxent
*, char **, char **,
2159 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2160 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2161 the symbol and its auxents. */
2164 swap_sym (symbol
, aux
, name
, raw
, symnump
, objfile
)
2165 struct internal_syment
*symbol
;
2166 union internal_auxent
*aux
;
2169 unsigned int *symnump
;
2170 struct objfile
*objfile
;
2172 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2173 if (symbol
->n_zeroes
)
2175 /* If it's exactly E_SYMNMLEN characters long it isn't
2177 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2179 /* FIXME: wastes memory for symbols which we don't end up putting
2180 into the minimal symbols. */
2182 p
= obstack_alloc (&objfile
->psymbol_obstack
, E_SYMNMLEN
+ 1);
2183 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2184 p
[E_SYMNMLEN
] = '\0';
2188 /* Point to the unswapped name as that persists as long as the
2190 *name
= ((struct external_syment
*)*raw
)->e
.e_name
;
2192 else if (symbol
->n_sclass
& 0x80)
2194 *name
= ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
2199 *name
= ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
2203 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2204 if (symbol
->n_numaux
> 0)
2206 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2207 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2209 *symnump
+= symbol
->n_numaux
;
2210 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2215 scan_xcoff_symtab (section_offsets
, objfile
)
2216 struct section_offsets
*section_offsets
;
2217 struct objfile
*objfile
;
2219 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2220 char *filestring
= NULL
;
2223 int past_first_source_file
= 0;
2228 /* Current partial symtab */
2229 struct partial_symtab
*pst
;
2231 /* List of current psymtab's include files */
2232 char **psymtab_include_list
;
2233 int includes_allocated
;
2236 /* Index within current psymtab dependency list */
2237 struct partial_symtab
**dependency_list
;
2238 int dependencies_used
, dependencies_allocated
;
2241 struct internal_syment symbol
;
2242 union internal_auxent main_aux
;
2243 unsigned int ssymnum
;
2245 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2246 CORE_ADDR last_csect_val
= 0;
2247 int last_csect_sec
= 0;
2248 int misc_func_recorded
= 0; /* true if any misc. function */
2249 int textlow_not_set
= 1;
2251 pst
= (struct partial_symtab
*) 0;
2253 includes_allocated
= 30;
2255 psymtab_include_list
= (char **) alloca (includes_allocated
*
2258 dependencies_allocated
= 30;
2259 dependencies_used
= 0;
2261 (struct partial_symtab
**) alloca (dependencies_allocated
*
2262 sizeof (struct partial_symtab
*));
2264 last_source_file
= NULL
;
2266 abfd
= objfile
->obfd
;
2268 sraw_symbol
= ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl
;
2269 nsyms
= ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl_num_syms
;
2271 while (ssymnum
< nsyms
)
2273 int sclass
= ((struct external_syment
*)sraw_symbol
)->e_sclass
[0] & 0xff;
2274 /* This is the type we pass to partial-stab.h. A less kludgy solution
2275 would be to break out partial-stab.h into its various parts--shuffle
2276 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2277 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2287 /* The CSECT auxent--always the last auxent. */
2288 union internal_auxent csect_aux
;
2289 unsigned int symnum_before
= ssymnum
;
2291 swap_sym (&symbol
, &main_aux
, &namestring
, &sraw_symbol
,
2293 if (symbol
.n_numaux
> 1)
2295 bfd_coff_swap_aux_in
2297 sraw_symbol
- coff_data(abfd
)->local_symesz
,
2300 symbol
.n_numaux
- 1,
2305 csect_aux
= main_aux
;
2307 /* If symbol name starts with ".$" or "$", ignore it. */
2308 if (namestring
[0] == '$'
2309 || (namestring
[0] == '.' && namestring
[1] == '$'))
2312 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2315 switch (csect_aux
.x_csect
.x_smclas
)
2318 if (last_csect_name
)
2320 /* If no misc. function recorded in the last
2321 seen csect, enter it as a function. This
2322 will take care of functions like strcmp()
2325 if (!misc_func_recorded
)
2327 RECORD_MINIMAL_SYMBOL
2328 (last_csect_name
, last_csect_val
,
2329 mst_text
, last_csect_sec
,
2335 /* We have to allocate one psymtab for
2336 each program csect, because their text
2337 sections need not be adjacent. */
2339 (pst
, psymtab_include_list
, includes_used
,
2340 symnum_before
, dependency_list
,
2341 dependencies_used
, textlow_not_set
);
2343 dependencies_used
= 0;
2344 /* Give all psymtabs for this source file the same
2346 pst
= xcoff_start_psymtab
2347 (objfile
, section_offsets
,
2350 objfile
->global_psymbols
.next
,
2351 objfile
->static_psymbols
.next
);
2354 if (namestring
&& namestring
[0] == '.')
2356 last_csect_name
= namestring
;
2357 last_csect_val
= symbol
.n_value
;
2359 secnum_to_section (symbol
.n_scnum
, objfile
);
2364 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2365 if (highval
> pst
->texthigh
)
2366 pst
->texthigh
= highval
;
2367 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2368 pst
->textlow
= symbol
.n_value
;
2370 misc_func_recorded
= 0;
2374 /* Data variables are recorded in the minimal symbol
2375 table, except for section symbols. */
2376 if (*namestring
!= '.')
2377 prim_record_minimal_symbol_and_info
2378 (namestring
, symbol
.n_value
,
2379 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2380 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2386 warning ("More than one XMC_TC0 symbol found.");
2387 toc_offset
= symbol
.n_value
;
2389 /* Make TOC offset relative to start address of section. */
2390 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2392 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2396 /* These symbols tell us where the TOC entry for a
2397 variable is, not the variable itself. */
2406 switch (csect_aux
.x_csect
.x_smclas
)
2409 /* A function entry point. */
2411 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2412 first_fun_line_offset
=
2413 main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2414 RECORD_MINIMAL_SYMBOL
2415 (namestring
, symbol
.n_value
,
2416 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2417 secnum_to_section (symbol
.n_scnum
, objfile
),
2422 /* shared library function trampoline code entry
2425 /* record trampoline code entries as
2426 mst_solib_trampoline symbol. When we lookup mst
2427 symbols, we will choose mst_text over
2428 mst_solib_trampoline. */
2429 RECORD_MINIMAL_SYMBOL
2430 (namestring
, symbol
.n_value
,
2431 mst_solib_trampoline
,
2432 secnum_to_section (symbol
.n_scnum
, objfile
),
2437 /* The symbols often have the same names as
2438 debug symbols for functions, and confuse
2444 /* xlc puts each variable in a separate csect,
2445 so we get an XTY_SD for each variable. But
2446 gcc puts several variables in a csect, so
2447 that each variable only gets an XTY_LD. We
2448 still need to record them. This will
2449 typically be XMC_RW; I suspect XMC_RO and
2450 XMC_BS might be possible too. */
2451 if (*namestring
!= '.')
2452 prim_record_minimal_symbol_and_info
2453 (namestring
, symbol
.n_value
,
2454 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2455 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2462 switch (csect_aux
.x_csect
.x_smclas
)
2466 /* Common variables are recorded in the minimal symbol
2467 table, except for section symbols. */
2468 if (*namestring
!= '.')
2469 prim_record_minimal_symbol_and_info
2470 (namestring
, symbol
.n_value
,
2471 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2472 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2485 unsigned int symnum_before
;
2487 symnum_before
= ssymnum
;
2488 swap_sym (&symbol
, &main_aux
, &namestring
, &sraw_symbol
,
2491 /* See if the last csect needs to be recorded. */
2493 if (last_csect_name
&& !misc_func_recorded
)
2496 /* If no misc. function recorded in the last seen csect, enter
2497 it as a function. This will take care of functions like
2498 strcmp() compiled by xlc. */
2500 RECORD_MINIMAL_SYMBOL
2501 (last_csect_name
, last_csect_val
,
2502 mst_text
, last_csect_sec
, objfile
);
2507 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2508 symnum_before
, dependency_list
,
2509 dependencies_used
, textlow_not_set
);
2511 dependencies_used
= 0;
2513 first_fun_line_offset
= 0;
2515 /* XCOFF, according to the AIX 3.2 documentation, puts the
2516 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2517 do things the standard COFF way and put it in the auxent.
2518 We use the auxent if the symbol is ".file" and an auxent
2519 exists, otherwise use the symbol itself. */
2520 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2522 filestring
= coff_getfilename (&main_aux
, objfile
);
2525 filestring
= namestring
;
2527 pst
= xcoff_start_psymtab (objfile
, section_offsets
,
2530 objfile
->global_psymbols
.next
,
2531 objfile
->static_psymbols
.next
);
2532 last_csect_name
= NULL
;
2538 static struct complaint msg
=
2539 {"Storage class %d not recognized during scan", 0, 0};
2540 complain (&msg
, sclass
);
2544 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2545 to handle only the C_FUN and C_EXT. */
2560 /* C_EINCL means we are switching back to the main file. But there
2561 is no reason to care; the only thing we want to know about
2562 includes is the names of all the included (.h) files. */
2567 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2571 /* I don't think the name of the common block (as opposed to the
2572 variables within it) is something which is user visible
2580 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2581 so C_LSYM would appear to be only for locals. */
2587 /* We probably could save a few instructions by assuming that
2588 C_LSYM, C_PSYM, etc., never have auxents. */
2590 ((struct external_syment
*)sraw_symbol
)->e_numaux
[0] + 1;
2592 sraw_symbol
+= sizeof (struct external_syment
) * naux1
;
2601 /* The value of the C_FUN is not the address of the function (it
2602 appears to be the address before linking), but as long as it
2603 is smaller than the actual address, then find_pc_partial_function
2604 will use the minimal symbols instead. I hope. */
2612 swap_sym (&symbol
, &main_aux
, &namestring
, &sraw_symbol
,
2614 #define CUR_SYMBOL_TYPE stype
2615 #define CUR_SYMBOL_VALUE symbol.n_value
2617 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2618 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2620 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms) 0
2621 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
2623 /* We have already set the namestring. */
2624 #define SET_NAMESTRING() /* */
2626 #include "partial-stab.h"
2632 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2633 ssymnum
, dependency_list
,
2634 dependencies_used
, textlow_not_set
);
2637 /* Record the toc offset value of this symbol table into ldinfo structure.
2638 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2639 this information would be file auxiliary header. */
2641 if (xcoff_add_toc_to_loadinfo_hook
!= NULL
)
2642 (*xcoff_add_toc_to_loadinfo_hook
) ((unsigned long) toc_offset
);
2645 /* Scan and build partial symbols for a symbol file.
2646 We have been initialized by a call to dbx_symfile_init, which
2647 put all the relevant info into a "struct dbx_symfile_info",
2648 hung off the objfile structure.
2650 SECTION_OFFSETS contains offsets relative to which the symbols in the
2651 various sections are (depending where the sections were actually loaded).
2652 MAINLINE is true if we are reading the main symbol
2653 table (as opposed to a shared lib or dynamically loaded file). */
2656 xcoff_initial_scan (objfile
, section_offsets
, mainline
)
2657 struct objfile
*objfile
;
2658 struct section_offsets
*section_offsets
;
2659 int mainline
; /* FIXME comments above */
2663 struct cleanup
*back_to
;
2664 int num_symbols
; /* # of symbols */
2665 file_ptr symtab_offset
; /* symbol table and */
2666 file_ptr stringtab_offset
; /* string table file offsets */
2667 struct coff_symfile_info
*info
;
2671 /* Initialize load info structure. */
2672 if (mainline
&& xcoff_init_loadinfo_hook
!= NULL
)
2673 (*xcoff_init_loadinfo_hook
) ();
2675 info
= (struct coff_symfile_info
*) objfile
-> sym_private
;
2676 symfile_bfd
= abfd
= objfile
->obfd
;
2677 name
= objfile
->name
;
2679 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2680 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2681 stringtab_offset
= symtab_offset
+
2682 num_symbols
* coff_data(abfd
)->local_symesz
;
2684 info
->min_lineno_offset
= 0;
2685 info
->max_lineno_offset
= 0;
2686 bfd_map_over_sections (abfd
, find_linenos
, info
);
2688 if (num_symbols
> 0)
2690 /* Read the string table. */
2691 init_stringtab (abfd
, stringtab_offset
, objfile
);
2693 /* Read the .debug section, if present. */
2696 bfd_size_type length
;
2697 char *debugsec
= NULL
;
2699 secp
= bfd_get_section_by_name (abfd
, ".debug");
2702 length
= bfd_section_size (abfd
, secp
);
2706 (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
2708 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2709 (file_ptr
) 0, length
))
2711 error ("Error reading .debug section of `%s': %s",
2712 name
, bfd_errmsg (bfd_get_error ()));
2716 ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
=
2721 /* Read the symbols. We keep them in core because we will want to
2722 access them randomly in read_symbol*. */
2723 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2725 error ("Error reading symbols from %s: %s",
2726 name
, bfd_errmsg (bfd_get_error ()));
2727 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2728 ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl
=
2729 obstack_alloc (&objfile
->symbol_obstack
, size
);
2730 ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl_num_syms
=
2733 val
= bfd_read (((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl
,
2736 perror_with_name ("reading symbol table");
2738 /* If we are reinitializing, or if we have never loaded syms yet, init */
2740 || objfile
->global_psymbols
.size
== 0
2741 || objfile
->static_psymbols
.size
== 0)
2742 /* I'm not sure how how good num_symbols is; the rule of thumb in
2743 init_psymbol_list was developed for a.out. On the one hand,
2744 num_symbols includes auxents. On the other hand, it doesn't
2746 init_psymbol_list (objfile
, num_symbols
);
2748 free_pending_blocks ();
2749 back_to
= make_cleanup (really_free_pendings
, 0);
2751 init_minimal_symbol_collection ();
2752 make_cleanup (discard_minimal_symbols
, 0);
2754 /* Now that the symbol table data of the executable file are all in core,
2755 process them and define symbols accordingly. */
2757 scan_xcoff_symtab (section_offsets
, objfile
);
2759 /* Install any minimal symbols that have been collected as the current
2760 minimal symbols for this objfile. */
2762 install_minimal_symbols (objfile
);
2764 do_cleanups (back_to
);
2767 static struct section_offsets
*
2768 xcoff_symfile_offsets (objfile
, addr
)
2769 struct objfile
*objfile
;
2772 struct section_offsets
*section_offsets
;
2775 objfile
->num_sections
= SECT_OFF_MAX
;
2776 section_offsets
= (struct section_offsets
*)
2778 (&objfile
-> psymbol_obstack
,
2779 sizeof (struct section_offsets
)
2780 + sizeof (section_offsets
->offsets
) * objfile
->num_sections
);
2782 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2783 of the .text section. This strikes me as wrong--whether the
2784 offset to be applied to symbol reading is relative to the start
2785 address of the section depends on the symbol format. In any
2786 event, this whole "addr" concept is pretty broken (it doesn't
2787 handle any section but .text sensibly), so just ignore the addr
2788 parameter and use 0. rs6000-nat.c will set the correct section
2789 offsets via objfile_relocate. */
2790 for (i
= 0; i
< objfile
->num_sections
; ++i
)
2791 ANOFFSET (section_offsets
, i
) = 0;
2793 return section_offsets
;
2796 /* Register our ability to parse symbols for xcoff BFD files. */
2798 static struct sym_fns xcoff_sym_fns
=
2801 /* Because the bfd uses coff_flavour, we need to specially kludge
2802 the flavour. It is possible that coff and xcoff should be merged as
2803 they do have fundamental similarities (for example, the extra storage
2804 classes used for stabs could presumably be recognized in any COFF file).
2805 However, in addition to obvious things like all the csect hair, there are
2806 some subtler differences between xcoffread.c and coffread.c, notably
2807 the fact that coffread.c has no need to read in all the symbols, but
2808 xcoffread.c reads all the symbols and does in fact randomly access them
2809 (in C_BSTAT and line number processing). */
2811 (enum bfd_flavour
)-1,
2813 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2814 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
2815 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
2816 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
2817 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
2818 NULL
/* next: pointer to next struct sym_fns */
2822 _initialize_xcoffread ()
2824 add_symtab_fns(&xcoff_sym_fns
);
2826 func_symbol_type
= init_type (TYPE_CODE_FUNC
, 1, 0,
2827 "<function, no debug info>", NULL
);
2828 TYPE_TARGET_TYPE (func_symbol_type
) = builtin_type_int
;
2830 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
2831 "<variable, no debug info>", NULL
);