GDB (xrefs)

Classes | Macros | Functions | Variables
py-inferior.c File Reference
`#include "defs.h"`
`#include "gdbcore.h"`
`#include "gdbthread.h"`
`#include "inferior.h"`
`#include "objfiles.h"`
`#include "observer.h"`
`#include "python-internal.h"`
`#include "arch-utils.h"`
`#include "language.h"`
`#include "gdb_signals.h"`
`#include "py-event.h"`
`#include "py-stopevent.h"`

Go to the source code of this file.

## Classes
struct | threadlist_entry
struct | inferior_object
struct | membuf_object

## Macros
#define | INFPY_REQUIRE_VALID(Inferior)
#define | CHARBUFFERPROC_NAME charbufferproc

## Functions
PyTypeObject inferior_object_type | CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("inferior_object")
PyTypeObject membuf_object_type | CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("membuf_object")
static void | python_on_normal_stop (struct bpstats *bs, int print_frame)
static void | python_on_resume (ptid_t ptid)
static void | python_on_inferior_call_pre (ptid_t thread, CORE_ADDR address)
static void | python_on_inferior_call_post (ptid_t thread, CORE_ADDR address)
static void | python_on_memory_change (struct inferior *inferior, CORE_ADDR addr, ssize_t len, const bfd_byte *data)
static void | python_on_register_change (struct frame_info *frame, int regnum)
static void | python_inferior_exit (struct inferior *inf)
static void | python_new_objfile (struct objfile *objfile)
PyObject * | inferior_to_inferior_object (struct inferior *inferior)
static void | python_new_inferior (struct inferior *inf)
static void | python_inferior_deleted (struct inferior *inf)
PyObject * | find_inferior_object (int pid)
thread_object * | find_thread_object (ptid_t ptid)
static void | add_thread_object (struct thread_info *tp)
static void | delete_thread_object (struct thread_info *tp, int ignore)
static PyObject * | infpy_threads (PyObject *self, PyObject *args)
static PyObject * | infpy_get_num (PyObject *self, void *closure)
static PyObject * | infpy_get_pid (PyObject *self, void *closure)
static PyObject * | infpy_get_was_attached (PyObject *self, void *closure)
static int | build_inferior_list (struct inferior *inf, void *arg)
PyObject * | gdbpy_inferiors (PyObject *unused, PyObject *unused2)
static PyObject * | infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
static PyObject * | infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
static void | mbpy_dealloc (PyObject *self)
static PyObject * | mbpy_str (PyObject *self)
static Py_ssize_t | get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
static Py_ssize_t | get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
static Py_ssize_t | get_seg_count (PyObject *self, Py_ssize_t *lenp)
static Py_ssize_t | get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
static PyObject * | infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
static PyObject * | infpy_is_valid (PyObject *self, PyObject *args)
PyObject * | infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
static void | infpy_dealloc (PyObject *obj)
static void | py_free_inferior (struct inferior *inf, void *datum)
PyObject * | gdbpy_selected_inferior (PyObject *self, PyObject *args)
int | gdbpy_initialize_inferior (void)

## Variables
static const struct inferior_data * | infpy_inf_data_key
static gdb_PyGetSetDef | inferior_object_getset []
static PyMethodDef | inferior_object_methods []
PyTypeObject | inferior_object_type
static PyBufferProcs | buffer_procs
PyTypeObject | membuf_object_type

## Macro Definition Documentation

## ◆ CHARBUFFERPROC_NAME

#define CHARBUFFERPROC_NAME charbufferproc

Definition at line 1040 of file py-inferior.c.

## ◆ INFPY_REQUIRE_VALID

#define INFPY_REQUIRE_VALID | ( |  | Inferior | ) |

Value:
do { \
if (!Inferior->inferior) \
{ \
PyErr_SetString (PyExc_RuntimeError, \
_("Inferior no longer exists.")); \
return NULL; \
} \
} while (0)
_
#define _(String)
Definition: gdb_locale.h:35

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

