2012-04-27 Sergio Durigan Junior <sergiodj@redhat.com>
[deliverable/binutils-gdb.git] / gdb / xcoffread.c
1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-2004, 2007-2012 Free Software Foundation, Inc.
3 Derived from coffread.c, dbxread.c, and a lot of hacking.
4 Contributed by IBM Corporation.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include "defs.h"
22 #include "bfd.h"
23
24 #include <sys/types.h>
25 #include <fcntl.h>
26 #include <ctype.h>
27 #include "gdb_string.h"
28
29 #include <sys/param.h>
30 #ifdef HAVE_SYS_FILE_H
31 #include <sys/file.h>
32 #endif
33 #include "gdb_stat.h"
34
35 #include "coff/internal.h"
36 #include "libcoff.h" /* FIXME, internal data from BFD */
37 #include "coff/xcoff.h"
38 #include "libxcoff.h"
39 #include "coff/rs6000.h"
40 #include "xcoffread.h"
41
42 #include "symtab.h"
43 #include "gdbtypes.h"
44 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */
45 #include "symfile.h"
46 #include "objfiles.h"
47 #include "buildsym.h"
48 #include "stabsread.h"
49 #include "expression.h"
50 #include "complaints.h"
51 #include "psympriv.h"
52
53 #include "gdb-stabs.h"
54
55 /* For interface with stabsread.c. */
56 #include "aout/stab_gnu.h"
57
58 \f
59 /* We put a pointer to this structure in the read_symtab_private field
60 of the psymtab. */
61
62 struct symloc
63 {
64
65 /* First symbol number for this file. */
66
67 int first_symnum;
68
69 /* Number of symbols in the section of the symbol table devoted to
70 this file's symbols (actually, the section bracketed may contain
71 more than just this file's symbols). If numsyms is 0, the only
72 reason for this thing's existence is the dependency list. Nothing
73 else will happen when it is read in. */
74
75 int numsyms;
76
77 /* Position of the start of the line number information for this
78 psymtab. */
79 unsigned int lineno_off;
80 };
81
82 /* Remember what we deduced to be the source language of this psymtab. */
83
84 static enum language psymtab_language = language_unknown;
85 \f
86
87 /* Simplified internal version of coff symbol table information. */
88
89 struct coff_symbol
90 {
91 char *c_name;
92 int c_symnum; /* Symbol number of this entry. */
93 int c_naux; /* 0 if syment only, 1 if syment + auxent. */
94 long c_value;
95 unsigned char c_sclass;
96 int c_secnum;
97 unsigned int c_type;
98 };
99
100 /* Last function's saved coff symbol `cs'. */
101
102 static struct coff_symbol fcn_cs_saved;
103
104 static bfd *symfile_bfd;
105
106 /* Core address of start and end of text of current source file.
107 This is calculated from the first function seen after a C_FILE
108 symbol. */
109
110
111 static CORE_ADDR cur_src_end_addr;
112
113 /* Core address of the end of the first object file. */
114
115 static CORE_ADDR first_object_file_end;
116
117 /* Initial symbol-table-debug-string vector length. */
118
119 #define INITIAL_STABVECTOR_LENGTH 40
120
121 /* Nonzero if within a function (so symbols should be local,
122 if nothing says specifically). */
123
124 int within_function;
125
126 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
127 there is any reason not to just use a #define, but might as well
128 ask BFD for the size and store it here, I guess. */
129
130 static unsigned local_symesz;
131
132 struct coff_symfile_info
133 {
134 file_ptr min_lineno_offset; /* Where in file lowest line#s are. */
135 file_ptr max_lineno_offset; /* 1+last byte of line#s in file. */
136
137 /* Pointer to the string table. */
138 char *strtbl;
139
140 /* Pointer to debug section. */
141 char *debugsec;
142
143 /* Pointer to the a.out symbol table. */
144 char *symtbl;
145
146 /* Number of symbols in symtbl. */
147 int symtbl_num_syms;
148
149 /* Offset in data section to TOC anchor. */
150 CORE_ADDR toc_offset;
151 };
152
153 /* XCOFF names for dwarf sections. There is no compressed sections. */
154
155 static const struct dwarf2_debug_sections dwarf2_xcoff_names = {
156 { ".dwinfo", NULL },
157 { ".dwabrev", NULL },
158 { ".dwline", NULL },
159 { ".dwloc", NULL },
160 { NULL, NULL }, /* debug_macinfo */
161 { NULL, NULL }, /* debug_macro */
162 { ".dwstr", NULL },
163 { ".dwrnges", NULL },
164 { NULL, NULL }, /* debug_types */
165 { ".dwframe", NULL },
166 { NULL, NULL }, /* eh_frame */
167 { NULL, NULL }, /* gdb_index */
168 23
169 };
170
171 static void
172 bf_notfound_complaint (void)
173 {
174 complaint (&symfile_complaints,
175 _("line numbers off, `.bf' symbol not found"));
176 }
177
178 static void
179 ef_complaint (int arg1)
180 {
181 complaint (&symfile_complaints,
182 _("Mismatched .ef symbol ignored starting at symnum %d"), arg1);
183 }
184
185 static void
186 eb_complaint (int arg1)
187 {
188 complaint (&symfile_complaints,
189 _("Mismatched .eb symbol ignored starting at symnum %d"), arg1);
190 }
191
192 static void xcoff_initial_scan (struct objfile *, int);
193
194 static void scan_xcoff_symtab (struct objfile *);
195
196 static char *xcoff_next_symbol_text (struct objfile *);
197
198 static void record_include_begin (struct coff_symbol *);
199
200 static void
201 enter_line_range (struct subfile *, unsigned, unsigned,
202 CORE_ADDR, CORE_ADDR, unsigned *);
203
204 static void init_stringtab (bfd *, file_ptr, struct objfile *);
205
206 static void xcoff_symfile_init (struct objfile *);
207
208 static void xcoff_new_init (struct objfile *);
209
210 static void xcoff_symfile_finish (struct objfile *);
211
212 static void xcoff_symfile_offsets (struct objfile *,
213 struct section_addr_info *addrs);
214
215 static char *coff_getfilename (union internal_auxent *, struct objfile *);
216
217 static void read_symbol (struct internal_syment *, int);
218
219 static int read_symbol_lineno (int);
220
221 static CORE_ADDR read_symbol_nvalue (int);
222
223 static struct symbol *process_xcoff_symbol (struct coff_symbol *,
224 struct objfile *);
225
226 static void read_xcoff_symtab (struct partial_symtab *);
227
228 #if 0
229 static void add_stab_to_list (char *, struct pending_stabs **);
230 #endif
231
232 static int compare_lte (const void *, const void *);
233
234 static struct linetable *arrange_linetable (struct linetable *);
235
236 static void record_include_end (struct coff_symbol *);
237
238 static void process_linenos (CORE_ADDR, CORE_ADDR);
239 \f
240
241 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
242 code. */
243 static int secnum_to_section (int, struct objfile *);
244 static asection *secnum_to_bfd_section (int, struct objfile *);
245
246 struct find_targ_sec_arg
247 {
248 int targ_index;
249 int *resultp;
250 asection **bfd_sect;
251 struct objfile *objfile;
252 };
253
254 static void find_targ_sec (bfd *, asection *, void *);
255
256 static void
257 find_targ_sec (bfd *abfd, asection *sect, void *obj)
258 {
259 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *) obj;
260 struct objfile *objfile = args->objfile;
261
262 if (sect->target_index == args->targ_index)
263 {
264 /* This is the section. Figure out what SECT_OFF_* code it is. */
265 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
266 *args->resultp = SECT_OFF_TEXT (objfile);
267 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
268 *args->resultp = SECT_OFF_DATA (objfile);
269 else
270 *args->resultp = sect->index;
271 *args->bfd_sect = sect;
272 }
273 }
274
275 /* Search all BFD sections for the section whose target_index is
276 equal to N_SCNUM. Set *BFD_SECT to that section. The section's
277 associated index in the objfile's section_offset table is also
278 stored in *SECNUM.
279
280 If no match is found, *BFD_SECT is set to NULL, and *SECNUM
281 is set to the text section's number. */
282
283 static void
284 xcoff_secnum_to_sections (int n_scnum, struct objfile *objfile,
285 asection **bfd_sect, int *secnum)
286 {
287 struct find_targ_sec_arg args;
288
289 args.targ_index = n_scnum;
290 args.resultp = secnum;
291 args.bfd_sect = bfd_sect;
292 args.objfile = objfile;
293
294 *bfd_sect = NULL;
295 *secnum = SECT_OFF_TEXT (objfile);
296
297 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
298 }
299
300 /* Return the section number (SECT_OFF_*) that N_SCNUM points to. */
301
302 static int
303 secnum_to_section (int n_scnum, struct objfile *objfile)
304 {
305 int secnum;
306 asection *ignored;
307
308 xcoff_secnum_to_sections (n_scnum, objfile, &ignored, &secnum);
309 return secnum;
310 }
311
312 /* Return the BFD section that N_SCNUM points to. */
313
314 static asection *
315 secnum_to_bfd_section (int n_scnum, struct objfile *objfile)
316 {
317 int ignored;
318 asection *bfd_sect;
319
320 xcoff_secnum_to_sections (n_scnum, objfile, &bfd_sect, &ignored);
321 return bfd_sect;
322 }
323 \f
324 /* add a given stab string into given stab vector. */
325
326 #if 0
327
328 static void
329 add_stab_to_list (char *stabname, struct pending_stabs **stabvector)
330 {
331 if (*stabvector == NULL)
332 {
333 *stabvector = (struct pending_stabs *)
334 xmalloc (sizeof (struct pending_stabs) +
335 INITIAL_STABVECTOR_LENGTH * sizeof (char *));
336 (*stabvector)->count = 0;
337 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
338 }
339 else if ((*stabvector)->count >= (*stabvector)->length)
340 {
341 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
342 *stabvector = (struct pending_stabs *)
343 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
344 (*stabvector)->length * sizeof (char *));
345 }
346 (*stabvector)->stab[(*stabvector)->count++] = stabname;
347 }
348
349 #endif
350 \f/* *INDENT-OFF* */
351 /* Linenos are processed on a file-by-file basis.
352
353 Two reasons:
354
355 1) xlc (IBM's native c compiler) postpones static function code
356 emission to the end of a compilation unit. This way it can
357 determine if those functions (statics) are needed or not, and
358 can do some garbage collection (I think). This makes line
359 numbers and corresponding addresses unordered, and we end up
360 with a line table like:
361
362
363 lineno addr
364 foo() 10 0x100
365 20 0x200
366 30 0x300
367
368 foo3() 70 0x400
369 80 0x500
370 90 0x600
371
372 static foo2()
373 40 0x700
374 50 0x800
375 60 0x900
376
377 and that breaks gdb's binary search on line numbers, if the
378 above table is not sorted on line numbers. And that sort
379 should be on function based, since gcc can emit line numbers
380 like:
381
382 10 0x100 - for the init/test part of a for stmt.
383 20 0x200
384 30 0x300
385 10 0x400 - for the increment part of a for stmt.
386
387 arrange_linetable() will do this sorting.
388
389 2) aix symbol table might look like:
390
391 c_file // beginning of a new file
392 .bi // beginning of include file
393 .ei // end of include file
394 .bi
395 .ei
396
397 basically, .bi/.ei pairs do not necessarily encapsulate
398 their scope. They need to be recorded, and processed later
399 on when we come the end of the compilation unit.
400 Include table (inclTable) and process_linenos() handle
401 that. */
402 /* *INDENT-ON* */
403
404
405
406 /* compare line table entry addresses. */
407
408 static int
409 compare_lte (const void *lte1p, const void *lte2p)
410 {
411 struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
412 struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
413
414 return lte1->pc - lte2->pc;
415 }
416
417 /* Given a line table with function entries are marked, arrange its
418 functions in ascending order and strip off function entry markers
419 and return it in a newly created table. If the old one is good
420 enough, return the old one. */
421 /* FIXME: I think all this stuff can be replaced by just passing
422 sort_linevec = 1 to end_symtab. */
423
424 static struct linetable *
425 arrange_linetable (struct linetable *oldLineTb)
426 {
427 int ii, jj, newline, /* new line count */
428 function_count; /* # of functions */
429
430 struct linetable_entry *fentry; /* function entry vector */
431 int fentry_size; /* # of function entries */
432 struct linetable *newLineTb; /* new line table */
433
434 #define NUM_OF_FUNCTIONS 20
435
436 fentry_size = NUM_OF_FUNCTIONS;
437 fentry = (struct linetable_entry *)
438 xmalloc (fentry_size * sizeof (struct linetable_entry));
439
440 for (function_count = 0, ii = 0; ii < oldLineTb->nitems; ++ii)
441 {
442 if (oldLineTb->item[ii].line == 0)
443 { /* Function entry found. */
444 if (function_count >= fentry_size)
445 { /* Make sure you have room. */
446 fentry_size *= 2;
447 fentry = (struct linetable_entry *)
448 xrealloc (fentry,
449 fentry_size * sizeof (struct linetable_entry));
450 }
451 fentry[function_count].line = ii;
452 fentry[function_count].pc = oldLineTb->item[ii].pc;
453 ++function_count;
454 }
455 }
456
457 if (function_count == 0)
458 {
459 xfree (fentry);
460 return oldLineTb;
461 }
462 else if (function_count > 1)
463 qsort (fentry, function_count,
464 sizeof (struct linetable_entry), compare_lte);
465
466 /* Allocate a new line table. */
467 newLineTb = (struct linetable *)
468 xmalloc
469 (sizeof (struct linetable) +
470 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
471
472 /* If line table does not start with a function beginning, copy up until
473 a function begin. */
474
475 newline = 0;
476 if (oldLineTb->item[0].line != 0)
477 for (newline = 0;
478 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
479 newLineTb->item[newline] = oldLineTb->item[newline];
480
481 /* Now copy function lines one by one. */
482
483 for (ii = 0; ii < function_count; ++ii)
484 {
485 for (jj = fentry[ii].line + 1;
486 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
487 ++jj, ++newline)
488 newLineTb->item[newline] = oldLineTb->item[jj];
489 }
490 xfree (fentry);
491 newLineTb->nitems = oldLineTb->nitems - function_count;
492 return newLineTb;
493 }
494
495 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
496 following `IncludeChain'. At the end of each symtab (end_symtab),
497 we will determine if we should create additional symtab's to
498 represent if (the include files. */
499
500
501 typedef struct _inclTable
502 {
503 char *name; /* include filename */
504
505 /* Offsets to the line table. end points to the last entry which is
506 part of this include file. */
507 int begin, end;
508
509 struct subfile *subfile;
510 unsigned funStartLine; /* Start line # of its function. */
511 }
512 InclTable;
513
514 #define INITIAL_INCLUDE_TABLE_LENGTH 20
515 static InclTable *inclTable; /* global include table */
516 static int inclIndx; /* last entry to table */
517 static int inclLength; /* table length */
518 static int inclDepth; /* nested include depth */
519
520 static void allocate_include_entry (void);
521
522 static void
523 record_include_begin (struct coff_symbol *cs)
524 {
525 if (inclDepth)
526 {
527 /* In xcoff, we assume include files cannot be nested (not in .c files
528 of course, but in corresponding .s files.). */
529
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 complaint (&symfile_complaints, _("Nested C_BINCL symbols"));
534 }
535 ++inclDepth;
536
537 allocate_include_entry ();
538
539 inclTable[inclIndx].name = cs->c_name;
540 inclTable[inclIndx].begin = cs->c_value;
541 }
542
543 static void
544 record_include_end (struct coff_symbol *cs)
545 {
546 InclTable *pTbl;
547
548 if (inclDepth == 0)
549 {
550 complaint (&symfile_complaints, _("Mismatched C_BINCL/C_EINCL pair"));
551 }
552
553 allocate_include_entry ();
554
555 pTbl = &inclTable[inclIndx];
556 pTbl->end = cs->c_value;
557
558 --inclDepth;
559 ++inclIndx;
560 }
561
562 static void
563 allocate_include_entry (void)
564 {
565 if (inclTable == NULL)
566 {
567 inclTable = (InclTable *)
568 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
569 memset (inclTable,
570 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
571 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
572 inclIndx = 0;
573 }
574 else if (inclIndx >= inclLength)
575 {
576 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
577 inclTable = (InclTable *)
578 xrealloc (inclTable, sizeof (InclTable) * inclLength);
579 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
580 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
581 }
582 }
583
584 /* Global variable to pass the psymtab down to all the routines involved
585 in psymtab to symtab processing. */
586 static struct partial_symtab *this_symtab_psymtab;
587
588 /* given the start and end addresses of a compilation unit (or a csect,
589 at times) process its lines and create appropriate line vectors. */
590
591 static void
592 process_linenos (CORE_ADDR start, CORE_ADDR end)
593 {
594 int offset, ii;
595 file_ptr max_offset =
596 ((struct coff_symfile_info *) this_symtab_psymtab->objfile
597 ->deprecated_sym_private)->max_lineno_offset;
598
599 /* subfile structure for the main compilation unit. */
600 struct subfile main_subfile;
601
602 /* In the main source file, any time we see a function entry, we
603 reset this variable to function's absolute starting line number.
604 All the following line numbers in the function are relative to
605 this, and we record absolute line numbers in record_line(). */
606
607 unsigned int main_source_baseline = 0;
608
609 unsigned *firstLine;
610
611 offset =
612 ((struct symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off;
613 if (offset == 0)
614 goto return_after_cleanup;
615
616 memset (&main_subfile, '\0', sizeof (main_subfile));
617
618 if (inclIndx == 0)
619 /* All source lines were in the main source file. None in include
620 files. */
621
622 enter_line_range (&main_subfile, offset, 0, start, end,
623 &main_source_baseline);
624
625 else
626 {
627 /* There was source with line numbers in include files. */
628
629 int linesz =
630 coff_data (this_symtab_psymtab->objfile->obfd)->local_linesz;
631 main_source_baseline = 0;
632
633 for (ii = 0; ii < inclIndx; ++ii)
634 {
635 struct subfile *tmpSubfile;
636
637 /* If there is main file source before include file, enter it. */
638 if (offset < inclTable[ii].begin)
639 {
640 enter_line_range
641 (&main_subfile, offset, inclTable[ii].begin - linesz,
642 start, 0, &main_source_baseline);
643 }
644
645 if (strcmp (inclTable[ii].name, last_source_file) == 0)
646 {
647 /* The entry in the include table refers to the main source
648 file. Add the lines to the main subfile. */
649
650 main_source_baseline = inclTable[ii].funStartLine;
651 enter_line_range
652 (&main_subfile, inclTable[ii].begin, inclTable[ii].end,
653 start, 0, &main_source_baseline);
654 inclTable[ii].subfile = &main_subfile;
655 }
656 else
657 {
658 /* Have a new subfile for the include file. */
659
660 tmpSubfile = inclTable[ii].subfile =
661 (struct subfile *) xmalloc (sizeof (struct subfile));
662
663 memset (tmpSubfile, '\0', sizeof (struct subfile));
664 firstLine = &(inclTable[ii].funStartLine);
665
666 /* Enter include file's lines now. */
667 enter_line_range (tmpSubfile, inclTable[ii].begin,
668 inclTable[ii].end, start, 0, firstLine);
669 }
670
671 if (offset <= inclTable[ii].end)
672 offset = inclTable[ii].end + linesz;
673 }
674
675 /* All the include files' line have been processed at this point. Now,
676 enter remaining lines of the main file, if any left. */
677 if (offset < max_offset + 1 - linesz)
678 {
679 enter_line_range (&main_subfile, offset, 0, start, end,
680 &main_source_baseline);
681 }
682 }
683
684 /* Process main file's line numbers. */
685 if (main_subfile.line_vector)
686 {
687 struct linetable *lineTb, *lv;
688
689 lv = main_subfile.line_vector;
690
691 /* Line numbers are not necessarily ordered. xlc compilation will
692 put static function to the end. */
693
694 lineTb = arrange_linetable (lv);
695 if (lv == lineTb)
696 {
697 current_subfile->line_vector = (struct linetable *)
698 xrealloc (lv, (sizeof (struct linetable)
699 + lv->nitems * sizeof (struct linetable_entry)));
700 }
701 else
702 {
703 xfree (lv);
704 current_subfile->line_vector = lineTb;
705 }
706
707 current_subfile->line_vector_length =
708 current_subfile->line_vector->nitems;
709 }
710
711 /* Now, process included files' line numbers. */
712
713 for (ii = 0; ii < inclIndx; ++ii)
714 {
715 if (inclTable[ii].subfile != ((struct subfile *) &main_subfile)
716 && (inclTable[ii].subfile)->line_vector) /* Useless if!!!
717 FIXMEmgo */
718 {
719 struct linetable *lineTb, *lv;
720
721 lv = (inclTable[ii].subfile)->line_vector;
722
723 /* Line numbers are not necessarily ordered. xlc compilation will
724 put static function to the end. */
725
726 lineTb = arrange_linetable (lv);
727
728 push_subfile ();
729
730 /* For the same include file, we might want to have more than one
731 subfile. This happens if we have something like:
732
733 ......
734 #include "foo.h"
735 ......
736 #include "foo.h"
737 ......
738
739 while foo.h including code in it. (stupid but possible)
740 Since start_subfile() looks at the name and uses an
741 existing one if finds, we need to provide a fake name and
742 fool it. */
743
744 #if 0
745 start_subfile (inclTable[ii].name, (char *) 0);
746 #else
747 {
748 /* Pick a fake name that will produce the same results as this
749 one when passed to deduce_language_from_filename. Kludge on
750 top of kludge. */
751 char *fakename = strrchr (inclTable[ii].name, '.');
752
753 if (fakename == NULL)
754 fakename = " ?";
755 start_subfile (fakename, (char *) 0);
756 xfree (current_subfile->name);
757 }
758 current_subfile->name = xstrdup (inclTable[ii].name);
759 #endif
760
761 if (lv == lineTb)
762 {
763 current_subfile->line_vector =
764 (struct linetable *) xrealloc
765 (lv, (sizeof (struct linetable)
766 + lv->nitems * sizeof (struct linetable_entry)));
767
768 }
769 else
770 {
771 xfree (lv);
772 current_subfile->line_vector = lineTb;
773 }
774
775 current_subfile->line_vector_length =
776 current_subfile->line_vector->nitems;
777 start_subfile (pop_subfile (), (char *) 0);
778 }
779 }
780
781 return_after_cleanup:
782
783 /* We don't want to keep alloc/free'ing the global include file table. */
784 inclIndx = 0;
785
786 /* Start with a fresh subfile structure for the next file. */
787 memset (&main_subfile, '\0', sizeof (struct subfile));
788 }
789
790 static void
791 aix_process_linenos (void)
792 {
793 /* There is no linenos to read if there are only dwarf info. */
794 if (this_symtab_psymtab == NULL)
795 return;
796
797 /* Process line numbers and enter them into line vector. */
798 process_linenos (last_source_start_addr, cur_src_end_addr);
799 }
800
801
802 /* Enter a given range of lines into the line vector.
803 can be called in the following two ways:
804 enter_line_range (subfile, beginoffset, endoffset,
805 startaddr, 0, firstLine) or
806 enter_line_range (subfile, beginoffset, 0,
807 startaddr, endaddr, firstLine)
808
809 endoffset points to the last line table entry that we should pay
810 attention to. */
811
812 static void
813 enter_line_range (struct subfile *subfile, unsigned beginoffset,
814 unsigned endoffset, /* offsets to line table */
815 CORE_ADDR startaddr, /* offsets to line table */
816 CORE_ADDR endaddr, unsigned *firstLine)
817 {
818 struct objfile *objfile = this_symtab_psymtab->objfile;
819 struct gdbarch *gdbarch = get_objfile_arch (objfile);
820 unsigned int curoffset;
821 CORE_ADDR addr;
822 void *ext_lnno;
823 struct internal_lineno int_lnno;
824 unsigned int limit_offset;
825 bfd *abfd;
826 int linesz;
827
828 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
829 return;
830 curoffset = beginoffset;
831 limit_offset =
832 ((struct coff_symfile_info *) objfile->deprecated_sym_private)
833 ->max_lineno_offset;
834
835 if (endoffset != 0)
836 {
837 if (endoffset >= limit_offset)
838 {
839 complaint (&symfile_complaints,
840 _("Bad line table offset in C_EINCL directive"));
841 return;
842 }
843 limit_offset = endoffset;
844 }
845 else
846 limit_offset -= 1;
847
848 abfd = objfile->obfd;
849 linesz = coff_data (abfd)->local_linesz;
850 ext_lnno = alloca (linesz);
851
852 while (curoffset <= limit_offset)
853 {
854 bfd_seek (abfd, curoffset, SEEK_SET);
855 bfd_bread (ext_lnno, linesz, abfd);
856 bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno);
857
858 /* Find the address this line represents. */
859 addr = (int_lnno.l_lnno
860 ? int_lnno.l_addr.l_paddr
861 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
862 addr += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
863
864 if (addr < startaddr || (endaddr && addr >= endaddr))
865 return;
866
867 if (int_lnno.l_lnno == 0)
868 {
869 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
870 record_line (subfile, 0, gdbarch_addr_bits_remove (gdbarch, addr));
871 --(*firstLine);
872 }
873 else
874 record_line (subfile, *firstLine + int_lnno.l_lnno,
875 gdbarch_addr_bits_remove (gdbarch, addr));
876 curoffset += linesz;
877 }
878 }
879
880
881 /* Save the vital information for use when closing off the current file.
882 NAME is the file name the symbols came from, START_ADDR is the first
883 text address for the file, and SIZE is the number of bytes of text. */
884
885 #define complete_symtab(name, start_addr) { \
886 last_source_file = xstrdup (name); \
887 last_source_start_addr = start_addr; \
888 }
889
890
891 /* Refill the symbol table input buffer
892 and set the variables that control fetching entries from it.
893 Reports an error if no data available.
894 This function can read past the end of the symbol table
895 (into the string table) but this does no harm. */
896
897 /* Create a new minimal symbol (using prim_record_minimal_symbol_and_info).
898
899 Arguments are:
900
901 NAME - the symbol's name (but if NAME starts with a period, that
902 leading period is discarded).
903 ADDRESS - the symbol's address.
904 MS_TYPE - the symbol's type.
905 N_SCNUM - the symbol's XCOFF section number.
906 OBJFILE - the objfile associated with the minimal symbol. */
907
908 static void
909 record_minimal_symbol (const char *name, CORE_ADDR address,
910 enum minimal_symbol_type ms_type,
911 int n_scnum,
912 struct objfile *objfile)
913 {
914 struct find_targ_sec_arg args;
915 int secnum;
916 asection *bfd_sect;
917
918 if (name[0] == '.')
919 ++name;
920
921 xcoff_secnum_to_sections (n_scnum, objfile, &bfd_sect, &secnum);
922 prim_record_minimal_symbol_and_info (name, address, ms_type,
923 secnum, bfd_sect, objfile);
924 }
925
926 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
927 nested. At any given time, a symbol can only be in one static block.
928 This is the base address of current static block, zero if non exists. */
929
930 static int static_block_base = 0;
931
932 /* Section number for the current static block. */
933
934 static int static_block_section = -1;
935
936 /* true if space for symbol name has been allocated. */
937
938 static int symname_alloced = 0;
939
940 /* Next symbol to read. Pointer into raw seething symbol table. */
941
942 static char *raw_symbol;
943
944 /* This is the function which stabsread.c calls to get symbol
945 continuations. */
946
947 static char *
948 xcoff_next_symbol_text (struct objfile *objfile)
949 {
950 struct internal_syment symbol;
951 char *retval;
952
953 /* FIXME: is this the same as the passed arg? */
954 if (this_symtab_psymtab)
955 objfile = this_symtab_psymtab->objfile;
956
957 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
958 if (symbol.n_zeroes)
959 {
960 complaint (&symfile_complaints, _("Unexpected symbol continuation"));
961
962 /* Return something which points to '\0' and hope the symbol reading
963 code does something reasonable. */
964 retval = "";
965 }
966 else if (symbol.n_sclass & 0x80)
967 {
968 retval = ((struct coff_symfile_info *)
969 objfile->deprecated_sym_private)->debugsec
970 + symbol.n_offset;
971 raw_symbol += coff_data (objfile->obfd)->local_symesz;
972 ++symnum;
973 }
974 else
975 {
976 complaint (&symfile_complaints, _("Unexpected symbol continuation"));
977
978 /* Return something which points to '\0' and hope the symbol reading
979 code does something reasonable. */
980 retval = "";
981 }
982 return retval;
983 }
984
985 /* Read symbols for a given partial symbol table. */
986
987 static void
988 read_xcoff_symtab (struct partial_symtab *pst)
989 {
990 struct objfile *objfile = pst->objfile;
991 bfd *abfd = objfile->obfd;
992 char *raw_auxptr; /* Pointer to first raw aux entry for sym. */
993 char *strtbl =
994 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl;
995 char *debugsec =
996 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec;
997 const char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF";
998
999 struct internal_syment symbol[1];
1000 union internal_auxent main_aux;
1001 struct coff_symbol cs[1];
1002 CORE_ADDR file_start_addr = 0;
1003 CORE_ADDR file_end_addr = 0;
1004
1005 int next_file_symnum = -1;
1006 unsigned int max_symnum;
1007 int just_started = 1;
1008 int depth = 0;
1009 int fcn_start_addr = 0;
1010
1011 struct coff_symbol fcn_stab_saved = { 0 };
1012
1013 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1014 union internal_auxent fcn_aux_saved = main_aux;
1015 struct context_stack *new;
1016
1017 char *filestring = " _start_ "; /* Name of the current file. */
1018
1019 const char *last_csect_name; /* Last seen csect's name. */
1020
1021 this_symtab_psymtab = pst;
1022
1023 /* Get the appropriate COFF "constants" related to the file we're
1024 handling. */
1025 local_symesz = coff_data (abfd)->local_symesz;
1026
1027 last_source_file = NULL;
1028 last_csect_name = 0;
1029
1030 start_stabs ();
1031 start_symtab (filestring, (char *) NULL, file_start_addr);
1032 record_debugformat (debugfmt);
1033 symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum;
1034 max_symnum =
1035 symnum + ((struct symloc *) pst->read_symtab_private)->numsyms;
1036 first_object_file_end = 0;
1037
1038 raw_symbol =
1039 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl
1040 + symnum * local_symesz;
1041
1042 while (symnum < max_symnum)
1043 {
1044 QUIT; /* make this command interruptable. */
1045
1046 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1047 /* read one symbol into `cs' structure. After processing the
1048 whole symbol table, only string table will be kept in memory,
1049 symbol table and debug section of xcoff will be freed. Thus
1050 we can mark symbols with names in string table as
1051 `alloced'. */
1052 {
1053 int ii;
1054
1055 /* Swap and align the symbol into a reasonable C structure. */
1056 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1057
1058 cs->c_symnum = symnum;
1059 cs->c_naux = symbol->n_numaux;
1060 if (symbol->n_zeroes)
1061 {
1062 symname_alloced = 0;
1063 /* We must use the original, unswapped, name here so the name field
1064 pointed to by cs->c_name will persist throughout xcoffread. If
1065 we use the new field, it gets overwritten for each symbol. */
1066 cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name;
1067 /* If it's exactly E_SYMNMLEN characters long it isn't
1068 '\0'-terminated. */
1069 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1070 {
1071 char *p;
1072
1073 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
1074 strncpy (p, cs->c_name, E_SYMNMLEN);
1075 p[E_SYMNMLEN] = '\0';
1076 cs->c_name = p;
1077 symname_alloced = 1;
1078 }
1079 }
1080 else if (symbol->n_sclass & 0x80)
1081 {
1082 cs->c_name = debugsec + symbol->n_offset;
1083 symname_alloced = 0;
1084 }
1085 else
1086 {
1087 /* in string table */
1088 cs->c_name = strtbl + (int) symbol->n_offset;
1089 symname_alloced = 1;
1090 }
1091 cs->c_value = symbol->n_value;
1092 cs->c_sclass = symbol->n_sclass;
1093 cs->c_secnum = symbol->n_scnum;
1094 cs->c_type = (unsigned) symbol->n_type;
1095
1096 raw_symbol += local_symesz;
1097 ++symnum;
1098
1099 /* Save addr of first aux entry. */
1100 raw_auxptr = raw_symbol;
1101
1102 /* Skip all the auxents associated with this symbol. */
1103 for (ii = symbol->n_numaux; ii; --ii)
1104 {
1105 raw_symbol += coff_data (abfd)->local_auxesz;
1106 ++symnum;
1107 }
1108 }
1109
1110 /* if symbol name starts with ".$" or "$", ignore it. */
1111 if (cs->c_name[0] == '$'
1112 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1113 continue;
1114
1115 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1116 {
1117 if (last_source_file)
1118 {
1119 pst->symtab = end_symtab (cur_src_end_addr, objfile,
1120 SECT_OFF_TEXT (objfile));
1121 end_stabs ();
1122 }
1123
1124 start_stabs ();
1125 start_symtab ("_globals_", (char *) NULL, (CORE_ADDR) 0);
1126 record_debugformat (debugfmt);
1127 cur_src_end_addr = first_object_file_end;
1128 /* Done with all files, everything from here on is globals. */
1129 }
1130
1131 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1132 && cs->c_naux == 1)
1133 {
1134 /* Dealing with a symbol with a csect entry. */
1135
1136 #define CSECT(PP) ((PP)->x_csect)
1137 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1138 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1139 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1140 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1141
1142 /* Convert the auxent to something we can access. */
1143 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1144 0, cs->c_naux, &main_aux);
1145
1146 switch (CSECT_SMTYP (&main_aux))
1147 {
1148
1149 case XTY_ER:
1150 /* Ignore all external references. */
1151 continue;
1152
1153 case XTY_SD:
1154 /* A section description. */
1155 {
1156 switch (CSECT_SCLAS (&main_aux))
1157 {
1158
1159 case XMC_PR:
1160 {
1161
1162 /* A program csect is seen. We have to allocate one
1163 symbol table for each program csect. Normally gdb
1164 prefers one symtab for each source file. In case
1165 of AIX, one source file might include more than one
1166 [PR] csect, and they don't have to be adjacent in
1167 terms of the space they occupy in memory. Thus, one
1168 single source file might get fragmented in the
1169 memory and gdb's file start and end address
1170 approach does not work! GCC (and I think xlc) seem
1171 to put all the code in the unnamed program csect. */
1172
1173 if (last_csect_name)
1174 {
1175 complete_symtab (filestring, file_start_addr);
1176 cur_src_end_addr = file_end_addr;
1177 end_symtab (file_end_addr, objfile,
1178 SECT_OFF_TEXT (objfile));
1179 end_stabs ();
1180 start_stabs ();
1181 /* Give all csects for this source file the same
1182 name. */
1183 start_symtab (filestring, NULL, (CORE_ADDR) 0);
1184 record_debugformat (debugfmt);
1185 }
1186
1187 /* If this is the very first csect seen,
1188 basically `__start'. */
1189 if (just_started)
1190 {
1191 first_object_file_end
1192 = cs->c_value + CSECT_LEN (&main_aux);
1193 just_started = 0;
1194 }
1195
1196 file_start_addr =
1197 cs->c_value + ANOFFSET (objfile->section_offsets,
1198 SECT_OFF_TEXT (objfile));
1199 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1200
1201 if (cs->c_name && (cs->c_name[0] == '.' || cs->c_name[0] == '@'))
1202 last_csect_name = cs->c_name;
1203 }
1204 continue;
1205
1206 /* All other symbols are put into the minimal symbol
1207 table only. */
1208
1209 case XMC_RW:
1210 continue;
1211
1212 case XMC_TC0:
1213 continue;
1214
1215 case XMC_TC:
1216 continue;
1217
1218 default:
1219 /* Ignore the symbol. */
1220 continue;
1221 }
1222 }
1223 break;
1224
1225 case XTY_LD:
1226
1227 switch (CSECT_SCLAS (&main_aux))
1228 {
1229 case XMC_PR:
1230 /* a function entry point. */
1231 function_entry_point:
1232
1233 fcn_start_addr = cs->c_value;
1234
1235 /* save the function header info, which will be used
1236 when `.bf' is seen. */
1237 fcn_cs_saved = *cs;
1238 fcn_aux_saved = main_aux;
1239 continue;
1240
1241 case XMC_GL:
1242 /* shared library function trampoline code entry point. */
1243 continue;
1244
1245 case XMC_DS:
1246 /* The symbols often have the same names as debug symbols for
1247 functions, and confuse lookup_symbol. */
1248 continue;
1249
1250 default:
1251 /* xlc puts each variable in a separate csect, so we get
1252 an XTY_SD for each variable. But gcc puts several
1253 variables in a csect, so that each variable only gets
1254 an XTY_LD. This will typically be XMC_RW; I suspect
1255 XMC_RO and XMC_BS might be possible too.
1256 These variables are put in the minimal symbol table
1257 only. */
1258 continue;
1259 }
1260 break;
1261
1262 case XTY_CM:
1263 /* Common symbols are put into the minimal symbol table only. */
1264 continue;
1265
1266 default:
1267 break;
1268 }
1269 }
1270
1271 /* If explicitly specified as a function, treat is as one. This check
1272 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1273 after the above CSECT check. */
1274 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
1275 {
1276 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1277 0, cs->c_naux, &main_aux);
1278 goto function_entry_point;
1279 }
1280
1281 switch (cs->c_sclass)
1282 {
1283 case C_FILE:
1284
1285 /* c_value field contains symnum of next .file entry in table
1286 or symnum of first global after last .file. */
1287
1288 next_file_symnum = cs->c_value;
1289
1290 /* Complete symbol table for last object file containing
1291 debugging information. */
1292
1293 /* Whether or not there was a csect in the previous file, we
1294 have to call `end_stabs' and `start_stabs' to reset
1295 type_vector, line_vector, etc. structures. */
1296
1297 complete_symtab (filestring, file_start_addr);
1298 cur_src_end_addr = file_end_addr;
1299 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1300 end_stabs ();
1301
1302 /* XCOFF, according to the AIX 3.2 documentation, puts the
1303 filename in cs->c_name. But xlc 1.3.0.2 has decided to
1304 do things the standard COFF way and put it in the auxent.
1305 We use the auxent if the symbol is ".file" and an auxent
1306 exists, otherwise use the symbol itself. Simple
1307 enough. */
1308 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1309 {
1310 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1311 0, cs->c_naux, &main_aux);
1312 filestring = coff_getfilename (&main_aux, objfile);
1313 }
1314 else
1315 filestring = cs->c_name;
1316
1317 start_stabs ();
1318 start_symtab (filestring, (char *) NULL, (CORE_ADDR) 0);
1319 record_debugformat (debugfmt);
1320 last_csect_name = 0;
1321
1322 /* reset file start and end addresses. A compilation unit
1323 with no text (only data) should have zero file
1324 boundaries. */
1325 file_start_addr = file_end_addr = 0;
1326 break;
1327
1328 case C_FUN:
1329 fcn_stab_saved = *cs;
1330 break;
1331
1332 case C_FCN:
1333 if (strcmp (cs->c_name, ".bf") == 0)
1334 {
1335 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1336 SECT_OFF_TEXT (objfile));
1337
1338 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1339 0, cs->c_naux, &main_aux);
1340
1341 within_function = 1;
1342
1343 new = push_context (0, fcn_start_addr + off);
1344
1345 new->name = define_symbol
1346 (fcn_cs_saved.c_value + off,
1347 fcn_stab_saved.c_name, 0, 0, objfile);
1348 if (new->name != NULL)
1349 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT (objfile);
1350 }
1351 else if (strcmp (cs->c_name, ".ef") == 0)
1352 {
1353 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1354 0, cs->c_naux, &main_aux);
1355
1356 /* The value of .ef is the address of epilogue code;
1357 not useful for gdb. */
1358 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1359 contains number of lines to '}' */
1360
1361 if (context_stack_depth <= 0)
1362 { /* We attempted to pop an empty context stack. */
1363 ef_complaint (cs->c_symnum);
1364 within_function = 0;
1365 break;
1366 }
1367 new = pop_context ();
1368 /* Stack must be empty now. */
1369 if (context_stack_depth > 0 || new == NULL)
1370 {
1371 ef_complaint (cs->c_symnum);
1372 within_function = 0;
1373 break;
1374 }
1375
1376 finish_block (new->name, &local_symbols, new->old_blocks,
1377 new->start_addr,
1378 (fcn_cs_saved.c_value
1379 + fcn_aux_saved.x_sym.x_misc.x_fsize
1380 + ANOFFSET (objfile->section_offsets,
1381 SECT_OFF_TEXT (objfile))),
1382 objfile);
1383 within_function = 0;
1384 }
1385 break;
1386
1387 case C_BSTAT:
1388 /* Begin static block. */
1389 {
1390 struct internal_syment symbol;
1391
1392 read_symbol (&symbol, cs->c_value);
1393 static_block_base = symbol.n_value;
1394 static_block_section =
1395 secnum_to_section (symbol.n_scnum, objfile);
1396 }
1397 break;
1398
1399 case C_ESTAT:
1400 /* End of static block. */
1401 static_block_base = 0;
1402 static_block_section = -1;
1403 break;
1404
1405 case C_ARG:
1406 case C_REGPARM:
1407 case C_REG:
1408 case C_TPDEF:
1409 case C_STRTAG:
1410 case C_UNTAG:
1411 case C_ENTAG:
1412 {
1413 complaint (&symfile_complaints,
1414 _("Unrecognized storage class %d."),
1415 cs->c_sclass);
1416 }
1417 break;
1418
1419 case C_LABEL:
1420 case C_NULL:
1421 /* Ignore these. */
1422 break;
1423
1424 case C_HIDEXT:
1425 case C_STAT:
1426 break;
1427
1428 case C_BINCL:
1429 /* beginning of include file */
1430 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1431 order. Thus, when wee see them, we might not know enough info
1432 to process them. Thus, we'll be saving them into a table
1433 (inclTable) and postpone their processing. */
1434
1435 record_include_begin (cs);
1436 break;
1437
1438 case C_EINCL:
1439 /* End of include file. */
1440 /* See the comment after case C_BINCL. */
1441 record_include_end (cs);
1442 break;
1443
1444 case C_BLOCK:
1445 if (strcmp (cs->c_name, ".bb") == 0)
1446 {
1447 depth++;
1448 new = push_context (depth,
1449 (cs->c_value
1450 + ANOFFSET (objfile->section_offsets,
1451 SECT_OFF_TEXT (objfile))));
1452 }
1453 else if (strcmp (cs->c_name, ".eb") == 0)
1454 {
1455 if (context_stack_depth <= 0)
1456 { /* We attempted to pop an empty context stack. */
1457 eb_complaint (cs->c_symnum);
1458 break;
1459 }
1460 new = pop_context ();
1461 if (depth-- != new->depth)
1462 {
1463 eb_complaint (cs->c_symnum);
1464 break;
1465 }
1466 if (local_symbols && context_stack_depth > 0)
1467 {
1468 /* Make a block for the local symbols within. */
1469 finish_block (new->name, &local_symbols, new->old_blocks,
1470 new->start_addr,
1471 (cs->c_value
1472 + ANOFFSET (objfile->section_offsets,
1473 SECT_OFF_TEXT (objfile))),
1474 objfile);
1475 }
1476 local_symbols = new->locals;
1477 }
1478 break;
1479
1480 default:
1481 process_xcoff_symbol (cs, objfile);
1482 break;
1483 }
1484 }
1485
1486 if (last_source_file)
1487 {
1488 struct symtab *s;
1489
1490 complete_symtab (filestring, file_start_addr);
1491 cur_src_end_addr = file_end_addr;
1492 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1493 /* When reading symbols for the last C_FILE of the objfile, try
1494 to make sure that we set pst->symtab to the symtab for the
1495 file, not to the _globals_ symtab. I'm not sure whether this
1496 actually works right or when/if it comes up. */
1497 if (pst->symtab == NULL)
1498 pst->symtab = s;
1499 end_stabs ();
1500 }
1501 }
1502
1503 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1504 (SYMBOL2) = (struct symbol *) \
1505 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1506 *(SYMBOL2) = *(SYMBOL1);
1507
1508
1509 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1510 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), \
1511 &objfile->objfile_obstack))
1512
1513
1514 /* process one xcoff symbol. */
1515
1516 static struct symbol *
1517 process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
1518 {
1519 struct symbol onesymbol;
1520 struct symbol *sym = &onesymbol;
1521 struct symbol *sym2 = NULL;
1522 char *name, *pp;
1523
1524 int sec;
1525 CORE_ADDR off;
1526
1527 if (cs->c_secnum < 0)
1528 {
1529 /* The value is a register number, offset within a frame, etc.,
1530 and does not get relocated. */
1531 off = 0;
1532 sec = -1;
1533 }
1534 else
1535 {
1536 sec = secnum_to_section (cs->c_secnum, objfile);
1537 off = ANOFFSET (objfile->section_offsets, sec);
1538 }
1539
1540 name = cs->c_name;
1541 if (name[0] == '.')
1542 ++name;
1543
1544 memset (sym, '\0', sizeof (struct symbol));
1545
1546 /* default assumptions */
1547 SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off;
1548 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1549 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1550
1551 if (ISFCN (cs->c_type))
1552 {
1553 /* At this point, we don't know the type of the function. This
1554 will be patched with the type from its stab entry later on in
1555 patch_block_stabs (), unless the file was compiled without -g. */
1556
1557 SYMBOL_SET_LINKAGE_NAME (sym, SYMNAME_ALLOC (name, symname_alloced));
1558 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_text_symbol;
1559
1560 SYMBOL_CLASS (sym) = LOC_BLOCK;
1561 SYMBOL_DUP (sym, sym2);
1562
1563 if (cs->c_sclass == C_EXT)
1564 add_symbol_to_list (sym2, &global_symbols);
1565 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1566 add_symbol_to_list (sym2, &file_symbols);
1567 }
1568 else
1569 {
1570 /* In case we can't figure out the type, provide default. */
1571 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_data_symbol;
1572
1573 switch (cs->c_sclass)
1574 {
1575 #if 0
1576 /* The values of functions and global symbols are now resolved
1577 via the global_sym_chain in stabsread.c. */
1578 case C_FUN:
1579 if (fcn_cs_saved.c_sclass == C_EXT)
1580 add_stab_to_list (name, &global_stabs);
1581 else
1582 add_stab_to_list (name, &file_stabs);
1583 break;
1584
1585 case C_GSYM:
1586 add_stab_to_list (name, &global_stabs);
1587 break;
1588 #endif
1589
1590 case C_BCOMM:
1591 common_block_start (cs->c_name, objfile);
1592 break;
1593
1594 case C_ECOMM:
1595 common_block_end (objfile);
1596 break;
1597
1598 default:
1599 complaint (&symfile_complaints, _("Unexpected storage class: %d"),
1600 cs->c_sclass);
1601 /* FALLTHROUGH */
1602
1603 case C_DECL:
1604 case C_PSYM:
1605 case C_RPSYM:
1606 case C_ECOML:
1607 case C_LSYM:
1608 case C_RSYM:
1609 case C_GSYM:
1610
1611 {
1612 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1613 if (sym != NULL)
1614 {
1615 SYMBOL_SECTION (sym) = sec;
1616 }
1617 return sym;
1618 }
1619
1620 case C_STSYM:
1621
1622 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1623 all statics and we need to distinguish file-scope versus
1624 function-scope using within_function. We do this by
1625 changing the string we pass to define_symbol to use 'S'
1626 where we need to, which is not necessarily super-clean,
1627 but seems workable enough. */
1628
1629 if (*name == ':')
1630 return NULL;
1631
1632 pp = strchr (name, ':');
1633 if (pp == NULL)
1634 return NULL;
1635
1636 ++pp;
1637 if (*pp == 'V' && !within_function)
1638 *pp = 'S';
1639 sym = define_symbol ((cs->c_value
1640 + ANOFFSET (objfile->section_offsets,
1641 static_block_section)),
1642 cs->c_name, 0, 0, objfile);
1643 if (sym != NULL)
1644 {
1645 SYMBOL_VALUE_ADDRESS (sym) += static_block_base;
1646 SYMBOL_SECTION (sym) = static_block_section;
1647 }
1648 return sym;
1649
1650 }
1651 }
1652 return sym2;
1653 }
1654
1655 /* Extract the file name from the aux entry of a C_FILE symbol.
1656 Result is in static storage and is only good for temporary use. */
1657
1658 static char *
1659 coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile)
1660 {
1661 static char buffer[BUFSIZ];
1662
1663 if (aux_entry->x_file.x_n.x_zeroes == 0)
1664 strcpy (buffer, ((struct coff_symfile_info *)
1665 objfile->deprecated_sym_private)->strtbl
1666 + aux_entry->x_file.x_n.x_offset);
1667 else
1668 {
1669 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1670 buffer[FILNMLEN] = '\0';
1671 }
1672 return (buffer);
1673 }
1674
1675 /* Set *SYMBOL to symbol number symno in symtbl. */
1676 static void
1677 read_symbol (struct internal_syment *symbol, int symno)
1678 {
1679 int nsyms
1680 = ((struct coff_symfile_info *)
1681 this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl_num_syms;
1682 char *stbl = ((struct coff_symfile_info *)
1683 this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl;
1684
1685 if (symno < 0 || symno >= nsyms)
1686 {
1687 complaint (&symfile_complaints, _("Invalid symbol offset"));
1688 symbol->n_value = 0;
1689 symbol->n_scnum = -1;
1690 return;
1691 }
1692 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1693 stbl + (symno * local_symesz),
1694 symbol);
1695 }
1696
1697 /* Get value corresponding to symbol number symno in symtbl. */
1698
1699 static CORE_ADDR
1700 read_symbol_nvalue (int symno)
1701 {
1702 struct internal_syment symbol[1];
1703
1704 read_symbol (symbol, symno);
1705 return symbol->n_value;
1706 }
1707
1708
1709 /* Find the address of the function corresponding to symno, where
1710 symno is the symbol pointed to by the linetable. */
1711
1712 static int
1713 read_symbol_lineno (int symno)
1714 {
1715 struct objfile *objfile = this_symtab_psymtab->objfile;
1716 int xcoff64 = bfd_xcoff_is_xcoff64 (objfile->obfd);
1717
1718 struct coff_symfile_info *info =
1719 (struct coff_symfile_info *)objfile->deprecated_sym_private;
1720 int nsyms = info->symtbl_num_syms;
1721 char *stbl = info->symtbl;
1722 char *strtbl = info->strtbl;
1723
1724 struct internal_syment symbol[1];
1725 union internal_auxent main_aux[1];
1726
1727 if (symno < 0)
1728 {
1729 bf_notfound_complaint ();
1730 return 0;
1731 }
1732
1733 /* Note that just searching for a short distance (e.g. 50 symbols)
1734 is not enough, at least in the following case.
1735
1736 .extern foo
1737 [many .stabx entries]
1738 [a few functions, referring to foo]
1739 .globl foo
1740 .bf
1741
1742 What happens here is that the assembler moves the .stabx entries
1743 to right before the ".bf" for foo, but the symbol for "foo" is before
1744 all the stabx entries. See PR gdb/2222. */
1745
1746 /* Maintaining a table of .bf entries might be preferable to this search.
1747 If I understand things correctly it would need to be done only for
1748 the duration of a single psymtab to symtab conversion. */
1749 while (symno < nsyms)
1750 {
1751 bfd_coff_swap_sym_in (symfile_bfd,
1752 stbl + (symno * local_symesz), symbol);
1753 if (symbol->n_sclass == C_FCN)
1754 {
1755 char *name = xcoff64 ? strtbl + symbol->n_offset : symbol->n_name;
1756
1757 if (strcmp (name, ".bf") == 0)
1758 goto gotit;
1759 }
1760 symno += symbol->n_numaux + 1;
1761 }
1762
1763 bf_notfound_complaint ();
1764 return 0;
1765
1766 gotit:
1767 /* Take aux entry and return its lineno. */
1768 symno++;
1769 bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz,
1770 symbol->n_type, symbol->n_sclass,
1771 0, symbol->n_numaux, main_aux);
1772
1773 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1774 }
1775
1776 /* Support for line number handling. */
1777
1778 /* This function is called for every section; it finds the outer limits
1779 * of the line table (minimum and maximum file offset) so that the
1780 * mainline code can read the whole thing for efficiency.
1781 */
1782 static void
1783 find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo)
1784 {
1785 struct coff_symfile_info *info;
1786 int size, count;
1787 file_ptr offset, maxoff;
1788
1789 count = asect->lineno_count;
1790
1791 if (strcmp (asect->name, ".text") != 0 || count == 0)
1792 return;
1793
1794 size = count * coff_data (abfd)->local_linesz;
1795 info = (struct coff_symfile_info *) vpinfo;
1796 offset = asect->line_filepos;
1797 maxoff = offset + size;
1798
1799 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1800 info->min_lineno_offset = offset;
1801
1802 if (maxoff > info->max_lineno_offset)
1803 info->max_lineno_offset = maxoff;
1804 }
1805 \f
1806 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab *);
1807
1808 static void
1809 xcoff_psymtab_to_symtab_1 (struct partial_symtab *pst)
1810 {
1811 struct cleanup *old_chain;
1812 int i;
1813
1814 if (!pst)
1815 return;
1816
1817 if (pst->readin)
1818 {
1819 fprintf_unfiltered
1820 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1821 pst->filename);
1822 return;
1823 }
1824
1825 /* Read in all partial symtabs on which this one is dependent. */
1826 for (i = 0; i < pst->number_of_dependencies; i++)
1827 if (!pst->dependencies[i]->readin)
1828 {
1829 /* Inform about additional files that need to be read in. */
1830 if (info_verbose)
1831 {
1832 fputs_filtered (" ", gdb_stdout);
1833 wrap_here ("");
1834 fputs_filtered ("and ", gdb_stdout);
1835 wrap_here ("");
1836 printf_filtered ("%s...", pst->dependencies[i]->filename);
1837 wrap_here (""); /* Flush output */
1838 gdb_flush (gdb_stdout);
1839 }
1840 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1841 }
1842
1843 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
1844 {
1845 /* Init stuff necessary for reading in symbols. */
1846 stabsread_init ();
1847 buildsym_init ();
1848 old_chain = make_cleanup (really_free_pendings, 0);
1849
1850 read_xcoff_symtab (pst);
1851
1852 do_cleanups (old_chain);
1853 }
1854
1855 pst->readin = 1;
1856 }
1857
1858 static void xcoff_psymtab_to_symtab (struct partial_symtab *);
1859
1860 /* Read in all of the symbols for a given psymtab for real.
1861 Be verbose about it if the user wants that. */
1862
1863 static void
1864 xcoff_psymtab_to_symtab (struct partial_symtab *pst)
1865 {
1866 bfd *sym_bfd;
1867
1868 if (!pst)
1869 return;
1870
1871 if (pst->readin)
1872 {
1873 fprintf_unfiltered
1874 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1875 pst->filename);
1876 return;
1877 }
1878
1879 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0
1880 || pst->number_of_dependencies)
1881 {
1882 /* Print the message now, before reading the string table,
1883 to avoid disconcerting pauses. */
1884 if (info_verbose)
1885 {
1886 printf_filtered ("Reading in symbols for %s...", pst->filename);
1887 gdb_flush (gdb_stdout);
1888 }
1889
1890 sym_bfd = pst->objfile->obfd;
1891
1892 next_symbol_text_func = xcoff_next_symbol_text;
1893
1894 xcoff_psymtab_to_symtab_1 (pst);
1895
1896 /* Match with global symbols. This only needs to be done once,
1897 after all of the symtabs and dependencies have been read in. */
1898 scan_file_globals (pst->objfile);
1899
1900 /* Finish up the debug error message. */
1901 if (info_verbose)
1902 printf_filtered ("done.\n");
1903 }
1904 }
1905 \f
1906 static void
1907 xcoff_new_init (struct objfile *objfile)
1908 {
1909 stabsread_new_init ();
1910 buildsym_new_init ();
1911 }
1912
1913 /* Do initialization in preparation for reading symbols from OBJFILE.
1914
1915 We will only be called if this is an XCOFF or XCOFF-like file.
1916 BFD handles figuring out the format of the file, and code in symfile.c
1917 uses BFD's determination to vector to us. */
1918
1919 static void
1920 xcoff_symfile_init (struct objfile *objfile)
1921 {
1922 /* Allocate struct to keep track of the symfile. */
1923 objfile->deprecated_sym_private
1924 = xmalloc (sizeof (struct coff_symfile_info));
1925
1926 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1927 find this causes a significant slowdown in gdb then we could
1928 set it in the debug symbol readers only when necessary. */
1929 objfile->flags |= OBJF_REORDERED;
1930
1931 init_entry_point_info (objfile);
1932 }
1933
1934 /* Perform any local cleanups required when we are done with a particular
1935 objfile. I.E, we are in the process of discarding all symbol information
1936 for an objfile, freeing up all memory held for it, and unlinking the
1937 objfile struct from the global list of known objfiles. */
1938
1939 static void
1940 xcoff_symfile_finish (struct objfile *objfile)
1941 {
1942 if (objfile->deprecated_sym_private != NULL)
1943 {
1944 xfree (objfile->deprecated_sym_private);
1945 }
1946
1947 /* Start with a fresh include table for the next objfile. */
1948 if (inclTable)
1949 {
1950 xfree (inclTable);
1951 inclTable = NULL;
1952 }
1953 inclIndx = inclLength = inclDepth = 0;
1954
1955 dwarf2_free_objfile (objfile);
1956 }
1957
1958
1959 static void
1960 init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile)
1961 {
1962 long length;
1963 int val;
1964 unsigned char lengthbuf[4];
1965 char *strtbl;
1966
1967 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
1968 = NULL;
1969
1970 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1971 error (_("cannot seek to string table in %s: %s"),
1972 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1973
1974 val = bfd_bread ((char *) lengthbuf, sizeof lengthbuf, abfd);
1975 length = bfd_h_get_32 (abfd, lengthbuf);
1976
1977 /* If no string table is needed, then the file may end immediately
1978 after the symbols. Just return with `strtbl' set to NULL. */
1979
1980 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1981 return;
1982
1983 /* Allocate string table from objfile_obstack. We will need this table
1984 as long as we have its symbol table around. */
1985
1986 strtbl = (char *) obstack_alloc (&objfile->objfile_obstack, length);
1987 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
1988 = strtbl;
1989
1990 /* Copy length buffer, the first byte is usually zero and is
1991 used for stabs with a name length of zero. */
1992 memcpy (strtbl, lengthbuf, sizeof lengthbuf);
1993 if (length == sizeof lengthbuf)
1994 return;
1995
1996 val = bfd_bread (strtbl + sizeof lengthbuf, length - sizeof lengthbuf, abfd);
1997
1998 if (val != length - sizeof lengthbuf)
1999 error (_("cannot read string table from %s: %s"),
2000 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
2001 if (strtbl[length - 1] != '\0')
2002 error (_("bad symbol file: string table "
2003 "does not end with null character"));
2004
2005 return;
2006 }
2007 \f
2008 /* If we have not yet seen a function for this psymtab, this is 0. If we
2009 have seen one, it is the offset in the line numbers of the line numbers
2010 for the psymtab. */
2011 static unsigned int first_fun_line_offset;
2012
2013 /* Allocate and partially fill a partial symtab. It will be
2014 completely filled at the end of the symbol list.
2015
2016 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2017 is the address relative to which its symbols are (incremental) or 0
2018 (normal). */
2019
2020 static struct partial_symtab *
2021 xcoff_start_psymtab (struct objfile *objfile,
2022 const char *filename, int first_symnum,
2023 struct partial_symbol **global_syms,
2024 struct partial_symbol **static_syms)
2025 {
2026 struct partial_symtab *result =
2027 start_psymtab_common (objfile, objfile->section_offsets,
2028 filename,
2029 /* We fill in textlow later. */
2030 0,
2031 global_syms, static_syms);
2032
2033 result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2034 sizeof (struct symloc));
2035 ((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum;
2036 result->read_symtab = xcoff_psymtab_to_symtab;
2037
2038 /* Deduce the source language from the filename for this psymtab. */
2039 psymtab_language = deduce_language_from_filename (filename);
2040
2041 return result;
2042 }
2043
2044 /* Close off the current usage of PST.
2045 Returns PST, or NULL if the partial symtab was empty and thrown away.
2046
2047 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2048
2049 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2050 are the information for includes and dependencies. */
2051
2052 static struct partial_symtab *
2053 xcoff_end_psymtab (struct partial_symtab *pst, const char **include_list,
2054 int num_includes, int capping_symbol_number,
2055 struct partial_symtab **dependency_list,
2056 int number_dependencies, int textlow_not_set)
2057 {
2058 int i;
2059 struct objfile *objfile = pst->objfile;
2060
2061 if (capping_symbol_number != -1)
2062 ((struct symloc *) pst->read_symtab_private)->numsyms =
2063 capping_symbol_number
2064 - ((struct symloc *) pst->read_symtab_private)->first_symnum;
2065 ((struct symloc *) pst->read_symtab_private)->lineno_off =
2066 first_fun_line_offset;
2067 first_fun_line_offset = 0;
2068 pst->n_global_syms = objfile->global_psymbols.next
2069 - (objfile->global_psymbols.list + pst->globals_offset);
2070 pst->n_static_syms = objfile->static_psymbols.next
2071 - (objfile->static_psymbols.list + pst->statics_offset);
2072
2073 pst->number_of_dependencies = number_dependencies;
2074 if (number_dependencies)
2075 {
2076 pst->dependencies = (struct partial_symtab **)
2077 obstack_alloc (&objfile->objfile_obstack,
2078 number_dependencies * sizeof (struct partial_symtab *));
2079 memcpy (pst->dependencies, dependency_list,
2080 number_dependencies * sizeof (struct partial_symtab *));
2081 }
2082 else
2083 pst->dependencies = 0;
2084
2085 for (i = 0; i < num_includes; i++)
2086 {
2087 struct partial_symtab *subpst =
2088 allocate_psymtab (include_list[i], objfile);
2089
2090 subpst->section_offsets = pst->section_offsets;
2091 subpst->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2092 sizeof (struct symloc));
2093 ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
2094 ((struct symloc *) subpst->read_symtab_private)->numsyms = 0;
2095 subpst->textlow = 0;
2096 subpst->texthigh = 0;
2097
2098 /* We could save slight bits of space by only making one of these,
2099 shared by the entire set of include files. FIXME-someday. */
2100 subpst->dependencies = (struct partial_symtab **)
2101 obstack_alloc (&objfile->objfile_obstack,
2102 sizeof (struct partial_symtab *));
2103 subpst->dependencies[0] = pst;
2104 subpst->number_of_dependencies = 1;
2105
2106 subpst->globals_offset =
2107 subpst->n_global_syms =
2108 subpst->statics_offset =
2109 subpst->n_static_syms = 0;
2110
2111 subpst->readin = 0;
2112 subpst->symtab = 0;
2113 subpst->read_symtab = pst->read_symtab;
2114 }
2115
2116 sort_pst_symbols (pst);
2117
2118 if (num_includes == 0
2119 && number_dependencies == 0
2120 && pst->n_global_syms == 0
2121 && pst->n_static_syms == 0)
2122 {
2123 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2124 it is on the obstack, but we can forget to chain it on the list. */
2125 /* Empty psymtabs happen as a result of header files which don't have
2126 any symbols in them. There can be a lot of them. */
2127
2128 discard_psymtab (pst);
2129
2130 /* Indicate that psymtab was thrown away. */
2131 pst = (struct partial_symtab *) NULL;
2132 }
2133 return pst;
2134 }
2135
2136 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2137 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2138 the symbol and its auxents. */
2139
2140 static void
2141 swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
2142 const char **name, char **raw, unsigned int *symnump,
2143 struct objfile *objfile)
2144 {
2145 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2146 if (symbol->n_zeroes)
2147 {
2148 /* If it's exactly E_SYMNMLEN characters long it isn't
2149 '\0'-terminated. */
2150 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2151 {
2152 /* FIXME: wastes memory for symbols which we don't end up putting
2153 into the minimal symbols. */
2154 char *p;
2155
2156 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
2157 strncpy (p, symbol->n_name, E_SYMNMLEN);
2158 p[E_SYMNMLEN] = '\0';
2159 *name = p;
2160 }
2161 else
2162 /* Point to the unswapped name as that persists as long as the
2163 objfile does. */
2164 *name = ((struct external_syment *) *raw)->e.e_name;
2165 }
2166 else if (symbol->n_sclass & 0x80)
2167 {
2168 *name = ((struct coff_symfile_info *)
2169 objfile->deprecated_sym_private)->debugsec + symbol->n_offset;
2170 }
2171 else
2172 {
2173 *name = ((struct coff_symfile_info *)
2174 objfile->deprecated_sym_private)->strtbl + symbol->n_offset;
2175 }
2176 ++*symnump;
2177 *raw += coff_data (objfile->obfd)->local_symesz;
2178 if (symbol->n_numaux > 0)
2179 {
2180 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2181 symbol->n_sclass, 0, symbol->n_numaux, aux);
2182
2183 *symnump += symbol->n_numaux;
2184 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2185 }
2186 }
2187
2188 static void
2189 function_outside_compilation_unit_complaint (const char *arg1)
2190 {
2191 complaint (&symfile_complaints,
2192 _("function `%s' appears to be defined "
2193 "outside of all compilation units"),
2194 arg1);
2195 }
2196
2197 static void
2198 scan_xcoff_symtab (struct objfile *objfile)
2199 {
2200 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2201 CORE_ADDR toc_offset = 0; /* toc offset value in data section. */
2202 const char *filestring = NULL;
2203
2204 const char *namestring;
2205 int past_first_source_file = 0;
2206 bfd *abfd;
2207 asection *bfd_sect;
2208 unsigned int nsyms;
2209
2210 /* Current partial symtab */
2211 struct partial_symtab *pst;
2212
2213 /* List of current psymtab's include files. */
2214 const char **psymtab_include_list;
2215 int includes_allocated;
2216 int includes_used;
2217
2218 /* Index within current psymtab dependency list. */
2219 struct partial_symtab **dependency_list;
2220 int dependencies_used, dependencies_allocated;
2221
2222 char *sraw_symbol;
2223 struct internal_syment symbol;
2224 union internal_auxent main_aux[5];
2225 unsigned int ssymnum;
2226
2227 const char *last_csect_name = NULL; /* Last seen csect's name and value. */
2228 CORE_ADDR last_csect_val = 0;
2229 int last_csect_sec = 0;
2230 int misc_func_recorded = 0; /* true if any misc. function. */
2231 int textlow_not_set = 1;
2232
2233 pst = (struct partial_symtab *) 0;
2234
2235 includes_allocated = 30;
2236 includes_used = 0;
2237 psymtab_include_list = (const char **) alloca (includes_allocated *
2238 sizeof (const char *));
2239
2240 dependencies_allocated = 30;
2241 dependencies_used = 0;
2242 dependency_list =
2243 (struct partial_symtab **) alloca (dependencies_allocated *
2244 sizeof (struct partial_symtab *));
2245
2246 last_source_file = NULL;
2247
2248 abfd = objfile->obfd;
2249 next_symbol_text_func = xcoff_next_symbol_text;
2250
2251 sraw_symbol = ((struct coff_symfile_info *)
2252 objfile->deprecated_sym_private)->symtbl;
2253 nsyms = ((struct coff_symfile_info *)
2254 objfile->deprecated_sym_private)->symtbl_num_syms;
2255 ssymnum = 0;
2256 while (ssymnum < nsyms)
2257 {
2258 int sclass;
2259
2260 QUIT;
2261
2262 bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol);
2263 sclass = symbol.n_sclass;
2264
2265 switch (sclass)
2266 {
2267 case C_EXT:
2268 case C_HIDEXT:
2269 {
2270 /* The CSECT auxent--always the last auxent. */
2271 union internal_auxent csect_aux;
2272 unsigned int symnum_before = ssymnum;
2273
2274 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2275 &ssymnum, objfile);
2276 if (symbol.n_numaux > 1)
2277 {
2278 bfd_coff_swap_aux_in
2279 (objfile->obfd,
2280 sraw_symbol - coff_data (abfd)->local_symesz,
2281 symbol.n_type,
2282 symbol.n_sclass,
2283 symbol.n_numaux - 1,
2284 symbol.n_numaux,
2285 &csect_aux);
2286 }
2287 else
2288 csect_aux = main_aux[0];
2289
2290 /* If symbol name starts with ".$" or "$", ignore it. */
2291 if (namestring[0] == '$'
2292 || (namestring[0] == '.' && namestring[1] == '$'))
2293 break;
2294
2295 switch (csect_aux.x_csect.x_smtyp & 0x7)
2296 {
2297 case XTY_SD:
2298 switch (csect_aux.x_csect.x_smclas)
2299 {
2300 case XMC_PR:
2301 if (last_csect_name)
2302 {
2303 /* If no misc. function recorded in the last
2304 seen csect, enter it as a function. This
2305 will take care of functions like strcmp()
2306 compiled by xlc. */
2307
2308 if (!misc_func_recorded)
2309 {
2310 record_minimal_symbol
2311 (last_csect_name, last_csect_val,
2312 mst_text, last_csect_sec, objfile);
2313 misc_func_recorded = 1;
2314 }
2315
2316 if (pst != NULL)
2317 {
2318 /* We have to allocate one psymtab for
2319 each program csect, because their text
2320 sections need not be adjacent. */
2321 xcoff_end_psymtab
2322 (pst, psymtab_include_list, includes_used,
2323 symnum_before, dependency_list,
2324 dependencies_used, textlow_not_set);
2325 includes_used = 0;
2326 dependencies_used = 0;
2327 /* Give all psymtabs for this source file the same
2328 name. */
2329 pst = xcoff_start_psymtab
2330 (objfile,
2331 filestring,
2332 symnum_before,
2333 objfile->global_psymbols.next,
2334 objfile->static_psymbols.next);
2335 }
2336 }
2337 /* Activate the misc_func_recorded mechanism for
2338 compiler- and linker-generated CSECTs like ".strcmp"
2339 and "@FIX1". */
2340 if (namestring && (namestring[0] == '.'
2341 || namestring[0] == '@'))
2342 {
2343 last_csect_name = namestring;
2344 last_csect_val = symbol.n_value;
2345 last_csect_sec = symbol.n_scnum;
2346 }
2347 if (pst != NULL)
2348 {
2349 CORE_ADDR highval =
2350 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2351
2352 if (highval > pst->texthigh)
2353 pst->texthigh = highval;
2354 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2355 pst->textlow = symbol.n_value;
2356 }
2357 misc_func_recorded = 0;
2358 break;
2359
2360 case XMC_RW:
2361 case XMC_TD:
2362 /* Data variables are recorded in the minimal symbol
2363 table, except for section symbols. */
2364 if (*namestring != '.')
2365 prim_record_minimal_symbol_and_info
2366 (namestring, symbol.n_value,
2367 sclass == C_HIDEXT ? mst_file_data : mst_data,
2368 secnum_to_section (symbol.n_scnum, objfile),
2369 secnum_to_bfd_section (symbol.n_scnum, objfile),
2370 objfile);
2371 break;
2372
2373 case XMC_TC0:
2374 if (toc_offset)
2375 warning (_("More than one XMC_TC0 symbol found."));
2376 toc_offset = symbol.n_value;
2377
2378 /* Make TOC offset relative to start address of
2379 section. */
2380 bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile);
2381 if (bfd_sect)
2382 toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect);
2383 break;
2384
2385 case XMC_TC:
2386 /* These symbols tell us where the TOC entry for a
2387 variable is, not the variable itself. */
2388 break;
2389
2390 default:
2391 break;
2392 }
2393 break;
2394
2395 case XTY_LD:
2396 switch (csect_aux.x_csect.x_smclas)
2397 {
2398 case XMC_PR:
2399 /* A function entry point. */
2400
2401 if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
2402 first_fun_line_offset =
2403 main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr;
2404 {
2405 record_minimal_symbol
2406 (namestring, symbol.n_value,
2407 sclass == C_HIDEXT ? mst_file_text : mst_text,
2408 symbol.n_scnum, objfile);
2409 misc_func_recorded = 1;
2410 }
2411 break;
2412
2413 case XMC_GL:
2414 /* shared library function trampoline code entry
2415 point. */
2416
2417 /* record trampoline code entries as
2418 mst_solib_trampoline symbol. When we lookup mst
2419 symbols, we will choose mst_text over
2420 mst_solib_trampoline. */
2421 record_minimal_symbol
2422 (namestring, symbol.n_value,
2423 mst_solib_trampoline, symbol.n_scnum, objfile);
2424 misc_func_recorded = 1;
2425 break;
2426
2427 case XMC_DS:
2428 /* The symbols often have the same names as
2429 debug symbols for functions, and confuse
2430 lookup_symbol. */
2431 break;
2432
2433 default:
2434
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 secnum_to_section (symbol.n_scnum, objfile),
2447 secnum_to_bfd_section (symbol.n_scnum, objfile),
2448 objfile);
2449 break;
2450 }
2451 break;
2452
2453 case XTY_CM:
2454 switch (csect_aux.x_csect.x_smclas)
2455 {
2456 case XMC_RW:
2457 case XMC_BS:
2458 /* Common variables are recorded in the minimal symbol
2459 table, except for section symbols. */
2460 if (*namestring != '.')
2461 prim_record_minimal_symbol_and_info
2462 (namestring, symbol.n_value,
2463 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
2464 secnum_to_section (symbol.n_scnum, objfile),
2465 secnum_to_bfd_section (symbol.n_scnum, objfile),
2466 objfile);
2467 break;
2468 }
2469 break;
2470
2471 default:
2472 break;
2473 }
2474 }
2475 break;
2476 case C_FILE:
2477 {
2478 unsigned int symnum_before;
2479
2480 symnum_before = ssymnum;
2481 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2482 &ssymnum, objfile);
2483
2484 /* See if the last csect needs to be recorded. */
2485
2486 if (last_csect_name && !misc_func_recorded)
2487 {
2488 /* If no misc. function recorded in the last seen csect, enter
2489 it as a function. This will take care of functions like
2490 strcmp() compiled by xlc. */
2491
2492 record_minimal_symbol (last_csect_name, last_csect_val,
2493 mst_text, last_csect_sec, objfile);
2494 misc_func_recorded = 1;
2495 }
2496
2497 if (pst)
2498 {
2499 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2500 symnum_before, dependency_list,
2501 dependencies_used, textlow_not_set);
2502 includes_used = 0;
2503 dependencies_used = 0;
2504 }
2505 first_fun_line_offset = 0;
2506
2507 /* XCOFF, according to the AIX 3.2 documentation, puts the
2508 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2509 do things the standard COFF way and put it in the auxent.
2510 We use the auxent if the symbol is ".file" and an auxent
2511 exists, otherwise use the symbol itself. */
2512 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2513 {
2514 filestring = coff_getfilename (&main_aux[0], objfile);
2515 }
2516 else
2517 filestring = namestring;
2518
2519 pst = xcoff_start_psymtab (objfile,
2520 filestring,
2521 symnum_before,
2522 objfile->global_psymbols.next,
2523 objfile->static_psymbols.next);
2524 last_csect_name = NULL;
2525 }
2526 break;
2527
2528 default:
2529 {
2530 complaint (&symfile_complaints,
2531 _("Storage class %d not recognized during scan"),
2532 sclass);
2533 }
2534 /* FALLTHROUGH */
2535
2536 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2537 to handle only the C_FUN and C_EXT. */
2538 case C_FCN:
2539
2540 case C_BSTAT:
2541 case C_ESTAT:
2542 case C_ARG:
2543 case C_REGPARM:
2544 case C_REG:
2545 case C_TPDEF:
2546 case C_STRTAG:
2547 case C_UNTAG:
2548 case C_ENTAG:
2549 case C_LABEL:
2550 case C_NULL:
2551
2552 /* C_EINCL means we are switching back to the main file. But there
2553 is no reason to care; the only thing we want to know about
2554 includes is the names of all the included (.h) files. */
2555 case C_EINCL:
2556
2557 case C_BLOCK:
2558
2559 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2560 used instead. */
2561 case C_STAT:
2562
2563 /* I don't think the name of the common block (as opposed to the
2564 variables within it) is something which is user visible
2565 currently. */
2566 case C_BCOMM:
2567 case C_ECOMM:
2568
2569 case C_PSYM:
2570 case C_RPSYM:
2571
2572 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2573 so C_LSYM would appear to be only for locals. */
2574 case C_LSYM:
2575
2576 case C_AUTO:
2577 case C_RSYM:
2578 {
2579 /* We probably could save a few instructions by assuming that
2580 C_LSYM, C_PSYM, etc., never have auxents. */
2581 int naux1 = symbol.n_numaux + 1;
2582
2583 ssymnum += naux1;
2584 sraw_symbol += bfd_coff_symesz (abfd) * naux1;
2585 }
2586 break;
2587
2588 case C_BINCL:
2589 {
2590 /* Mark down an include file in the current psymtab. */
2591 enum language tmp_language;
2592
2593 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2594 &ssymnum, objfile);
2595
2596 tmp_language = deduce_language_from_filename (namestring);
2597
2598 /* Only change the psymtab's language if we've learned
2599 something useful (eg. tmp_language is not language_unknown).
2600 In addition, to match what start_subfile does, never change
2601 from C++ to C. */
2602 if (tmp_language != language_unknown
2603 && (tmp_language != language_c
2604 || psymtab_language != language_cplus))
2605 psymtab_language = tmp_language;
2606
2607 /* In C++, one may expect the same filename to come round many
2608 times, when code is coming alternately from the main file
2609 and from inline functions in other files. So I check to see
2610 if this is a file we've seen before -- either the main
2611 source file, or a previously included file.
2612
2613 This seems to be a lot of time to be spending on N_SOL, but
2614 things like "break c-exp.y:435" need to work (I
2615 suppose the psymtab_include_list could be hashed or put
2616 in a binary tree, if profiling shows this is a major hog). */
2617 if (pst && strcmp (namestring, pst->filename) == 0)
2618 continue;
2619
2620 {
2621 int i;
2622
2623 for (i = 0; i < includes_used; i++)
2624 if (strcmp (namestring, psymtab_include_list[i]) == 0)
2625 {
2626 i = -1;
2627 break;
2628 }
2629 if (i == -1)
2630 continue;
2631 }
2632 psymtab_include_list[includes_used++] = namestring;
2633 if (includes_used >= includes_allocated)
2634 {
2635 const char **orig = psymtab_include_list;
2636
2637 psymtab_include_list = (const char **)
2638 alloca ((includes_allocated *= 2) *
2639 sizeof (const char *));
2640 memcpy (psymtab_include_list, orig,
2641 includes_used * sizeof (const char *));
2642 }
2643 continue;
2644 }
2645 case C_FUN:
2646 /* The value of the C_FUN is not the address of the function (it
2647 appears to be the address before linking), but as long as it
2648 is smaller than the actual address, then find_pc_partial_function
2649 will use the minimal symbols instead. I hope. */
2650
2651 case C_GSYM:
2652 case C_ECOML:
2653 case C_DECL:
2654 case C_STSYM:
2655 {
2656 char *p;
2657
2658 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2659 &ssymnum, objfile);
2660
2661 p = strchr (namestring, ':');
2662 if (!p)
2663 continue; /* Not a debugging symbol. */
2664
2665 /* Main processing section for debugging symbols which
2666 the initial read through the symbol tables needs to worry
2667 about. If we reach this point, the symbol which we are
2668 considering is definitely one we are interested in.
2669 p must also contain the (valid) index into the namestring
2670 which indicates the debugging type symbol. */
2671
2672 switch (p[1])
2673 {
2674 case 'S':
2675 symbol.n_value += ANOFFSET (objfile->section_offsets,
2676 SECT_OFF_DATA (objfile));
2677
2678 if (gdbarch_static_transform_name_p (gdbarch))
2679 namestring = gdbarch_static_transform_name
2680 (gdbarch, namestring);
2681
2682 add_psymbol_to_list (namestring, p - namestring, 1,
2683 VAR_DOMAIN, LOC_STATIC,
2684 &objfile->static_psymbols,
2685 0, symbol.n_value,
2686 psymtab_language, objfile);
2687 continue;
2688
2689 case 'G':
2690 symbol.n_value += ANOFFSET (objfile->section_offsets,
2691 SECT_OFF_DATA (objfile));
2692 /* The addresses in these entries are reported to be
2693 wrong. See the code that reads 'G's for symtabs. */
2694 add_psymbol_to_list (namestring, p - namestring, 1,
2695 VAR_DOMAIN, LOC_STATIC,
2696 &objfile->global_psymbols,
2697 0, symbol.n_value,
2698 psymtab_language, objfile);
2699 continue;
2700
2701 case 'T':
2702 /* When a 'T' entry is defining an anonymous enum, it
2703 may have a name which is the empty string, or a
2704 single space. Since they're not really defining a
2705 symbol, those shouldn't go in the partial symbol
2706 table. We do pick up the elements of such enums at
2707 'check_enum:', below. */
2708 if (p >= namestring + 2
2709 || (p == namestring + 1
2710 && namestring[0] != ' '))
2711 {
2712 add_psymbol_to_list (namestring, p - namestring, 1,
2713 STRUCT_DOMAIN, LOC_TYPEDEF,
2714 &objfile->static_psymbols,
2715 symbol.n_value, 0,
2716 psymtab_language, objfile);
2717 if (p[2] == 't')
2718 {
2719 /* Also a typedef with the same name. */
2720 add_psymbol_to_list (namestring, p - namestring, 1,
2721 VAR_DOMAIN, LOC_TYPEDEF,
2722 &objfile->static_psymbols,
2723 symbol.n_value, 0,
2724 psymtab_language, objfile);
2725 p += 1;
2726 }
2727 }
2728 goto check_enum;
2729
2730 case 't':
2731 if (p != namestring) /* a name is there, not just :T... */
2732 {
2733 add_psymbol_to_list (namestring, p - namestring, 1,
2734 VAR_DOMAIN, LOC_TYPEDEF,
2735 &objfile->static_psymbols,
2736 symbol.n_value, 0,
2737 psymtab_language, objfile);
2738 }
2739 check_enum:
2740 /* If this is an enumerated type, we need to
2741 add all the enum constants to the partial symbol
2742 table. This does not cover enums without names, e.g.
2743 "enum {a, b} c;" in C, but fortunately those are
2744 rare. There is no way for GDB to find those from the
2745 enum type without spending too much time on it. Thus
2746 to solve this problem, the compiler needs to put out the
2747 enum in a nameless type. GCC2 does this. */
2748
2749 /* We are looking for something of the form
2750 <name> ":" ("t" | "T") [<number> "="] "e"
2751 {<constant> ":" <value> ","} ";". */
2752
2753 /* Skip over the colon and the 't' or 'T'. */
2754 p += 2;
2755 /* This type may be given a number. Also, numbers can come
2756 in pairs like (0,26). Skip over it. */
2757 while ((*p >= '0' && *p <= '9')
2758 || *p == '(' || *p == ',' || *p == ')'
2759 || *p == '=')
2760 p++;
2761
2762 if (*p++ == 'e')
2763 {
2764 /* The aix4 compiler emits extra crud before the
2765 members. */
2766 if (*p == '-')
2767 {
2768 /* Skip over the type (?). */
2769 while (*p != ':')
2770 p++;
2771
2772 /* Skip over the colon. */
2773 p++;
2774 }
2775
2776 /* We have found an enumerated type. */
2777 /* According to comments in read_enum_type
2778 a comma could end it instead of a semicolon.
2779 I don't know where that happens.
2780 Accept either. */
2781 while (*p && *p != ';' && *p != ',')
2782 {
2783 char *q;
2784
2785 /* Check for and handle cretinous dbx symbol name
2786 continuation! */
2787 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
2788 p = next_symbol_text (objfile);
2789
2790 /* Point to the character after the name
2791 of the enum constant. */
2792 for (q = p; *q && *q != ':'; q++)
2793 ;
2794 /* Note that the value doesn't matter for
2795 enum constants in psymtabs, just in symtabs. */
2796 add_psymbol_to_list (p, q - p, 1,
2797 VAR_DOMAIN, LOC_CONST,
2798 &objfile->static_psymbols, 0,
2799 0, psymtab_language, objfile);
2800 /* Point past the name. */
2801 p = q;
2802 /* Skip over the value. */
2803 while (*p && *p != ',')
2804 p++;
2805 /* Advance past the comma. */
2806 if (*p)
2807 p++;
2808 }
2809 }
2810 continue;
2811
2812 case 'c':
2813 /* Constant, e.g. from "const" in Pascal. */
2814 add_psymbol_to_list (namestring, p - namestring, 1,
2815 VAR_DOMAIN, LOC_CONST,
2816 &objfile->static_psymbols, symbol.n_value,
2817 0, psymtab_language, objfile);
2818 continue;
2819
2820 case 'f':
2821 if (! pst)
2822 {
2823 int name_len = p - namestring;
2824 char *name = xmalloc (name_len + 1);
2825
2826 memcpy (name, namestring, name_len);
2827 name[name_len] = '\0';
2828 function_outside_compilation_unit_complaint (name);
2829 xfree (name);
2830 }
2831 symbol.n_value += ANOFFSET (objfile->section_offsets,
2832 SECT_OFF_TEXT (objfile));
2833 add_psymbol_to_list (namestring, p - namestring, 1,
2834 VAR_DOMAIN, LOC_BLOCK,
2835 &objfile->static_psymbols,
2836 0, symbol.n_value,
2837 psymtab_language, objfile);
2838 continue;
2839
2840 /* Global functions were ignored here, but now they
2841 are put into the global psymtab like one would expect.
2842 They're also in the minimal symbol table. */
2843 case 'F':
2844 if (! pst)
2845 {
2846 int name_len = p - namestring;
2847 char *name = xmalloc (name_len + 1);
2848
2849 memcpy (name, namestring, name_len);
2850 name[name_len] = '\0';
2851 function_outside_compilation_unit_complaint (name);
2852 xfree (name);
2853 }
2854
2855 /* We need only the minimal symbols for these
2856 loader-generated definitions. Keeping the global
2857 symbols leads to "in psymbols but not in symbols"
2858 errors. */
2859 if (strncmp (namestring, "@FIX", 4) == 0)
2860 continue;
2861
2862 symbol.n_value += ANOFFSET (objfile->section_offsets,
2863 SECT_OFF_TEXT (objfile));
2864 add_psymbol_to_list (namestring, p - namestring, 1,
2865 VAR_DOMAIN, LOC_BLOCK,
2866 &objfile->global_psymbols,
2867 0, symbol.n_value,
2868 psymtab_language, objfile);
2869 continue;
2870
2871 /* Two things show up here (hopefully); static symbols of
2872 local scope (static used inside braces) or extensions
2873 of structure symbols. We can ignore both. */
2874 case 'V':
2875 case '(':
2876 case '0':
2877 case '1':
2878 case '2':
2879 case '3':
2880 case '4':
2881 case '5':
2882 case '6':
2883 case '7':
2884 case '8':
2885 case '9':
2886 case '-':
2887 case '#': /* For symbol identification (used in
2888 live ranges). */
2889 continue;
2890
2891 case ':':
2892 /* It is a C++ nested symbol. We don't need to record it
2893 (I don't think); if we try to look up foo::bar::baz,
2894 then symbols for the symtab containing foo should get
2895 read in, I think. */
2896 /* Someone says sun cc puts out symbols like
2897 /foo/baz/maclib::/usr/local/bin/maclib,
2898 which would get here with a symbol type of ':'. */
2899 continue;
2900
2901 default:
2902 /* Unexpected symbol descriptor. The second and
2903 subsequent stabs of a continued stab can show up
2904 here. The question is whether they ever can mimic
2905 a normal stab--it would be nice if not, since we
2906 certainly don't want to spend the time searching to
2907 the end of every string looking for a
2908 backslash. */
2909
2910 complaint (&symfile_complaints,
2911 _("unknown symbol descriptor `%c'"), p[1]);
2912
2913 /* Ignore it; perhaps it is an extension that we don't
2914 know about. */
2915 continue;
2916 }
2917 }
2918 }
2919 }
2920
2921 if (pst)
2922 {
2923 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2924 ssymnum, dependency_list,
2925 dependencies_used, textlow_not_set);
2926 }
2927
2928 /* Record the toc offset value of this symbol table into objfile
2929 structure. If no XMC_TC0 is found, toc_offset should be zero.
2930 Another place to obtain this information would be file auxiliary
2931 header. */
2932
2933 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->toc_offset
2934 = toc_offset;
2935 }
2936
2937 /* Return the toc offset value for a given objfile. */
2938
2939 CORE_ADDR
2940 xcoff_get_toc_offset (struct objfile *objfile)
2941 {
2942 if (objfile)
2943 return ((struct coff_symfile_info *)
2944 objfile->deprecated_sym_private)->toc_offset;
2945 return 0;
2946 }
2947
2948 /* Scan and build partial symbols for a symbol file.
2949 We have been initialized by a call to dbx_symfile_init, which
2950 put all the relevant info into a "struct dbx_symfile_info",
2951 hung off the objfile structure.
2952
2953 SECTION_OFFSETS contains offsets relative to which the symbols in the
2954 various sections are (depending where the sections were actually
2955 loaded). */
2956
2957 static void
2958 xcoff_initial_scan (struct objfile *objfile, int symfile_flags)
2959 {
2960 bfd *abfd;
2961 int val;
2962 struct cleanup *back_to;
2963 int num_symbols; /* # of symbols */
2964 file_ptr symtab_offset; /* symbol table and */
2965 file_ptr stringtab_offset; /* string table file offsets */
2966 struct coff_symfile_info *info;
2967 char *name;
2968 unsigned int size;
2969
2970 info = (struct coff_symfile_info *) objfile->deprecated_sym_private;
2971 symfile_bfd = abfd = objfile->obfd;
2972 name = objfile->name;
2973
2974 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2975 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2976 stringtab_offset = symtab_offset +
2977 num_symbols * coff_data (abfd)->local_symesz;
2978
2979 info->min_lineno_offset = 0;
2980 info->max_lineno_offset = 0;
2981 bfd_map_over_sections (abfd, find_linenos, info);
2982
2983 if (num_symbols > 0)
2984 {
2985 /* Read the string table. */
2986 init_stringtab (abfd, stringtab_offset, objfile);
2987
2988 /* Read the .debug section, if present. */
2989 {
2990 struct bfd_section *secp;
2991 bfd_size_type length;
2992 char *debugsec = NULL;
2993
2994 secp = bfd_get_section_by_name (abfd, ".debug");
2995 if (secp)
2996 {
2997 length = bfd_section_size (abfd, secp);
2998 if (length)
2999 {
3000 debugsec =
3001 (char *) obstack_alloc (&objfile->objfile_obstack, length);
3002
3003 if (!bfd_get_section_contents (abfd, secp, debugsec,
3004 (file_ptr) 0, length))
3005 {
3006 error (_("Error reading .debug section of `%s': %s"),
3007 name, bfd_errmsg (bfd_get_error ()));
3008 }
3009 }
3010 }
3011 ((struct coff_symfile_info *)
3012 objfile->deprecated_sym_private)->debugsec
3013 = debugsec;
3014 }
3015 }
3016
3017 /* Read the symbols. We keep them in core because we will want to
3018 access them randomly in read_symbol*. */
3019 val = bfd_seek (abfd, symtab_offset, SEEK_SET);
3020 if (val < 0)
3021 error (_("Error reading symbols from %s: %s"),
3022 name, bfd_errmsg (bfd_get_error ()));
3023 size = coff_data (abfd)->local_symesz * num_symbols;
3024 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl =
3025 obstack_alloc (&objfile->objfile_obstack, size);
3026 ((struct coff_symfile_info *)
3027 objfile->deprecated_sym_private)->symtbl_num_syms
3028 = num_symbols;
3029
3030 val = bfd_bread (((struct coff_symfile_info *)
3031 objfile->deprecated_sym_private)->symtbl,
3032 size, abfd);
3033 if (val != size)
3034 perror_with_name (_("reading symbol table"));
3035
3036 /* If we are reinitializing, or if we have never loaded syms yet, init. */
3037 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
3038 /* I'm not sure how how good num_symbols is; the rule of thumb in
3039 init_psymbol_list was developed for a.out. On the one hand,
3040 num_symbols includes auxents. On the other hand, it doesn't
3041 include N_SLINE. */
3042 init_psymbol_list (objfile, num_symbols);
3043
3044 free_pending_blocks ();
3045 back_to = make_cleanup (really_free_pendings, 0);
3046
3047 init_minimal_symbol_collection ();
3048 make_cleanup_discard_minimal_symbols ();
3049
3050 /* Now that the symbol table data of the executable file are all in core,
3051 process them and define symbols accordingly. */
3052
3053 scan_xcoff_symtab (objfile);
3054
3055 /* Install any minimal symbols that have been collected as the current
3056 minimal symbols for this objfile. */
3057
3058 install_minimal_symbols (objfile);
3059
3060 /* DWARF2 sections. */
3061
3062 if (dwarf2_has_info (objfile, &dwarf2_xcoff_names))
3063 dwarf2_build_psymtabs (objfile);
3064
3065 dwarf2_build_frame_info (objfile);
3066
3067 do_cleanups (back_to);
3068 }
3069 \f
3070 static void
3071 xcoff_symfile_offsets (struct objfile *objfile,
3072 struct section_addr_info *addrs)
3073 {
3074 asection *sect = NULL;
3075 int i;
3076
3077 objfile->num_sections = bfd_count_sections (objfile->obfd);
3078 objfile->section_offsets = (struct section_offsets *)
3079 obstack_alloc (&objfile->objfile_obstack,
3080 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
3081
3082 /* Initialize the section indexes for future use. */
3083 sect = bfd_get_section_by_name (objfile->obfd, ".text");
3084 if (sect)
3085 objfile->sect_index_text = sect->index;
3086
3087 sect = bfd_get_section_by_name (objfile->obfd, ".data");
3088 if (sect)
3089 objfile->sect_index_data = sect->index;
3090
3091 sect = bfd_get_section_by_name (objfile->obfd, ".bss");
3092 if (sect)
3093 objfile->sect_index_bss = sect->index;
3094
3095 sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
3096 if (sect)
3097 objfile->sect_index_rodata = sect->index;
3098
3099 for (i = 0; i < objfile->num_sections; ++i)
3100 {
3101 /* syms_from_objfile kindly subtracts from addr the
3102 bfd_section_vma of the .text section. This strikes me as
3103 wrong--whether the offset to be applied to symbol reading is
3104 relative to the start address of the section depends on the
3105 symbol format. In any event, this whole "addr" concept is
3106 pretty broken (it doesn't handle any section but .text
3107 sensibly), so just ignore the addr parameter and use 0.
3108 rs6000-nat.c will set the correct section offsets via
3109 objfile_relocate. */
3110 (objfile->section_offsets)->offsets[i] = 0;
3111 }
3112 }
3113
3114 /* Register our ability to parse symbols for xcoff BFD files. */
3115
3116 static const struct sym_fns xcoff_sym_fns =
3117 {
3118
3119 /* It is possible that coff and xcoff should be merged as
3120 they do have fundamental similarities (for example, the extra storage
3121 classes used for stabs could presumably be recognized in any COFF file).
3122 However, in addition to obvious things like all the csect hair, there are
3123 some subtler differences between xcoffread.c and coffread.c, notably
3124 the fact that coffread.c has no need to read in all the symbols, but
3125 xcoffread.c reads all the symbols and does in fact randomly access them
3126 (in C_BSTAT and line number processing). */
3127
3128 bfd_target_xcoff_flavour,
3129
3130 xcoff_new_init, /* init anything gbl to entire symtab */
3131 xcoff_symfile_init, /* read initial info, setup for sym_read() */
3132 xcoff_initial_scan, /* read a symbol file into symtab */
3133 NULL, /* sym_read_psymbols */
3134 xcoff_symfile_finish, /* finished with file, cleanup */
3135 xcoff_symfile_offsets, /* xlate offsets ext->int form */
3136 default_symfile_segments, /* Get segment information from a file. */
3137 aix_process_linenos,
3138 default_symfile_relocate, /* Relocate a debug section. */
3139 NULL, /* sym_probe_fns */
3140 &psym_functions
3141 };
3142
3143 /* Provide a prototype to silence -Wmissing-prototypes. */
3144 extern initialize_file_ftype _initialize_xcoffread;
3145
3146 void
3147 _initialize_xcoffread (void)
3148 {
3149 add_symtab_fns (&xcoff_sym_fns);
3150 }
This page took 0.094923 seconds and 4 git commands to generate.