[2/8] Record explicit block ranges from dwarf2read.c

Message ID 20180625234434.5c3913fa@pinnacle.lan
State New, archived
Headers

Commit Message

Kevin Buettner June 26, 2018, 6:44 a.m. UTC
  This change sets BLOCK_RANGES for the block under consideration by
calling make_blockranges().  This action is performed in
dwarf2_record_block_ranges().

It should be noted that dwarf2_record_block_ranges() already does some
recording of the range via a call to record_block_range().  The ranges
recorded in that fashion end up in the address map associated with the
blockvector for the compilation unit's symtab.  Given an address, the
addrmap provides a fast way of finding the block containing that
address.  The address map does not, however, provide a convenient way
of determining which address ranges make up a particular block.

While reading a set of ranges, a vector of pairs is used to collect
the starting and ending addresses for each range in the block.  Once
all of the ranges for a block have been collected, make_blockranges()
is called to fill in BLOCK_RANGES for the block.

The ranges are stored for the block in the order that they're read
from the debug info.  For DWARF, the starting address of the first
range of the block will be the entry pc in cases where DW_AT_entry_pc
is not present.  (Well, that would ideally be the case.  At the moment
DW_AT_entry_pc is not being handled.)

gdb/ChangeLog:
    
    	* dwarf2read.c (dwarf2_record_block_ranges): Fill in BLOCK_RANGES
    	for block.
---
 gdb/dwarf2read.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Simon Marchi Aug. 1, 2018, 1:40 a.m. UTC | #1
On 2018-06-26 02:44 AM, Kevin Buettner wrote:
> This change sets BLOCK_RANGES for the block under consideration by
> calling make_blockranges().  This action is performed in
> dwarf2_record_block_ranges().
> 
> It should be noted that dwarf2_record_block_ranges() already does some
> recording of the range via a call to record_block_range().  The ranges
> recorded in that fashion end up in the address map associated with the
> blockvector for the compilation unit's symtab.  Given an address, the
> addrmap provides a fast way of finding the block containing that
> address.  The address map does not, however, provide a convenient way
> of determining which address ranges make up a particular block.
> 
> While reading a set of ranges, a vector of pairs is used to collect
> the starting and ending addresses for each range in the block.  Once
> all of the ranges for a block have been collected, make_blockranges()
> is called to fill in BLOCK_RANGES for the block.
> 
> The ranges are stored for the block in the order that they're read
> from the debug info.  For DWARF, the starting address of the first
> range of the block will be the entry pc in cases where DW_AT_entry_pc
> is not present.  (Well, that would ideally be the case.  At the moment
> DW_AT_entry_pc is not being handled.)
> 
> gdb/ChangeLog:
>     
>     	* dwarf2read.c (dwarf2_record_block_ranges): Fill in BLOCK_RANGES
>     	for block.
> ---
>  gdb/dwarf2read.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 4ad0527..2f0f9b9 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -14722,6 +14722,7 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
>        unsigned long offset = (DW_UNSND (attr)
>  			      + (need_ranges_base ? cu->ranges_base : 0));
>  
> +      std::vector<std::pair<CORE_ADDR, CORE_ADDR>> blockvec;
>        dwarf2_ranges_process (offset, cu,
>  	[&] (CORE_ADDR start, CORE_ADDR end)
>  	{
> @@ -14730,7 +14731,10 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
>  	  start = gdbarch_adjust_dwarf2_addr (gdbarch, start);
>  	  end = gdbarch_adjust_dwarf2_addr (gdbarch, end);
>  	  record_block_range (block, start, end - 1);
> +	  blockvec.push_back (std::make_pair (start, end));

A real small nit, using

  blockvec.emplace_back (start, end);

would avoid some unnecessary copying.  Otherwise, it LGTM.

Simon
  

Patch

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4ad0527..2f0f9b9 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -14722,6 +14722,7 @@  dwarf2_record_block_ranges (struct die_info *die, struct block *block,
       unsigned long offset = (DW_UNSND (attr)
 			      + (need_ranges_base ? cu->ranges_base : 0));
 
+      std::vector<std::pair<CORE_ADDR, CORE_ADDR>> blockvec;
       dwarf2_ranges_process (offset, cu,
 	[&] (CORE_ADDR start, CORE_ADDR end)
 	{
@@ -14730,7 +14731,10 @@  dwarf2_record_block_ranges (struct die_info *die, struct block *block,
 	  start = gdbarch_adjust_dwarf2_addr (gdbarch, start);
 	  end = gdbarch_adjust_dwarf2_addr (gdbarch, end);
 	  record_block_range (block, start, end - 1);
+	  blockvec.push_back (std::make_pair (start, end));
 	});
+
+      BLOCK_RANGES(block) = make_blockranges (objfile, blockvec);
     }
 }