Referenced by infpy_get_num(), infpy_get_pid(), infpy_get_was_attached(), infpy_thread_from_thread_handle(), and infpy_threads().

## Function Documentation

## ◆ add_thread_object()

static void add_thread_object | ( | struct thread_info * | tp | ) |
| static

Definition at line 329 of file py-inferior.c.

References create_thread_event_object(), create_thread_object(), evpy_emit_event(), evregpy_no_listeners_p(), gdb_py_events, gdb_python_initialized, gdbpy_print_stack(), gdb::ref_ptr< T, Policy >::get(), thread_object::inf_obj, threadlist_entry::next, inferior_object::nthreads, python_gdbarch, python_language, threadlist_entry::thread_obj, inferior_object::threads, and XNEW.

Referenced by gdbpy_initialize_inferior().

## ◆ build_inferior_list()

static int build_inferior_list | ( | struct inferior * | inf,
|  | void * | arg
| ) |  |
| static

Definition at line 466 of file py-inferior.c.

References inferior_to_inferior_object().

Referenced by gdbpy_inferiors().

## ◆ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF() [1/2]

PyTypeObject inferior_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF | ( | "inferior_object" |  | ) |

## ◆ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF() [2/2]

PyTypeObject membuf_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF | ( | "membuf_object" |  | ) |

## ◆ delete_thread_object()

static void delete_thread_object | ( | struct thread_info * | tp,
|  | int | ignore
| ) |  |
| static

Definition at line 367 of file py-inferior.c.

References find_inferior_object(), gdb_python_initialized, threadlist_entry::next, thread_info::ptid, ptid_get_pid(), Py_DECREF, python_gdbarch, python_language, thread_object::thread, threadlist_entry::thread_obj, and xfree().

Referenced by gdbpy_initialize_inferior().

## ◆ find_inferior_object()

PyObject* find_inferior_object | ( | int | pid | ) |

Definition at line 296 of file py-inferior.c.

References find_inferior_pid(), inferior_to_inferior_object(), and pid.

Referenced by create_thread_object(), delete_thread_object(), and find_thread_object().

## ◆ find_thread_object()

thread_object* find_thread_object | ( | ptid_t | ptid | ) |

Definition at line 307 of file py-inferior.c.

References find_inferior_object(), gdb::ref_ptr< T, Policy >::get(), threadlist_entry::next, pid, thread_info::ptid, ptid_equal(), ptid_get_pid(), thread_object::thread, and threadlist_entry::thread_obj.

Referenced by gdbpy_selected_thread(), get_event_thread(), and infpy_thread_from_thread_handle().

## ◆ gdbpy_inferiors()

PyObject* gdbpy_inferiors | ( | PyObject * | unused,
|  | PyObject * | unused2
| ) |  |

Definition at line 480 of file py-inferior.c.

References build_inferior_list(), gdb::ref_ptr< T, Policy >::get(), and iterate_over_inferiors().

## ◆ gdbpy_initialize_inferior()

int gdbpy_initialize_inferior | ( | void |  | ) |

Definition at line 917 of file py-inferior.c.

References add_thread_object(), delete_thread_object(), gdb_module, gdb_pymodule_addobject(), inferior_object_type, infpy_inf_data_key, membuf_object_type, observer_attach_inferior_added(), observer_attach_inferior_call_post(), observer_attach_inferior_call_pre(), observer_attach_inferior_exit(), observer_attach_inferior_removed(), observer_attach_memory_changed(), observer_attach_new_objfile(), observer_attach_new_thread(), observer_attach_normal_stop(), observer_attach_register_changed(), observer_attach_target_resumed(), observer_attach_thread_exit(), py_free_inferior(), python_inferior_deleted(), python_inferior_exit(), python_new_inferior(), python_new_objfile(), python_on_inferior_call_post(), python_on_inferior_call_pre(), python_on_memory_change(), python_on_normal_stop(), python_on_register_change(), and python_on_resume().

