[RFA] Handle DW_AT_ranges in partial_die_info::read

Tom Tromey tom@tromey.com
Sat Jun 23 00:15:00 GMT 2018


On x86-64 Fedora 28, with the system gcc (8.1.1), I got this failure
when running the gdb.gdb tests:

    (gdb) call catch_command_errors(execute_command, "python print(5)", 0)
    Cannot resolve function catch_command_errors to any overloaded instance

Debugging interactively showed that gdb was not finding debug info for
execute_command:

    (top-gdb) print execute_command
    $2 = {<text variable, no debug info>} 0x7ecec0 <execute_command(char const*, int)>

However, the DWARF was definitely there:

    [4d5a860]	subprogram
	    external	true
	    name	"execute_command"
	    decl_file	"../../binutils-gdb/gdb/top.c"
	    decl_line	540
	    decl_column	1
	    linkage_name	"_Z15execute_commandPKci"
	    ranges	0x429cfc..0x429d32, 0x7ecec0..0x7ed3d3
	    frame_base	0..0xffffffffffffffff:0 call_frame_cfa
	    GNU_all_call_sites	true
	    sibling	[4d5b890] structure_type

Debugging further showed that the DIE was being rejected by
load_partial_dies, because the partial DIE's "has_pc_info" flag was
not set.

This patch fixes the problem by changing partial_die_info::read to
recognize DW_AT_ranges.  I had filed this as PR symtab/23331.

Someday it would be good to unify the partial symtab and full symtab
DWARF readers.  That would make this sort of bug much less likely.

I am not completely sure this patch is correct.  Perhaps it's
necessary to arrange to pass the partial symtab into
dwarf2_ranges_read.

Also, I did not know how to write a standalone test case for this.  It
does fix a regression locally, though.

Tested by the buildbot.

gdb/ChangeLog
2018-06-22  Tom Tromey  <tom@tromey.com>

	PR symtab/23331:
	* dwarf2read.c (partial_die_info::read): Handle DW_AT_ranges.
---
 gdb/ChangeLog    |  5 +++++
 gdb/dwarf2read.c | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9539c87ca18..5cc427bd49b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-06-22  Tom Tromey  <tom@tromey.com>
+
+	PR symtab/23331:
+	* dwarf2read.c (partial_die_info::read): Handle DW_AT_ranges.
+
 2018-06-22  Alan Hayward  <alan.hayward@arm.com>
 
 	* regcache.c (readable_regcache::read_part): Fix asserts.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4ad05274064..8e5389c55b6 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -18424,6 +18424,25 @@ partial_die_info::read (const struct die_reader_specs *reader,
 	  if (cu->header.version >= 4 && attr_form_is_constant (&attr))
 		high_pc_relative = 1;
 	  break;
+	case DW_AT_ranges:
+	  {
+	    bool need_ranges_base = tag != DW_TAG_compile_unit;
+	    unsigned int ranges_offset = (DW_UNSND (&attr)
+					  + (need_ranges_base
+					     ? cu->ranges_base
+					     : 0));
+
+	    /* Value of the DW_AT_ranges attribute is the offset in
+	       the .debug_ranges section.  */
+	    if (dwarf2_ranges_read (ranges_offset, &lowpc, &highpc, cu,
+				    nullptr))
+	      {
+		has_low_pc_attr = 1;
+		has_high_pc_attr = 1;
+		high_pc_relative = 0;
+	      }
+	  }
+	  break;
 	case DW_AT_location:
           /* Support the .debug_loc offsets.  */
           if (attr_form_is_block (&attr))
-- 
2.17.1



More information about the Gdb-patches mailing list