39 #define builtin_type_pyint builtin_type (python_gdbarch)->builtin_long 42 #define builtin_type_pyfloat builtin_type (python_gdbarch)->builtin_double 45 #define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long 48 #define builtin_type_upylong builtin_type \ 49 (python_gdbarch)->builtin_unsigned_long_long 51 #define builtin_type_pybool \ 52 language_bool_type (python_language, python_gdbarch) 54 #define builtin_type_pychar \ 55 language_string_char_type (python_language, python_gdbarch) 104 Py_XDECREF (self->dynamic_type);
106 Py_TYPE (
self)->tp_free (
self);
116 value_obj->
prev = NULL;
123 valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
128 if (PyTuple_Size (args) != 1)
130 PyErr_SetString (PyExc_TypeError,
_(
"Value object creation takes only " 135 value_obj = (
value_object *) subtype->tp_alloc (subtype, 1);
136 if (value_obj == NULL)
138 PyErr_SetString (PyExc_MemoryError,
_(
"Could not allocate memory to " 139 "create Value object."));
146 subtype->tp_free (value_obj);
153 value_obj->
type = NULL;
157 return (PyObject *) value_obj;
176 PyObject *result = NULL;
180 struct value *res_val;
206 PyObject *result = NULL;
210 struct value *self_val, *res_val;
224 error(
_(
"Trying to get the referenced value from a value which is " 225 "neither a pointer nor a reference."));
244 PyObject *result = NULL;
248 struct value *self_val;
280 PyObject *result = NULL;
284 struct value *self_val, *res_val;
310 struct value *res_val;
341 Py_INCREF (obj->
type);
370 struct value *target;
433 const char *user_encoding = NULL;
434 static const char *keywords[] = {
"encoding",
"length", NULL };
435 PyObject *str_obj = NULL;
438 keywords, &user_encoding, &length))
443 PyErr_SetString (PyExc_ValueError,
_(
"Invalid length."));
467 array_length = high_bound - low_bound + 1;
470 else if (array_length == -1)
475 else if (
length != array_length)
479 if (
length > array_length)
480 error (
_(
"Length is larger than array size."));
524 const char *encoding = NULL;
525 const char *
errors = NULL;
526 const char *user_encoding = NULL;
527 const char *la_encoding = NULL;
528 struct type *char_type;
529 static const char *keywords[] = {
"encoding",
"errors",
"length", NULL };
545 encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
546 unicode = PyUnicode_Decode ((
const char *)
buffer,
559 PyObject *type_obj, *result = NULL;
562 if (! PyArg_ParseTuple (args,
"O", &type_obj))
568 PyErr_SetString (PyExc_RuntimeError,
569 _(
"Argument must be a type."));
576 struct value *res_val;
579 if (op == UNOP_DYNAMIC_CAST)
581 else if (op == UNOP_REINTERPRET_CAST)
628 PyErr_SetString (PyExc_NotImplementedError,
629 _(
"Invalid operation on gdb.Value."));
639 struct type *parent_type, *val_type;
648 if (parent_type == NULL)
650 PyErr_SetString (PyExc_TypeError,
651 _(
"'parent_type' attribute of gdb.Field object is not a" 652 "gdb.Type object."));
688 if (flag_object == NULL)
691 return PyObject_IsTrue (flag_object.
get ());
703 if (ftype_obj == NULL)
707 PyErr_SetString (PyExc_TypeError,
708 _(
"'type' attribute of gdb.Field object is not a " 709 "gdb.Type object."));
724 struct type *base_class_type = NULL, *field_type = NULL;
726 PyObject *result = NULL;
736 int is_base_class, valid_field;
741 else if (valid_field == 0)
743 PyErr_SetString (PyExc_TypeError,
744 _(
"Invalid lookup for a field not contained in " 751 if (is_base_class < 0)
753 else if (is_base_class > 0)
756 if (base_class_type == NULL)
763 if (name_obj == NULL)
766 if (name_obj != Py_None)
776 PyErr_SetString (PyExc_AttributeError,
777 _(
"gdb.Field object has no name and no " 778 "'bitpos' attribute."));
783 if (bitpos_obj == NULL)
789 if (field_type == NULL)
798 struct value *res_val = NULL;
803 "struct/class/union");
806 "struct/class/union");
807 else if (base_class_type != NULL)
809 struct type *val_type;
840 error (
_(
"Cannot subscript requested type."));
863 PyErr_Format (PyExc_NotImplementedError,
864 _(
"Setting of struct elements is not currently supported."));
871 valpy_call (PyObject *
self, PyObject *args, PyObject *keywords)
873 Py_ssize_t args_count;
875 struct value **vargs = NULL;
876 struct type *ftype = NULL;
877 PyObject *result = NULL;
891 PyErr_SetString (PyExc_RuntimeError,
892 _(
"Value is not callable (not TYPE_CODE_FUNC)."));
896 if (! PyTuple_Check (args))
898 PyErr_SetString (PyExc_TypeError,
899 _(
"Inferior arguments must be provided in a tuple."));
903 args_count = PyTuple_Size (args);
908 vargs = XALLOCAVEC (
struct value *, args_count);
909 for (i = 0; i < args_count; i++)
911 PyObject *item = PyTuple_GetItem (args, i);
917 if (vargs[i] == NULL)
925 struct value *return_value;
1037 return (intptr_t)
self;
1056 #define STRIP_REFERENCE(TYPE) \ 1057 (TYPE_IS_REFERENCE (TYPE) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE)) 1066 PyObject *result = NULL;
1068 struct value *arg1, *arg2;
1069 struct value *res_val = NULL;
1159 op = BINOP_BITWISE_AND;
1162 op = BINOP_BITWISE_IOR;
1165 op = BINOP_BITWISE_XOR;
1189 PyObject *result = NULL;
1240 if (unused != Py_None)
1242 PyErr_SetString (PyExc_NotImplementedError,
1243 "Invalid operation on gdb.Value.");
1253 PyObject *result = NULL;
1344 struct value *val = NULL;
1403 struct value *value_other;
1404 struct value *value_self;
1409 if (value_other == NULL)
1417 result =
value_less (value_self, value_other);
1420 result =
value_less (value_self, value_other)
1430 result =
value_less (value_other, value_self);
1433 result = (
value_less (value_other, value_self)
1438 PyErr_SetString (PyExc_NotImplementedError,
1439 _(
"Invalid operation on gdb.Value."));
1455 if (other == Py_None)
1469 PyErr_SetString (PyExc_NotImplementedError,
1470 _(
"Invalid operation on gdb.Value."));
1506 error (
_(
"Cannot convert value to int."));
1534 error (
_(
"Cannot convert value to long."));
1563 error (
_(
"Cannot convert value to float."));
1573 return PyFloat_FromDouble (d);
1584 if (val_obj != NULL)
1586 val_obj->
value = val;
1589 val_obj->
type = NULL;
1594 return (PyObject *) val_obj;
1624 if (PyBool_Check (obj))
1626 cmp = PyObject_IsTrue (obj);
1637 else if (PyLong_Check (obj))
1639 LONGEST l = PyLong_AsLongLong (obj);
1641 if (PyErr_Occurred ())
1645 if (PyErr_ExceptionMatches (PyExc_OverflowError))
1647 PyObject *etype, *evalue, *etraceback;
1649 PyErr_Fetch (&etype, &evalue, &etraceback);
1653 if (PyObject_RichCompareBool (obj, zero.
get (), Py_GT) > 0)
1657 ul = PyLong_AsUnsignedLongLong (obj);
1658 if (! PyErr_Occurred ())
1663 PyErr_Restore (etype, evalue, etraceback);
1669 #if PY_MAJOR_VERSION == 2 1670 else if (PyInt_Check (obj))
1672 long l = PyInt_AsLong (obj);
1674 if (! PyErr_Occurred ())
1678 else if (PyFloat_Check (obj))
1680 double d = PyFloat_AsDouble (obj);
1682 if (! PyErr_Occurred ())
1708 PyErr_Format (PyExc_TypeError,
1709 _(
"Could not convert Python object: %S."), obj);
1711 PyErr_Format (PyExc_TypeError,
1712 _(
"Could not convert Python object: %s."),
1713 PyString_AsString (PyObject_Str (obj)));
1719 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
1720 "%s", except.message);
1733 struct value *res_val = NULL;
1735 if (!PyArg_ParseTuple (args,
"i", &i))
1775 "Boolean telling whether the value is optimized " 1776 "out (i.e., not available).",
1780 "Dynamic type of the value.", NULL },
1782 "Boolean telling whether the value is lazy (not fetched yet\n\ 1783 from the inferior). A lazy value is fetched when needed, or when\n\ 1784 the \"fetch_lazy()\" method is called.", NULL },
1789 {
"cast",
valpy_cast, METH_VARARGS,
"Cast the value to the supplied type." },
1791 "dynamic_cast (gdb.Type) -> gdb.Value\n\ 1792 Cast the value to the supplied type, as if by the C++ dynamic_cast operator." 1795 "reinterpret_cast (gdb.Type) -> gdb.Value\n\ 1796 Cast the value to the supplied type, as if by the C++\n\ 1797 reinterpret_cast operator." 1801 "Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." },
1803 "Return a value of type TYPE_CODE_REF referencing this value." },
1805 "Return a value of type TYPE_CODE_RVALUE_REF referencing this value." },
1807 "Return a 'const' qualied version of the same value." },
1809 METH_VARARGS | METH_KEYWORDS,
1810 "lazy_string ([encoding] [, length]) -> lazy_string\n\ 1811 Return a lazy string representation of the value." },
1812 {
"string", (PyCFunction)
valpy_string, METH_VARARGS | METH_KEYWORDS,
1813 "string ([encoding] [, errors] [, length]) -> string\n\ 1814 Return Unicode string representation of the value." },
1816 "Fetches the value from the inferior, if it was lazy." },
1870 #ifndef HAVE_LIBPYTHON2_4 1902 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES
1903 | Py_TPFLAGS_BASETYPE,
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)
struct type * value_rtti_type(struct value *v, int *full, LONGEST *top, int *using_enc)
static PyObject * valpy_do_cast(PyObject *self, PyObject *args, enum exp_opcode op)
PyObject_HEAD struct value_object * next
#define PyObject_GetAttrString(obj, attr)
struct type * lookup_array_range_type(struct type *element_type, LONGEST low_bound, LONGEST high_bound)
struct value * value_addr(struct value *arg1)
static PyObject * valpy_add(PyObject *self, PyObject *other)
PyTypeObject value_object_type
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)
bool target_float_is_zero(const gdb_byte *addr, const struct type *type)
struct value * value_struct_elt_bitpos(struct value **argp, int bitpos, struct type *ftype, const char *err)
static PyObject * valpy_long(PyObject *self)
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)
struct type * type_object_to_type(PyObject *obj)
static PyObject * valpy_binop_throw(enum valpy_opcode opcode, PyObject *self, PyObject *other)
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)
struct pyty_type_object type_object
static PyObject * valpy_str(PyObject *self)
static PyObject * valpy_absolute(PyObject *self)
#define gdb_py_long_from_ulongest
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
int value_lazy(const struct value *value)
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)
double target_float_to_host_double(const gdb_byte *addr, const struct type *type)
#define builtin_type_pylong
static PyObject * valpy_get_dynamic_type(PyObject *self, void *closure)
static PyObject * valpy_power(PyObject *self, PyObject *other, PyObject *unused)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
#define PyVarObject_HEAD_INIT(type, size)
static PyObject * valpy_remainder(PyObject *self, PyObject *other)
struct value * allocate_value(struct type *type)
static PyObject * valpy_lsh(PyObject *self, PyObject *other)
#define TYPE_IS_REFERENCE(t)
#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)
static gdb_PyGetSetDef value_object_getset[]
const gdb_byte * value_contents(struct value *value)
#define CATCH(EXCEPTION, MASK)
int gdbpy_initialize_values(void)
struct type * lookup_rvalue_reference_type(struct type *type)
static PyObject * valpy_fetch_lazy(PyObject *self, PyObject *args)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
def has_field(type_, field)
PyObject * gdb_py_object_from_longest(LONGEST l)
static PyObject * valpy_reinterpret_cast(PyObject *self, PyObject *args)
int is_integral_type(struct type *t)
static PyObject * valpy_xor(PyObject *self, PyObject *other)
#define builtin_type_pybool
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)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
static PyObject * valpy_rvalue_reference_value(PyObject *self, PyObject *args)
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)
int value_equal(struct value *arg1, struct value *arg2)
static PyObject * valpy_dereference(PyObject *self, PyObject *args)
#define STRIP_REFERENCE(TYPE)
void gdbpy_preserve_values(const struct extension_language_defn *extlang, struct objfile *objfile, htab_t copied_types)
static PyMappingMethods value_object_as_mapping
#define gdb_py_long_from_longest
struct value * value_ref(struct value *arg1, enum type_code refcode)
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)
void target_float_from_host_double(gdb_byte *addr, const struct type *type, double val)
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)
static PyNumberMethods value_object_as_number
#define TYPE_CODE(thistype)
const char * c_str() const
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)
int gdbpy_is_lazy_string(PyObject *result)
static PyObject * valpy_int(PyObject *self)
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 * call_function_by_hand(struct value *function, type *default_return_type, int nargs, struct value **args)
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 value * access_value_history(int num)
struct value * value_from_ulongest(struct type *type, ULONGEST num)
CORE_ADDR value_as_address(struct value *val)
struct value * value_object_to_value(PyObject *self)
static void note_value(value_object *value_obj)
const struct language_defn * python_language
gdb::unique_xmalloc_ptr< char > python_string_to_target_string(PyObject *obj)
const char * host_charset(void)
gdb_byte * value_contents_raw(struct value *value)
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)
struct value * value_cstring(const char *ptr, ssize_t len, struct type *char_type)
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)
int get_array_bounds(struct type *type, LONGEST *low_bound, LONGEST *high_bound)
static PyObject * valpy_lvalue_reference_value(PyObject *self, PyObject *args)
static int valpy_richcompare_throw(PyObject *self, PyObject *other, int op)
struct type * lookup_lvalue_reference_type(struct type *type)
void error(const char *fmt,...)
static Py_hash_t valpy_hash(PyObject *self)
struct type * lookup_pointer_type(struct type *type)
#define PyObject_HasAttrString(obj, attr)
bool is_floating_value(struct value *val)
#define LA_GET_STRING(value, buffer, length, chartype, encoding)
static struct type * get_field_type(PyObject *field)
static PyObject * valpy_reference_value(PyObject *self, PyObject *args, enum type_code refcode)
static PyObject * valpy_subtract(PyObject *self, PyObject *other)
PyObject * type_to_type_object(struct type *type)