From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19357 invoked by alias); 28 Mar 2011 08:11:41 -0000 Received: (qmail 19340 invoked by uid 22791); 28 Mar 2011 08:11:38 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_BJ,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-vw0-f41.google.com (HELO mail-vw0-f41.google.com) (209.85.212.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Mar 2011 08:11:33 +0000 Received: by vws4 with SMTP id 4so2671998vws.0 for ; Mon, 28 Mar 2011 01:11:32 -0700 (PDT) Received: by 10.220.198.200 with SMTP id ep8mr1011231vcb.132.1301299892285; Mon, 28 Mar 2011 01:11:32 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.200.3 with HTTP; Mon, 28 Mar 2011 01:11:12 -0700 (PDT) In-Reply-To: References: From: Kevin Pouget Date: Mon, 28 Mar 2011 08:51:00 -0000 Message-ID: Subject: Re: [RFC - Python] New ObjFile event To: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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/msg01117.txt.bz2 sorry, gdb/python/py-newobjfileevent.c has not been included in the patch, here is its content: ----- /* Python interface to new object file loading events. Copyright (C) 2009, 2010, 2011 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 "py-event.h" static PyTypeObject new_objfile_event_object_type; PyObject * create_new_objfile_event_object (void) { return create_event_object (&new_objfile_event_object_type); } /* Callback function which notifies observers when a new objfile event occu= rs. This function will create a new Python new_objfile event object. Return -1 if emit fails. */ int emit_new_objfile_event (struct objfile *objfile) { PyObject *event; if (evregpy_no_listeners_p (gdb_py_events.newobjfile)) return 0; event =3D create_new_objfile_event_object (); if (event) return evpy_emit_event (event, gdb_py_events.newobjfile); return -1; } GDBPY_NEW_EVENT_TYPE (new_objfile, "gdb.NewObjFileEvent", "NewObjFileEvent", "GDB new object file event object", event_object_type, static); --- On Mon, Mar 28, 2011 at 4:06 AM, Kevin Pouget wrot= e: > Hello, > > following this discussion at > http://sourceware.org/ml/gdb/2011-03/msg00136.html, I would like to > suggest a patch for the Python event system. Based on the ''exited", > "cont", ... events, this patch allows a python script to register an > interest to the loading of new object files in the debuggee. GDB > observer "observer_attach_new_objfile" is used to trigger the Python > callback. > > This patch completes the auto-loading feature > (http://sourceware.org/gdb/current/onlinedocs/gdb/objfile_002dgdb_002epy-= file.html#objfile_002dgdb_002epy-file), > and, likewise, allows Python's "gdb.current_objfile ()" to return the cur= rent > object file. > > Here is an example of it utilization: > >> def obj_handler (event): >> =A0 =A0 =A0 if gdb.current_objfile () is not None: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 print "-->",gdb.current_objfile ().filename >> =A0 =A0 =A0 else: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 print "---------------->Cleanup" >> >> gdb.events.newobjfile.connect (obj_handler) > > > There is still one thing I'm not happy with in the code, it's how to > 'properly' access "gdbpy_current_objfile" ? I commented out "static" > and declared it "extern" when I needed it, but that's certainly not > the best way: > > gdb/python/python.c > /*static*/ struct objfile *gdbpy_current_objfile; > gdb/python/py-inferior.c > extern struct objfile *gdbpy_current_objfile; > > > please let me know what you thing about it > > Cordially, > > Kevin >