public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: "Steinar H. Gunderson" <sesse@google.com>
Cc: Nick Clifton <nickc@redhat.com>,
	binutils@sourceware.org, sesse@chromium.org
Subject: Re: [PATCH] Add a trie to map quickly from address range to compilation unit.
Date: Thu, 24 Mar 2022 15:52:27 +1030	[thread overview]
Message-ID: <YjwAEy5hY4/yzBSc@squeak.grove.modra.org> (raw)
In-Reply-To: <YjueFJBHo9aP0Vlf@google.com>

On Wed, Mar 23, 2022 at 11:24:20PM +0100, Steinar H. Gunderson via Binutils wrote:
> But I noticed something else that's probably not good in the existing
> code; the “found” variable leaks out of the loop from the last iteration
> (only). So if you find a match without a line number of the
> second-to-last compilation unit but not in the last, found = false on
> return, but if you find a similar match in the last compilation unit,
> found = true.
> 
> I suppose this isn't intentional, but what is the intention? Should
> there be a “found = false;” before the test on *linenumber_ptr?

Huh, I remember looking at this code a while ago and finding it
confusing.  I think the code would be clearer, and behave the same on
normal line number info with the following patch:

	* dwarf2.c (_bfd_dwarf2_find_nearest_line): Simplify setting of
	"found" in loop checking previous comp units with
	comp_unit_contains_address.

diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index 8b5ac6012e1..ca8403da6da 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -5195,16 +5195,16 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd,
 
       for (each = stash->f.all_comp_units; each; each = each->next_unit)
 	{
-	  bfd_vma range = (bfd_vma) -1;
-
-	  found = ((each->arange.high == 0
-		    || comp_unit_contains_address (each, addr))
-		   && (range = (comp_unit_find_nearest_line
-				(each, addr, &local_filename,
-				 &local_function, &local_linenumber,
-				 &local_discriminator))) != 0);
-	  if (found)
+	  bfd_vma range;
+
+	  if ((each->arange.high == 0
+	       || comp_unit_contains_address (each, addr))
+	      && (range = (comp_unit_find_nearest_line
+			   (each, addr, &local_filename,
+			    &local_function, &local_linenumber,
+			    &local_discriminator))) != 0)
 	    {
+	      found = true;
 	      /* PRs 15935 15994: Bogus debug information may have provided us
 		 with an erroneous match.  We attempt to counter this by
 		 selecting the match that has the smallest address range
@@ -5231,11 +5231,8 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd,
 	    }
 	}
 
-      if (* linenumber_ptr)
-	{
-	  found = true;
-	  goto done;
-	}
+      if (found)
+	goto done;
     }
 
   /* Read each remaining comp. units checking each as they are read.  */

-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2022-03-24  5:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21  9:40 Steinar H. Gunderson
2022-03-23 14:14 ` Nick Clifton
2022-03-23 15:53   ` Steinar H. Gunderson
2022-03-23 22:24   ` Steinar H. Gunderson
2022-03-24  5:22     ` Alan Modra [this message]
2022-03-24  8:01       ` Steinar H. Gunderson
2022-03-24 23:30         ` Alan Modra
2022-03-25  0:01           ` Steinar H. Gunderson
2022-03-28 10:19           ` Jan Beulich
2022-03-28 23:47             ` Alan Modra
2022-03-29  6:07               ` Jan Beulich
2022-03-31  6:21                 ` Steinar H. Gunderson
2022-04-03 11:39                   ` Alan Modra
2022-04-04  7:29                     ` Steinar H. Gunderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YjwAEy5hY4/yzBSc@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=nickc@redhat.com \
    --cc=sesse@chromium.org \
    --cc=sesse@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).