gdb: change blockvector::contains() to handle blockvectors with "holes"

This commit slightly changes the logic in blockvector::contains()
to handle a case where the blockvector contains blocks with disjoint
regions (see the comment in blockvector::contains for details).

This change may potentially change GDB's behavior. It is not clear to me
if there was a reason for blockvector_contains_pc() behaving differently
depending whether or not given blockvector contain a map. With this
change, blockvector::contains() return the same value regardless. The
reason for it is to make it work as expected also for "dynamic" code
created by JIT reader (and perhaps by Python in the future).

Note that for CUs created from DWARF, blockvectors have always a map set
so this change in behavior should not affect them. Running testsuite
on Linux x86_64 shown no regressions.

Finally, I was considering of making this change up in lookup method
but in the end decided to be bit more conservative because comment in
original find_block_in_blockvector() suggested that returning a static
block from there is an expected situation.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Jan Vrany
2025-11-28 13:47:02 +00:00
parent 116ea63b99
commit cc1fc6af41

View File

@@ -864,7 +864,34 @@ blockvector::lookup (CORE_ADDR addr) const
bool
blockvector::contains (CORE_ADDR addr) const
{
return lookup (addr) != nullptr;
auto b = lookup (addr);
if (b == nullptr)
return false;
/* Handle the case that the blockvector has no address map but still has
"holes". For example, consider the following blockvector:
B0 0x1000 - 0x4000 (global block)
B1 0x1000 - 0x4000 (static block)
B3 0x1000 - 0x2000
(hole)
B4 0x3000 - 0x4000
In this case, the above blockvector does not contain address 0x2500 but
lookup (0x2500) would return the blockvector's static block.
So here we check if the returned block is a static block and if yes, still
return false. However, if the blockvector contains no blocks other than
the global and static blocks and ADDR falls into the static block,
conservatively return true.
See comment in find_compunit_symtab_for_pc_sect, symtab.c.
Also, note that if the blockvector in the above example would contain
an address map, then lookup (0x2500) would return NULL instead of
the static block.
*/
return b != static_block () || num_blocks () == 2;
}
/* See block.h. */