This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] bfd/dwarf2.c gives wrong line number for inlined code


On Fri, Sep 18, 2009 at 11:14:00AM -0700, Cary Coutant wrote:
> >> Maybe it's time to throw away these old hacks? ?They date back to
> >> http://sourceware.org/ml/binutils/2002-03/msg00292.html
> >
> > I think so, too.
> 
> OK, how's this?

There's a hack at the end of the loop for gcc-2.95 and yet another 5
year old hack for the Intel 6.0 C++ compiler.  See
http://sourceware.org/ml/binutils/2002-10/msg00422.html

Does anyone object to the following cleanup?

Index: bfd/dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.123
diff -c -r1.123 dwarf2.c
*** bfd/dwarf2.c	9 Sep 2009 21:38:57 -0000	1.123
--- bfd/dwarf2.c	19 Sep 2009 02:26:27 -0000
***************
*** 1495,1587 ****
  static bfd_boolean
  lookup_address_in_line_info_table (struct line_info_table *table,
  				   bfd_vma addr,
- 				   struct funcinfo *function,
  				   const char **filename_ptr,
  				   unsigned int *linenumber_ptr)
  {
    /* Note: table->last_line should be a descendingly sorted list. */
!   struct line_info* next_line = table->last_line;
!   struct line_info* each_line = NULL;
!   *filename_ptr = NULL;
  
!   if (!next_line)
      return FALSE;
  
!   each_line = next_line->prev_line;
! 
!   /* Check for large addresses */
!   if (addr > next_line->address)
!     each_line = NULL; /* ensure we skip over the normal case */
! 
!   /* Normal case: search the list; save  */
!   while (each_line && next_line)
      {
-       /* If we have an address match, save this info.  This allows us
- 	 to return as good as results as possible for strange debugging
- 	 info.  */
-       bfd_boolean addr_match = FALSE;
-       if (each_line->address <= addr && addr < next_line->address)
- 	{
- 	  addr_match = TRUE;
- 
- 	  /* If this line appears to span functions, and addr is in the
- 	     later function, return the first line of that function instead
- 	     of the last line of the earlier one.  This check is for GCC
- 	     2.95, which emits the first line number for a function late.  */
- 
- 	  if (function != NULL)
- 	    {
- 	      bfd_vma lowest_pc;
- 	      struct arange *arange;
- 
- 	      /* Find the lowest address in the function's range list */
- 	      lowest_pc = function->arange.low;
- 	      for (arange = &function->arange;
- 		   arange;
- 		   arange = arange->next)
- 		{
- 		  if (function->arange.low < lowest_pc)
- 		    lowest_pc = function->arange.low;
- 		}
- 	      /* Check for spanning function and set outgoing line info */
- 	      if (addr >= lowest_pc
- 		  && each_line->address < lowest_pc
- 		  && next_line->address > lowest_pc)
- 		{
- 		  *filename_ptr = next_line->filename;
- 		  *linenumber_ptr = next_line->line;
- 		}
- 	      else
- 		{
- 		  *filename_ptr = each_line->filename;
- 		  *linenumber_ptr = each_line->line;
- 		}
- 	    }
- 	  else
- 	    {
- 	      *filename_ptr = each_line->filename;
- 	      *linenumber_ptr = each_line->line;
- 	    }
- 	}
- 
-       if (addr_match && !each_line->end_sequence)
- 	return TRUE; /* we have definitely found what we want */
- 
-       next_line = each_line;
        each_line = each_line->prev_line;
!     }
  
!   /* At this point each_line is NULL but next_line is not.  If we found
!      a candidate end-of-sequence point in the loop above, we can return
!      that (compatibility with a bug in the Intel compiler); otherwise,
!      assuming that we found the containing function for this address in
!      this compilation unit, return the first line we have a number for
!      (compatibility with GCC 2.95).  */
!   if (*filename_ptr == NULL && function != NULL)
!     {
!       *filename_ptr = next_line->filename;
!       *linenumber_ptr = next_line->line;
!       return TRUE;
      }
  
    return FALSE;
--- 1495,1522 ----
  static bfd_boolean
  lookup_address_in_line_info_table (struct line_info_table *table,
  				   bfd_vma addr,
  				   const char **filename_ptr,
  				   unsigned int *linenumber_ptr)
  {
    /* Note: table->last_line should be a descendingly sorted list. */
!   struct line_info *each_line = table->last_line;
  
!   *filename_ptr = NULL;
!   if (!each_line)
      return FALSE;
  
!   while (addr < each_line->address)
      {
        each_line = each_line->prev_line;
!       if (!each_line)
! 	break;
  
!       if (each_line->address <= addr && !each_line->end_sequence)
! 	{
! 	  *filename_ptr = each_line->filename;
! 	  *linenumber_ptr = each_line->line;
! 	  return TRUE;
! 	}
      }
  
    return FALSE;
***************
*** 2298,2304 ****
    if (func_p && (function->tag == DW_TAG_inlined_subroutine))
      stash->inliner_chain = function;
    line_p = lookup_address_in_line_info_table (unit->line_table, addr,
! 					      function, filename_ptr,
  					      linenumber_ptr);
    return line_p || func_p;
  }
--- 2233,2239 ----
    if (func_p && (function->tag == DW_TAG_inlined_subroutine))
      stash->inliner_chain = function;
    line_p = lookup_address_in_line_info_table (unit->line_table, addr,
! 					      filename_ptr,
  					      linenumber_ptr);
    return line_p || func_p;
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]