[PATCHv2 4/7] gdb: move block range recording into its own function

Andrew Burgess
2025-08-01T09:00:38Z

Like the previous commit, this is a refactor that makes a later commit
in this series easier. The later commit improves GDB's ability to
debug optimised code. To do this I propose to "fix" the address
ranges of some inline blocks.

In order to know which blocks to fix, I need to record the end address
of inline blocks.

And so, I'd like to create a single common function where block ranges
are recorded, in a later commit I can then hook into this function to
record the block's end address(es). This commit sets up this single
common function.

The new function I'm adding dwarf2_record_single_block_range, takes a
currently unused argument unrel_high. This argument will be needed in
the later commit. I've added it now as this will allow the later
commit to be smaller and more focused. I only plan to push this
commit at the same time as the later, so I don't think adding
the (currently) unused argument is too much of a problem.

There should be no user visible change after this commit.
---
gdb/dwarf2/read.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index a68b1434e53..e553a47e970 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9845,6 +9845,20 @@ dwarf2_record_block_entry_pc (struct die_info *die, struct block *block,
}
}

+/* Helper function for dwarf2_record_block_ranges. This function records
+ the address range for a single BLOCK. LOW and HIGH are the block's
+ range, these addresses are inclusive, so LOW is the first address in
+ the range, and HIGH is the last address inside the range. UNREL_HIGH
+ is the unrelocated version of HIGH. */
+
+static void
+dwarf2_record_single_block_range (struct dwarf2_cu *cu, struct block *block,
+ CORE_ADDR low, CORE_ADDR high,
+ unrelocated_addr unrel_high)
+{
+ cu->get_builder ()->record_block_range (block, low, high);
+}
+
/* Record the address ranges for BLOCK, offset by BASEADDR, as given
in DIE. Also set the entry PC for BLOCK. */

@@ -9913,7 +9927,8 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
in GDB's internal structures, it's just more to search
through, and it will never match any address. */
if (high >= low)
- cu->get_builder ()->record_block_range (block, low, high);
+ dwarf2_record_single_block_range (cu, block, low, high,
+ unrel_high);
}

attr = dwarf2_attr (die, DW_AT_ranges, cu);
@@ -9943,8 +9958,8 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
{
CORE_ADDR abs_start = per_objfile->relocate (start);
CORE_ADDR abs_end = per_objfile->relocate (end);
- cu->get_builder ()->record_block_range (block, abs_start,
- abs_end - 1);
+ dwarf2_record_single_block_range (cu, block, abs_start,
+ abs_end - 1, end);
blockvec.emplace_back (abs_start, abs_end);
});

--
2.47.1