tab = line_info->fdrtab;   i = fdrtab_lookup (line_info, offset); if (i < 0) return false;		 fdr_ptr = tab[i].fdr;   stabs = false; if (fdr_ptr->csym >= 2)
if (line_info->cache.sect == NULL || line_info->cache.sect != section || offset < line_info->cache.start || offset >= line_info->cache.stop)
_bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,			line_info, filename_ptr, functionname_ptr, retline_ptr)     bfd *abfd;     asection *section;     bfd_vma offset;     struct ecoff_debug_info * const debug_info;     const struct ecoff_debug_swap * const debug_swap;     struct ecoff_find_line *line_info;     const char **filename_ptr;     const char **functionname_ptr;     unsigned int *retline_ptr;{  struct ecoff_fdrtab_entry *tab;  boolean stabs;  FDR *fdr_ptr;  int i;    offset += section->vma;       /* Build FDR table (sorted by object file's base-address) if we     don't have it already.  */  if (line_info->fdrtab == NULL      && !mk_fdrtab (abfd, debug_info, debug_swap, line_info))    return false;  tab = line_info->fdrtab;  /* find first FDR for address OFFSET */  i = fdrtab_lookup (line_info, offset);  if (i < 0)    return false;		/* no FDR, no fun... */  fdr_ptr = tab[i].fdr;  /* Check whether this file has stabs debugging information.  In a     file with stabs debugging information, the second local symbol is     named @stabs.  */  stabs = false;  if (fdr_ptr->csym >= 2)    {      char *sym_ptr;      SYMR sym;      sym_ptr = ((char *) debug_info->external_sym		 + (fdr_ptr->isymBase + 1) * debug_swap->external_sym_size);      (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);      if (strcmp (debug_info->ss + fdr_ptr->issBase + sym.iss,		  STABS_SYMBOL) == 0)	stabs = true;    }  if (!stabs)    {      bfd_size_type external_pdr_size;      char *pdr_ptr;      char *best_pdr = NULL;      FDR *best_fdr;      bfd_vma best_dist = ~0;      PDR pdr;      unsigned char *line_ptr;      unsigned char *line_end;      int lineno;      /* This file uses ECOFF debugging information.  Each FDR has a         list of procedure descriptors (PDR).  The address in the FDR         is the absolute address of the first procedure.  The address         in the first PDR gives the offset of that procedure relative         to the object file's base-address.  The addresses in         subsequent PDRs specify each procedure's address relative to         the object file's base-address.  To make things more juicy,         whenever the PROF bit in the PDR is set, the real entry point         of the procedure may be 16 bytes below what would normally be         the procedure's entry point.  Instead, DEC came up with a         wicked scheme to create profiled libraries "on the fly":         instead of shipping a regular and a profiled version of each         library, they insert 16 bytes of unused space in front of         each procedure and set the "prof" bit in the PDR to indicate         that there is a gap there (this is done automagically by "as"         when option "-pg" is specified).  Thus, normally, you link         against such a library and, except for lots of 16 byte gaps         between functions, things will behave as usual.  However,         when invoking "ld" with option "-pg", it will fill those gaps         with code that calls mcount().  It then moves the function's         entry point down by 16 bytes, and out pops a binary that has         all functions profiled.         NOTE: Neither FDRs nor PDRs are strictly sorted in memory               order.  For example, when including header-files that               define functions, the FDRs follow behind the including               file, even though their code may have been generated at               a lower address.  File coff-alpha.c from libbfd               illustrates this (use "odump -PFv" to look at a file's               FDR/PDR).  Similarly, PDRs are sometimes out of order               as well.  An example of this is OSF/1 v3.0 libc's               malloc.c.  I'm not sure why this happens, but it could               be due to optimizations that reorder a function's               position within an object-file.                 Strategy:                  On the first call to this function, we build a table of FDRs         that is sorted by the base-address of the object-file the FDR         is referring to.  Notice that each object-file may contain         code from multiple source files (e.g., due to code defined in         include files).  Thus, for any given base-address, there may         be multiple FDRs (but this case is, fortunately, uncommon).         lookup(addr) guarantees to return the first FDR that applies         to address ADDR.  Thus, after invoking lookup(), we have a         list of FDRs that may contain the PDR for ADDR.  Next, we         walk through the PDRs of these FDRs and locate the one that         is closest to ADDR (i.e., for which the difference between         ADDR and the PDR's entry point is positive and minimal).         Once, the right FDR and PDR are located, we simply walk         through the line-number table to lookup the line-number that         best matches ADDR.  Obviously, things could be sped up by         keeping a sorted list of PDRs instead of a sorted list of         FDRs.  However, this would increase space requirements         considerably, which is undesirable.  */      external_pdr_size = debug_swap->external_pdr_size;      /* Make offset relative to object file's start-address: */      offset -= tab[i].base_addr;      /* Search FDR list starting at tab[i] for the PDR that best matches         OFFSET.  Normally, the FDR list is only one entry long.  */      best_fdr = NULL;      do	{	  bfd_vma dist, min_dist = 0;	  char *pdr_hold;	  char *pdr_end;	  	  fdr_ptr = tab[i].fdr;	  	  pdr_ptr = ((char *) debug_info->external_pdr		     + fdr_ptr->ipdFirst * external_pdr_size);	  pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;	  (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);	  /* Find PDR that is closest to OFFSET.  If pdr.prof is set,	     the procedure entry-point *may* be 0x10 below pdr.adr.  We	     simply pretend that pdr.prof *implies* a lower entry-point.	     This is safe because it just means that may identify 4 NOPs	     in front of the function as belonging to the function.  */	  for (pdr_hold = NULL;	       pdr_ptr < pdr_end;	       (pdr_ptr += external_pdr_size,		(*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr)))	    {	      if (offset >= (pdr.adr - 0x10 * pdr.prof))		{		  dist = offset - (pdr.adr - 0x10 * pdr.prof);		  if (!pdr_hold || dist < min_dist)		    {		      min_dist = dist;		      pdr_hold = pdr_ptr;		    }		}	    }	  	  if (!best_pdr || min_dist < best_dist)	    {	      best_dist = min_dist;	      best_fdr = fdr_ptr;	      best_pdr = pdr_hold;	    }	  /* continue looping until base_addr of next entry is different: */	}      while (++i < line_info->fdrtab_len	     && tab[i].base_addr == tab[i - 1].base_addr);      if (!best_fdr || !best_pdr)	return false;			/* shouldn't happen... */      /* phew, finally we got something that we can hold onto: */      fdr_ptr = best_fdr;      pdr_ptr = best_pdr;      (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);      /* Now we can look for the actual line number.  The line numbers         are stored in a very funky format, which I won't try to         describe.  The search is bounded by the end of the FDRs line         number entries.  */      line_end = debug_info->line + fdr_ptr->cbLineOffset + fdr_ptr->cbLine;      /* Make offset relative to procedure entry: */      offset -= pdr.adr - 0x10 * pdr.prof;      lineno = pdr.lnLow;      line_ptr = debug_info->line + fdr_ptr->cbLineOffset + pdr.cbLineOffset;      while (line_ptr < line_end)	{	  int delta;	  unsigned int count;	  delta = *line_ptr >> 4;	  if (delta >= 0x8)	    delta -= 0x10;	  count = (*line_ptr & 0xf) + 1;	  ++line_ptr;	  if (delta == -8)	    {	      delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);	      if (delta >= 0x8000)		delta -= 0x10000;	      line_ptr += 2;	    }	  lineno += delta;	  if (offset < count * 4)	    break;	  offset -= count * 4;	}      /* If fdr_ptr->rss is -1, then this file does not have full         symbols, at least according to gdb/mipsread.c.  */      if (fdr_ptr->rss == -1)	{	  *filename_ptr = NULL;	  if (pdr.isym == -1)	    *functionname_ptr = NULL;	  else	    {	      EXTR proc_ext;	      (*debug_swap->swap_ext_in)		(abfd,		 ((char *) debug_info->external_ext		  + pdr.isym * debug_swap->external_ext_size),		 &proc_ext);	      *functionname_ptr = debug_info->ssext + proc_ext.asym.iss;	    }	}      else	{	  SYMR proc_sym;	  *filename_ptr = debug_info->ss + fdr_ptr->issBase + fdr_ptr->rss;	  (*debug_swap->swap_sym_in)	    (abfd,	     ((char *) debug_info->external_sym	      + (fdr_ptr->isymBase + pdr.isym) * debug_swap->external_sym_size),	     &proc_sym);	  *functionname_ptr = debug_info->ss + fdr_ptr->issBase + proc_sym.iss;	}      if (lineno == ilineNil)	lineno = 0;      *retline_ptr = lineno;    }  else    {      bfd_size_type external_sym_size;      const char *directory_name;      const char *main_file_name;      const char *current_file_name;      const char *function_name;      const char *line_file_name;      bfd_vma low_func_vma;      bfd_vma low_line_vma;      boolean past_line;      boolean past_fn;      char *sym_ptr, *sym_ptr_end;      size_t len, funclen;      char *buffer = NULL;      /* This file uses stabs debugging information.  When gcc is not	 optimizing, it will put the line number information before	 the function name stabs entry.  When gcc is optimizing, it	 will put the stabs entry for all the function first, followed	 by the line number information.  (This appears to happen	 because of the two output files used by the -mgpopt switch,	 which is implied by -O).  This means that we must keep	 looking through the symbols until we find both a line number	 and a function name which are beyond the address we want.  */      *filename_ptr = NULL;      *functionname_ptr = NULL;      *retline_ptr = 0;      directory_name = NULL;      main_file_name = NULL;      current_file_name = NULL;      function_name = NULL;      line_file_name = NULL;      low_func_vma = 0;      low_line_vma = 0;      past_line = false;      past_fn = false;      external_sym_size = debug_swap->external_sym_size;      sym_ptr = ((char *) debug_info->external_sym		 + (fdr_ptr->isymBase + 2) * external_sym_size);      sym_ptr_end = sym_ptr + (fdr_ptr->csym - 2) * external_sym_size;      for (;	   sym_ptr < sym_ptr_end && (! past_line || ! past_fn);	   sym_ptr += external_sym_size)	{	  SYMR sym;	  (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);	  if (ECOFF_IS_STAB (&sym))	    {	      switch (ECOFF_UNMARK_STAB (sym.index))		{		case N_SO:		  main_file_name = current_file_name =		    debug_info->ss + fdr_ptr->issBase + sym.iss;		  /* Check the next symbol to see if it is also an                     N_SO symbol.  */		  if (sym_ptr + external_sym_size < sym_ptr_end)		    {		      SYMR nextsym;		      (*debug_swap->swap_sym_in) (abfd,						  sym_ptr + external_sym_size,						  &nextsym);		      if (ECOFF_IS_STAB (&nextsym)			  && ECOFF_UNMARK_STAB (nextsym.index) == N_SO)			{ 			  directory_name = current_file_name;			  main_file_name = current_file_name =			    debug_info->ss + fdr_ptr->issBase + nextsym.iss;			  sym_ptr += external_sym_size;			}		    }		  break;		case N_SOL:		  current_file_name =		    debug_info->ss + fdr_ptr->issBase + sym.iss;		  break;		case N_FUN:		  if (sym.value > offset)		    past_fn = true;		  else if (sym.value >= low_func_vma)		    {		      low_func_vma = sym.value;		      function_name =			debug_info->ss + fdr_ptr->issBase + sym.iss;		    }		  break;		}	    }	  else if (sym.st == stLabel && sym.index != indexNil)	    {	      if (sym.value > offset)		past_line = true;	      else if (sym.value >= low_line_vma)		{		  low_line_vma = sym.value;		  line_file_name = current_file_name;		  *retline_ptr = sym.index;		}	    }	}      if (*retline_ptr != 0)	main_file_name = line_file_name;      /* We need to remove the stuff after the colon in the function         name.  We also need to put the directory name and the file         name together.  */      if (function_name == NULL)	len = funclen = 0;      else	len = funclen = strlen (function_name) + 1;      if (main_file_name != NULL	  && directory_name != NULL	  && main_file_name[0] != '/')	len += strlen (directory_name) + strlen (main_file_name) + 1;      if (len != 0)	{	  if (line_info->find_buffer != NULL)	    free (line_info->find_buffer);	  buffer = (char *) malloc (len);	  if (buffer == NULL)	    {	      bfd_set_error (bfd_error_no_memory);	      return false;	    }	  line_info->find_buffer = buffer;	}      if (function_name != NULL)	{	  char *colon;	  strcpy (buffer, function_name);	  colon = strchr (buffer, ':');	  if (colon != NULL)	    *colon = '\0';	  *functionname_ptr = buffer;	}      if (main_file_name != NULL)	{	  if (directory_name == NULL || main_file_name[0] == '/')	    *filename_ptr = main_file_name;	  else	    {	      sprintf (buffer + funclen, "%s%s", directory_name,		       main_file_name);	      *filename_ptr = buffer + funclen;	    }	}    }  return true;}