PATCH: ld/2338: objdump -d -l doesn't work correctly

Alan Modra amodra@bigpond.net.au
Mon Mar 6 04:51:00 GMT 2006


On Sun, Mar 05, 2006 at 05:37:29PM -0800, H. J. Lu wrote:
> On Mon, Mar 06, 2006 at 10:11:30AM +1030, Alan Modra wrote:
> > Hmm, I see there isn't any real need for the outer loop in
> > add_line_info.  I'll make a follow-up patch after you commit this one.
> 
> I checked in the updated patch with your change.
> 

OK, here's the outer loop removal.  Fairly obvious, really.  The only
time we do anything but break out of the outer loop immediately is the
"abnormal and hard" case where we search for a new lcl_head.  On
entering the loop again, the new lcl_head must match one of the
"abnormal but easy" cases (which I've merged), so we can simply perform
the "abnormal but easy" actions in the "abnormal and hard" branch.

	* dwarf2.c: Formatting.
	(add_line_info): Remove outer loop.

Index: bfd/dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.85
diff -c -p -r1.85 dwarf2.c
*** bfd/dwarf2.c	6 Mar 2006 01:36:52 -0000	1.85
--- bfd/dwarf2.c	6 Mar 2006 04:48:00 -0000
***************
*** 1,6 ****
  /* DWARF 2 support.
     Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
!    2004, 2005 Free Software Foundation, Inc.
  
     Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
     (gavin@cygnus.com).
--- 1,6 ----
  /* DWARF 2 support.
     Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
!    2004, 2005, 2006 Free Software Foundation, Inc.
  
     Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
     (gavin@cygnus.com).
*************** read_abbrevs (bfd *abfd, bfd_uint64_t of
*** 493,513 ****
  	      amt *= sizeof (struct attr_abbrev);
  	      tmp = bfd_realloc (cur_abbrev->attrs, amt);
  	      if (tmp == NULL)
! 	        {
! 	          size_t i;
  
! 	          for (i = 0; i < ABBREV_HASH_SIZE; i++)
! 	            {
! 	            struct abbrev_info *abbrev = abbrevs[i];
! 
! 	            while (abbrev)
! 	              {
! 	                free (abbrev->attrs);
! 	                abbrev = abbrev->next;
! 	              }
! 	            }
! 	          return NULL;
! 	        }
  	      cur_abbrev->attrs = tmp;
  	    }
  
--- 493,513 ----
  	      amt *= sizeof (struct attr_abbrev);
  	      tmp = bfd_realloc (cur_abbrev->attrs, amt);
  	      if (tmp == NULL)
! 		{
! 		  size_t i;
! 
! 		  for (i = 0; i < ABBREV_HASH_SIZE; i++)
! 		    {
! 		      struct abbrev_info *abbrev = abbrevs[i];
  
! 		      while (abbrev)
! 			{
! 			  free (abbrev->attrs);
! 			  abbrev = abbrev->next;
! 			}
! 		    }
! 		  return NULL;
! 		}
  	      cur_abbrev->attrs = tmp;
  	    }
  
*************** read_abbrevs (bfd *abfd, bfd_uint64_t of
*** 533,539 ****
  	 for the next compile unit) or if the end of the abbreviation
  	 table is reached.  */
        if ((unsigned int) (abbrev_ptr - stash->dwarf_abbrev_buffer)
! 	    >= stash->dwarf_abbrev_size)
  	break;
        abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
        abbrev_ptr += bytes_read;
--- 533,539 ----
  	 for the next compile unit) or if the end of the abbreviation
  	 table is reached.  */
        if ((unsigned int) (abbrev_ptr - stash->dwarf_abbrev_buffer)
! 	  >= stash->dwarf_abbrev_size)
  	break;
        abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
        abbrev_ptr += bytes_read;
*************** add_line_info (struct line_info_table *t
*** 813,868 ****
  
       Note: we may receive duplicate entries from 'decode_line_info'.  */
  
!   while (1)
!     if (!table->last_line
! 	|| new_line_sorts_after (info, table->last_line))
!       {
! 	/* Normal case: add 'info' to the beginning of the list */
! 	info->prev_line = table->last_line;
! 	table->last_line = info;
! 
! 	/* lcl_head: initialize to head a *possible* sequence at the end.  */
! 	if (!table->lcl_head)
! 	  table->lcl_head = info;
! 	break;
!       }
!     else if (!table->lcl_head->prev_line
! 	     && !new_line_sorts_after (info, table->lcl_head))
!       {
! 	/* Abnormal but easy: lcl_head is 1) at the *end* of the line
! 	   list and 2) the head of 'info'.  */
! 	info->prev_line = NULL;
! 	table->lcl_head->prev_line = info;
! 	break;
!       }
!     else if (table->lcl_head->prev_line
! 	     && !new_line_sorts_after (info, table->lcl_head)
! 	     && new_line_sorts_after (info, table->lcl_head->prev_line))
!       {
! 	/* Abnormal but easy: lcl_head is 1) in the *middle* of the line
! 	   list and 2) the head of 'info'.  */
! 	info->prev_line = table->lcl_head->prev_line;
! 	table->lcl_head->prev_line = info;
! 	break;
!       }
!     else
!       {
! 	/* Abnormal and hard: Neither 'last_line' nor 'lcl_head' are valid
! 	   heads for 'info'.  Reset 'lcl_head' and repeat.  */
! 	struct line_info* li2 = table->last_line; /* always non-NULL */
! 	struct line_info* li1 = li2->prev_line;
  
! 	while (li1)
! 	  {
! 	    if (!new_line_sorts_after (info, li2)
! 		&& new_line_sorts_after (info, li1))
! 	      break;
  
! 	    li2 = li1; /* always non-NULL */
! 	    li1 = li1->prev_line;
! 	  }
! 	table->lcl_head = li2;
!       }
  }
  
  /* Extract a fully qualified filename from a line info table.
--- 813,857 ----
  
       Note: we may receive duplicate entries from 'decode_line_info'.  */
  
