From: Phil Muldoon <pmuldoon@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: Joel Brobecker <brobecker@adacore.com>,
gdb-patches ml <gdb-patches@sourceware.org>
Subject: Re: [patch] Implement post_event for Python scripts.
Date: Tue, 03 Aug 2010 14:26:00 -0000 [thread overview]
Message-ID: <4C582707.6080101@redhat.com> (raw)
In-Reply-To: <m3sk303au4.fsf@fleche.redhat.com>
On 30/07/10 22:42, Tom Tromey wrote:
>>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> 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.
next prev parent reply other threads:[~2010-08-03 14:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-20 18:53 Phil Muldoon
2010-07-20 19:08 ` Tom Tromey
2010-07-27 16:30 ` Joel Brobecker
2010-07-28 14:18 ` Phil Muldoon
2010-07-28 17:31 ` Joel Brobecker
2010-07-30 21:43 ` Tom Tromey
2010-08-03 14:26 ` Phil Muldoon [this message]
2010-08-03 17:00 ` Eli Zaretskii
2010-08-11 18:35 ` Tom Tromey
2010-08-11 19:05 ` Joel Brobecker
2010-08-11 21:08 ` Phil Muldoon
2010-07-28 17:49 ` Eli Zaretskii
2010-08-18 13:46 ` Pedro Alves
2010-08-18 14:36 ` Daniel Jacobowitz
2010-08-18 17:39 ` Pedro Alves
2010-08-18 18:13 ` Tom Tromey
2010-08-20 0:35 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C582707.6080101@redhat.com \
--to=pmuldoon@redhat.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox