This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc] Skip empty range entries in DW_AT_ranges


Hello,

when using GDB to debug an ARM Linux system image under QEMU, we noticed
a problem with GDB running into an internal error in inline-frame.c:

inline-frame.c:169: internal-error: inline_frame_this_id:
Assertion `!frame_id_eq (*this_id, outer_frame_id)' failed.

Looking into this, the problem turns out to be that in the vmlinux image,
a bunch of functions that were compiled into "exit" sections are thrown away
at link time, but debug information describing those is still present.
However, all addresses refering to code in those sections now points to 0.
This results in a lot of functions being represented as living in address
ranges 0 .. 0 (or actually 1 .. 1 as the linker attempts to clean up).

Now, according to the DWARF standard, such empty ranges have no effect
(and should be ignored by the debugger). i However, GDB does not do so.
This results in many source files apparently covering address ranges from
1 to 0xc???????, which causes GDB to mistakenly interpret the initial PC
as belonging to a function instance inlined into one of those discarded
exit functions.  This in the end causes the failed assertion.

The fix should be to simply ignore empty range entries as suggested by
the DWARF standard.  The patch below does so, which fixes the problems
we were seeing.  In addition, the patch adds code to complain about
*inverted* ranges (i.e. beginning > end), which are not allowed at all
according to DWARF (I haven't actually seen this complaint).

Fully tested on i386-linux.

Any comments?  I'm planning on committing this in a couple of days.

Thanks,
Ulrich



ChangeLog:

	* dwarf2read.c (dwarf2_ranges_read): Skip empty range entries.
	Complain about inverted range entries.
	(dwarf2_record_block_ranges): Likewise.

Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.496
diff -u -p -r1.496 dwarf2read.c
--- gdb/dwarf2read.c	25 Jan 2011 17:25:12 -0000	1.496
+++ gdb/dwarf2read.c	3 Feb 2011 19:02:27 -0000
@@ -5863,10 +5863,22 @@ dwarf2_ranges_read (unsigned offset, COR
 	  return 0;
 	}
 
+      if (range_beginning > range_end)
+	{
+	  /* Inverted range entries are invalid.  */
+	  complaint (&symfile_complaints,
+		     _("Invalid .debug_ranges data (inverted range)"));
+	  return 0;
+	}
+
+      /* Empty range entries have no effect.  */
+      if (range_beginning == range_end)
+	continue;
+
       range_beginning += base;
       range_end += base;
 
-      if (ranges_pst != NULL && range_beginning < range_end)
+      if (ranges_pst != NULL)
 	addrmap_set_empty (objfile->psymtabs_addrmap,
 			   range_beginning + baseaddr,
 			   range_end - 1 + baseaddr,
@@ -6149,6 +6161,19 @@ dwarf2_record_block_ranges (struct die_i
                   return;
                 }
 
+	      if (start > end)
+		{
+		  /* Inverted range entries are invalid.  */
+		  complaint (&symfile_complaints,
+			     _("Invalid .debug_ranges data "
+			       "(inverted range)"));
+		  return;
+		}
+
+	      /* Empty range entries have no effect.  */
+	      if (start == end)
+		continue;
+
               record_block_range (block,
                                   baseaddr + base + start,
                                   baseaddr + base + end - 1);
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]