Referenced by do_start_initialization().

## ◆ gdbpy_selected_inferior()

PyObject* gdbpy_selected_inferior | ( | PyObject * | self,
|  | PyObject * | args
| ) |  |

Definition at line 911 of file py-inferior.c.

References current_inferior(), and inferior_to_inferior_object().

## ◆ get_char_buffer()

static Py_ssize_t get_char_buffer | ( | PyObject * | self,
|  | Py_ssize_t | segment,
|  | char ** | ptrptr
| ) |  |
| static

Definition at line 688 of file py-inferior.c.

References get_read_buffer().

## ◆ get_read_buffer()

static Py_ssize_t get_read_buffer | ( | PyObject * | self,
|  | Py_ssize_t | segment,
|  | void ** | ptrptr
| ) |  |
| static

Definition at line 656 of file py-inferior.c.

References _, membuf_object::buffer, and membuf_object::length.

Referenced by get_char_buffer(), and get_write_buffer().

## ◆ get_seg_count()

static Py_ssize_t get_seg_count | ( | PyObject * | self,
|  | Py_ssize_t * | lenp
| ) |  |
| static

Definition at line 679 of file py-inferior.c.

## ◆ get_write_buffer()

static Py_ssize_t get_write_buffer | ( | PyObject * | self,
|  | Py_ssize_t | segment,
|  | void ** | ptrptr
| ) |  |
| static

Definition at line 673 of file py-inferior.c.

References get_read_buffer().

## ◆ inferior_to_inferior_object()

PyObject* inferior_to_inferior_object | ( | struct inferior * | inferior | ) |

Definition at line 211 of file py-inferior.c.

References inferior_object::inferior, inferior_object_type, infpy_inf_data_key, inferior_object::nthreads, and inferior_object::threads.

Referenced by build_inferior_list(), create_exited_event_object(), find_inferior_object(), gdbpy_selected_inferior(), python_inferior_deleted(), and python_new_inferior().

## ◆ infpy_dealloc()

static void infpy_dealloc | ( | PyObject * | obj | ) |
| static

Definition at line 868 of file py-inferior.c.

References inferior_object::inferior, and infpy_inf_data_key.

## ◆ infpy_get_num()

static PyObject* infpy_get_num | ( | PyObject * | self,
|  | void * | closure
| ) |  |
| static

Definition at line 435 of file py-inferior.c.

References INFPY_REQUIRE_VALID.

## ◆ infpy_get_pid()

static PyObject* infpy_get_pid | ( | PyObject * | self,
|  | void * | closure
| ) |  |
| static

Definition at line 445 of file py-inferior.c.

References INFPY_REQUIRE_VALID, and inf::pid.

## ◆ infpy_get_was_attached()

static PyObject* infpy_get_was_attached | ( | PyObject * | self,
|  | void * | closure
| ) |  |
| static

Definition at line 455 of file py-inferior.c.

References INFPY_REQUIRE_VALID.

## ◆ infpy_is_valid()

static PyObject* infpy_is_valid | ( | PyObject * | self,
|  | PyObject * | args
| ) |  |
| static

Definition at line 807 of file py-inferior.c.

## ◆ infpy_read_memory()

static PyObject* infpy_read_memory | ( | PyObject * | self,
|  | PyObject * | args,
|  | PyObject * | kw
| ) |  |
| static

Definition at line 499 of file py-inferior.c.

References CATCH, END_CATCH, GDB_PY_HANDLE_EXCEPTION, gdb_PyArg_ParseTupleAndKeywords(), get_addr_from_python(), membuf_object_type, read_memory(), RETURN_MASK_ALL, TRY, xfree(), and xmalloc().

## ◆ infpy_search_memory()

static PyObject* infpy_search_memory | ( | PyObject * | self,
|  | PyObject * | args,
|  | PyObject * | kw
| ) |  |
| static

Definition at line 710 of file py-inferior.c.

References _, CATCH, CORE_ADDR_MAX, END_CATCH, exception_none, GDB_PY_HANDLE_EXCEPTION, gdb_PyArg_ParseTupleAndKeywords(), get_addr_from_python(), if(), RETURN_MASK_ALL, target_search_memory(), and TRY.

## ◆ infpy_thread_from_thread_handle()

PyObject* infpy_thread_from_thread_handle | ( | PyObject * | self,
|  | PyObject * | args,
|  | PyObject * | kw
| ) |  |

Definition at line 821 of file py-inferior.c.

References _, CATCH, END_CATCH, find_thread_by_handle(), find_thread_object(), GDB_PY_HANDLE_EXCEPTION, gdb_PyArg_ParseTupleAndKeywords(), gdbpy_is_value_object(), inferior_object::inferior, INFPY_REQUIRE_VALID, thread_info::ptid, RETURN_MASK_ALL, thread_info::thread_info(), TRY, and value_object_to_value().

## ◆ infpy_threads()

static PyObject* infpy_threads | ( | PyObject * | self,
|  | PyObject * | args
| ) |  |
| static

Definition at line 401 of file py-inferior.c.

References CATCH, END_CATCH, GDB_PY_HANDLE_EXCEPTION, INFPY_REQUIRE_VALID, threadlist_entry::next, inferior_object::nthreads, RETURN_MASK_ALL, threadlist_entry::thread_obj, inferior_object::threads, TRY, and update_thread_list().

## ◆ infpy_write_memory()

static PyObject* infpy_write_memory | ( | PyObject * | self,
|  | PyObject * | args,
|  | PyObject * | kw
| ) |  |
| static

Definition at line 556 of file py-inferior.c.

References CATCH, END_CATCH, exception_none, GDB_PY_HANDLE_EXCEPTION, gdb_PyArg_ParseTupleAndKeywords(), get_addr_from_python(), if(), RETURN_MASK_ALL, TRY, and write_memory_with_notification().

## ◆ mbpy_dealloc()

static void mbpy_dealloc | ( | PyObject * | self | ) |
| static

Definition at line 616 of file py-inferior.c.

References Py_TYPE, and xfree().

## ◆ mbpy_str()

static PyObject* mbpy_str | ( | PyObject * | self | ) |
| static

Definition at line 624 of file py-inferior.c.

References _, membuf_object::addr, membuf_object::length, paddress(), pulongest(), and python_gdbarch.

## ◆ py_free_inferior()

static void py_free_inferior | ( | struct inferior * | inf,
|  | void * | datum
| ) |  |
| static

Definition at line 882 of file py-inferior.c.

References gdb_python_initialized, threadlist_entry::next, Py_DECREF, python_gdbarch, python_language, threadlist_entry::thread_obj, and xfree().

Referenced by gdbpy_initialize_inferior().

## ◆ python_inferior_deleted()

static void python_inferior_deleted | ( | struct inferior * | inf | ) |
| static

Definition at line 268 of file py-inferior.c.

References create_event_object(), evpy_add_attribute(), evpy_emit_event(), evregpy_no_listeners_p(), gdb_py_events, gdb_python_initialized, gdbpy_print_stack(), gdb::ref_ptr< T, Policy >::get(), inferior_to_inferior_object(), python_gdbarch, and python_language.

Referenced by gdbpy_initialize_inferior().

## ◆ python_inferior_exit()

static void python_inferior_exit | ( | struct inferior * | inf | ) |
| static

Definition at line 163 of file py-inferior.c.

References current_language, emit_exited_event(), gdb_python_initialized, gdbpy_print_stack(), and target_gdbarch().

Referenced by gdbpy_initialize_inferior().

## ◆ python_new_inferior()

static void python_new_inferior | ( | struct inferior * | inf | ) |
| static

Definition at line 241 of file py-inferior.c.

