System notice: In light of the Debian OpenSSL security issue we've regenerated the server keys. See this thread for instructions and the new key fingerprints.

Commit 2c4adcf4febf071858d538fe5b09633a2f80984f

Export hooks to Python.

Commit diff

gdb/Makefile.in

 
262262#
263263SUBDIR_PYTHON_OBS = \
264264 python.o \
265 python-hooks.o \
265266 python-value.o
266267SUBDIR_PYTHON_SRCS = \
267268 python/python.c \
269 python/hooks.c \
268270 python/value.c
269271SUBDIR_PYTHON_DEPS =
270272SUBDIR_PYTHON_LDFLAGS=
34153415 $(command_h) $(libiberty_h) $(cli_decode_h) $(charset_h) $(top_h) \
34163416 $(exceptions_h) $(python_internal_h) $(version_h)
34173417 $(CC) -c $(INTERNAL_CFLAGS) $(PYTHON_CFLAGS) $(srcdir)/python/python.c
3418python-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
34183422python-value.o: $(srcdir)/python/value.c $(defs_h) $(exceptions_h) \
34193423 $(python_internal_h) $(value_h)
34203424 $(CC) -c $(INTERNAL_CFLAGS) $(PYTHON_CFLAGS) \
toggle raw diff

gdb/interps.c

 
191191 }
192192
193193 /* Clear out any installed interpreter hooks/event handlers. */
194 clear_interpreter_hooks ();
194 /* FIXME - we don't want python to be a normal interpreter, but we
195 do want to be able to hook in everywhere. Not sure what to do
196 about this -- maybe allow events to be delivered to multiple
197 handlers. */
198/* clear_interpreter_hooks (); */
195199
196200 if (interp->procs->resume_proc != NULL
197201 && (!interp->procs->resume_proc (interp->data)))
toggle raw diff

gdb/python/hooks.c

 
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
27static struct gdb_events handlers;
28
29PyObject *
30gdbpy_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
48static void
49gdbpy_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
72static void
73gdbpy_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
85static void
86gdbpy_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
98static void
99gdbpy_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
111void
112gdbpy_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

gdb/python/python-internal.h

 
3232PyObject *gdbpy_make_value_from_int (PyObject *self, PyObject *args);
3333PyObject *gdbpy_get_value_from_history (PyObject *self, PyObject *args);
3434
35PyObject *variable_to_python (struct cmd_list_element *);
3536PyObject *value_to_value_object (struct value *v);
3637PyObject *gdb_owned_value_to_value_object (struct value *v);
3738
3839struct value *value_object_to_value (PyObject *self);
3940
41PyObject *gdbpy_get_hook_function (const char *);
42
4043void gdbpy_initialize_values (void);
44void gdbpy_initialize_hooks (void);
4145
4246/* Use this after a TRY_EXCEPT to throw the appropriate Python
4347 exception. FIXME: throw different errors depending on
toggle raw diff

gdb/python/python.c

 
6464 PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", host_name);
6565 PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", target_name);
6666
67 gdbpy_initialize_hooks ();
6768 gdbpy_initialize_values ();
6869
6970 PyRun_SimpleString ("import gdb");
toggle raw diff