static PyObject * infpy_threads (PyObject *self, PyObject *args) { int i; struct threadlist_entry *entry; inferior_object *inf_obj = (inferior_object *) self; PyObject *tuple; volatile struct gdb_exception except; INFPY_REQUIRE_VALID (inf_obj); TRY_CATCH (except, RETURN_MASK_ALL) update_thread_list (); GDB_PY_HANDLE_EXCEPTION (except); tuple = PyTuple_New (inf_obj->nthreads); if (!tuple) return NULL; for (i = 0, entry = inf_obj->threads; i < inf_obj->nthreads; i++, entry = entry->next) { Py_INCREF (entry->thread_obj); PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->thread_obj); } return tuple; }
/* Implementation of gdb.lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this) A tuple with 2 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 (see comment in lookup_symbol_in_language). */ PyObject * gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) { int domain = VAR_DOMAIN, is_a_field_of_this = 0; const char *name; static char *keywords[] = { "name", "block", "domain", NULL }; struct symbol *symbol; PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj; struct block *block = NULL; if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name, &block_object_type, &block_obj, &domain)) return NULL; if (block_obj) block = block_object_to_block (block_obj); else { struct frame_info *selected_frame; volatile struct gdb_exception except; TRY_CATCH (except, RETURN_MASK_ALL) { selected_frame = get_selected_frame (_("No frame selected.")); block = block_for_pc (get_frame_address_in_block (selected_frame)); } GDB_PY_HANDLE_EXCEPTION (except); }
static PyObject * frapy_is_valid (PyObject *self, PyObject *args) { struct frame_info *frame = NULL; TRY { frame = frame_object_to_frame_info (self); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
/* Find a pretty-printer object for the varobj module. Returns a new reference to the object if successful; returns NULL if not. VALUE is the value for which a printer tests to determine if it can pretty-print the value. */ PyObject * gdbpy_get_varobj_pretty_printer (struct value *value) { PyObject *val_obj; PyObject *pretty_printer = NULL; TRY { value = value_copy (value); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
static PyObject * thpy_switch (PyObject *self, PyObject *args) { thread_object *thread_obj = (thread_object *) self; THPY_REQUIRE_VALID (thread_obj); TRY { switch_to_thread (thread_obj->thread->ptid); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
static PyObject * typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind) { PyObject *py_type = self; PyObject *result = NULL, *iter = NULL; struct type *type = ((type_object *) py_type)->type; struct type *checked_type = type; TRY { checked_type = check_typedef (checked_type); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
static PyObject * sympy_needs_frame (PyObject *self, void *closure) { struct symbol *symbol = NULL; int result = 0; SYMPY_REQUIRE_VALID (self, symbol); TRY { result = symbol_read_needs_frame (symbol); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
PyObject * recpy_bt_insn_sal (PyObject *self, void *closure) { const btrace_insn * const insn = btrace_insn_from_recpy_insn (self); PyObject *result = NULL; if (insn == NULL) return NULL; TRY { result = symtab_and_line_to_sal_object (find_pc_line (insn->pc, 0)); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
static PyObject * stpy_convert_to_value (PyObject *self, PyObject *args) { lazy_string_object *self_string = (lazy_string_object *) self; struct value *val = NULL; if (self_string->address == 0) { PyErr_SetString (gdbpy_gdb_memory_error, _("Cannot create a value from NULL.")); return NULL; } TRY { struct type *type = type_object_to_type (self_string->type); struct type *realtype; gdb_assert (type != NULL); realtype = check_typedef (type); switch (TYPE_CODE (realtype)) { case TYPE_CODE_PTR: /* If a length is specified we need to convert this to an array of the specified size. */ if (self_string->length != -1) { /* PR 20786: There's no way to specify an array of length zero. Record a length of [0,-1] which is how Ada does it. Anything we do is broken, but this is one possible solution. */ type = lookup_array_range_type (TYPE_TARGET_TYPE (realtype), 0, self_string->length - 1); val = value_at_lazy (type, self_string->address); } else val = value_from_pointer (type, self_string->address); break; default: val = value_at_lazy (type, self_string->address); break; } } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
static PyObject * objfpy_get_build_id (PyObject *self, void *closure) { objfile_object *obj = (objfile_object *) self; struct objfile *objfile = obj->objfile; const struct bfd_build_id *build_id = NULL; OBJFPY_REQUIRE_VALID (obj); TRY { build_id = build_id_bfd_get (objfile->obfd); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
/* Given a value of a pointer type, apply the C unary * operator to it. */ static PyObject * valpy_dereference (PyObject *self, PyObject *args) { PyObject *result = NULL; TRY { struct value *res_val; struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ()); res_val = value_ind (((value_object *) self)->value); result = value_to_value_object (res_val); do_cleanups (cleanup); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
static PyObject * infpy_threads (PyObject *self, PyObject *args) { int i; struct threadlist_entry *entry; inferior_object *inf_obj = (inferior_object *) self; PyObject *tuple; INFPY_REQUIRE_VALID (inf_obj); TRY { update_thread_list (); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
/* Return the innermost lexical block containing the specified pc value, or 0 if there is none. */ PyObject * gdbpy_block_for_pc (PyObject *self, PyObject *args) { gdb_py_ulongest pc; const struct block *block = NULL; struct compunit_symtab *cust = NULL; if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc)) return NULL; TRY { cust = find_pc_compunit_symtab (pc); if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL) block = block_for_pc (pc); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
/* Implementation of gdb.write_memory (address, buffer [, length]). Writes the contents of BUFFER (a Python object supporting the read buffer protocol) at ADDRESS in the inferior's memory. Write LENGTH bytes from BUFFER, or its entire contents if the argument is not provided. The function returns nothing. */ static PyObject * infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) { int buf_len, error = 0; const char *buffer; CORE_ADDR addr, length; PyObject *addr_obj, *length_obj = NULL; volatile struct gdb_exception except; static char *keywords[] = { "address", "buffer", "length", NULL }; if (! PyArg_ParseTupleAndKeywords (args, kw, "Os#|O", keywords, &addr_obj, &buffer, &buf_len, &length_obj)) return NULL; TRY_CATCH (except, RETURN_MASK_ALL) { if (!get_addr_from_python (addr_obj, &addr)) { error = 1; break; } if (!length_obj) length = buf_len; else if (!get_addr_from_python (length_obj, &length)) { error = 1; break; } write_memory (addr, buffer, length); } GDB_PY_HANDLE_EXCEPTION (except); if (error) return NULL; Py_RETURN_NONE; }
CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
/* Implementation of gdb.read_memory (address, length). Returns a Python buffer object with LENGTH bytes of the inferior's memory at ADDRESS. Both arguments are integers. */ static PyObject * infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) { int error = 0; CORE_ADDR addr, length; void *buffer = NULL; membuf_object *membuf_obj; PyObject *addr_obj, *length_obj; struct cleanup *cleanups; volatile struct gdb_exception except; static char *keywords[] = { "address", "length", NULL }; if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords, &addr_obj, &length_obj)) return NULL; cleanups = make_cleanup (null_cleanup, NULL); TRY_CATCH (except, RETURN_MASK_ALL) { if (!get_addr_from_python (addr_obj, &addr) || !get_addr_from_python (length_obj, &length)) { error = 1; break; } buffer = xmalloc (length); make_cleanup (xfree, buffer); read_memory (addr, buffer, length); } if (except.reason < 0) { do_cleanups (cleanups); GDB_PY_HANDLE_EXCEPTION (except); } if (error) { do_cleanups (cleanups); return NULL; } membuf_obj = PyObject_New (membuf_object, &membuf_object_type); if (membuf_obj == NULL) { PyErr_SetString (PyExc_MemoryError, _("Could not allocate memory buffer object.")); do_cleanups (cleanups); return NULL; } discard_cleanups (cleanups); membuf_obj->buffer = buffer; membuf_obj->addr = addr; membuf_obj->length = length; return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0, Py_END_OF_BUFFER); }