References create_event_object(), evpy_add_attribute(), evpy_emit_event(), evregpy_no_listeners_p(), gdb_py_events, gdb_python_initialized, gdbpy_print_stack(), gdb::ref_ptr< T, Policy >::get(), inferior_to_inferior_object(), python_gdbarch, and python_language.

Referenced by gdbpy_initialize_inferior().

## ◆ python_new_objfile()

static void python_new_objfile | ( | struct objfile * | objfile | ) |
| static

Definition at line 184 of file py-inferior.c.

References current_language, emit_clear_objfiles_event(), emit_new_objfile_event(), gdb_python_initialized, gdbpy_print_stack(), get_objfile_arch(), and target_gdbarch().

Referenced by gdbpy_initialize_inferior().

## ◆ python_on_inferior_call_post()

static void python_on_inferior_call_post | ( | ptid_t | thread,
|  | CORE_ADDR | address
| ) |  |
| static

Definition at line 128 of file py-inferior.c.

References current_language, emit_inferior_call_event(), gdbpy_print_stack(), INFERIOR_CALL_POST, and target_gdbarch().

Referenced by gdbpy_initialize_inferior().

## ◆ python_on_inferior_call_pre()

static void python_on_inferior_call_pre | ( | ptid_t | thread,
|  | CORE_ADDR | address
| ) |  |
| static

Definition at line 116 of file py-inferior.c.

References current_language, emit_inferior_call_event(), gdbpy_print_stack(), INFERIOR_CALL_PRE, and target_gdbarch().

Referenced by gdbpy_initialize_inferior().

## ◆ python_on_memory_change()

static void python_on_memory_change | ( | struct inferior * | inferior,
|  | CORE_ADDR | addr,
|  | ssize_t | len,
|  | const bfd_byte * | data
| ) |  |
| static

Definition at line 141 of file py-inferior.c.

References current_language, emit_memory_changed_event(), gdbpy_print_stack(), and target_gdbarch().

Referenced by gdbpy_initialize_inferior().

## ◆ python_on_normal_stop()

static void python_on_normal_stop | ( | struct bpstats * | bs,
|  | int | print_frame
| ) |  |
| static

Definition at line 82 of file py-inferior.c.

References current_language, emit_stop_event(), find_thread_ptid(), gdb_python_initialized, gdbpy_print_stack(), get_current_arch(), inferior_ptid, inferior_thread(), thread_suspend_state::stop_signal, and thread_info::suspend.

Referenced by gdbpy_initialize_inferior().

## ◆ python_on_register_change()

static void python_on_register_change | ( | struct frame_info * | frame,
|  | int | regnum
| ) |  |
| static

Definition at line 154 of file py-inferior.c.

References current_language, emit_register_changed_event(), gdbpy_print_stack(), regnum, and target_gdbarch().

Referenced by gdbpy_initialize_inferior().

## ◆ python_on_resume()

static void python_on_resume | ( | ptid_t | ptid | ) |
| static

Definition at line 101 of file py-inferior.c.

References current_language, emit_continue_event(), gdb_python_initialized, gdbpy_print_stack(), and target_gdbarch().

Referenced by gdbpy_initialize_inferior().

## Variable Documentation

## ◆ buffer_procs

PyBufferProcs buffer_procs
| static

Initial value:
= {
get_read_buffer,
get_write_buffer,
get_seg_count,
(CHARBUFFERPROC_NAME) get_char_buffer
}
CHARBUFFERPROC_NAME
#define CHARBUFFERPROC_NAME
Definition: py-inferior.c:1040
get_read_buffer
static Py_ssize_t get_read_buffer(PyObject *self, Py_ssize_t segment, void **ptrptr)
Definition: py-inferior.c:656
get_seg_count
static Py_ssize_t get_seg_count(PyObject *self, Py_ssize_t *lenp)
Definition: py-inferior.c:679
get_char_buffer
static Py_ssize_t get_char_buffer(PyObject *self, Py_ssize_t segment, char **ptrptr)
Definition: py-inferior.c:688
get_write_buffer
static Py_ssize_t get_write_buffer(PyObject *self, Py_ssize_t segment, void **ptrptr)
Definition: py-inferior.c:673

