This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Implement post_event for Python scripts.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]