| |   |
| 262 | 262 | # |
| 263 | 263 | SUBDIR_PYTHON_OBS = \ |
| 264 | 264 | python.o \ |
| 265 | python-hooks.o \ |
| 265 | 266 | python-value.o |
| 266 | 267 | SUBDIR_PYTHON_SRCS = \ |
| 267 | 268 | python/python.c \ |
| 269 | python/hooks.c \ |
| 268 | 270 | python/value.c |
| 269 | 271 | SUBDIR_PYTHON_DEPS = |
| 270 | 272 | SUBDIR_PYTHON_LDFLAGS= |
| … | … | |
| 3415 | 3415 | $(command_h) $(libiberty_h) $(cli_decode_h) $(charset_h) $(top_h) \ |
| 3416 | 3416 | $(exceptions_h) $(python_internal_h) $(version_h) |
| 3417 | 3417 | $(CC) -c $(INTERNAL_CFLAGS) $(PYTHON_CFLAGS) $(srcdir)/python/python.c |
| 3418 | python-hooks.o: $(srcdir)/python/hooks.c $(defs_h) $(cli_decode_h) \ |
| 3419 | $(charset_h) $(gdb_events_h) $(python_h) $(python_internal_h) |
| 3420 | $(CC) -c $(INTERNAL_CFLAGS) $(PYTHON_CFLAGS) \ |
| 3421 | $(srcdir)/python/hooks.c -o python-hooks.o |
| 3418 | 3422 | python-value.o: $(srcdir)/python/value.c $(defs_h) $(exceptions_h) \ |
| 3419 | 3423 | $(python_internal_h) $(value_h) |
| 3420 | 3424 | $(CC) -c $(INTERNAL_CFLAGS) $(PYTHON_CFLAGS) \ |
| toggle raw diff |
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -262,9 +262,11 @@ SUBDIR_TUI_CFLAGS= \
#
SUBDIR_PYTHON_OBS = \
python.o \
+ python-hooks.o \
python-value.o
SUBDIR_PYTHON_SRCS = \
python/python.c \
+ python/hooks.c \
python/value.c
SUBDIR_PYTHON_DEPS =
SUBDIR_PYTHON_LDFLAGS=
@@ -3413,6 +3415,10 @@ python.o: $(srcdir)/python/python.c $(defs_h) $(python_h) \
$(command_h) $(libiberty_h) $(cli_decode_h) $(charset_h) $(top_h) \
$(exceptions_h) $(python_internal_h) $(version_h)
$(CC) -c $(INTERNAL_CFLAGS) $(PYTHON_CFLAGS) $(srcdir)/python/python.c
+python-hooks.o: $(srcdir)/python/hooks.c $(defs_h) $(cli_decode_h) \
+ $(charset_h) $(gdb_events_h) $(python_h) $(python_internal_h)
+ $(CC) -c $(INTERNAL_CFLAGS) $(PYTHON_CFLAGS) \
+ $(srcdir)/python/hooks.c -o python-hooks.o
python-value.o: $(srcdir)/python/value.c $(defs_h) $(exceptions_h) \
$(python_internal_h) $(value_h)
$(CC) -c $(INTERNAL_CFLAGS) $(PYTHON_CFLAGS) \ |
| |   |
| 1 | /* Notifications from gdb to Python |
| 2 | |
| 3 | Copyright (C) 2008 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #include "defs.h" |
| 21 | #include "cli/cli-decode.h" |
| 22 | #include "charset.h" |
| 23 | #include "gdb-events.h" |
| 24 | #include "python.h" |
| 25 | #include "python-internal.h" |
| 26 | |
| 27 | static struct gdb_events handlers; |
| 28 | |
| 29 | PyObject * |
| 30 | gdbpy_get_hook_function (const char *name) |
| 31 | { |
| 32 | PyObject *hooks; |
| 33 | |
| 34 | if (! PyObject_HasAttrString (gdb_module, "hooks")) |
| 35 | return NULL; |
| 36 | hooks = PyObject_GetAttrString (gdb_module, "hooks"); |
| 37 | if (! hooks) |
| 38 | return NULL; |
| 39 | /* The cast is because the Python function doesn't declare const argument. |
| 40 | This is a problem in Python version 2.4, but not in 2.5. */ |
| 41 | if (! PyObject_HasAttrString (hooks, (char *) name)) |
| 42 | return NULL; |
| 43 | /* The cast is because the Python function doesn't declare const argument. |
| 44 | This is a problem in Python version 2.4, but not in 2.5. */ |
| 45 | return PyObject_GetAttrString (hooks, (char *) name); |
| 46 | } |
| 47 | |
| 48 | static void |
| 49 | gdbpy_set_hook (struct cmd_list_element *cmd) |
| 50 | { |
| 51 | char *name; |
| 52 | PyObject *nameobj, *valobj, *func; |
| 53 | |
| 54 | func = gdbpy_get_hook_function ("post_set"); |
| 55 | if (! func) |
| 56 | return; |
| 57 | |
| 58 | valobj = variable_to_python (cmd); |
| 59 | if (! valobj) |
| 60 | return; |
| 61 | |
| 62 | name = concat (cmd->prefixname ? cmd->prefixname : "", " ", cmd->name, NULL); |
| 63 | nameobj = PyString_Decode (name, strlen (name), host_charset (), |
| 64 | NULL /* FIXME */); |
| 65 | xfree (name); |
| 66 | |
| 67 | PyObject_CallFunctionObjArgs (func, nameobj, valobj, NULL); |
| 68 | if (PyErr_Occurred ()) |
| 69 | PyErr_Print (); |
| 70 | } |
| 71 | |
| 72 | static void |
| 73 | gdbpy_attach (void) |
| 74 | { |
| 75 | PyObject *func; |
| 76 | func = gdbpy_get_hook_function ("post_attach"); |
| 77 | if (func) |
| 78 | { |
| 79 | PyObject_CallFunctionObjArgs (func, NULL); |
| 80 | if (PyErr_Occurred ()) |
| 81 | PyErr_Print (); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | static void |
| 86 | gdbpy_detach (void) |
| 87 | { |
| 88 | PyObject *func; |
| 89 | func = gdbpy_get_hook_function ("post_detach"); |
| 90 | if (func) |
| 91 | { |
| 92 | PyObject_CallFunctionObjArgs (func, NULL); |
| 93 | if (PyErr_Occurred ()) |
| 94 | PyErr_Print (); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | static void |
| 99 | gdbpy_architecture_changed (void) |
| 100 | { |
| 101 | PyObject *func; |
| 102 | func = gdbpy_get_hook_function ("post_architecture_change"); |
| 103 | if (func) |
| 104 | { |
| 105 | PyObject_CallFunctionObjArgs (func, NULL); |
| 106 | if (PyErr_Occurred ()) |
| 107 | PyErr_Print (); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void |
| 112 | gdbpy_initialize_hooks (void) |
| 113 | { |
| 114 | handlers.architecture_changed = gdbpy_architecture_changed; |
| 115 | deprecated_set_gdb_event_hooks (&handlers); |
| 116 | |
| 117 | deprecated_set_hook = gdbpy_set_hook; |
| 118 | deprecated_attach_hook = gdbpy_attach; |
| 119 | deprecated_detach_hook = gdbpy_detach; |
| 120 | } |
| toggle raw diff |
--- /dev/null
+++ b/gdb/python/hooks.c
@@ -0,0 +1,120 @@
+/* Notifications from gdb to Python
+
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "defs.h"
+#include "cli/cli-decode.h"
+#include "charset.h"
+#include "gdb-events.h"
+#include "python.h"
+#include "python-internal.h"
+
+static struct gdb_events handlers;
+
+PyObject *
+gdbpy_get_hook_function (const char *name)
+{
+ PyObject *hooks;
+
+ if (! PyObject_HasAttrString (gdb_module, "hooks"))
+ return NULL;
+ hooks = PyObject_GetAttrString (gdb_module, "hooks");
+ if (! hooks)
+ return NULL;
+ /* The cast is because the Python function doesn't declare const argument.
+ This is a problem in Python version 2.4, but not in 2.5. */
+ if (! PyObject_HasAttrString (hooks, (char *) name))
+ return NULL;
+ /* The cast is because the Python function doesn't declare const argument.
+ This is a problem in Python version 2.4, but not in 2.5. */
+ return PyObject_GetAttrString (hooks, (char *) name);
+}
+
+static void
+gdbpy_set_hook (struct cmd_list_element *cmd)
+{
+ char *name;
+ PyObject *nameobj, *valobj, *func;
+
+ func = gdbpy_get_hook_function ("post_set");
+ if (! func)
+ return;
+
+ valobj = variable_to_python (cmd);
+ if (! valobj)
+ return;
+
+ name = concat (cmd->prefixname ? cmd->prefixname : "", " ", cmd->name, NULL);
+ nameobj = PyString_Decode (name, strlen (name), host_charset (),
+ NULL /* FIXME */);
+ xfree (name);
+
+ PyObject_CallFunctionObjArgs (func, nameobj, valobj, NULL);
+ if (PyErr_Occurred ())
+ PyErr_Print ();
+}
+
+static void
+gdbpy_attach (void)
+{
+ PyObject *func;
+ func = gdbpy_get_hook_function ("post_attach");
+ if (func)
+ {
+ PyObject_CallFunctionObjArgs (func, NULL);
+ if (PyErr_Occurred ())
+ PyErr_Print ();
+ }
+}
+
+static void
+gdbpy_detach (void)
+{
+ PyObject *func;
+ func = gdbpy_get_hook_function ("post_detach");
+ if (func)
+ {
+ PyObject_CallFunctionObjArgs (func, NULL);
+ if (PyErr_Occurred ())
+ PyErr_Print ();
+ }
+}
+
+static void
+gdbpy_architecture_changed (void)
+{
+ PyObject *func;
+ func = gdbpy_get_hook_function ("post_architecture_change");
+ if (func)
+ {
+ PyObject_CallFunctionObjArgs (func, NULL);
+ if (PyErr_Occurred ())
+ PyErr_Print ();
+ }
+}
+
+void
+gdbpy_initialize_hooks (void)
+{
+ handlers.architecture_changed = gdbpy_architecture_changed;
+ deprecated_set_gdb_event_hooks (&handlers);
+
+ deprecated_set_hook = gdbpy_set_hook;
+ deprecated_attach_hook = gdbpy_attach;
+ deprecated_detach_hook = gdbpy_detach;
+} |
| |   |
| 32 | 32 | PyObject *gdbpy_make_value_from_int (PyObject *self, PyObject *args); |
| 33 | 33 | PyObject *gdbpy_get_value_from_history (PyObject *self, PyObject *args); |
| 34 | 34 | |
| 35 | PyObject *variable_to_python (struct cmd_list_element *); |
| 35 | 36 | PyObject *value_to_value_object (struct value *v); |
| 36 | 37 | PyObject *gdb_owned_value_to_value_object (struct value *v); |
| 37 | 38 | |
| 38 | 39 | struct value *value_object_to_value (PyObject *self); |
| 39 | 40 | |
| 41 | PyObject *gdbpy_get_hook_function (const char *); |
| 42 | |
| 40 | 43 | void gdbpy_initialize_values (void); |
| 44 | void gdbpy_initialize_hooks (void); |
| 41 | 45 | |
| 42 | 46 | /* Use this after a TRY_EXCEPT to throw the appropriate Python |
| 43 | 47 | exception. FIXME: throw different errors depending on |
| toggle raw diff |
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -32,12 +32,16 @@ extern PyTypeObject value_object_type;
PyObject *gdbpy_make_value_from_int (PyObject *self, PyObject *args);
PyObject *gdbpy_get_value_from_history (PyObject *self, PyObject *args);
+PyObject *variable_to_python (struct cmd_list_element *);
PyObject *value_to_value_object (struct value *v);
PyObject *gdb_owned_value_to_value_object (struct value *v);
struct value *value_object_to_value (PyObject *self);
+PyObject *gdbpy_get_hook_function (const char *);
+
void gdbpy_initialize_values (void);
+void gdbpy_initialize_hooks (void);
/* Use this after a TRY_EXCEPT to throw the appropriate Python
exception. FIXME: throw different errors depending on |