Assert on lval_register

Message ID 20161206101513.GA28789@E107787-LIN
State New, archived
Headers

Commit Message

Yao Qi Dec. 6, 2016, 10:15 a.m. UTC
  On 16-11-30 22:16:37, Ulrich Weigand wrote:
 
> > This also reveals a design issue in frame_register_unwind, that is
> > arguments addrp and realnump are mutually exclusive, we either use
> > addrp (for lval_memory), or use realnump (for lval_register).  This
> > can be done in a separate patch.
> 
> I think we should simply get rid of frame_register_unwind.  Callers
> should be changed to use frame_unwind_register_value directly, and
> just operate on the value.
> 

Yeah, that is what I was trying to do, but we should be careful on
the value management in the end of frame_register_unwind,

  /* Dispose of the new value.  This prevents watchpoints from
     trying to watch the saved frame pointer.  */
  release_value (value);
  value_free (value);

> >    *lvalp = VALUE_LVAL (value);
> >    *addrp = value_address (value);
> > -  *realnump = VALUE_REGNUM (value);
> > +  if (*lvalp == lval_register)
> > +    *realnump = VALUE_REGNUM (value);
> 
> But as long as the above change is not done yet, maybe we ought to
> at least provide a defined value (e.g. -1), to avoid callers maybe
> making use of uninitialized variables?
> 

OK, how about the patch below?
  

Comments

Yao Qi Dec. 6, 2016, 2:26 p.m. UTC | #1
On 16-12-06 14:13:28, Ulrich Weigand wrote:
> 
> > OK, how about the patch below?
> 
> Looks good to me.
> 

Patch is pushed in.
  

Patch

diff --git a/gdb/frame.c b/gdb/frame.c
index 5414cb3..00001bc 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1107,7 +1107,10 @@  frame_register_unwind (struct frame_info *frame, int regnum,
   *unavailablep = !value_entirely_available (value);
   *lvalp = VALUE_LVAL (value);
   *addrp = value_address (value);
-  *realnump = VALUE_REGNUM (value);
+  if (*lvalp == lval_register)
+    *realnump = VALUE_REGNUM (value);
+  else
+    *realnump = -1;
 
   if (bufferp)
     {
diff --git a/gdb/value.c b/gdb/value.c
index cc291cf..022900f 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1576,12 +1576,14 @@  deprecated_value_internalvar_hack (struct value *value)
 struct frame_id *
 deprecated_value_next_frame_id_hack (struct value *value)
 {
+  gdb_assert (value->lval == lval_register);
   return &value->location.reg.next_frame_id;
 }
 
 int *
 deprecated_value_regnum_hack (struct value *value)
 {
+  gdb_assert (value->lval == lval_register);
   return &value->location.reg.regnum;
 }