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,
22 Boston, MA 02111-1307, USA. */
27 #include <sys/types.h>
30 #include "gdb_string.h"
32 #include <sys/param.h>
38 #include "coff/internal.h"
39 #include "libcoff.h" /* FIXME, internal data from BFD */
40 #include "coff/rs6000.h"
47 #include "stabsread.h"
48 #include "expression.h"
49 #include "language.h" /* Needed inside partial-stab.h */
50 #include "complaints.h"
52 #include "gdb-stabs.h"
54 /* For interface with stabsread.c. */
55 #include "aout/stab_gnu.h"
57 /* For interface with partial-stab.h. */
58 #define N_UNDF 0 /* Undefined symbol */
61 #define N_TEXT 4 /* Text sym -- defined at offset in text seg */
62 #define N_DATA 6 /* Data sym -- defined at offset in data seg */
63 #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
64 #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
65 #define N_FN 0x1f /* File name of .o file */
66 #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
67 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
68 N_DATA, or N_BSS. When the low-order bit of other types is set,
69 (e.g. N_WARNING versus N_FN), they are two different types. */
70 #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
73 /* The following symbols refer to set elements.
74 All the N_SET[ATDB] symbols with the same name form one set.
75 Space is allocated for the set in the text section, and each set
76 elements value is stored into one word of the space.
77 The first word of the space is the length of the set (number of elements).
79 The address of the set is made into an N_SETV symbol
80 whose name is the same as the name of the set.
81 This symbol acts like a N_DATA global symbol
82 in that it can satisfy undefined external references. */
84 /* These appear as input to LD, in a .o file. */
85 #define N_SETA 0x14 /* Absolute set element symbol */
86 #define N_SETT 0x16 /* Text set element symbol */
87 #define N_SETD 0x18 /* Data set element symbol */
88 #define N_SETB 0x1A /* Bss set element symbol */
90 /* This is output from LD. */
91 #define N_SETV 0x1C /* Pointer to set vector in data area. */
93 /* We put a pointer to this structure in the read_symtab_private field
99 /* First symbol number for this file. */
103 /* Number of symbols in the section of the symbol table devoted to
104 this file's symbols (actually, the section bracketed may contain
105 more than just this file's symbols). If numsyms is 0, the only
106 reason for this thing's existence is the dependency list. Nothing
107 else will happen when it is read in. */
111 /* Position of the start of the line number information for this psymtab. */
112 unsigned int lineno_off
;
115 /* Remember what we deduced to be the source language of this psymtab. */
117 static enum language psymtab_language
= language_unknown
;
120 /* Simplified internal version of coff symbol table information */
125 int c_symnum
; /* symbol number of this entry */
126 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
128 unsigned char c_sclass
;
133 /* last function's saved coff symbol `cs' */
135 static struct coff_symbol fcn_cs_saved
;
137 static bfd
*symfile_bfd
;
139 /* Core address of start and end of text of current source file.
140 This is calculated from the first function seen after a C_FILE
144 static CORE_ADDR cur_src_end_addr
;
146 /* Core address of the end of the first object file. */
148 static CORE_ADDR first_object_file_end
;
150 /* initial symbol-table-debug-string vector length */
152 #define INITIAL_STABVECTOR_LENGTH 40
154 /* Nonzero if within a function (so symbols should be local,
155 if nothing says specifically). */
159 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
160 there is any reason not to just use a #define, but might as well
161 ask BFD for the size and store it here, I guess. */
163 static unsigned local_symesz
;
165 struct coff_symfile_info
167 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
168 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
170 /* Pointer to the string table. */
173 /* Pointer to debug section. */
176 /* Pointer to the a.out symbol table. */
179 /* Number of symbols in symtbl. */
182 /* Offset in data section to TOC anchor. */
183 CORE_ADDR toc_offset
;
186 static struct complaint storclass_complaint
=
187 {"Unexpected storage class: %d", 0, 0};
189 static struct complaint bf_notfound_complaint
=
190 {"line numbers off, `.bf' symbol not found", 0, 0};
192 static struct complaint ef_complaint
=
193 {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
195 static struct complaint eb_complaint
=
196 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
198 static void xcoff_initial_scan (struct objfile
*, int);
200 static void scan_xcoff_symtab (struct objfile
*);
202 static char *xcoff_next_symbol_text (struct objfile
*);
204 static void record_include_begin (struct coff_symbol
*);
207 enter_line_range (struct subfile
*, unsigned, unsigned,
208 CORE_ADDR
, CORE_ADDR
, unsigned *);
210 static void init_stringtab (bfd
*, file_ptr
, struct objfile
*);
212 static void xcoff_symfile_init (struct objfile
*);
214 static void xcoff_new_init (struct objfile
*);
216 static void xcoff_symfile_finish (struct objfile
*);
219 xcoff_symfile_offsets (struct objfile
*, struct section_addr_info
*addrs
);
221 static void find_linenos (bfd
*, sec_ptr
, PTR
);
223 static char *coff_getfilename (union internal_auxent
*, struct objfile
*);
225 static void read_symbol (struct internal_syment
*, int);
227 static int read_symbol_lineno (int);
229 static CORE_ADDR
read_symbol_nvalue (int);
231 static struct symbol
*process_xcoff_symbol (struct coff_symbol
*,
234 static void read_xcoff_symtab (struct partial_symtab
*);
237 static void add_stab_to_list (char *, struct pending_stabs
**);
240 static int compare_lte (const void *, const void *);
242 static struct linetable
*arrange_linetable (struct linetable
*);
244 static void record_include_end (struct coff_symbol
*);
246 static void process_linenos (CORE_ADDR
, CORE_ADDR
);
249 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
251 static int secnum_to_section (int, struct objfile
*);
252 static asection
*secnum_to_bfd_section (int, struct objfile
*);
254 struct find_targ_sec_arg
259 struct objfile
*objfile
;
262 static void find_targ_sec (bfd
*, asection
*, void *);
265 find_targ_sec (abfd
, sect
, obj
)
270 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*) obj
;
271 struct objfile
*objfile
= args
->objfile
;
272 if (sect
->target_index
== args
->targ_index
)
274 /* This is the section. Figure out what SECT_OFF_* code it is. */
275 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
276 *args
->resultp
= SECT_OFF_TEXT (objfile
);
277 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
278 *args
->resultp
= SECT_OFF_DATA (objfile
);
280 *args
->resultp
= SECT_OFF_BSS (objfile
);
281 *args
->bfd_sect
= sect
;
285 /* Return the section number (SECT_OFF_*) that CS points to. */
287 secnum_to_section (secnum
, objfile
)
289 struct objfile
*objfile
;
291 int off
= SECT_OFF_TEXT (objfile
);
292 asection
*sect
= NULL
;
293 struct find_targ_sec_arg args
;
294 args
.targ_index
= secnum
;
296 args
.bfd_sect
= §
;
297 args
.objfile
= objfile
;
298 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
302 /* Return the BFD section that CS points to. */
304 secnum_to_bfd_section (secnum
, objfile
)
306 struct objfile
*objfile
;
308 int off
= SECT_OFF_TEXT (objfile
);
309 asection
*sect
= NULL
;
310 struct find_targ_sec_arg args
;
311 args
.targ_index
= secnum
;
313 args
.bfd_sect
= §
;
314 args
.objfile
= objfile
;
315 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
319 /* add a given stab string into given stab vector. */
324 add_stab_to_list (stabname
, stabvector
)
326 struct pending_stabs
**stabvector
;
328 if (*stabvector
== NULL
)
330 *stabvector
= (struct pending_stabs
*)
331 xmalloc (sizeof (struct pending_stabs
) +
332 INITIAL_STABVECTOR_LENGTH
* sizeof (char *));
333 (*stabvector
)->count
= 0;
334 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
336 else if ((*stabvector
)->count
>= (*stabvector
)->length
)
338 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
339 *stabvector
= (struct pending_stabs
*)
340 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
341 (*stabvector
)->length
* sizeof (char *));
343 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
348 /* Linenos are processed on a file-by-file basis.
352 1) xlc (IBM's native c compiler) postpones static function code
353 emission to the end of a compilation unit. This way it can
354 determine if those functions (statics) are needed or not, and
355 can do some garbage collection (I think). This makes line
356 numbers and corresponding addresses unordered, and we end up
357 with a line table like:
374 and that breaks gdb's binary search on line numbers, if the
375 above table is not sorted on line numbers. And that sort
376 should be on function based, since gcc can emit line numbers
379 10 0x100 - for the init/test part of a for stmt.
382 10 0x400 - for the increment part of a for stmt.
384 arrange_linetable() will do this sorting.
386 2) aix symbol table might look like:
388 c_file // beginning of a new file
389 .bi // beginning of include file
390 .ei // end of include file
394 basically, .bi/.ei pairs do not necessarily encapsulate
395 their scope. They need to be recorded, and processed later
396 on when we come the end of the compilation unit.
397 Include table (inclTable) and process_linenos() handle
403 /* compare line table entry addresses. */
406 compare_lte (lte1p
, lte2p
)
410 struct linetable_entry
*lte1
= (struct linetable_entry
*) lte1p
;
411 struct linetable_entry
*lte2
= (struct linetable_entry
*) lte2p
;
412 return lte1
->pc
- lte2
->pc
;
415 /* Given a line table with function entries are marked, arrange its functions
416 in ascending order and strip off function entry markers and return it in
417 a newly created table. If the old one is good enough, return the old one. */
418 /* FIXME: I think all this stuff can be replaced by just passing
419 sort_linevec = 1 to end_symtab. */
421 static struct linetable
*
422 arrange_linetable (oldLineTb
)
423 struct linetable
*oldLineTb
; /* old linetable */
425 int ii
, jj
, newline
, /* new line count */
426 function_count
; /* # of functions */
428 struct linetable_entry
*fentry
; /* function entry vector */
429 int fentry_size
; /* # of function entries */
430 struct linetable
*newLineTb
; /* new line table */
432 #define NUM_OF_FUNCTIONS 20
434 fentry_size
= NUM_OF_FUNCTIONS
;
435 fentry
= (struct linetable_entry
*)
436 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
438 for (function_count
= 0, ii
= 0; ii
< oldLineTb
->nitems
; ++ii
)
441 if (oldLineTb
->item
[ii
].line
== 0)
442 { /* function entry found. */
444 if (function_count
>= fentry_size
)
445 { /* make sure you have room. */
447 fentry
= (struct linetable_entry
*)
448 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
450 fentry
[function_count
].line
= ii
;
451 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
456 if (function_count
== 0)
461 else if (function_count
> 1)
462 qsort (fentry
, function_count
, sizeof (struct linetable_entry
), compare_lte
);
464 /* allocate a new line table. */
465 newLineTb
= (struct linetable
*)
467 (sizeof (struct linetable
) +
468 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
470 /* if line table does not start with a function beginning, copy up until
474 if (oldLineTb
->item
[0].line
!= 0)
476 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
477 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
479 /* Now copy function lines one by one. */
481 for (ii
= 0; ii
< function_count
; ++ii
)
483 for (jj
= fentry
[ii
].line
+ 1;
484 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
486 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
489 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
493 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
494 following `IncludeChain'. At the end of each symtab (end_symtab),
495 we will determine if we should create additional symtab's to
496 represent if (the include files. */
499 typedef struct _inclTable
501 char *name
; /* include filename */
503 /* Offsets to the line table. end points to the last entry which is
504 part of this include file. */
507 struct subfile
*subfile
;
508 unsigned funStartLine
; /* start line # of its function */
512 #define INITIAL_INCLUDE_TABLE_LENGTH 20
513 static InclTable
*inclTable
; /* global include table */
514 static int inclIndx
; /* last entry to table */
515 static int inclLength
; /* table length */
516 static int inclDepth
; /* nested include depth */
518 static void allocate_include_entry (void);
521 record_include_begin (cs
)
522 struct coff_symbol
*cs
;
526 /* In xcoff, we assume include files cannot be nested (not in .c files
527 of course, but in corresponding .s files.). */
529 /* This can happen with old versions of GCC.
530 GCC 2.3.3-930426 does not exhibit this on a test case which
531 a user said produced the message for him. */
532 static struct complaint msg
=
533 {"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
=
553 {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
557 allocate_include_entry ();
559 pTbl
= &inclTable
[inclIndx
];
560 pTbl
->end
= cs
->c_value
;
567 allocate_include_entry ()
569 if (inclTable
== NULL
)
571 inclTable
= (InclTable
*)
572 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
574 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
575 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
578 else if (inclIndx
>= inclLength
)
580 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
581 inclTable
= (InclTable
*)
582 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
583 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
584 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
588 /* Global variable to pass the psymtab down to all the routines involved
589 in psymtab to symtab processing. */
590 static struct partial_symtab
*this_symtab_psymtab
;
592 /* given the start and end addresses of a compilation unit (or a csect,
593 at times) process its lines and create appropriate line vectors. */
596 process_linenos (start
, end
)
597 CORE_ADDR start
, end
;
600 file_ptr max_offset
=
601 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
604 /* subfile structure for the main compilation unit. */
605 struct subfile main_subfile
;
607 /* In the main source file, any time we see a function entry, we
608 reset this variable to function's absolute starting line number.
609 All the following line numbers in the function are relative to
610 this, and we record absolute line numbers in record_line(). */
612 unsigned int main_source_baseline
= 0;
617 ((struct symloc
*) this_symtab_psymtab
->read_symtab_private
)->lineno_off
;
619 goto return_after_cleanup
;
621 memset (&main_subfile
, '\0', sizeof (main_subfile
));
624 /* All source lines were in the main source file. None in include files. */
626 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
627 &main_source_baseline
);
631 /* There was source with line numbers in include files. */
634 coff_data (this_symtab_psymtab
->objfile
->obfd
)->local_linesz
;
635 main_source_baseline
= 0;
637 for (ii
= 0; ii
< inclIndx
; ++ii
)
639 struct subfile
*tmpSubfile
;
641 /* If there is main file source before include file, enter it. */
642 if (offset
< inclTable
[ii
].begin
)
645 (&main_subfile
, offset
, inclTable
[ii
].begin
- linesz
,
646 start
, 0, &main_source_baseline
);
649 /* Have a new subfile for the include file. */
651 tmpSubfile
= inclTable
[ii
].subfile
=
652 (struct subfile
*) xmalloc (sizeof (struct subfile
));
654 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
655 firstLine
= &(inclTable
[ii
].funStartLine
);
657 /* Enter include file's lines now. */
658 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
659 inclTable
[ii
].end
, start
, 0, firstLine
);
661 if (offset
<= inclTable
[ii
].end
)
662 offset
= inclTable
[ii
].end
+ linesz
;
665 /* All the include files' line have been processed at this point. Now,
666 enter remaining lines of the main file, if any left. */
667 if (offset
< max_offset
+ 1 - linesz
)
669 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
670 &main_source_baseline
);
674 /* Process main file's line numbers. */
675 if (main_subfile
.line_vector
)
677 struct linetable
*lineTb
, *lv
;
679 lv
= main_subfile
.line_vector
;
681 /* Line numbers are not necessarily ordered. xlc compilation will
682 put static function to the end. */
684 lineTb
= arrange_linetable (lv
);
687 current_subfile
->line_vector
= (struct linetable
*)
688 xrealloc (lv
, (sizeof (struct linetable
)
689 + lv
->nitems
* sizeof (struct linetable_entry
)));
694 current_subfile
->line_vector
= lineTb
;
697 current_subfile
->line_vector_length
=
698 current_subfile
->line_vector
->nitems
;
701 /* Now, process included files' line numbers. */
703 for (ii
= 0; ii
< inclIndx
; ++ii
)
705 if ((inclTable
[ii
].subfile
)->line_vector
) /* Useless if!!! FIXMEmgo */
707 struct linetable
*lineTb
, *lv
;
709 lv
= (inclTable
[ii
].subfile
)->line_vector
;
711 /* Line numbers are not necessarily ordered. xlc compilation will
712 put static function to the end. */
714 lineTb
= arrange_linetable (lv
);
718 /* For the same include file, we might want to have more than one
719 subfile. This happens if we have something like:
727 while foo.h including code in it. (stupid but possible)
728 Since start_subfile() looks at the name and uses an
729 existing one if finds, we need to provide a fake name and
733 start_subfile (inclTable
[ii
].name
, (char *) 0);
736 /* Pick a fake name that will produce the same results as this
737 one when passed to deduce_language_from_filename. Kludge on
739 char *fakename
= strrchr (inclTable
[ii
].name
, '.');
740 if (fakename
== NULL
)
742 start_subfile (fakename
, (char *) 0);
743 free (current_subfile
->name
);
745 current_subfile
->name
= xstrdup (inclTable
[ii
].name
);
750 current_subfile
->line_vector
=
751 (struct linetable
*) xrealloc
752 (lv
, (sizeof (struct linetable
)
753 + lv
->nitems
* sizeof (struct linetable_entry
)));
759 current_subfile
->line_vector
= lineTb
;
762 current_subfile
->line_vector_length
=
763 current_subfile
->line_vector
->nitems
;
764 start_subfile (pop_subfile (), (char *) 0);
768 return_after_cleanup
:
770 /* We don't want to keep alloc/free'ing the global include file table. */
773 /* Start with a fresh subfile structure for the next file. */
774 memset (&main_subfile
, '\0', sizeof (struct subfile
));
778 aix_process_linenos ()
780 /* process line numbers and enter them into line vector */
781 process_linenos (last_source_start_addr
, cur_src_end_addr
);
785 /* Enter a given range of lines into the line vector.
786 can be called in the following two ways:
787 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
788 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
790 endoffset points to the last line table entry that we should pay
794 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
,
796 struct subfile
*subfile
;
797 unsigned beginoffset
, endoffset
; /* offsets to line table */
798 CORE_ADDR startaddr
, endaddr
;
801 unsigned int curoffset
;
804 struct internal_lineno int_lnno
;
805 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
;
830 abfd
= this_symtab_psymtab
->objfile
->obfd
;
831 linesz
= coff_data (abfd
)->local_linesz
;
832 ext_lnno
= alloca (linesz
);
834 while (curoffset
<= limit_offset
)
836 bfd_seek (abfd
, curoffset
, SEEK_SET
);
837 bfd_read (ext_lnno
, linesz
, 1, abfd
);
838 bfd_coff_swap_lineno_in (abfd
, ext_lnno
, &int_lnno
);
840 /* Find the address this line represents. */
841 addr
= (int_lnno
.l_lnno
842 ? int_lnno
.l_addr
.l_paddr
843 : read_symbol_nvalue (int_lnno
.l_addr
.l_symndx
));
844 addr
+= ANOFFSET (this_symtab_psymtab
->objfile
->section_offsets
,
845 SECT_OFF_TEXT (this_symtab_psymtab
->objfile
));
847 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
850 if (int_lnno
.l_lnno
== 0)
852 *firstLine
= read_symbol_lineno (int_lnno
.l_addr
.l_symndx
);
853 record_line (subfile
, 0, addr
);
857 record_line (subfile
, *firstLine
+ int_lnno
.l_lnno
, addr
);
863 /* Save the vital information for use when closing off the current file.
864 NAME is the file name the symbols came from, START_ADDR is the first
865 text address for the file, and SIZE is the number of bytes of text. */
867 #define complete_symtab(name, start_addr) { \
868 last_source_file = savestring (name, strlen (name)); \
869 last_source_start_addr = start_addr; \
873 /* Refill the symbol table input buffer
874 and set the variables that control fetching entries from it.
875 Reports an error if no data available.
876 This function can read past the end of the symbol table
877 (into the string table) but this does no harm. */
879 /* Reading symbol table has to be fast! Keep the followings as macros, rather
882 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
886 if (namestr[0] == '.') ++namestr; \
887 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
888 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
889 misc_func_recorded = 1; \
893 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
894 nested. At any given time, a symbol can only be in one static block.
895 This is the base address of current static block, zero if non exists. */
897 static int static_block_base
= 0;
899 /* Section number for the current static block. */
901 static int static_block_section
= -1;
903 /* true if space for symbol name has been allocated. */
905 static int symname_alloced
= 0;
907 /* Next symbol to read. Pointer into raw seething symbol table. */
909 static char *raw_symbol
;
911 /* This is the function which stabsread.c calls to get symbol
915 xcoff_next_symbol_text (objfile
)
916 struct objfile
*objfile
;
918 struct internal_syment symbol
;
919 static struct complaint msg
=
920 {"Unexpected symbol continuation", 0, 0};
922 /* FIXME: is this the same as the passed arg? */
923 objfile
= this_symtab_psymtab
->objfile
;
925 bfd_coff_swap_sym_in (objfile
->obfd
, raw_symbol
, &symbol
);
930 /* Return something which points to '\0' and hope the symbol reading
931 code does something reasonable. */
934 else if (symbol
.n_sclass
& 0x80)
937 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
940 coff_data (objfile
->obfd
)->local_symesz
;
947 /* Return something which points to '\0' and hope the symbol reading
948 code does something reasonable. */
954 /* Read symbols for a given partial symbol table. */
957 read_xcoff_symtab (pst
)
958 struct partial_symtab
*pst
;
960 struct objfile
*objfile
= pst
->objfile
;
961 bfd
*abfd
= objfile
->obfd
;
962 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
963 char *strtbl
= ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
;
965 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
;
966 char *debugfmt
= xcoff_data (abfd
)->xcoff64
? "XCOFF64" : "XCOFF";
968 struct internal_syment symbol
[1];
969 union internal_auxent main_aux
;
970 struct coff_symbol cs
[1];
971 CORE_ADDR file_start_addr
= 0;
972 CORE_ADDR file_end_addr
= 0;
974 int next_file_symnum
= -1;
975 unsigned int max_symnum
;
976 int just_started
= 1;
978 int fcn_start_addr
= 0;
980 struct coff_symbol fcn_stab_saved
;
982 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
983 union internal_auxent fcn_aux_saved
;
984 struct context_stack
*new;
986 char *filestring
= " _start_ "; /* Name of the current file. */
988 char *last_csect_name
; /* last seen csect's name and value */
989 CORE_ADDR last_csect_val
;
992 this_symtab_psymtab
= pst
;
994 /* Get the appropriate COFF "constants" related to the file we're
996 local_symesz
= coff_data (abfd
)->local_symesz
;
998 last_source_file
= NULL
;
1003 start_symtab (filestring
, (char *) NULL
, file_start_addr
);
1004 record_debugformat (debugfmt
);
1005 symnum
= ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
1007 symnum
+ ((struct symloc
*) pst
->read_symtab_private
)->numsyms
;
1008 first_object_file_end
= 0;
1011 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
1012 + symnum
* local_symesz
;
1014 while (symnum
< max_symnum
)
1017 QUIT
; /* make this command interruptable. */
1019 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1020 /* read one symbol into `cs' structure. After processing the
1021 whole symbol table, only string table will be kept in memory,
1022 symbol table and debug section of xcoff will be freed. Thus
1023 we can mark symbols with names in string table as
1028 /* Swap and align the symbol into a reasonable C structure. */
1029 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1031 cs
->c_symnum
= symnum
;
1032 cs
->c_naux
= symbol
->n_numaux
;
1033 if (symbol
->n_zeroes
)
1035 symname_alloced
= 0;
1036 /* We must use the original, unswapped, name here so the name field
1037 pointed to by cs->c_name will persist throughout xcoffread. If
1038 we use the new field, it gets overwritten for each symbol. */
1039 cs
->c_name
= ((struct external_syment
*) raw_symbol
)->e
.e_name
;
1040 /* If it's exactly E_SYMNMLEN characters long it isn't
1042 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1045 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
1046 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1047 p
[E_SYMNMLEN
] = '\0';
1049 symname_alloced
= 1;
1052 else if (symbol
->n_sclass
& 0x80)
1054 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1055 symname_alloced
= 0;
1059 /* in string table */
1060 cs
->c_name
= strtbl
+ (int) symbol
->n_offset
;
1061 symname_alloced
= 1;
1063 cs
->c_value
= symbol
->n_value
;
1064 cs
->c_sclass
= symbol
->n_sclass
;
1065 cs
->c_secnum
= symbol
->n_scnum
;
1066 cs
->c_type
= (unsigned) symbol
->n_type
;
1068 raw_symbol
+= local_symesz
;
1071 /* Save addr of first aux entry. */
1072 raw_auxptr
= raw_symbol
;
1074 /* Skip all the auxents associated with this symbol. */
1075 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1077 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1082 /* if symbol name starts with ".$" or "$", ignore it. */
1083 if (cs
->c_name
[0] == '$'
1084 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1087 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1089 if (last_source_file
)
1092 end_symtab (cur_src_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1097 start_symtab ("_globals_", (char *) NULL
, (CORE_ADDR
) 0);
1098 record_debugformat (debugfmt
);
1099 cur_src_end_addr
= first_object_file_end
;
1100 /* done with all files, everything from here on is globals */
1103 /* if explicitly specified as a function, treat is as one. */
1104 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1106 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1107 0, cs
->c_naux
, &main_aux
);
1108 goto function_entry_point
;
1111 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1114 /* Dealing with a symbol with a csect entry. */
1116 #define CSECT(PP) ((PP)->x_csect)
1117 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1118 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1119 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1120 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1122 /* Convert the auxent to something we can access. */
1123 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1124 0, cs
->c_naux
, &main_aux
);
1126 switch (CSECT_SMTYP (&main_aux
))
1130 /* Ignore all external references. */
1134 /* A section description. */
1136 switch (CSECT_SCLAS (&main_aux
))
1142 /* A program csect is seen. We have to allocate one
1143 symbol table for each program csect. Normally gdb
1144 prefers one symtab for each source file. In case
1145 of AIX, one source file might include more than one
1146 [PR] csect, and they don't have to be adjacent in
1147 terms of the space they occupy in memory. Thus, one
1148 single source file might get fragmented in the
1149 memory and gdb's file start and end address
1150 approach does not work! GCC (and I think xlc) seem
1151 to put all the code in the unnamed program csect. */
1153 if (last_csect_name
)
1155 complete_symtab (filestring
, file_start_addr
);
1156 cur_src_end_addr
= file_end_addr
;
1157 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1160 /* Give all csects for this source file the same
1162 start_symtab (filestring
, NULL
, (CORE_ADDR
) 0);
1163 record_debugformat (debugfmt
);
1166 /* If this is the very first csect seen,
1167 basically `__start'. */
1170 first_object_file_end
1171 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1176 cs
->c_value
+ ANOFFSET (objfile
->section_offsets
,
1177 SECT_OFF_TEXT (objfile
));
1178 file_end_addr
= file_start_addr
+ CSECT_LEN (&main_aux
);
1180 if (cs
->c_name
&& cs
->c_name
[0] == '.')
1182 last_csect_name
= cs
->c_name
;
1183 last_csect_val
= cs
->c_value
;
1184 last_csect_sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1189 /* All other symbols are put into the minimal symbol
1202 /* Ignore the symbol. */
1210 switch (CSECT_SCLAS (&main_aux
))
1213 /* a function entry point. */
1214 function_entry_point
:
1216 fcn_start_addr
= cs
->c_value
;
1218 /* save the function header info, which will be used
1219 when `.bf' is seen. */
1221 fcn_aux_saved
= main_aux
;
1225 /* shared library function trampoline code entry point. */
1229 /* The symbols often have the same names as debug symbols for
1230 functions, and confuse lookup_symbol. */
1234 /* xlc puts each variable in a separate csect, so we get
1235 an XTY_SD for each variable. But gcc puts several
1236 variables in a csect, so that each variable only gets
1237 an XTY_LD. This will typically be XMC_RW; I suspect
1238 XMC_RO and XMC_BS might be possible too.
1239 These variables are put in the minimal symbol table
1246 /* Common symbols are put into the minimal symbol table only. */
1254 switch (cs
->c_sclass
)
1259 /* c_value field contains symnum of next .file entry in table
1260 or symnum of first global after last .file. */
1262 next_file_symnum
= cs
->c_value
;
1264 /* Complete symbol table for last object file containing
1265 debugging information. */
1267 /* Whether or not there was a csect in the previous file, we
1268 have to call `end_stabs' and `start_stabs' to reset
1269 type_vector, line_vector, etc. structures. */
1271 complete_symtab (filestring
, file_start_addr
);
1272 cur_src_end_addr
= file_end_addr
;
1273 end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1276 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1277 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1278 standard COFF way and put it in the auxent. We use the auxent if
1279 the symbol is ".file" and an auxent exists, otherwise use the symbol
1280 itself. Simple enough. */
1281 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1283 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1284 0, cs
->c_naux
, &main_aux
);
1285 filestring
= coff_getfilename (&main_aux
, objfile
);
1288 filestring
= cs
->c_name
;
1291 start_symtab (filestring
, (char *) NULL
, (CORE_ADDR
) 0);
1292 record_debugformat (debugfmt
);
1293 last_csect_name
= 0;
1295 /* reset file start and end addresses. A compilation unit with no text
1296 (only data) should have zero file boundaries. */
1297 file_start_addr
= file_end_addr
= 0;
1301 fcn_stab_saved
= *cs
;
1305 if (STREQ (cs
->c_name
, ".bf"))
1307 CORE_ADDR off
= ANOFFSET (objfile
->section_offsets
,
1308 SECT_OFF_TEXT (objfile
));
1309 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1310 0, cs
->c_naux
, &main_aux
);
1312 within_function
= 1;
1314 new = push_context (0, fcn_start_addr
+ off
);
1316 new->name
= define_symbol
1317 (fcn_cs_saved
.c_value
+ off
,
1318 fcn_stab_saved
.c_name
, 0, 0, objfile
);
1319 if (new->name
!= NULL
)
1320 SYMBOL_SECTION (new->name
) = SECT_OFF_TEXT (objfile
);
1322 else if (STREQ (cs
->c_name
, ".ef"))
1325 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1326 0, cs
->c_naux
, &main_aux
);
1328 /* The value of .ef is the address of epilogue code;
1329 not useful for gdb. */
1330 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1331 contains number of lines to '}' */
1333 if (context_stack_depth
<= 0)
1334 { /* We attempted to pop an empty context stack */
1335 complain (&ef_complaint
, cs
->c_symnum
);
1336 within_function
= 0;
1339 new = pop_context ();
1340 /* Stack must be empty now. */
1341 if (context_stack_depth
> 0 || new == NULL
)
1343 complain (&ef_complaint
, cs
->c_symnum
);
1344 within_function
= 0;
1348 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1350 (fcn_cs_saved
.c_value
1351 + fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1352 + ANOFFSET (objfile
->section_offsets
,
1353 SECT_OFF_TEXT (objfile
))),
1355 within_function
= 0;
1360 /* Begin static block. */
1362 struct internal_syment symbol
;
1364 read_symbol (&symbol
, cs
->c_value
);
1365 static_block_base
= symbol
.n_value
;
1366 static_block_section
=
1367 secnum_to_section (symbol
.n_scnum
, objfile
);
1372 /* End of static block. */
1373 static_block_base
= 0;
1374 static_block_section
= -1;
1385 static struct complaint msg
=
1386 {"Unrecognized storage class %d.", 0, 0};
1387 complain (&msg
, cs
->c_sclass
);
1401 /* beginning of include file */
1402 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1403 order. Thus, when wee see them, we might not know enough info
1404 to process them. Thus, we'll be saving them into a table
1405 (inclTable) and postpone their processing. */
1407 record_include_begin (cs
);
1411 /* End of include file. */
1412 /* See the comment after case C_BINCL. */
1413 record_include_end (cs
);
1417 if (STREQ (cs
->c_name
, ".bb"))
1420 new = push_context (depth
,
1422 + ANOFFSET (objfile
->section_offsets
,
1423 SECT_OFF_TEXT (objfile
))));
1425 else if (STREQ (cs
->c_name
, ".eb"))
1427 if (context_stack_depth
<= 0)
1428 { /* We attempted to pop an empty context stack */
1429 complain (&eb_complaint
, cs
->c_symnum
);
1432 new = pop_context ();
1433 if (depth
-- != new->depth
)
1435 complain (&eb_complaint
, cs
->c_symnum
);
1438 if (local_symbols
&& context_stack_depth
> 0)
1440 /* Make a block for the local symbols within. */
1441 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1444 + ANOFFSET (objfile
->section_offsets
,
1445 SECT_OFF_TEXT (objfile
))),
1448 local_symbols
= new->locals
;
1453 process_xcoff_symbol (cs
, objfile
);
1458 if (last_source_file
)
1462 complete_symtab (filestring
, file_start_addr
);
1463 cur_src_end_addr
= file_end_addr
;
1464 s
= end_symtab (file_end_addr
, objfile
, SECT_OFF_TEXT (objfile
));
1465 /* When reading symbols for the last C_FILE of the objfile, try
1466 to make sure that we set pst->symtab to the symtab for the
1467 file, not to the _globals_ symtab. I'm not sure whether this
1468 actually works right or when/if it comes up. */
1469 if (pst
->symtab
== NULL
)
1475 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1476 (SYMBOL2) = (struct symbol *) \
1477 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1478 *(SYMBOL2) = *(SYMBOL1);
1481 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1482 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1485 static struct type
*func_symbol_type
;
1486 static struct type
*var_symbol_type
;
1488 /* process one xcoff symbol. */
1490 static struct symbol
*
1491 process_xcoff_symbol (cs
, objfile
)
1492 register struct coff_symbol
*cs
;
1493 struct objfile
*objfile
;
1495 struct symbol onesymbol
;
1496 register struct symbol
*sym
= &onesymbol
;
1497 struct symbol
*sym2
= NULL
;
1503 if (cs
->c_secnum
< 0)
1505 /* The value is a register number, offset within a frame, etc.,
1506 and does not get relocated. */
1512 sec
= secnum_to_section (cs
->c_secnum
, objfile
);
1513 off
= ANOFFSET (objfile
->section_offsets
, sec
);
1520 memset (sym
, '\0', sizeof (struct symbol
));
1522 /* default assumptions */
1523 SYMBOL_VALUE_ADDRESS (sym
) = cs
->c_value
+ off
;
1524 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1525 SYMBOL_SECTION (sym
) = secnum_to_section (cs
->c_secnum
, objfile
);
1527 if (ISFCN (cs
->c_type
))
1529 /* At this point, we don't know the type of the function. This
1530 will be patched with the type from its stab entry later on in
1531 patch_block_stabs (), unless the file was compiled without -g. */
1533 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1534 SYMBOL_TYPE (sym
) = func_symbol_type
;
1536 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1537 SYMBOL_DUP (sym
, sym2
);
1539 if (cs
->c_sclass
== C_EXT
)
1540 add_symbol_to_list (sym2
, &global_symbols
);
1541 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1542 add_symbol_to_list (sym2
, &file_symbols
);
1546 /* In case we can't figure out the type, provide default. */
1547 SYMBOL_TYPE (sym
) = var_symbol_type
;
1549 switch (cs
->c_sclass
)
1552 /* The values of functions and global symbols are now resolved
1553 via the global_sym_chain in stabsread.c. */
1555 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1556 add_stab_to_list (name
, &global_stabs
);
1558 add_stab_to_list (name
, &file_stabs
);
1562 add_stab_to_list (name
, &global_stabs
);
1567 common_block_start (cs
->c_name
, objfile
);
1571 common_block_end (objfile
);
1575 complain (&storclass_complaint
, cs
->c_sclass
);
1587 sym
= define_symbol (cs
->c_value
+ off
, cs
->c_name
, 0, 0, objfile
);
1590 SYMBOL_SECTION (sym
) = sec
;
1597 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1598 all statics and we need to distinguish file-scope versus
1599 function-scope using within_function. We do this by
1600 changing the string we pass to define_symbol to use 'S'
1601 where we need to, which is not necessarily super-clean,
1602 but seems workable enough. */
1604 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1608 if (*pp
== 'V' && !within_function
)
1610 sym
= define_symbol ((cs
->c_value
1611 + ANOFFSET (objfile
->section_offsets
,
1612 static_block_section
)),
1613 cs
->c_name
, 0, 0, objfile
);
1616 SYMBOL_VALUE_ADDRESS (sym
) += static_block_base
;
1617 SYMBOL_SECTION (sym
) = static_block_section
;
1626 /* Extract the file name from the aux entry of a C_FILE symbol.
1627 Result is in static storage and is only good for temporary use. */
1630 coff_getfilename (aux_entry
, objfile
)
1631 union internal_auxent
*aux_entry
;
1632 struct objfile
*objfile
;
1634 static char buffer
[BUFSIZ
];
1636 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1638 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
1639 + aux_entry
->x_file
.x_n
.x_offset
);
1642 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1643 buffer
[FILNMLEN
] = '\0';
1648 /* Set *SYMBOL to symbol number symno in symtbl. */
1650 read_symbol (symbol
, symno
)
1651 struct internal_syment
*symbol
;
1655 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
1658 ((struct coff_symfile_info
*) this_symtab_psymtab
->objfile
->sym_private
)
1660 if (symno
< 0 || symno
>= nsyms
)
1662 static struct complaint msg
=
1663 {"Invalid symbol offset", 0, 0};
1665 symbol
->n_value
= 0;
1666 symbol
->n_scnum
= -1;
1669 bfd_coff_swap_sym_in (this_symtab_psymtab
->objfile
->obfd
,
1670 stbl
+ (symno
* local_symesz
),
1674 /* Get value corresponding to symbol number symno in symtbl. */
1677 read_symbol_nvalue (symno
)
1680 struct internal_syment symbol
[1];
1682 read_symbol (symbol
, symno
);
1683 return symbol
->n_value
;
1687 /* Find the address of the function corresponding to symno, where
1688 symno is the symbol pointed to by the linetable. */
1691 read_symbol_lineno (symno
)
1694 struct objfile
*objfile
= this_symtab_psymtab
->objfile
;
1695 boolean xcoff64
= xcoff_data (objfile
->obfd
)->xcoff64
;
1697 struct coff_symfile_info
*info
=
1698 (struct coff_symfile_info
*)objfile
->sym_private
;
1699 int nsyms
= info
->symtbl_num_syms
;
1700 char *stbl
= info
->symtbl
;
1701 char *strtbl
= info
->strtbl
;
1703 struct internal_syment symbol
[1];
1704 union internal_auxent main_aux
[1];
1708 complain (&bf_notfound_complaint
);
1712 /* Note that just searching for a short distance (e.g. 50 symbols)
1713 is not enough, at least in the following case.
1716 [many .stabx entries]
1717 [a few functions, referring to foo]
1721 What happens here is that the assembler moves the .stabx entries
1722 to right before the ".bf" for foo, but the symbol for "foo" is before
1723 all the stabx entries. See PR gdb/2222. */
1725 /* Maintaining a table of .bf entries might be preferable to this search.
1726 If I understand things correctly it would need to be done only for
1727 the duration of a single psymtab to symtab conversion. */
1728 while (symno
< nsyms
)
1730 bfd_coff_swap_sym_in (symfile_bfd
,
1731 stbl
+ (symno
* local_symesz
), symbol
);
1732 if (symbol
->n_sclass
== C_FCN
)
1734 char *name
= xcoff64
? strtbl
+ symbol
->n_offset
: symbol
->n_name
;
1735 if (STREQ (name
, ".bf"))
1738 symno
+= symbol
->n_numaux
+ 1;
1741 complain (&bf_notfound_complaint
);
1745 /* take aux entry and return its lineno */
1747 bfd_coff_swap_aux_in (objfile
->obfd
, stbl
+ symno
* local_symesz
,
1748 symbol
->n_type
, symbol
->n_sclass
,
1749 0, symbol
->n_numaux
, main_aux
);
1751 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1754 /* Support for line number handling */
1756 /* This function is called for every section; it finds the outer limits
1757 * of the line table (minimum and maximum file offset) so that the
1758 * mainline code can read the whole thing for efficiency.
1761 find_linenos (abfd
, asect
, vpinfo
)
1766 struct coff_symfile_info
*info
;
1768 file_ptr offset
, maxoff
;
1770 count
= asect
->lineno_count
;
1772 if (!STREQ (asect
->name
, ".text") || count
== 0)
1775 size
= count
* coff_data (abfd
)->local_linesz
;
1776 info
= (struct coff_symfile_info
*) vpinfo
;
1777 offset
= asect
->line_filepos
;
1778 maxoff
= offset
+ size
;
1780 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1781 info
->min_lineno_offset
= offset
;
1783 if (maxoff
> info
->max_lineno_offset
)
1784 info
->max_lineno_offset
= maxoff
;
1787 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab
*);
1790 xcoff_psymtab_to_symtab_1 (pst
)
1791 struct partial_symtab
*pst
;
1793 struct cleanup
*old_chain
;
1802 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1807 /* Read in all partial symtabs on which this one is dependent */
1808 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1809 if (!pst
->dependencies
[i
]->readin
)
1811 /* Inform about additional files that need to be read in. */
1814 fputs_filtered (" ", gdb_stdout
);
1816 fputs_filtered ("and ", gdb_stdout
);
1818 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1819 wrap_here (""); /* Flush output */
1820 gdb_flush (gdb_stdout
);
1822 xcoff_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1825 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0)
1827 /* Init stuff necessary for reading in symbols. */
1830 old_chain
= make_cleanup (really_free_pendings
, 0);
1832 read_xcoff_symtab (pst
);
1833 sort_symtab_syms (pst
->symtab
);
1835 do_cleanups (old_chain
);
1841 static void xcoff_psymtab_to_symtab (struct partial_symtab
*);
1843 /* Read in all of the symbols for a given psymtab for real.
1844 Be verbose about it if the user wants that. */
1847 xcoff_psymtab_to_symtab (pst
)
1848 struct partial_symtab
*pst
;
1858 (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1863 if (((struct symloc
*) pst
->read_symtab_private
)->numsyms
!= 0
1864 || pst
->number_of_dependencies
)
1866 /* Print the message now, before reading the string table,
1867 to avoid disconcerting pauses. */
1870 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1871 gdb_flush (gdb_stdout
);
1874 sym_bfd
= pst
->objfile
->obfd
;
1876 next_symbol_text_func
= xcoff_next_symbol_text
;
1878 xcoff_psymtab_to_symtab_1 (pst
);
1880 /* Match with global symbols. This only needs to be done once,
1881 after all of the symtabs and dependencies have been read in. */
1882 scan_file_globals (pst
->objfile
);
1884 /* Finish up the debug error message. */
1886 printf_filtered ("done.\n");
1891 xcoff_new_init (objfile
)
1892 struct objfile
*objfile
;
1894 stabsread_new_init ();
1895 buildsym_new_init ();
1898 /* Do initialization in preparation for reading symbols from OBJFILE.
1900 We will only be called if this is an XCOFF or XCOFF-like file.
1901 BFD handles figuring out the format of the file, and code in symfile.c
1902 uses BFD's determination to vector to us. */
1905 xcoff_symfile_init (objfile
)
1906 struct objfile
*objfile
;
1908 /* Allocate struct to keep track of the symfile */
1909 objfile
->sym_private
= xmmalloc (objfile
->md
,
1910 sizeof (struct coff_symfile_info
));
1912 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1913 find this causes a significant slowdown in gdb then we could
1914 set it in the debug symbol readers only when necessary. */
1915 objfile
->flags
|= OBJF_REORDERED
;
1917 init_entry_point_info (objfile
);
1920 /* Perform any local cleanups required when we are done with a particular
1921 objfile. I.E, we are in the process of discarding all symbol information
1922 for an objfile, freeing up all memory held for it, and unlinking the
1923 objfile struct from the global list of known objfiles. */
1926 xcoff_symfile_finish (objfile
)
1927 struct objfile
*objfile
;
1929 if (objfile
->sym_private
!= NULL
)
1931 mfree (objfile
->md
, objfile
->sym_private
);
1934 /* Start with a fresh include table for the next objfile. */
1940 inclIndx
= inclLength
= inclDepth
= 0;
1945 init_stringtab (abfd
, offset
, objfile
)
1948 struct objfile
*objfile
;
1952 unsigned char lengthbuf
[4];
1955 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
= NULL
;
1957 if (bfd_seek (abfd
, offset
, SEEK_SET
) < 0)
1958 error ("cannot seek to string table in %s: %s",
1959 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1961 val
= bfd_read ((char *) lengthbuf
, 1, sizeof lengthbuf
, abfd
);
1962 length
= bfd_h_get_32 (abfd
, lengthbuf
);
1964 /* If no string table is needed, then the file may end immediately
1965 after the symbols. Just return with `strtbl' set to NULL. */
1967 if (val
!= sizeof lengthbuf
|| length
< sizeof lengthbuf
)
1970 /* Allocate string table from symbol_obstack. We will need this table
1971 as long as we have its symbol table around. */
1973 strtbl
= (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
1974 ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
= strtbl
;
1976 /* Copy length buffer, the first byte is usually zero and is
1977 used for stabs with a name length of zero. */
1978 memcpy (strtbl
, lengthbuf
, sizeof lengthbuf
);
1979 if (length
== sizeof lengthbuf
)
1982 val
= bfd_read (strtbl
+ sizeof lengthbuf
, 1, length
- sizeof lengthbuf
,
1985 if (val
!= length
- sizeof lengthbuf
)
1986 error ("cannot read string table from %s: %s",
1987 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1988 if (strtbl
[length
- 1] != '\0')
1989 error ("bad symbol file: string table does not end with null character");
1994 /* If we have not yet seen a function for this psymtab, this is 0. If we
1995 have seen one, it is the offset in the line numbers of the line numbers
1997 static unsigned int first_fun_line_offset
;
1999 static struct partial_symtab
*xcoff_start_psymtab
2000 (struct objfile
*, char *, int,
2001 struct partial_symbol
**, struct partial_symbol
**);
2003 /* Allocate and partially fill a partial symtab. It will be
2004 completely filled at the end of the symbol list.
2006 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2007 is the address relative to which its symbols are (incremental) or 0
2010 static struct partial_symtab
*
2011 xcoff_start_psymtab (objfile
, filename
, first_symnum
, global_syms
,
2013 struct objfile
*objfile
;
2016 struct partial_symbol
**global_syms
;
2017 struct partial_symbol
**static_syms
;
2019 struct partial_symtab
*result
=
2020 start_psymtab_common (objfile
, objfile
->section_offsets
,
2022 /* We fill in textlow later. */
2024 global_syms
, static_syms
);
2026 result
->read_symtab_private
= (char *)
2027 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2028 ((struct symloc
*) result
->read_symtab_private
)->first_symnum
= first_symnum
;
2029 result
->read_symtab
= xcoff_psymtab_to_symtab
;
2031 /* Deduce the source language from the filename for this psymtab. */
2032 psymtab_language
= deduce_language_from_filename (filename
);
2037 static struct partial_symtab
*xcoff_end_psymtab
2038 (struct partial_symtab
*, char **, int, int,
2039 struct partial_symtab
**, int, int);
2041 /* Close off the current usage of PST.
2042 Returns PST, or NULL if the partial symtab was empty and thrown away.
2044 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2046 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2047 are the information for includes and dependencies. */
2049 static struct partial_symtab
*
2050 xcoff_end_psymtab (pst
, include_list
, num_includes
, capping_symbol_number
,
2051 dependency_list
, number_dependencies
, textlow_not_set
)
2052 struct partial_symtab
*pst
;
2053 char **include_list
;
2055 int capping_symbol_number
;
2056 struct partial_symtab
**dependency_list
;
2057 int number_dependencies
;
2058 int textlow_not_set
;
2061 struct objfile
*objfile
= pst
->objfile
;
2063 if (capping_symbol_number
!= -1)
2064 ((struct symloc
*) pst
->read_symtab_private
)->numsyms
=
2065 capping_symbol_number
2066 - ((struct symloc
*) pst
->read_symtab_private
)->first_symnum
;
2067 ((struct symloc
*) pst
->read_symtab_private
)->lineno_off
=
2068 first_fun_line_offset
;
2069 first_fun_line_offset
= 0;
2070 pst
->n_global_syms
=
2071 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2072 pst
->n_static_syms
=
2073 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2075 pst
->number_of_dependencies
= number_dependencies
;
2076 if (number_dependencies
)
2078 pst
->dependencies
= (struct partial_symtab
**)
2079 obstack_alloc (&objfile
->psymbol_obstack
,
2080 number_dependencies
* sizeof (struct partial_symtab
*));
2081 memcpy (pst
->dependencies
, dependency_list
,
2082 number_dependencies
* sizeof (struct partial_symtab
*));
2085 pst
->dependencies
= 0;
2087 for (i
= 0; i
< num_includes
; i
++)
2089 struct partial_symtab
*subpst
=
2090 allocate_psymtab (include_list
[i
], objfile
);
2092 subpst
->section_offsets
= pst
->section_offsets
;
2093 subpst
->read_symtab_private
=
2094 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
2095 sizeof (struct symloc
));
2096 ((struct symloc
*) subpst
->read_symtab_private
)->first_symnum
= 0;
2097 ((struct symloc
*) subpst
->read_symtab_private
)->numsyms
= 0;
2098 subpst
->textlow
= 0;
2099 subpst
->texthigh
= 0;
2101 /* We could save slight bits of space by only making one of these,
2102 shared by the entire set of include files. FIXME-someday. */
2103 subpst
->dependencies
= (struct partial_symtab
**)
2104 obstack_alloc (&objfile
->psymbol_obstack
,
2105 sizeof (struct partial_symtab
*));
2106 subpst
->dependencies
[0] = pst
;
2107 subpst
->number_of_dependencies
= 1;
2109 subpst
->globals_offset
=
2110 subpst
->n_global_syms
=
2111 subpst
->statics_offset
=
2112 subpst
->n_static_syms
= 0;
2116 subpst
->read_symtab
= pst
->read_symtab
;
2119 sort_pst_symbols (pst
);
2121 /* If there is already a psymtab or symtab for a file of this name,
2122 remove it. (If there is a symtab, more drastic things also
2123 happen.) This happens in VxWorks. */
2124 free_named_symtabs (pst
->filename
);
2126 if (num_includes
== 0
2127 && number_dependencies
== 0
2128 && pst
->n_global_syms
== 0
2129 && pst
->n_static_syms
== 0)
2131 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2132 it is on the obstack, but we can forget to chain it on the list. */
2133 /* Empty psymtabs happen as a result of header files which don't have
2134 any symbols in them. There can be a lot of them. */
2136 discard_psymtab (pst
);
2138 /* Indicate that psymtab was thrown away. */
2139 pst
= (struct partial_symtab
*) NULL
;
2144 static void swap_sym (struct internal_syment
*,
2145 union internal_auxent
*, char **, char **,
2146 unsigned int *, struct objfile
*);
2148 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2149 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2150 the symbol and its auxents. */
2153 swap_sym (symbol
, aux
, name
, raw
, symnump
, objfile
)
2154 struct internal_syment
*symbol
;
2155 union internal_auxent
*aux
;
2158 unsigned int *symnump
;
2159 struct objfile
*objfile
;
2161 bfd_coff_swap_sym_in (objfile
->obfd
, *raw
, symbol
);
2162 if (symbol
->n_zeroes
)
2164 /* If it's exactly E_SYMNMLEN characters long it isn't
2166 if (symbol
->n_name
[E_SYMNMLEN
- 1] != '\0')
2168 /* FIXME: wastes memory for symbols which we don't end up putting
2169 into the minimal symbols. */
2171 p
= obstack_alloc (&objfile
->psymbol_obstack
, E_SYMNMLEN
+ 1);
2172 strncpy (p
, symbol
->n_name
, E_SYMNMLEN
);
2173 p
[E_SYMNMLEN
] = '\0';
2177 /* Point to the unswapped name as that persists as long as the
2179 *name
= ((struct external_syment
*) *raw
)->e
.e_name
;
2181 else if (symbol
->n_sclass
& 0x80)
2183 *name
= ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
2188 *name
= ((struct coff_symfile_info
*) objfile
->sym_private
)->strtbl
2192 *raw
+= coff_data (objfile
->obfd
)->local_symesz
;
2193 if (symbol
->n_numaux
> 0)
2195 bfd_coff_swap_aux_in (objfile
->obfd
, *raw
, symbol
->n_type
,
2196 symbol
->n_sclass
, 0, symbol
->n_numaux
, aux
);
2198 *symnump
+= symbol
->n_numaux
;
2199 *raw
+= coff_data (objfile
->obfd
)->local_symesz
* symbol
->n_numaux
;
2204 scan_xcoff_symtab (objfile
)
2205 struct objfile
*objfile
;
2207 CORE_ADDR toc_offset
= 0; /* toc offset value in data section. */
2208 char *filestring
= NULL
;
2211 int past_first_source_file
= 0;
2216 /* Current partial symtab */
2217 struct partial_symtab
*pst
;
2219 /* List of current psymtab's include files */
2220 char **psymtab_include_list
;
2221 int includes_allocated
;
2224 /* Index within current psymtab dependency list */
2225 struct partial_symtab
**dependency_list
;
2226 int dependencies_used
, dependencies_allocated
;
2229 struct internal_syment symbol
;
2230 union internal_auxent main_aux
[5];
2231 unsigned int ssymnum
;
2233 char *last_csect_name
= NULL
; /* last seen csect's name and value */
2234 CORE_ADDR last_csect_val
= 0;
2235 int last_csect_sec
= 0;
2236 int misc_func_recorded
= 0; /* true if any misc. function */
2237 int textlow_not_set
= 1;
2239 pst
= (struct partial_symtab
*) 0;
2241 includes_allocated
= 30;
2243 psymtab_include_list
= (char **) alloca (includes_allocated
*
2246 dependencies_allocated
= 30;
2247 dependencies_used
= 0;
2249 (struct partial_symtab
**) alloca (dependencies_allocated
*
2250 sizeof (struct partial_symtab
*));
2252 last_source_file
= NULL
;
2254 abfd
= objfile
->obfd
;
2256 sraw_symbol
= ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
;
2257 nsyms
= ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl_num_syms
;
2259 while (ssymnum
< nsyms
)
2262 /* This is the type we pass to partial-stab.h. A less kludgy solution
2263 would be to break out partial-stab.h into its various parts--shuffle
2264 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2265 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2270 bfd_coff_swap_sym_in (abfd
, sraw_symbol
, &symbol
);
2271 sclass
= symbol
.n_sclass
;
2278 /* The CSECT auxent--always the last auxent. */
2279 union internal_auxent csect_aux
;
2280 unsigned int symnum_before
= ssymnum
;
2282 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2284 if (symbol
.n_numaux
> 1)
2286 bfd_coff_swap_aux_in
2288 sraw_symbol
- coff_data (abfd
)->local_symesz
,
2291 symbol
.n_numaux
- 1,
2296 csect_aux
= main_aux
[0];
2298 /* If symbol name starts with ".$" or "$", ignore it. */
2299 if (namestring
[0] == '$'
2300 || (namestring
[0] == '.' && namestring
[1] == '$'))
2303 switch (csect_aux
.x_csect
.x_smtyp
& 0x7)
2306 switch (csect_aux
.x_csect
.x_smclas
)
2309 if (last_csect_name
)
2311 /* If no misc. function recorded in the last
2312 seen csect, enter it as a function. This
2313 will take care of functions like strcmp()
2316 if (!misc_func_recorded
)
2318 RECORD_MINIMAL_SYMBOL
2319 (last_csect_name
, last_csect_val
,
2320 mst_text
, last_csect_sec
,
2326 /* We have to allocate one psymtab for
2327 each program csect, because their text
2328 sections need not be adjacent. */
2330 (pst
, psymtab_include_list
, includes_used
,
2331 symnum_before
, dependency_list
,
2332 dependencies_used
, textlow_not_set
);
2334 dependencies_used
= 0;
2335 /* Give all psymtabs for this source file the same
2337 pst
= xcoff_start_psymtab
2341 objfile
->global_psymbols
.next
,
2342 objfile
->static_psymbols
.next
);
2345 if (namestring
&& namestring
[0] == '.')
2347 last_csect_name
= namestring
;
2348 last_csect_val
= symbol
.n_value
;
2350 secnum_to_section (symbol
.n_scnum
, objfile
);
2355 symbol
.n_value
+ csect_aux
.x_csect
.x_scnlen
.l
;
2356 if (highval
> pst
->texthigh
)
2357 pst
->texthigh
= highval
;
2358 if (pst
->textlow
== 0 || symbol
.n_value
< pst
->textlow
)
2359 pst
->textlow
= symbol
.n_value
;
2361 misc_func_recorded
= 0;
2365 /* Data variables are recorded in the minimal symbol
2366 table, except for section symbols. */
2367 if (*namestring
!= '.')
2368 prim_record_minimal_symbol_and_info
2369 (namestring
, symbol
.n_value
,
2370 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2371 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2377 warning ("More than one XMC_TC0 symbol found.");
2378 toc_offset
= symbol
.n_value
;
2380 /* Make TOC offset relative to start address of section. */
2381 bfd_sect
= secnum_to_bfd_section (symbol
.n_scnum
, objfile
);
2383 toc_offset
-= bfd_section_vma (objfile
->obfd
, bfd_sect
);
2387 /* These symbols tell us where the TOC entry for a
2388 variable is, not the variable itself. */
2397 switch (csect_aux
.x_csect
.x_smclas
)
2400 /* A function entry point. */
2402 if (first_fun_line_offset
== 0 && symbol
.n_numaux
> 1)
2403 first_fun_line_offset
=
2404 main_aux
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2405 RECORD_MINIMAL_SYMBOL
2406 (namestring
, symbol
.n_value
,
2407 sclass
== C_HIDEXT
? mst_file_text
: mst_text
,
2408 secnum_to_section (symbol
.n_scnum
, objfile
),
2413 /* shared library function trampoline code entry
2416 /* record trampoline code entries as
2417 mst_solib_trampoline symbol. When we lookup mst
2418 symbols, we will choose mst_text over
2419 mst_solib_trampoline. */
2420 RECORD_MINIMAL_SYMBOL
2421 (namestring
, symbol
.n_value
,
2422 mst_solib_trampoline
,
2423 secnum_to_section (symbol
.n_scnum
, objfile
),
2428 /* The symbols often have the same names as
2429 debug symbols for functions, and confuse
2435 /* xlc puts each variable in a separate csect,
2436 so we get an XTY_SD for each variable. But
2437 gcc puts several variables in a csect, so
2438 that each variable only gets an XTY_LD. We
2439 still need to record them. This will
2440 typically be XMC_RW; I suspect XMC_RO and
2441 XMC_BS might be possible too. */
2442 if (*namestring
!= '.')
2443 prim_record_minimal_symbol_and_info
2444 (namestring
, symbol
.n_value
,
2445 sclass
== C_HIDEXT
? mst_file_data
: mst_data
,
2446 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2453 switch (csect_aux
.x_csect
.x_smclas
)
2457 /* Common variables are recorded in the minimal symbol
2458 table, except for section symbols. */
2459 if (*namestring
!= '.')
2460 prim_record_minimal_symbol_and_info
2461 (namestring
, symbol
.n_value
,
2462 sclass
== C_HIDEXT
? mst_file_bss
: mst_bss
,
2463 NULL
, secnum_to_section (symbol
.n_scnum
, objfile
),
2476 unsigned int symnum_before
;
2478 symnum_before
= ssymnum
;
2479 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2482 /* See if the last csect needs to be recorded. */
2484 if (last_csect_name
&& !misc_func_recorded
)
2487 /* If no misc. function recorded in the last seen csect, enter
2488 it as a function. This will take care of functions like
2489 strcmp() compiled by xlc. */
2491 RECORD_MINIMAL_SYMBOL
2492 (last_csect_name
, last_csect_val
,
2493 mst_text
, last_csect_sec
, objfile
);
2498 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2499 symnum_before
, dependency_list
,
2500 dependencies_used
, textlow_not_set
);
2502 dependencies_used
= 0;
2504 first_fun_line_offset
= 0;
2506 /* XCOFF, according to the AIX 3.2 documentation, puts the
2507 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2508 do things the standard COFF way and put it in the auxent.
2509 We use the auxent if the symbol is ".file" and an auxent
2510 exists, otherwise use the symbol itself. */
2511 if (!strcmp (namestring
, ".file") && symbol
.n_numaux
> 0)
2513 filestring
= coff_getfilename (&main_aux
[0], objfile
);
2516 filestring
= namestring
;
2518 pst
= xcoff_start_psymtab (objfile
,
2521 objfile
->global_psymbols
.next
,
2522 objfile
->static_psymbols
.next
);
2523 last_csect_name
= NULL
;
2529 static struct complaint msg
=
2530 {"Storage class %d not recognized during scan", 0, 0};
2531 complain (&msg
, sclass
);
2535 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2536 to handle only the C_FUN and C_EXT. */
2551 /* C_EINCL means we are switching back to the main file. But there
2552 is no reason to care; the only thing we want to know about
2553 includes is the names of all the included (.h) files. */
2558 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2562 /* I don't think the name of the common block (as opposed to the
2563 variables within it) is something which is user visible
2571 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2572 so C_LSYM would appear to be only for locals. */
2578 /* We probably could save a few instructions by assuming that
2579 C_LSYM, C_PSYM, etc., never have auxents. */
2580 int naux1
= symbol
.n_numaux
+ 1;
2582 sraw_symbol
+= bfd_coff_symesz (abfd
) * naux1
;
2591 /* The value of the C_FUN is not the address of the function (it
2592 appears to be the address before linking), but as long as it
2593 is smaller than the actual address, then find_pc_partial_function
2594 will use the minimal symbols instead. I hope. */
2602 swap_sym (&symbol
, &main_aux
[0], &namestring
, &sraw_symbol
,
2604 #define CUR_SYMBOL_TYPE stype
2605 #define CUR_SYMBOL_VALUE symbol.n_value
2607 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2608 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2610 #define START_PSYMTAB(ofile,fname,low,symoff,global_syms,static_syms) 0
2611 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
2613 /* We have already set the namestring. */
2614 #define SET_NAMESTRING() /* */
2616 #include "partial-stab.h"
2622 xcoff_end_psymtab (pst
, psymtab_include_list
, includes_used
,
2623 ssymnum
, dependency_list
,
2624 dependencies_used
, textlow_not_set
);
2627 /* Record the toc offset value of this symbol table into objfile structure.
2628 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2629 this information would be file auxiliary header. */
2631 ((struct coff_symfile_info
*) objfile
->sym_private
)->toc_offset
= toc_offset
;
2634 /* Return the toc offset value for a given objfile. */
2637 get_toc_offset (objfile
)
2638 struct objfile
*objfile
;
2641 return ((struct coff_symfile_info
*) objfile
->sym_private
)->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
, mainline
)
2657 struct objfile
*objfile
;
2658 int mainline
; /* FIXME comments above */
2662 struct cleanup
*back_to
;
2663 int num_symbols
; /* # of symbols */
2664 file_ptr symtab_offset
; /* symbol table and */
2665 file_ptr stringtab_offset
; /* string table file offsets */
2666 struct coff_symfile_info
*info
;
2670 info
= (struct coff_symfile_info
*) objfile
->sym_private
;
2671 symfile_bfd
= abfd
= objfile
->obfd
;
2672 name
= objfile
->name
;
2674 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2675 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2676 stringtab_offset
= symtab_offset
+
2677 num_symbols
* coff_data (abfd
)->local_symesz
;
2679 info
->min_lineno_offset
= 0;
2680 info
->max_lineno_offset
= 0;
2681 bfd_map_over_sections (abfd
, find_linenos
, info
);
2683 if (num_symbols
> 0)
2685 /* Read the string table. */
2686 init_stringtab (abfd
, stringtab_offset
, objfile
);
2688 /* Read the .debug section, if present. */
2691 bfd_size_type length
;
2692 char *debugsec
= NULL
;
2694 secp
= bfd_get_section_by_name (abfd
, ".debug");
2697 length
= bfd_section_size (abfd
, secp
);
2701 (char *) obstack_alloc (&objfile
->symbol_obstack
, length
);
2703 if (!bfd_get_section_contents (abfd
, secp
, debugsec
,
2704 (file_ptr
) 0, length
))
2706 error ("Error reading .debug section of `%s': %s",
2707 name
, bfd_errmsg (bfd_get_error ()));
2711 ((struct coff_symfile_info
*) objfile
->sym_private
)->debugsec
=
2716 /* Read the symbols. We keep them in core because we will want to
2717 access them randomly in read_symbol*. */
2718 val
= bfd_seek (abfd
, symtab_offset
, SEEK_SET
);
2720 error ("Error reading symbols from %s: %s",
2721 name
, bfd_errmsg (bfd_get_error ()));
2722 size
= coff_data (abfd
)->local_symesz
* num_symbols
;
2723 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
=
2724 obstack_alloc (&objfile
->symbol_obstack
, size
);
2725 ((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl_num_syms
=
2728 val
= bfd_read (((struct coff_symfile_info
*) objfile
->sym_private
)->symtbl
,
2731 perror_with_name ("reading symbol table");
2733 /* If we are reinitializing, or if we have never loaded syms yet, init */
2735 || objfile
->global_psymbols
.size
== 0
2736 || objfile
->static_psymbols
.size
== 0)
2737 /* I'm not sure how how good num_symbols is; the rule of thumb in
2738 init_psymbol_list was developed for a.out. On the one hand,
2739 num_symbols includes auxents. On the other hand, it doesn't
2741 init_psymbol_list (objfile
, num_symbols
);
2743 free_pending_blocks ();
2744 back_to
= make_cleanup (really_free_pendings
, 0);
2746 init_minimal_symbol_collection ();
2747 make_cleanup_discard_minimal_symbols ();
2749 /* Now that the symbol table data of the executable file are all in core,
2750 process them and define symbols accordingly. */
2752 scan_xcoff_symtab (objfile
);
2754 /* Install any minimal symbols that have been collected as the current
2755 minimal symbols for this objfile. */
2757 install_minimal_symbols (objfile
);
2759 do_cleanups (back_to
);
2763 xcoff_symfile_offsets (objfile
, addrs
)
2764 struct objfile
*objfile
;
2765 struct section_addr_info
*addrs
;
2767 asection
*sect
= NULL
;
2770 objfile
->num_sections
= SECT_OFF_MAX
;
2771 objfile
->section_offsets
= (struct section_offsets
*)
2772 obstack_alloc (&objfile
->psymbol_obstack
, SIZEOF_SECTION_OFFSETS
);
2774 /* Initialize the section indexes for future use. */
2775 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
2777 objfile
->sect_index_text
= sect
->index
;
2779 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
2781 objfile
->sect_index_data
= sect
->index
;
2783 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
2785 objfile
->sect_index_bss
= sect
->index
;
2787 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
2789 objfile
->sect_index_rodata
= sect
->index
;
2791 for (i
= 0; i
< objfile
->num_sections
; ++i
)
2793 /* syms_from_objfile kindly subtracts from addr the
2794 bfd_section_vma of the .text section. This strikes me as
2795 wrong--whether the offset to be applied to symbol reading is
2796 relative to the start address of the section depends on the
2797 symbol format. In any event, this whole "addr" concept is
2798 pretty broken (it doesn't handle any section but .text
2799 sensibly), so just ignore the addr parameter and use 0.
2800 rs6000-nat.c will set the correct section offsets via
2801 objfile_relocate. */
2802 ANOFFSET (objfile
->section_offsets
, i
) = 0;
2806 /* Register our ability to parse symbols for xcoff BFD files. */
2808 static struct sym_fns xcoff_sym_fns
=
2811 /* It is possible that coff and xcoff should be merged as
2812 they do have fundamental similarities (for example, the extra storage
2813 classes used for stabs could presumably be recognized in any COFF file).
2814 However, in addition to obvious things like all the csect hair, there are
2815 some subtler differences between xcoffread.c and coffread.c, notably
2816 the fact that coffread.c has no need to read in all the symbols, but
2817 xcoffread.c reads all the symbols and does in fact randomly access them
2818 (in C_BSTAT and line number processing). */
2820 bfd_target_xcoff_flavour
,
2822 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2823 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
2824 xcoff_initial_scan
, /* sym_read: read a symbol file into symtab */
2825 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
2826 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
2827 NULL
/* next: pointer to next struct sym_fns */
2831 _initialize_xcoffread ()
2833 add_symtab_fns (&xcoff_sym_fns
);
2835 func_symbol_type
= init_type (TYPE_CODE_FUNC
, 1, 0,
2836 "<function, no debug info>", NULL
);
2837 TYPE_TARGET_TYPE (func_symbol_type
) = builtin_type_int
;
2839 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
2840 "<variable, no debug info>", NULL
);