From ca5c20b6d32018c05a1c20a099a71137b4b27a4d Mon Sep 17 00:00:00 2001 From: Phil Muldoon Date: Wed, 11 Aug 2010 20:54:12 +0000 Subject: 2010-08-11 Tom Tromey Phil Muldoon * python/python.c (gdbpy_run_events): New function. (gdbpy_post_event): Likewise. (gdbpy_initialize_events): Likewise. (_initialize_python): Call gdbpy_initialize_events. 2010-08-11 Tom Tromey Phil Muldoon * gdb.texinfo (Basic Python): Describe post_event API. 2010-08-11 Phil Muldoon * gdb.python/python.exp (gdb_py_test_multiple): Add gdb.post_event tests. --- gdb/doc/ChangeLog | 5 +++++ gdb/doc/gdb.texinfo | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'gdb/doc') diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 9cc3664..5745151 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2010-08-11 Tom Tromey + Phil Muldoon + + * gdb.texinfo (Basic Python): Describe post_event API. + 2010-08-11 Phil Muldoon * gdb.texinfo (Basic Python): Describe solib_address and diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 9851212..ba1607c 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20525,6 +20525,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. -- cgit v1.1