public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* [RFC] PR python/10826
@ 2009-10-23 11:36 Phil Muldoon
  2009-10-30 22:21 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Phil Muldoon @ 2009-10-23 11:36 UTC (permalink / raw)
  To: Project Archer

[-- Attachment #1: Type: text/plain, Size: 1425 bytes --]

I've attached a patch to what I think is the best fix for the PR.  
Before the patch, "gdb.write" wrote to gdb_stdout and exited. The 
completion was noted, and MI appended "^done". While the command had 
indeed finished, the output was still still lurking in gdb_stdout, and 
was being flushed out later. This lead to out-of-sequence ^done message 
and "gdb.write" output.  I talked with Andre and Vlad on irc about 
possible fixes. We talked about the MI code flushing the buffer before 
appending ^done, but we are just not sure if this is correct. Given that 
many front ends presumably rely on the current MI expectation that each 
function flushes its own CLI output before exiting, the next best thing 
would be have gdb.write do just that.  This however does not allow large 
CLI messages to be constructed (or cached I guess) in gdb_stdout with 
successive calls to "gdb.write" - each write is flushed at the end of 
each "gdb.write" call. The workaround for this is to construct your 
message in some other buffer then feed the entire buffer to gdb.write at 
the end.

Anyway, here is the patch and test.

What do you think?

Cheers,

Phil

--

ChangeLog

2009-10-23  Phil Muldoon <pmuldoon@redhat.com>

     PR python/10826

     * python/python.c (gdbpy_write): Flush output.

Testsuite ChangeLog

2009-10-23  Phil Muldoon <pmuldoon@redhat.com>

     * gdb.python/py-mi.exp: Regression test for PR python/10826.


[-- Attachment #2: gdb_write_flush.patch --]
[-- Type: text/plain, Size: 847 bytes --]

diff --git a/gdb/python/python.c b/gdb/python/python.c
index 707b700..33c1bae 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -567,6 +567,7 @@ gdbpy_write (PyObject *self, PyObject *args)
   if (! PyArg_ParseTuple (args, "s", &arg))
     return NULL;
   printf_filtered ("%s", arg);
+  gdb_flush (gdb_stdout);
   Py_RETURN_NONE;
 }
 
diff --git a/gdb/testsuite/gdb.python/py-mi.exp b/gdb/testsuite/gdb.python/py-mi.exp
index 30d6f32..5b7c4e9 100644
--- a/gdb/testsuite/gdb.python/py-mi.exp
+++ b/gdb/testsuite/gdb.python/py-mi.exp
@@ -232,3 +232,7 @@ mi_continue_to_line \
     "step to second breakpoint"
 
 mi_varobj_update_with_type_change container int 0 "update after type change"
+
+mi_gdb_test "-interpreter-exec console \"python gdb.write (str(42))\"" \
+  ".*\~\\\"42\\\".*\\^done" \
+  "ensure gdb write output is flushed"

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-03 13:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-23 11:36 [RFC] PR python/10826 Phil Muldoon
2009-10-30 22:21 ` Tom Tromey
2009-11-03 13:49   ` Phil Muldoon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).