From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20887 invoked by alias); 30 Mar 2011 09:25:20 -0000 Received: (qmail 20850 invoked by uid 22791); 30 Mar 2011 09:25:16 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,TW_BJ X-Spam-Check-By: sourceware.org Received: from mail-vx0-f169.google.com (HELO mail-vx0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 30 Mar 2011 09:25:05 +0000 Received: by vxk20 with SMTP id 20so1097435vxk.0 for ; Wed, 30 Mar 2011 02:25:04 -0700 (PDT) Received: by 10.52.0.198 with SMTP id 6mr1204997vdg.152.1301477104274; Wed, 30 Mar 2011 02:25:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.200.3 with HTTP; Wed, 30 Mar 2011 02:24:44 -0700 (PDT) In-Reply-To: References: From: Kevin Pouget Date: Wed, 30 Mar 2011 11:32:00 -0000 Message-ID: Subject: Re: [RFC - Python] New ObjFile event To: Tom Tromey Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 2011-03/txt/msg01193.txt.bz2 Hello, here is a patch with all the modifications we discussed so far, including the ChangeLog entry and the new files Cordially, Kevin -- =46rom eec9cb69818ec72184b59ca0d928fcbc590c558f Mon Sep 17 00:00:00 2001 From: Kevin Pouget Date: Tue, 29 Mar 2011 11:26:34 -0400 Subject: [PATCH] Allow Python notification of new object-file loadings Signed-off-by: Kevin Pouget --- =A0gdb/ChangeLog=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 |=A0=A0 28 +++++++++++++++ =A0gdb/Makefile.in=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 |=A0=A0 11 +++++- =A0gdb/doc/gdb.texinfo=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 |=A0=A0 14 +++++-- =A0gdb/python/py-event.h=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 |=A0=A0=A0 1 + =A0gdb/python/py-events.h=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 |=A0=A0=A0 1 + =A0gdb/python/py-evts.c=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 |=A0=A0=A0 3 ++ =A0gdb/python/py-inferior.c=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 |=A0=A0 27 ++++++++++++++ =A0gdb/python/py-newobjfileevent.c=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 |=A0=A0= 53 ++++++++++++++++++++++++++++ =A0gdb/python/python-internal.h=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 |= =A0=A0=A0 2 + =A0gdb/python/python.c=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 |=A0=A0=A0 6 ++- =A0gdb/testsuite/gdb.python/py-events-shlib.c |=A0=A0 20 ++++++++++ =A0gdb/testsuite/gdb.python/py-events.c=A0=A0=A0=A0=A0=A0 |=A0=A0=A0 3 ++ =A0gdb/testsuite/gdb.python/py-events.exp=A0=A0=A0=A0 |=A0=A0 32 ++++++++++= ++++--- =A0gdb/testsuite/gdb.python/py-events.py=A0=A0=A0=A0=A0 |=A0=A0 20 ++++++++= ++ =A014 files changed, 208 insertions(+), 13 deletions(-) =A0create mode 100644 gdb/python/py-newobjfileevent.c =A0create mode 100644 gdb/testsuite/gdb.python/py-events-shlib.c diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 03885dd..2bceb45 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,31 @@ +2011-03-29 Kevin Pouget + +=A0=A0=A0 Allow Python notification of new object-file loadings +=A0=A0=A0 * Makefile.in (SUBDIR_PYTHON_SRCS): Add py-newobjfilevent.c. +=A0=A0=A0 (SUBDIR_PYTHON_OBS): Add py-newobjfileevent.o. +=A0=A0=A0 Add build rule for this file. +=A0=A0=A0 * python/py-event.h (emit_new_objfile_event): New prototype. +=A0=A0=A0 (newobjfile): New Python event emitter. +=A0=A0=A0 * python/py-evts.c (gdbpy_initialize_py_events): Add newobjfile = to +=A0=A0=A0 Python event registry. +=A0=A0=A0 * python/py-inferior.c: Include objfiles.h +=A0=A0=A0 (python_new_objfile): New function. +=A0=A0=A0 (gdbpy_initialize_inferior): Add python_new_objfile to the new o= bjfile +=A0=A0=A0 observers. +=A0=A0=A0 * python/py-newobjfileevent.c: New file. +=A0=A0=A0 * python-internal.h (gdbpy_initialize_new_objfile_event): New +=A0=A0=A0 prototype. +=A0=A0=A0 (gdbpy_current_objfile): New global variable. +=A0=A0=A0 * python/python.c (gdbpy_current_objfile): Make global. +=A0=A0=A0 (_initialize_python): Add gdbpy_initialize_new_objfile_event cal= l. +=A0=A0=A0 * testsuite/gdb.python/py-events-shlib.c: New file. +=A0=A0=A0 * testsuite/gdb.python/py-events.c (do_nothing): New global. +=A0=A0=A0 (main): Add call to shared library. +=A0=A0=A0 * testsuite/gdb.python/py-events.exp: Link the execfile to a sha= red +=A0=A0=A0 library and check newobjfile event notification. +=A0=A0=A0 * testsuite/gdb.python/py-events.py (new_objfile_handler): New C= lass. +=A0=A0=A0 (test_newobj_events): New class. + =A02011-03-28=A0 Jan Kratochvil=A0 =A0=A0=A0=A0 Support resolution of STT_GNU_IFUNC via breakpoints. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 489b1e9..3b79087 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -296,7 +296,8 @@ SUBDIR_PYTHON_OBS =3D \ =A0=A0=A0=A0 py-threadevent.o \ =A0=A0=A0=A0 py-type.o \ =A0=A0=A0=A0 py-utils.o \ -=A0=A0=A0 py-value.o +=A0=A0=A0 py-value.o \ +=A0=A0=A0 py-newobjfileevent.o =A0SUBDIR_PYTHON_SRCS =3D \ =A0=A0=A0=A0 python/python.c \ @@ -326,7 +327,8 @@ SUBDIR_PYTHON_SRCS =3D \ =A0=A0=A0=A0 python/py-threadevent.c \ =A0=A0=A0=A0 python/py-type.c \ =A0=A0=A0=A0 python/py-utils.c \ -=A0=A0=A0 python/py-value.c +=A0=A0=A0 python/py-value.c \ +=A0=A0=A0 python/py-newobjfileevent.c =A0SUBDIR_PYTHON_DEPS =3D =A0SUBDIR_PYTHON_LDFLAGS=3D =A0SUBDIR_PYTHON_CFLAGS=3D @@ -2110,6 +2112,11 @@ py-value.o: $(srcdir)/python/py-value.c =A0=A0=A0=A0 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-value.c =A0=A0=A0=A0 $(POSTCOMPILE) +py-newobjfileevent.o: $(srcdir)/python/py-newobjfileevent.c +=A0=A0=A0 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-newobjfileevent.c +=A0=A0=A0 $(POSTCOMPILE) + + =A0# =A0# Dependency tracking.=A0 Most of this is conditional on GNU Make being =A0# found by configure; if GNU Make is not found, we fall back to a diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index a4e976f..360ff51 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -22057,6 +22057,12 @@ Emits @code{gdb.SignalEvent} which extends @code{gdb.StopEvent}. =A0This event indicates that the inferior or one of its threads has receive= d as =A0signal.=A0 @code{gdb.SignalEvent} has the following attributes: +@item events.newobjfile +Emits @code{gdb.NewObjFileEvent} which indicates that a new object-file has +been loaded in the inferior. + +During the callback, ``current objfile'' will be set to the new object fil= e. + =A0@table @code =A0@defivar SignalEvent stop_signal =A0A string representing the signal received by the inferior.=A0 A list of = possible @@ -22699,10 +22705,10 @@ The following objfile-related functions are available in the =A0@findex gdb.current_objfile =A0@defun current_objfile -When auto-loading a Python script (@pxref{Auto-loading}), @value{GDBN} -sets the ``current objfile'' to the corresponding objfile.=A0 This -function returns the current objfile.=A0 If there is no current objfile, -this function returns @code{None}. +When auto-loading a Python script (@pxref{Auto-loading}) and during new +object-file callbacks, @value{GDBN} sets the ``current objfile'' to the +corresponding objfile.=A0 This function returns the current objfile.=A0 If +there is no current objfile, this function returns @code{None}. =A0@end defun =A0@findex gdb.objfiles diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h index bc95521..9a3ba82 100644 --- a/gdb/python/py-event.h +++ b/gdb/python/py-event.h @@ -105,6 +105,7 @@ typedef struct =A0extern int emit_continue_event (ptid_t ptid); =A0extern int emit_exited_event (LONGEST exit_code); +extern int emit_new_objfile_event (struct objfile *objfile); =A0extern int evpy_emit_event (PyObject *event, =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 eventregistry_object *registry); diff --git a/gdb/python/py-events.h b/gdb/python/py-events.h index 6d4dae5..9c42e39 100644 --- a/gdb/python/py-events.h +++ b/gdb/python/py-events.h @@ -45,6 +45,7 @@ typedef struct =A0=A0 eventregistry_object *stop; =A0=A0 eventregistry_object *cont; =A0=A0 eventregistry_object *exited; +=A0 eventregistry_object *newobjfile; =A0=A0 PyObject *module; diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c index 50c05f3..ee60560 100644 --- a/gdb/python/py-evts.c +++ b/gdb/python/py-evts.c @@ -57,6 +57,9 @@ gdbpy_initialize_py_events (void) =A0=A0 if (add_new_registry (&gdb_py_events.exited, "exited") < 0) =A0=A0=A0=A0 goto fail; + +=A0 if (add_new_registry (&gdb_py_events.newobjfile, "newobjfile") < 0) +=A0=A0=A0 goto fail; =A0=A0 Py_INCREF (gdb_py_events.module); =A0=A0 if (PyModule_AddObject (gdb_module, diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index b9df394..ebd2a2a 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -22,6 +22,7 @@ =A0#include "gdbcore.h" =A0#include "gdbthread.h" =A0#include "inferior.h" +#include "objfiles.h" =A0#include "observer.h" =A0#include "python-internal.h" =A0#include "arch-utils.h" @@ -129,6 +130,31 @@ python_inferior_exit (struct inferior *inf) =A0=A0 do_cleanups (cleanup); =A0} +/* Callback used to notify Python listeners about new objfiles loaded in t= he +=A0=A0 inferior. Python global variable 'gdb.current_objfile ()' will be s= et +=A0=A0 during the notifications. + */ + +static void +python_new_objfile (struct objfile *objfile) +{ +=A0 struct cleanup *cleanup; + +=A0 /* Will be NULL when clearing the symtab. */ +=A0 if (objfile) +=A0=A0=A0 cleanup =3D ensure_python_env (get_objfile_arch (objfile), curre= nt_language); +=A0 else +=A0=A0=A0 cleanup =3D ensure_python_env (get_current_arch (), current_lang= uage); + +=A0 gdbpy_current_objfile =3D objfile; + +=A0 if (emit_new_objfile_event (objfile) < 0) +=A0=A0=A0 gdbpy_print_stack (); + +=A0 do_cleanups (cleanup); +=A0 gdbpy_current_objfile =3D NULL; +} + =A0/* Return a borrowed reference to the Python object of type Inferior =A0=A0=A0 representing INFERIOR.=A0 If the object has already been created, =A0=A0=A0 return it,=A0 otherwise, create it.=A0 Return NULL on failure.=A0= */ @@ -669,6 +695,7 @@ gdbpy_initialize_inferior (void) =A0=A0 observer_attach_normal_stop (python_on_normal_stop); =A0=A0 observer_attach_target_resumed (python_on_resume); =A0=A0 observer_attach_inferior_exit (python_inferior_exit); +=A0 observer_attach_new_objfile (python_new_objfile); =A0=A0 if (PyType_Ready (&membuf_object_type) < 0) =A0=A0=A0=A0 return; diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileeven= t.c new file mode 100644 index 0000000..20e2b31 --- /dev/null +++ b/gdb/python/py-newobjfileevent.c @@ -0,0 +1,53 @@ +/* Python interface to new object file loading events. + +=A0=A0 Copyright (C) 2011 Free Software Foundation, Inc. + +=A0=A0 This file is part of GDB. + +=A0=A0 This program is free software; you can redistribute it and/or modify +=A0=A0 it under the terms of the GNU General Public License as published by +=A0=A0 the Free Software Foundation; either version 3 of the License, or +=A0=A0 (at your option) any later version. + +=A0=A0 This program is distributed in the hope that it will be useful, +=A0=A0 but WITHOUT ANY WARRANTY; without even the implied warranty of +=A0=A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.=A0 See the +=A0=A0 GNU General Public License for more details. + +=A0=A0 You should have received a copy of the GNU General Public License +=A0=A0 along with this program.=A0 If not, see .=A0 */ + +#include "py-event.h" + +static PyTypeObject new_objfile_event_object_type; + +PyObject * +create_new_objfile_event_object (void) +{ +=A0 return create_event_object (&new_objfile_event_object_type); +} + +/* Callback function which notifies observers when a new objfile event occ= urs. +=A0=A0 This function will create a new Python new_objfile event object. +=A0=A0 Return -1 if emit fails.=A0 */ + +int +emit_new_objfile_event (struct objfile *objfile) +{ +=A0 PyObject *event; + +=A0 if (evregpy_no_listeners_p (gdb_py_events.newobjfile)) +=A0=A0=A0 return 0; + +=A0 event =3D create_new_objfile_event_object (); +=A0 if (event) +=A0=A0=A0 return evpy_emit_event (event, gdb_py_events.newobjfile); +=A0 return -1; +} + +GDBPY_NEW_EVENT_TYPE (new_objfile, +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "gdb.NewOb= jFileEvent", +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "NewObjFil= eEvent", +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "GDB new o= bject file event object", +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 event_obje= ct_type, +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 static); diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index d3cb788..cc9108f 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -207,6 +207,7 @@ void gdbpy_initialize_breakpoint_event (void); =A0void gdbpy_initialize_continue_event (void); =A0void gdbpy_initialize_exited_event (void); =A0void gdbpy_initialize_thread_event (void); +void gdbpy_initialize_new_objfile_event (void); =A0struct cleanup *make_cleanup_py_decref (PyObject *py); @@ -215,6 +216,7 @@ struct cleanup *ensure_python_env (struct gdbarch *gdba= rch, =A0extern struct gdbarch *python_gdbarch; =A0extern const struct language_defn *python_language; +extern struct objfile *gdbpy_current_objfile; =A0/* Use this after a TRY_EXCEPT to throw the appropriate Python =A0=A0=A0 exception.=A0 */ diff --git a/gdb/python/python.c b/gdb/python/python.c index 90d5dc8..df883ef 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -811,8 +811,9 @@ gdbpy_progspaces (PyObject *unused1, PyObject *unused2) =A0/* The "current" objfile.=A0 This is set when gdb detects that a new =A0=A0=A0 objfile has been loaded.=A0 It is only set for the duration of a = call to -=A0=A0 source_python_script_for_objfile; it is NULL at other times.=A0 */ -static struct objfile *gdbpy_current_objfile; +=A0=A0 source_python_script_for_objfile and new_objfile callbacks; it is N= ULL at +=A0=A0 other times.=A0 */ +struct objfile *gdbpy_current_objfile; =A0/* Set the current objfile to OBJFILE and then read STREAM,FILE as =A0=A0=A0 Python code.=A0 */ @@ -1074,6 +1075,7 @@ Enables or disables printing of Python stack traces."= ), =A0=A0 gdbpy_initialize_continue_event (); =A0=A0 gdbpy_initialize_exited_event (); =A0=A0 gdbpy_initialize_thread_event (); +=A0 gdbpy_initialize_new_objfile_event () ; =A0=A0 PyRun_SimpleString ("import gdb"); =A0=A0 PyRun_SimpleString ("gdb.pretty_printers =3D []"); diff --git a/gdb/testsuite/gdb.python/py-events-shlib.c b/gdb/testsuite/gdb.python/py-events-shlib.c new file mode 100644 index 0000000..2a17bbf --- /dev/null +++ b/gdb/testsuite/gdb.python/py-events-shlib.c @@ -0,0 +1,20 @@ +/* This testcase is part of GDB, the GNU debugger. + +=A0=A0 Copyright 2011 Free Software Foundation, Inc. + +=A0=A0 This program is free software; you can redistribute it and/or modify +=A0=A0 it under the terms of the GNU General Public License as published by +=A0=A0 the Free Software Foundation; either version 3 of the License, or +=A0=A0 (at your option) any later version. + +=A0=A0 This program is distributed in the hope that it will be useful, +=A0=A0 but WITHOUT ANY WARRANTY; without even the implied warranty of +=A0=A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.=A0 See the +=A0=A0 GNU General Public License for more details. + +=A0=A0 You should have received a copy of the GNU General Public License +=A0=A0 along with this program.=A0 If not, see .=A0 */ + + +void do_nothing (void) {} + diff --git a/gdb/testsuite/gdb.python/py-events.c b/gdb/testsuite/gdb.python/py-events.c index ceb697e..1cf7cc7 100644 --- a/gdb/testsuite/gdb.python/py-events.c +++ b/gdb/testsuite/gdb.python/py-events.c @@ -16,6 +16,8 @@ =A0=A0=A0 along with this program.=A0 If not, see=A0 . =A0*/ +extern void do_nothing (void) ; + =A0int second(){ =A0=A0 return 12; =A0} @@ -25,5 +27,6 @@ int first(){ =A0} =A0int main (){ +=A0 do_nothing() ; =A0=A0 return first(); =A0} diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index e5d6daf..56e8f86 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -24,23 +24,45 @@ if $tracelevel then { =A0load_lib gdb-python.exp +set libfile "py-events-shlib" +set libsrc=A0 $srcdir/$subdir/$libfile.c +set lib_sl=A0 $objdir/$subdir/$libfile.so +set lib_opts=A0 debug + =A0set testfile "py-events" =A0set srcfile ${testfile}.c =A0set binfile ${objdir}/${subdir}/${testfile} +set exec_opts [list debug shlib=3D$lib_sl] =A0set pyfile ${srcdir}/${subdir}/${testfile}.py -if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { +if [get_compiler_info ${binfile}] { +=A0=A0=A0 return -1 +} + +if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] !=3D "" +=A0=A0=A0=A0 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] !=3D ""} { +=A0=A0=A0 untested "Could not compile either $libsrc or $srcdir/$subdir/$s= rcfile." =A0=A0=A0=A0 return -1 =A0} +# Start with a fresh gdb. + +gdb_exit +gdb_start + =A0if { [skip_python_tests] } { continue } +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + =A0gdb_test_no_output "python execfile ('${pyfile}')" "" -if ![runto_main ] then { -=A0=A0=A0 fail "Can't run to main" -=A0=A0=A0 return -1 -} +gdb_test "Test_Newobj_Events" "New ObjectFile Event tester registered." + +gdb_breakpoint "main" {temporary} + +gdb_test "run" ".*event type: new_objfile.* +.*new objfile name.*" =A0gdb_test "Test_Events" "Event testers registered." diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.python/py-events.py index 9f05b9f..12e36e8 100644 --- a/gdb/testsuite/gdb.python/py-events.py +++ b/gdb/testsuite/gdb.python/py-events.py @@ -48,6 +48,14 @@ def continue_handler (event): =A0=A0=A0=A0 if ( event.inferior_thread is not None) : =A0=A0=A0=A0=A0=A0=A0=A0 print "thread num: %s" % (event.inferior_thread.nu= m); +def new_objfile_handler (event): +=A0=A0=A0 if (isinstance (event, gdb.NewObjFileEvent)): +=A0=A0=A0=A0=A0=A0=A0 print "event type: new_objfile" +=A0=A0=A0 if (gdb.current_objfile () is not None): +=A0=A0=A0 =A0=A0=A0 print "new objfile name: %s" % (gdb.current_objfile ()= .filename) +=A0=A0=A0 else: +=A0=A0=A0=A0=A0=A0=A0 print "new objfile is None" + =A0class test_events (gdb.Command): =A0=A0=A0=A0 """Test events.""" @@ -62,3 +70,15 @@ class test_events (gdb.Command): =A0=A0=A0=A0=A0=A0=A0=A0 print "Event testers registered." =A0test_events () + +class test_newobj_events (gdb.Command): +=A0=A0=A0 """NewObj events.""" + +=A0=A0=A0 def __init__ (self): +=A0=A0=A0=A0=A0=A0=A0 gdb.Command.__init__ (self, "test_newobj_events", gd= b.COMMAND_STACK) + +=A0=A0=A0 def invoke (self, arg, from_tty): +=A0=A0=A0=A0=A0=A0=A0 gdb.events.newobjfile.connect (new_objfile_handler) +=A0=A0=A0=A0=A0=A0=A0 print "New ObjectFile Event tester registered." + +test_newobj_events () -- 1.7.4 On Tue, Mar 29, 2011 at 4:21 AM, Kevin Pouget wrot= e: > > Hello, > > > > Do you have copyright assignment paperwork in place? =A0If not, let me > > know and I can get you started. =A0This is a requirement before we can > > accept a non-trivial patch. > > No, not yet, what I am supposed to ? > > > Kevin> and, likewise, allows Python's "gdb.current_objfile ()" to return > > Kevin> the current object file. > > > > I'm ambivalent about this part. > > > > It seems to me that the objfile should be an attribute of the event. > > Also setting it globally is ok, if you really want that, but it isn't a > > necessity. > > I was ambivalent about this point too; I chose "gdb.current_objfile > ()" because autoloading > (http://sourceware.org/gdb/current/onlinedocs/gdb/Auto_002dloading.html) > already does it this way, and the two features are pretty similar. I > felt that it would have been strange to access "gdb.current_objfile > ()" in one case, and sth like "event.new_objfile" in the other case > > let me know if you agree with this perspective; it wouldn't be a big > deal to flip to the other solution otherwise > > > Kevin> There is still one thing I'm not happy with in the code, it's ho= w to > > Kevin> 'properly' access "gdbpy_current_objfile" ? I commented out "sta= tic" > > Kevin> and declared it "extern" when I needed it, but that's certainly = not > > Kevin> the best way: > > > > Dropping the `static' is ok. =A0GDB is already full of this kind of thi= ng. > > > > Kevin> +extern struct objfile *gdbpy_current_objfile; > > > > Should be in python-internal.h. > > fixed > > > Kevin> +static void > > Kevin> +python_new_objfile (struct objfile *objfile) > > > > New functions need an introductory comment. > > > > Kevin> + =A0/* Will be NULL when clearing the symtab. */ > > Kevin> + =A0if (objfile) > > Kevin> + =A0 =A0cleanup =3D ensure_python_env (get_objfile_arch (objfil= e), current_language); > > > > Is this comment stale? =A0It doesn't seem relevant. =A0When can objfile= =3D=3DNULL? > > I've been _once_ notified with NULL objfiles, coming from > >> gdb/symfile.c:clear_symtab_users "observer_notify_new_objfile (NULL);" > > that's why I added the null-checking, but I didn't investigate what's > behind this 'clear_symtab_users' and assumed > 'observer_notify_new_objfile (NULL)' justifies the verification by > itself > > is it okay for you? > > > Kevin> - > > Kevin> + =A0observer_attach_new_objfile (python_new_objfile); > > Kevin> + > > > > Gratuitous whitespace change. > > removed > > > Kevin> int > > Kevin> emit_new_objfile_event (struct objfile *objfile) > > Kevin> { > > Kevin> =A0 PyObject *event; > > [...] > > Kevin> =A0 event =3D create_new_objfile_event_object (); > > Kevin> =A0 if (event) > > Kevin> =A0 =A0 return evpy_emit_event (event, gdb_py_events.newobjfile); > > Kevin> =A0 return -1; > > > > I think this should attach the objfile to the event object. > > that's discussed above, I'm waiting for your point of view > > * I added to the patch a few lines of documentation and updated the > python event test-case. The exec is now linked with a shared-library > automatically created, so that we know that the new objfile observers > have to be notified. I'm not 100% confident about the test-case > protocol, please don't hesitate to tell me if it's not resilient > enough > > * I don't know how to add gdb/python/py-newobjfileevent.c and > gdb/testsuite/gdb.python/py-events-shlib.c to the CVS diff, I'll move > to git today so it should be fixed for the next patchs I send ; they > are at the bottom of the mail, separated with '----' > > * I don't know if there is an 'automatic' way to update the ChangeLog > (based on CVS/GIT), or if I should do it manually ? > > > Cheers, > > Kevin > > > ---- > > ? gdb/python/py-newobjfileevent.c > ? gdb/testsuite/gdb.python/py-events-shlib.c > Index: gdb/Makefile.in > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/Makefile.in,v > retrieving revision 1.1163 > diff -u -r1.1163 Makefile.in > --- gdb/Makefile.in =A0 =A0 9 Mar 2011 06:10:37 -0000 =A0 =A0 =A0 1.1163 > +++ gdb/Makefile.in =A0 =A0 29 Mar 2011 08:08:41 -0000 > @@ -296,7 +296,8 @@ > =A0 =A0 =A0 =A0py-threadevent.o \ > =A0 =A0 =A0 =A0py-type.o \ > =A0 =A0 =A0 =A0py-utils.o \ > - =A0 =A0 =A0 py-value.o > + =A0 =A0 =A0 py-value.o \ > + =A0 =A0 =A0 py-newobjfileevent.o > > =A0SUBDIR_PYTHON_SRCS =3D \ > =A0 =A0 =A0 =A0python/python.c \ > @@ -326,7 +327,8 @@ > =A0 =A0 =A0 =A0python/py-threadevent.c \ > =A0 =A0 =A0 =A0python/py-type.c \ > =A0 =A0 =A0 =A0python/py-utils.c \ > - =A0 =A0 =A0 python/py-value.c > + =A0 =A0 =A0 python/py-value.c \ > + =A0 =A0 =A0 python/py-newobjfileevent.c > =A0SUBDIR_PYTHON_DEPS =3D > =A0SUBDIR_PYTHON_LDFLAGS=3D > =A0SUBDIR_PYTHON_CFLAGS=3D > @@ -2110,6 +2112,11 @@ > =A0 =A0 =A0 =A0$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-value.c > =A0 =A0 =A0 =A0$(POSTCOMPILE) > > +py-newobjfileevent.o: $(srcdir)/python/py-newobjfileevent.c > + =A0 =A0 =A0 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-newobjfilee= vent.c > + =A0 =A0 =A0 $(POSTCOMPILE) > + > + > =A0# > =A0# Dependency tracking. =A0Most of this is conditional on GNU Make being > =A0# found by configure; if GNU Make is not found, we fall back to a > Index: gdb/doc/gdb.texinfo > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v > retrieving revision 1.814 > diff -u -r1.814 gdb.texinfo > --- gdb/doc/gdb.texinfo 18 Mar 2011 08:44:46 -0000 =A0 =A0 =A01.814 > +++ gdb/doc/gdb.texinfo 29 Mar 2011 08:08:45 -0000 > @@ -22054,6 +22054,12 @@ > =A0This event indicates that the inferior or one of its threads has recei= ved as > =A0signal. =A0@code{gdb.SignalEvent} has the following attributes: > > +@item events.newobjfile > +Emits @code{gdb.NewObjFileEvent} which indicates that a new object-file = has > +been loaded in the inferior. > + > +During the callback, ``current objfile'' will be set to the new object f= ile. > + > =A0@table @code > =A0@defivar SignalEvent stop_signal > =A0A string representing the signal received by the inferior. =A0A list o= f possible > @@ -22696,10 +22702,10 @@ > > =A0@findex gdb.current_objfile > =A0@defun current_objfile > -When auto-loading a Python script (@pxref{Auto-loading}), @value{GDBN} > -sets the ``current objfile'' to the corresponding objfile. =A0This > -function returns the current objfile. =A0If there is no current objfile, > -this function returns @code{None}. > +When auto-loading a Python script (@pxref{Auto-loading}) and during new > +object-file callbacks, @value{GDBN} sets the ``current objfile'' to the > +corresponding objfile. =A0This function returns the current objfile. =A0= If > +there is no current objfile, this function returns @code{None}. > =A0@end defun > > =A0@findex gdb.objfiles > Index: gdb/python/py-event.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/python/py-event.h,v > retrieving revision 1.1 > diff -u -r1.1 py-event.h > --- gdb/python/py-event.h =A0 =A0 =A0 5 Feb 2011 05:27:23 -0000 =A0 =A0 = =A0 1.1 > +++ gdb/python/py-event.h =A0 =A0 =A0 29 Mar 2011 08:08:46 -0000 > @@ -105,6 +105,7 @@ > > =A0extern int emit_continue_event (ptid_t ptid); > =A0extern int emit_exited_event (LONGEST exit_code); > +extern int emit_new_objfile_event (struct objfile *objfile); > > =A0extern int evpy_emit_event (PyObject *event, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 eventregistry_obj= ect *registry); > Index: gdb/python/py-events.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/python/py-events.h,v > retrieving revision 1.1 > diff -u -r1.1 py-events.h > --- gdb/python/py-events.h =A0 =A0 =A05 Feb 2011 05:27:23 -0000 =A0 =A0 = =A0 1.1 > +++ gdb/python/py-events.h =A0 =A0 =A029 Mar 2011 08:08:46 -0000 > @@ -45,6 +45,7 @@ > =A0 eventregistry_object *stop; > =A0 eventregistry_object *cont; > =A0 eventregistry_object *exited; > + =A0eventregistry_object *newobjfile; > > =A0 PyObject *module; > > Index: gdb/python/py-evts.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/python/py-evts.c,v > retrieving revision 1.2 > diff -u -r1.2 py-evts.c > --- gdb/python/py-evts.c =A0 =A0 =A0 =A014 Mar 2011 15:43:51 -0000 =A0 = =A0 =A01.2 > +++ gdb/python/py-evts.c =A0 =A0 =A0 =A029 Mar 2011 08:08:46 -0000 > @@ -57,6 +57,9 @@ > > =A0 if (add_new_registry (&gdb_py_events.exited, "exited") < 0) > =A0 =A0 goto fail; > + > + =A0if (add_new_registry (&gdb_py_events.newobjfile, "newobjfile") < 0) > + =A0 =A0goto fail; > > =A0 Py_INCREF (gdb_py_events.module); > =A0 if (PyModule_AddObject (gdb_module, > Index: gdb/python/py-inferior.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/python/py-inferior.c,v > retrieving revision 1.7 > diff -u -r1.7 py-inferior.c > --- gdb/python/py-inferior.c =A0 =A017 Mar 2011 09:36:16 -0000 =A0 =A0 = =A01.7 > +++ gdb/python/py-inferior.c =A0 =A029 Mar 2011 08:08:46 -0000 > @@ -22,6 +22,7 @@ > =A0#include "gdbcore.h" > =A0#include "gdbthread.h" > =A0#include "inferior.h" > +#include "objfiles.h" > =A0#include "observer.h" > =A0#include "python-internal.h" > =A0#include "arch-utils.h" > @@ -129,6 +130,31 @@ > =A0 do_cleanups (cleanup); > =A0} > > +/* Callback used to notify Python listeners about new objfiles loaded in= the > + =A0 inferior. Python global variable 'gdb.current_objfile ()' will be s= et > + =A0 during the notifications. > + */ > + > +static void > +python_new_objfile (struct objfile *objfile) > +{ > + =A0struct cleanup *cleanup; > + > + =A0/* Will be NULL when clearing the symtab. */ > + =A0if (objfile) > + =A0 =A0cleanup =3D ensure_python_env (get_objfile_arch (objfile), curre= nt_language); > + =A0else > + =A0 =A0cleanup =3D ensure_python_env (get_current_arch (), current_lang= uage); > + > + =A0gdbpy_current_objfile =3D objfile; > + > + =A0if (emit_new_objfile_event (objfile) < 0) > + =A0 =A0gdbpy_print_stack (); > + > + =A0do_cleanups (cleanup); > + =A0gdbpy_current_objfile =3D NULL; > +} > + > =A0/* Return a borrowed reference to the Python object of type Inferior > =A0 =A0representing INFERIOR. =A0If the object has already been created, > =A0 =A0return it, =A0otherwise, create it. =A0Return NULL on failure. =A0= */ > @@ -669,6 +695,7 @@ > =A0 observer_attach_normal_stop (python_on_normal_stop); > =A0 observer_attach_target_resumed (python_on_resume); > =A0 observer_attach_inferior_exit (python_inferior_exit); > + =A0observer_attach_new_objfile (python_new_objfile); > > =A0 if (PyType_Ready (&membuf_object_type) < 0) > =A0 =A0 return; > Index: gdb/python/python-internal.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/python/python-internal.h,v > retrieving revision 1.44 > diff -u -r1.44 python-internal.h > --- gdb/python/python-internal.h =A0 =A0 =A0 =A028 Feb 2011 19:38:34 -000= 0 =A0 =A0 =A01.44 > +++ gdb/python/python-internal.h =A0 =A0 =A0 =A029 Mar 2011 08:08:46 -0000 > @@ -207,6 +207,7 @@ > =A0void gdbpy_initialize_continue_event (void); > =A0void gdbpy_initialize_exited_event (void); > =A0void gdbpy_initialize_thread_event (void); > +void gdbpy_initialize_new_objfile_event (void); > > =A0struct cleanup *make_cleanup_py_decref (PyObject *py); > > @@ -215,6 +216,7 @@ > > =A0extern struct gdbarch *python_gdbarch; > =A0extern const struct language_defn *python_language; > +extern struct objfile *gdbpy_current_objfile; > > =A0/* Use this after a TRY_EXCEPT to throw the appropriate Python > =A0 =A0exception. =A0*/ > Index: gdb/python/python.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/python/python.c,v > retrieving revision 1.63 > diff -u -r1.63 python.c > --- gdb/python/python.c 18 Mar 2011 08:44:47 -0000 =A0 =A0 =A01.63 > +++ gdb/python/python.c 29 Mar 2011 08:08:46 -0000 > @@ -811,8 +811,9 @@ > > =A0/* The "current" objfile. =A0This is set when gdb detects that a new > =A0 =A0objfile has been loaded. =A0It is only set for the duration of a c= all to > - =A0 source_python_script_for_objfile; it is NULL at other times. =A0*/ > -static struct objfile *gdbpy_current_objfile; > + =A0 source_python_script_for_objfile and new_objfile callbacks; it is N= ULL at > + =A0 other times. =A0*/ > +struct objfile *gdbpy_current_objfile; > > =A0/* Set the current objfile to OBJFILE and then read STREAM,FILE as > =A0 =A0Python code. =A0*/ > @@ -1074,6 +1075,7 @@ > =A0 gdbpy_initialize_continue_event (); > =A0 gdbpy_initialize_exited_event (); > =A0 gdbpy_initialize_thread_event (); > + =A0gdbpy_initialize_new_objfile_event () ; > > =A0 PyRun_SimpleString ("import gdb"); > =A0 PyRun_SimpleString ("gdb.pretty_printers =3D []"); > Index: gdb/testsuite/gdb.python/py-events.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-events.c,v > retrieving revision 1.1 > diff -u -r1.1 py-events.c > --- gdb/testsuite/gdb.python/py-events.c =A0 =A0 =A0 =A05 Feb 2011 05:27:= 23 -0000 =A0 =A0 =A0 1.1 > +++ gdb/testsuite/gdb.python/py-events.c =A0 =A0 =A0 =A029 Mar 2011 08:08= :46 -0000 > @@ -16,6 +16,8 @@ > =A0 =A0along with this program. =A0If not, see =A0. > =A0*/ > > +extern void do_nothing (void) ; > + > =A0int second(){ > =A0 return 12; > =A0} > @@ -25,5 +27,6 @@ > =A0} > > =A0int main (){ > + =A0do_nothing() ; > =A0 return first(); > =A0} > Index: gdb/testsuite/gdb.python/py-events.exp > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-events.exp,v > retrieving revision 1.1 > diff -u -r1.1 py-events.exp > --- gdb/testsuite/gdb.python/py-events.exp =A0 =A0 =A05 Feb 2011 05:27:23= -0000 =A0 =A0 =A0 1.1 > +++ gdb/testsuite/gdb.python/py-events.exp =A0 =A0 =A029 Mar 2011 08:08:4= 6 -0000 > @@ -24,23 +24,45 @@ > > =A0load_lib gdb-python.exp > > +set libfile "py-events-shlib" > +set libsrc =A0$srcdir/$subdir/$libfile.c > +set lib_sl =A0$objdir/$subdir/$libfile.so > +set lib_opts =A0debug > + > =A0set testfile "py-events" > =A0set srcfile ${testfile}.c > =A0set binfile ${objdir}/${subdir}/${testfile} > +set exec_opts [list debug shlib=3D$lib_sl] > =A0set pyfile ${srcdir}/${subdir}/${testfile}.py > > -if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { > +if [get_compiler_info ${binfile}] { > + =A0 =A0return -1 > +} > + > +if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] !=3D "" > + =A0 =A0 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable > $exec_opts] !=3D ""} { > + =A0 =A0untested "Could not compile either $libsrc or $srcdir/$subdir/$s= rcfile." > =A0 =A0 return -1 > =A0} > > +# Start with a fresh gdb. > + > +gdb_exit > +gdb_start > + > =A0if { [skip_python_tests] } { continue } > > +gdb_reinitialize_dir $srcdir/$subdir > +gdb_load ${binfile} > + > =A0gdb_test_no_output "python execfile ('${pyfile}')" "" > > -if ![runto_main ] then { > - =A0 =A0fail "Can't run to main" > - =A0 =A0return -1 > -} > +gdb_test "Test_Newobj_Events" "New ObjectFile Event tester registered." > + > +gdb_breakpoint "main" {temporary} > + > +gdb_test "run" ".*event type: new_objfile.* > +.*new objfile name.*" > > =A0gdb_test "Test_Events" "Event testers registered." > > Index: gdb/testsuite/gdb.python/py-events.py > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-events.py,v > retrieving revision 1.1 > diff -u -r1.1 py-events.py > --- gdb/testsuite/gdb.python/py-events.py =A0 =A0 =A0 5 Feb 2011 05:27:23= -0000 =A0 =A0 =A0 1.1 > +++ gdb/testsuite/gdb.python/py-events.py =A0 =A0 =A0 29 Mar 2011 08:08:4= 6 -0000 > @@ -48,6 +48,14 @@ > =A0 =A0 if ( event.inferior_thread is not None) : > =A0 =A0 =A0 =A0 print "thread num: %s" % (event.inferior_thread.num); > > +def new_objfile_handler (event): > + =A0 =A0if (isinstance (event, gdb.NewObjFileEvent)): > + =A0 =A0 =A0 =A0print "event type: new_objfile" > + =A0 =A0if (gdb.current_objfile () is not None): > + =A0 =A0 =A0 print "new objfile name: %s" % (gdb.current_objfile ().file= name) > + =A0 =A0else: > + =A0 =A0 =A0 =A0print "new objfile is None" > + > =A0class test_events (gdb.Command): > =A0 =A0 """Test events.""" > > @@ -62,3 +70,15 @@ > =A0 =A0 =A0 =A0 print "Event testers registered." > > =A0test_events () > + > +class test_newobj_events (gdb.Command): > + =A0 =A0"""NewObj events.""" > + > + =A0 =A0def __init__ (self): > + =A0 =A0 =A0 =A0gdb.Command.__init__ (self, "test_newobj_events", gdb.CO= MMAND_STACK) > + > + =A0 =A0def invoke (self, arg, from_tty): > + =A0 =A0 =A0 =A0gdb.events.newobjfile.connect (new_objfile_handler) > + =A0 =A0 =A0 =A0print "New ObjectFile Event tester registered." > + > +test_newobj_events () > > ---- > > /* Python interface to new object file loading events. > > =A0 Copyright (C) 2011 Free Software Foundation, Inc. > > =A0 This file is part of GDB. > > =A0 This program is free software; you can redistribute it and/or modify > =A0 it under the terms of the GNU General Public License as published by > =A0 the Free Software Foundation; either version 3 of the License, or > =A0 (at your option) any later version. > > =A0 This program is distributed in the hope that it will be useful, > =A0 but WITHOUT ANY WARRANTY; without even the implied warranty of > =A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =A0See the > =A0 GNU General Public License for more details. > > =A0 You should have received a copy of the GNU General Public License > =A0 along with this program. =A0If not, see . =A0*/ > > #include "py-event.h" > > static PyTypeObject new_objfile_event_object_type; > > PyObject * > create_new_objfile_event_object (void) > { > =A0return create_event_object (&new_objfile_event_object_type); > } > > /* Callback function which notifies observers when a new objfile event oc= curs. > =A0 This function will create a new Python new_objfile event object. > =A0 Return -1 if emit fails. =A0*/ > > int > emit_new_objfile_event (struct objfile *objfile) > { > =A0PyObject *event; > > =A0if (evregpy_no_listeners_p (gdb_py_events.newobjfile)) > =A0 =A0return 0; > > =A0event =3D create_new_objfile_event_object (); > =A0if (event) > =A0 =A0return evpy_emit_event (event, gdb_py_events.newobjfile); > =A0return -1; > } > > GDBPY_NEW_EVENT_TYPE (new_objfile, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"gdb.NewObjFileEvent", > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"NewObjFileEvent", > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"GDB new object file event obj= ect", > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0event_object_type, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0static); > > ---- > > /* This testcase is part of GDB, the GNU debugger. > > =A0 Copyright 2011 Free Software Foundation, Inc. > > =A0 This program is free software; you can redistribute it and/or modify > =A0 it under the terms of the GNU General Public License as published by > =A0 the Free Software Foundation; either version 3 of the License, or > =A0 (at your option) any later version. > > =A0 This program is distributed in the hope that it will be useful, > =A0 but WITHOUT ANY WARRANTY; without even the implied warranty of > =A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =A0See the > =A0 GNU General Public License for more details. > > =A0 You should have received a copy of the GNU General Public License > =A0 along with this program. =A0If not, see . =A0*/ > > > void do_nothing (void) {}