!   if (!table->last_line
!       || new_line_sorts_after (info, table->last_line))
!     {
!       /* Normal case: add 'info' to the beginning of the list */
!       info->prev_line = table->last_line;
!       table->last_line = info;
! 
!       /* lcl_head: initialize to head a *possible* sequence at the end.  */
!       if (!table->lcl_head)
! 	table->lcl_head = info;
!     }
!   else if (!new_line_sorts_after (info, table->lcl_head)
! 	   && (!table->lcl_head->prev_line
! 	       || new_line_sorts_after (info, table->lcl_head->prev_line)))
!     {
!       /* Abnormal but easy: lcl_head is the head of 'info'.  */
!       info->prev_line = table->lcl_head->prev_line;
!       table->lcl_head->prev_line = info;
!     }
!   else
!     {
!       /* Abnormal and hard: Neither 'last_line' nor 'lcl_head' are valid
! 	 heads for 'info'.  Reset 'lcl_head'.  */
!       struct line_info* li2 = table->last_line; /* always non-NULL */
!       struct line_info* li1 = li2->prev_line;
  
!       while (li1)
! 	{
! 	  if (!new_line_sorts_after (info, li2)
! 	      && new_line_sorts_after (info, li1))
! 	    break;
  
! 	  li2 = li1; /* always non-NULL */
! 	  li1 = li1->prev_line;
! 	}
!       table->lcl_head = li2;
!       info->prev_line = table->lcl_head->prev_line;
!       table->lcl_head->prev_line = info;
!     }
  }
  
  /* Extract a fully qualified filename from a line info table.
*************** decode_line_info (struct comp_unit *unit
*** 1192,1203 ****
  		      amt *= sizeof (struct fileinfo);
  		      tmp = bfd_realloc (table->files, amt);
  		      if (tmp == NULL)
! 		        {
  			  free (table->files);
  			  free (table->dirs);
  			  free (filename);
  			  return NULL;
! 		        }
  		      table->files = tmp;
  		    }
  		  table->files[table->num_files].name = cur_file;
--- 1181,1192 ----
  		      amt *= sizeof (struct fileinfo);
  		      tmp = bfd_realloc (table->files, amt);
  		      if (tmp == NULL)
! 			{
  			  free (table->files);
  			  free (table->dirs);
  			  free (filename);
  			  return NULL;
! 			}
  		      table->files = tmp;
  		    }
  		  table->files[table->num_files].name = cur_file;
*************** read_rangelist (struct comp_unit *unit, 
*** 1609,1615 ****
  	return;
      }
    ranges_ptr = unit->stash->dwarf_ranges_buffer + offset;
!     
    for (;;)
      {
        bfd_vma low_pc;
--- 1598,1604 ----
  	return;
      }
    ranges_ptr = unit->stash->dwarf_ranges_buffer + offset;
! 
    for (;;)
      {
        bfd_vma low_pc;
*************** scan_unit_for_symbols (struct comp_unit 
*** 1826,1832 ****
  						 attr.u.blk->data + 1);
  			}
  		      break;
! 		    
  		    default:
  		      break;
  		    }
--- 1815,1821 ----
  						 attr.u.blk->data + 1);
  			}
  		      break;
! 
  		    default:
  		      break;
  		    }
*************** _bfd_dwarf2_cleanup_debug_info (bfd *abf
*** 2784,2804 ****
        size_t i;
  
        for (i = 0; i < ABBREV_HASH_SIZE; i++)
!         {
!           struct abbrev_info *abbrev = abbrevs[i];
  
!           while (abbrev)
!             {
!               free (abbrev->attrs);
!               abbrev = abbrev->next;
!             }
!         }
  
        if (each->line_table)
!         {
!           free (each->line_table->dirs);
!           free (each->line_table->files);
!         }
      }
  
    free (stash->dwarf_abbrev_buffer);
--- 2773,2793 ----
        size_t i;
  
        for (i = 0; i < ABBREV_HASH_SIZE; i++)
! 	{
! 	  struct abbrev_info *abbrev = abbrevs[i];
  
! 	  while (abbrev)
! 	    {
! 	      free (abbrev->attrs);
! 	      abbrev = abbrev->next;
! 	    }
! 	}
  
        if (each->line_table)
! 	{
! 	  free (each->line_table->dirs);
! 	  free (each->line_table->files);
! 	}
      }
  
    free (stash->dwarf_abbrev_buffer);



More information about the Binutils mailing list