gdbserver: avoid empty structs
[deliverable/binutils-gdb.git] / gdb / value.c
index c5b50c2ec59b8a8717b010a8958ed6a6634d243c..fae8b9847112cb1dc11f86c908e5bcfc59519b05 100644 (file)
@@ -1,6 +1,6 @@
 /* Low level packing and unpacking of values for GDB, the GNU Debugger.
 
-   Copyright (C) 1986-2000, 2002-2012 Free Software Foundation, Inc.
+   Copyright (C) 1986-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -543,9 +543,7 @@ value_available_contents_eq (const struct value *val1, int offset1,
 {
   int idx1 = 0, idx2 = 0;
 
-  /* This routine is used by printing routines, where we should
-     already have read the value.  Note that we only know whether a
-     value chunk is available if we've tried to read it.  */
+  /* See function description in value.h.  */
   gdb_assert (!val1->lazy && !val2->lazy);
 
   while (length > 0)
@@ -811,7 +809,12 @@ value_parent (struct value *value)
 void
 set_value_parent (struct value *value, struct value *parent)
 {
+  struct value *old = value->parent;
+
   value->parent = parent;
+  if (parent != NULL)
+    value_incref (parent);
+  value_free (old);
 }
 
 gdb_byte *
@@ -841,7 +844,6 @@ value_actual_type (struct value *value, int resolve_simple_types,
                   int *real_type_found)
 {
   struct value_print_options opts;
-  struct value *target;
   struct type *result;
 
   get_user_print_options (&opts);
@@ -851,8 +853,12 @@ value_actual_type (struct value *value, int resolve_simple_types,
   result = value_type (value);
   if (opts.objectprint)
     {
-      if (TYPE_CODE (result) == TYPE_CODE_PTR
+      /* If result's target type is TYPE_CODE_STRUCT, proceed to
+        fetch its rtti type.  */
+      if ((TYPE_CODE (result) == TYPE_CODE_PTR
          || TYPE_CODE (result) == TYPE_CODE_REF)
+         && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
+            == TYPE_CODE_STRUCT)
         {
           struct type *real_type;
 
@@ -1034,15 +1040,14 @@ value_contents_equal (struct value *val1, struct value *val2)
 {
   struct type *type1;
   struct type *type2;
-  int len;
 
   type1 = check_typedef (value_type (val1));
   type2 = check_typedef (value_type (val2));
-  len = TYPE_LENGTH (type1);
-  if (len != TYPE_LENGTH (type2))
+  if (TYPE_LENGTH (type1) != TYPE_LENGTH (type2))
     return 0;
 
-  return (memcmp (value_contents (val1), value_contents (val2), len) == 0);
+  return (memcmp (value_contents (val1), value_contents (val2),
+                 TYPE_LENGTH (type1)) == 0);
 }
 
 int
@@ -1196,11 +1201,6 @@ deprecated_value_modifiable (struct value *value)
 {
   return value->modifiable;
 }
-void
-deprecated_set_value_modifiable (struct value *value, int modifiable)
-{
-  value->modifiable = modifiable;
-}
 \f
 /* Return a mark in the value chain.  All values allocated after the
    mark is obtained (except for those released) are subject to being freed
@@ -1401,9 +1401,7 @@ value_copy (struct value *arg)
 
     }
   val->unavailable = VEC_copy (range_s, arg->unavailable);
-  val->parent = arg->parent;
-  if (val->parent)
-    value_incref (val->parent);
+  set_value_parent (val, arg->parent);
   if (VALUE_LVAL (val) == lval_computed)
     {
       const struct lval_funcs *funcs = val->location.computed.funcs;
@@ -1715,6 +1713,29 @@ lookup_only_internalvar (const char *name)
   return NULL;
 }
 
+/* Complete NAME by comparing it to the names of internal variables.
+   Returns a vector of newly allocated strings, or NULL if no matches
+   were found.  */
+
+VEC (char_ptr) *
+complete_internalvar (const char *name)
+{
+  VEC (char_ptr) *result = NULL;
+  struct internalvar *var;
+  int len;
+
+  len = strlen (name);
+
+  for (var = internalvars; var; var = var->next)
+    if (strncmp (var->name, name, len) == 0)
+      {
+       char *r = xstrdup (var->name);
+
+       VEC_safe_push (char_ptr, result, r);
+      }
+
+  return result;
+}
 
 /* Create an internal variable with name NAME and with a void value.
    NAME should not normally include a dollar sign.  */
@@ -2110,7 +2131,7 @@ function_command (char *command, int from_tty)
 static void
 function_destroyer (struct cmd_list_element *self, void *ignore)
 {
-  xfree (self->name);
+  xfree ((char *) self->name);
   xfree (self->doc);
 }
 
@@ -2233,11 +2254,17 @@ show_convenience (char *ignore, int from_tty)
       printf_filtered (("\n"));
     }
   if (!varseen)
-    printf_unfiltered (_("No debugger convenience variables now defined.\n"
-                        "Convenience variables have "
-                        "names starting with \"$\";\n"
-                        "use \"set\" as in \"set "
-                        "$foo = 5\" to define them.\n"));
+    {
+      /* This text does not mention convenience functions on purpose.
+        The user can't create them except via Python, and if Python support
+        is installed this message will never be printed ($_streq will
+        exist).  */
+      printf_unfiltered (_("No debugger convenience variables now defined.\n"
+                          "Convenience variables have "
+                          "names starting with \"$\";\n"
+                          "use \"set\" as in \"set "
+                          "$foo = 5\" to define them.\n"));
+    }
 }
 \f
 /* Extract a value as a C number (either long or double).
@@ -2626,8 +2653,7 @@ value_primitive_field (struct value *arg1, int offset,
       v->offset = (value_embedded_offset (arg1)
                   + offset
                   + (bitpos - v->bitpos) / 8);
-      v->parent = arg1;
-      value_incref (v->parent);
+      set_value_parent (v, arg1);
       if (!value_lazy (arg1))
        value_fetch_lazy (v);
     }
@@ -3297,6 +3323,23 @@ coerce_array (struct value *arg)
 }
 \f
 
+/* Return the return value convention that will be used for the
+   specified type.  */
+
+enum return_value_convention
+struct_return_convention (struct gdbarch *gdbarch,
+                         struct value *function, struct type *value_type)
+{
+  enum type_code code = TYPE_CODE (value_type);
+
+  if (code == TYPE_CODE_ERROR)
+    error (_("Function return type unknown."));
+
+  /* Probe the architecture for the return-value convention.  */
+  return gdbarch_return_value (gdbarch, function, value_type,
+                              NULL, NULL, NULL);
+}
+
 /* Return true if the function returning the specified type is using
    the convention of returning structures in memory (passing in the
    address as a hidden first parameter).  */
@@ -3305,19 +3348,12 @@ int
 using_struct_return (struct gdbarch *gdbarch,
                     struct value *function, struct type *value_type)
 {
-  enum type_code code = TYPE_CODE (value_type);
-
-  if (code == TYPE_CODE_ERROR)
-    error (_("Function return type unknown."));
-
-  if (code == TYPE_CODE_VOID)
+  if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
     /* A void return value is never in memory.  See also corresponding
        code in "print_return_value".  */
     return 0;
 
-  /* Probe the architecture for the return-value convention.  */
-  return (gdbarch_return_value (gdbarch, function, value_type,
-                               NULL, NULL, NULL)
+  return (struct_return_convention (gdbarch, function, value_type)
          != RETURN_VALUE_REGISTER_CONVENTION);
 }
 
@@ -3341,14 +3377,19 @@ void
 _initialize_values (void)
 {
   add_cmd ("convenience", no_class, show_convenience, _("\
-Debugger convenience (\"$foo\") variables.\n\
-These variables are created when you assign them values;\n\
-thus, \"print $foo=1\" gives \"$foo\" the value 1.  Values may be any type.\n\
+Debugger convenience (\"$foo\") variables and functions.\n\
+Convenience variables are created when you assign them values;\n\
+thus, \"set $foo=1\" gives \"$foo\" the value 1.  Values may be any type.\n\
 \n\
 A few convenience variables are given values automatically:\n\
 \"$_\"holds the last address examined with \"x\" or \"info lines\",\n\
-\"$__\" holds the contents of the last address examined with \"x\"."),
-          &showlist);
+\"$__\" holds the contents of the last address examined with \"x\"."
+#ifdef HAVE_PYTHON
+"\n\n\
+Convenience functions are defined via the Python API."
+#endif
+          ), &showlist);
+  add_alias_cmd ("conv", "convenience", no_class, 1, &showlist);
 
   add_cmd ("values", no_set_class, show_values, _("\
 Elements of value history around item number IDX (or last ten)."),
This page took 0.034462 seconds and 4 git commands to generate.