complain (&msg);
complaint (&symfile_complaints, "Unexpected symbol continuation");
xcoff_next_symbol_text PARAMS ((struct objfile *));static voidrecord_include_begin PARAMS ((struct coff_symbol *));static voidenter_line_range PARAMS ((struct subfile *, unsigned, unsigned,			  CORE_ADDR, CORE_ADDR, unsigned *));static voidinit_stringtab PARAMS ((bfd *, file_ptr, struct objfile *));static voidxcoff_symfile_init PARAMS ((struct objfile *));static voidxcoff_new_init PARAMS ((struct objfile *));static voidxcoff_symfile_finish PARAMS ((struct objfile *));static struct section_offsets *xcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));static voidfind_linenos PARAMS ((bfd *, sec_ptr, PTR));static char *coff_getfilename PARAMS ((union internal_auxent *, struct objfile *));static voidread_symbol PARAMS ((struct internal_syment *, int));static intread_symbol_lineno PARAMS ((int));static intread_symbol_nvalue PARAMS ((int));static struct symbol *process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *));static voidread_xcoff_symtab PARAMS ((struct partial_symtab *));#if 0static voidadd_stab_to_list PARAMS ((char *, struct pending_stabs **));#endifstatic intcompare_lte PARAMS ((const void *, const void *));static struct linetable *arrange_linetable PARAMS ((struct linetable *));static voidrecord_include_end PARAMS ((struct coff_symbol *));static voidprocess_linenos PARAMS ((CORE_ADDR, CORE_ADDR));/* Translate from a COFF section number (target_index) to a SECT_OFF_*   code.  */static int secnum_to_section PARAMS ((int, struct objfile *));struct find_targ_sec_arg {  int targ_index;  int *resultp;};static void find_targ_sec PARAMS ((bfd *, asection *, void *));static void find_targ_sec (abfd, sect, obj)     bfd *abfd;     asection *sect;     PTR obj;{  struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj;  if (sect->target_index == args->targ_index)    {      /* This is the section.  Figure out what SECT_OFF_* code it is.  */      if (bfd_get_section_flags (abfd, sect) & SEC_CODE)	*args->resultp = SECT_OFF_TEXT;      else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)	*args->resultp = SECT_OFF_DATA;      else	*args->resultp = SECT_OFF_BSS;    }}/* Return the section number (SECT_OFF_*) that CS points to.  */static intsecnum_to_section (secnum, objfile)     int secnum;     struct objfile *objfile;{  int off = SECT_OFF_TEXT;  struct find_targ_sec_arg args;  args.targ_index = secnum;  args.resultp = &off;  bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);  return off;}/* add a given stab string into given stab vector. */#if 0static voidadd_stab_to_list (stabname, stabvector)char *stabname;struct pending_stabs **stabvector;{  if ( *stabvector == NULL) {    *stabvector = (struct pending_stabs *)	xmalloc (sizeof (struct pending_stabs) + 			INITIAL_STABVECTOR_LENGTH * sizeof (char*));    (*stabvector)->count = 0;    (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;  }  else if ((*stabvector)->count >= (*stabvector)->length) {    (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;    *stabvector = (struct pending_stabs *)	xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) + 	(*stabvector)->length * sizeof (char*));  }  (*stabvector)->stab [(*stabvector)->count++] = stabname;}#endif/* Linenos are processed on a file-by-file basis.   Two reasons:    1) xlc (IBM's native c compiler) postpones static function code       emission to the end of a compilation unit. This way it can       determine if those functions (statics) are needed or not, and       can do some garbage collection (I think). This makes line       numbers and corresponding addresses unordered, and we end up       with a line table like:       		lineno	addr        foo()	  10	0x100		  20	0x200		  30	0x300	foo3()	  70	0x400		  80	0x500		  90	0x600	static foo2()		  40	0x700		  50	0x800		  60	0x900			and that breaks gdb's binary search on line numbers, if the	above table is not sorted on line numbers. And that sort	should be on function based, since gcc can emit line numbers	like:			10	0x100	- for the init/test part of a for stmt.		20	0x200		30	0x300		10	0x400	- for the increment part of a for stmt.	arrange_linetable() will do this sorting.		     2)	aix symbol table might look like:		c_file		// beginning of a new file		.bi		// beginning of include file		.ei		// end of include file		.bi		.ei	basically, .bi/.ei pairs do not necessarily encapsulate	their scope. They need to be recorded, and processed later	on when we come the end of the compilation unit.	Include table (inclTable) and process_linenos() handle	that.  *//* compare line table entry addresses. */static intcompare_lte (lte1p, lte2p)     const void *lte1p;     const void *lte2p;{  struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;  struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;  return lte1->pc - lte2->pc;}/* Given a line table with function entries are marked, arrange its functions   in ascending order and strip off function entry markers and return it in   a newly created table. If the old one is good enough, return the old one. *//* FIXME: I think all this stuff can be replaced by just passing   sort_linevec = 1 to end_symtab.  */static struct linetable *arrange_linetable (oldLineTb)     struct linetable *oldLineTb;			/* old linetable */{  int ii, jj,       newline, 					/* new line count */      function_count;				/* # of functions */  struct linetable_entry *fentry;		/* function entry vector */  int fentry_size;				/* # of function entries */  struct linetable *newLineTb;			/* new line table */#define NUM_OF_FUNCTIONS 20  fentry_size = NUM_OF_FUNCTIONS;  fentry = (struct linetable_entry*)    xmalloc (fentry_size * sizeof (struct linetable_entry));  for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) {    if (oldLineTb->item[ii].line == 0) {	/* function entry found. */      if (function_count >= fentry_size) {	/* make sure you have room. */	fentry_size *= 2;	fentry = (struct linetable_entry*) 	  xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));      }      fentry[function_count].line = ii;      fentry[function_count].pc = oldLineTb->item[ii].pc;      ++function_count;    }  }  if (function_count == 0) {    free (fentry);    return oldLineTb;  }  else if (function_count > 1)    qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte);  /* allocate a new line table. */  newLineTb = (struct linetable *)    xmalloc      (sizeof (struct linetable) +        (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));  /* if line table does not start with a function beginning, copy up until     a function begin. */  newline = 0;  if (oldLineTb->item[0].line != 0)    for (newline=0; 	newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)      newLineTb->item[newline] = oldLineTb->item[newline];  /* Now copy function lines one by one. */  for (ii=0; ii < function_count; ++ii) {    for (jj = fentry[ii].line + 1;	         jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0; 							 ++jj, ++newline)      newLineTb->item[newline] = oldLineTb->item[jj];  }  free (fentry);  newLineTb->nitems = oldLineTb->nitems - function_count;  return newLineTb;  }     /* include file support: C_BINCL/C_EINCL pairs will be kept in the    following `IncludeChain'. At the end of each symtab (end_symtab),   we will determine if we should create additional symtab's to   represent if (the include files. */typedef struct _inclTable {  char		*name;				/* include filename */  /* Offsets to the line table.  end points to the last entry which is     part of this include file.  */  int		begin, end;    struct subfile *subfile;  unsigned	funStartLine;			/* start line # of its function */} InclTable;#define	INITIAL_INCLUDE_TABLE_LENGTH	20static InclTable  *inclTable;			/* global include table */static int	  inclIndx;			/* last entry to table */static int	  inclLength;			/* table length */static int	  inclDepth;			/* nested include depth */static void allocate_include_entry PARAMS ((void));static voidrecord_include_begin (cs)struct coff_symbol *cs;{  if (inclDepth)    {      /* In xcoff, we assume include files cannot be nested (not in .c files	 of course, but in corresponding .s files.).  */      /* This can happen with old versions of GCC.	 GCC 2.3.3-930426 does not exhibit this on a test case which	 a user said produced the message for him.  */      static struct complaint msg = {"Nested C_BINCL symbols", 0, 0};      complain (&msg);    }  ++inclDepth;  allocate_include_entry ();  inclTable [inclIndx].name  = cs->c_name;  inclTable [inclIndx].begin = cs->c_value;}static voidrecord_include_end (cs)struct coff_symbol *cs;{  InclTable *pTbl;    if (inclDepth == 0)    {      static struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0};      complain (&msg);    }  allocate_include_entry ();  pTbl = &inclTable [inclIndx];  pTbl->end = cs->c_value;  --inclDepth;  ++inclIndx;}static voidallocate_include_entry (){  if (inclTable == NULL)    {      inclTable = (InclTable *) 	xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);      memset (inclTable,	      '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);      inclLength = INITIAL_INCLUDE_TABLE_LENGTH;      inclIndx = 0;    }  else if (inclIndx >= inclLength)    {      inclLength += INITIAL_INCLUDE_TABLE_LENGTH;      inclTable = (InclTable *) 	xrealloc (inclTable, sizeof (InclTable) * inclLength);      memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH, 	      '\0', sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);    }}/* Global variable to pass the psymtab down to all the routines involved   in psymtab to symtab processing.  */static struct partial_symtab *this_symtab_psymtab;/* given the start and end addresses of a compilation unit (or a csect,   at times) process its lines and create appropriate line vectors. */static voidprocess_linenos (start, end)     CORE_ADDR start, end;{  int offset, ii;  file_ptr max_offset =    ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)      ->max_lineno_offset;  /* subfile structure for the main compilation unit.  */  struct subfile main_subfile;  /* In the main source file, any time we see a function entry, we     reset this variable to function's absolute starting line number.     All the following line numbers in the function are relative to     this, and we record absolute line numbers in record_line().  */  unsigned int main_source_baseline = 0;  unsigned *firstLine;  offset =    ((struct symloc *)this_symtab_psymtab->read_symtab_private)->lineno_off;  if (offset == 0)    goto return_after_cleanup;  memset (&main_subfile, '\0', sizeof (main_subfile));  if (inclIndx == 0)    /* All source lines were in the main source file. None in include files. */    enter_line_range (&main_subfile, offset, 0, start, end,     						&main_source_baseline);  else    {      /* There was source with line numbers in include files.  */      main_source_baseline = 0;      for (ii=0; ii < inclIndx; ++ii)	{	  struct subfile *tmpSubfile;	  /* If there is main file source before include file, enter it.  */	  if (offset < inclTable[ii].begin)	    {	      enter_line_range		(&main_subfile, offset, inclTable[ii].begin - LINESZ,		 start, 0, &main_source_baseline);	    }	  /* Have a new subfile for the include file.  */	  tmpSubfile = inclTable[ii].subfile =	    (struct subfile *) xmalloc (sizeof (struct subfile));	  memset (tmpSubfile, '\0', sizeof (struct subfile));	  firstLine = &(inclTable[ii].funStartLine);	  /* Enter include file's lines now.  */	  enter_line_range (tmpSubfile, inclTable[ii].begin, 			    inclTable[ii].end, start, 0, firstLine);	  if (offset <= inclTable[ii].end)	    offset = inclTable[ii].end + LINESZ;	}      /* All the include files' line have been processed at this point.  Now,	 enter remaining lines of the main file, if any left.  */      if (offset < max_offset + 1 - LINESZ)	{	  enter_line_range (&main_subfile, offset, 0, start, end, 			    &main_source_baseline);	}    }  /* Process main file's line numbers.  */  if (main_subfile.line_vector)    {      struct linetable *lineTb, *lv;      lv = main_subfile.line_vector;      /* Line numbers are not necessarily ordered. xlc compilation will	 put static function to the end. */      lineTb = arrange_linetable (lv);      if (lv == lineTb)	{	  current_subfile->line_vector = (struct linetable *)	    xrealloc (lv, (sizeof (struct linetable)			   + lv->nitems * sizeof (struct linetable_entry)));	}      else	{	  free (lv);	  current_subfile->line_vector = lineTb;	}      current_subfile->line_vector_length = 	current_subfile->line_vector->nitems;    }  /* Now, process included files' line numbers.  */  for (ii=0; ii < inclIndx; ++ii)    {      if ((inclTable[ii].subfile)->line_vector) /* Useless if!!! FIXMEmgo */	{	  struct linetable *lineTb, *lv;	  lv = (inclTable[ii].subfile)->line_vector;	  /* Line numbers are not necessarily ordered. xlc compilation will	     put static function to the end. */	  lineTb = arrange_linetable (lv);	  push_subfile ();	  /* For the same include file, we might want to have more than one	     subfile.  This happens if we have something like:  		......	        #include "foo.h"		......	 	#include "foo.h"		......	     while foo.h including code in it. (stupid but possible)	     Since start_subfile() looks at the name and uses an	     existing one if finds, we need to provide a fake name and	     fool it.  */#if 0	  start_subfile (inclTable[ii].name, (char*)0);#else	  {	    /* Pick a fake name that will produce the same results as this	       one when passed to deduce_language_from_filename.  Kludge on	       top of kludge.  */	    char *fakename = strrchr (inclTable[ii].name, '.');	    if (fakename == NULL)	      fakename = " ?";	    start_subfile (fakename, (char*)0);	    free (current_subfile->name);	  }	  current_subfile->name = strdup (inclTable[ii].name);#endif	  if (lv == lineTb)	    {	      current_subfile->line_vector =		(struct linetable *) xrealloc		  (lv, (sizeof (struct linetable)			+ lv->nitems * sizeof (struct linetable_entry)));	    }	  else	    {	      free (lv);	      current_subfile->line_vector = lineTb;	    }	  current_subfile->line_vector_length = 	    current_subfile->line_vector->nitems;	  start_subfile (pop_subfile (), (char*)0);	}    } return_after_cleanup:  /* We don't want to keep alloc/free'ing the global include file table.  */  inclIndx = 0;  /* Start with a fresh subfile structure for the next file.  */  memset (&main_subfile, '\0', sizeof (struct subfile));}voidaix_process_linenos (){  /* process line numbers and enter them into line vector */  process_linenos (last_source_start_addr, cur_src_end_addr);}/* Enter a given range of lines into the line vector.   can be called in the following two ways:     enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine)  or     enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)   endoffset points to the last line table entry that we should pay   attention to.  */static voidenter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr,		  firstLine)     struct subfile *subfile;     unsigned   beginoffset, endoffset;	/* offsets to line table */     CORE_ADDR  startaddr, endaddr;     unsigned   *firstLine;{  unsigned int curoffset;  CORE_ADDR addr;  struct external_lineno ext_lnno;  struct internal_lineno int_lnno;  unsigned int limit_offset;  bfd *abfd;  if (endoffset == 0 && startaddr == 0 && endaddr == 0)    return;  curoffset = beginoffset;  limit_offset =    ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)      ->max_lineno_offset;  if (endoffset != 0)    {      if (endoffset >= limit_offset)	{	  static struct complaint msg =	    {"Bad line table offset in C_EINCL directive", 0, 0};	  complain (&msg);	  return;	}      limit_offset = endoffset;    }  else    limit_offset -= 1;  abfd = this_symtab_psymtab->objfile->obfd;  while (curoffset <= limit_offset)    {      bfd_seek (abfd, curoffset, SEEK_SET);      bfd_read (&ext_lnno, sizeof (struct external_lineno), 1, abfd);      bfd_coff_swap_lineno_in (abfd, &ext_lnno, &int_lnno);      /* Find the address this line represents.  */      addr = (int_lnno.l_lnno	      ? int_lnno.l_addr.l_paddr	      : read_symbol_nvalue (int_lnno.l_addr.l_symndx));      addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets,			SECT_OFF_TEXT);      if (addr < startaddr || (endaddr && addr >= endaddr))	return;      if (int_lnno.l_lnno == 0)	{	  *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);	  record_line (subfile, 0, addr);	  --(*firstLine);	}      else	record_line (subfile, *firstLine + int_lnno.l_lnno, addr);      curoffset += LINESZ;    }}/* Save the vital information for use when closing off the current file.   NAME is the file name the symbols came from, START_ADDR is the first   text address for the file, and SIZE is the number of bytes of text.  */#define complete_symtab(name, start_addr) {	\  last_source_file = savestring (name, strlen (name));	\  last_source_start_addr = start_addr;			\}/* Refill the symbol table input buffer   and set the variables that control fetching entries from it.   Reports an error if no data available.   This function can read past the end of the symbol table   (into the string table) but this does no harm.  *//* Reading symbol table has to be fast! Keep the followings as macros, rather   than functions. */#define	RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \{						\  char *namestr;				\  namestr = (NAME); \  if (namestr[0] == '.') ++namestr; \  prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \				       (char *)NULL, (SECTION), (OBJFILE)); \  misc_func_recorded = 1;					\}/* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be   nested. At any given time, a symbol can only be in one static block.   This is the base address of current static block, zero if non exists. */   static int static_block_base = 0;/* Section number for the current static block.  */static int static_block_section = -1;/* true if space for symbol name has been allocated. */static int symname_alloced = 0;/* Next symbol to read.  Pointer into raw seething symbol table.  */static char *raw_symbol;/* This is the function which stabsread.c calls to get symbol   continuations.  */static char *xcoff_next_symbol_text (objfile)     struct objfile *objfile;{  struct internal_syment symbol;  static struct complaint msg =    {"Unexpected symbol continuation", 0, 0};  char *retval;  /* FIXME: is this the same as the passed arg? */  objfile = this_symtab_psymtab->objfile;  bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);  if (symbol.n_zeroes)    {      complain (&msg);      /* Return something which points to '\0' and hope the symbol reading	 code does something reasonable.  */      retval = "";    }  else if (symbol.n_sclass & 0x80)    {      retval =	((struct coff_symfile_info *)objfile->sym_private)->debugsec	  + symbol.n_offset;      raw_symbol +=	coff_data (objfile->obfd)->local_symesz;      ++symnum;    }  else    {      complain (&msg);      /* Return something which points to '\0' and hope the symbol reading	 code does something reasonable.  */      retval = "";    }  return retval;}