| |   |
| 23 | 23 | #include "exceptions.h" |
| 24 | 24 | #include "symtab.h" |
| 25 | 25 | #include "stack.h" |
| 26 | #include "value.h" |
| 26 | 27 | #include "python-internal.h" |
| 27 | 28 | |
| 28 | 29 | typedef struct { |
| … | … | |
| 57 | 57 | static PyObject *frapy_get_prev (PyObject *self, PyObject *args); |
| 58 | 58 | static PyObject *frapy_get_next (PyObject *self, PyObject *args); |
| 59 | 59 | static PyObject *frapy_find_sal (PyObject *self, PyObject *args); |
| 60 | static PyObject *frapy_read_var_value (PyObject *self, PyObject *args); |
| 60 | 61 | |
| 61 | 62 | #define FRAPY_REQUIRE_VALID(frame_obj, frame) \ |
| 62 | 63 | do { \ |
| … | … | |
| 88 | 88 | { "get_next", frapy_get_next, METH_NOARGS, "Return the next (inner) frame." }, |
| 89 | 89 | { "find_sal", frapy_find_sal, METH_NOARGS, |
| 90 | 90 | "Return the frame's symtab and line." }, |
| 91 | { "read_var_value", frapy_read_var_value, METH_VARARGS, |
| 92 | "Return the value of the variable in this frame." }, |
| 91 | 93 | {NULL} /* Sentinel */ |
| 92 | 94 | }; |
| 93 | 95 | |
| … | … | |
| 429 | 429 | return sal_obj; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | static PyObject * |
| 433 | frapy_read_var_value (PyObject *self, PyObject *args) |
| 434 | { |
| 435 | struct frame_info *frame; |
| 436 | PyObject *sym_obj; |
| 437 | struct symbol *var; |
| 438 | struct value *val = NULL; |
| 439 | volatile struct gdb_exception except; |
| 440 | |
| 441 | if (!PyArg_ParseTuple (args, "O!", &symbol_object_type, &sym_obj)) |
| 442 | return NULL; |
| 443 | |
| 444 | var = symbol_object_to_symbol (sym_obj); |
| 445 | |
| 446 | TRY_CATCH (except, RETURN_MASK_ALL) |
| 447 | { |
| 448 | FRAPY_REQUIRE_VALID ((frame_object *) self, frame); |
| 449 | |
| 450 | val = read_var_value (var, frame); |
| 451 | } |
| 452 | GDB_PY_HANDLE_EXCEPTION (except); |
| 453 | |
| 454 | if (val) |
| 455 | return value_to_value_object (val); |
| 456 | |
| 457 | Py_RETURN_NONE; |
| 458 | } |
| 459 | |
| 432 | 460 | PyObject * |
| 433 | 461 | gdbpy_frames (PyObject *self, PyObject *args) |
| 434 | 462 | { |
| toggle raw diff |
--- a/gdb/python/frame.c
+++ b/gdb/python/frame.c
@@ -23,6 +23,7 @@
#include "exceptions.h"
#include "symtab.h"
#include "stack.h"
+#include "value.h"
#include "python-internal.h"
typedef struct {
@@ -56,6 +57,7 @@ static PyObject *frapy_get_address_in_block (PyObject *self, PyObject *args);
static PyObject *frapy_get_prev (PyObject *self, PyObject *args);
static PyObject *frapy_get_next (PyObject *self, PyObject *args);
static PyObject *frapy_find_sal (PyObject *self, PyObject *args);
+static PyObject *frapy_read_var_value (PyObject *self, PyObject *args);
#define FRAPY_REQUIRE_VALID(frame_obj, frame) \
do { \
@@ -86,6 +88,8 @@ static PyMethodDef frame_object_methods[] = {
{ "get_next", frapy_get_next, METH_NOARGS, "Return the next (inner) frame." },
{ "find_sal", frapy_find_sal, METH_NOARGS,
"Return the frame's symtab and line." },
+ { "read_var_value", frapy_read_var_value, METH_VARARGS,
+ "Return the value of the variable in this frame." },
{NULL} /* Sentinel */
};
@@ -425,6 +429,34 @@ frapy_find_sal (PyObject *self, PyObject *args)
return sal_obj;
}
+static PyObject *
+frapy_read_var_value (PyObject *self, PyObject *args)
+{
+ struct frame_info *frame;
+ PyObject *sym_obj;
+ struct symbol *var;
+ struct value *val = NULL;
+ volatile struct gdb_exception except;
+
+ if (!PyArg_ParseTuple (args, "O!", &symbol_object_type, &sym_obj))
+ return NULL;
+
+ var = symbol_object_to_symbol (sym_obj);
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
+
+ val = read_var_value (var, frame);
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
+
+ if (val)
+ return value_to_value_object (val);
+
+ Py_RETURN_NONE;
+}
+
PyObject *
gdbpy_frames (PyObject *self, PyObject *args)
{ |
| |   |
| 32 | 32 | static PyObject *sympy_get_natural_name (PyObject *self, PyObject *args); |
| 33 | 33 | static PyObject *sympy_get_linkage_name (PyObject *self, PyObject *args); |
| 34 | 34 | static PyObject *sympy_get_print_name (PyObject *self, PyObject *args); |
| 35 | static PyObject *sympy_get_class (PyObject *self, PyObject *args); |
| 35 | 36 | |
| 36 | 37 | static PyMethodDef symbol_object_methods[] = { |
| 37 | 38 | { "get_value", sympy_get_value, METH_NOARGS, |
| … | … | |
| 45 | 45 | "Return the name of the symbol as used by the linker." }, |
| 46 | 46 | { "get_print_name", sympy_get_print_name, METH_NOARGS, |
| 47 | 47 | "Return the name of the symbol in a form suitable for output." }, |
| 48 | { "get_class", sympy_get_class, METH_NOARGS, |
| 49 | "Return the class of the symbol." }, |
| 48 | 50 | {NULL} /* Sentinel */ |
| 49 | 51 | }; |
| 50 | 52 | |
| 51 | | static PyTypeObject symbol_object_type = { |
| 53 | PyTypeObject symbol_object_type = { |
| 52 | 54 | PyObject_HEAD_INIT (NULL) |
| 53 | 55 | 0, /*ob_size*/ |
| 54 | 56 | "gdb.Symbol", /*tp_name*/ |
| … | … | |
| 149 | 149 | return PyString_FromString (SYMBOL_PRINT_NAME (self_sym->symbol)); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | static PyObject * |
| 153 | sympy_get_class (PyObject *self, PyObject *args) |
| 154 | { |
| 155 | symbol_object *self_sym = (symbol_object *) self; |
| 156 | |
| 157 | return PyInt_FromLong (SYMBOL_CLASS (self_sym->symbol)); |
| 158 | } |
| 159 | |
| 152 | 160 | PyObject * |
| 153 | 161 | symbol_to_symbol_object (struct symbol *sym) |
| 154 | 162 | { |
| … | … | |
| 174 | 174 | return (PyObject *) sym_obj; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | struct symbol * |
| 178 | symbol_object_to_symbol (PyObject *obj) |
| 179 | { |
| 180 | return ((symbol_object *) obj)->symbol; |
| 181 | } |
| 182 | |
| 183 | /* This function has less arguments than its C counterpart, to simplify the |
| 184 | Python interface: name, block and domain. The other two arguments are always |
| 185 | assumed to be set, and a tuple with 3 elements is always returned. The first |
| 186 | is the symbol object or None, the second is a boolean with the value of |
| 187 | is_a_field_of_this, and the third is the symbol object or None. */ |
| 188 | PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args) |
| 189 | { |
| 190 | int domain, is_a_field_of_this = 0; |
| 191 | const char *name; |
| 192 | struct symbol *symbol; |
| 193 | struct symtab *symtab; |
| 194 | PyObject *block_obj, *ret_tuple, *sym_obj, *symtab_obj, *bool_obj; |
| 195 | |
| 196 | PyArg_ParseTuple (args, "sO!i", &name, &block_object_type, &block_obj, |
| 197 | &domain); |
| 198 | |
| 199 | symbol = lookup_symbol (name, block_object_to_block (block_obj), domain, |
| 200 | &is_a_field_of_this, &symtab); |
| 201 | |
| 202 | ret_tuple = PyTuple_New (3); |
| 203 | if (!ret_tuple) |
| 204 | { |
| 205 | PyErr_SetString (PyExc_MemoryError, "Could not allocate tuple object."); |
| 206 | return NULL; |
| 207 | } |
| 208 | |
| 209 | if (symbol) |
| 210 | { |
| 211 | sym_obj = symbol_to_symbol_object (symbol); |
| 212 | if (!sym_obj) |
| 213 | { |
| 214 | Py_DECREF (ret_tuple); |
| 215 | return NULL; |
| 216 | } |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | sym_obj = Py_None; |
| 221 | Py_INCREF (Py_None); |
| 222 | } |
| 223 | PyTuple_SET_ITEM (ret_tuple, 0, sym_obj); |
| 224 | |
| 225 | bool_obj = is_a_field_of_this? Py_True : Py_False; |
| 226 | Py_INCREF (bool_obj); |
| 227 | PyTuple_SET_ITEM (ret_tuple, 1, bool_obj); |
| 228 | |
| 229 | if (symtab) |
| 230 | { |
| 231 | symtab_obj = symtab_to_symtab_object (symtab); |
| 232 | if (!symtab_obj) |
| 233 | { |
| 234 | /* I *think* this will take care of decref'ing sym_obj and |
| 235 | bool_obj. */ |
| 236 | Py_DECREF (ret_tuple); |
| 237 | return NULL; |
| 238 | } |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | symtab_obj = Py_None; |
| 243 | Py_INCREF (Py_None); |
| 244 | } |
| 245 | PyTuple_SET_ITEM (ret_tuple, 2, symtab_obj); |
| 246 | |
| 247 | return ret_tuple; |
| 248 | } |
| 249 | |
| 177 | 250 | void |
| 178 | 251 | gdbpy_initialize_symbols (void) |
| 179 | 252 | { |
| … | … | |
| 254 | 254 | if (PyType_Ready (&symbol_object_type) < 0) |
| 255 | 255 | return; |
| 256 | 256 | |
| 257 | /* FIXME: These would probably be best exposed as class attributes of Symbol, |
| 258 | but I don't know how to do it except by messing with the type's dictionary. |
| 259 | That seems too messy. */ |
| 260 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF); |
| 261 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST", LOC_CONST); |
| 262 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC", LOC_STATIC); |
| 263 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER", LOC_REGISTER); |
| 264 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG", LOC_ARG); |
| 265 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG", LOC_REF_ARG); |
| 266 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM", LOC_REGPARM); |
| 267 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR", |
| 268 | LOC_REGPARM_ADDR); |
| 269 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL", LOC_LOCAL); |
| 270 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF", LOC_TYPEDEF); |
| 271 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL", LOC_LABEL); |
| 272 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK", LOC_BLOCK); |
| 273 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES", |
| 274 | LOC_CONST_BYTES); |
| 275 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL_ARG", LOC_LOCAL_ARG); |
| 276 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BASEREG", LOC_BASEREG); |
| 277 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BASEREG_ARG", |
| 278 | LOC_BASEREG_ARG); |
| 279 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED", LOC_UNRESOLVED); |
| 280 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_HP_THREAD_LOCAL_STATIC", |
| 281 | LOC_HP_THREAD_LOCAL_STATIC); |
| 282 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT", |
| 283 | LOC_OPTIMIZED_OUT); |
| 284 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_INDIRECT", LOC_INDIRECT); |
| 285 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED", LOC_COMPUTED); |
| 286 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED_ARG", |
| 287 | LOC_COMPUTED_ARG); |
| 288 | |
| 289 | PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN", UNDEF_DOMAIN); |
| 290 | PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN", VAR_DOMAIN); |
| 291 | PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN", STRUCT_DOMAIN); |
| 292 | PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN", LABEL_DOMAIN); |
| 293 | PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN", |
| 294 | VARIABLES_DOMAIN); |
| 295 | PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN", |
| 296 | FUNCTIONS_DOMAIN); |
| 297 | PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN", TYPES_DOMAIN); |
| 298 | PyModule_AddIntConstant (gdb_module, "SYMBOL_METHODS_DOMAIN", METHODS_DOMAIN); |
| 299 | |
| 257 | 300 | Py_INCREF (&symbol_object_type); |
| 258 | 301 | PyModule_AddObject (gdb_module, "Symbol", (PyObject *) &symbol_object_type); |
| 259 | 302 | } |
| toggle raw diff |
--- a/gdb/python/symbol.c
+++ b/gdb/python/symbol.c
@@ -32,6 +32,7 @@ static PyObject *sympy_get_symtab (PyObject *self, PyObject *args);
static PyObject *sympy_get_natural_name (PyObject *self, PyObject *args);
static PyObject *sympy_get_linkage_name (PyObject *self, PyObject *args);
static PyObject *sympy_get_print_name (PyObject *self, PyObject *args);
+static PyObject *sympy_get_class (PyObject *self, PyObject *args);
static PyMethodDef symbol_object_methods[] = {
{ "get_value", sympy_get_value, METH_NOARGS,
@@ -44,10 +45,12 @@ static PyMethodDef symbol_object_methods[] = {
"Return the name of the symbol as used by the linker." },
{ "get_print_name", sympy_get_print_name, METH_NOARGS,
"Return the name of the symbol in a form suitable for output." },
+ { "get_class", sympy_get_class, METH_NOARGS,
+ "Return the class of the symbol." },
{NULL} /* Sentinel */
};
-static PyTypeObject symbol_object_type = {
+PyTypeObject symbol_object_type = {
PyObject_HEAD_INIT (NULL)
0, /*ob_size*/
"gdb.Symbol", /*tp_name*/
@@ -146,6 +149,14 @@ sympy_get_print_name (PyObject *self, PyObject *args)
return PyString_FromString (SYMBOL_PRINT_NAME (self_sym->symbol));
}
+static PyObject *
+sympy_get_class (PyObject *self, PyObject *args)
+{
+ symbol_object *self_sym = (symbol_object *) self;
+
+ return PyInt_FromLong (SYMBOL_CLASS (self_sym->symbol));
+}
+
PyObject *
symbol_to_symbol_object (struct symbol *sym)
{
@@ -163,6 +174,79 @@ symbol_to_symbol_object (struct symbol *sym)
return (PyObject *) sym_obj;
}
+struct symbol *
+symbol_object_to_symbol (PyObject *obj)
+{
+ return ((symbol_object *) obj)->symbol;
+}
+
+/* This function has less arguments than its C counterpart, to simplify the
+ Python interface: name, block and domain. The other two arguments are always
+ assumed to be set, and a tuple with 3 elements is always returned. The first
+ is the symbol object or None, the second is a boolean with the value of
+ is_a_field_of_this, and the third is the symbol object or None. */
+PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args)
+{
+ int domain, is_a_field_of_this = 0;
+ const char *name;
+ struct symbol *symbol;
+ struct symtab *symtab;
+ PyObject *block_obj, *ret_tuple, *sym_obj, *symtab_obj, *bool_obj;
+
+ PyArg_ParseTuple (args, "sO!i", &name, &block_object_type, &block_obj,
+ &domain);
+
+ symbol = lookup_symbol (name, block_object_to_block (block_obj), domain,
+ &is_a_field_of_this, &symtab);
+
+ ret_tuple = PyTuple_New (3);
+ if (!ret_tuple)
+ {
+ PyErr_SetString (PyExc_MemoryError, "Could not allocate tuple object.");
+ return NULL;
+ }
+
+ if (symbol)
+ {
+ sym_obj = symbol_to_symbol_object (symbol);
+ if (!sym_obj)
+ {
+ Py_DECREF (ret_tuple);
+ return NULL;
+ }
+ }
+ else
+ {
+ sym_obj = Py_None;
+ Py_INCREF (Py_None);
+ }
+ PyTuple_SET_ITEM (ret_tuple, 0, sym_obj);
+
+ bool_obj = is_a_field_of_this? Py_True : Py_False;
+ Py_INCREF (bool_obj);
+ PyTuple_SET_ITEM (ret_tuple, 1, bool_obj);
+
+ if (symtab)
+ {
+ symtab_obj = symtab_to_symtab_object (symtab);
+ if (!symtab_obj)
+ {
+ /* I *think* this will take care of decref'ing sym_obj and
+ bool_obj. */
+ Py_DECREF (ret_tuple);
+ return NULL;
+ }
+ }
+ else
+ {
+ symtab_obj = Py_None;
+ Py_INCREF (Py_None);
+ }
+ PyTuple_SET_ITEM (ret_tuple, 2, symtab_obj);
+
+ return ret_tuple;
+}
+
void
gdbpy_initialize_symbols (void)
{
@@ -170,6 +254,49 @@ gdbpy_initialize_symbols (void)
if (PyType_Ready (&symbol_object_type) < 0)
return;
+ /* FIXME: These would probably be best exposed as class attributes of Symbol,
+ but I don't know how to do it except by messing with the type's dictionary.
+ That seems too messy. */
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST", LOC_CONST);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC", LOC_STATIC);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER", LOC_REGISTER);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG", LOC_ARG);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG", LOC_REF_ARG);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM", LOC_REGPARM);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
+ LOC_REGPARM_ADDR);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL", LOC_LOCAL);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF", LOC_TYPEDEF);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL", LOC_LABEL);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK", LOC_BLOCK);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
+ LOC_CONST_BYTES);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL_ARG", LOC_LOCAL_ARG);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BASEREG", LOC_BASEREG);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BASEREG_ARG",
+ LOC_BASEREG_ARG);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED", LOC_UNRESOLVED);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_HP_THREAD_LOCAL_STATIC",
+ LOC_HP_THREAD_LOCAL_STATIC);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
+ LOC_OPTIMIZED_OUT);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_INDIRECT", LOC_INDIRECT);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED", LOC_COMPUTED);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED_ARG",
+ LOC_COMPUTED_ARG);
+
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN", UNDEF_DOMAIN);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN", VAR_DOMAIN);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN", STRUCT_DOMAIN);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN", LABEL_DOMAIN);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
+ VARIABLES_DOMAIN);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
+ FUNCTIONS_DOMAIN);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN", TYPES_DOMAIN);
+ PyModule_AddIntConstant (gdb_module, "SYMBOL_METHODS_DOMAIN", METHODS_DOMAIN);
+
Py_INCREF (&symbol_object_type);
PyModule_AddObject (gdb_module, "Symbol", (PyObject *) &symbol_object_type);
} |
| |   |
| 41 | 41 | static PyObject *valpy_equal_p (PyObject *self, PyObject *args); |
| 42 | 42 | static PyObject * valpy_lazy_p (PyObject *self, PyObject *args); |
| 43 | 43 | static PyObject * valpy_fetch_lazy (PyObject *self, PyObject *args); |
| 44 | static PyObject * valpy_common_print (PyObject *self, PyObject *args); |
| 44 | 45 | |
| 45 | 46 | static PyMethodDef value_object_methods[] = { |
| 46 | 47 | { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." }, |
| … | … | |
| 53 | 53 | "Returns True if the value is lazy, False if not." }, |
| 54 | 54 | { "fetch_lazy", valpy_fetch_lazy, METH_NOARGS, |
| 55 | 55 | "Fetches value from inferior memory." }, |
| 56 | { "common_print", valpy_common_print, METH_VARARGS, "Prints value." }, |
| 56 | 57 | {NULL} /* Sentinel */ |
| 57 | 58 | }; |
| 58 | 59 | |
| … | … | |
| 256 | 256 | Py_RETURN_NONE; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | static PyObject * |
| 260 | valpy_common_print (PyObject *self, PyObject *args) |
| 261 | { |
| 262 | value_object *self_value = (value_object *) self; |
| 263 | int ret = 0, format, recurse, pretty; |
| 264 | PyObject *format_obj, *deref_obj; |
| 265 | struct ui_stream *stb; |
| 266 | struct cleanup *chain; |
| 267 | volatile struct gdb_exception except; |
| 268 | |
| 269 | if (!PyArg_ParseTuple (args, "OO!ii", &format_obj, &PyBool_Type, &deref_obj, |
| 270 | &recurse, &pretty)) |
| 271 | return NULL; |
| 272 | |
| 273 | if (format_obj == Py_None) |
| 274 | format = 0; |
| 275 | else |
| 276 | { |
| 277 | if (!PyString_Check (format_obj) || PyString_Size (format_obj) != 1) |
| 278 | { |
| 279 | PyErr_SetString (PyExc_TypeError, "Argument 1 must be char or None."); |
| 280 | return NULL; |
| 281 | } |
| 282 | |
| 283 | format = *PyString_AsString (format_obj); |
| 284 | } |
| 285 | |
| 286 | stb = ui_out_stream_new (uiout); |
| 287 | chain = make_cleanup_ui_out_stream_delete (stb); |
| 288 | |
| 289 | TRY_CATCH (except, RETURN_MASK_ALL) |
| 290 | { |
| 291 | ret = common_val_print (self_value->value, stb->stream, format, |
| 292 | deref_obj == Py_True, recurse, pretty); |
| 293 | /* FIXME: should I really use ui_out_field_stream? */ |
| 294 | ui_out_field_stream (uiout, "value", stb); |
| 295 | } |
| 296 | GDB_PY_HANDLE_EXCEPTION (except); |
| 297 | |
| 298 | do_cleanups (chain); |
| 299 | |
| 300 | return PyInt_FromLong (ret); |
| 301 | } |
| 302 | |
| 259 | 303 | /* FIXME: clarify the naming to say the value |
| 260 | 304 | won't be deleted by the Python code. */ |
| 261 | 305 | PyObject * |
| … | … | |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | PyObject * |
| 320 | value_to_value_object (struct value *v) |
| 321 | { |
| 322 | value_object *val_obj; |
| 323 | |
| 324 | VALPY_RETURN_VALUE (val_obj, v); |
| 325 | } |
| 326 | |
| 327 | PyObject * |
| 320 | 328 | gdb_value_from_int (PyObject *self, PyObject *args) |
| 321 | 329 | { |
| 322 | 330 | int i; |
| … | … | |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | struct value * |
| 381 | | gdb_value_from_py_value (PyObject *self) |
| 381 | value_object_to_value (PyObject *self) |
| 382 | 382 | { |
| 383 | 383 | value_object *real = (value_object *)self; |
| 384 | 384 | return real->value; |
| toggle raw diff |
--- a/gdb/python/value.c
+++ b/gdb/python/value.c
@@ -41,6 +41,7 @@ static PyObject *valpy_increment (PyObject *self, PyObject *args);
static PyObject *valpy_equal_p (PyObject *self, PyObject *args);
static PyObject * valpy_lazy_p (PyObject *self, PyObject *args);
static PyObject * valpy_fetch_lazy (PyObject *self, PyObject *args);
+static PyObject * valpy_common_print (PyObject *self, PyObject *args);
static PyMethodDef value_object_methods[] = {
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
@@ -52,6 +53,7 @@ static PyMethodDef value_object_methods[] = {
"Returns True if the value is lazy, False if not." },
{ "fetch_lazy", valpy_fetch_lazy, METH_NOARGS,
"Fetches value from inferior memory." },
+ { "common_print", valpy_common_print, METH_VARARGS, "Prints value." },
{NULL} /* Sentinel */
};
@@ -254,6 +256,50 @@ valpy_fetch_lazy (PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *
+valpy_common_print (PyObject *self, PyObject *args)
+{
+ value_object *self_value = (value_object *) self;
+ int ret = 0, format, recurse, pretty;
+ PyObject *format_obj, *deref_obj;
+ struct ui_stream *stb;
+ struct cleanup *chain;
+ volatile struct gdb_exception except;
+
+ if (!PyArg_ParseTuple (args, "OO!ii", &format_obj, &PyBool_Type, &deref_obj,
+ &recurse, &pretty))
+ return NULL;
+
+ if (format_obj == Py_None)
+ format = 0;
+ else
+ {
+ if (!PyString_Check (format_obj) || PyString_Size (format_obj) != 1)
+ {
+ PyErr_SetString (PyExc_TypeError, "Argument 1 must be char or None.");
+ return NULL;
+ }
+
+ format = *PyString_AsString (format_obj);
+ }
+
+ stb = ui_out_stream_new (uiout);
+ chain = make_cleanup_ui_out_stream_delete (stb);
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ ret = common_val_print (self_value->value, stb->stream, format,
+ deref_obj == Py_True, recurse, pretty);
+ /* FIXME: should I really use ui_out_field_stream? */
+ ui_out_field_stream (uiout, "value", stb);
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
+
+ do_cleanups (chain);
+
+ return PyInt_FromLong (ret);
+}
+
/* FIXME: clarify the naming to say the value
won't be deleted by the Python code. */
PyObject *
@@ -271,6 +317,14 @@ value_from_value (struct value *v)
}
PyObject *
+value_to_value_object (struct value *v)
+{
+ value_object *val_obj;
+
+ VALPY_RETURN_VALUE (val_obj, v);
+}
+
+PyObject *
gdb_value_from_int (PyObject *self, PyObject *args)
{
int i;
@@ -324,7 +378,7 @@ gdbpy_initialize_values (void)
}
struct value *
-gdb_value_from_py_value (PyObject *self)
+value_object_to_value (PyObject *self)
{
value_object *real = (value_object *)self;
return real->value; |