From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28183 invoked by alias); 15 Jun 2008 22:31:41 -0000 Received: (qmail 28088 invoked by uid 22791); 15 Jun 2008 22:31:40 -0000 X-Spam-Check-By: sourceware.org Received: from e32.co.us.ibm.com (HELO e32.co.us.ibm.com) (32.97.110.150) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 15 Jun 2008 22:31:13 +0000 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e32.co.us.ibm.com (8.13.8/8.13.8) with ESMTP id m5FMQkwe008778 for ; Sun, 15 Jun 2008 18:26:46 -0400 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v9.0) with ESMTP id m5FMVBaw093768 for ; Sun, 15 Jun 2008 16:31:11 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m5FMVAR1001620 for ; Sun, 15 Jun 2008 16:31:10 -0600 Received: from linux.ibm.com (imap.raleigh.ibm.com [9.37.253.145]) by d03av02.boulder.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id m5FMVA6n001616; Sun, 15 Jun 2008 16:31:10 -0600 Received: from 9.18.199.132 ([9.18.199.132]) by imap.linux.ibm.com (Horde MIME library) with HTTP; Sun, 15 Jun 2008 18:31:10 -0400 Message-ID: <20080615183110.xi9zc6qx2iokwwsg@imap.linux.ibm.com> Date: Sun, 15 Jun 2008 22:53:00 -0000 From: Thiago Jung Bauermann To: tromey@redhat.com Cc: gdb-patches@sourceware.org Subject: Re: [RFC][patch 3/9] export hooks mechanism to Python References: <20080429155212.444237503@br.ibm.com> <20080429155304.641779989@br.ibm.com> <20080528212612.GC2969@caradoc.them.org> In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_4sd06jgtkby" Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) H3 (4.1.3) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-06/txt/msg00294.txt.bz2 This message is in MIME format. --=_4sd06jgtkby Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: 7bit Content-length: 323 Zitat von Tom Tromey : >>>>>> "Daniel" == Daniel Jacobowitz 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 --=_4sd06jgtkby Content-Type: text/x-patch; charset=UTF-8; name="python-hooks.diff" Content-Disposition: attachment; filename="python-hooks.diff" Content-Transfer-Encoding: quoted-printable Content-length: 6671 gdb/ 2008-06-15 Tom Tromey * 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 * 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=3D \ # # python sub directory definitons # -SUBDIR_PYTHON_OBS =3D +SUBDIR_PYTHON_OBS =3D \ + python-hooks.o SUBDIR_PYTHON_SRCS =3D \ python/python.c \ + python/hooks.c \ python/value.c SUBDIR_PYTHON_DEPS =3D SUBDIR_PYTHON_LDFLAGS=3D @@ -3413,6 +3415,11 @@ python.o: $(srcdir)/python/python.c $(defs_h) $(pyth= on_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); =20 if (b->ops !=3D NULL && b->ops->print_mention !=3D 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); =20 if (breakpoint_chain =3D=3D bpt) breakpoint_chain =3D 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 @@ =20 @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 inval= idated. The thread specified by @var{t} has been created. @end deftypefun =20 +@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 . = */ + +#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 =3D PyObject_GetAttrString (gdb_module, "hooks"); + if (! hooks) + return NULL; + /* The cast is because the Python function doesn't declare const argumen= t. + 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 argumen= t. + This is a problem in Python version 2.4, but not in 2.5. */ + result =3D 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); =20 struct value *value_object_to_value (PyObject *self); =20 +PyObject *gdbpy_get_hook_function (const char *); + void gdbpy_initialize_values (void); +void gdbpy_initialize_hooks (void); =20 /* 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); =20 + gdbpy_initialize_hooks (); gdbpy_initialize_values (); =20 PyRun_SimpleString ("import gdb"); --=_4sd06jgtkby--