GDB (xrefs)
Classes | Macros | Typedefs | Enumerations | Functions | Variables
py-value.c File Reference
#include "defs.h"
#include "charset.h"
#include "value.h"
#include "language.h"
#include "dfp.h"
#include "valprint.h"
#include "infcall.h"
#include "expression.h"
#include "cp-abi.h"
#include "python.h"
#include "python-internal.h"

Go to the source code of this file.

Classes

struct  value_object
 

Macros

#define builtin_type_pyint   builtin_type (python_gdbarch)->builtin_long
 
#define builtin_type_pyfloat   builtin_type (python_gdbarch)->builtin_double
 
#define builtin_type_pylong   builtin_type (python_gdbarch)->builtin_long_long
 
#define builtin_type_upylong
 
#define builtin_type_pybool   language_bool_type (python_language, python_gdbarch)
 
#define builtin_type_pychar   language_string_char_type (python_language, python_gdbarch)
 
#define STRIP_REFERENCE(TYPE)   ((TYPE_CODE (TYPE) == TYPE_CODE_REF) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))
 

Typedefs

typedef struct value_object value_object
 

Enumerations

enum  valpy_opcode {
  VALPY_ADD, VALPY_SUB, VALPY_MUL, VALPY_DIV,
  VALPY_REM, VALPY_POW, VALPY_LSH, VALPY_RSH,
  VALPY_BITAND, VALPY_BITOR, VALPY_BITXOR
}
 

Functions

static void valpy_dealloc (PyObject *obj)
 
static void note_value (value_object *value_obj)
 
static PyObject * valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
 
void gdbpy_preserve_values (const struct extension_language_defn *extlang, struct objfile *objfile, htab_t copied_types)
 
static PyObject * valpy_dereference (PyObject *self, PyObject *args)
 
static PyObject * valpy_referenced_value (PyObject *self, PyObject *args)
 
static PyObject * valpy_reference_value (PyObject *self, PyObject *args)
 
static PyObject * valpy_const_value (PyObject *self, PyObject *args)
 
static PyObject * valpy_get_address (PyObject *self, void *closure)
 
static PyObject * valpy_get_type (PyObject *self, void *closure)
 
static PyObject * valpy_get_dynamic_type (PyObject *self, void *closure)
 
static PyObject * valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObject * valpy_string (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObject * valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op)
 
static PyObject * valpy_cast (PyObject *self, PyObject *args)
 
static PyObject * valpy_dynamic_cast (PyObject *self, PyObject *args)
 
static PyObject * valpy_reinterpret_cast (PyObject *self, PyObject *args)
 
static Py_ssize_t valpy_length (PyObject *self)
 
static int value_has_field (struct value *v, PyObject *field)
 
static int get_field_flag (PyObject *field, const char *flag_name)
 
static struct typeget_field_type (PyObject *field)
 
static PyObject * valpy_getitem (PyObject *self, PyObject *key)
 
static int valpy_setitem (PyObject *self, PyObject *key, PyObject *value)
 
static PyObject * valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
 
static PyObject * valpy_str (PyObject *self)
 
static PyObject * valpy_get_is_optimized_out (PyObject *self, void *closure)
 
static PyObject * valpy_get_is_lazy (PyObject *self, void *closure)
 
static PyObject * valpy_fetch_lazy (PyObject *self, PyObject *args)
 
static Py_hash_t valpy_hash (PyObject *self)
 
static PyObject * valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
 
static PyObject * valpy_add (PyObject *self, PyObject *other)
 
static PyObject * valpy_subtract (PyObject *self, PyObject *other)
 
static PyObject * valpy_multiply (PyObject *self, PyObject *other)
 
static PyObject * valpy_divide (PyObject *self, PyObject *other)
 
static PyObject * valpy_remainder (PyObject *self, PyObject *other)
 
static PyObject * valpy_power (PyObject *self, PyObject *other, PyObject *unused)
 
static PyObject * valpy_negative (PyObject *self)
 
static PyObject * valpy_positive (PyObject *self)
 
static PyObject * valpy_absolute (PyObject *self)
 
static int valpy_nonzero (PyObject *self)
 
static PyObject * valpy_invert (PyObject *self)
 
static PyObject * valpy_lsh (PyObject *self, PyObject *other)
 
static PyObject * valpy_rsh (PyObject *self, PyObject *other)
 
static PyObject * valpy_and (PyObject *self, PyObject *other)
 
static PyObject * valpy_or (PyObject *self, PyObject *other)
 
static PyObject * valpy_xor (PyObject *self, PyObject *other)
 
