From b877360bf761c7a9488d8f04207990316e499df0 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 26 May 2006 11:52:20 +0000 Subject: Wrap our drivers gdb_getc() function so that if it returns -1 we try again. This way it matches the console behaviour and allows us to share more code. --- sys/gdb/gdb_packet.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'sys/gdb/gdb_packet.c') diff --git a/sys/gdb/gdb_packet.c b/sys/gdb/gdb_packet.c index a4bbe24..753c9b7 100644 --- a/sys/gdb/gdb_packet.c +++ b/sys/gdb/gdb_packet.c @@ -48,6 +48,21 @@ char *gdb_txp = NULL; /* Used in inline functions. */ #define N2C(n) (((n) < 10) ? (n) + '0' : (n) + 'a' - 10) /* + * Get a single character + */ + +static int +gdb_getc(void) +{ + int c; + + do + c = gdb_cur->gdb_getc(); + while (c == -1); + return (c); +} + +/* * Functions to receive and extract from a packet. */ @@ -62,14 +77,14 @@ gdb_rx_begin(void) * Wait for the start character, ignore all others. * XXX needs a timeout. */ - while ((c = gdb_cur->gdb_getc()) != '$') + while ((c = gdb_getc()) != '$') ; /* Read until a # or end of buffer is found. */ cksum = 0; gdb_rxsz = 0; while (gdb_rxsz < sizeof(gdb_rxbuf) - 1) { - c = gdb_cur->gdb_getc(); + c = gdb_getc(); if (c == '#') break; gdb_rxbuf[gdb_rxsz++] = c; @@ -84,9 +99,9 @@ gdb_rx_begin(void) return (ENOSPC); } - c = gdb_cur->gdb_getc(); + c = gdb_getc(); cksum -= (C2N(c) << 4) & 0xf0; - c = gdb_cur->gdb_getc(); + c = gdb_getc(); cksum -= C2N(c) & 0x0f; gdb_cur->gdb_putc((cksum == 0) ? '+' : '-'); if (cksum != 0) @@ -245,7 +260,7 @@ gdb_tx_end(void) c = cksum & 0x0f; gdb_cur->gdb_putc(N2C(c)); - c = gdb_cur->gdb_getc(); + c = gdb_getc(); } while (c != '+'); return (0); -- cgit v1.1