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

Re: -var-update and address changes


Shouldn't the call to var->root->lang->value_of_root down at the bottom of value_of_root take care of fetching the new value? You don't want to discard the old varobj unless you have to, because if the varobj represents a structure or pointer to a structure and the user has fetched any children, or changed the format, or whatever, you will lose that state.

Also, I must be missing something this morning, but I can't see any difference between your two examples.

Jim

On May 2, 2006, at 6:40 AM, Vladimir Prus wrote:

On Tuesday 02 May 2006 17:14, Nick Roberts wrote:
Vladimir Prus writes:
On Friday 14 April 2006 23:49, Jim Ingham wrote:
Note as an aside, that we had to add another varobj type which is
evaluated in the selected frame, whatever that happens to be. That
was useful for a general "variable inspector" window. People wanted
to put some expression there, and have it re-evaluated in the topmost
frame whenever they stopped. So we added that functionality. But
that is clearly distinct from what the "*" varobj type is supposed to
mean.

Hi Jim,
is this "variable inspector" the same thing that's called "watches" in
other IDEs? Well, I really wish that gdb did support variable objects
that are reevaluated in the current frame. As it stands now, I have to
re-create variable objects on each step.

Assuming some ambiguity with current/selected, have you tried (not documented):

"-var-create - @ NAME"

which behaves a bit differently to "-var-create - * NAME".

Wow, that's exactly what I'm looking for. Except that it's buggy :-( When I have code like this:

  int foo()
  {
      long i = 15;
      printf("foo\n");
  }

  int main()
  {
    int i = 5;
    printf("hi 1\n");
    foo();
  }

and I use

-var-create I @ i

right before call to 'foo()', then when I enter 'foo', -var-update correctly
notices the change in value and in type. However, when I have:


  int foo()
  {
      long i = 15;
      printf("foo\n");
  }

  int main()
  {
    int i = 5;
    printf("hi 1\n");
    foo();
  }

then -var-update inside 'foo' does not report anything and
-var-evaluate-expression still reports the value of 'i' from 'main'. Here's
the faulty code (varobj.c: value_of_root):


    tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
			       USE_SELECTED_FRAME);
     if (tmp_var == NULL)
	{
	  return NULL;
	}
     new_type = varobj_get_type (tmp_var);
     if (strcmp (old_type, new_type) == 0)
	{
	  varobj_delete (tmp_var, NULL, 0);
	  *type_changed = 0;
	}
     else

In other words, if the type of 'i' in the current frame happens to be the
same, the newly created varobj is immediately deleted. What about patch along
the following lines, that will create new varobj even if type is the same?


@@ -1641,28 +1741,14 @@
 	  return NULL;
 	}
       new_type = varobj_get_type (tmp_var);
-      if (strcmp (old_type, new_type) == 0)
-	{
-	  varobj_delete (tmp_var, NULL, 0);
-	  *type_changed = 0;
-	}
-      else
-	{
-	  if (*type_changed)
-	    {
-	      tmp_var->obj_name =
-		savestring (var->obj_name, strlen (var->obj_name));
-	      varobj_delete (var, NULL, 0);
-	    }
-	  else
-	    {
-	      tmp_var->obj_name = varobj_gen_name ();
-	    }
-	  install_variable (tmp_var);
-	  *var_handle = tmp_var;
-	  var = *var_handle;
-	  *type_changed = 1;
-	}
+      *type_changed = (strcmp (old_type, new_type) != 0);
+
+      tmp_var->obj_name =
+          savestring (var->obj_name, strlen (var->obj_name));
+      varobj_delete (var, NULL, 0);
+      install_variable (tmp_var);
+      *var_handle = tmp_var;
+      var = *var_handle;
     }

- Volodya



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