Sometimes run_serial() will timeout before the data requested by the command in dump_target() has returned. That will make the current file empty(because it assumes the data is there), but then it proceeds to the next file which then gets the output from the previous command. Each file from then on will have the output from the previous command. This makes it fairly hard to use the debug programatically or even manually since you have to inspect each file to figure out what the data actually is. This could most likely be fixed by running a command such as "echo 'Running command foo'" as a heading before each command, and putting all the data in the same file. Or by then postprocessing based on the heading and putting the data into separate files based on the headings.
The problem is that there is a timeout while reading the socket. This timeout could be omitted because we are searching for the prompt as the last thing the socket will get
Sent patch for review
Patch is integrated in master: http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=3b95964bc1cb63c1b78249fd8f8c2d5d5fb2c288