System notice: In light of the Debian OpenSSL security issue we've regenerated the server keys. See this thread for instructions and the new key fingerprints.

Commit 70784b8d90a6200230630e72403b6fc8e33ca883

Add code needed to print function argument values.

Commit diff

gdb/Makefile.in

 
34163416 $(srcdir)/python/cmd.c -o python-cmd.o
34173417python-frame.o: $(srcdir)/python/frame.c $(defs_h) $(python_h) \
34183418 $(python_internal_h) $(frame_h) $(exceptions_h) $(symtab_h) \
3419 $(charset_h) $(stack_h)
3419 $(charset_h) $(stack_h) $(value_h)
34203420 $(CC) -c $(INTERNAL_CFLAGS) $(PYTHON_CFLAGS) \
34213421 $(srcdir)/python/frame.c -o python-frame.o
34223422python-hooks.o: $(srcdir)/python/hooks.c $(defs_h) $(cli_decode_h) \
toggle raw diff

gdb/python/block.c

 
4949 {NULL} /* Sentinel */
5050};
5151
52static PyTypeObject block_object_type = {
52PyTypeObject block_object_type = {
5353 PyObject_HEAD_INIT (NULL)
5454 0, /*ob_size*/
5555 "gdb.Block", /*tp_name*/
209209 return (PyObject *) block_obj;
210210}
211211
212struct block *
213block_object_to_block (PyObject *obj)
214{
215 return ((block_object *) obj)->block;
216}
217
212218static PyObject *
213219blpy_block_syms_iter (PyObject *self)
214220{
toggle raw diff

gdb/python/frame.c

 
2323#include "exceptions.h"
2424#include "symtab.h"
2525#include "stack.h"
26#include "value.h"
2627#include "python-internal.h"
2728
2829typedef struct {
5757static PyObject *frapy_get_prev (PyObject *self, PyObject *args);
5858static PyObject *frapy_get_next (PyObject *self, PyObject *args);
5959static PyObject *frapy_find_sal (PyObject *self, PyObject *args);
60static PyObject *frapy_read_var_value (PyObject *self, PyObject *args);
6061
6162#define FRAPY_REQUIRE_VALID(frame_obj, frame) \
6263 do { \
8888 { "get_next", frapy_get_next, METH_NOARGS, "Return the next (inner) frame." },
8989 { "find_sal", frapy_find_sal, METH_NOARGS,
9090 "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." },
9193 {NULL} /* Sentinel */
9294};
9395
429429 return sal_obj;
430430}
431431
432static PyObject *
433frapy_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
432460PyObject *
433461gdbpy_frames (PyObject *self, PyObject *args)
434462{
toggle raw diff

gdb/python/python-internal.h

 
2727#endif
2828
2929extern PyObject *gdb_module;
30extern PyTypeObject block_object_type;
31extern PyTypeObject value_object_type;
32extern PyTypeObject symbol_object_type;
3033
3134PyObject *gdb_value_from_int (PyObject *self, PyObject *args);
3235PyObject *gdb_value_from_history (PyObject *self, PyObject *args);
3737PyObject *gdbpy_frames (PyObject *, PyObject *);
3838PyObject *gdbpy_current_frame (PyObject *, PyObject *);
3939PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
40PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args);
4041
4142PyObject *value_from_value (struct value *v);
4243PyObject *variable_to_python (struct cmd_list_element *);
4545PyObject *symtab_to_symtab_object (struct symtab *symtab);
4646PyObject *symbol_to_symbol_object (struct symbol *sym);
4747PyObject *block_to_block_object (struct block *block);
48PyObject *value_to_value_object (struct value *v);
4849
49struct value *gdb_value_from_py_value (PyObject *self);
50struct block *block_object_to_block (PyObject *obj);
51struct symbol *symbol_object_to_symbol (PyObject *obj);
52struct value *value_object_to_value (PyObject *self);
5053
5154PyObject *gdbpy_get_hook_function (const char *);
5255
7777void gdbpy_breakpoint_created (int);
7878void gdbpy_breakpoint_deleted (int);
7979
80extern PyTypeObject value_object_type;
81
8280#endif /* GDB_PYTHON_INTERNAL_H */
toggle raw diff

gdb/python/python.c

 
7979 { "frame_stop_reason_string", gdbpy_frame_stop_reason_string,
8080 METH_VARARGS, "Return a string explaining unwind stop reason" },
8181
82 { "lookup_symbol", gdbpy_lookup_symbol, METH_VARARGS,
83 "Return the symbol corresponding to the given name, or None." },
8284 { "solib_address", gdbpy_solib_address, METH_VARARGS,
8385 "Return shared library holding a given address, or None." },
8486
217217 if (!PyObject_IsInstance (py_v, (PyObject *)&value_object_type))
218218 error ("child list has object of invalid type");
219219
220 v = gdb_value_from_py_value (py_v);
220 v = value_object_to_value (py_v);
221221
222222 varobj_add_child (var, name, v);
223223 }
toggle raw diff

gdb/python/symbol.c

 
3232static PyObject *sympy_get_natural_name (PyObject *self, PyObject *args);
3333static PyObject *sympy_get_linkage_name (PyObject *self, PyObject *args);
3434static PyObject *sympy_get_print_name (PyObject *self, PyObject *args);
35static PyObject *sympy_get_class (PyObject *self, PyObject *args);
3536
3637static PyMethodDef symbol_object_methods[] = {
3738 { "get_value", sympy_get_value, METH_NOARGS,
4545 "Return the name of the symbol as used by the linker." },
4646 { "get_print_name", sympy_get_print_name, METH_NOARGS,
4747 "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." },
4850 {NULL} /* Sentinel */
4951};
5052
51static PyTypeObject symbol_object_type = {
53PyTypeObject symbol_object_type = {
5254 PyObject_HEAD_INIT (NULL)
5355 0, /*ob_size*/
5456 "gdb.Symbol", /*tp_name*/
149149 return PyString_FromString (SYMBOL_PRINT_NAME (self_sym->symbol));
150150}
151151
152static PyObject *
153sympy_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
152160PyObject *
153161symbol_to_symbol_object (struct symbol *sym)
154162{
174174 return (PyObject *) sym_obj;
175175}
176176
177struct symbol *
178symbol_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. */
188PyObject *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
177250void
178251gdbpy_initialize_symbols (void)
179252{
254254 if (PyType_Ready (&symbol_object_type) < 0)
255255 return;
256256
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
257300 Py_INCREF (&symbol_object_type);
258301 PyModule_AddObject (gdb_module, "Symbol", (PyObject *) &symbol_object_type);
259302}
toggle raw diff

gdb/python/value.c

 
4141static PyObject *valpy_equal_p (PyObject *self, PyObject *args);
4242static PyObject * valpy_lazy_p (PyObject *self, PyObject *args);
4343static PyObject * valpy_fetch_lazy (PyObject *self, PyObject *args);
44static PyObject * valpy_common_print (PyObject *self, PyObject *args);
4445
4546static PyMethodDef value_object_methods[] = {
4647 { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
5353 "Returns True if the value is lazy, False if not." },
5454 { "fetch_lazy", valpy_fetch_lazy, METH_NOARGS,
5555 "Fetches value from inferior memory." },
56 { "common_print", valpy_common_print, METH_VARARGS, "Prints value." },
5657 {NULL} /* Sentinel */
5758};
5859
256256 Py_RETURN_NONE;
257257}
258258
259static PyObject *
260valpy_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
259303/* FIXME: clarify the naming to say the value
260304 won't be deleted by the Python code. */
261305PyObject *
317317}
318318
319319PyObject *
320value_to_value_object (struct value *v)
321{
322 value_object *val_obj;
323
324 VALPY_RETURN_VALUE (val_obj, v);
325}
326
327PyObject *
320328gdb_value_from_int (PyObject *self, PyObject *args)
321329{
322330 int i;
378378}
379379
380380struct value *
381gdb_value_from_py_value (PyObject *self)
381value_object_to_value (PyObject *self)
382382{
383383 value_object *real = (value_object *)self;
384384 return real->value;
toggle raw diff

gdb/varobj.c

 
887887 if (!PyObject_IsInstance (py_v, (PyObject *)&value_object_type))
888888 error ("child list has object of invalid type");
889889
890 v = gdb_value_from_py_value (py_v);
890 v = value_object_to_value (py_v);
891891
892892 /* TODO: This assume the name of the i-th child never changes. */
893893
toggle raw diff