diff options
author | Sami Wagiaalla <swagiaal@redhat.com> | 2011-02-04 21:54:16 +0000 |
---|---|---|
committer | Sami Wagiaalla <swagiaal@redhat.com> | 2011-02-04 21:54:16 +0000 |
commit | 505500db28fbb90d6391c2fdcfd27bcab443cd9c (patch) | |
tree | 82a0b8c11cf0c80e0b16b73d3b468427ad8be8b6 /gdb/python | |
parent | 9e0ac564072ea01f85a0f3c1f8b873abbbe634be (diff) | |
download | gdb-505500db28fbb90d6391c2fdcfd27bcab443cd9c.zip gdb-505500db28fbb90d6391c2fdcfd27bcab443cd9c.tar.gz gdb-505500db28fbb90d6391c2fdcfd27bcab443cd9c.tar.bz2 |
Add Python support for GDB events.
2011-02-04 Sami Wagiaalla <swagiaal@redhat.com>
* gdb.python/py-evthreads.c: New file.
* gdb.python/py-evthreads.exp: New file.
* gdb.python/py-events.py: New file.
* gdb.python/py-events.exp: New file.
* gdb.python/py-events.c: New file.
2011-02-04 Sami Wagiaalla <swagiaal@redhat.com>
Oguz Kayral <oguzkayral@gmail.com>
* python/py-inferior.c (python_on_normal_stop): New function.
(python_on_resume): New function.
(python_inferior_exit): New function.
(gdbpy_initialize_inferior): Add normal_stop, target_resumed, and
inferior_exit observers.
* python/py-evtregistry.c: New file.
* python/py-threadevent.c : New file.
* python/py-event.c: New file.
* python/py-evts.c: New file.
* python/py-continueevent.c: New file.
* python/py-bpevent.c: New file.
* python/py-signalevent.c: New file.
* python/py-exetiedevent.c: New file.
* python/py-breakpoint.c (gdbpy_breakpoint_from_bpstats): New function.
Move struct breakpoint_object from here...
* python/python-internal.h: ... to here.
* python/py-event.h: New file.
* python/py-events.h: New file.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-breakpointstopevent.o,
py-continueevent.o, py-event.o, py-eventregistry.o, py-events.o,
py-exitedevent.o, py-signalstopevent.o, and py-stopevent.o.
(SUBDIR_PYTHON_SRCS): Add py-breakpointstopevent.c,
py-continueevent.c, py-event.c, py-eventregistry.c, py-events.c,
py-exitedevent.c, py-signalstopevent.c, and py-stopevent.c.
Add build rules for all the above.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-breakpoint.c | 3 | ||||
-rw-r--r-- | gdb/python/py-inferior.c | 63 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 18 | ||||
-rw-r--r-- | gdb/python/python.c | 10 |
4 files changed, 89 insertions, 5 deletions
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index e58533a..bfad002 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -29,9 +29,6 @@ #include "cli/cli-script.h" #include "ada-lang.h" -/* From breakpoint.c. */ -typedef struct breakpoint_object breakpoint_object; - static PyTypeObject breakpoint_object_type; /* Number of live breakpoints. */ diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index ba81177..12a82d2 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -26,6 +26,9 @@ #include "python-internal.h" #include "arch-utils.h" #include "language.h" +#include "gdb_signals.h" +#include "py-event.h" +#include "py-stopevent.h" struct threadlist_entry { thread_object *thread_obj; @@ -73,6 +76,59 @@ static PyTypeObject membuf_object_type; } \ } while (0) +static void +python_on_normal_stop (struct bpstats *bs, int print_frame) +{ + struct cleanup *cleanup; + enum target_signal stop_signal; + + if (!find_thread_ptid (inferior_ptid)) + return; + + stop_signal = inferior_thread ()->suspend.stop_signal; + + cleanup = ensure_python_env (get_current_arch (), current_language); + + if (emit_stop_event (bs, stop_signal) < 0) + gdbpy_print_stack (); + + do_cleanups (cleanup); +} + +static void +python_on_resume (ptid_t ptid) +{ + struct cleanup *cleanup; + + cleanup = ensure_python_env (get_current_arch (), current_language); + + if (emit_continue_event (ptid) < 0) + gdbpy_print_stack (); + + do_cleanups (cleanup); +} + +static void +python_inferior_exit (struct inferior *inf) +{ + struct cleanup *cleanup; + LONGEST exit_code = -1; + ptid_t ptidp; + struct target_waitstatus status; + + cleanup = ensure_python_env (get_current_arch (), current_language); + + get_last_target_status (&ptidp, &status); + + exit_code = status.value.integer; + + if (exit_code >= 0 + && emit_exited_event (exit_code) < 0) + gdbpy_print_stack (); + + do_cleanups (cleanup); +} + /* Return a borrowed reference to the Python object of type Inferior representing INFERIOR. If the object has already been created, return it, otherwise, create it. Return NULL on failure. */ @@ -108,8 +164,8 @@ inferior_to_inferior_object (struct inferior *inferior) /* Finds the Python Inferior object for the given PID. Returns a borrowed reference, or NULL if PID does not match any inferior - obect. - */ + object. */ + PyObject * find_inferior_object (int pid) { @@ -590,6 +646,9 @@ gdbpy_initialize_inferior (void) observer_attach_new_thread (add_thread_object); observer_attach_thread_exit (delete_thread_object); + observer_attach_normal_stop (python_on_normal_stop); + observer_attach_target_resumed (python_on_resume); + observer_attach_inferior_exit (python_inferior_exit); if (PyType_Ready (&membuf_object_type) < 0) return; diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index cf4f936..134268b 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -97,6 +97,7 @@ typedef unsigned long gdb_py_ulongest; /* Also needed to parse enum var_types. */ #include "command.h" +#include "breakpoint.h" #include "exceptions.h" @@ -104,11 +105,18 @@ struct block; struct value; struct language_defn; struct program_space; +struct bpstats; extern PyObject *gdb_module; extern PyTypeObject value_object_type; extern PyTypeObject block_object_type; extern PyTypeObject symbol_object_type; +extern PyTypeObject event_object_type; +extern PyTypeObject events_object_type; +extern PyTypeObject stop_event_object_type; + +/* Defined in py-breakpoint.c */ +typedef struct breakpoint_object breakpoint_object; typedef struct { @@ -161,6 +169,7 @@ PyObject *objfpy_get_printers (PyObject *, void *); thread_object *create_thread_object (struct thread_info *tp); thread_object *find_thread_object (ptid_t ptid); PyObject *find_inferior_object (int pid); +PyObject *inferior_to_inferior_object (struct inferior *inferior); struct block *block_object_to_block (PyObject *obj); struct symbol *symbol_object_to_symbol (PyObject *obj); @@ -187,6 +196,15 @@ void gdbpy_initialize_lazy_string (void); void gdbpy_initialize_parameters (void); void gdbpy_initialize_thread (void); void gdbpy_initialize_inferior (void); +void gdbpy_initialize_eventregistry (void); +void gdbpy_initialize_event (void); +void gdbpy_initialize_py_events (void); +void gdbpy_initialize_stop_event (void); +void gdbpy_initialize_signal_event (void); +void gdbpy_initialize_breakpoint_event (void); +void gdbpy_initialize_continue_event (void); +void gdbpy_initialize_exited_event (void); +void gdbpy_initialize_thread_event (void); struct cleanup *make_cleanup_py_decref (PyObject *py); diff --git a/gdb/python/python.c b/gdb/python/python.c index b2ee8f9..b79504a 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -997,6 +997,16 @@ Enables or disables printing of Python stack traces."), gdbpy_initialize_inferior (); gdbpy_initialize_events (); + gdbpy_initialize_eventregistry (); + gdbpy_initialize_py_events (); + gdbpy_initialize_event (); + gdbpy_initialize_stop_event (); + gdbpy_initialize_signal_event (); + gdbpy_initialize_breakpoint_event (); + gdbpy_initialize_continue_event (); + gdbpy_initialize_exited_event (); + gdbpy_initialize_thread_event (); + PyRun_SimpleString ("import gdb"); PyRun_SimpleString ("gdb.pretty_printers = []"); |