GDB (API)
|
00001 /* Read AIX xcoff symbol tables and convert to internal format, for GDB. 00002 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00003 Derived from coffread.c, dbxread.c, and a lot of hacking. 00004 Contributed by IBM Corporation. 00005 00006 This file is part of GDB. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00020 00021 #include "defs.h" 00022 #include "bfd.h" 00023 00024 #include <sys/types.h> 00025 #include <fcntl.h> 00026 #include <ctype.h> 00027 #include "gdb_string.h" 00028 00029 #ifdef HAVE_SYS_FILE_H 00030 #include <sys/file.h> 00031 #endif 00032 #include "gdb_stat.h" 00033 00034 #include "coff/internal.h" 00035 #include "libcoff.h" /* FIXME, internal data from BFD */ 00036 #include "coff/xcoff.h" 00037 #include "libxcoff.h" 00038 #include "coff/rs6000.h" 00039 #include "xcoffread.h" 00040 00041 #include "symtab.h" 00042 #include "gdbtypes.h" 00043 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */ 00044 #include "symfile.h" 00045 #include "objfiles.h" 00046 #include "buildsym.h" 00047 #include "stabsread.h" 00048 #include "expression.h" 00049 #include "complaints.h" 00050 #include "psympriv.h" 00051 00052 #include "gdb-stabs.h" 00053 00054 /* For interface with stabsread.c. */ 00055 #include "aout/stab_gnu.h" 00056 00057 00058 /* Key for XCOFF-associated data. */ 00059 00060 static const struct objfile_data *xcoff_objfile_data_key; 00061 00062 /* We put a pointer to this structure in the read_symtab_private field 00063 of the psymtab. */ 00064 00065 struct symloc 00066 { 00067 00068 /* First symbol number for this file. */ 00069 00070 int first_symnum; 00071 00072 /* Number of symbols in the section of the symbol table devoted to 00073 this file's symbols (actually, the section bracketed may contain 00074 more than just this file's symbols). If numsyms is 0, the only 00075 reason for this thing's existence is the dependency list. Nothing 00076 else will happen when it is read in. */ 00077 00078 int numsyms; 00079 00080 /* Position of the start of the line number information for this 00081 psymtab. */ 00082 unsigned int lineno_off; 00083 }; 00084 00085 /* Remember what we deduced to be the source language of this psymtab. */ 00086 00087 static enum language psymtab_language = language_unknown; 00088 00089 00090 /* Simplified internal version of coff symbol table information. */ 00091 00092 struct coff_symbol 00093 { 00094 char *c_name; 00095 int c_symnum; /* Symbol number of this entry. */ 00096 int c_naux; /* 0 if syment only, 1 if syment + auxent. */ 00097 CORE_ADDR c_value; 00098 unsigned char c_sclass; 00099 int c_secnum; 00100 unsigned int c_type; 00101 }; 00102 00103 /* Last function's saved coff symbol `cs'. */ 00104 00105 static struct coff_symbol fcn_cs_saved; 00106 00107 static bfd *symfile_bfd; 00108 00109 /* Core address of start and end of text of current source file. 00110 This is calculated from the first function seen after a C_FILE 00111 symbol. */ 00112 00113 00114 static CORE_ADDR cur_src_end_addr; 00115 00116 /* Core address of the end of the first object file. */ 00117 00118 static CORE_ADDR first_object_file_end; 00119 00120 /* Initial symbol-table-debug-string vector length. */ 00121 00122 #define INITIAL_STABVECTOR_LENGTH 40 00123 00124 /* Nonzero if within a function (so symbols should be local, 00125 if nothing says specifically). */ 00126 00127 int within_function; 00128 00129 /* Size of a COFF symbol. I think it is always 18, so I'm not sure 00130 there is any reason not to just use a #define, but might as well 00131 ask BFD for the size and store it here, I guess. */ 00132 00133 static unsigned local_symesz; 00134 00135 struct coff_symfile_info 00136 { 00137 file_ptr min_lineno_offset; /* Where in file lowest line#s are. */ 00138 file_ptr max_lineno_offset; /* 1+last byte of line#s in file. */ 00139 00140 /* Pointer to the string table. */ 00141 char *strtbl; 00142 00143 /* Pointer to debug section. */ 00144 char *debugsec; 00145 00146 /* Pointer to the a.out symbol table. */ 00147 char *symtbl; 00148 00149 /* Number of symbols in symtbl. */ 00150 int symtbl_num_syms; 00151 00152 /* Offset in data section to TOC anchor. */ 00153 CORE_ADDR toc_offset; 00154 }; 00155 00156 /* Convenience macro to access the per-objfile XCOFF data. */ 00157 00158 #define XCOFF_DATA(objfile) \ 00159 ((struct coff_symfile_info *) objfile_data ((objfile), \ 00160 xcoff_objfile_data_key)) 00161 00162 /* XCOFF names for dwarf sections. There is no compressed sections. */ 00163 00164 static const struct dwarf2_debug_sections dwarf2_xcoff_names = { 00165 { ".dwinfo", NULL }, 00166 { ".dwabrev", NULL }, 00167 { ".dwline", NULL }, 00168 { ".dwloc", NULL }, 00169 { NULL, NULL }, /* debug_macinfo */ 00170 { NULL, NULL }, /* debug_macro */ 00171 { ".dwstr", NULL }, 00172 { ".dwrnges", NULL }, 00173 { NULL, NULL }, /* debug_types */ 00174 { NULL, NULL }, /* debug_addr */ 00175 { ".dwframe", NULL }, 00176 { NULL, NULL }, /* eh_frame */ 00177 { NULL, NULL }, /* gdb_index */ 00178 23 00179 }; 00180 00181 static void 00182 bf_notfound_complaint (void) 00183 { 00184 complaint (&symfile_complaints, 00185 _("line numbers off, `.bf' symbol not found")); 00186 } 00187 00188 static void 00189 ef_complaint (int arg1) 00190 { 00191 complaint (&symfile_complaints, 00192 _("Mismatched .ef symbol ignored starting at symnum %d"), arg1); 00193 } 00194 00195 static void 00196 eb_complaint (int arg1) 00197 { 00198 complaint (&symfile_complaints, 00199 _("Mismatched .eb symbol ignored starting at symnum %d"), arg1); 00200 } 00201 00202 static void xcoff_initial_scan (struct objfile *, int); 00203 00204 static void scan_xcoff_symtab (struct objfile *); 00205 00206 static char *xcoff_next_symbol_text (struct objfile *); 00207 00208 static void record_include_begin (struct coff_symbol *); 00209 00210 static void 00211 enter_line_range (struct subfile *, unsigned, unsigned, 00212 CORE_ADDR, CORE_ADDR, unsigned *); 00213 00214 static void init_stringtab (bfd *, file_ptr, struct objfile *); 00215 00216 static void xcoff_symfile_init (struct objfile *); 00217 00218 static void xcoff_new_init (struct objfile *); 00219 00220 static void xcoff_symfile_finish (struct objfile *); 00221 00222 static char *coff_getfilename (union internal_auxent *, struct objfile *); 00223 00224 static void read_symbol (struct internal_syment *, int); 00225 00226 static int read_symbol_lineno (int); 00227 00228 static CORE_ADDR read_symbol_nvalue (int); 00229 00230 static struct symbol *process_xcoff_symbol (struct coff_symbol *, 00231 struct objfile *); 00232 00233 static void read_xcoff_symtab (struct objfile *, struct partial_symtab *); 00234 00235 #if 0 00236 static void add_stab_to_list (char *, struct pending_stabs **); 00237 #endif 00238 00239 static int compare_lte (const void *, const void *); 00240 00241 static struct linetable *arrange_linetable (struct linetable *); 00242 00243 static void record_include_end (struct coff_symbol *); 00244 00245 static void process_linenos (CORE_ADDR, CORE_ADDR); 00246 00247 00248 /* Translate from a COFF section number (target_index) to a SECT_OFF_* 00249 code. */ 00250 static int secnum_to_section (int, struct objfile *); 00251 static asection *secnum_to_bfd_section (int, struct objfile *); 00252 00253 struct find_targ_sec_arg 00254 { 00255 int targ_index; 00256 int *resultp; 00257 asection **bfd_sect; 00258 struct objfile *objfile; 00259 }; 00260 00261 static void find_targ_sec (bfd *, asection *, void *); 00262 00263 static void 00264 find_targ_sec (bfd *abfd, asection *sect, void *obj) 00265 { 00266 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *) obj; 00267 struct objfile *objfile = args->objfile; 00268 00269 if (sect->target_index == args->targ_index) 00270 { 00271 /* This is the section. Figure out what SECT_OFF_* code it is. */ 00272 if (bfd_get_section_flags (abfd, sect) & SEC_CODE) 00273 *args->resultp = SECT_OFF_TEXT (objfile); 00274 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD) 00275 *args->resultp = SECT_OFF_DATA (objfile); 00276 else 00277 *args->resultp = gdb_bfd_section_index (abfd, sect); 00278 *args->bfd_sect = sect; 00279 } 00280 } 00281 00282 /* Search all BFD sections for the section whose target_index is 00283 equal to N_SCNUM. Set *BFD_SECT to that section. The section's 00284 associated index in the objfile's section_offset table is also 00285 stored in *SECNUM. 00286 00287 If no match is found, *BFD_SECT is set to NULL, and *SECNUM 00288 is set to the text section's number. */ 00289 00290 static void 00291 xcoff_secnum_to_sections (int n_scnum, struct objfile *objfile, 00292 asection **bfd_sect, int *secnum) 00293 { 00294 struct find_targ_sec_arg args; 00295 00296 args.targ_index = n_scnum; 00297 args.resultp = secnum; 00298 args.bfd_sect = bfd_sect; 00299 args.objfile = objfile; 00300 00301 *bfd_sect = NULL; 00302 *secnum = SECT_OFF_TEXT (objfile); 00303 00304 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args); 00305 } 00306 00307 /* Return the section number (SECT_OFF_*) that N_SCNUM points to. */ 00308 00309 static int 00310 secnum_to_section (int n_scnum, struct objfile *objfile) 00311 { 00312 int secnum; 00313 asection *ignored; 00314 00315 xcoff_secnum_to_sections (n_scnum, objfile, &ignored, &secnum); 00316 return secnum; 00317 } 00318 00319 /* Return the BFD section that N_SCNUM points to. */ 00320 00321 static asection * 00322 secnum_to_bfd_section (int n_scnum, struct objfile *objfile) 00323 { 00324 int ignored; 00325 asection *bfd_sect; 00326 00327 xcoff_secnum_to_sections (n_scnum, objfile, &bfd_sect, &ignored); 00328 return bfd_sect; 00329 } 00330 00331 /* add a given stab string into given stab vector. */ 00332 00333 #if 0 00334 00335 static void 00336 add_stab_to_list (char *stabname, struct pending_stabs **stabvector) 00337 { 00338 if (*stabvector == NULL) 00339 { 00340 *stabvector = (struct pending_stabs *) 00341 xmalloc (sizeof (struct pending_stabs) + 00342 INITIAL_STABVECTOR_LENGTH * sizeof (char *)); 00343 (*stabvector)->count = 0; 00344 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH; 00345 } 00346 else if ((*stabvector)->count >= (*stabvector)->length) 00347 { 00348 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH; 00349 *stabvector = (struct pending_stabs *) 00350 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) + 00351 (*stabvector)->length * sizeof (char *)); 00352 } 00353 (*stabvector)->stab[(*stabvector)->count++] = stabname; 00354 } 00355 00356 #endif 00357 /* *INDENT-OFF* */ 00358 /* Linenos are processed on a file-by-file basis. 00359 00360 Two reasons: 00361 00362 1) xlc (IBM's native c compiler) postpones static function code 00363 emission to the end of a compilation unit. This way it can 00364 determine if those functions (statics) are needed or not, and 00365 can do some garbage collection (I think). This makes line 00366 numbers and corresponding addresses unordered, and we end up 00367 with a line table like: 00368 00369 00370 lineno addr 00371 foo() 10 0x100 00372 20 0x200 00373 30 0x300 00374 00375 foo3() 70 0x400 00376 80 0x500 00377 90 0x600 00378 00379 static foo2() 00380 40 0x700 00381 50 0x800 00382 60 0x900 00383 00384 and that breaks gdb's binary search on line numbers, if the 00385 above table is not sorted on line numbers. And that sort 00386 should be on function based, since gcc can emit line numbers 00387 like: 00388 00389 10 0x100 - for the init/test part of a for stmt. 00390 20 0x200 00391 30 0x300 00392 10 0x400 - for the increment part of a for stmt. 00393 00394 arrange_linetable() will do this sorting. 00395 00396 2) aix symbol table might look like: 00397 00398 c_file // beginning of a new file 00399 .bi // beginning of include file 00400 .ei // end of include file 00401 .bi 00402 .ei 00403 00404 basically, .bi/.ei pairs do not necessarily encapsulate 00405 their scope. They need to be recorded, and processed later 00406 on when we come the end of the compilation unit. 00407 Include table (inclTable) and process_linenos() handle 00408 that. */ 00409 /* *INDENT-ON* */ 00410 00411 00412 00413 /* compare line table entry addresses. */ 00414 00415 static int 00416 compare_lte (const void *lte1p, const void *lte2p) 00417 { 00418 struct linetable_entry *lte1 = (struct linetable_entry *) lte1p; 00419 struct linetable_entry *lte2 = (struct linetable_entry *) lte2p; 00420 00421 return lte1->pc - lte2->pc; 00422 } 00423 00424 /* Given a line table with function entries are marked, arrange its 00425 functions in ascending order and strip off function entry markers 00426 and return it in a newly created table. If the old one is good 00427 enough, return the old one. */ 00428 /* FIXME: I think all this stuff can be replaced by just passing 00429 sort_linevec = 1 to end_symtab. */ 00430 00431 static struct linetable * 00432 arrange_linetable (struct linetable *oldLineTb) 00433 { 00434 int ii, jj, newline, /* new line count */ 00435 function_count; /* # of functions */ 00436 00437 struct linetable_entry *fentry; /* function entry vector */ 00438 int fentry_size; /* # of function entries */ 00439 struct linetable *newLineTb; /* new line table */ 00440 int extra_lines = 0; 00441 00442 #define NUM_OF_FUNCTIONS 20 00443 00444 fentry_size = NUM_OF_FUNCTIONS; 00445 fentry = (struct linetable_entry *) 00446 xmalloc (fentry_size * sizeof (struct linetable_entry)); 00447 00448 for (function_count = 0, ii = 0; ii < oldLineTb->nitems; ++ii) 00449 { 00450 if (oldLineTb->item[ii].line == 0) 00451 { /* Function entry found. */ 00452 if (function_count >= fentry_size) 00453 { /* Make sure you have room. */ 00454 fentry_size *= 2; 00455 fentry = (struct linetable_entry *) 00456 xrealloc (fentry, 00457 fentry_size * sizeof (struct linetable_entry)); 00458 } 00459 fentry[function_count].line = ii; 00460 fentry[function_count].pc = oldLineTb->item[ii].pc; 00461 ++function_count; 00462 00463 /* If the function was compiled with XLC, we may have to add an 00464 extra line entry later. Reserve space for that. */ 00465 if (ii + 1 < oldLineTb->nitems 00466 && oldLineTb->item[ii].pc != oldLineTb->item[ii + 1].pc) 00467 extra_lines++; 00468 } 00469 } 00470 00471 if (function_count == 0) 00472 { 00473 xfree (fentry); 00474 return oldLineTb; 00475 } 00476 else if (function_count > 1) 00477 qsort (fentry, function_count, 00478 sizeof (struct linetable_entry), compare_lte); 00479 00480 /* Allocate a new line table. */ 00481 newLineTb = (struct linetable *) 00482 xmalloc 00483 (sizeof (struct linetable) + 00484 (oldLineTb->nitems - function_count + extra_lines) * sizeof (struct linetable_entry)); 00485 00486 /* If line table does not start with a function beginning, copy up until 00487 a function begin. */ 00488 00489 newline = 0; 00490 if (oldLineTb->item[0].line != 0) 00491 for (newline = 0; 00492 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline) 00493 newLineTb->item[newline] = oldLineTb->item[newline]; 00494 00495 /* Now copy function lines one by one. */ 00496 00497 for (ii = 0; ii < function_count; ++ii) 00498 { 00499 /* If the function was compiled with XLC, we may have to add an 00500 extra line to cover the function prologue. */ 00501 jj = fentry[ii].line; 00502 if (jj + 1 < oldLineTb->nitems 00503 && oldLineTb->item[jj].pc != oldLineTb->item[jj + 1].pc) 00504 { 00505 newLineTb->item[newline] = oldLineTb->item[jj]; 00506 newLineTb->item[newline].line = oldLineTb->item[jj + 1].line; 00507 newline++; 00508 } 00509 00510 for (jj = fentry[ii].line + 1; 00511 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0; 00512 ++jj, ++newline) 00513 newLineTb->item[newline] = oldLineTb->item[jj]; 00514 } 00515 xfree (fentry); 00516 /* The number of items in the line table must include these 00517 extra lines which were added in case of XLC compiled functions. */ 00518 newLineTb->nitems = oldLineTb->nitems - function_count + extra_lines; 00519 return newLineTb; 00520 } 00521 00522 /* include file support: C_BINCL/C_EINCL pairs will be kept in the 00523 following `IncludeChain'. At the end of each symtab (end_symtab), 00524 we will determine if we should create additional symtab's to 00525 represent if (the include files. */ 00526 00527 00528 typedef struct _inclTable 00529 { 00530 char *name; /* include filename */ 00531 00532 /* Offsets to the line table. end points to the last entry which is 00533 part of this include file. */ 00534 int begin, end; 00535 00536 struct subfile *subfile; 00537 unsigned funStartLine; /* Start line # of its function. */ 00538 } 00539 InclTable; 00540 00541 #define INITIAL_INCLUDE_TABLE_LENGTH 20 00542 static InclTable *inclTable; /* global include table */ 00543 static int inclIndx; /* last entry to table */ 00544 static int inclLength; /* table length */ 00545 static int inclDepth; /* nested include depth */ 00546 00547 static void allocate_include_entry (void); 00548 00549 static void 00550 record_include_begin (struct coff_symbol *cs) 00551 { 00552 if (inclDepth) 00553 { 00554 /* In xcoff, we assume include files cannot be nested (not in .c files 00555 of course, but in corresponding .s files.). */ 00556 00557 /* This can happen with old versions of GCC. 00558 GCC 2.3.3-930426 does not exhibit this on a test case which 00559 a user said produced the message for him. */ 00560 complaint (&symfile_complaints, _("Nested C_BINCL symbols")); 00561 } 00562 ++inclDepth; 00563 00564 allocate_include_entry (); 00565 00566 inclTable[inclIndx].name = cs->c_name; 00567 inclTable[inclIndx].begin = cs->c_value; 00568 } 00569 00570 static void 00571 record_include_end (struct coff_symbol *cs) 00572 { 00573 InclTable *pTbl; 00574 00575 if (inclDepth == 0) 00576 { 00577 complaint (&symfile_complaints, _("Mismatched C_BINCL/C_EINCL pair")); 00578 } 00579 00580 allocate_include_entry (); 00581 00582 pTbl = &inclTable[inclIndx]; 00583 pTbl->end = cs->c_value; 00584 00585 --inclDepth; 00586 ++inclIndx; 00587 } 00588 00589 static void 00590 allocate_include_entry (void) 00591 { 00592 if (inclTable == NULL) 00593 { 00594 inclTable = (InclTable *) 00595 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH); 00596 memset (inclTable, 00597 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH); 00598 inclLength = INITIAL_INCLUDE_TABLE_LENGTH; 00599 inclIndx = 0; 00600 } 00601 else if (inclIndx >= inclLength) 00602 { 00603 inclLength += INITIAL_INCLUDE_TABLE_LENGTH; 00604 inclTable = (InclTable *) 00605 xrealloc (inclTable, sizeof (InclTable) * inclLength); 00606 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH, 00607 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH); 00608 } 00609 } 00610 00611 /* Global variable to pass the psymtab down to all the routines involved 00612 in psymtab to symtab processing. */ 00613 static struct partial_symtab *this_symtab_psymtab; 00614 00615 /* Objfile related to this_symtab_psymtab; set at the same time. */ 00616 static struct objfile *this_symtab_objfile; 00617 00618 /* given the start and end addresses of a compilation unit (or a csect, 00619 at times) process its lines and create appropriate line vectors. */ 00620 00621 static void 00622 process_linenos (CORE_ADDR start, CORE_ADDR end) 00623 { 00624 int offset, ii; 00625 file_ptr max_offset 00626 = XCOFF_DATA (this_symtab_objfile)->max_lineno_offset; 00627 00628 /* subfile structure for the main compilation unit. */ 00629 struct subfile main_subfile; 00630 00631 /* In the main source file, any time we see a function entry, we 00632 reset this variable to function's absolute starting line number. 00633 All the following line numbers in the function are relative to 00634 this, and we record absolute line numbers in record_line(). */ 00635 00636 unsigned int main_source_baseline = 0; 00637 00638 unsigned *firstLine; 00639 00640 offset = 00641 ((struct symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off; 00642 if (offset == 0) 00643 goto return_after_cleanup; 00644 00645 memset (&main_subfile, '\0', sizeof (main_subfile)); 00646 00647 if (inclIndx == 0) 00648 /* All source lines were in the main source file. None in include 00649 files. */ 00650 00651 enter_line_range (&main_subfile, offset, 0, start, end, 00652 &main_source_baseline); 00653 00654 else 00655 { 00656 /* There was source with line numbers in include files. */ 00657 00658 int linesz = 00659 coff_data (this_symtab_objfile->obfd)->local_linesz; 00660 main_source_baseline = 0; 00661 00662 for (ii = 0; ii < inclIndx; ++ii) 00663 { 00664 struct subfile *tmpSubfile; 00665 00666 /* If there is main file source before include file, enter it. */ 00667 if (offset < inclTable[ii].begin) 00668 { 00669 enter_line_range 00670 (&main_subfile, offset, inclTable[ii].begin - linesz, 00671 start, 0, &main_source_baseline); 00672 } 00673 00674 if (strcmp (inclTable[ii].name, get_last_source_file ()) == 0) 00675 { 00676 /* The entry in the include table refers to the main source 00677 file. Add the lines to the main subfile. */ 00678 00679 main_source_baseline = inclTable[ii].funStartLine; 00680 enter_line_range 00681 (&main_subfile, inclTable[ii].begin, inclTable[ii].end, 00682 start, 0, &main_source_baseline); 00683 inclTable[ii].subfile = &main_subfile; 00684 } 00685 else 00686 { 00687 /* Have a new subfile for the include file. */ 00688 00689 tmpSubfile = inclTable[ii].subfile = 00690 (struct subfile *) xmalloc (sizeof (struct subfile)); 00691 00692 memset (tmpSubfile, '\0', sizeof (struct subfile)); 00693 firstLine = &(inclTable[ii].funStartLine); 00694 00695 /* Enter include file's lines now. */ 00696 enter_line_range (tmpSubfile, inclTable[ii].begin, 00697 inclTable[ii].end, start, 0, firstLine); 00698 } 00699 00700 if (offset <= inclTable[ii].end) 00701 offset = inclTable[ii].end + linesz; 00702 } 00703 00704 /* All the include files' line have been processed at this point. Now, 00705 enter remaining lines of the main file, if any left. */ 00706 if (offset < max_offset + 1 - linesz) 00707 { 00708 enter_line_range (&main_subfile, offset, 0, start, end, 00709 &main_source_baseline); 00710 } 00711 } 00712 00713 /* Process main file's line numbers. */ 00714 if (main_subfile.line_vector) 00715 { 00716 struct linetable *lineTb, *lv; 00717 00718 lv = main_subfile.line_vector; 00719 00720 /* Line numbers are not necessarily ordered. xlc compilation will 00721 put static function to the end. */ 00722 00723 lineTb = arrange_linetable (lv); 00724 if (lv == lineTb) 00725 { 00726 current_subfile->line_vector = (struct linetable *) 00727 xrealloc (lv, (sizeof (struct linetable) 00728 + lv->nitems * sizeof (struct linetable_entry))); 00729 } 00730 else 00731 { 00732 xfree (lv); 00733 current_subfile->line_vector = lineTb; 00734 } 00735 00736 current_subfile->line_vector_length = 00737 current_subfile->line_vector->nitems; 00738 } 00739 00740 /* Now, process included files' line numbers. */ 00741 00742 for (ii = 0; ii < inclIndx; ++ii) 00743 { 00744 if (inclTable[ii].subfile != ((struct subfile *) &main_subfile) 00745 && (inclTable[ii].subfile)->line_vector) /* Useless if!!! 00746 FIXMEmgo */ 00747 { 00748 struct linetable *lineTb, *lv; 00749 00750 lv = (inclTable[ii].subfile)->line_vector; 00751 00752 /* Line numbers are not necessarily ordered. xlc compilation will 00753 put static function to the end. */ 00754 00755 lineTb = arrange_linetable (lv); 00756 00757 push_subfile (); 00758 00759 /* For the same include file, we might want to have more than one 00760 subfile. This happens if we have something like: 00761 00762 ...... 00763 #include "foo.h" 00764 ...... 00765 #include "foo.h" 00766 ...... 00767 00768 while foo.h including code in it. (stupid but possible) 00769 Since start_subfile() looks at the name and uses an 00770 existing one if finds, we need to provide a fake name and 00771 fool it. */ 00772 00773 #if 0 00774 start_subfile (inclTable[ii].name, (char *) 0); 00775 #else 00776 { 00777 /* Pick a fake name that will produce the same results as this 00778 one when passed to deduce_language_from_filename. Kludge on 00779 top of kludge. */ 00780 char *fakename = strrchr (inclTable[ii].name, '.'); 00781 00782 if (fakename == NULL) 00783 fakename = " ?"; 00784 start_subfile (fakename, (char *) 0); 00785 xfree (current_subfile->name); 00786 } 00787 current_subfile->name = xstrdup (inclTable[ii].name); 00788 #endif 00789 00790 if (lv == lineTb) 00791 { 00792 current_subfile->line_vector = 00793 (struct linetable *) xrealloc 00794 (lv, (sizeof (struct linetable) 00795 + lv->nitems * sizeof (struct linetable_entry))); 00796 00797 } 00798 else 00799 { 00800 xfree (lv); 00801 current_subfile->line_vector = lineTb; 00802 } 00803 00804 current_subfile->line_vector_length = 00805 current_subfile->line_vector->nitems; 00806 start_subfile (pop_subfile (), (char *) 0); 00807 } 00808 } 00809 00810 return_after_cleanup: 00811 00812 /* We don't want to keep alloc/free'ing the global include file table. */ 00813 inclIndx = 0; 00814 00815 /* Start with a fresh subfile structure for the next file. */ 00816 memset (&main_subfile, '\0', sizeof (struct subfile)); 00817 } 00818 00819 static void 00820 aix_process_linenos (struct objfile *objfile) 00821 { 00822 /* There is no linenos to read if there are only dwarf info. */ 00823 if (this_symtab_psymtab == NULL) 00824 return; 00825 00826 /* Process line numbers and enter them into line vector. */ 00827 process_linenos (last_source_start_addr, cur_src_end_addr); 00828 } 00829 00830 00831 /* Enter a given range of lines into the line vector. 00832 can be called in the following two ways: 00833 enter_line_range (subfile, beginoffset, endoffset, 00834 startaddr, 0, firstLine) or 00835 enter_line_range (subfile, beginoffset, 0, 00836 startaddr, endaddr, firstLine) 00837 00838 endoffset points to the last line table entry that we should pay 00839 attention to. */ 00840 00841 static void 00842 enter_line_range (struct subfile *subfile, unsigned beginoffset, 00843 unsigned endoffset, /* offsets to line table */ 00844 CORE_ADDR startaddr, /* offsets to line table */ 00845 CORE_ADDR endaddr, unsigned *firstLine) 00846 { 00847 struct objfile *objfile = this_symtab_objfile; 00848 struct gdbarch *gdbarch = get_objfile_arch (objfile); 00849 unsigned int curoffset; 00850 CORE_ADDR addr; 00851 void *ext_lnno; 00852 struct internal_lineno int_lnno; 00853 unsigned int limit_offset; 00854 bfd *abfd; 00855 int linesz; 00856 00857 if (endoffset == 0 && startaddr == 0 && endaddr == 0) 00858 return; 00859 curoffset = beginoffset; 00860 limit_offset = XCOFF_DATA (objfile)->max_lineno_offset; 00861 00862 if (endoffset != 0) 00863 { 00864 if (endoffset >= limit_offset) 00865 { 00866 complaint (&symfile_complaints, 00867 _("Bad line table offset in C_EINCL directive")); 00868 return; 00869 } 00870 limit_offset = endoffset; 00871 } 00872 else 00873 limit_offset -= 1; 00874 00875 abfd = objfile->obfd; 00876 linesz = coff_data (abfd)->local_linesz; 00877 ext_lnno = alloca (linesz); 00878 00879 while (curoffset <= limit_offset) 00880 { 00881 bfd_seek (abfd, curoffset, SEEK_SET); 00882 bfd_bread (ext_lnno, linesz, abfd); 00883 bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno); 00884 00885 /* Find the address this line represents. */ 00886 addr = (int_lnno.l_lnno 00887 ? int_lnno.l_addr.l_paddr 00888 : read_symbol_nvalue (int_lnno.l_addr.l_symndx)); 00889 addr += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 00890 00891 if (addr < startaddr || (endaddr && addr >= endaddr)) 00892 return; 00893 00894 if (int_lnno.l_lnno == 0) 00895 { 00896 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx); 00897 record_line (subfile, 0, gdbarch_addr_bits_remove (gdbarch, addr)); 00898 --(*firstLine); 00899 } 00900 else 00901 record_line (subfile, *firstLine + int_lnno.l_lnno, 00902 gdbarch_addr_bits_remove (gdbarch, addr)); 00903 curoffset += linesz; 00904 } 00905 } 00906 00907 00908 /* Save the vital information for use when closing off the current file. 00909 NAME is the file name the symbols came from, START_ADDR is the first 00910 text address for the file, and SIZE is the number of bytes of text. */ 00911 00912 #define complete_symtab(name, start_addr) { \ 00913 set_last_source_file (name); \ 00914 last_source_start_addr = start_addr; \ 00915 } 00916 00917 00918 /* Refill the symbol table input buffer 00919 and set the variables that control fetching entries from it. 00920 Reports an error if no data available. 00921 This function can read past the end of the symbol table 00922 (into the string table) but this does no harm. */ 00923 00924 /* Create a new minimal symbol (using prim_record_minimal_symbol_and_info). 00925 00926 Creation of all new minimal symbols should go through this function 00927 rather than calling the various prim_record_[...] functions in order 00928 to make sure that all symbol addresses get properly relocated. 00929 00930 Arguments are: 00931 00932 NAME - the symbol's name (but if NAME starts with a period, that 00933 leading period is discarded). 00934 ADDRESS - the symbol's address, prior to relocation. This function 00935 relocates the address before recording the minimal symbol. 00936 MS_TYPE - the symbol's type. 00937 N_SCNUM - the symbol's XCOFF section number. 00938 OBJFILE - the objfile associated with the minimal symbol. */ 00939 00940 static void 00941 record_minimal_symbol (const char *name, CORE_ADDR address, 00942 enum minimal_symbol_type ms_type, 00943 int n_scnum, 00944 struct objfile *objfile) 00945 { 00946 int section = secnum_to_section (n_scnum, objfile); 00947 00948 if (name[0] == '.') 00949 ++name; 00950 00951 address += ANOFFSET (objfile->section_offsets, section); 00952 prim_record_minimal_symbol_and_info (name, address, ms_type, 00953 secnum_to_section (n_scnum, objfile), 00954 objfile); 00955 } 00956 00957 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be 00958 nested. At any given time, a symbol can only be in one static block. 00959 This is the base address of current static block, zero if non exists. */ 00960 00961 static int static_block_base = 0; 00962 00963 /* Section number for the current static block. */ 00964 00965 static int static_block_section = -1; 00966 00967 /* true if space for symbol name has been allocated. */ 00968 00969 static int symname_alloced = 0; 00970 00971 /* Next symbol to read. Pointer into raw seething symbol table. */ 00972 00973 static char *raw_symbol; 00974 00975 /* This is the function which stabsread.c calls to get symbol 00976 continuations. */ 00977 00978 static char * 00979 xcoff_next_symbol_text (struct objfile *objfile) 00980 { 00981 struct internal_syment symbol; 00982 char *retval; 00983 00984 /* FIXME: is this the same as the passed arg? */ 00985 if (this_symtab_objfile) 00986 objfile = this_symtab_objfile; 00987 00988 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol); 00989 if (symbol.n_zeroes) 00990 { 00991 complaint (&symfile_complaints, _("Unexpected symbol continuation")); 00992 00993 /* Return something which points to '\0' and hope the symbol reading 00994 code does something reasonable. */ 00995 retval = ""; 00996 } 00997 else if (symbol.n_sclass & 0x80) 00998 { 00999 retval = XCOFF_DATA (objfile)->debugsec + symbol.n_offset; 01000 raw_symbol += coff_data (objfile->obfd)->local_symesz; 01001 ++symnum; 01002 } 01003 else 01004 { 01005 complaint (&symfile_complaints, _("Unexpected symbol continuation")); 01006 01007 /* Return something which points to '\0' and hope the symbol reading 01008 code does something reasonable. */ 01009 retval = ""; 01010 } 01011 return retval; 01012 } 01013 01014 /* Read symbols for a given partial symbol table. */ 01015 01016 static void 01017 read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) 01018 { 01019 bfd *abfd = objfile->obfd; 01020 char *raw_auxptr; /* Pointer to first raw aux entry for sym. */ 01021 struct coff_symfile_info *xcoff = XCOFF_DATA (objfile); 01022 char *strtbl = xcoff->strtbl; 01023 char *debugsec = xcoff->debugsec; 01024 const char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF"; 01025 01026 struct internal_syment symbol[1]; 01027 union internal_auxent main_aux; 01028 struct coff_symbol cs[1]; 01029 CORE_ADDR file_start_addr = 0; 01030 CORE_ADDR file_end_addr = 0; 01031 01032 int next_file_symnum = -1; 01033 unsigned int max_symnum; 01034 int just_started = 1; 01035 int depth = 0; 01036 CORE_ADDR fcn_start_addr = 0; 01037 01038 struct coff_symbol fcn_stab_saved = { 0 }; 01039 01040 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */ 01041 union internal_auxent fcn_aux_saved = main_aux; 01042 struct context_stack *new; 01043 01044 char *filestring = " _start_ "; /* Name of the current file. */ 01045 01046 const char *last_csect_name; /* Last seen csect's name. */ 01047 01048 this_symtab_psymtab = pst; 01049 this_symtab_objfile = objfile; 01050 01051 /* Get the appropriate COFF "constants" related to the file we're 01052 handling. */ 01053 local_symesz = coff_data (abfd)->local_symesz; 01054 01055 set_last_source_file (NULL); 01056 last_csect_name = 0; 01057 01058 start_stabs (); 01059 start_symtab (filestring, (char *) NULL, file_start_addr); 01060 record_debugformat (debugfmt); 01061 symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum; 01062 max_symnum = 01063 symnum + ((struct symloc *) pst->read_symtab_private)->numsyms; 01064 first_object_file_end = 0; 01065 01066 raw_symbol = xcoff->symtbl + symnum * local_symesz; 01067 01068 while (symnum < max_symnum) 01069 { 01070 QUIT; /* make this command interruptable. */ 01071 01072 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */ 01073 /* read one symbol into `cs' structure. After processing the 01074 whole symbol table, only string table will be kept in memory, 01075 symbol table and debug section of xcoff will be freed. Thus 01076 we can mark symbols with names in string table as 01077 `alloced'. */ 01078 { 01079 int ii; 01080 01081 /* Swap and align the symbol into a reasonable C structure. */ 01082 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol); 01083 01084 cs->c_symnum = symnum; 01085 cs->c_naux = symbol->n_numaux; 01086 if (symbol->n_zeroes) 01087 { 01088 symname_alloced = 0; 01089 /* We must use the original, unswapped, name here so the name field 01090 pointed to by cs->c_name will persist throughout xcoffread. If 01091 we use the new field, it gets overwritten for each symbol. */ 01092 cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name; 01093 /* If it's exactly E_SYMNMLEN characters long it isn't 01094 '\0'-terminated. */ 01095 if (cs->c_name[E_SYMNMLEN - 1] != '\0') 01096 { 01097 char *p; 01098 01099 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1); 01100 strncpy (p, cs->c_name, E_SYMNMLEN); 01101 p[E_SYMNMLEN] = '\0'; 01102 cs->c_name = p; 01103 symname_alloced = 1; 01104 } 01105 } 01106 else if (symbol->n_sclass & 0x80) 01107 { 01108 cs->c_name = debugsec + symbol->n_offset; 01109 symname_alloced = 0; 01110 } 01111 else 01112 { 01113 /* in string table */ 01114 cs->c_name = strtbl + (int) symbol->n_offset; 01115 symname_alloced = 1; 01116 } 01117 cs->c_value = symbol->n_value; 01118 cs->c_sclass = symbol->n_sclass; 01119 cs->c_secnum = symbol->n_scnum; 01120 cs->c_type = (unsigned) symbol->n_type; 01121 01122 raw_symbol += local_symesz; 01123 ++symnum; 01124 01125 /* Save addr of first aux entry. */ 01126 raw_auxptr = raw_symbol; 01127 01128 /* Skip all the auxents associated with this symbol. */ 01129 for (ii = symbol->n_numaux; ii; --ii) 01130 { 01131 raw_symbol += coff_data (abfd)->local_auxesz; 01132 ++symnum; 01133 } 01134 } 01135 01136 /* if symbol name starts with ".$" or "$", ignore it. */ 01137 if (cs->c_name[0] == '$' 01138 || (cs->c_name[1] == '$' && cs->c_name[0] == '.')) 01139 continue; 01140 01141 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) 01142 { 01143 if (get_last_source_file ()) 01144 { 01145 pst->symtab = end_symtab (cur_src_end_addr, objfile, 01146 SECT_OFF_TEXT (objfile)); 01147 end_stabs (); 01148 } 01149 01150 start_stabs (); 01151 start_symtab ("_globals_", (char *) NULL, (CORE_ADDR) 0); 01152 record_debugformat (debugfmt); 01153 cur_src_end_addr = first_object_file_end; 01154 /* Done with all files, everything from here on is globals. */ 01155 } 01156 01157 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) 01158 && cs->c_naux == 1) 01159 { 01160 /* Dealing with a symbol with a csect entry. */ 01161 01162 #define CSECT(PP) ((PP)->x_csect) 01163 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l) 01164 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp)) 01165 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp)) 01166 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas) 01167 01168 /* Convert the auxent to something we can access. */ 01169 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, 01170 0, cs->c_naux, &main_aux); 01171 01172 switch (CSECT_SMTYP (&main_aux)) 01173 { 01174 01175 case XTY_ER: 01176 /* Ignore all external references. */ 01177 continue; 01178 01179 case XTY_SD: 01180 /* A section description. */ 01181 { 01182 switch (CSECT_SCLAS (&main_aux)) 01183 { 01184 01185 case XMC_PR: 01186 { 01187 01188 /* A program csect is seen. We have to allocate one 01189 symbol table for each program csect. Normally gdb 01190 prefers one symtab for each source file. In case 01191 of AIX, one source file might include more than one 01192 [PR] csect, and they don't have to be adjacent in 01193 terms of the space they occupy in memory. Thus, one 01194 single source file might get fragmented in the 01195 memory and gdb's file start and end address 01196 approach does not work! GCC (and I think xlc) seem 01197 to put all the code in the unnamed program csect. */ 01198 01199 if (last_csect_name) 01200 { 01201 complete_symtab (filestring, file_start_addr); 01202 cur_src_end_addr = file_end_addr; 01203 end_symtab (file_end_addr, objfile, 01204 SECT_OFF_TEXT (objfile)); 01205 end_stabs (); 01206 start_stabs (); 01207 /* Give all csects for this source file the same 01208 name. */ 01209 start_symtab (filestring, NULL, (CORE_ADDR) 0); 01210 record_debugformat (debugfmt); 01211 } 01212 01213 /* If this is the very first csect seen, 01214 basically `__start'. */ 01215 if (just_started) 01216 { 01217 first_object_file_end 01218 = cs->c_value + CSECT_LEN (&main_aux); 01219 just_started = 0; 01220 } 01221 01222 file_start_addr = 01223 cs->c_value + ANOFFSET (objfile->section_offsets, 01224 SECT_OFF_TEXT (objfile)); 01225 file_end_addr = file_start_addr + CSECT_LEN (&main_aux); 01226 01227 if (cs->c_name && (cs->c_name[0] == '.' || cs->c_name[0] == '@')) 01228 last_csect_name = cs->c_name; 01229 } 01230 continue; 01231 01232 /* All other symbols are put into the minimal symbol 01233 table only. */ 01234 01235 case XMC_RW: 01236 continue; 01237 01238 case XMC_TC0: 01239 continue; 01240 01241 case XMC_TC: 01242 continue; 01243 01244 default: 01245 /* Ignore the symbol. */ 01246 continue; 01247 } 01248 } 01249 break; 01250 01251 case XTY_LD: 01252 01253 switch (CSECT_SCLAS (&main_aux)) 01254 { 01255 case XMC_PR: 01256 /* a function entry point. */ 01257 function_entry_point: 01258 01259 fcn_start_addr = cs->c_value; 01260 01261 /* save the function header info, which will be used 01262 when `.bf' is seen. */ 01263 fcn_cs_saved = *cs; 01264 fcn_aux_saved = main_aux; 01265 continue; 01266 01267 case XMC_GL: 01268 /* shared library function trampoline code entry point. */ 01269 continue; 01270 01271 case XMC_DS: 01272 /* The symbols often have the same names as debug symbols for 01273 functions, and confuse lookup_symbol. */ 01274 continue; 01275 01276 default: 01277 /* xlc puts each variable in a separate csect, so we get 01278 an XTY_SD for each variable. But gcc puts several 01279 variables in a csect, so that each variable only gets 01280 an XTY_LD. This will typically be XMC_RW; I suspect 01281 XMC_RO and XMC_BS might be possible too. 01282 These variables are put in the minimal symbol table 01283 only. */ 01284 continue; 01285 } 01286 break; 01287 01288 case XTY_CM: 01289 /* Common symbols are put into the minimal symbol table only. */ 01290 continue; 01291 01292 default: 01293 break; 01294 } 01295 } 01296 01297 /* If explicitly specified as a function, treat is as one. This check 01298 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur 01299 after the above CSECT check. */ 01300 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF) 01301 { 01302 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, 01303 0, cs->c_naux, &main_aux); 01304 goto function_entry_point; 01305 } 01306 01307 switch (cs->c_sclass) 01308 { 01309 case C_FILE: 01310 01311 /* c_value field contains symnum of next .file entry in table 01312 or symnum of first global after last .file. */ 01313 01314 next_file_symnum = cs->c_value; 01315 01316 /* Complete symbol table for last object file containing 01317 debugging information. */ 01318 01319 /* Whether or not there was a csect in the previous file, we 01320 have to call `end_stabs' and `start_stabs' to reset 01321 type_vector, line_vector, etc. structures. */ 01322 01323 complete_symtab (filestring, file_start_addr); 01324 cur_src_end_addr = file_end_addr; 01325 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile)); 01326 end_stabs (); 01327 01328 /* XCOFF, according to the AIX 3.2 documentation, puts the 01329 filename in cs->c_name. But xlc 1.3.0.2 has decided to 01330 do things the standard COFF way and put it in the auxent. 01331 We use the auxent if the symbol is ".file" and an auxent 01332 exists, otherwise use the symbol itself. Simple 01333 enough. */ 01334 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0) 01335 { 01336 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, 01337 0, cs->c_naux, &main_aux); 01338 filestring = coff_getfilename (&main_aux, objfile); 01339 } 01340 else 01341 filestring = cs->c_name; 01342 01343 start_stabs (); 01344 start_symtab (filestring, (char *) NULL, (CORE_ADDR) 0); 01345 record_debugformat (debugfmt); 01346 last_csect_name = 0; 01347 01348 /* reset file start and end addresses. A compilation unit 01349 with no text (only data) should have zero file 01350 boundaries. */ 01351 file_start_addr = file_end_addr = 0; 01352 break; 01353 01354 case C_FUN: 01355 fcn_stab_saved = *cs; 01356 break; 01357 01358 case C_FCN: 01359 if (strcmp (cs->c_name, ".bf") == 0) 01360 { 01361 CORE_ADDR off = ANOFFSET (objfile->section_offsets, 01362 SECT_OFF_TEXT (objfile)); 01363 01364 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, 01365 0, cs->c_naux, &main_aux); 01366 01367 within_function = 1; 01368 01369 new = push_context (0, fcn_start_addr + off); 01370 01371 new->name = define_symbol 01372 (fcn_cs_saved.c_value + off, 01373 fcn_stab_saved.c_name, 0, 0, objfile); 01374 if (new->name != NULL) 01375 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT (objfile); 01376 } 01377 else if (strcmp (cs->c_name, ".ef") == 0) 01378 { 01379 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, 01380 0, cs->c_naux, &main_aux); 01381 01382 /* The value of .ef is the address of epilogue code; 01383 not useful for gdb. */ 01384 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno 01385 contains number of lines to '}' */ 01386 01387 if (context_stack_depth <= 0) 01388 { /* We attempted to pop an empty context stack. */ 01389 ef_complaint (cs->c_symnum); 01390 within_function = 0; 01391 break; 01392 } 01393 new = pop_context (); 01394 /* Stack must be empty now. */ 01395 if (context_stack_depth > 0 || new == NULL) 01396 { 01397 ef_complaint (cs->c_symnum); 01398 within_function = 0; 01399 break; 01400 } 01401 01402 finish_block (new->name, &local_symbols, new->old_blocks, 01403 new->start_addr, 01404 (fcn_cs_saved.c_value 01405 + fcn_aux_saved.x_sym.x_misc.x_fsize 01406 + ANOFFSET (objfile->section_offsets, 01407 SECT_OFF_TEXT (objfile))), 01408 objfile); 01409 within_function = 0; 01410 } 01411 break; 01412 01413 case C_BSTAT: 01414 /* Begin static block. */ 01415 { 01416 struct internal_syment symbol; 01417 01418 read_symbol (&symbol, cs->c_value); 01419 static_block_base = symbol.n_value; 01420 static_block_section = 01421 secnum_to_section (symbol.n_scnum, objfile); 01422 } 01423 break; 01424 01425 case C_ESTAT: 01426 /* End of static block. */ 01427 static_block_base = 0; 01428 static_block_section = -1; 01429 break; 01430 01431 case C_ARG: 01432 case C_REGPARM: 01433 case C_REG: 01434 case C_TPDEF: 01435 case C_STRTAG: 01436 case C_UNTAG: 01437 case C_ENTAG: 01438 { 01439 complaint (&symfile_complaints, 01440 _("Unrecognized storage class %d."), 01441 cs->c_sclass); 01442 } 01443 break; 01444 01445 case C_LABEL: 01446 case C_NULL: 01447 /* Ignore these. */ 01448 break; 01449 01450 case C_HIDEXT: 01451 case C_STAT: 01452 break; 01453 01454 case C_BINCL: 01455 /* beginning of include file */ 01456 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted 01457 order. Thus, when wee see them, we might not know enough info 01458 to process them. Thus, we'll be saving them into a table 01459 (inclTable) and postpone their processing. */ 01460 01461 record_include_begin (cs); 01462 break; 01463 01464 case C_EINCL: 01465 /* End of include file. */ 01466 /* See the comment after case C_BINCL. */ 01467 record_include_end (cs); 01468 break; 01469 01470 case C_BLOCK: 01471 if (strcmp (cs->c_name, ".bb") == 0) 01472 { 01473 depth++; 01474 new = push_context (depth, 01475 (cs->c_value 01476 + ANOFFSET (objfile->section_offsets, 01477 SECT_OFF_TEXT (objfile)))); 01478 } 01479 else if (strcmp (cs->c_name, ".eb") == 0) 01480 { 01481 if (context_stack_depth <= 0) 01482 { /* We attempted to pop an empty context stack. */ 01483 eb_complaint (cs->c_symnum); 01484 break; 01485 } 01486 new = pop_context (); 01487 if (depth-- != new->depth) 01488 { 01489 eb_complaint (cs->c_symnum); 01490 break; 01491 } 01492 if (local_symbols && context_stack_depth > 0) 01493 { 01494 /* Make a block for the local symbols within. */ 01495 finish_block (new->name, &local_symbols, new->old_blocks, 01496 new->start_addr, 01497 (cs->c_value 01498 + ANOFFSET (objfile->section_offsets, 01499 SECT_OFF_TEXT (objfile))), 01500 objfile); 01501 } 01502 local_symbols = new->locals; 01503 } 01504 break; 01505 01506 default: 01507 process_xcoff_symbol (cs, objfile); 01508 break; 01509 } 01510 } 01511 01512 if (get_last_source_file ()) 01513 { 01514 struct symtab *s; 01515 01516 complete_symtab (filestring, file_start_addr); 01517 cur_src_end_addr = file_end_addr; 01518 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile)); 01519 /* When reading symbols for the last C_FILE of the objfile, try 01520 to make sure that we set pst->symtab to the symtab for the 01521 file, not to the _globals_ symtab. I'm not sure whether this 01522 actually works right or when/if it comes up. */ 01523 if (pst->symtab == NULL) 01524 pst->symtab = s; 01525 end_stabs (); 01526 } 01527 } 01528 01529 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \ 01530 (SYMBOL2) = (struct symbol *) \ 01531 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \ 01532 *(SYMBOL2) = *(SYMBOL1); 01533 01534 01535 #define SYMNAME_ALLOC(NAME, ALLOCED) \ 01536 ((ALLOCED) ? (NAME) : obstack_copy0 (&objfile->objfile_obstack, \ 01537 (NAME), strlen (NAME))) 01538 01539 01540 /* process one xcoff symbol. */ 01541 01542 static struct symbol * 01543 process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile) 01544 { 01545 struct symbol onesymbol; 01546 struct symbol *sym = &onesymbol; 01547 struct symbol *sym2 = NULL; 01548 char *name, *pp; 01549 01550 int sec; 01551 CORE_ADDR off; 01552 01553 if (cs->c_secnum < 0) 01554 { 01555 /* The value is a register number, offset within a frame, etc., 01556 and does not get relocated. */ 01557 off = 0; 01558 sec = -1; 01559 } 01560 else 01561 { 01562 sec = secnum_to_section (cs->c_secnum, objfile); 01563 off = ANOFFSET (objfile->section_offsets, sec); 01564 } 01565 01566 name = cs->c_name; 01567 if (name[0] == '.') 01568 ++name; 01569 01570 initialize_symbol (sym); 01571 01572 /* default assumptions */ 01573 SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off; 01574 SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 01575 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile); 01576 01577 if (ISFCN (cs->c_type)) 01578 { 01579 /* At this point, we don't know the type of the function. This 01580 will be patched with the type from its stab entry later on in 01581 patch_block_stabs (), unless the file was compiled without -g. */ 01582 01583 SYMBOL_SET_LINKAGE_NAME (sym, SYMNAME_ALLOC (name, symname_alloced)); 01584 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_text_symbol; 01585 01586 SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK; 01587 SYMBOL_DUP (sym, sym2); 01588 01589 if (cs->c_sclass == C_EXT) 01590 add_symbol_to_list (sym2, &global_symbols); 01591 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT) 01592 add_symbol_to_list (sym2, &file_symbols); 01593 } 01594 else 01595 { 01596 /* In case we can't figure out the type, provide default. */ 01597 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_data_symbol; 01598 01599 switch (cs->c_sclass) 01600 { 01601 #if 0 01602 /* The values of functions and global symbols are now resolved 01603 via the global_sym_chain in stabsread.c. */ 01604 case C_FUN: 01605 if (fcn_cs_saved.c_sclass == C_EXT) 01606 add_stab_to_list (name, &global_stabs); 01607 else 01608 add_stab_to_list (name, &file_stabs); 01609 break; 01610 01611 case C_GSYM: 01612 add_stab_to_list (name, &global_stabs); 01613 break; 01614 #endif 01615 01616 case C_BCOMM: 01617 common_block_start (cs->c_name, objfile); 01618 break; 01619 01620 case C_ECOMM: 01621 common_block_end (objfile); 01622 break; 01623 01624 default: 01625 complaint (&symfile_complaints, _("Unexpected storage class: %d"), 01626 cs->c_sclass); 01627 /* FALLTHROUGH */ 01628 01629 case C_DECL: 01630 case C_PSYM: 01631 case C_RPSYM: 01632 case C_ECOML: 01633 case C_LSYM: 01634 case C_RSYM: 01635 case C_GSYM: 01636 01637 { 01638 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile); 01639 if (sym != NULL) 01640 { 01641 SYMBOL_SECTION (sym) = sec; 01642 } 01643 return sym; 01644 } 01645 01646 case C_STSYM: 01647 01648 /* For xlc (not GCC), the 'V' symbol descriptor is used for 01649 all statics and we need to distinguish file-scope versus 01650 function-scope using within_function. We do this by 01651 changing the string we pass to define_symbol to use 'S' 01652 where we need to, which is not necessarily super-clean, 01653 but seems workable enough. */ 01654 01655 if (*name == ':') 01656 return NULL; 01657 01658 pp = strchr (name, ':'); 01659 if (pp == NULL) 01660 return NULL; 01661 01662 ++pp; 01663 if (*pp == 'V' && !within_function) 01664 *pp = 'S'; 01665 sym = define_symbol ((cs->c_value 01666 + ANOFFSET (objfile->section_offsets, 01667 static_block_section)), 01668 cs->c_name, 0, 0, objfile); 01669 if (sym != NULL) 01670 { 01671 SYMBOL_VALUE_ADDRESS (sym) += static_block_base; 01672 SYMBOL_SECTION (sym) = static_block_section; 01673 } 01674 return sym; 01675 01676 } 01677 } 01678 return sym2; 01679 } 01680 01681 /* Extract the file name from the aux entry of a C_FILE symbol. 01682 Result is in static storage and is only good for temporary use. */ 01683 01684 static char * 01685 coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile) 01686 { 01687 static char buffer[BUFSIZ]; 01688 01689 if (aux_entry->x_file.x_n.x_zeroes == 0) 01690 strcpy (buffer, (XCOFF_DATA (objfile)->strtbl 01691 + aux_entry->x_file.x_n.x_offset)); 01692 else 01693 { 01694 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN); 01695 buffer[FILNMLEN] = '\0'; 01696 } 01697 return (buffer); 01698 } 01699 01700 /* Set *SYMBOL to symbol number symno in symtbl. */ 01701 static void 01702 read_symbol (struct internal_syment *symbol, int symno) 01703 { 01704 struct coff_symfile_info *xcoff = XCOFF_DATA (this_symtab_objfile); 01705 int nsyms = xcoff->symtbl_num_syms; 01706 char *stbl = xcoff->symtbl; 01707 01708 if (symno < 0 || symno >= nsyms) 01709 { 01710 complaint (&symfile_complaints, _("Invalid symbol offset")); 01711 symbol->n_value = 0; 01712 symbol->n_scnum = -1; 01713 return; 01714 } 01715 bfd_coff_swap_sym_in (this_symtab_objfile->obfd, 01716 stbl + (symno * local_symesz), 01717 symbol); 01718 } 01719 01720 /* Get value corresponding to symbol number symno in symtbl. */ 01721 01722 static CORE_ADDR 01723 read_symbol_nvalue (int symno) 01724 { 01725 struct internal_syment symbol[1]; 01726 01727 read_symbol (symbol, symno); 01728 return symbol->n_value; 01729 } 01730 01731 01732 /* Find the address of the function corresponding to symno, where 01733 symno is the symbol pointed to by the linetable. */ 01734 01735 static int 01736 read_symbol_lineno (int symno) 01737 { 01738 struct objfile *objfile = this_symtab_objfile; 01739 int xcoff64 = bfd_xcoff_is_xcoff64 (objfile->obfd); 01740 01741 struct coff_symfile_info *info = XCOFF_DATA (objfile); 01742 int nsyms = info->symtbl_num_syms; 01743 char *stbl = info->symtbl; 01744 char *strtbl = info->strtbl; 01745 01746 struct internal_syment symbol[1]; 01747 union internal_auxent main_aux[1]; 01748 01749 if (symno < 0) 01750 { 01751 bf_notfound_complaint (); 01752 return 0; 01753 } 01754 01755 /* Note that just searching for a short distance (e.g. 50 symbols) 01756 is not enough, at least in the following case. 01757 01758 .extern foo 01759 [many .stabx entries] 01760 [a few functions, referring to foo] 01761 .globl foo 01762 .bf 01763 01764 What happens here is that the assembler moves the .stabx entries 01765 to right before the ".bf" for foo, but the symbol for "foo" is before 01766 all the stabx entries. See PR gdb/2222. */ 01767 01768 /* Maintaining a table of .bf entries might be preferable to this search. 01769 If I understand things correctly it would need to be done only for 01770 the duration of a single psymtab to symtab conversion. */ 01771 while (symno < nsyms) 01772 { 01773 bfd_coff_swap_sym_in (symfile_bfd, 01774 stbl + (symno * local_symesz), symbol); 01775 if (symbol->n_sclass == C_FCN) 01776 { 01777 char *name = xcoff64 ? strtbl + symbol->n_offset : symbol->n_name; 01778 01779 if (strcmp (name, ".bf") == 0) 01780 goto gotit; 01781 } 01782 symno += symbol->n_numaux + 1; 01783 } 01784 01785 bf_notfound_complaint (); 01786 return 0; 01787 01788 gotit: 01789 /* Take aux entry and return its lineno. */ 01790 symno++; 01791 bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz, 01792 symbol->n_type, symbol->n_sclass, 01793 0, symbol->n_numaux, main_aux); 01794 01795 return main_aux->x_sym.x_misc.x_lnsz.x_lnno; 01796 } 01797 01798 /* Support for line number handling. */ 01799 01800 /* This function is called for every section; it finds the outer limits 01801 * of the line table (minimum and maximum file offset) so that the 01802 * mainline code can read the whole thing for efficiency. 01803 */ 01804 static void 01805 find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo) 01806 { 01807 struct coff_symfile_info *info; 01808 int size, count; 01809 file_ptr offset, maxoff; 01810 01811 count = asect->lineno_count; 01812 01813 if (strcmp (asect->name, ".text") != 0 || count == 0) 01814 return; 01815 01816 size = count * coff_data (abfd)->local_linesz; 01817 info = (struct coff_symfile_info *) vpinfo; 01818 offset = asect->line_filepos; 01819 maxoff = offset + size; 01820 01821 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0) 01822 info->min_lineno_offset = offset; 01823 01824 if (maxoff > info->max_lineno_offset) 01825 info->max_lineno_offset = maxoff; 01826 } 01827 01828 static void 01829 xcoff_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst) 01830 { 01831 struct cleanup *old_chain; 01832 int i; 01833 01834 if (!pst) 01835 return; 01836 01837 if (pst->readin) 01838 { 01839 fprintf_unfiltered 01840 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", 01841 pst->filename); 01842 return; 01843 } 01844 01845 /* Read in all partial symtabs on which this one is dependent. */ 01846 for (i = 0; i < pst->number_of_dependencies; i++) 01847 if (!pst->dependencies[i]->readin) 01848 { 01849 /* Inform about additional files that need to be read in. */ 01850 if (info_verbose) 01851 { 01852 fputs_filtered (" ", gdb_stdout); 01853 wrap_here (""); 01854 fputs_filtered ("and ", gdb_stdout); 01855 wrap_here (""); 01856 printf_filtered ("%s...", pst->dependencies[i]->filename); 01857 wrap_here (""); /* Flush output */ 01858 gdb_flush (gdb_stdout); 01859 } 01860 xcoff_psymtab_to_symtab_1 (objfile, pst->dependencies[i]); 01861 } 01862 01863 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0) 01864 { 01865 /* Init stuff necessary for reading in symbols. */ 01866 stabsread_init (); 01867 buildsym_init (); 01868 old_chain = make_cleanup (really_free_pendings, 0); 01869 01870 read_xcoff_symtab (objfile, pst); 01871 01872 do_cleanups (old_chain); 01873 } 01874 01875 pst->readin = 1; 01876 } 01877 01878 /* Read in all of the symbols for a given psymtab for real. 01879 Be verbose about it if the user wants that. SELF is not NULL. */ 01880 01881 static void 01882 xcoff_read_symtab (struct partial_symtab *self, struct objfile *objfile) 01883 { 01884 if (self->readin) 01885 { 01886 fprintf_unfiltered 01887 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", 01888 self->filename); 01889 return; 01890 } 01891 01892 if (((struct symloc *) self->read_symtab_private)->numsyms != 0 01893 || self->number_of_dependencies) 01894 { 01895 /* Print the message now, before reading the string table, 01896 to avoid disconcerting pauses. */ 01897 if (info_verbose) 01898 { 01899 printf_filtered ("Reading in symbols for %s...", self->filename); 01900 gdb_flush (gdb_stdout); 01901 } 01902 01903 next_symbol_text_func = xcoff_next_symbol_text; 01904 01905 xcoff_psymtab_to_symtab_1 (objfile, self); 01906 01907 /* Match with global symbols. This only needs to be done once, 01908 after all of the symtabs and dependencies have been read in. */ 01909 scan_file_globals (objfile); 01910 01911 /* Finish up the debug error message. */ 01912 if (info_verbose) 01913 printf_filtered ("done.\n"); 01914 } 01915 } 01916 01917 static void 01918 xcoff_new_init (struct objfile *objfile) 01919 { 01920 stabsread_new_init (); 01921 buildsym_new_init (); 01922 } 01923 01924 /* Do initialization in preparation for reading symbols from OBJFILE. 01925 01926 We will only be called if this is an XCOFF or XCOFF-like file. 01927 BFD handles figuring out the format of the file, and code in symfile.c 01928 uses BFD's determination to vector to us. */ 01929 01930 static void 01931 xcoff_symfile_init (struct objfile *objfile) 01932 { 01933 struct coff_symfile_info *xcoff; 01934 01935 /* Allocate struct to keep track of the symfile. */ 01936 xcoff = XNEW (struct coff_symfile_info); 01937 set_objfile_data (objfile, xcoff_objfile_data_key, xcoff); 01938 01939 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we 01940 find this causes a significant slowdown in gdb then we could 01941 set it in the debug symbol readers only when necessary. */ 01942 objfile->flags |= OBJF_REORDERED; 01943 } 01944 01945 /* Perform any local cleanups required when we are done with a particular 01946 objfile. I.E, we are in the process of discarding all symbol information 01947 for an objfile, freeing up all memory held for it, and unlinking the 01948 objfile struct from the global list of known objfiles. */ 01949 01950 static void 01951 xcoff_symfile_finish (struct objfile *objfile) 01952 { 01953 /* Start with a fresh include table for the next objfile. */ 01954 if (inclTable) 01955 { 01956 xfree (inclTable); 01957 inclTable = NULL; 01958 } 01959 inclIndx = inclLength = inclDepth = 0; 01960 01961 dwarf2_free_objfile (objfile); 01962 } 01963 01964 01965 static void 01966 init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile) 01967 { 01968 long length; 01969 int val; 01970 unsigned char lengthbuf[4]; 01971 char *strtbl; 01972 struct coff_symfile_info *xcoff = XCOFF_DATA (objfile); 01973 01974 xcoff->strtbl = NULL; 01975 01976 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 01977 error (_("cannot seek to string table in %s: %s"), 01978 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ())); 01979 01980 val = bfd_bread ((char *) lengthbuf, sizeof lengthbuf, abfd); 01981 length = bfd_h_get_32 (abfd, lengthbuf); 01982 01983 /* If no string table is needed, then the file may end immediately 01984 after the symbols. Just return with `strtbl' set to NULL. */ 01985 01986 if (val != sizeof lengthbuf || length < sizeof lengthbuf) 01987 return; 01988 01989 /* Allocate string table from objfile_obstack. We will need this table 01990 as long as we have its symbol table around. */ 01991 01992 strtbl = (char *) obstack_alloc (&objfile->objfile_obstack, length); 01993 xcoff->strtbl = strtbl; 01994 01995 /* Copy length buffer, the first byte is usually zero and is 01996 used for stabs with a name length of zero. */ 01997 memcpy (strtbl, lengthbuf, sizeof lengthbuf); 01998 if (length == sizeof lengthbuf) 01999 return; 02000 02001 val = bfd_bread (strtbl + sizeof lengthbuf, length - sizeof lengthbuf, abfd); 02002 02003 if (val != length - sizeof lengthbuf) 02004 error (_("cannot read string table from %s: %s"), 02005 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ())); 02006 if (strtbl[length - 1] != '\0') 02007 error (_("bad symbol file: string table " 02008 "does not end with null character")); 02009 02010 return; 02011 } 02012 02013 /* If we have not yet seen a function for this psymtab, this is 0. If we 02014 have seen one, it is the offset in the line numbers of the line numbers 02015 for the psymtab. */ 02016 static unsigned int first_fun_line_offset; 02017 02018 /* Allocate and partially fill a partial symtab. It will be 02019 completely filled at the end of the symbol list. 02020 02021 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR 02022 is the address relative to which its symbols are (incremental) or 0 02023 (normal). */ 02024 02025 static struct partial_symtab * 02026 xcoff_start_psymtab (struct objfile *objfile, 02027 const char *filename, int first_symnum, 02028 struct partial_symbol **global_syms, 02029 struct partial_symbol **static_syms) 02030 { 02031 struct partial_symtab *result = 02032 start_psymtab_common (objfile, objfile->section_offsets, 02033 filename, 02034 /* We fill in textlow later. */ 02035 0, 02036 global_syms, static_syms); 02037 02038 result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack, 02039 sizeof (struct symloc)); 02040 ((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum; 02041 result->read_symtab = xcoff_read_symtab; 02042 02043 /* Deduce the source language from the filename for this psymtab. */ 02044 psymtab_language = deduce_language_from_filename (filename); 02045 02046 return result; 02047 } 02048 02049 /* Close off the current usage of PST. 02050 Returns PST, or NULL if the partial symtab was empty and thrown away. 02051 02052 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive). 02053 02054 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES 02055 are the information for includes and dependencies. */ 02056 02057 static struct partial_symtab * 02058 xcoff_end_psymtab (struct objfile *objfile, struct partial_symtab *pst, 02059 const char **include_list, int num_includes, 02060 int capping_symbol_number, 02061 struct partial_symtab **dependency_list, 02062 int number_dependencies, int textlow_not_set) 02063 { 02064 int i; 02065 02066 if (capping_symbol_number != -1) 02067 ((struct symloc *) pst->read_symtab_private)->numsyms = 02068 capping_symbol_number 02069 - ((struct symloc *) pst->read_symtab_private)->first_symnum; 02070 ((struct symloc *) pst->read_symtab_private)->lineno_off = 02071 first_fun_line_offset; 02072 first_fun_line_offset = 0; 02073 pst->n_global_syms = objfile->global_psymbols.next 02074 - (objfile->global_psymbols.list + pst->globals_offset); 02075 pst->n_static_syms = objfile->static_psymbols.next 02076 - (objfile->static_psymbols.list + pst->statics_offset); 02077 02078 pst->number_of_dependencies = number_dependencies; 02079 if (number_dependencies) 02080 { 02081 pst->dependencies = (struct partial_symtab **) 02082 obstack_alloc (&objfile->objfile_obstack, 02083 number_dependencies * sizeof (struct partial_symtab *)); 02084 memcpy (pst->dependencies, dependency_list, 02085 number_dependencies * sizeof (struct partial_symtab *)); 02086 } 02087 else 02088 pst->dependencies = 0; 02089 02090 for (i = 0; i < num_includes; i++) 02091 { 02092 struct partial_symtab *subpst = 02093 allocate_psymtab (include_list[i], objfile); 02094 02095 subpst->section_offsets = pst->section_offsets; 02096 subpst->read_symtab_private = obstack_alloc (&objfile->objfile_obstack, 02097 sizeof (struct symloc)); 02098 ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0; 02099 ((struct symloc *) subpst->read_symtab_private)->numsyms = 0; 02100 subpst->textlow = 0; 02101 subpst->texthigh = 0; 02102 02103 /* We could save slight bits of space by only making one of these, 02104 shared by the entire set of include files. FIXME-someday. */ 02105 subpst->dependencies = (struct partial_symtab **) 02106 obstack_alloc (&objfile->objfile_obstack, 02107 sizeof (struct partial_symtab *)); 02108 subpst->dependencies[0] = pst; 02109 subpst->number_of_dependencies = 1; 02110 02111 subpst->globals_offset = 02112 subpst->n_global_syms = 02113 subpst->statics_offset = 02114 subpst->n_static_syms = 0; 02115 02116 subpst->readin = 0; 02117 subpst->symtab = 0; 02118 subpst->read_symtab = pst->read_symtab; 02119 } 02120 02121 sort_pst_symbols (objfile, pst); 02122 02123 if (num_includes == 0 02124 && number_dependencies == 0 02125 && pst->n_global_syms == 0 02126 && pst->n_static_syms == 0) 02127 { 02128 /* Throw away this psymtab, it's empty. We can't deallocate it, since 02129 it is on the obstack, but we can forget to chain it on the list. */ 02130 /* Empty psymtabs happen as a result of header files which don't have 02131 any symbols in them. There can be a lot of them. */ 02132 02133 discard_psymtab (objfile, pst); 02134 02135 /* Indicate that psymtab was thrown away. */ 02136 pst = (struct partial_symtab *) NULL; 02137 } 02138 return pst; 02139 } 02140 02141 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in 02142 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over 02143 the symbol and its auxents. */ 02144 02145 static void 02146 swap_sym (struct internal_syment *symbol, union internal_auxent *aux, 02147 const char **name, char **raw, unsigned int *symnump, 02148 struct objfile *objfile) 02149 { 02150 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol); 02151 if (symbol->n_zeroes) 02152 { 02153 /* If it's exactly E_SYMNMLEN characters long it isn't 02154 '\0'-terminated. */ 02155 if (symbol->n_name[E_SYMNMLEN - 1] != '\0') 02156 { 02157 /* FIXME: wastes memory for symbols which we don't end up putting 02158 into the minimal symbols. */ 02159 char *p; 02160 02161 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1); 02162 strncpy (p, symbol->n_name, E_SYMNMLEN); 02163 p[E_SYMNMLEN] = '\0'; 02164 *name = p; 02165 } 02166 else 02167 /* Point to the unswapped name as that persists as long as the 02168 objfile does. */ 02169 *name = ((struct external_syment *) *raw)->e.e_name; 02170 } 02171 else if (symbol->n_sclass & 0x80) 02172 { 02173 *name = XCOFF_DATA (objfile)->debugsec + symbol->n_offset; 02174 } 02175 else 02176 { 02177 *name = XCOFF_DATA (objfile)->strtbl + symbol->n_offset; 02178 } 02179 ++*symnump; 02180 *raw += coff_data (objfile->obfd)->local_symesz; 02181 if (symbol->n_numaux > 0) 02182 { 02183 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type, 02184 symbol->n_sclass, 0, symbol->n_numaux, aux); 02185 02186 *symnump += symbol->n_numaux; 02187 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux; 02188 } 02189 } 02190 02191 static void 02192 function_outside_compilation_unit_complaint (const char *arg1) 02193 { 02194 complaint (&symfile_complaints, 02195 _("function `%s' appears to be defined " 02196 "outside of all compilation units"), 02197 arg1); 02198 } 02199 02200 static void 02201 scan_xcoff_symtab (struct objfile *objfile) 02202 { 02203 struct gdbarch *gdbarch = get_objfile_arch (objfile); 02204 CORE_ADDR toc_offset = 0; /* toc offset value in data section. */ 02205 const char *filestring = NULL; 02206 02207 const char *namestring; 02208 int past_first_source_file = 0; 02209 bfd *abfd; 02210 asection *bfd_sect; 02211 unsigned int nsyms; 02212 02213 /* Current partial symtab */ 02214 struct partial_symtab *pst; 02215 02216 /* List of current psymtab's include files. */ 02217 const char **psymtab_include_list; 02218 int includes_allocated; 02219 int includes_used; 02220 02221 /* Index within current psymtab dependency list. */ 02222 struct partial_symtab **dependency_list; 02223 int dependencies_used, dependencies_allocated; 02224 02225 char *sraw_symbol; 02226 struct internal_syment symbol; 02227 union internal_auxent main_aux[5]; 02228 unsigned int ssymnum; 02229 02230 const char *last_csect_name = NULL; /* Last seen csect's name and value. */ 02231 CORE_ADDR last_csect_val = 0; 02232 int last_csect_sec = 0; 02233 int misc_func_recorded = 0; /* true if any misc. function. */ 02234 int textlow_not_set = 1; 02235 02236 pst = (struct partial_symtab *) 0; 02237 02238 includes_allocated = 30; 02239 includes_used = 0; 02240 psymtab_include_list = (const char **) alloca (includes_allocated * 02241 sizeof (const char *)); 02242 02243 dependencies_allocated = 30; 02244 dependencies_used = 0; 02245 dependency_list = 02246 (struct partial_symtab **) alloca (dependencies_allocated * 02247 sizeof (struct partial_symtab *)); 02248 02249 set_last_source_file (NULL); 02250 02251 abfd = objfile->obfd; 02252 next_symbol_text_func = xcoff_next_symbol_text; 02253 02254 sraw_symbol = XCOFF_DATA (objfile)->symtbl; 02255 nsyms = XCOFF_DATA (objfile)->symtbl_num_syms; 02256 ssymnum = 0; 02257 while (ssymnum < nsyms) 02258 { 02259 int sclass; 02260 02261 QUIT; 02262 02263 bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol); 02264 sclass = symbol.n_sclass; 02265 02266 switch (sclass) 02267 { 02268 case C_EXT: 02269 case C_HIDEXT: 02270 { 02271 /* The CSECT auxent--always the last auxent. */ 02272 union internal_auxent csect_aux; 02273 unsigned int symnum_before = ssymnum; 02274 02275 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol, 02276 &ssymnum, objfile); 02277 if (symbol.n_numaux > 1) 02278 { 02279 bfd_coff_swap_aux_in 02280 (objfile->obfd, 02281 sraw_symbol - coff_data (abfd)->local_symesz, 02282 symbol.n_type, 02283 symbol.n_sclass, 02284 symbol.n_numaux - 1, 02285 symbol.n_numaux, 02286 &csect_aux); 02287 } 02288 else 02289 csect_aux = main_aux[0]; 02290 02291 /* If symbol name starts with ".$" or "$", ignore it. */ 02292 if (namestring[0] == '$' 02293 || (namestring[0] == '.' && namestring[1] == '$')) 02294 break; 02295 02296 switch (csect_aux.x_csect.x_smtyp & 0x7) 02297 { 02298 case XTY_SD: 02299 switch (csect_aux.x_csect.x_smclas) 02300 { 02301 case XMC_PR: 02302 if (last_csect_name) 02303 { 02304 /* If no misc. function recorded in the last 02305 seen csect, enter it as a function. This 02306 will take care of functions like strcmp() 02307 compiled by xlc. */ 02308 02309 if (!misc_func_recorded) 02310 { 02311 record_minimal_symbol 02312 (last_csect_name, last_csect_val, 02313 mst_text, last_csect_sec, objfile); 02314 misc_func_recorded = 1; 02315 } 02316 02317 if (pst != NULL) 02318 { 02319 /* We have to allocate one psymtab for 02320 each program csect, because their text 02321 sections need not be adjacent. */ 02322 xcoff_end_psymtab 02323 (objfile, pst, psymtab_include_list, 02324 includes_used, symnum_before, dependency_list, 02325 dependencies_used, textlow_not_set); 02326 includes_used = 0; 02327 dependencies_used = 0; 02328 /* Give all psymtabs for this source file the same 02329 name. */ 02330 pst = xcoff_start_psymtab 02331 (objfile, 02332 filestring, 02333 symnum_before, 02334 objfile->global_psymbols.next, 02335 objfile->static_psymbols.next); 02336 } 02337 } 02338 /* Activate the misc_func_recorded mechanism for 02339 compiler- and linker-generated CSECTs like ".strcmp" 02340 and "@FIX1". */ 02341 if (namestring && (namestring[0] == '.' 02342 || namestring[0] == '@')) 02343 { 02344 last_csect_name = namestring; 02345 last_csect_val = symbol.n_value; 02346 last_csect_sec = symbol.n_scnum; 02347 } 02348 if (pst != NULL) 02349 { 02350 CORE_ADDR highval = 02351 symbol.n_value + csect_aux.x_csect.x_scnlen.l; 02352 02353 if (highval > pst->texthigh) 02354 pst->texthigh = highval; 02355 if (pst->textlow == 0 || symbol.n_value < pst->textlow) 02356 pst->textlow = symbol.n_value; 02357 } 02358 misc_func_recorded = 0; 02359 break; 02360 02361 case XMC_RW: 02362 case XMC_TD: 02363 /* Data variables are recorded in the minimal symbol 02364 table, except for section symbols. */ 02365 if (*namestring != '.') 02366 record_minimal_symbol 02367 (namestring, symbol.n_value, 02368 sclass == C_HIDEXT ? mst_file_data : mst_data, 02369 symbol.n_scnum, objfile); 02370 break; 02371 02372 case XMC_TC0: 02373 if (toc_offset) 02374 warning (_("More than one XMC_TC0 symbol found.")); 02375 toc_offset = symbol.n_value; 02376 02377 /* Make TOC offset relative to start address of 02378 section. */ 02379 bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile); 02380 if (bfd_sect) 02381 toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect); 02382 break; 02383 02384 case XMC_TC: 02385 /* These symbols tell us where the TOC entry for a 02386 variable is, not the variable itself. */ 02387 break; 02388 02389 default: 02390 break; 02391 } 02392 break; 02393 02394 case XTY_LD: 02395 switch (csect_aux.x_csect.x_smclas) 02396 { 02397 case XMC_PR: 02398 /* A function entry point. */ 02399 02400 if (first_fun_line_offset == 0 && symbol.n_numaux > 1) 02401 first_fun_line_offset = 02402 main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr; 02403 { 02404 record_minimal_symbol 02405 (namestring, symbol.n_value, 02406 sclass == C_HIDEXT ? mst_file_text : mst_text, 02407 symbol.n_scnum, objfile); 02408 misc_func_recorded = 1; 02409 } 02410 break; 02411 02412 case XMC_GL: 02413 /* shared library function trampoline code entry 02414 point. */ 02415 02416 /* record trampoline code entries as 02417 mst_solib_trampoline symbol. When we lookup mst 02418 symbols, we will choose mst_text over 02419 mst_solib_trampoline. */ 02420 record_minimal_symbol 02421 (namestring, symbol.n_value, 02422 mst_solib_trampoline, symbol.n_scnum, objfile); 02423 misc_func_recorded = 1; 02424 break; 02425 02426 case XMC_DS: 02427 /* The symbols often have the same names as 02428 debug symbols for functions, and confuse 02429 lookup_symbol. */ 02430 break; 02431 02432 default: 02433 02434 /* xlc puts each variable in a separate csect, 02435 so we get an XTY_SD for each variable. But 02436 gcc puts several variables in a csect, so 02437 that each variable only gets an XTY_LD. We 02438 still need to record them. This will 02439 typically be XMC_RW; I suspect XMC_RO and 02440 XMC_BS might be possible too. */ 02441 if (*namestring != '.') 02442 record_minimal_symbol 02443 (namestring, symbol.n_value, 02444 sclass == C_HIDEXT ? mst_file_data : mst_data, 02445 symbol.n_scnum, objfile); 02446 break; 02447 } 02448 break; 02449 02450 case XTY_CM: 02451 switch (csect_aux.x_csect.x_smclas) 02452 { 02453 case XMC_RW: 02454 case XMC_BS: 02455 /* Common variables are recorded in the minimal symbol 02456 table, except for section symbols. */ 02457 if (*namestring != '.') 02458 record_minimal_symbol 02459 (namestring, symbol.n_value, 02460 sclass == C_HIDEXT ? mst_file_bss : mst_bss, 02461 symbol.n_scnum, objfile); 02462 break; 02463 } 02464 break; 02465 02466 default: 02467 break; 02468 } 02469 } 02470 break; 02471 case C_FILE: 02472 { 02473 unsigned int symnum_before; 02474 02475 symnum_before = ssymnum; 02476 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol, 02477 &ssymnum, objfile); 02478 02479 /* See if the last csect needs to be recorded. */ 02480 02481 if (last_csect_name && !misc_func_recorded) 02482 { 02483 /* If no misc. function recorded in the last seen csect, enter 02484 it as a function. This will take care of functions like 02485 strcmp() compiled by xlc. */ 02486 02487 record_minimal_symbol (last_csect_name, last_csect_val, 02488 mst_text, last_csect_sec, objfile); 02489 misc_func_recorded = 1; 02490 } 02491 02492 if (pst) 02493 { 02494 xcoff_end_psymtab (objfile, pst, psymtab_include_list, 02495 includes_used, symnum_before, 02496 dependency_list, dependencies_used, 02497 textlow_not_set); 02498 includes_used = 0; 02499 dependencies_used = 0; 02500 } 02501 first_fun_line_offset = 0; 02502 02503 /* XCOFF, according to the AIX 3.2 documentation, puts the 02504 filename in cs->c_name. But xlc 1.3.0.2 has decided to 02505 do things the standard COFF way and put it in the auxent. 02506 We use the auxent if the symbol is ".file" and an auxent 02507 exists, otherwise use the symbol itself. */ 02508 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0) 02509 { 02510 filestring = coff_getfilename (&main_aux[0], objfile); 02511 } 02512 else 02513 filestring = namestring; 02514 02515 pst = xcoff_start_psymtab (objfile, 02516 filestring, 02517 symnum_before, 02518 objfile->global_psymbols.next, 02519 objfile->static_psymbols.next); 02520 last_csect_name = NULL; 02521 } 02522 break; 02523 02524 default: 02525 { 02526 complaint (&symfile_complaints, 02527 _("Storage class %d not recognized during scan"), 02528 sclass); 02529 } 02530 /* FALLTHROUGH */ 02531 02532 /* C_FCN is .bf and .ef symbols. I think it is sufficient 02533 to handle only the C_FUN and C_EXT. */ 02534 case C_FCN: 02535 02536 case C_BSTAT: 02537 case C_ESTAT: 02538 case C_ARG: 02539 case C_REGPARM: 02540 case C_REG: 02541 case C_TPDEF: 02542 case C_STRTAG: 02543 case C_UNTAG: 02544 case C_ENTAG: 02545 case C_LABEL: 02546 case C_NULL: 02547 02548 /* C_EINCL means we are switching back to the main file. But there 02549 is no reason to care; the only thing we want to know about 02550 includes is the names of all the included (.h) files. */ 02551 case C_EINCL: 02552 02553 case C_BLOCK: 02554 02555 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be 02556 used instead. */ 02557 case C_STAT: 02558 02559 /* I don't think the name of the common block (as opposed to the 02560 variables within it) is something which is user visible 02561 currently. */ 02562 case C_BCOMM: 02563 case C_ECOMM: 02564 02565 case C_PSYM: 02566 case C_RPSYM: 02567 02568 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL 02569 so C_LSYM would appear to be only for locals. */ 02570 case C_LSYM: 02571 02572 case C_AUTO: 02573 case C_RSYM: 02574 { 02575 /* We probably could save a few instructions by assuming that 02576 C_LSYM, C_PSYM, etc., never have auxents. */ 02577 int naux1 = symbol.n_numaux + 1; 02578 02579 ssymnum += naux1; 02580 sraw_symbol += bfd_coff_symesz (abfd) * naux1; 02581 } 02582 break; 02583 02584 case C_BINCL: 02585 { 02586 /* Mark down an include file in the current psymtab. */ 02587 enum language tmp_language; 02588 02589 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol, 02590 &ssymnum, objfile); 02591 02592 tmp_language = deduce_language_from_filename (namestring); 02593 02594 /* Only change the psymtab's language if we've learned 02595 something useful (eg. tmp_language is not language_unknown). 02596 In addition, to match what start_subfile does, never change 02597 from C++ to C. */ 02598 if (tmp_language != language_unknown 02599 && (tmp_language != language_c 02600 || psymtab_language != language_cplus)) 02601 psymtab_language = tmp_language; 02602 02603 /* In C++, one may expect the same filename to come round many 02604 times, when code is coming alternately from the main file 02605 and from inline functions in other files. So I check to see 02606 if this is a file we've seen before -- either the main 02607 source file, or a previously included file. 02608 02609 This seems to be a lot of time to be spending on N_SOL, but 02610 things like "break c-exp.y:435" need to work (I 02611 suppose the psymtab_include_list could be hashed or put 02612 in a binary tree, if profiling shows this is a major hog). */ 02613 if (pst && strcmp (namestring, pst->filename) == 0) 02614 continue; 02615 02616 { 02617 int i; 02618 02619 for (i = 0; i < includes_used; i++) 02620 if (strcmp (namestring, psymtab_include_list[i]) == 0) 02621 { 02622 i = -1; 02623 break; 02624 } 02625 if (i == -1) 02626 continue; 02627 } 02628 psymtab_include_list[includes_used++] = namestring; 02629 if (includes_used >= includes_allocated) 02630 { 02631 const char **orig = psymtab_include_list; 02632 02633 psymtab_include_list = (const char **) 02634 alloca ((includes_allocated *= 2) * 02635 sizeof (const char *)); 02636 memcpy (psymtab_include_list, orig, 02637 includes_used * sizeof (const char *)); 02638 } 02639 continue; 02640 } 02641 case C_FUN: 02642 /* The value of the C_FUN is not the address of the function (it 02643 appears to be the address before linking), but as long as it 02644 is smaller than the actual address, then find_pc_partial_function 02645 will use the minimal symbols instead. I hope. */ 02646 02647 case C_GSYM: 02648 case C_ECOML: 02649 case C_DECL: 02650 case C_STSYM: 02651 { 02652 char *p; 02653 02654 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol, 02655 &ssymnum, objfile); 02656 02657 p = strchr (namestring, ':'); 02658 if (!p) 02659 continue; /* Not a debugging symbol. */ 02660 02661 /* Main processing section for debugging symbols which 02662 the initial read through the symbol tables needs to worry 02663 about. If we reach this point, the symbol which we are 02664 considering is definitely one we are interested in. 02665 p must also contain the (valid) index into the namestring 02666 which indicates the debugging type symbol. */ 02667 02668 switch (p[1]) 02669 { 02670 case 'S': 02671 symbol.n_value += ANOFFSET (objfile->section_offsets, 02672 SECT_OFF_DATA (objfile)); 02673 02674 if (gdbarch_static_transform_name_p (gdbarch)) 02675 namestring = gdbarch_static_transform_name 02676 (gdbarch, namestring); 02677 02678 add_psymbol_to_list (namestring, p - namestring, 1, 02679 VAR_DOMAIN, LOC_STATIC, 02680 &objfile->static_psymbols, 02681 0, symbol.n_value, 02682 psymtab_language, objfile); 02683 continue; 02684 02685 case 'G': 02686 symbol.n_value += ANOFFSET (objfile->section_offsets, 02687 SECT_OFF_DATA (objfile)); 02688 /* The addresses in these entries are reported to be 02689 wrong. See the code that reads 'G's for symtabs. */ 02690 add_psymbol_to_list (namestring, p - namestring, 1, 02691 VAR_DOMAIN, LOC_STATIC, 02692 &objfile->global_psymbols, 02693 0, symbol.n_value, 02694 psymtab_language, objfile); 02695 continue; 02696 02697 case 'T': 02698 /* When a 'T' entry is defining an anonymous enum, it 02699 may have a name which is the empty string, or a 02700 single space. Since they're not really defining a 02701 symbol, those shouldn't go in the partial symbol 02702 table. We do pick up the elements of such enums at 02703 'check_enum:', below. */ 02704 if (p >= namestring + 2 02705 || (p == namestring + 1 02706 && namestring[0] != ' ')) 02707 { 02708 add_psymbol_to_list (namestring, p - namestring, 1, 02709 STRUCT_DOMAIN, LOC_TYPEDEF, 02710 &objfile->static_psymbols, 02711 symbol.n_value, 0, 02712 psymtab_language, objfile); 02713 if (p[2] == 't') 02714 { 02715 /* Also a typedef with the same name. */ 02716 add_psymbol_to_list (namestring, p - namestring, 1, 02717 VAR_DOMAIN, LOC_TYPEDEF, 02718 &objfile->static_psymbols, 02719 symbol.n_value, 0, 02720 psymtab_language, objfile); 02721 p += 1; 02722 } 02723 } 02724 goto check_enum; 02725 02726 case 't': 02727 if (p != namestring) /* a name is there, not just :T... */ 02728 { 02729 add_psymbol_to_list (namestring, p - namestring, 1, 02730 VAR_DOMAIN, LOC_TYPEDEF, 02731 &objfile->static_psymbols, 02732 symbol.n_value, 0, 02733 psymtab_language, objfile); 02734 } 02735 check_enum: 02736 /* If this is an enumerated type, we need to 02737 add all the enum constants to the partial symbol 02738 table. This does not cover enums without names, e.g. 02739 "enum {a, b} c;" in C, but fortunately those are 02740 rare. There is no way for GDB to find those from the 02741 enum type without spending too much time on it. Thus 02742 to solve this problem, the compiler needs to put out the 02743 enum in a nameless type. GCC2 does this. */ 02744 02745 /* We are looking for something of the form 02746 <name> ":" ("t" | "T") [<number> "="] "e" 02747 {<constant> ":" <value> ","} ";". */ 02748 02749 /* Skip over the colon and the 't' or 'T'. */ 02750 p += 2; 02751 /* This type may be given a number. Also, numbers can come 02752 in pairs like (0,26). Skip over it. */ 02753 while ((*p >= '0' && *p <= '9') 02754 || *p == '(' || *p == ',' || *p == ')' 02755 || *p == '=') 02756 p++; 02757 02758 if (*p++ == 'e') 02759 { 02760 /* The aix4 compiler emits extra crud before the 02761 members. */ 02762 if (*p == '-') 02763 { 02764 /* Skip over the type (?). */ 02765 while (*p != ':') 02766 p++; 02767 02768 /* Skip over the colon. */ 02769 p++; 02770 } 02771 02772 /* We have found an enumerated type. */ 02773 /* According to comments in read_enum_type 02774 a comma could end it instead of a semicolon. 02775 I don't know where that happens. 02776 Accept either. */ 02777 while (*p && *p != ';' && *p != ',') 02778 { 02779 char *q; 02780 02781 /* Check for and handle cretinous dbx symbol name 02782 continuation! */ 02783 if (*p == '\\' || (*p == '?' && p[1] == '\0')) 02784 p = next_symbol_text (objfile); 02785 02786 /* Point to the character after the name 02787 of the enum constant. */ 02788 for (q = p; *q && *q != ':'; q++) 02789 ; 02790 /* Note that the value doesn't matter for 02791 enum constants in psymtabs, just in symtabs. */ 02792 add_psymbol_to_list (p, q - p, 1, 02793 VAR_DOMAIN, LOC_CONST, 02794 &objfile->static_psymbols, 0, 02795 0, psymtab_language, objfile); 02796 /* Point past the name. */ 02797 p = q; 02798 /* Skip over the value. */ 02799 while (*p && *p != ',') 02800 p++; 02801 /* Advance past the comma. */ 02802 if (*p) 02803 p++; 02804 } 02805 } 02806 continue; 02807 02808 case 'c': 02809 /* Constant, e.g. from "const" in Pascal. */ 02810 add_psymbol_to_list (namestring, p - namestring, 1, 02811 VAR_DOMAIN, LOC_CONST, 02812 &objfile->static_psymbols, symbol.n_value, 02813 0, psymtab_language, objfile); 02814 continue; 02815 02816 case 'f': 02817 if (! pst) 02818 { 02819 int name_len = p - namestring; 02820 char *name = xmalloc (name_len + 1); 02821 02822 memcpy (name, namestring, name_len); 02823 name[name_len] = '\0'; 02824 function_outside_compilation_unit_complaint (name); 02825 xfree (name); 02826 } 02827 symbol.n_value += ANOFFSET (objfile->section_offsets, 02828 SECT_OFF_TEXT (objfile)); 02829 add_psymbol_to_list (namestring, p - namestring, 1, 02830 VAR_DOMAIN, LOC_BLOCK, 02831 &objfile->static_psymbols, 02832 0, symbol.n_value, 02833 psymtab_language, objfile); 02834 continue; 02835 02836 /* Global functions were ignored here, but now they 02837 are put into the global psymtab like one would expect. 02838 They're also in the minimal symbol table. */ 02839 case 'F': 02840 if (! pst) 02841 { 02842 int name_len = p - namestring; 02843 char *name = xmalloc (name_len + 1); 02844 02845 memcpy (name, namestring, name_len); 02846 name[name_len] = '\0'; 02847 function_outside_compilation_unit_complaint (name); 02848 xfree (name); 02849 } 02850 02851 /* We need only the minimal symbols for these 02852 loader-generated definitions. Keeping the global 02853 symbols leads to "in psymbols but not in symbols" 02854 errors. */ 02855 if (strncmp (namestring, "@FIX", 4) == 0) 02856 continue; 02857 02858 symbol.n_value += ANOFFSET (objfile->section_offsets, 02859 SECT_OFF_TEXT (objfile)); 02860 add_psymbol_to_list (namestring, p - namestring, 1, 02861 VAR_DOMAIN, LOC_BLOCK, 02862 &objfile->global_psymbols, 02863 0, symbol.n_value, 02864 psymtab_language, objfile); 02865 continue; 02866 02867 /* Two things show up here (hopefully); static symbols of 02868 local scope (static used inside braces) or extensions 02869 of structure symbols. We can ignore both. */ 02870 case 'V': 02871 case '(': 02872 case '0': 02873 case '1': 02874 case '2': 02875 case '3': 02876 case '4': 02877 case '5': 02878 case '6': 02879 case '7': 02880 case '8': 02881 case '9': 02882 case '-': 02883 case '#': /* For symbol identification (used in 02884 live ranges). */ 02885 continue; 02886 02887 case ':': 02888 /* It is a C++ nested symbol. We don't need to record it 02889 (I don't think); if we try to look up foo::bar::baz, 02890 then symbols for the symtab containing foo should get 02891 read in, I think. */ 02892 /* Someone says sun cc puts out symbols like 02893 /foo/baz/maclib::/usr/local/bin/maclib, 02894 which would get here with a symbol type of ':'. */ 02895 continue; 02896 02897 default: 02898 /* Unexpected symbol descriptor. The second and 02899 subsequent stabs of a continued stab can show up 02900 here. The question is whether they ever can mimic 02901 a normal stab--it would be nice if not, since we 02902 certainly don't want to spend the time searching to 02903 the end of every string looking for a 02904 backslash. */ 02905 02906 complaint (&symfile_complaints, 02907 _("unknown symbol descriptor `%c'"), p[1]); 02908 02909 /* Ignore it; perhaps it is an extension that we don't 02910 know about. */ 02911 continue; 02912 } 02913 } 02914 } 02915 } 02916 02917 if (pst) 02918 { 02919 xcoff_end_psymtab (objfile, pst, psymtab_include_list, includes_used, 02920 ssymnum, dependency_list, 02921 dependencies_used, textlow_not_set); 02922 } 02923 02924 /* Record the toc offset value of this symbol table into objfile 02925 structure. If no XMC_TC0 is found, toc_offset should be zero. 02926 Another place to obtain this information would be file auxiliary 02927 header. */ 02928 02929 XCOFF_DATA (objfile)->toc_offset = toc_offset; 02930 } 02931 02932 /* Return the toc offset value for a given objfile. */ 02933 02934 CORE_ADDR 02935 xcoff_get_toc_offset (struct objfile *objfile) 02936 { 02937 if (objfile) 02938 return XCOFF_DATA (objfile)->toc_offset; 02939 return 0; 02940 } 02941 02942 /* Scan and build partial symbols for a symbol file. 02943 We have been initialized by a call to dbx_symfile_init, which 02944 put all the relevant info into a "struct dbx_symfile_info", 02945 hung off the objfile structure. 02946 02947 SECTION_OFFSETS contains offsets relative to which the symbols in the 02948 various sections are (depending where the sections were actually 02949 loaded). */ 02950 02951 static void 02952 xcoff_initial_scan (struct objfile *objfile, int symfile_flags) 02953 { 02954 bfd *abfd; 02955 int val; 02956 struct cleanup *back_to; 02957 int num_symbols; /* # of symbols */ 02958 file_ptr symtab_offset; /* symbol table and */ 02959 file_ptr stringtab_offset; /* string table file offsets */ 02960 struct coff_symfile_info *info; 02961 const char *name; 02962 unsigned int size; 02963 02964 info = XCOFF_DATA (objfile); 02965 symfile_bfd = abfd = objfile->obfd; 02966 name = objfile_name (objfile); 02967 02968 num_symbols = bfd_get_symcount (abfd); /* # of symbols */ 02969 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */ 02970 stringtab_offset = symtab_offset + 02971 num_symbols * coff_data (abfd)->local_symesz; 02972 02973 info->min_lineno_offset = 0; 02974 info->max_lineno_offset = 0; 02975 bfd_map_over_sections (abfd, find_linenos, info); 02976 02977 if (num_symbols > 0) 02978 { 02979 /* Read the string table. */ 02980 init_stringtab (abfd, stringtab_offset, objfile); 02981 02982 /* Read the .debug section, if present. */ 02983 { 02984 struct bfd_section *secp; 02985 bfd_size_type length; 02986 bfd_byte *debugsec = NULL; 02987 02988 secp = bfd_get_section_by_name (abfd, ".debug"); 02989 if (secp) 02990 { 02991 length = bfd_section_size (abfd, secp); 02992 if (length) 02993 { 02994 debugsec = obstack_alloc (&objfile->objfile_obstack, length); 02995 02996 if (!bfd_get_full_section_contents (abfd, secp, &debugsec)) 02997 { 02998 error (_("Error reading .debug section of `%s': %s"), 02999 name, bfd_errmsg (bfd_get_error ())); 03000 } 03001 } 03002 } 03003 info->debugsec = (char *) debugsec; 03004 } 03005 } 03006 03007 /* Read the symbols. We keep them in core because we will want to 03008 access them randomly in read_symbol*. */ 03009 val = bfd_seek (abfd, symtab_offset, SEEK_SET); 03010 if (val < 0) 03011 error (_("Error reading symbols from %s: %s"), 03012 name, bfd_errmsg (bfd_get_error ())); 03013 size = coff_data (abfd)->local_symesz * num_symbols; 03014 info->symtbl = obstack_alloc (&objfile->objfile_obstack, size); 03015 info->symtbl_num_syms = num_symbols; 03016 03017 val = bfd_bread (info->symtbl, size, abfd); 03018 if (val != size) 03019 perror_with_name (_("reading symbol table")); 03020 03021 /* If we are reinitializing, or if we have never loaded syms yet, init. */ 03022 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) 03023 /* I'm not sure how how good num_symbols is; the rule of thumb in 03024 init_psymbol_list was developed for a.out. On the one hand, 03025 num_symbols includes auxents. On the other hand, it doesn't 03026 include N_SLINE. */ 03027 init_psymbol_list (objfile, num_symbols); 03028 03029 free_pending_blocks (); 03030 back_to = make_cleanup (really_free_pendings, 0); 03031 03032 init_minimal_symbol_collection (); 03033 make_cleanup_discard_minimal_symbols (); 03034 03035 /* Now that the symbol table data of the executable file are all in core, 03036 process them and define symbols accordingly. */ 03037 03038 scan_xcoff_symtab (objfile); 03039 03040 /* Install any minimal symbols that have been collected as the current 03041 minimal symbols for this objfile. */ 03042 03043 install_minimal_symbols (objfile); 03044 03045 /* DWARF2 sections. */ 03046 03047 if (dwarf2_has_info (objfile, &dwarf2_xcoff_names)) 03048 dwarf2_build_psymtabs (objfile); 03049 03050 dwarf2_build_frame_info (objfile); 03051 03052 do_cleanups (back_to); 03053 } 03054 03055 static void 03056 xcoff_symfile_offsets (struct objfile *objfile, 03057 const struct section_addr_info *addrs) 03058 { 03059 const char *first_section_name; 03060 03061 default_symfile_offsets (objfile, addrs); 03062 03063 /* Oneof the weird side-effects of default_symfile_offsets is that 03064 it sometimes sets some section indices to zero for sections that, 03065 in fact do not exist. See the body of default_symfile_offsets 03066 for more info on when that happens. Undo that, as this then allows 03067 us to test whether the associated section exists or not, and then 03068 access it quickly (without searching it again). */ 03069 03070 if (objfile->num_sections == 0) 03071 return; /* Is that even possible? Better safe than sorry. */ 03072 03073 first_section_name 03074 = bfd_section_name (objfile->obfd, objfile->sections[0].the_bfd_section); 03075 03076 if (objfile->sect_index_text == 0 03077 && strcmp (first_section_name, ".text") != 0) 03078 objfile->sect_index_text = -1; 03079 03080 if (objfile->sect_index_data == 0 03081 && strcmp (first_section_name, ".data") != 0) 03082 objfile->sect_index_data = -1; 03083 03084 if (objfile->sect_index_bss == 0 03085 && strcmp (first_section_name, ".bss") != 0) 03086 objfile->sect_index_bss = -1; 03087 03088 if (objfile->sect_index_rodata == 0 03089 && strcmp (first_section_name, ".rodata") != 0) 03090 objfile->sect_index_rodata = -1; 03091 } 03092 03093 /* Register our ability to parse symbols for xcoff BFD files. */ 03094 03095 static const struct sym_fns xcoff_sym_fns = 03096 { 03097 03098 /* It is possible that coff and xcoff should be merged as 03099 they do have fundamental similarities (for example, the extra storage 03100 classes used for stabs could presumably be recognized in any COFF file). 03101 However, in addition to obvious things like all the csect hair, there are 03102 some subtler differences between xcoffread.c and coffread.c, notably 03103 the fact that coffread.c has no need to read in all the symbols, but 03104 xcoffread.c reads all the symbols and does in fact randomly access them 03105 (in C_BSTAT and line number processing). */ 03106 03107 xcoff_new_init, /* init anything gbl to entire symtab */ 03108 xcoff_symfile_init, /* read initial info, setup for sym_read() */ 03109 xcoff_initial_scan, /* read a symbol file into symtab */ 03110 NULL, /* sym_read_psymbols */ 03111 xcoff_symfile_finish, /* finished with file, cleanup */ 03112 xcoff_symfile_offsets, /* xlate offsets ext->int form */ 03113 default_symfile_segments, /* Get segment information from a file. */ 03114 aix_process_linenos, 03115 default_symfile_relocate, /* Relocate a debug section. */ 03116 NULL, /* sym_probe_fns */ 03117 &psym_functions 03118 }; 03119 03120 /* Same as xcoff_get_n_import_files, but for core files. */ 03121 03122 static int 03123 xcoff_get_core_n_import_files (bfd *abfd) 03124 { 03125 asection *sect = bfd_get_section_by_name (abfd, ".ldinfo"); 03126 gdb_byte buf[4]; 03127 file_ptr offset = 0; 03128 int n_entries = 0; 03129 03130 if (sect == NULL) 03131 return -1; /* Not a core file. */ 03132 03133 for (offset = 0; offset < bfd_get_section_size (sect);) 03134 { 03135 int next; 03136 03137 n_entries++; 03138 03139 if (!bfd_get_section_contents (abfd, sect, buf, offset, 4)) 03140 return -1; 03141 next = bfd_get_32 (abfd, buf); 03142 if (next == 0) 03143 break; /* This is the last entry. */ 03144 offset += next; 03145 } 03146 03147 /* Return the number of entries, excluding the first one, which is 03148 the path to the executable that produced this core file. */ 03149 return n_entries - 1; 03150 } 03151 03152 /* Return the number of import files (shared libraries) that the given 03153 BFD depends on. Return -1 if this number could not be computed. */ 03154 03155 int 03156 xcoff_get_n_import_files (bfd *abfd) 03157 { 03158 asection *sect = bfd_get_section_by_name (abfd, ".loader"); 03159 gdb_byte buf[4]; 03160 int l_nimpid; 03161 03162 /* If the ".loader" section does not exist, the objfile is probably 03163 not an executable. Might be a core file... */ 03164 if (sect == NULL) 03165 return xcoff_get_core_n_import_files (abfd); 03166 03167 /* The number of entries in the Import Files Table is stored in 03168 field l_nimpid. This field is always at offset 16, and is 03169 always 4 bytes long. Read those 4 bytes. */ 03170 03171 if (!bfd_get_section_contents (abfd, sect, buf, 16, 4)) 03172 return -1; 03173 l_nimpid = bfd_get_32 (abfd, buf); 03174 03175 /* By convention, the first entry is the default LIBPATH value 03176 to be used by the system loader, so it does not count towards 03177 the number of import files. */ 03178 return l_nimpid - 1; 03179 } 03180 03181 /* Free the per-objfile xcoff data. */ 03182 03183 static void 03184 xcoff_free_info (struct objfile *objfile, void *arg) 03185 { 03186 xfree (arg); 03187 } 03188 03189 /* Provide a prototype to silence -Wmissing-prototypes. */ 03190 extern initialize_file_ftype _initialize_xcoffread; 03191 03192 void 03193 _initialize_xcoffread (void) 03194 { 03195 add_symtab_fns (bfd_target_xcoff_flavour, &xcoff_sym_fns); 03196 03197 xcoff_objfile_data_key = register_objfile_data_with_cleanup (NULL, 03198 xcoff_free_info); 03199 }