From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: tromey@redhat.com
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC][patch 3/9] export hooks mechanism to Python
Date: Sun, 15 Jun 2008 22:53:00 -0000 [thread overview]
Message-ID: <20080615183110.xi9zc6qx2iokwwsg@imap.linux.ibm.com> (raw)
In-Reply-To: <m3skw0dekt.fsf@fleche.redhat.com>
[-- Attachment #1: Type: text/plain, Size: 323 bytes --]
Zitat von Tom Tromey <tromey@redhat.com>:
>>>>>> "Daniel" == Daniel Jacobowitz <drow@false.org> writes:
>
> Daniel> I won't look at this one, as I believe Tom's rewritten it to use
> Daniel> observers instead.
>
> Yeah, that's right.
>
Here's the new version.
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
[-- Attachment #2: python-hooks.diff --]
[-- Type: text/x-patch, Size: 6803 bytes --]
gdb/
2008-06-15 Tom Tromey <tromey@redhat.com>
* Makefile.in (SUBDIR_PYTHON_OBS): Add python-hooks.o.
(SUBDIR_PYTHON_SRCS): Add python/hooks.c.
(python-hooks.o): New target.
* breakpoint.c (mention): Notify observers of created
breakpoint.
(delete_breakpoint): Notify observers of deleted
breakpoint.
* python/hooks.c: New file.
* python/python-internal.h (gdbpy_get_hook_function,
gdbpy_initialize_hooks): Declare.
* python/python.c (_initialize_python): Call gdbpy_initialize_hooks.
doc/
2008-06-15 Tom Tromey <tromey@redhat.com>
* observer.texi (Notifications): Document breakpoint_created
and breakpoint_deleted.
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index b15fa61..45ecfbd 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -257,9 +257,11 @@ SUBDIR_TUI_CFLAGS= \
#
# python sub directory definitons
#
-SUBDIR_PYTHON_OBS =
+SUBDIR_PYTHON_OBS = \
+ python-hooks.o
SUBDIR_PYTHON_SRCS = \
python/python.c \
+ python/hooks.c \
python/value.c
SUBDIR_PYTHON_DEPS =
SUBDIR_PYTHON_LDFLAGS=
@@ -3413,6 +3415,11 @@ python.o: $(srcdir)/python/python.c $(defs_h) $(python_h) \
$(exceptions_h) $(python_internal_h) $(version_h) $(cli_script_h) \
$(ui_out_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) \
+ $(observer_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) \
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 24ef7bf..4c2b1eb 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4913,6 +4913,7 @@ mention (struct breakpoint *b)
if (deprecated_create_breakpoint_hook)
deprecated_create_breakpoint_hook (b);
breakpoint_create_event (b->number);
+ observer_notify_breakpoint_created (b->number);
if (b->ops != NULL && b->ops->print_mention != NULL)
b->ops->print_mention (b);
@@ -7141,6 +7142,7 @@ delete_breakpoint (struct breakpoint *bpt)
if (deprecated_delete_breakpoint_hook)
deprecated_delete_breakpoint_hook (bpt);
breakpoint_delete_event (bpt->number);
+ observer_notify_breakpoint_deleted (bpt->number);
if (breakpoint_chain == bpt)
breakpoint_chain = bpt->next;
diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
index 5bcc76c..b6aefab 100644
--- a/gdb/doc/observer.texi
+++ b/gdb/doc/observer.texi
@@ -2,7 +2,7 @@
@c This file is part of the GDB manual.
@c
-@c Copyright (C) 2003, 2004, 2005, 2006
+@c Copyright (C) 2003, 2004, 2005, 2006, 2008
@c Free Software Foundation, Inc.
@c
@c See the file gdbint.texinfo for copying conditions.
@@ -133,3 +133,13 @@ previously loaded symbol table data has now been invalidated.
The thread specified by @var{t} has been created.
@end deftypefun
+@deftypefun void breakpoint_created (int @var{bpnum})
+A new breakpoint has been created. The argument @var{bpnum} is the
+number of the newly-created breakpoint.
+@end deftypefun
+
+@deftypefun void breakpoint_deleted (int @var{bpnum})
+A breakpoint has been destroyed. The argument @var{bpnum} is the
+number of the newly-destroyed breakpoint.
+@end deftypefun
+
diff --git a/gdb/python/hooks.c b/gdb/python/hooks.c
new file mode 100644
index 0000000..21f3a28
--- /dev/null
+++ b/gdb/python/hooks.c
@@ -0,0 +1,62 @@
+/* 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"
+#include "observer.h"
+
+PyObject *
+gdbpy_get_hook_function (const char *name)
+{
+ PyObject *hooks;
+ PyObject *result;
+
+ 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))
+ {
+ Py_DECREF (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. */
+ result = PyObject_GetAttrString (hooks, (char *) name);
+ Py_DECREF (hooks);
+ return result;
+}
+
+void
+gdbpy_initialize_hooks (void)
+{
+ /* If you need to hook into any sort of state change in gdb, do so
+ by adding a new observer to observer.texi, attach to the new
+ observer here, and notify the new observer at the appropriate
+ place. */
+ observer_attach_breakpoint_created (gdbpy_breakpoint_created);
+ observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
+}
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 0abdfde..1bb2422 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -56,7 +56,10 @@ 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. */
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 5b8b975..2e8db56 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -282,6 +282,7 @@ the end of the command."));
PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) target_name);
+ gdbpy_initialize_hooks ();
gdbpy_initialize_values ();
PyRun_SimpleString ("import gdb");
next prev parent reply other threads:[~2008-06-15 22:31 UTC|newest]
Thread overview: 147+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-29 15:59 [RFC][patch 0/9] Python support in GDB Thiago Jung Bauermann
2008-04-29 15:59 ` [RFC][patch 5/9] permit GDB commands implemented in Python Thiago Jung Bauermann
2008-04-29 15:59 ` [RFC][patch 8/9] export symtab mechanism to Python Thiago Jung Bauermann
2008-04-29 15:59 ` [RFC][patch 6/9] export frames " Thiago Jung Bauermann
2008-04-29 15:59 ` [RFC][patch 9/9] export threads " Thiago Jung Bauermann
2008-04-29 15:59 ` [RFC][patch 3/9] export hooks mechanism " Thiago Jung Bauermann
2008-04-29 21:29 ` Tom Tromey
2008-04-30 18:27 ` Joel Brobecker
2008-04-30 21:30 ` Tom Tromey
2008-05-27 18:22 ` Tom Tromey
2008-04-30 18:29 ` Daniel Jacobowitz
2008-04-30 23:00 ` Tom Tromey
2008-05-29 7:55 ` Daniel Jacobowitz
2008-05-30 14:59 ` Tom Tromey
2008-06-15 22:53 ` Thiago Jung Bauermann [this message]
2008-06-15 22:58 ` Tom Tromey
2008-06-16 3:22 ` Daniel Jacobowitz
2008-06-17 18:13 ` Thiago Jung Bauermann
2008-06-17 22:20 ` Joel Brobecker
2008-06-23 17:58 ` Tom Tromey
2008-04-29 16:08 ` [RFC][patch 7/9] export block and symbol " Thiago Jung Bauermann
2008-04-29 18:11 ` [RFC][patch 4/9] export breakpoints " Thiago Jung Bauermann
2008-04-29 18:15 ` [RFC][patch 1/9] initial Python support Thiago Jung Bauermann
2008-05-05 8:12 ` Thiago Jung Bauermann
2008-05-05 14:39 ` Daniel Jacobowitz
2008-05-05 14:46 ` Thiago Jung Bauermann
2008-05-05 16:50 ` Daniel Jacobowitz
2008-05-06 2:38 ` Thiago Jung Bauermann
2008-05-11 22:24 ` Thiago Jung Bauermann
2008-05-11 22:26 ` Daniel Jacobowitz
2008-05-12 20:33 ` Thiago Jung Bauermann
2008-05-12 20:39 ` Daniel Jacobowitz
2008-05-12 21:00 ` Thiago Jung Bauermann
2008-05-29 0:29 ` Daniel Jacobowitz
2008-05-30 13:07 ` Function syntax (Was: [RFC][patch 1/9] initial Python support) Tom Tromey
2008-06-08 15:24 ` Doug Evans
2008-06-08 15:32 ` Function syntax Tom Tromey
2008-06-08 18:21 ` Function syntax (Was: [RFC][patch 1/9] initial Python support) Daniel Jacobowitz
2008-06-09 13:48 ` Thiago Jung Bauermann
2008-06-09 18:43 ` Daniel Jacobowitz
2008-06-10 0:24 ` Function syntax Tom Tromey
2008-06-10 0:04 ` Tom Tromey
2008-06-11 0:04 ` Thiago Jung Bauermann
2008-06-10 0:00 ` Tom Tromey
2008-05-30 14:47 ` [RFC][patch 1/9] initial Python support Tom Tromey
2008-06-15 22:35 ` thiagoju
2008-06-23 17:36 ` Tom Tromey
2008-07-06 17:28 ` Tom Tromey
2008-07-08 4:12 ` Thiago Jung Bauermann
2008-07-15 7:38 ` [RFA] " Thiago Jung Bauermann
2008-07-15 17:19 ` Tom Tromey
2008-07-15 18:33 ` Thiago Jung Bauermann
2008-07-15 19:03 ` Tom Tromey
2008-07-16 7:14 ` Thiago Jung Bauermann
2008-07-16 14:39 ` Tom Tromey
2008-07-16 22:02 ` Thiago Jung Bauermann
2008-07-18 19:50 ` Daniel Jacobowitz
2008-07-18 23:24 ` Tom Tromey
2008-07-19 0:45 ` Daniel Jacobowitz
2008-07-19 19:50 ` [RFA] iRe: " Thiago Jung Bauermann
2008-07-19 21:13 ` Daniel Jacobowitz
2008-07-19 22:13 ` Thiago Jung Bauermann
2008-07-20 23:47 ` Thiago Jung Bauermann
2008-07-21 2:03 ` Daniel Jacobowitz
2008-07-23 17:46 ` [obvious] Wipe out CONFIG_INITS Thiago Jung Bauermann
2008-07-20 22:43 ` [RFA] Re: [RFC][patch 1/9] initial Python support Tom Tromey
2008-07-21 1:59 ` Daniel Jacobowitz
2008-07-21 15:29 ` [RFA][patch 1/9] Yet another respin of the patch with " Thiago Jung Bauermann
2008-07-21 16:47 ` Thiago Jung Bauermann
2008-07-26 13:07 ` Eli Zaretskii
2008-07-26 13:43 ` Daniel Jacobowitz
2008-07-26 14:02 ` Eli Zaretskii
2008-07-26 14:42 ` Daniel Jacobowitz
2008-07-26 17:06 ` Eli Zaretskii
2008-07-26 17:26 ` Tom Tromey
2008-07-26 19:21 ` Eli Zaretskii
2008-07-26 17:40 ` Daniel Jacobowitz
2008-07-26 17:10 ` Tom Tromey
2008-07-26 17:40 ` Eli Zaretskii
2008-07-26 18:00 ` Tom Tromey
2008-07-26 18:29 ` Eli Zaretskii
2008-07-26 18:45 ` Tom Tromey
2008-07-26 19:34 ` Eli Zaretskii
2008-07-30 14:59 ` Thiago Jung Bauermann
2008-07-30 17:57 ` Eli Zaretskii
2008-08-04 4:44 ` Thiago Jung Bauermann
2008-08-04 19:18 ` Eli Zaretskii
2008-08-05 3:42 ` Thiago Jung Bauermann
2008-07-26 17:04 ` Tom Tromey
2008-07-26 17:35 ` Daniel Jacobowitz
2008-07-26 17:42 ` Tom Tromey
2008-07-26 19:18 ` Eli Zaretskii
2008-08-04 2:52 ` Thiago Jung Bauermann
2008-08-04 3:22 ` Eli Zaretskii
2008-08-04 12:15 ` Daniel Jacobowitz
2008-08-04 19:50 ` Eli Zaretskii
2008-08-05 2:08 ` Daniel Jacobowitz
2008-08-05 2:41 ` Thiago Jung Bauermann
2008-08-05 3:32 ` Eli Zaretskii
2008-08-05 12:19 ` Daniel Jacobowitz
2008-08-05 18:10 ` Eli Zaretskii
2008-08-05 18:23 ` Daniel Jacobowitz
2008-08-05 18:50 ` Eli Zaretskii
2008-08-05 18:58 ` Daniel Jacobowitz
2008-07-26 19:20 ` Eli Zaretskii
2008-07-26 18:11 ` Eli Zaretskii
2008-07-26 18:30 ` Daniel Jacobowitz
2008-07-26 19:26 ` Eli Zaretskii
2008-08-01 20:04 ` Tom Tromey
2008-08-02 17:38 ` Daniel Jacobowitz
2008-08-02 17:50 ` Tom Tromey
2008-08-02 19:00 ` Eli Zaretskii
2008-08-05 4:19 ` Thiago Jung Bauermann
2008-08-05 18:14 ` Eli Zaretskii
2008-08-06 5:35 ` [RFA][patch 1/9] Initial Python support, patch du jour Thiago Jung Bauermann
2008-08-06 18:24 ` Eli Zaretskii
2008-08-06 19:53 ` Thiago Jung Bauermann
2008-08-04 4:44 ` [RFA][patch 1/9] Yet another respin of the patch with initial Python support Thiago Jung Bauermann
2008-08-04 19:22 ` Eli Zaretskii
2008-08-05 1:24 ` Thiago Jung Bauermann
2008-08-02 17:41 ` Daniel Jacobowitz
2008-08-02 19:02 ` Eli Zaretskii
2008-08-02 19:07 ` Daniel Jacobowitz
2008-07-15 18:01 ` [RFA] Re: [RFC][patch 1/9] " Thiago Jung Bauermann
2008-04-29 18:17 ` [RFC][patch 2/9] export values mechanism to Python Thiago Jung Bauermann
2008-05-29 1:23 ` Daniel Jacobowitz
2008-06-03 0:19 ` Tom Tromey
2008-06-03 13:04 ` Daniel Jacobowitz
2008-06-03 14:52 ` Tom Tromey
2008-07-07 6:03 ` Thiago Jung Bauermann
2008-07-07 23:44 ` Tom Tromey
2008-07-26 2:55 ` Daniel Jacobowitz
2008-07-26 17:17 ` Tom Tromey
2008-07-26 17:41 ` Daniel Jacobowitz
2008-07-30 3:01 ` Tom Tromey
2008-07-30 14:26 ` Thiago Jung Bauermann
2008-08-13 6:45 ` [python] acessing struct elements Thiago Jung Bauermann
2008-08-13 12:38 ` Daniel Jacobowitz
2008-08-13 20:38 ` Thiago Jung Bauermann
2008-08-17 20:16 ` Tom Tromey
2008-04-29 18:38 ` [RFC][patch 0/9] Python support in GDB Eli Zaretskii
2008-04-29 20:37 ` Thiago Jung Bauermann
2008-04-29 21:22 ` Tom Tromey
2008-04-30 7:54 ` Eli Zaretskii
2008-04-30 19:38 ` Thiago Jung Bauermann
2008-04-30 19:52 ` Eli Zaretskii
2008-05-02 18:30 ` Vladimir Prus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080615183110.xi9zc6qx2iokwwsg@imap.linux.ibm.com \
--to=bauerman@br.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox