diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-12-08 19:20:58 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-12-08 19:20:58 -0600 |
| commit | 357acc5d82a2b04cf846d69826ec89671e78e759 (patch) | |
| tree | c0fded1f5c5f18eb1c9e4df76d2497ad84c1f777 /sim/gdbstub.py | |
| parent | d6fff0eb1ce867192d30babb839fc09c30049f0b (diff) | |
Support gdb interrupts
Diffstat (limited to '')
| -rw-r--r-- | sim/gdbstub.py | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/sim/gdbstub.py b/sim/gdbstub.py index 8d20f39..914f717 100644 --- a/sim/gdbstub.py +++ b/sim/gdbstub.py @@ -3,29 +3,53 @@ import sys, socket cycles = None enable_tty = True start_halted = True +sock, client = None, None def init(): - global client + global sock sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(('127.0.0.1', 1234)) sock.listen() - print('Listening for gdb on', sock.getsockname(), file=sys.stderr) - client, peer = sock.accept() - sock.close() - print('Accepted connection from', peer, file=sys.stderr) +def halt(): + return yield_to_gdb() + +def fatal(): + global stop_reason + stop_reason = 'fatal' + yield_to_gdb() buffer = b'' -haltFromStop = False +stop_reason = None -def halt(): - global buffer, haltFromStop +def yield_to_gdb(): + global client, buffer, stop_reason + + if not client: + print('Listening for gdb on', sock.getsockname(), file=sys.stderr) + + client, peer = sock.accept() + print('Accepted connection from', peer, file=sys.stderr) + + register_interrupt(client) + stop_reason = 'reset' + + dead = stop_reason == 'fatal' + sendStop = True + + if stop_reason == 'break': + stop_reply = b'S05' + elif stop_reason == 'reset': + stop_reply = b'S05' + stop_reason = 'break' + sendStop = False + elif stop_reason == 'fatal': + stop_reply = b'S0a' - if haltFromStop: - reply(b'S05') + if sendStop: + reply(stop_reply) - haltFromStop = True while True: data = client.recv(4096) if not data: @@ -53,8 +77,8 @@ def halt(): client.send(b'+') if data == b'?': - out = b'S05' - elif data == b'c': + out = stop_reply + elif data == b'c' and not dead: return 'continue' elif data == b'D': out = b'OK' @@ -75,7 +99,7 @@ def halt(): elif data[0] == b'p'[0]: reg = gdb_reg(int(data[1:], 16)) out = hexout(read_reg(reg) if reg is not None else None) - elif data == b's': + elif data == b's' and not dead: return 'step' else: out = b'' |
