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 /* We put a pointer to this structure in the read_symtab_private field
97 /* First symbol number for this file. */
101 /* Number of symbols in the section of the symbol table devoted to
102 this file's symbols (actually, the section bracketed may contain
103 more than just this file's symbols). If numsyms is 0, the only
104 reason for this thing's existence is the dependency list. Nothing
105 else will happen when it is read in. */
109 /* Position of the start of the line number information for this psymtab. */
110 unsigned int lineno_off
;
113 /* Remember what we deduced to be the source language of this psymtab. */
115 static enum language psymtab_language
= language_unknown
;
118 /* Simplified internal version of coff symbol table information */
122 int c_symnum
; /* symbol number of this entry */
123 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
125 unsigned char c_sclass
;
130 /* last function's saved coff symbol `cs' */
132 static struct coff_symbol fcn_cs_saved
;
134 static bfd
*symfile_bfd
;
136 /* Core address of start and end of text of current source file.
137 This is calculated from the first function seen after a C_FILE
141 static CORE_ADDR cur_src_end_addr
;
143 /* Core address of the end of the first object file. */
145 static CORE_ADDR first_object_file_end
;
147 /* initial symbol-table-debug-string vector length */
149 #define INITIAL_STABVECTOR_LENGTH 40
151 /* Nonzero if within a function (so symbols should be local,
152 if nothing says specifically). */
156 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
157 there is any reason not to just use a #define, but might as well
158 ask BFD for the size and store it here, I guess. */
160 static unsigned local_symesz
;
162 struct coff_symfile_info
{
163 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
164 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
166 /* Pointer to the string table. */
169 /* Pointer to debug section. */
172 /* Pointer to the a.out symbol table. */
175 /* Number of symbols in symtbl. */
178 /* Offset in data section to TOC anchor. */
179 CORE_ADDR toc_offset
;
182 static struct complaint storclass_complaint
=
183 {"Unexpected storage class: %d", 0, 0};
185 static struct complaint bf_notfound_complaint
=
186 {"line numbers off, `.bf' symbol not found", 0, 0};
188 static struct complaint ef_complaint
=
189 {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
191 static struct complaint eb_complaint
=
192 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
195 xcoff_initial_scan
PARAMS ((struct objfile
*, struct section_offsets
*, int));
198 scan_xcoff_symtab
PARAMS ((struct section_offsets
*, struct objfile
*));
201 xcoff_next_symbol_text
PARAMS ((struct objfile
*));
204 record_include_begin
PARAMS ((struct coff_symbol
*));
207 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned,
208 CORE_ADDR
, CORE_ADDR
, unsigned *));
211 init_stringtab
PARAMS ((bfd
*, file_ptr
, struct objfile
*));
214 xcoff_symfile_init
PARAMS ((struct objfile
*));
217 xcoff_new_init
PARAMS ((struct objfile
*));
220 xcoff_symfile_finish
PARAMS ((struct objfile
*));
222 static struct section_offsets
*
223 xcoff_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
226 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
229 coff_getfilename
PARAMS ((union internal_auxent
*, struct objfile
*));
232 read_symbol
PARAMS ((struct internal_syment
*, int));
235 read_symbol_lineno
PARAMS ((int));
238 read_symbol_nvalue
PARAMS ((int));
240 static struct symbol
*
241 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
244 read_xcoff_symtab
PARAMS ((struct partial_symtab
*));
248 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
252 compare_lte
PARAMS ((const void *, const void *));
254 static struct linetable
*
255 arrange_linetable
PARAMS ((struct linetable
*));
258 record_include_end
PARAMS ((struct coff_symbol
*));
261 process_linenos
PARAMS ((CORE_ADDR
, CORE_ADDR
));
264 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
266 static int secnum_to_section
PARAMS ((int, struct objfile
*));
267 static asection
* secnum_to_bfd_section
PARAMS ((int, struct objfile
*));
269 struct find_targ_sec_arg
{
275 static void find_targ_sec
PARAMS ((bfd
*, asection
*, void *));
277 static void find_targ_sec (abfd
, sect
, obj
)
282 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*)obj
;
283 if (sect
->target_index
== args
->targ_index
)
285 /* This is the section. Figure out what SECT_OFF_* code it is. */
286 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
287 *args
->resultp
= SECT_OFF_TEXT
;
288 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
289 *args
->resultp
= SECT_OFF_DATA
;
291 *args
->resultp
= SECT_OFF_BSS
;
292 *args
->bfd_sect
= sect
;
296 /* Return the section number (SECT_OFF_*) that CS points to. */
298 secnum_to_section (secnum
, objfile
)
300 struct objfile
*objfile
;
302 int off
= SECT_OFF_TEXT
;
303 asection
*sect
= NULL
;
304 struct find_targ_sec_arg args
;
305 args
.targ_index
= secnum
;
307 args
.bfd_sect
= §
;
308 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
312 /* Return the BFD section that CS points to. */
314 secnum_to_bfd_section (secnum
, objfile
)
316 struct objfile
*objfile
;
318 int off
= SECT_OFF_TEXT
;
319 asection
*sect
= NULL
;
320 struct find_targ_sec_arg args
;
321 args
.targ_index
= secnum
;
323 args
.bfd_sect
= §
;
324 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
328 /* add a given stab string into given stab vector. */
333 add_stab_to_list (stabname
, stabvector
)
335 struct pending_stabs
**stabvector
;
337 if ( *stabvector
== NULL
) {
338 *stabvector
= (struct pending_stabs
*)
339 xmalloc (sizeof (struct pending_stabs
) +
340 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
341 (*stabvector
)->count
= 0;
342 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
344 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
345 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
346 *stabvector
= (struct pending_stabs
*)
347 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
348 (*stabvector
)->length
* sizeof (char*));
350 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
357 /* Linenos are processed on a file-by-file basis.
361 1) xlc (IBM's native c compiler) postpones static function code
362 emission to the end of a compilation unit. This way it can
363 determine if those functions (statics) are needed or not, and
364 can do some garbage collection (I think). This makes line
365 numbers and corresponding addresses unordered, and we end up
366 with a line table like:
383 and that breaks gdb's binary search on line numbers, if the
384 above table is not sorted on line numbers. And that sort
385 should be on function based, since gcc can emit line numbers
388 10 0x100 - for the init/test part of a for stmt.
391 10 0x400 - for the increment part of a for stmt.
393 arrange_linetable() will do this sorting.
395 2) aix symbol table might look like:
397 c_file // beginning of a new file
398 .bi // beginning of include file
399 .ei // end of include file
403 basically, .bi/.ei pairs do not necessarily encapsulate
404 their scope. They need to be recorded, and processed later
405 on when we come the end of the compilation unit.
406 Include table (inclTable) and process_linenos() handle
410 /* compare line table entry addresses. */
413 compare_lte (lte1p
, lte2p
)
417 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
418 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
419 return lte1
->pc
- lte2
->pc
;
422 /* Given a line table with function entries are marked, arrange its functions
423 in ascending order and strip off function entry markers and return it in
424 a newly created table. If the old one is good enough, return the old one. */
425 /* FIXME: I think all this stuff can be replaced by just passing
426 sort_linevec = 1 to end_symtab. */
428 static struct linetable
*
429 arrange_linetable (oldLineTb
)
430 struct linetable
*oldLineTb
; /* old linetable */
433 newline
, /* new line count */
434 function_count
; /* # of functions */
436 struct linetable_entry
*fentry
; /* function entry vector */
437 int fentry_size
; /* # of function entries */
438 struct linetable
*newLineTb
; /* new line table */
440 #define NUM_OF_FUNCTIONS 20
442 fentry_size
= NUM_OF_FUNCTIONS
;
443 fentry
= (struct linetable_entry
*)
444 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
446 for (function_count
=0, ii
=0; ii
<oldLineTb
->nitems
; ++ii
) {
448 if (oldLineTb
->item
[ii
].line
== 0) { /* function entry found. */
450 if (function_count
>= fentry_size
) { /* make sure you have room. */
452 fentry
= (struct linetable_entry
*)
453 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
455 fentry
[function_count
].line
= ii
;
456 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
461 if (function_count
== 0) {
465 else if (function_count
> 1)
466 qsort (fentry
, function_count
, sizeof(struct linetable_entry
), compare_lte
);
468 /* allocate a new line table. */
469 newLineTb
= (struct linetable
*)
471 (sizeof (struct linetable
) +
472 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
474 /* if line table does not start with a function beginning, copy up until
478 if (oldLineTb
->item
[0].line
!= 0)
480 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
481 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
483 /* Now copy function lines one by one. */
485 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
{
503 char *name
; /* include filename */
505 /* Offsets to the line table. end points to the last entry which is
506 part of this include file. */
509 struct subfile
*subfile
;
510 unsigned funStartLine
; /* start line # of its function */
513 #define INITIAL_INCLUDE_TABLE_LENGTH 20
514 static InclTable
*inclTable
; /* global include table */
515 static int inclIndx
; /* last entry to table */
516 static int inclLength
; /* table length */
517 static int inclDepth
; /* nested include depth */
519 static void allocate_include_entry
PARAMS ((void));
522 record_include_begin (cs
)
523 struct coff_symbol
*cs
;
527 /* In xcoff, we assume include files cannot be nested (not in .c files
528 of course, but in corresponding .s files.). */
530 /* This can happen with old versions of GCC.
531 GCC 2.3.3-930426 does not exhibit this on a test case which
532 a user said produced the message for him. */
533 static struct complaint msg
= {"Nested C_BINCL symbols", 0, 0};
538 allocate_include_entry ();
540 inclTable
[inclIndx
].name
= cs
->c_name
;
541 inclTable
[inclIndx
].begin
= cs
->c_value
;
545 record_include_end (cs
)
546 struct coff_symbol
*cs
;
552 static struct complaint msg
= {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
556 allocate_include_entry ();
558 pTbl
= &inclTable
[inclIndx
];
559 pTbl
->end
= cs
->c_value
;
566 allocate_include_entry ()
568 if (inclTable
== NULL
)
570 inclTable
= (InclTable
*)
571 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
573 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
574 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
577 else if (inclIndx
>= inclLength
)
579 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
580 inclTable
= (InclTable
*)
581 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
582 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
583 '\0', sizeof (InclTable
)*INITIAL_INCLUDE_TABLE_LENGTH
);
587 /* Global variable to pass the psymtab down to all the routines involved
588 in psymtab to symtab processing. */
589 static struct partial_symtab
*this_symtab_psymtab
;
591 /* given the start and end addresses of a compilation unit (or a csect,
592 at times) process its lines and create appropriate line vectors. */
595 process_linenos (start
, end
)
596 CORE_ADDR start
, end
;
599 file_ptr max_offset
=
600 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
603 /* subfile structure for the main compilation unit. */
604 struct subfile main_subfile
;
606 /* In the main source file, any time we see a function entry, we
607 reset this variable to function's absolute starting line number.
608 All the following line numbers in the function are relative to
609 this, and we record absolute line numbers in record_line(). */
611 unsigned int main_source_baseline
= 0;
616 ((struct symloc
*)this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
618 goto return_after_cleanup
;
620 memset (&main_subfile
, '\0', sizeof (main_subfile
));
623 /* All source lines were in the main source file. None in include files. */
625 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
626 &main_source_baseline
);
630 /* There was source with line numbers in include files. */
631 main_source_baseline
= 0;
632 for (ii
=0; ii
< inclIndx
; ++ii
)
634 struct subfile
*tmpSubfile
;
636 /* If there is main file source before include file, enter it. */
637 if (offset
< inclTable
[ii
].begin
)
640 (&main_subfile
, offset
, inclTable
[ii
].begin
- LINESZ
,
641 start
, 0, &main_source_baseline
);
644 /* Have a new subfile for the include file. */
646 tmpSubfile
= inclTable
[ii
].subfile
=
647 (struct subfile
*) xmalloc (sizeof (struct subfile
));
649 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
650 firstLine
= &(inclTable
[ii
].funStartLine
);
652 /* Enter include file's lines now. */
653 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
654 inclTable
[ii
].end
, start
, 0, firstLine
);
656 if (offset
<= inclTable
[ii
].end
)
657 offset
= inclTable
[ii
].end
+ LINESZ
;
660 /* All the include files' line have been processed at this point. Now,
661 enter remaining lines of the main file, if any left. */
662 if (offset
< max_offset
+ 1 - LINESZ
)
664 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
665 &main_source_baseline
);
669 /* Process main file's line numbers. */
670 if (main_subfile
.line_vector
)
672 struct linetable
*lineTb
, *lv
;
674 lv
= main_subfile
.line_vector
;
676 /* Line numbers are not necessarily ordered. xlc compilation will
677 put static function to the end. */
679 lineTb
= arrange_linetable (lv
);
682 current_subfile
->line_vector
= (struct linetable
*)
683 xrealloc (lv
, (sizeof (struct linetable
)
684 + lv
->nitems
* sizeof (struct linetable_entry
)));
689 current_subfile
->line_vector
= lineTb
;
692 current_subfile
->line_vector_length
=
693 current_subfile
->line_vector
->nitems
;
696 /* Now, process included files' line numbers. */
698 for (ii
=0; ii
< inclIndx
; ++ii
)
700 if ((inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
702 struct linetable
*lineTb
, *lv
;
704 lv
= (inclTable
[ii
].subfile
)->line_vector
;
706 /* Line numbers are not necessarily ordered. xlc compilation will
707 put static function to the end. */
709 lineTb
= arrange_linetable (lv
);
713 /* For the same include file, we might want to have more than one
714 subfile. This happens if we have something like:
722 while foo.h including code in it. (stupid but possible)
723 Since start_subfile() looks at the name and uses an
724 existing one if finds, we need to provide a fake name and
728 start_subfile (inclTable
[ii
].name
, (char*)0);
731 /* Pick a fake name that will produce the same results as this
732 one when passed to deduce_language_from_filename. Kludge on
734 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
735 if (fakename
== NULL
)
737 start_subfile (fakename
, (char*)0);
738 free (current_subfile
->name
);
740 current_subfile
->name
= strdup (inclTable
[ii
].name
);
745 current_subfile
->line_vector
=
746 (struct linetable
*) xrealloc
747 (lv
, (sizeof (struct linetable
)
748 + lv
->nitems
* sizeof (struct linetable_entry
)));
754 current_subfile
->line_vector
= lineTb
;
757 current_subfile
->line_vector_length
=
758 current_subfile
->line_vector
->nitems
;
759 start_subfile (pop_subfile (), (char*)0);
763 return_after_cleanup
:
765 /* We don't want to keep alloc/free'ing the global include file table. */
768 /* Start with a fresh subfile structure for the next file. */
769 memset (&main_subfile
, '\0', sizeof (struct subfile
));
773 aix_process_linenos ()
775 /* process line numbers and enter them into line vector */
776 process_linenos (last_source_start_addr
, cur_src_end_addr
);
780 /* Enter a given range of lines into the line vector.
781 can be called in the following two ways:
782 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
783 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
785 endoffset points to the last line table entry that we should pay
789 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
,
791 struct subfile
*subfile
;
792 unsigned beginoffset
, endoffset
; /* offsets to line table */
793 CORE_ADDR startaddr
, endaddr
;
796 unsigned int curoffset
;
798 struct external_lineno ext_lnno
;
799 struct internal_lineno int_lnno
;
800 unsigned int limit_offset
;
803 if (endoffset
== 0 && startaddr
== 0 && endaddr
== 0)
805 curoffset
= beginoffset
;
807 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
812 if (endoffset
>= limit_offset
)
814 static struct complaint msg
=
815 {"Bad line table offset in C_EINCL directive", 0, 0};
819 limit_offset
= endoffset
;
823 abfd
= this_symtab_psymtab
->objfile
->obfd
;
825 while (curoffset
<= limit_offset
)
827 bfd_seek (abfd
, curoffset
, SEEK_SET
);
828 bfd_read (&ext_lnno
, sizeof (struct external_lineno
), 1, abfd
);
829 bfd_coff_swap_lineno_in (abfd
, &ext_lnno
, &int_lnno
);
831 /* Find the address this line represents. */
832 addr
= (int_lnno
.l_lnno
833 ? int_lnno
.l_addr
.l_paddr
834 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
835 addr
+= ANOFFSET (this_symtab_psymtab
->objfile
->section_offsets
,
838 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
841 if (int_lnno
.l_lnno
== 0)
843 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
844 record_line (subfile
, 0, addr
);
848 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
, addr
);
854 /* Save the vital information for use when closing off the current file.
855 NAME is the file name the symbols came from, START_ADDR is the first
856 text address for the file, and SIZE is the number of bytes of text. */
858 #define complete_symtab(name, start_addr) { \
859 last_source_file = savestring (name, strlen (name)); \
860 last_source_start_addr = start_addr; \
864 /* Refill the symbol table input buffer
865 and set the variables that control fetching entries from it.
866 Reports an error if no data available.
867 This function can read past the end of the symbol table
868 (into the string table) but this does no harm. */
870 /* Reading symbol table has to be fast! Keep the followings as macros, rather
873 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
877 if (namestr[0] == '.') ++namestr; \
878 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
879 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
880 misc_func_recorded = 1; \
884 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
885 nested. At any given time, a symbol can only be in one static block.
886 This is the base address of current static block, zero if non exists. */
888 static int static_block_base
= 0;
890 /* Section number for the current static block. */
892 static int static_block_section
= -1;
894 /* true if space for symbol name has been allocated. */
896 static int symname_alloced
= 0;
898 /* Next symbol to read. Pointer into raw seething symbol table. */
900 static char *raw_symbol
;
902 /* This is the function which stabsread.c calls to get symbol
906 xcoff_next_symbol_text (objfile
)
907 struct objfile
*objfile
;
909 struct internal_syment symbol
;
910 static struct complaint msg
=
911 {"Unexpected symbol continuation", 0, 0};
913 /* FIXME: is this the same as the passed arg? */
914 objfile
= this_symtab_psymtab
->objfile
;
916 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
921 /* Return something which points to '\0' and hope the symbol reading
922 code does something reasonable. */
925 else if (symbol
.n_sclass
& 0x80)
928 ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
931 coff_data (objfile
->obfd
)->local_symesz
;
938 /* Return something which points to '\0' and hope the symbol reading
939 code does something reasonable. */
945 /* Read symbols for a given partial symbol table. */
948 read_xcoff_symtab (pst
)
949 struct partial_symtab
*pst
;
951 struct objfile
*objfile
= pst
->objfile
;
952 bfd
*abfd
= objfile
->obfd
;
953 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
954 char *strtbl
= ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
;
956 ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
;
958 struct internal_syment symbol
[1];
959 union internal_auxent main_aux
;
960 struct coff_symbol cs
[1];
961 CORE_ADDR file_start_addr
= 0;
962 CORE_ADDR file_end_addr
= 0;
964 int next_file_symnum
= -1;
965 unsigned int max_symnum
;
966 int just_started
= 1;
968 int fcn_start_addr
= 0;
970 struct coff_symbol fcn_stab_saved
;
972 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
973 union internal_auxent fcn_aux_saved
;
974 struct context_stack
*new;
976 char *filestring
= " _start_ "; /* Name of the current file. */
978 char *last_csect_name
; /* last seen csect's name and value */
979 CORE_ADDR last_csect_val
;
982 this_symtab_psymtab
= pst
;
984 /* Get the appropriate COFF "constants" related to the file we're
986 local_symesz
= coff_data (abfd
)->local_symesz
;
988 last_source_file
= NULL
;
993 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
994 record_debugformat ("XCOFF");
995 symnum
= ((struct symloc
*)pst
->read_symtab_private
)->first_symnum
;
997 symnum
+ ((struct symloc
*)pst
->read_symtab_private
)->numsyms
;
998 first_object_file_end
= 0;
1001 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
1002 + symnum
* local_symesz
;
1004 while (symnum
< max_symnum
)
1007 QUIT
; /* make this command interruptable. */
1009 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1010 /* read one symbol into `cs' structure. After processing the
1011 whole symbol table, only string table will be kept in memory,
1012 symbol table and debug section of xcoff will be freed. Thus
1013 we can mark symbols with names in string table as
1018 /* Swap and align the symbol into a reasonable C structure. */
1019 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1021 cs
->c_symnum
= symnum
;
1022 cs
->c_naux
= symbol
->n_numaux
;
1023 if (symbol
->n_zeroes
)
1025 symname_alloced
= 0;
1026 /* We must use the original, unswapped, name here so the name field
1027 pointed to by cs->c_name will persist throughout xcoffread. If
1028 we use the new field, it gets overwritten for each symbol. */
1029 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
1030 /* If it's exactly E_SYMNMLEN characters long it isn't
1032 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1035 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
1036 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1037 p
[E_SYMNMLEN
] = '\0';
1039 symname_alloced
= 1;
1042 else if (symbol
->n_sclass
& 0x80)
1044 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1045 symname_alloced
= 0;
1049 /* in string table */
1050 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
1051 symname_alloced
= 1;
1053 cs
->c_value
= symbol
->n_value
;
1054 cs
->c_sclass
= symbol
->n_sclass
;
1055 cs
->c_secnum
= symbol
->n_scnum
;
1056 cs
->c_type
= (unsigned)symbol
->n_type
;
1058 raw_symbol
+= coff_data (abfd
)->local_symesz
;
1061 /* Save addr of first aux entry. */
1062 raw_auxptr
= raw_symbol
;
1064 /* Skip all the auxents associated with this symbol. */
1065 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1067 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1072 /* if symbol name starts with ".$" or "$", ignore it. */
1073 if (cs
->c_name
[0] == '$'
1074 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1077 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1079 if (last_source_file
)
1082 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT
);
1087 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
1088 record_debugformat ("XCOFF");
1089 cur_src_end_addr
= first_object_file_end
;
1090 /* done with all files, everything from here on is globals */
1093 /* if explicitly specified as a function, treat is as one. */
1094 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1096 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1097 0, cs
->c_naux
, &main_aux
);
1098 goto function_entry_point
;
1101 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1104 /* Dealing with a symbol with a csect entry. */
1106 #define CSECT(PP) ((PP)->x_csect)
1107 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1108 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1109 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1110 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1112 /* Convert the auxent to something we can access. */
1113 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1114 0, cs
->c_naux
, &main_aux
);
1116 switch (CSECT_SMTYP (&main_aux
))
1120 /* Ignore all external references. */
1124 /* A section description. */
1126 switch (CSECT_SCLAS (&main_aux
))
1132 /* A program csect is seen. We have to allocate one
1133 symbol table for each program csect. Normally gdb
1134 prefers one symtab for each source file. In case
1135 of AIX, one source file might include more than one
1136 [PR] csect, and they don't have to be adjacent in
1137 terms of the space they occupy in memory. Thus, one
1138 single source file might get fragmented in the
1139 memory and gdb's file start and end address
1140 approach does not work! GCC (and I think xlc) seem
1141 to put all the code in the unnamed program csect. */
1143 if (last_csect_name
)
1145 complete_symtab (filestring
, file_start_addr
);
1146 cur_src_end_addr
= file_end_addr
;
1147 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT
);
1150 /* Give all csects for this source file the same
1152 start_symtab (filestring
, NULL
, (CORE_ADDR
)0);
1153 record_debugformat ("XCOFF");
1156 /* If this is the very first csect seen,
1157 basically `__start'. */
1160 first_object_file_end
1161 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1166 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1168 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1170 if (cs
->c_name
&& cs
->c_name
[0] == '.')
1172 last_csect_name
= cs
->c_name
;
1173 last_csect_val
= cs
->c_value
;
1174 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1179 /* All other symbols are put into the minimal symbol
1192 /* Ignore the symbol. */
1200 switch (CSECT_SCLAS (&main_aux
))
1203 /* a function entry point. */
1204 function_entry_point
:
1206 fcn_start_addr
= cs
->c_value
;
1208 /* save the function header info, which will be used
1209 when `.bf' is seen. */
1211 fcn_aux_saved
= main_aux
;
1215 /* shared library function trampoline code entry point. */
1219 /* The symbols often have the same names as debug symbols for
1220 functions, and confuse lookup_symbol. */
1224 /* xlc puts each variable in a separate csect, so we get
1225 an XTY_SD for each variable. But gcc puts several
1226 variables in a csect, so that each variable only gets
1227 an XTY_LD. This will typically be XMC_RW; I suspect
1228 XMC_RO and XMC_BS might be possible too.
1229 These variables are put in the minimal symbol table
1236 /* Common symbols are put into the minimal symbol table only. */
1244 switch (cs
->c_sclass
)
1249 /* c_value field contains symnum of next .file entry in table
1250 or symnum of first global after last .file. */
1252 next_file_symnum
= cs
->c_value
;
1254 /* Complete symbol table for last object file containing
1255 debugging information. */
1257 /* Whether or not there was a csect in the previous file, we
1258 have to call `end_stabs' and `start_stabs' to reset
1259 type_vector, line_vector, etc. structures. */
1261 complete_symtab (filestring
, file_start_addr
);
1262 cur_src_end_addr
= file_end_addr
;
1263 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT
);
1266 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1267 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1268 standard COFF way and put it in the auxent. We use the auxent if
1269 the symbol is ".file" and an auxent exists, otherwise use the symbol
1270 itself. Simple enough. */
1271 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1273 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1274 0, cs
->c_naux
, &main_aux
);
1275 filestring
= coff_getfilename (&main_aux
, objfile
);
1278 filestring
= cs
->c_name
;
1281 start_symtab (filestring
, (char *)NULL
, (CORE_ADDR
)0);
1282 record_debugformat ("XCOFF");
1283 last_csect_name
= 0;
1285 /* reset file start and end addresses. A compilation unit with no text
1286 (only data) should have zero file boundaries. */
1287 file_start_addr
= file_end_addr
= 0;
1291 fcn_stab_saved
= *cs
;
1295 if (STREQ (cs
->c_name
, ".bf"))
1297 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1299 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1300 0, cs
->c_naux
, &main_aux
);
1302 within_function
= 1;
1304 new = push_context (0, fcn_start_addr
+ off
);
1306 new->name
= define_symbol
1307 (fcn_cs_saved
.c_value
+ off
,
1308 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1309 if (new->name
!= NULL
)
1310 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT
;
1312 else if (STREQ (cs
->c_name
, ".ef"))
1315 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1316 0, cs
->c_naux
, &main_aux
);
1318 /* The value of .ef is the address of epilogue code;
1319 not useful for gdb. */
1320 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1321 contains number of lines to '}' */
1323 if (context_stack_depth
<= 0)
1324 { /* We attempted to pop an empty context stack */
1325 complain (&ef_complaint
, cs
->c_symnum
);
1326 within_function
= 0;
1329 new = pop_context ();
1330 /* Stack must be empty now. */
1331 if (context_stack_depth
> 0 || new == NULL
)
1333 complain (&ef_complaint
, cs
->c_symnum
);
1334 within_function
= 0;
1338 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1340 (fcn_cs_saved
.c_value
1341 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1342 + ANOFFSET (objfile
->section_offsets
,
1345 within_function
= 0;
1350 /* Begin static block. */
1352 struct internal_syment symbol
;
1354 read_symbol (&symbol
, cs
->c_value
);
1355 static_block_base
= symbol
.n_value
;
1356 static_block_section
=
1357 secnum_to_section (symbol
.n_scnum
, objfile
);
1362 /* End of static block. */
1363 static_block_base
= 0;
1364 static_block_section
= -1;
1375 static struct complaint msg
=
1376 {"Unrecognized storage class %d.", 0, 0};
1377 complain (&msg
, cs
->c_sclass
);
1391 /* beginning of include file */
1392 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1393 order. Thus, when wee see them, we might not know enough info
1394 to process them. Thus, we'll be saving them into a table
1395 (inclTable) and postpone their processing. */
1397 record_include_begin (cs
);
1401 /* End of include file. */
1402 /* See the comment after case C_BINCL. */
1403 record_include_end (cs
);
1407 if (STREQ (cs
->c_name
, ".bb"))
1410 new = push_context (depth
,
1412 + ANOFFSET (objfile
->section_offsets
,
1415 else if (STREQ (cs
->c_name
, ".eb"))
1417 if (context_stack_depth
<= 0)
1418 { /* We attempted to pop an empty context stack */
1419 complain (&eb_complaint
, cs
->c_symnum
);
1422 new = pop_context ();
1423 if (depth
-- != new->depth
)
1425 complain (&eb_complaint
, cs
->c_symnum
);
1428 if (local_symbols
&& context_stack_depth
> 0)
1430 /* Make a block for the local symbols within. */
1431 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1434 + ANOFFSET (objfile
->section_offsets
,
1438 local_symbols
= new->locals
;
1443 process_xcoff_symbol (cs
, objfile
);
1448 if (last_source_file
)
1452 complete_symtab (filestring
, file_start_addr
);
1453 cur_src_end_addr
= file_end_addr
;
1454 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT
);
1455 /* When reading symbols for the last C_FILE of the objfile, try
1456 to make sure that we set pst->symtab to the symtab for the
1457 file, not to the _globals_ symtab. I'm not sure whether this
1458 actually works right or when/if it comes up. */
1459 if (pst
->symtab
== NULL
)
1465 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1466 (SYMBOL2) = (struct symbol *) \
1467 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1468 *(SYMBOL2) = *(SYMBOL1);
1471 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1472 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1475 static struct type
*func_symbol_type
;
1476 static struct type
*var_symbol_type
;
1478 /* process one xcoff symbol. */
1480 static struct symbol
*
1481 process_xcoff_symbol (cs
, objfile
)
1482 register struct coff_symbol
*cs
;
1483 struct objfile
*objfile
;
1485 struct symbol onesymbol
;
1486 register struct symbol
*sym
= &onesymbol
;
1487 struct symbol
*sym2
= NULL
;
1493 if (cs
->c_secnum
< 0)
1495 /* The value is a register number, offset within a frame, etc.,
1496 and does not get relocated. */
1502 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1503 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1510 memset (sym
, '\0', sizeof (struct symbol
));
1512 /* default assumptions */
1513 SYMBOL_VALUE (sym
) = cs
->c_value
+ off
;
1514 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1515 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1517 if (ISFCN (cs
->c_type
))
1519 /* At this point, we don't know the type of the function. This
1520 will be patched with the type from its stab entry later on in
1521 patch_block_stabs (), unless the file was compiled without -g. */
1523 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1524 SYMBOL_TYPE (sym
) = func_symbol_type
;
1526 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1527 SYMBOL_DUP (sym
, sym2
);
1529 if (cs
->c_sclass
== C_EXT
)
1530 add_symbol_to_list (sym2
, &global_symbols
);
1531 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1532 add_symbol_to_list (sym2
, &file_symbols
);
1536 /* In case we can't figure out the type, provide default. */
1537 SYMBOL_TYPE (sym
) = var_symbol_type
;
1539 switch (cs
->c_sclass
)
1542 /* The values of functions and global symbols are now resolved
1543 via the global_sym_chain in stabsread.c. */
1545 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1546 add_stab_to_list (name
, &global_stabs
);
1548 add_stab_to_list (name
, &file_stabs
);
1552 add_stab_to_list (name
, &global_stabs
);
1557 common_block_start (cs
->c_name
, objfile
);
1561 common_block_end (objfile
);
1565 complain (&storclass_complaint
, cs
->c_sclass
);
1577 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1580 SYMBOL_SECTION (sym
) = sec
;
1587 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1588 all statics and we need to distinguish file-scope versus
1589 function-scope using within_function. We do this by
1590 changing the string we pass to define_symbol to use 'S'
1591 where we need to, which is not necessarily super-clean,
1592 but seems workable enough. */
1594 if (*name
== ':' || (pp
= (char *) strchr(name
, ':')) == NULL
)
1598 if (*pp
== 'V' && !within_function
)
1600 sym
= define_symbol ((cs
->c_value
1601 + ANOFFSET (objfile
->section_offsets
,
1602 static_block_section
)),
1603 cs
->c_name
, 0, 0, objfile
);
1606 SYMBOL_VALUE (sym
) += static_block_base
;
1607 SYMBOL_SECTION (sym
) = static_block_section
;
1616 /* Extract the file name from the aux entry of a C_FILE symbol.
1617 Result is in static storage and is only good for temporary use. */
1620 coff_getfilename (aux_entry
, objfile
)
1621 union internal_auxent
*aux_entry
;
1622 struct objfile
*objfile
;
1624 static char buffer
[BUFSIZ
];
1626 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1628 ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
1629 + aux_entry
->x_file
.x_n
.x_offset
);
1632 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1633 buffer
[FILNMLEN
] = '\0';
1638 /* Set *SYMBOL to symbol number symno in symtbl. */
1640 read_symbol (symbol
, symno
)
1641 struct internal_syment
*symbol
;
1645 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1648 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1650 if (symno
< 0 || symno
>= nsyms
)
1652 static struct complaint msg
=
1653 {"Invalid symbol offset", 0, 0};
1655 symbol
->n_value
= 0;
1656 symbol
->n_scnum
= -1;
1659 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1660 stbl
+ (symno
*local_symesz
),
1664 /* Get value corresponding to symbol number symno in symtbl. */
1667 read_symbol_nvalue (symno
)
1670 struct internal_syment symbol
[1];
1672 read_symbol (symbol
, symno
);
1673 return symbol
->n_value
;
1677 /* Find the address of the function corresponding to symno, where
1678 symno is the symbol pointed to by the linetable. */
1681 read_symbol_lineno (symno
)
1685 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1688 ((struct coff_symfile_info
*)this_symtab_psymtab
->objfile
->sym_private
)
1690 struct internal_syment symbol
[1];
1691 union internal_auxent main_aux
[1];
1695 complain (&bf_notfound_complaint
);
1699 /* Note that just searching for a short distance (e.g. 50 symbols)
1700 is not enough, at least in the following case.
1703 [many .stabx entries]
1704 [a few functions, referring to foo]
1708 What happens here is that the assembler moves the .stabx entries
1709 to right before the ".bf" for foo, but the symbol for "foo" is before
1710 all the stabx entries. See PR gdb/2222. */
1712 /* Maintaining a table of .bf entries might be preferable to this search.
1713 If I understand things correctly it would need to be done only for
1714 the duration of a single psymtab to symtab conversion. */
1715 while (symno
< nsyms
)
1717 bfd_coff_swap_sym_in (symfile_bfd
,
1718 stbl
+ (symno
* local_symesz
), symbol
);
1719 if (symbol
->n_sclass
== C_FCN
&& STREQ (symbol
->n_name
, ".bf"))
1721 symno
+= symbol
->n_numaux
+ 1;
1724 complain (&bf_notfound_complaint
);
1728 /* take aux entry and return its lineno */
1730 bfd_coff_swap_aux_in (this_symtab_psymtab
->objfile
->obfd
,
1731 stbl
+ symno
* local_symesz
,
1732 symbol
->n_type
, symbol
->n_sclass
,
1733 0, symbol
->n_numaux
, main_aux
);
1735 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1738 /* Support for line number handling */
1740 /* This function is called for every section; it finds the outer limits
1741 * of the line table (minimum and maximum file offset) so that the
1742 * mainline code can read the whole thing for efficiency.
1745 find_linenos (abfd
, asect
, vpinfo
)
1750 struct coff_symfile_info
*info
;
1752 file_ptr offset
, maxoff
;
1754 count
= asect
->lineno_count
;
1756 if (!STREQ (asect
->name
, ".text") || count
== 0)
1759 size
= count
* coff_data (abfd
)->local_linesz
;
1760 info
= (struct coff_symfile_info
*)vpinfo
;
1761 offset
= asect
->line_filepos
;
1762 maxoff
= offset
+ size
;
1764 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1765 info
->min_lineno_offset
= offset
;
1767 if (maxoff
> info
->max_lineno_offset
)
1768 info
->max_lineno_offset
= maxoff
;
1771 static void xcoff_psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
1774 xcoff_psymtab_to_symtab_1 (pst
)
1775 struct partial_symtab
*pst
;
1777 struct cleanup
*old_chain
;
1786 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1791 /* Read in all partial symtabs on which this one is dependent */
1792 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1793 if (!pst
->dependencies
[i
]->readin
)
1795 /* Inform about additional files that need to be read in. */
1798 fputs_filtered (" ", gdb_stdout
);
1800 fputs_filtered ("and ", gdb_stdout
);
1802 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1803 wrap_here (""); /* Flush output */
1804 gdb_flush (gdb_stdout
);
1806 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1809 if (((struct symloc
*)pst
->read_symtab_private
)->numsyms
!= 0)
1811 /* Init stuff necessary for reading in symbols. */
1814 old_chain
= make_cleanup ((make_cleanup_func
) really_free_pendings
, 0);
1816 read_xcoff_symtab (pst
);
1817 sort_symtab_syms (pst
->symtab
);
1819 do_cleanups (old_chain
);
1825 static void xcoff_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
1827 /* Read in all of the symbols for a given psymtab for real.
1828 Be verbose about it if the user wants that. */
1831 xcoff_psymtab_to_symtab (pst
)
1832 struct partial_symtab
*pst
;
1842 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1847 if (((struct symloc
*)pst
->read_symtab_private
)->numsyms
!= 0
1848 || pst
->number_of_dependencies
)
1850 /* Print the message now, before reading the string table,
1851 to avoid disconcerting pauses. */
1854 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1855 gdb_flush (gdb_stdout
);
1858 sym_bfd
= pst
->objfile
->obfd
;
1860 next_symbol_text_func
= xcoff_next_symbol_text
;
1862 xcoff_psymtab_to_symtab_1 (pst
);
1864 /* Match with global symbols. This only needs to be done once,
1865 after all of the symtabs and dependencies have been read in. */
1866 scan_file_globals (pst
->objfile
);
1868 /* Finish up the debug error message. */
1870 printf_filtered ("done.\n");
1875 xcoff_new_init (objfile
)
1876 struct objfile
*objfile
;
1878 stabsread_new_init ();
1879 buildsym_new_init ();
1882 /* Do initialization in preparation for reading symbols from OBJFILE.
1884 We will only be called if this is an XCOFF or XCOFF-like file.
1885 BFD handles figuring out the format of the file, and code in symfile.c
1886 uses BFD's determination to vector to us. */
1889 xcoff_symfile_init (objfile
)
1890 struct objfile
*objfile
;
1892 /* Allocate struct to keep track of the symfile */
1893 objfile
-> sym_private
= xmmalloc (objfile
-> md
,
1894 sizeof (struct coff_symfile_info
));
1896 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1897 find this causes a significant slowdown in gdb then we could
1898 set it in the debug symbol readers only when necessary. */
1899 objfile
->flags
|= OBJF_REORDERED
;
1901 init_entry_point_info (objfile
);
1904 /* Perform any local cleanups required when we are done with a particular
1905 objfile. I.E, we are in the process of discarding all symbol information
1906 for an objfile, freeing up all memory held for it, and unlinking the
1907 objfile struct from the global list of known objfiles. */
1910 xcoff_symfile_finish (objfile
)
1911 struct objfile
*objfile
;
1913 if (objfile
-> sym_private
!= NULL
)
1915 mfree (objfile
-> md
, objfile
-> sym_private
);
1918 /* Start with a fresh include table for the next objfile. */
1924 inclIndx
= inclLength
= inclDepth
= 0;
1929 init_stringtab (abfd
, offset
, objfile
)
1932 struct objfile
*objfile
;
1936 unsigned char lengthbuf
[4];
1939 ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
= NULL
;
1941 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1942 error ("cannot seek to string table in %s: %s",
1943 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1945 val
= bfd_read ((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
1946 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1948 /* If no string table is needed, then the file may end immediately
1949 after the symbols. Just return with `strtbl' set to NULL. */
1951 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1954 /* Allocate string table from symbol_obstack. We will need this table
1955 as long as we have its symbol table around. */
1957 strtbl
= (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
1958 ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
= strtbl
;
1960 /* Copy length buffer, the first byte is usually zero and is
1961 used for stabs with a name length of zero. */
1962 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1963 if (length
== sizeof lengthbuf
)
1966 val
= bfd_read (strtbl
+ sizeof lengthbuf
, 1, length
- sizeof lengthbuf
,
1969 if (val
!= length
- sizeof lengthbuf
)
1970 error ("cannot read string table from %s: %s",
1971 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1972 if (strtbl
[length
- 1] != '\0')
1973 error ("bad symbol file: string table does not end with null character");
1978 /* If we have not yet seen a function for this psymtab, this is 0. If we
1979 have seen one, it is the offset in the line numbers of the line numbers
1981 static unsigned int first_fun_line_offset
;
1983 static struct partial_symtab
*xcoff_start_psymtab
1984 PARAMS ((struct objfile
*, struct section_offsets
*, char *, int,
1985 struct partial_symbol
**, struct partial_symbol
**));
1987 /* Allocate and partially fill a partial symtab. It will be
1988 completely filled at the end of the symbol list.
1990 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1991 is the address relative to which its symbols are (incremental) or 0
1994 static struct partial_symtab
*
1995 xcoff_start_psymtab (objfile
, section_offsets
,
1996 filename
, first_symnum
, global_syms
, static_syms
)
1997 struct objfile
*objfile
;
1998 struct section_offsets
*section_offsets
;
2001 struct partial_symbol
**global_syms
;
2002 struct partial_symbol
**static_syms
;
2004 struct partial_symtab
*result
=
2005 start_psymtab_common (objfile
, section_offsets
,
2007 /* We fill in textlow later. */
2009 global_syms
, static_syms
);
2011 result
->read_symtab_private
= (char *)
2012 obstack_alloc (&objfile
-> psymbol_obstack
, sizeof (struct symloc
));
2013 ((struct symloc
*)result
->read_symtab_private
)->first_symnum
= first_symnum
;
2014 result
->read_symtab
= xcoff_psymtab_to_symtab
;
2016 /* Deduce the source language from the filename for this psymtab. */
2017 psymtab_language
= deduce_language_from_filename (filename
);
2022 static struct partial_symtab
*xcoff_end_psymtab
2023 PARAMS ((struct partial_symtab
*, char **, int, int,
2024 struct partial_symtab
**, int, int));
2026 /* Close off the current usage of PST.
2027 Returns PST, or NULL if the partial symtab was empty and thrown away.
2029 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2031 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2032 are the information for includes and dependencies. */
2034 static struct partial_symtab
*
2035 xcoff_end_psymtab (pst
, include_list
, num_includes
, capping_symbol_number
,
2036 dependency_list
, number_dependencies
, textlow_not_set
)
2037 struct partial_symtab
*pst
;
2038 char **include_list
;
2040 int capping_symbol_number
;
2041 struct partial_symtab
**dependency_list
;
2042 int number_dependencies
;
2043 int textlow_not_set
;
2046 struct objfile
*objfile
= pst
-> objfile
;
2048 if (capping_symbol_number
!= -1)
2049 ((struct symloc
*)pst
->read_symtab_private
)->numsyms
=
2050 capping_symbol_number
2051 - ((struct symloc
*)pst
->read_symtab_private
)->first_symnum
;
2052 ((struct symloc
*)pst
->read_symtab_private
)->lineno_off
=
2053 first_fun_line_offset
;
2054 first_fun_line_offset
= 0;
2055 pst
->n_global_syms
=
2056 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2057 pst
->n_static_syms
=
2058 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2060 pst
->number_of_dependencies
= number_dependencies
;
2061 if (number_dependencies
)
2063 pst
->dependencies
= (struct partial_symtab
**)
2064 obstack_alloc (&objfile
->psymbol_obstack
,
2065 number_dependencies
* sizeof (struct partial_symtab
*));
2066 memcpy (pst
->dependencies
, dependency_list
,
2067 number_dependencies
* sizeof (struct partial_symtab
*));
2070 pst
->dependencies
= 0;
2072 for (i
= 0; i
< num_includes
; i
++)
2074 struct partial_symtab
*subpst
=
2075 allocate_psymtab (include_list
[i
], objfile
);
2077 subpst
->section_offsets
= pst
->section_offsets
;
2078 subpst
->read_symtab_private
=
2079 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
2080 sizeof (struct symloc
));
2081 ((struct symloc
*)subpst
->read_symtab_private
)->first_symnum
= 0;
2082 ((struct symloc
*)subpst
->read_symtab_private
)->numsyms
= 0;
2083 subpst
->textlow
= 0;
2084 subpst
->texthigh
= 0;
2086 /* We could save slight bits of space by only making one of these,
2087 shared by the entire set of include files. FIXME-someday. */
2088 subpst
->dependencies
= (struct partial_symtab
**)
2089 obstack_alloc (&objfile
->psymbol_obstack
,
2090 sizeof (struct partial_symtab
*));
2091 subpst
->dependencies
[0] = pst
;
2092 subpst
->number_of_dependencies
= 1;
2094 subpst
->globals_offset
=
2095 subpst
->n_global_syms
=
2096 subpst
->statics_offset
=
2097 subpst
->n_static_syms
= 0;
2101 subpst
->read_symtab
= pst
->read_symtab
;
2104 sort_pst_symbols (pst
);
2106 /* If there is already a psymtab or symtab for a file of this name,
2107 remove it. (If there is a symtab, more drastic things also
2108 happen.) This happens in VxWorks. */
2109 free_named_symtabs (pst
->filename
);
2111 if (num_includes
== 0
2112 && number_dependencies
== 0
2113 && pst
->n_global_syms
== 0
2114 && pst
->n_static_syms
== 0)
2116 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2117 it is on the obstack, but we can forget to chain it on the list. */
2118 /* Empty psymtabs happen as a result of header files which don't have
2119 any symbols in them. There can be a lot of them. */
2121 discard_psymtab (pst
);
2123 /* Indicate that psymtab was thrown away. */
2124 pst
= (struct partial_symtab
*)NULL
;
2129 static void swap_sym
PARAMS ((struct internal_syment
*,
2130 union internal_auxent
*, char **, char **,
2134 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2135 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2136 the symbol and its auxents. */
2139 swap_sym (symbol
, aux
, name
, raw
, symnump
, objfile
)
2140 struct internal_syment
*symbol
;
2141 union internal_auxent
*aux
;
2144 unsigned int *symnump
;
2145 struct objfile
*objfile
;
2147 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2148 if (symbol
->n_zeroes
)
2150 /* If it's exactly E_SYMNMLEN characters long it isn't
2152 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2154 /* FIXME: wastes memory for symbols which we don't end up putting
2155 into the minimal symbols. */
2157 p
= obstack_alloc (&objfile
->psymbol_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
*)objfile
->sym_private
)->debugsec
2174 *name
= ((struct coff_symfile_info
*)objfile
->sym_private
)->strtbl
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 scan_xcoff_symtab (section_offsets
, objfile
)
2191 struct section_offsets
*section_offsets
;
2192 struct objfile
*objfile
;
2194 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2195 char *filestring
= NULL
;
2198 int past_first_source_file
= 0;
2203 /* Current partial symtab */
2204 struct partial_symtab
*pst
;
2206 /* List of current psymtab's include files */
2207 char **psymtab_include_list
;
2208 int includes_allocated
;
2211 /* Index within current psymtab dependency list */
2212 struct partial_symtab
**dependency_list
;
2213 int dependencies_used
, dependencies_allocated
;
2216 struct internal_syment symbol
;
2217 union internal_auxent main_aux
;
2218 unsigned int ssymnum
;
2220 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2221 CORE_ADDR last_csect_val
= 0;
2222 int last_csect_sec
= 0;
2223 int misc_func_recorded
= 0; /* true if any misc. function */
2224 int textlow_not_set
= 1;
2226 pst
= (struct partial_symtab
*) 0;
2228 includes_allocated
= 30;
2230 psymtab_include_list
= (char **) alloca (includes_allocated
*
2233 dependencies_allocated
= 30;
2234 dependencies_used
= 0;
2236 (struct partial_symtab
**) alloca (dependencies_allocated
*
2237 sizeof (struct partial_symtab
*));
2239 last_source_file
= NULL
;
2241 abfd
= objfile
->obfd
;
2243 sraw_symbol
= ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl
;
2244 nsyms
= ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl_num_syms
;
2246 while (ssymnum
< nsyms
)
2248 int sclass
= ((struct external_syment
*)sraw_symbol
)->e_sclass
[0] & 0xff;
2249 /* This is the type we pass to partial-stab.h. A less kludgy solution
2250 would be to break out partial-stab.h into its various parts--shuffle
2251 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2252 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2262 /* The CSECT auxent--always the last auxent. */
2263 union internal_auxent csect_aux
;
2264 unsigned int symnum_before
= ssymnum
;
2266 swap_sym (&symbol
, &main_aux
, &namestring
, &sraw_symbol
,
2268 if (symbol
.n_numaux
> 1)
2270 bfd_coff_swap_aux_in
2272 sraw_symbol
- coff_data(abfd
)->local_symesz
,
2275 symbol
.n_numaux
- 1,
2280 csect_aux
= main_aux
;
2282 /* If symbol name starts with ".$" or "$", ignore it. */
2283 if (namestring
[0] == '$'
2284 || (namestring
[0] == '.' && namestring
[1] == '$'))
2287 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2290 switch (csect_aux
.x_csect
.x_smclas
)
2293 if (last_csect_name
)
2295 /* If no misc. function recorded in the last
2296 seen csect, enter it as a function. This
2297 will take care of functions like strcmp()
2300 if (!misc_func_recorded
)
2302 RECORD_MINIMAL_SYMBOL
2303 (last_csect_name
, last_csect_val
,
2304 mst_text
, last_csect_sec
,
2310 /* We have to allocate one psymtab for
2311 each program csect, because their text
2312 sections need not be adjacent. */
2314 (pst
, psymtab_include_list
, includes_used
,
2315 symnum_before
, dependency_list
,
2316 dependencies_used
, textlow_not_set
);
2318 dependencies_used
= 0;
2319 /* Give all psymtabs for this source file the same
2321 pst
= xcoff_start_psymtab
2322 (objfile
, section_offsets
,
2325 objfile
->global_psymbols
.next
,
2326 objfile
->static_psymbols
.next
);
2329 if (namestring
&& namestring
[0] == '.')
2331 last_csect_name
= namestring
;
2332 last_csect_val
= symbol
.n_value
;
2334 secnum_to_section (symbol
.n_scnum
, objfile
);
2339 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2340 if (highval
> pst
->texthigh
)
2341 pst
->texthigh
= highval
;
2342 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2343 pst
->textlow
= symbol
.n_value
;
2345 misc_func_recorded
= 0;
2349 /* Data variables are recorded in the minimal symbol
2350 table, except for section symbols. */
2351 if (*namestring
!= '.')
2352 prim_record_minimal_symbol_and_info
2353 (namestring
, symbol
.n_value
,
2354 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2355 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2361 warning ("More than one XMC_TC0 symbol found.");
2362 toc_offset
= symbol
.n_value
;
2364 /* Make TOC offset relative to start address of section. */
2365 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2367 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2371 /* These symbols tell us where the TOC entry for a
2372 variable is, not the variable itself. */
2381 switch (csect_aux
.x_csect
.x_smclas
)
2384 /* A function entry point. */
2386 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2387 first_fun_line_offset
=
2388 main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2389 RECORD_MINIMAL_SYMBOL
2390 (namestring
, symbol
.n_value
,
2391 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2392 secnum_to_section (symbol
.n_scnum
, objfile
),
2397 /* shared library function trampoline code entry
2400 /* record trampoline code entries as
2401 mst_solib_trampoline symbol. When we lookup mst
2402 symbols, we will choose mst_text over
2403 mst_solib_trampoline. */
2404 RECORD_MINIMAL_SYMBOL
2405 (namestring
, symbol
.n_value
,
2406 mst_solib_trampoline
,
2407 secnum_to_section (symbol
.n_scnum
, objfile
),
2412 /* The symbols often have the same names as
2413 debug symbols for functions, and confuse
2419 /* xlc puts each variable in a separate csect,
2420 so we get an XTY_SD for each variable. But
2421 gcc puts several variables in a csect, so
2422 that each variable only gets an XTY_LD. We
2423 still need to record them. This will
2424 typically be XMC_RW; I suspect XMC_RO and
2425 XMC_BS might be possible too. */
2426 if (*namestring
!= '.')
2427 prim_record_minimal_symbol_and_info
2428 (namestring
, symbol
.n_value
,
2429 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2430 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2437 switch (csect_aux
.x_csect
.x_smclas
)
2441 /* Common variables are recorded in the minimal symbol
2442 table, except for section symbols. */
2443 if (*namestring
!= '.')
2444 prim_record_minimal_symbol_and_info
2445 (namestring
, symbol
.n_value
,
2446 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2447 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2460 unsigned int symnum_before
;
2462 symnum_before
= ssymnum
;
2463 swap_sym (&symbol
, &main_aux
, &namestring
, &sraw_symbol
,
2466 /* See if the last csect needs to be recorded. */
2468 if (last_csect_name
&& !misc_func_recorded
)
2471 /* If no misc. function recorded in the last seen csect, enter
2472 it as a function. This will take care of functions like
2473 strcmp() compiled by xlc. */
2475 RECORD_MINIMAL_SYMBOL
2476 (last_csect_name
, last_csect_val
,
2477 mst_text
, last_csect_sec
, objfile
);
2482 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2483 symnum_before
, dependency_list
,
2484 dependencies_used
, textlow_not_set
);
2486 dependencies_used
= 0;
2488 first_fun_line_offset
= 0;
2490 /* XCOFF, according to the AIX 3.2 documentation, puts the
2491 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2492 do things the standard COFF way and put it in the auxent.
2493 We use the auxent if the symbol is ".file" and an auxent
2494 exists, otherwise use the symbol itself. */
2495 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2497 filestring
= coff_getfilename (&main_aux
, objfile
);
2500 filestring
= namestring
;
2502 pst
= xcoff_start_psymtab (objfile
, section_offsets
,
2505 objfile
->global_psymbols
.next
,
2506 objfile
->static_psymbols
.next
);
2507 last_csect_name
= NULL
;
2513 static struct complaint msg
=
2514 {"Storage class %d not recognized during scan", 0, 0};
2515 complain (&msg
, sclass
);
2519 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2520 to handle only the C_FUN and C_EXT. */
2535 /* C_EINCL means we are switching back to the main file. But there
2536 is no reason to care; the only thing we want to know about
2537 includes is the names of all the included (.h) files. */
2542 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2546 /* I don't think the name of the common block (as opposed to the
2547 variables within it) is something which is user visible
2555 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2556 so C_LSYM would appear to be only for locals. */
2562 /* We probably could save a few instructions by assuming that
2563 C_LSYM, C_PSYM, etc., never have auxents. */
2565 ((struct external_syment
*)sraw_symbol
)->e_numaux
[0] + 1;
2567 sraw_symbol
+= sizeof (struct external_syment
) * naux1
;
2576 /* The value of the C_FUN is not the address of the function (it
2577 appears to be the address before linking), but as long as it
2578 is smaller than the actual address, then find_pc_partial_function
2579 will use the minimal symbols instead. I hope. */
2587 swap_sym (&symbol
, &main_aux
, &namestring
, &sraw_symbol
,
2589 #define CUR_SYMBOL_TYPE stype
2590 #define CUR_SYMBOL_VALUE symbol.n_value
2592 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2593 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2595 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms) 0
2596 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
2598 /* We have already set the namestring. */
2599 #define SET_NAMESTRING() /* */
2601 #include "partial-stab.h"
2607 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2608 ssymnum
, dependency_list
,
2609 dependencies_used
, textlow_not_set
);
2612 /* Record the toc offset value of this symbol table into objfile structure.
2613 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2614 this information would be file auxiliary header. */
2616 ((struct coff_symfile_info
*) objfile
->sym_private
)->toc_offset
= toc_offset
;
2619 /* Return the toc offset value for a given objfile. */
2622 get_toc_offset (objfile
)
2623 struct objfile
*objfile
;
2626 return ((struct coff_symfile_info
*) objfile
->sym_private
)->toc_offset
;
2630 /* Scan and build partial symbols for a symbol file.
2631 We have been initialized by a call to dbx_symfile_init, which
2632 put all the relevant info into a "struct dbx_symfile_info",
2633 hung off the objfile structure.
2635 SECTION_OFFSETS contains offsets relative to which the symbols in the
2636 various sections are (depending where the sections were actually loaded).
2637 MAINLINE is true if we are reading the main symbol
2638 table (as opposed to a shared lib or dynamically loaded file). */
2641 xcoff_initial_scan (objfile
, section_offsets
, mainline
)
2642 struct objfile
*objfile
;
2643 struct section_offsets
*section_offsets
;
2644 int mainline
; /* FIXME comments above */
2648 struct cleanup
*back_to
;
2649 int num_symbols
; /* # of symbols */
2650 file_ptr symtab_offset
; /* symbol table and */
2651 file_ptr stringtab_offset
; /* string table file offsets */
2652 struct coff_symfile_info
*info
;
2656 info
= (struct coff_symfile_info
*) objfile
-> sym_private
;
2657 symfile_bfd
= abfd
= objfile
->obfd
;
2658 name
= objfile
->name
;
2660 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2661 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2662 stringtab_offset
= symtab_offset
+
2663 num_symbols
* coff_data(abfd
)->local_symesz
;
2665 info
->min_lineno_offset
= 0;
2666 info
->max_lineno_offset
= 0;
2667 bfd_map_over_sections (abfd
, find_linenos
, info
);
2669 if (num_symbols
> 0)
2671 /* Read the string table. */
2672 init_stringtab (abfd
, stringtab_offset
, objfile
);
2674 /* Read the .debug section, if present. */
2677 bfd_size_type length
;
2678 char *debugsec
= NULL
;
2680 secp
= bfd_get_section_by_name (abfd
, ".debug");
2683 length
= bfd_section_size (abfd
, secp
);
2687 (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
2689 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2690 (file_ptr
) 0, length
))
2692 error ("Error reading .debug section of `%s': %s",
2693 name
, bfd_errmsg (bfd_get_error ()));
2697 ((struct coff_symfile_info
*)objfile
->sym_private
)->debugsec
=
2702 /* Read the symbols. We keep them in core because we will want to
2703 access them randomly in read_symbol*. */
2704 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2706 error ("Error reading symbols from %s: %s",
2707 name
, bfd_errmsg (bfd_get_error ()));
2708 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2709 ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl
=
2710 obstack_alloc (&objfile
->symbol_obstack
, size
);
2711 ((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl_num_syms
=
2714 val
= bfd_read (((struct coff_symfile_info
*)objfile
->sym_private
)->symtbl
,
2717 perror_with_name ("reading symbol table");
2719 /* If we are reinitializing, or if we have never loaded syms yet, init */
2721 || objfile
->global_psymbols
.size
== 0
2722 || objfile
->static_psymbols
.size
== 0)
2723 /* I'm not sure how how good num_symbols is; the rule of thumb in
2724 init_psymbol_list was developed for a.out. On the one hand,
2725 num_symbols includes auxents. On the other hand, it doesn't
2727 init_psymbol_list (objfile
, num_symbols
);
2729 free_pending_blocks ();
2730 back_to
= make_cleanup ((make_cleanup_func
) really_free_pendings
, 0);
2732 init_minimal_symbol_collection ();
2733 make_cleanup ((make_cleanup_func
) discard_minimal_symbols
, 0);
2735 /* Now that the symbol table data of the executable file are all in core,
2736 process them and define symbols accordingly. */
2738 scan_xcoff_symtab (section_offsets
, objfile
);
2740 /* Install any minimal symbols that have been collected as the current
2741 minimal symbols for this objfile. */
2743 install_minimal_symbols (objfile
);
2745 do_cleanups (back_to
);
2748 static struct section_offsets
*
2749 xcoff_symfile_offsets (objfile
, addr
)
2750 struct objfile
*objfile
;
2753 struct section_offsets
*section_offsets
;
2756 objfile
->num_sections
= SECT_OFF_MAX
;
2757 section_offsets
= (struct section_offsets
*)
2759 (&objfile
-> psymbol_obstack
,
2760 sizeof (struct section_offsets
)
2761 + sizeof (section_offsets
->offsets
) * objfile
->num_sections
);
2763 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2764 of the .text section. This strikes me as wrong--whether the
2765 offset to be applied to symbol reading is relative to the start
2766 address of the section depends on the symbol format. In any
2767 event, this whole "addr" concept is pretty broken (it doesn't
2768 handle any section but .text sensibly), so just ignore the addr
2769 parameter and use 0. rs6000-nat.c will set the correct section
2770 offsets via objfile_relocate. */
2771 for (i
= 0; i
< objfile
->num_sections
; ++i
)
2772 ANOFFSET (section_offsets
, i
) = 0;
2774 return section_offsets
;
2777 /* Register our ability to parse symbols for xcoff BFD files. */
2779 static struct sym_fns xcoff_sym_fns
=
2782 /* Because the bfd uses coff_flavour, we need to specially kludge
2783 the flavour. It is possible that coff and xcoff should be merged as
2784 they do have fundamental similarities (for example, the extra storage
2785 classes used for stabs could presumably be recognized in any COFF file).
2786 However, in addition to obvious things like all the csect hair, there are
2787 some subtler differences between xcoffread.c and coffread.c, notably
2788 the fact that coffread.c has no need to read in all the symbols, but
2789 xcoffread.c reads all the symbols and does in fact randomly access them
2790 (in C_BSTAT and line number processing). */
2792 (enum bfd_flavour
)-1,
2794 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2795 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
2796 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
2797 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
2798 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
2799 NULL
/* next: pointer to next struct sym_fns */
2803 _initialize_xcoffread ()
2805 add_symtab_fns(&xcoff_sym_fns
);
2807 func_symbol_type
= init_type (TYPE_CODE_FUNC
, 1, 0,
2808 "<function, no debug info>", NULL
);
2809 TYPE_TARGET_TYPE (func_symbol_type
) = builtin_type_int
;
2811 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
2812 "<variable, no debug info>", NULL
);