This is the mail archive of the gdb@sources.redhat.com 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]

Re: Gdb generates location list without DW_AT_frame_base


On Fri, Dec 31, 2004 at 11:57:34AM -0800, H. J. Lu wrote:
> On Thu, Dec 30, 2004 at 07:35:13PM -0500, Daniel Berlin wrote:
> > 
> > 
> > On Thu, 30 Dec 2004, H. J. Lu wrote:
> > 
> > >On Thu, Dec 30, 2004 at 03:56:33PM -0500, Daniel Berlin wrote:
> > >>
> > >>>And what's in the location lists?  If it's DW_OP_fbreg, then I presume
> > >>>it's a GCC bug.  According to my reading of the DWARF spec, anyway.
> > >>It is.
> > >>
> > >>I added code to tell it when not to use fbreg, but i only told it not to
> > >>use fbreg in the location expression when we were outputting the
> > >>frame_base attribute.
> > >>
> > >>However, it appears we don't output a frame base attribute for external
> > >>procedures, so we need to tell it it can't use if we don't have a frame
> > >>base attribute.
> > >>
> > >>You just need to change when loc_descriptor is called with a second
> > >>parameter of true/1 to fix this.
> > >
> > >Do you have a patch I can try?
> > 
> > This may not fix all of them, but it should help.
> 
> > Index: dwarf2out.c
> > ===================================================================
> > RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
> > retrieving revision 1.564
> > diff -u -p -r1.564 dwarf2out.c
> > --- dwarf2out.c	24 Dec 2004 05:23:07 -0000	1.564
> > +++ dwarf2out.c	31 Dec 2004 00:34:38 -0000
> > @@ -9980,6 +9980,7 @@ add_location_or_const_value_attribute (d
> >    rtx rtl;
> >    dw_loc_descr_ref descr;
> >    var_loc_list *loc_list;
> > +  bool can_use_fb = attr != DW_AT_frame_base && !DECL_EXTERNAL (decl);
> >  
> >    if (TREE_CODE (decl) == ERROR_MARK)
> >      return;
> > @@ -10049,7 +10050,7 @@ add_location_or_const_value_attribute (d
> >  	    varloc = NOTE_VAR_LOCATION (node->var_loc_note);
> >  	    add_loc_descr_to_loc_list (&list,
> >  				       loc_descriptor (varloc,
> > -						       attr != DW_AT_frame_base),
> > +						       can_use_fb),
> >  				       node->label, node->next->label, secname);
> >  	  }
> >  
> > @@ -10070,7 +10071,7 @@ add_location_or_const_value_attribute (d
> >  	    }
> >  	  add_loc_descr_to_loc_list (&list,
> >  				     loc_descriptor (varloc,
> > -						     attr != DW_AT_frame_base),
> > +						     can_use_fb),
> >  				     node->label, endname, secname);
> >  	}
> >  
> 
> There are several problems with this patch:
> 
> 1. It checks DECL_EXTERNAL. Did you mean TREE_PUBLIC?
> 2. It doesn't cover PARM_DECL nor RESULT_DECL.
> 3. For
> 

This patch seems to generate better debug info.


H.J.
--- dwarf2out.c.loc	2004-12-27 12:04:10.000000000 -0800
+++ dwarf2out.c	2004-12-31 12:10:01.400120743 -0800
@@ -3919,8 +3919,8 @@ static int is_based_loc (rtx);
 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode, bool);
 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
 static dw_loc_descr_ref loc_descriptor (rtx, bool);
-static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
-static dw_loc_descr_ref loc_descriptor_from_tree (tree);
+static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, bool, int);
+static dw_loc_descr_ref loc_descriptor_from_tree (tree, bool);
 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
 static tree field_type (tree);
 static unsigned int simple_type_align_in_bits (tree);