static PyObject * valpy_richcompare (PyObject *self, PyObject *other, int op)
 
static PyObject * valpy_int (PyObject *self)
 
static PyObject * valpy_long (PyObject *self)
 
static PyObject * valpy_float (PyObject *self)
 
PyObject * value_to_value_object (struct value *val)
 
struct valuevalue_object_to_value (PyObject *self)
 
struct valueconvert_value_from_python (PyObject *obj)
 
PyObject * gdbpy_history (PyObject *self, PyObject *args)
 
int gdbpy_is_value_object (PyObject *obj)
 
int gdbpy_initialize_values (void)
 

Variables

static value_objectvalues_in_python = NULL
 
static PyGetSetDef value_object_getset []
 
static PyMethodDef value_object_methods []
 
static PyNumberMethods value_object_as_number
 
static PyMappingMethods value_object_as_mapping
 
PyTypeObject value_object_type
 

Macro Definition Documentation

#define builtin_type_pybool   language_bool_type (python_language, python_gdbarch)

Definition at line 50 of file py-value.c.

Referenced by convert_value_from_python().

#define builtin_type_pychar   language_string_char_type (python_language, python_gdbarch)

Definition at line 53 of file py-value.c.

Referenced by convert_value_from_python().

#define builtin_type_pyfloat   builtin_type (python_gdbarch)->builtin_double

Definition at line 41 of file py-value.c.

Referenced by convert_value_from_python().

#define builtin_type_pyint   builtin_type (python_gdbarch)->builtin_long

Definition at line 38 of file py-value.c.

Referenced by convert_value_from_python(), and valpy_binop().

#define builtin_type_pylong   builtin_type (python_gdbarch)->builtin_long_long

Definition at line 44 of file py-value.c.

Referenced by convert_value_from_python().

#define builtin_type_upylong
Value:
(python_gdbarch)->builtin_unsigned_long_long
struct gdbarch * python_gdbarch
Definition: python.c:201

Definition at line 47 of file py-value.c.

Referenced by convert_value_from_python().

#define STRIP_REFERENCE (   TYPE)    ((TYPE_CODE (TYPE) == TYPE_CODE_REF) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))

Definition at line 1018 of file py-value.c.

Referenced by valpy_binop().

Typedef Documentation

typedef struct value_object value_object

Enumeration Type Documentation

Enumerator
VALPY_ADD 
VALPY_SUB 
VALPY_MUL 
VALPY_DIV 
VALPY_REM 
VALPY_POW 
VALPY_LSH 
VALPY_RSH 
VALPY_BITAND 
VALPY_BITOR 
VALPY_BITXOR 

Definition at line 1002 of file py-value.c.

Function Documentation

struct value* convert_value_from_python ( PyObject *  obj)
PyObject* gdbpy_history ( PyObject *  self,
PyObject *  args 
)
int gdbpy_initialize_values ( void  )

Definition at line 1706 of file py-value.c.

References gdb_module, gdb_pymodule_addobject(), and value_object_type.

Referenced by _initialize_python().

int gdbpy_is_value_object ( PyObject *  obj)

Definition at line 1700 of file py-value.c.

References value_object_type.

Referenced by get_addr_from_python().

void gdbpy_preserve_values ( const struct extension_language_defn extlang,
struct objfile objfile,
htab_t  copied_types 
)

Definition at line 162 of file py-value.c.

References value_object::next, preserve_one_value(), and value_object::value.

static int get_field_flag ( PyObject *  field,
const char *  flag_name 
)
static

Definition at line 626 of file py-value.c.

References Py_DECREF, and PyObject_GetAttrString.

Referenced by valpy_getitem().

static struct type* get_field_type ( PyObject *  field)
static

Definition at line 644 of file py-value.c.

References _, Py_DECREF, PyObject_GetAttrString, and type_object_to_type().

Referenced by valpy_getitem().

static void note_value ( value_object value_obj)
static

Definition at line 110 of file py-value.c.

References value_object::next, value_object::prev, and values_in_python.

Referenced by valpy_new(), and value_to_value_object().

static PyObject* valpy_absolute ( PyObject *  self)
static
static PyObject* valpy_add ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1159 of file py-value.c.

References VALPY_ADD, and valpy_binop().

static PyObject* valpy_and ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1335 of file py-value.c.

References valpy_binop(), and VALPY_BITAND.

static PyObject* valpy_binop ( enum valpy_opcode  opcode,
PyObject *  self,
PyObject *  other 
)
static
static PyObject* valpy_call ( PyObject *  self,
PyObject *  args,
PyObject *  keywords 
)
static
static PyObject* valpy_cast ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 543 of file py-value.c.

References valpy_do_cast().

static PyObject* valpy_const_value ( PyObject *  self,
PyObject *  args 
)
static
static void valpy_dealloc ( PyObject *  obj)
static

Definition at line 75 of file py-value.c.

References gdb_assert, value_object::next, value_object::prev, Py_DECREF, Py_TYPE, and value_free().

static PyObject* valpy_dereference ( PyObject *  self,
PyObject *  args 
)
static
static PyObject* valpy_divide ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1177 of file py-value.c.

References valpy_binop(), and VALPY_DIV.

static PyObject* valpy_do_cast ( PyObject *  self,
PyObject *  args,
enum exp_opcode  op 
)
static
static PyObject* valpy_dynamic_cast ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 551 of file py-value.c.

References valpy_do_cast().

static PyObject* valpy_fetch_lazy ( PyObject *  self,
PyObject *  args 
)
static
static PyObject* valpy_float ( PyObject *  self)
static
static PyObject* valpy_get_address ( PyObject *  self,
void *  closure 
)
static
static PyObject* valpy_get_dynamic_type ( PyObject *  self,
void *  closure 
)
static
static PyObject* valpy_get_is_lazy ( PyObject *  self,
void *  closure 
)
static

Definition at line 953 of file py-value.c.

References CATCH, END_CATCH, GDB_PY_HANDLE_EXCEPTION, RETURN_MASK_ALL, TRY, and value_lazy().

static PyObject* valpy_get_is_optimized_out ( PyObject *  self,
void *  closure 
)
static
static PyObject* valpy_get_type ( PyObject *  self,
void *  closure 
)
static
static PyObject* valpy_getitem ( PyObject *  self,
PyObject *  key 
)
static
static Py_hash_t valpy_hash ( PyObject *  self)
static

Definition at line 997 of file py-value.c.

