Bug 10826 - possibly re-order '^done' message and python script output in MI mode
Summary: possibly re-order '^done' message and python script output in MI mode
Status: RESOLVED INVALID
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: archer
: P2 enhancement
Target Milestone: 7.1
Assignee: Phil Muldoon
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-22 07:21 UTC by Andre'
Modified: 2009-11-03 13:45 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andre' 2009-10-22 07:21:35 UTC
When I issue a python based command 'xx' in mi mode I get output similar to the
following:

&"xx\n"
>^done
>~"the output"

i.e. the ^done message comes before the actual script output. that's somewhat
inconvenient if one wants to capture the script output as long as there is no
clear 'end of transmission' marker.

It would be nicer if the ^done message were sent only after the script output,
or possibly even better, if the script output would be made proper part of the
^done message.


The behaviour is reproducible with b6fd5e85924d71f28bb7e9d463e97bfd26a25f80 and
has been around for a while, probably all the time.
Comment 1 Phil Muldoon 2009-11-03 13:45:39 UTC
I submitted a patch for what I thought would the solution here:

http://sourceware.org/ml/archer/2009-q4/msg00023.html

And Tom reviewed it here:

http://sourceware.org/ml/archer/2009-q4/msg00033.html

Tom quite rightly points out that commands are required to flush the buffer or
emit a newline. And that this should be the same for Python scripts. I decided
to write a hello world command and test if the output was sequenced correctly if
there were multiple writes, and one flush: 

class HelloWorld (gdb.Command):
  """Greet the whole world."""

  def __init__ (self):
    super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_OBSCURE)

  def invoke (self, arg, from_tty):
    gdb.write("Hello, World!")
    gdb.write("Lovely weather!")
    gdb.write("What a nice day for a walk")
    gdb.flush()

HelloWorld ()

output:

(gdb) 
python execfile("/home/build/helloworld2.py")
&"python execfile(\"/home/build/helloworld2.py\")\n"
^done
(gdb) 
hello-world
&"hello-world\n"
~"Hello, World!Lovely weather!What a nice day for a walk"
^done


I also tested the case with just a new line at the end, and no flush:

hello-world
&"hello-world\n"
~"Hello, World!Lovely weather!What a nice day for a walk\n"
^done
(gdb) 

So in both cases this works, and no patch is needed. So closing, happily with no
patches needed!