@@ -8815,7 +8815,7 @@ loc_descriptor (rtx rtl, bool can_use_fb
    the value of LOC.  */
 
 static dw_loc_descr_ref
-loc_descriptor_from_tree_1 (tree loc, int want_address)
+loc_descriptor_from_tree_1 (tree loc, bool can_use_fb, int want_address)
 {
   dw_loc_descr_ref ret, ret1;
   int have_address = 0;
@@ -8854,7 +8854,7 @@ loc_descriptor_from_tree_1 (tree loc, in
 	return 0;
 
       /* Otherwise, process the argument and look for the address.  */
-      return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
+      return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), can_use_fb, 1);
 
     case VAR_DECL:
       if (DECL_THREAD_LOCAL (loc))
@@ -8895,7 +8895,8 @@ loc_descriptor_from_tree_1 (tree loc, in
 
     case PARM_DECL:
       if (DECL_VALUE_EXPR (loc))
-	return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc), want_address);
+	return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc), can_use_fb,
+					   want_address);
       /* FALLTHRU */
 
     case RESULT_DECL:
@@ -8925,7 +8926,7 @@ loc_descriptor_from_tree_1 (tree loc, in
 
 	    /* Certain constructs can only be represented at top-level.  */
 	    if (want_address == 2)
-	      return loc_descriptor (rtl, true);
+	      return loc_descriptor (rtl, can_use_fb);
 
 	    mode = GET_MODE (rtl);
 	    if (MEM_P (rtl))
@@ -8933,18 +8934,19 @@ loc_descriptor_from_tree_1 (tree loc, in
 		rtl = XEXP (rtl, 0);
 		have_address = 1;
 	      }
-	    ret = mem_loc_descriptor (rtl, mode, true);
+	    ret = mem_loc_descriptor (rtl, mode, can_use_fb);
 	  }
       }
       break;
 
     case INDIRECT_REF:
-      ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
+      ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), can_use_fb, 0);
       have_address = 1;
       break;
 
     case COMPOUND_EXPR:
-      return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
+      return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), can_use_fb,
+					 want_address);
 
     case NOP_EXPR:
     case CONVERT_EXPR:
@@ -8952,7 +8954,8 @@ loc_descriptor_from_tree_1 (tree loc, in
     case VIEW_CONVERT_EXPR:
     case SAVE_EXPR:
     case MODIFY_EXPR:
-      return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
+      return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), can_use_fb,
+					 want_address);
 
     case COMPONENT_REF:
     case BIT_FIELD_REF:
@@ -8970,7 +8973,7 @@ loc_descriptor_from_tree_1 (tree loc, in
 	if (obj == loc)
 	  return 0;
 
-	ret = loc_descriptor_from_tree_1 (obj, 1);
+	ret = loc_descriptor_from_tree_1 (obj, can_use_fb, 1);
 	if (ret == 0
 	    || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
 	  return 0;
@@ -8978,7 +8981,8 @@ loc_descriptor_from_tree_1 (tree loc, in
 	if (offset != NULL_TREE)
 	  {
 	    /* Variable offset.  */
-	    add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
+	    add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, can_use_fb,
+							     0));
 	    add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
 	  }
 
@@ -9012,7 +9016,7 @@ loc_descriptor_from_tree_1 (tree loc, in
 	  return 0;
 	mode = GET_MODE (rtl);
 	rtl = XEXP (rtl, 0);
-	ret = mem_loc_descriptor (rtl, mode, true);
+	ret = mem_loc_descriptor (rtl, mode, can_use_fb);
 	have_address = 1;
 	break;
       }
@@ -9068,7 +9072,7 @@ loc_descriptor_from_tree_1 (tree loc, in
       if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
 	  && host_integerp (TREE_OPERAND (loc, 1), 0))
 	{
-	  ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
+	  ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), can_use_fb, 0);
 	  if (ret == 0)
 	    return 0;
 
@@ -9120,8 +9124,8 @@ loc_descriptor_from_tree_1 (tree loc, in
       goto do_binop;
 
     do_binop:
-      ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
-      ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
+      ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), can_use_fb, 0);
+      ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), can_use_fb, 0);
       if (ret == 0 || ret1 == 0)
 	return 0;
 
@@ -9143,7 +9147,7 @@ loc_descriptor_from_tree_1 (tree loc, in
       goto do_unop;
 
     do_unop:
-      ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
+      ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), can_use_fb, 0);
       if (ret == 0)
 	return 0;
 