static PyObject* valpy_int ( PyObject *  self)
static
static PyObject* valpy_invert ( PyObject *  self)
static
static PyObject* valpy_lazy_string ( PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static
static Py_ssize_t valpy_length ( PyObject *  self)
static

Definition at line 565 of file py-value.c.

References _.

static PyObject* valpy_long ( PyObject *  self)
static
static PyObject* valpy_lsh ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1321 of file py-value.c.

References valpy_binop(), and VALPY_LSH.

static PyObject* valpy_multiply ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1171 of file py-value.c.

References valpy_binop(), and VALPY_MUL.

static PyObject* valpy_negative ( PyObject *  self)
static
static PyObject* valpy_new ( PyTypeObject *  subtype,
PyObject *  args,
PyObject *  keywords 
)
static
static int valpy_nonzero ( PyObject *  self)
static
static PyObject* valpy_or ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1342 of file py-value.c.

References valpy_binop(), and VALPY_BITOR.

static PyObject* valpy_positive ( PyObject *  self)
static

Definition at line 1229 of file py-value.c.

References value_to_value_object().

Referenced by valpy_absolute().

static PyObject* valpy_power ( PyObject *  self,
PyObject *  other,
PyObject *  unused 
)
static

Definition at line 1189 of file py-value.c.

References valpy_binop(), and VALPY_POW.

static PyObject* valpy_reference_value ( PyObject *  self,
PyObject *  args 
)
static
static PyObject* valpy_referenced_value ( PyObject *  self,
PyObject *  args 
)
static
static PyObject* valpy_reinterpret_cast ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 559 of file py-value.c.

References valpy_do_cast().

static PyObject* valpy_remainder ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1183 of file py-value.c.

References valpy_binop(), and VALPY_REM.

static PyObject* valpy_richcompare ( PyObject *  self,
PyObject *  other,
int  op 
)
static
static PyObject* valpy_rsh ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1328 of file py-value.c.

References valpy_binop(), and VALPY_RSH.

static int valpy_setitem ( PyObject *  self,
PyObject *  key,
PyObject *  value 
)
static

Definition at line 813 of file py-value.c.

References _.

static PyObject* valpy_str ( PyObject *  self)
static
static PyObject* valpy_string ( PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static
static PyObject* valpy_subtract ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1165 of file py-value.c.

References valpy_binop(), and VALPY_SUB.

static PyObject* valpy_xor ( PyObject *  self,
PyObject *  other 
)
static

Definition at line 1349 of file py-value.c.

References valpy_binop(), and VALPY_BITXOR.

static int value_has_field ( struct value v,
PyObject *  field 
)
static
struct value* value_object_to_value ( PyObject *  self)
PyObject* value_to_value_object ( struct value val)

Variable Documentation

PyMappingMethods value_object_as_mapping
static
Initial value:
= {
}
static PyObject * valpy_getitem(PyObject *self, PyObject *key)
Definition: py-value.c:666
static int valpy_setitem(PyObject *self, PyObject *key, PyObject *value)
Definition: py-value.c:813
static Py_ssize_t valpy_length(PyObject *self)
Definition: py-value.c:565

Definition at line 1811 of file py-value.c.

PyNumberMethods value_object_as_number
static

Definition at line 1764 of file py-value.c.

PyGetSetDef value_object_getset[]
static
Initial value:
= {
{ "address", valpy_get_address, NULL, "The address of the value.",
NULL },
{ "is_optimized_out", valpy_get_is_optimized_out, NULL,
"Boolean telling whether the value is optimized "
"out (i.e., not available).",
NULL },
{ "type", valpy_get_type, NULL, "Type of the value.", NULL },
{ "dynamic_type", valpy_get_dynamic_type, NULL,
"Dynamic type of the value.", NULL },
{ "is_lazy", valpy_get_is_lazy, NULL,
"Boolean telling whether the value is lazy (not fetched yet\n\
from the inferior). A lazy value is fetched when needed, or when\n\
the \"fetch_lazy()\" method is called.", NULL },
{NULL}
}
static PyObject * valpy_get_dynamic_type(PyObject *self, void *closure)
Definition: py-value.c:342
static PyObject * valpy_get_type(PyObject *self, void *closure)
Definition: py-value.c:325
static PyObject * valpy_get_is_optimized_out(PyObject *self, void *closure)
Definition: py-value.c:930
static PyObject * valpy_get_address(PyObject *self, void *closure)
Definition: py-value.c:294
static PyObject * valpy_get_is_lazy(PyObject *self, void *closure)
Definition: py-value.c:953

Definition at line 1717 of file py-value.c.

PyMethodDef value_object_methods[]
static
Initial value:
= {
{ "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." },
{ "dynamic_cast", valpy_dynamic_cast, METH_VARARGS,
"dynamic_cast (gdb.Type) -> gdb.Value\n\
Cast the value to the supplied type, as if by the C++ dynamic_cast operator."
},
{ "reinterpret_cast", valpy_reinterpret_cast, METH_VARARGS,
"reinterpret_cast (gdb.Type) -> gdb.Value\n\
Cast the value to the supplied type, as if by the C++\n\
reinterpret_cast operator."
},
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
{ "referenced_value", valpy_referenced_value, METH_NOARGS,
"Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." },
{ "reference_value", valpy_reference_value, METH_NOARGS,
"Return a value of type TYPE_CODE_REF referencing this value." },
{ "const_value", valpy_const_value, METH_NOARGS,
"Return a 'const' qualied version of the same value." },
{ "lazy_string", (PyCFunction) valpy_lazy_string,
METH_VARARGS | METH_KEYWORDS,
"lazy_string ([encoding] [, length]) -> lazy_string\n\
Return a lazy string representation of the value." },
{ "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
"string ([encoding] [, errors] [, length]) -> string\n\
Return Unicode string representation of the value." },
{ "fetch_lazy", valpy_fetch_lazy, METH_NOARGS,
"Fetches the value from the inferior, if it was lazy." },
{NULL}
}
static PyObject * valpy_lazy_string(PyObject *self, PyObject *args, PyObject *kw)
Definition: py-value.c:416
static PyObject * valpy_dynamic_cast(PyObject *self, PyObject *args)
Definition: py-value.c:551
static PyObject * valpy_referenced_value(PyObject *self, PyObject *args)
Definition: py-value.c:204
static PyObject * valpy_fetch_lazy(PyObject *self, PyObject *args)
Definition: py-value.c:976
static PyObject * valpy_reinterpret_cast(PyObject *self, PyObject *args)
Definition: py-value.c:559
static PyObject * valpy_cast(PyObject *self, PyObject *args)
Definition: py-value.c:543
static PyObject * valpy_dereference(PyObject *self, PyObject *args)
Definition: py-value.c:173
static PyObject * valpy_string(PyObject *self, PyObject *args, PyObject *kw)
Definition: py-value.c:457
static PyObject * valpy_reference_value(PyObject *self, PyObject *args)
Definition: py-value.c:242
static PyObject * valpy_const_value(PyObject *self, PyObject *args)
Definition: py-value.c:268

Definition at line 1734 of file py-value.c.

PyTypeObject value_object_type
value_object* values_in_python = NULL
static

Definition at line 71 of file py-value.c.

Referenced by note_value().