[PATCH] Add a trie to map quickly from address range to compilation unit.
Alan Modra
amodra@gmail.com
Thu Mar 24 05:22:27 GMT 2022
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
More information about the Binutils
mailing list