Commit a5b855ca authored by Tristan Gingold's avatar Tristan Gingold

debug: add detach, and poll for interrupt.

parent 419fd63d
......@@ -3,6 +3,7 @@ import PyUAL
import getopt, sys
import time
import socket
import select
import struct
gdb_port = 3000
......@@ -195,6 +196,7 @@ class GdbServer(object):
self.dap = dap
self.port = port
self.conn = None
self.packet_size = 2048
self.term = (flag_term
and self.dap.csr.readl(CSR_CORESEL) == self.dap.cpu)
if not self.term:
......@@ -276,9 +278,12 @@ class GdbServer(object):
sys.stdout.flush()
timeout = 1
# FIXME: ^C handling is not reliable (can happen anywhere).
stop = False
try:
time.sleep(timeout / 1000.0)
(r, w, x) = select.select([self.conn], [], [], timeout / 1000.0)
except KeyboardInterrupt:
stop = True
if stop or self.conn in r:
self.force_debug()
self.send('S02')
return
......@@ -287,6 +292,11 @@ class GdbServer(object):
elif timeout < 100:
timeout += 10
self.send('S05')
def handle_D(self, packet):
# Detach
self.dap.exec_insn(0x00100073) # ebreak
self.send('OK')
def handle_g(self, packet):
# Serious work: read all registers.
......@@ -398,7 +408,7 @@ class GdbServer(object):
self.send('')
def handle_q_supported(self, packet):
self.send('')
self.send('PacketSize={:x}'.format(self.packet_size))
def handle_q(self, packet):
if packet.startswith('qSupported:'):
......@@ -483,7 +493,7 @@ class GdbServer(object):
while True:
# Wait for a packet
packet = ""
data = self.conn.recv(2048)
data = self.conn.recv(self.packet_size)
# Exit in case of disconnection
if len(data) == 0:
break
......@@ -491,8 +501,14 @@ class GdbServer(object):
if len(packet) == 0:
if c == '$':
packet = c
else:
elif c == '+':
# Ignore ack to answers.
pass
elif c == '\x03':
print "Got a break!"
else:
if flag_verbose:
print "Ignore character {:x}".format(ord(c))
else:
packet += c
if len(packet) > 3 and packet[-3] == '#':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment