38 #define builtin_type_pyint builtin_type (python_gdbarch)->builtin_long
41 #define builtin_type_pyfloat builtin_type (python_gdbarch)->builtin_double
44 #define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long
47 #define builtin_type_upylong builtin_type \
48 (python_gdbarch)->builtin_unsigned_long_long
50 #define builtin_type_pybool \
51 language_bool_type (python_language, python_gdbarch)
53 #define builtin_type_pychar \
54 language_string_char_type (python_language, python_gdbarch)
85 values_in_python =
self->
next;
103 Py_XDECREF (self->dynamic_type);
105 Py_TYPE (
self)->tp_free (
self);
115 value_obj->
prev = NULL;
116 values_in_python = value_obj;
122 valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
127 if (PyTuple_Size (args) != 1)
129 PyErr_SetString (PyExc_TypeError,
_(
"Value object creation takes only "
134 value_obj = (
value_object *) subtype->tp_alloc (subtype, 1);
135 if (value_obj == NULL)
137 PyErr_SetString (PyExc_MemoryError,
_(
"Could not allocate memory to "
138 "create Value object."));
145 subtype->tp_free (value_obj);
149 value_obj->
value = value;
152 value_obj->
type = NULL;
156 return (PyObject *) value_obj;
167 for (iter = values_in_python; iter; iter = iter->
next)
175 PyObject *result = NULL;
179 struct value *res_val;
206 PyObject *result = NULL;
210 struct value *self_val, *res_val;
223 error(
_(
"Trying to get the referenced value from a value which is "
224 "neither a pointer nor a reference."));
244 PyObject *result = NULL;
248 struct value *self_val;
270 PyObject *result = NULL;
274 struct value *self_val, *res_val;
302 struct value *res_val;
335 Py_INCREF (obj->
type);
365 struct value *target;
420 const char *user_encoding = NULL;
421 static char *keywords[] = {
"encoding",
"length", NULL };
422 PyObject *str_obj = NULL;
424 if (!PyArg_ParseTupleAndKeywords (args, kw,
"|s" GDB_PY_LL_ARG, keywords,
425 &user_encoding, &length))
464 const char *
errors = NULL;
465 const char *user_encoding = NULL;
466 const char *la_encoding = NULL;
467 struct type *char_type;
468 static char *keywords[] = {
"encoding",
"errors",
"length", NULL };
470 if (!PyArg_ParseTupleAndKeywords (args, kw,
"|ssi", keywords,
471 &user_encoding, &errors, &length))
476 LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
484 encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
485 unicode = PyUnicode_Decode ((
const char *) buffer,
498 PyObject *type_obj, *result = NULL;
501 if (! PyArg_ParseTuple (args,
"O", &type_obj))
507 PyErr_SetString (PyExc_RuntimeError,
508 _(
"Argument must be a type."));
515 struct value *res_val;
518 if (op == UNOP_DYNAMIC_CAST)
520 else if (op == UNOP_REINTERPRET_CAST)
568 PyErr_SetString (PyExc_NotImplementedError,
569 _(
"Invalid operation on gdb.Value."));
579 struct type *parent_type, *val_type;
584 if (type_object == NULL)
589 if (parent_type == NULL)
591 PyErr_SetString (PyExc_TypeError,
592 _(
"'parent_type' attribute of gdb.Field object is not a"
593 "gdb.Type object."));
631 if (flag_object == NULL)
634 flag_value = PyObject_IsTrue (flag_object);
649 if (ftype_obj == NULL)
654 PyErr_SetString (PyExc_TypeError,
655 _(
"'type' attribute of gdb.Field object is not a "
656 "gdb.Type object."));
671 struct type *base_class_type = NULL, *field_type = NULL;
673 PyObject *result = NULL;
683 int is_base_class, valid_field;
688 else if (valid_field == 0)
690 PyErr_SetString (PyExc_TypeError,
691 _(
"Invalid lookup for a field not contained in "
698 if (is_base_class < 0)
700 else if (is_base_class > 0)
703 if (base_class_type == NULL)
710 if (name_obj == NULL)
713 if (name_obj != Py_None)
722 PyObject *bitpos_obj;
729 PyErr_SetString (PyExc_AttributeError,
730 _(
"gdb.Field object has no name and no "
731 "'bitpos' attribute."));
736 if (bitpos_obj == NULL)
744 if (field_type == NULL)
754 struct value *res_val = NULL;
758 else if (bitpos >= 0)
760 "struct/class/union");
761 else if (base_class_type != NULL)
763 struct type *val_type;
790 error (
_(
"Cannot subscript requested type."));
815 PyErr_Format (PyExc_NotImplementedError,
816 _(
"Setting of struct elements is not currently supported."));
823 valpy_call (PyObject *
self, PyObject *args, PyObject *keywords)
825 Py_ssize_t args_count;
827 struct value **vargs = NULL;
828 struct type *ftype = NULL;
830 PyObject *result = NULL;
844 PyErr_SetString (PyExc_RuntimeError,
845 _(
"Value is not callable (not TYPE_CODE_FUNC)."));
849 if (! PyTuple_Check (args))
851 PyErr_SetString (PyExc_TypeError,
852 _(
"Inferior arguments must be provided in a tuple."));
856 args_count = PyTuple_Size (args);
861 vargs = alloca (
sizeof (
struct value *) * args_count);
862 for (i = 0; i < args_count; i++)
864 PyObject *item = PyTuple_GetItem (args, i);
870 if (vargs[i] == NULL)
878 struct value *return_value;
922 result = PyUnicode_Decode (s, strlen (s),
host_charset (), NULL);
999 return (intptr_t)
self;
1018 #define STRIP_REFERENCE(TYPE) \
1019 ((TYPE_CODE (TYPE) == TYPE_CODE_REF) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))
1027 PyObject *result = NULL;
1031 struct value *arg1, *arg2;
1033 struct value *res_val = NULL;
1126 op = BINOP_BITWISE_AND;
1129 op = BINOP_BITWISE_IOR;
1132 op = BINOP_BITWISE_XOR;
1194 if (unused != Py_None)
1196 PyErr_SetString (PyExc_NotImplementedError,
1197 "Invalid operation on gdb.Value.");
1207 PyObject *result = NULL;
1304 struct value *val = NULL;
1361 if (other == Py_None)
1375 PyErr_SetString (PyExc_NotImplementedError,
1376 _(
"Invalid operation on gdb.Value."));
1386 if (value_other == NULL)
1417 PyErr_SetString (PyExc_NotImplementedError,
1418 _(
"Invalid operation on gdb.Value."));
1453 error (
_(
"Cannot convert value to int."));
1481 error (
_(
"Cannot convert value to long."));
1507 error (
_(
"Cannot convert value to float."));
1517 return PyFloat_FromDouble (d);
1527 val_obj = PyObject_New (
value_object, &value_object_type);
1528 if (val_obj != NULL)
1530 val_obj->
value = val;
1533 val_obj->
type = NULL;
1538 return (PyObject *) val_obj;
1548 if (! PyObject_TypeCheck (
self, &value_object_type))
1568 if (PyBool_Check (obj))
1570 cmp = PyObject_IsTrue (obj);
1581 else if (PyLong_Check (obj))
1583 LONGEST l = PyLong_AsLongLong (obj);
1585 if (PyErr_Occurred ())
1589 if (PyErr_ExceptionMatches (PyExc_OverflowError))
1591 PyObject *etype, *evalue, *etraceback, *zero;
1593 PyErr_Fetch (&etype, &evalue, &etraceback);
1594 zero = PyInt_FromLong (0);
1597 if (PyObject_RichCompareBool (obj, zero, Py_GT) > 0)
1601 ul = PyLong_AsUnsignedLongLong (obj);
1602 if (! PyErr_Occurred ())
1607 PyErr_Restore (etype, evalue, etraceback);
1615 else if (PyInt_Check (obj))
1617 long l = PyInt_AsLong (obj);
1619 if (! PyErr_Occurred ())
1622 else if (PyFloat_Check (obj))
1624 double d = PyFloat_AsDouble (obj);
1626 if (! PyErr_Occurred ())
1643 else if (PyObject_TypeCheck (obj, &value_object_type))
1654 PyErr_Format (PyExc_TypeError,
1655 _(
"Could not convert Python object: %S."), obj);
1657 PyErr_Format (PyExc_TypeError,
1658 _(
"Could not convert Python object: %s."),
1659 PyString_AsString (PyObject_Str (obj)));
1665 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
1666 "%s", except.message);
1679 struct value *res_val = NULL;
1681 if (!PyArg_ParseTuple (args,
"i", &i))
1702 return PyObject_TypeCheck (obj, &value_object_type);
1708 if (PyType_Ready (&value_object_type) < 0)
1712 (PyObject *) &value_object_type);
1721 "Boolean telling whether the value is optimized "
1722 "out (i.e., not available).",
1726 "Dynamic type of the value.", NULL },
1728 "Boolean telling whether the value is lazy (not fetched yet\n\
1729 from the inferior). A lazy value is fetched when needed, or when\n\
1730 the \"fetch_lazy()\" method is called.", NULL },
1735 {
"cast",
valpy_cast, METH_VARARGS,
"Cast the value to the supplied type." },
1737 "dynamic_cast (gdb.Type) -> gdb.Value\n\
1738 Cast the value to the supplied type, as if by the C++ dynamic_cast operator."
1741 "reinterpret_cast (gdb.Type) -> gdb.Value\n\
1742 Cast the value to the supplied type, as if by the C++\n\
1743 reinterpret_cast operator."
1747 "Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." },
1749 "Return a value of type TYPE_CODE_REF referencing this value." },
1751 "Return a 'const' qualied version of the same value." },
1753 METH_VARARGS | METH_KEYWORDS,
1754 "lazy_string ([encoding] [, length]) -> lazy_string\n\
1755 Return a lazy string representation of the value." },
1756 {
"string", (PyCFunction)
valpy_string, METH_VARARGS | METH_KEYWORDS,
1757 "string ([encoding] [, errors] [, length]) -> string\n\
1758 Return Unicode string representation of the value." },
1760 "Fetches the value from the inferior, if it was lazy." },
1764 static PyNumberMethods value_object_as_number = {
1811 static PyMappingMethods value_object_as_mapping = {
1817 PyTypeObject value_object_type = {
1828 &value_object_as_number,
1830 &value_object_as_mapping,
1837 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES
1838 | Py_TPFLAGS_BASETYPE,
1846 value_object_methods,
1848 value_object_getset,
static PyMethodDef value_object_methods[]
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
static PyObject * valpy_getitem(PyObject *self, PyObject *key)
struct value * value_zero(struct type *type, enum lval_type lv)
static PyObject * valpy_do_cast(PyObject *self, PyObject *args, enum exp_opcode op)
PyObject_HEAD struct value_object * next
struct value * value_mark(void)
#define PyObject_GetAttrString(obj, attr)
struct value * call_function_by_hand(struct value *function, int nargs, struct value **args)
struct value * value_addr(struct value *arg1)
static PyObject * valpy_add(PyObject *self, PyObject *other)
static PyObject * valpy_rsh(PyObject *self, PyObject *other)
struct value * make_cv_value(int cnst, int voltl, struct value *v)
static int valpy_nonzero(PyObject *self)
struct value * value_subscript(struct value *array, LONGEST index)
PyObject * gdbpy_value_cst
static int valpy_setitem(PyObject *self, PyObject *key, PyObject *value)
struct value * value_struct_elt_bitpos(struct value **argp, int bitpos, struct type *ftype, const char *err)
static PyObject * valpy_long(PyObject *self)
struct value * value_ref(struct value *arg1)
static PyObject * valpy_binop(enum valpy_opcode opcode, PyObject *self, PyObject *other)
static PyObject * valpy_call(PyObject *self, PyObject *args, PyObject *keywords)
struct value * value_reinterpret_cast(struct type *type, struct value *arg)
LONGEST value_as_long(struct value *val)
int gdbpy_is_string(PyObject *obj)
static PyGetSetDef value_object_getset[]
struct type * type_object_to_type(PyObject *obj)
char * ui_file_xstrdup(struct ui_file *file, long *length)
LONGEST value_ptrdiff(struct value *arg1, struct value *arg2)
void common_val_print(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
static PyObject * valpy_str(PyObject *self)
static PyObject * valpy_absolute(PyObject *self)
static PyObject * valpy_lazy_string(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * valpy_dynamic_cast(PyObject *self, PyObject *args)
const struct gdb_exception exception_none
struct value * coerce_ref(struct value *arg)
void value_free(struct value *val)
int gdbpy_is_field(PyObject *obj)
struct value * value_ind(struct value *arg1)
struct value * value_copy(struct value *arg)
static PyObject * valpy_referenced_value(PyObject *self, PyObject *args)
#define builtin_type_pylong
static PyObject * valpy_get_dynamic_type(PyObject *self, void *closure)
static PyObject * valpy_power(PyObject *self, PyObject *other, PyObject *unused)
char * python_string_to_target_string(PyObject *obj)
static PyObject * valpy_remainder(PyObject *self, PyObject *other)
static PyObject * valpy_lsh(PyObject *self, PyObject *other)
#define builtin_type_pychar
static value_object * values_in_python
static PyObject * valpy_and(PyObject *self, PyObject *other)
#define GDB_PY_HANDLE_EXCEPTION(Exception)
PyObject * gdbpy_history(PyObject *self, PyObject *args)
struct value * value_ptradd(struct value *arg1, LONGEST arg2)
struct value * value_struct_elt(struct value **argp, struct value **args, const char *name, int *static_memfuncp, const char *err)
#define builtin_type_pyint
void preserve_one_value(struct value *value, struct objfile *objfile, htab_t copied_types)
struct type * check_typedef(struct type *type)
const gdb_byte * value_contents(struct value *value)
#define CATCH(EXCEPTION, MASK)
int gdbpy_initialize_values(void)
static PyObject * valpy_fetch_lazy(PyObject *self, PyObject *args)
def has_field(type_, field)
int value_lazy(struct value *value)
PyObject * gdb_py_object_from_longest(LONGEST l)
static PyObject * valpy_reinterpret_cast(PyObject *self, PyObject *args)
struct cleanup * make_cleanup_value_free_to_mark(struct value *mark)
int is_integral_type(struct type *t)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
char * python_string_to_host_string(PyObject *obj)
static PyObject * valpy_xor(PyObject *self, PyObject *other)
#define builtin_type_pybool
int decimal_is_zero(const gdb_byte *x, int len, enum bfd_endian byte_order)
struct gdbarch * get_type_arch(const struct type *type)
static int value_has_field(struct value *v, PyObject *field)
#define GDB_PY_SET_HANDLE_EXCEPTION(Exception)
struct value * value_from_longest(struct type *type, LONGEST num)
PyObject * value_to_value_object(struct value *val)
struct value * value_cast(struct type *type, struct value *arg2)
struct value * value_dynamic_cast(struct type *type, struct value *arg)
static PyObject * valpy_cast(PyObject *self, PyObject *args)
int gdbpy_is_value_object(PyObject *obj)
struct value * value_from_double(struct type *type, DOUBLEST num)
int value_equal(struct value *arg1, struct value *arg2)
static PyObject * valpy_dereference(PyObject *self, PyObject *args)
struct ui_file * mem_fileopen(void)
#define STRIP_REFERENCE(TYPE)
void gdbpy_preserve_values(const struct extension_language_defn *extlang, struct objfile *objfile, htab_t copied_types)
#define gdb_py_long_from_longest
static PyObject * valpy_invert(PyObject *self)
static PyObject * valpy_float(PyObject *self)
static PyObject * valpy_or(PyObject *self, PyObject *other)
void release_value_or_incref(struct value *val)
int types_equal(struct type *a, struct type *b)
static PyObject * valpy_string(PyObject *self, PyObject *args, PyObject *kw)
int value_optimized_out(struct value *value)
static PyObject * valpy_get_type(PyObject *self, void *closure)
#define TYPE_TARGET_TYPE(thistype)
void value_fetch_lazy(struct value *val)
struct value * value_neg(struct value *arg1)
static PyObject * valpy_get_is_optimized_out(PyObject *self, void *closure)
struct cleanup * make_cleanup_ui_file_delete(struct ui_file *arg)
#define TYPE_CODE(thistype)
static PyObject * valpy_new(PyTypeObject *subtype, PyObject *args, PyObject *keywords)
static int get_field_flag(PyObject *field, const char *flag_name)
void get_user_print_options(struct value_print_options *opts)
int value_less(struct value *arg1, struct value *arg2)
struct value * convert_value_from_python(PyObject *obj)
struct value * value_complement(struct value *arg1)
struct value * value_cstring(char *ptr, ssize_t len, struct type *char_type)
struct type * value_rtti_type(struct value *v, int *full, int *top, int *using_enc)
int gdbpy_is_lazy_string(PyObject *result)
static PyObject * valpy_int(PyObject *self)
#define CHECK_TYPEDEF(TYPE)
static PyObject * valpy_reference_value(PyObject *self, PyObject *args)
struct value * value_binop(struct value *arg1, struct value *arg2, enum exp_opcode op)
static PyObject * valpy_divide(PyObject *self, PyObject *other)
static PyObject * valpy_negative(PyObject *self)
static PyObject * valpy_get_address(PyObject *self, void *closure)
int binop_user_defined_p(enum exp_opcode op, struct value *arg1, struct value *arg2)
static PyObject * valpy_positive(PyObject *self)
#define builtin_type_pyfloat
unsigned long long ULONGEST
struct value_object * prev
int gdb_py_int_as_long(PyObject *obj, long *result)
#define builtin_type_upylong
PyObject * gdbpy_create_lazy_string_object(CORE_ADDR address, long length, const char *encoding, struct type *type)
static PyObject * valpy_get_is_lazy(PyObject *self, void *closure)
struct type * value_type(const struct value *value)
struct type * lookup_reference_type(struct type *type)
struct value * access_value_history(int num)
struct value * value_from_ulongest(struct type *type, ULONGEST num)
struct value * value_object_to_value(PyObject *self)
static void note_value(value_object *value_obj)
const struct language_defn * python_language
const char * host_charset(void)
static PyObject * valpy_richcompare(PyObject *self, PyObject *other, int op)
#define TYPE_LENGTH(thistype)
struct value * value_x_binop(struct value *arg1, struct value *arg2, enum exp_opcode op, enum exp_opcode otherop, enum noside noside)
static PyObject * valpy_const_value(PyObject *self, PyObject *args)
static PyObject * valpy_multiply(PyObject *self, PyObject *other)
static void valpy_dealloc(PyObject *obj)
static Py_ssize_t valpy_length(PyObject *self)
struct value_object value_object
CORE_ADDR value_address(const struct value *value)
void error(const char *fmt,...)
DOUBLEST value_as_double(struct value *val)
static Py_hash_t valpy_hash(PyObject *self)
struct type * lookup_pointer_type(struct type *type)
#define PyObject_HasAttrString(obj, attr)
void do_cleanups(struct cleanup *old_chain)
#define LA_GET_STRING(value, buffer, length, chartype, encoding)
static struct type * get_field_type(PyObject *field)
static PyObject * valpy_subtract(PyObject *self, PyObject *other)
#define PyVarObject_HEAD_INIT(type, size)
PyObject * type_to_type_object(struct type *type)