Definition at line 1043 of file py-inferior.c.

## ◆ inferior_object_getset

gdb_PyGetSetDef inferior_object_getset[]
| static

Initial value:
=
{
{ "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL },
{ "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.",
NULL },
{ "was_attached", infpy_get_was_attached, NULL,
"True if the inferior was created using 'attach'.", NULL },
{ NULL }
}
infpy_get_was_attached
static PyObject * infpy_get_was_attached(PyObject *self, void *closure)
Definition: py-inferior.c:455
infpy_get_pid
static PyObject * infpy_get_pid(PyObject *self, void *closure)
Definition: py-inferior.c:445
infpy_get_num
static PyObject * infpy_get_num(PyObject *self, void *closure)
Definition: py-inferior.c:435

Definition at line 950 of file py-inferior.c.

## ◆ inferior_object_methods

PyMethodDef inferior_object_methods[]
| static

Initial value:
=
{
{ "is_valid", infpy_is_valid, METH_NOARGS,
"is_valid () -> Boolean.\n\
Return true if this inferior is valid, false if not." },
{ "threads", infpy_threads, METH_NOARGS,
"Return all the threads of this inferior." },
{ "read_memory", (PyCFunction) infpy_read_memory,
METH_VARARGS | METH_KEYWORDS,
"read_memory (address, length) -> buffer\n\
Return a buffer object for reading from the inferior's memory." },
{ "write_memory", (PyCFunction) infpy_write_memory,
METH_VARARGS | METH_KEYWORDS,
"write_memory (address, buffer [, length])\n\
Write the given buffer object to the inferior's memory." },
{ "search_memory", (PyCFunction) infpy_search_memory,
METH_VARARGS | METH_KEYWORDS,
"search_memory (address, length, pattern) -> long\n\
Return a long with the address of a match, or None." },
{ "thread_from_thread_handle", (PyCFunction) infpy_thread_from_thread_handle,
METH_VARARGS | METH_KEYWORDS,
"thread_from_thread_handle (handle) -> gdb.InferiorThread.\n\
Return thread object corresponding to thread handle." },
{ NULL }
}
infpy_is_valid
static PyObject * infpy_is_valid(PyObject *self, PyObject *args)
Definition: py-inferior.c:807
infpy_threads
static PyObject * infpy_threads(PyObject *self, PyObject *args)
Definition: py-inferior.c:401
infpy_thread_from_thread_handle
PyObject * infpy_thread_from_thread_handle(PyObject *self, PyObject *args, PyObject *kw)
Definition: py-inferior.c:821
infpy_read_memory
static PyObject * infpy_read_memory(PyObject *self, PyObject *args, PyObject *kw)
Definition: py-inferior.c:499
infpy_search_memory
static PyObject * infpy_search_memory(PyObject *self, PyObject *args, PyObject *kw)
Definition: py-inferior.c:710
infpy_write_memory
static PyObject * infpy_write_memory(PyObject *self, PyObject *args, PyObject *kw)
Definition: py-inferior.c:556

Definition at line 960 of file py-inferior.c.

## ◆ inferior_object_type

PyTypeObject inferior_object_type

Definition at line 986 of file py-inferior.c.

Referenced by gdbpy_initialize_inferior(), and inferior_to_inferior_object().

## ◆ infpy_inf_data_key

const struct inferior_data* infpy_inf_data_key
| static

Definition at line 56 of file py-inferior.c.

Referenced by gdbpy_initialize_inferior(), inferior_to_inferior_object(), and infpy_dealloc().

## ◆ membuf_object_type

PyTypeObject membuf_object_type

Definition at line 1053 of file py-inferior.c.

Referenced by gdbpy_initialize_inferior(), and infpy_read_memory().