/* Implementation of the GDB variable objects API.
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
- 2009 Free Software Foundation, Inc.
+ 2009, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
static int is_root_p (struct varobj *var);
+#if HAVE_PYTHON
+
static struct varobj *
varobj_add_child (struct varobj *var, const char *name, struct value *value);
+#endif /* HAVE_PYTHON */
+
/* C implementation */
static int c_number_of_children (struct varobj *var);
return delcount;
}
+#if HAVE_PYTHON
+
/* Convenience function for varobj_set_visualizer. Instantiate a
pretty-printer for a given value. */
static PyObject *
instantiate_pretty_printer (PyObject *constructor, struct value *value)
{
-#if HAVE_PYTHON
PyObject *val_obj = NULL;
PyObject *printer;
printer = PyObject_CallFunctionObjArgs (constructor, val_obj, NULL);
Py_DECREF (val_obj);
return printer;
-#endif
return NULL;
}
+#endif
+
/* Set/Get variable object display format */
enum varobj_display_formats
}
}
+#if HAVE_PYTHON
+
/* A helper for update_dynamic_varobj_children that installs a new
child when needed. */
}
}
-#if HAVE_PYTHON
-
static int
dynamic_varobj_has_child_method (struct varobj *var)
{
return var->children;
}
+#if HAVE_PYTHON
+
static struct varobj *
varobj_add_child (struct varobj *var, const char *name, struct value *value)
{
return v;
}
+#endif /* HAVE_PYTHON */
+
/* Obtain the type of an object Variable as a string similar to the one gdb
prints on the console */
struct cleanup *old_chain;
gdb_byte *thevalue = NULL;
struct value_print_options opts;
- int len = 0;
+ struct type *type = NULL;
+ long len = 0;
+ char *encoding = NULL;
+ struct gdbarch *gdbarch = NULL;
if (value == NULL)
return NULL;
+ gdbarch = get_type_arch (value_type (value));
#if HAVE_PYTHON
{
struct cleanup *back_to = varobj_ensure_python_env (var);
&replacement);
if (output)
{
- PyObject *py_str
- = python_string_to_target_python_string (output);
- if (py_str)
+ if (gdbpy_is_lazy_string (output))
+ {
+ thevalue = gdbpy_extract_lazy_string (output, &type,
+ &len, &encoding);
+ string_print = 1;
+ }
+ else
{
- char *s = PyString_AsString (py_str);
- len = PyString_Size (py_str);
- thevalue = xmemdup (s, len + 1, len + 1);
- Py_DECREF (py_str);
+ PyObject *py_str
+ = python_string_to_target_python_string (output);
+ if (py_str)
+ {
+ char *s = PyString_AsString (py_str);
+ len = PyString_Size (py_str);
+ thevalue = xmemdup (s, len + 1, len + 1);
+ type = builtin_type (gdbarch)->builtin_char;
+ Py_DECREF (py_str);
+ }
}
Py_DECREF (output);
}
if (thevalue && !string_print)
{
do_cleanups (back_to);
+ xfree (encoding);
return thevalue;
}
if (replacement)
opts.raw = 1;
if (thevalue)
{
- struct gdbarch *gdbarch = get_type_arch (value_type (value));
make_cleanup (xfree, thevalue);
- LA_PRINT_STRING (stb, builtin_type (gdbarch)->builtin_char,
- thevalue, len, 0, &opts);
+ make_cleanup (xfree, encoding);
+ LA_PRINT_STRING (stb, type, thevalue, len, encoding, 0, &opts);
}
else
common_val_print (value, stb, 0, &opts, current_language);
{
case TYPE_CODE_ARRAY:
if (cname)
- *cname = xstrprintf ("%d", index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+ *cname = xstrdup (int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0));
if (cvalue && value)
{
*ctype = get_target_type (type);
if (cfull_expression)
- *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression,
- index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+ *cfull_expression =
+ xstrprintf ("(%s)[%s]", parent_expression,
+ int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0));
break;
static void
cplus_class_num_children (struct type *type, int children[3])
{
- int i;
+ int i, vptr_fieldno;
+ struct type *basetype = NULL;
children[v_public] = 0;
children[v_private] = 0;
children[v_protected] = 0;
+ vptr_fieldno = get_vptr_fieldno (type, &basetype);
for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
{
- /* If we have a virtual table pointer, omit it. */
- if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
+ /* If we have a virtual table pointer, omit it. Even if virtual
+ table pointers are not specifically marked in the debug info,
+ they should be artificial. */
+ if ((type == basetype && i == vptr_fieldno)
+ || TYPE_FIELD_ARTIFICIAL (type, i))
continue;
if (TYPE_FIELD_PROTECTED (type, i))
find the indexed field. */
int type_index = TYPE_N_BASECLASSES (type);
enum accessibility acc = public_field;
+ int vptr_fieldno;
+ struct type *basetype = NULL;
+
+ vptr_fieldno = get_vptr_fieldno (type, &basetype);
if (strcmp (parent->name, "private") == 0)
acc = private_field;
else if (strcmp (parent->name, "protected") == 0)
while (index >= 0)
{
- if (TYPE_VPTR_BASETYPE (type) == type
- && type_index == TYPE_VPTR_FIELDNO (type))
+ if ((type == basetype && type_index == vptr_fieldno)
+ || TYPE_FIELD_ARTIFICIAL (type, type_index))
; /* ignore vptr */
else if (match_accessibility (type, type_index, acc))
--index;