def execute(command_string, timeout = nil)
raise "GDB session is already closed" if !@pid
puts "gdb write #{command_string.inspect}" if @debug
@in.puts(command_string)
@in.puts("echo \\n#{END_OF_RESPONSE_MARKER}\\n")
done = false
result = ""
while !done
begin
if select([@out], nil, nil, timeout)
line = @out.readline
puts "gdb read #{line.inspect}" if @debug
if line == "#{END_OF_RESPONSE_MARKER}\n"
done = true
else
result << line
end
else
close!
done = true
result = nil
end
rescue EOFError
done = true
end
end
result
end