From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17687 invoked by alias); 28 Jul 2010 14:18:13 -0000 Received: (qmail 17649 invoked by uid 22791); 28 Jul 2010 14:18:11 -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; Wed, 28 Jul 2010 14:18:01 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6SEHa0E020808 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Jul 2010 10:17:36 -0400 Received: from Phil-THINK.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6SEHYP6015431; Wed, 28 Jul 2010 10:17:35 -0400 Message-ID: <4C503BFE.8090608@redhat.com> Date: Wed, 28 Jul 2010 14:18: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: Joel Brobecker CC: gdb-patches ml Subject: Re: [patch] Implement post_event for Python scripts. References: <4C45F0B0.5000903@redhat.com> <20100727162956.GG13267@adacore.com> In-Reply-To: <20100727162956.GG13267@adacore.com> 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-07/txt/msg00478.txt.bz2 On 27/07/10 17:29, Joel Brobecker wrote: >> +@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}. > > Would it be useful to provide an exemple of how this feature could > be used? It does not seem obvious, and I am not sure without reading > the GDB Manual that users are familiar with GDB's internal even queue... 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? I've just regenerated the documentation patch for this reply. Cheers, Phil -- diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index be6cd3d..c7e1827 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20490,6 +20490,37 @@ 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 +>class Writer(): +> def __init__(self, message): +> self.message = message; +> def __call__(self): +> print self.message +> +>gdb.post_event(Writer("Hello")) +>gdb.post_event(Writer("World")) +>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.