RFA: Fixing incorrect DWARF2 DW_AT_location values in targets that use LEAF_REG_REMAP

Nick Clifton nickc@redhat.com
Wed Apr 26 19:57:00 GMT 2006

Hi Guys,

  We recently found a bug with the DWARF2 debug info that is being
  generated by GCC for some targets.  For example if this test code,
  taken from the GDB testcase gdb.base/store.c, is compiled for a
  SPARC target:

    extern short add_short (register short u, register short v);
    short wack_short (register short u, register short v)
      register short l = u, r = v;
      l = add_short (l, r);
      return l + r;

  then the .debug_info produced by GCC will claim that the local
  variables l and r are both held in, or relative to, register 7:

   <2><398>: Abbrev Number: 6 (DW_TAG_variable)
     DW_AT_name        : l	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 77	
     DW_AT_type        : <111>	
     DW_AT_location    : 2 byte block: 77 76 	(DW_OP_breg7: -10)
   <2><3a4>: Abbrev Number: 6 (DW_TAG_variable)
     DW_AT_name        : r	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 77	
     DW_AT_type        : <111>	
     DW_AT_location    : 1 byte block: 57 	(DW_OP_reg7)

  It turns out that this problem happens when a target defines the
  LEAF_REG_REMAP macro.  The code in dwarf2out.c that uses the macro
  does not check to see if the remapped register number is valid.  So,
  in the test above for example the variable 'l' instead of being
  relative to the frame pointer (register 30) was taken to be relative
  to register -1 !

  The attached patch fixes this problem by adding code to check the
  return value from LEAR_REG_REMAP and only using it if is not -1.

  Checked by building a sparc-elf toolchain and regression testing the
  GDB testsuite.

  Is this patch OK to apply ?


2006-04-26  Nick Clifton  <nickc@redhat.com>

	* dwarf2out.c (dbx_reg_number): Check return value from
	LEAF_REG_REMAP and only use it if it is valid.
	(multiple_reg_loc_descriptor): Likewise.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: dwarf2out.c.patch
Type: text/x-patch
Size: 836 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20060426/14e680a0/attachment.bin>

More information about the Gcc-patches mailing list