From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29183 invoked by alias); 3 Aug 2010 14:26:47 -0000 Received: (qmail 29166 invoked by uid 22791); 3 Aug 2010 14:26:45 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 03 Aug 2010 14:26:40 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o73EQHdo020159 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 Aug 2010 10:26:17 -0400 Received: from Phil-THINK.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o73EQFJl014096; Tue, 3 Aug 2010 10:26:16 -0400 Message-ID: <4C582707.6080101@redhat.com> Date: Tue, 03 Aug 2010 14:26:00 -0000 From: Phil Muldoon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100720 Fedora/3.1.1-1.fc13 Thunderbird/3.1.1 MIME-Version: 1.0 To: Tom Tromey CC: Joel Brobecker , gdb-patches ml Subject: Re: [patch] Implement post_event for Python scripts. References: <4C45F0B0.5000903@redhat.com> <20100727162956.GG13267@adacore.com> <4C503BFE.8090608@redhat.com> <20100728173128.GM13267@adacore.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 2010-08/txt/msg00009.txt.bz2 On 30/07/10 22:42, Tom Tromey wrote: >>>>>> "Joel" == Joel Brobecker writes: > >>> Providing an example of a multi-threaded python script using >>> post_event would be too complex for the manual (I'm not sure that was >>> what you wanted anyway). I provided a small example that shows usage. >>> Is this okay? > > Joel> I'm just trying to figure out how this feature can be useful, and > Joel> in particular when the callbacks are triggered. Perhaps, rather than > Joel> an example, what we need is a section that describes the event loop > Joel> and when it is queried. It's not useful to single-threaded scenarios (which I think are going to be the vast number of applications of Python scripting). For multi-threaded scenarios (say a UI running on top of GDB that has its own UI thread and event-loop) this is the only thread-safe way to interact with GDB. Describing the GDB even-loop would seem to be more the province of an internals manual. That being said, I take your point. > Tom> For the purposes of post_event, I think it is probably sufficient to say > Tom> that the callback will be executed in the main thread "sometime". I > Tom> don't think we can really provide anything more concrete than that > Tom> anyhow. I wrote up a multi-threaded example, but it is still a very basic shell of an example. To really show a useful example it would require loading an inferior, etc., and that would probably be too in-depth for the manual Cheers, Phil -- diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 03b59a3..77e21f2 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20533,6 +20533,45 @@ compute values, for example, it is the only way to get the value of a convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}. @end defun +@findex gdb.post_event +@defun post_event event +Put @var{event}, a callable object taking no arguments, into +@value{GDBN}'s internal event queue. This callable will be invoked at +some later point, during @value{GDBN}'s event processing. Events +posted using @code{post_event} will be run in the order in which they +were posted; however, there is no way to know when they will be +processed relative to other events inside @value{GDBN}. + +@value{GDBN} is not thread-safe. If your Python program uses multiple +threads, you must be careful to only call @value{GDBN}-specific +functions in the main @value{GDBN} thread. @code{post_event} ensures +this. For example: + +@smallexample +(@value{GDBP}) python +>import threading +> +>class Writer(): +> def __init__(self, message): +> self.message = message; +> def __call__(self): +> gdb.write(self.message) +> +>class MyThread1 (threading.Thread): +> def run (self): +> gdb.post_event(Writer("Hello ")) +> +>class MyThread2 (threading.Thread): +> def run (self): +> gdb.post_event(Writer("World\n")) +> +>MyThread1().start() +>MyThread2().start() +>end +(@value{GDBP}) Hello World +@end smallexample +@end defun + @findex gdb.write @defun write string Print a string to @value{GDBN}'s paginated standard output stream.