53 extern PyTypeObject inferior_object_type
67 extern PyTypeObject membuf_object_type
71 #define INFPY_REQUIRE_VALID(Inferior) \
73 if (!Inferior->inferior) \
75 PyErr_SetString (PyExc_RuntimeError, \
76 _("Inferior no longer exists.")); \
85 enum gdb_signal stop_signal;
189 const LONGEST *exit_code = NULL;
245 inf_obj = inferior_data (inferior, infpy_inf_data_key);
256 set_inferior_data (inferior, infpy_inf_data_key, inf_obj);
260 Py_INCREF ((PyObject *)inf_obj);
262 return (PyObject *) inf_obj;
297 thread = thread->
next)
366 for (entry = &inf_obj->
threads; *entry != NULL; entry =
368 if ((*entry)->thread_obj->thread == tp)
381 *entry = (*entry)->
next;
411 tuple = PyTuple_New (inf_obj->
nthreads);
415 for (i = 0, entry = inf_obj->
threads; i < inf_obj->nthreads;
416 i++, entry = entry->
next)
419 PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->
thread_obj);
459 PyObject *list = arg;
466 success = PyList_Append (list, inferior);
480 PyObject *list, *tuple;
482 list = PyList_New (0);
492 tuple = PyList_AsTuple (list);
510 PyObject *addr_obj, *length_obj, *result;
511 static char *keywords[] = {
"address",
"length", NULL };
513 if (! PyArg_ParseTupleAndKeywords (args, kw,
"OO", keywords,
514 &addr_obj, &length_obj))
534 membuf_obj = PyObject_New (
membuf_object, &membuf_object_type);
535 if (membuf_obj == NULL)
541 membuf_obj->buffer = buffer;
542 membuf_obj->addr = addr;
543 membuf_obj->length = length;
546 result = PyMemoryView_FromObject ((PyObject *) membuf_obj);
548 result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
569 PyObject *addr_obj, *length_obj = NULL;
570 static char *keywords[] = {
"address",
"buffer",
"length", NULL };
574 if (! PyArg_ParseTupleAndKeywords (args, kw,
"Os*|O", keywords,
582 if (! PyArg_ParseTupleAndKeywords (args, kw,
"Os#|O", keywords,
583 &addr_obj, &buffer, &buf_len,
607 PyBuffer_Release (&pybuf);
615 PyBuffer_Release (&pybuf);
625 Py_TYPE (
self)->tp_free (
self);
634 return PyString_FromFormat (
_(
"Memory buffer for address %s, \
635 which is %s bytes long."),
643 get_buffer (PyObject *
self, Py_buffer *buf,
int flags)
648 ret = PyBuffer_FillInfo (buf,
self, membuf_obj->
buffer,
665 PyErr_SetString (PyExc_SystemError,
666 _(
"The memory buffer supports only one segment."));
670 *ptrptr = membuf_obj->
buffer;
672 return membuf_obj->
length;
697 *ptrptr = (
char *) ptr;
717 static char *keywords[] = {
"address",
"length",
"pattern", NULL };
718 PyObject *start_addr_obj, *length_obj;
719 Py_ssize_t pattern_size;
726 if (! PyArg_ParseTupleAndKeywords (args, kw,
"OOs*", keywords,
727 &start_addr_obj, &length_obj,
732 pattern_size = pybuf.len;
736 if (! PyArg_ParseTupleAndKeywords (args, kw,
"OOO", keywords,
737 &start_addr_obj, &length_obj,
741 if (!PyObject_CheckReadBuffer (pattern))
743 PyErr_SetString (PyExc_RuntimeError,
744 _(
"The pattern is not a Python buffer."));
749 if (PyObject_AsReadBuffer (pattern, &buffer, &pattern_size) == -1)
761 PyErr_SetString (PyExc_ValueError,
762 _(
"Search range is empty."));
767 || (start_addr + length - 1) < start_addr)
769 PyErr_SetString (PyExc_ValueError,
770 _(
"The search range is too large."));
777 buffer, pattern_size,
787 PyBuffer_Release (&pybuf);
792 return PyLong_FromLong (found_addr);
798 PyBuffer_Release (&pybuf);
826 set_inferior_data (inf, infpy_inf_data_key, NULL);
847 for (th_entry = inf_obj->
threads; th_entry != NULL;)
852 th_entry = th_entry->
next;
874 if (PyType_Ready (&inferior_object_type) < 0)
878 (PyObject *) &inferior_object_type) < 0)
895 membuf_object_type.tp_new = PyType_GenericNew;
896 if (PyType_Ready (&membuf_object_type) < 0)
900 &membuf_object_type);
905 {
"num",
infpy_get_num, NULL,
"ID of inferior, as assigned by GDB.", NULL },
906 {
"pid",
infpy_get_pid, NULL,
"PID of inferior, as assigned by the OS.",
909 "True if the inferior was created using 'attach'.", NULL },
916 "is_valid () -> Boolean.\n\
917 Return true if this inferior is valid, false if not." },
919 "Return all the threads of this inferior." },
921 METH_VARARGS | METH_KEYWORDS,
922 "read_memory (address, length) -> buffer\n\
923 Return a buffer object for reading from the inferior's memory." },
925 METH_VARARGS | METH_KEYWORDS,
926 "write_memory (address, buffer [, length])\n\
927 Write the given buffer object to the inferior's memory." },
929 METH_VARARGS | METH_KEYWORDS,
930 "search_memory (address, length, pattern) -> long\n\
931 Return a long with the address of a match, or None." },
935 PyTypeObject inferior_object_type =
956 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
957 "GDB inferior object",
964 inferior_object_methods,
966 inferior_object_getset,
978 static PyBufferProcs buffer_procs =
986 #if HAVE_LIBPYTHON2_4
987 #define CHARBUFFERPROC_NAME getcharbufferproc
989 #define CHARBUFFERPROC_NAME charbufferproc
992 static PyBufferProcs buffer_procs = {
1002 PyTypeObject membuf_object_type = {
1023 "GDB memory buffer object",
struct gdbarch * target_gdbarch(void)
static void python_on_resume(ptid_t ptid)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
static PyObject * infpy_is_valid(PyObject *self, PyObject *args)
struct thread_info * find_thread_ptid(ptid_t ptid)
#define INFPY_REQUIRE_VALID(Inferior)
struct observer * observer_attach_thread_exit(observer_thread_exit_ftype *f)
static void python_on_normal_stop(struct bpstats *bs, int print_frame)
static void add_thread_object(struct thread_info *tp)
int ptid_equal(ptid_t ptid1, ptid_t ptid2)
thread_object * create_thread_object(struct thread_info *tp)
static void mbpy_dealloc(PyObject *self)
static PyObject * infpy_threads(PyObject *self, PyObject *args)
struct thread_info * inferior_thread(void)
const struct gdb_exception exception_none
#define CHARBUFFERPROC_NAME
struct observer * observer_attach_inferior_exit(observer_inferior_exit_ftype *f)
int emit_clear_objfiles_event(void)
struct inferior * iterate_over_inferiors(int(*callback)(struct inferior *, void *), void *data)
int emit_stop_event(struct bpstats *bs, enum gdb_signal stop_signal)
enum gdb_signal stop_signal
int emit_inferior_call_event(inferior_call_kind kind, ptid_t thread, CORE_ADDR addr)
static PyObject * infpy_get_was_attached(PyObject *self, void *closure)
static void python_on_inferior_call_post(ptid_t thread, CORE_ADDR address)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
int gdbpy_initialize_inferior(void)
static void py_free_inferior(struct inferior *inf, void *datum)
#define GDB_PY_HANDLE_EXCEPTION(Exception)
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
static void infpy_dealloc(PyObject *obj)
static int build_inferior_list(struct inferior *inf, void *arg)
#define CATCH(EXCEPTION, MASK)
static const struct inferior_data * infpy_inf_data_key
PyObject_HEAD struct inferior * inferior
static Py_ssize_t get_read_buffer(PyObject *self, Py_ssize_t segment, void **ptrptr)
static PyObject * infpy_get_pid(PyObject *self, void *closure)
int emit_exited_event(const LONGEST *exit_code, struct inferior *inf)
PyObject * gdbpy_selected_inferior(PyObject *self, PyObject *args)
thread_object * find_thread_object(ptid_t ptid)
int emit_memory_changed_event(CORE_ADDR addr, ssize_t len)
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
char * pulongest(ULONGEST u)
struct inferior * find_inferior_pid(int pid)
struct gdbarch * get_current_arch(void)
struct gdbarch * python_gdbarch
struct cleanup * ensure_python_env(struct gdbarch *gdbarch, const struct language_defn *language)
static PyObject * infpy_read_memory(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * infpy_search_memory(PyObject *self, PyObject *args, PyObject *kw)
struct observer * observer_attach_target_resumed(observer_target_resumed_ftype *f)
int gdb_python_initialized
int emit_register_changed_event(struct frame_info *frame, int regnum)
static PyMethodDef inferior_object_methods[]
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
static void python_on_inferior_call_pre(ptid_t thread, CORE_ADDR address)
PyTypeObject inferior_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("inferior_object")
int emit_new_objfile_event(struct objfile *objfile)
PyObject_HEAD struct thread_info * thread
int ptid_get_pid(ptid_t ptid)
static PyGetSetDef inferior_object_getset[]
static void python_on_memory_change(struct inferior *inferior, CORE_ADDR addr, ssize_t len, const bfd_byte *data)
static void print_frame(struct frame_info *frame, int print_level, enum print_what print_what, int print_args, struct symtab_and_line sal)
const struct language_defn * current_language
struct threadlist_entry * next
void update_thread_list(void)
PyObject * find_inferior_object(int pid)
static Py_ssize_t get_seg_count(PyObject *self, Py_ssize_t *lenp)
struct observer * observer_attach_register_changed(observer_register_changed_ftype *f)
int target_search_memory(CORE_ADDR start_addr, ULONGEST search_space_len, const gdb_byte *pattern, ULONGEST pattern_len, CORE_ADDR *found_addrp)
static PyObject * infpy_write_memory(PyObject *self, PyObject *args, PyObject *kw)
struct observer * observer_attach_inferior_call_pre(observer_inferior_call_pre_ftype *f)
void gdbpy_print_stack(void)
struct thread_suspend_state suspend
static Py_ssize_t get_char_buffer(PyObject *self, Py_ssize_t segment, char **ptrptr)
int emit_continue_event(ptid_t ptid)
struct inferior * current_inferior(void)
static void python_on_register_change(struct frame_info *frame, int regnum)
struct observer * observer_attach_inferior_call_post(observer_inferior_call_post_ftype *f)
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
static void python_new_objfile(struct objfile *objfile)
struct observer * observer_attach_normal_stop(observer_normal_stop_ftype *f)
struct observer * observer_attach_new_objfile(observer_new_objfile_ftype *f)
int get_addr_from_python(PyObject *obj, CORE_ADDR *addr)
PyObject_HEAD void * buffer
struct observer * observer_attach_new_thread(observer_new_thread_ftype *f)
static PyObject * mbpy_str(PyObject *self)
thread_object * thread_obj
const struct language_defn * python_language
static PyObject * infpy_get_num(PyObject *self, void *closure)
static Py_ssize_t get_write_buffer(PyObject *self, Py_ssize_t segment, void **ptrptr)
void write_memory_with_notification(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
PyObject * inferior_to_inferior_object(struct inferior *inferior)
PyObject * gdbpy_inferiors(PyObject *unused, PyObject *unused2)
struct observer * observer_attach_memory_changed(observer_memory_changed_ftype *f)
static void python_inferior_exit(struct inferior *inf)
struct threadlist_entry * threads
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int int rusage_t pid_t pid
void do_cleanups(struct cleanup *old_chain)
static void delete_thread_object(struct thread_info *tp, int ignore)
const ULONGEST const LONGEST len
#define PyVarObject_HEAD_INIT(type, size)