@@ -9167,12 +9171,12 @@ loc_descriptor_from_tree_1 (tree loc, in
     case COND_EXPR:
       {
 	dw_loc_descr_ref lhs
-	  = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
+	  = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), can_use_fb, 0);
 	dw_loc_descr_ref rhs
-	  = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
+	  = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), can_use_fb, 0);
 	dw_loc_descr_ref bra_node, jump_node, tmp;
 
-	ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
+	ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), can_use_fb, 0);
 	if (ret == 0 || lhs == 0 || rhs == 0)
 	  return 0;
 
@@ -9242,9 +9246,9 @@ loc_descriptor_from_tree_1 (tree loc, in
 }
 
 static inline dw_loc_descr_ref
-loc_descriptor_from_tree (tree loc)
+loc_descriptor_from_tree (tree loc, bool can_use_fb)
 {
-  return loc_descriptor_from_tree_1 (loc, 2);
+  return loc_descriptor_from_tree_1 (loc, can_use_fb, 2);
 }
 
 /* Given a value, round it up to the lowest multiple of `boundary'
@@ -9980,6 +9984,7 @@ add_location_or_const_value_attribute (d
   rtx rtl;
   dw_loc_descr_ref descr;
   var_loc_list *loc_list;
+  bool can_use_fb;
 
   if (TREE_CODE (decl) == ERROR_MARK)
     return;
@@ -9987,6 +9992,17 @@ add_location_or_const_value_attribute (d
   gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
 	      || TREE_CODE (decl) == RESULT_DECL);
 
+  switch (TREE_CODE (decl))
+    {
+    default:
+      can_use_fb = attr != DW_AT_frame_base && !TREE_PUBLIC (decl);
+      break;
+     case PARM_DECL:
+     case RESULT_DECL:
+      can_use_fb = attr != DW_AT_frame_base && !TREE_PUBLIC (DECL_CONTEXT (decl));
+      break;
+    }
+
   /* See if we possibly have multiple locations for this variable.  */
   loc_list = lookup_decl_loc (decl);
 
@@ -10037,7 +10053,7 @@ add_location_or_const_value_attribute (d
 
       node = loc_list->first;
       varloc = NOTE_VAR_LOCATION (node->var_loc_note);
-      list = new_loc_list (loc_descriptor (varloc, attr != DW_AT_frame_base),
+      list = new_loc_list (loc_descriptor (varloc, can_use_fb),
 			   node->label, node->next->label, secname, 1);
       node = node->next;
 
@@ -10049,7 +10065,7 @@ add_location_or_const_value_attribute (d
 	    varloc = NOTE_VAR_LOCATION (node->var_loc_note);
 	    add_loc_descr_to_loc_list (&list,
 				       loc_descriptor (varloc,
-						       attr != DW_AT_frame_base),
+						       can_use_fb),
 				       node->label, node->next->label, secname);
 	  }
 
@@ -10070,7 +10086,7 @@ add_location_or_const_value_attribute (d
 	    }
 	  add_loc_descr_to_loc_list (&list,
 				     loc_descriptor (varloc,
-						     attr != DW_AT_frame_base),
+						     can_use_fb),
 				     node->label, endname, secname);
 	}
 
@@ -10086,7 +10102,7 @@ add_location_or_const_value_attribute (d
       return;
     }
 
-  descr = loc_descriptor_from_tree (decl);
+  descr = loc_descriptor_from_tree (decl, can_use_fb);
   if (descr)
     add_AT_location_description (die, attr, descr);
 }
@@ -10205,7 +10221,7 @@ add_bound_info (dw_die_ref subrange_die,
 	dw_die_ref ctx, decl_die;
 	dw_loc_descr_ref loc;
 
-	loc = loc_descriptor_from_tree (bound);
+	loc = loc_descriptor_from_tree (bound, false);
 	if (loc == NULL)
 	  break;
 
@@ -11331,7 +11347,7 @@ gen_subprogram_die (tree decl, dw_die_re
 
       if (cfun->static_chain_decl)
 	add_AT_location_description (subr_die, DW_AT_static_link,
-		 loc_descriptor_from_tree (cfun->static_chain_decl));
+		 loc_descriptor_from_tree (cfun->static_chain_decl, false));
     }
 
   /* Now output descriptions of the arguments for this function. This gets


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