+/**
+ * The cool thing about this fn is that it allows buf_p and buf_cnt to be
+ * held in registers in the inner loop.
+ *
+ * For small caches and embedded systems this is important!
+ */
+static inline int gdb_get_char_fast(struct connection *connection, int* next_char, char **buf_p, int *buf_cnt)
+{
+ int retval = ERROR_OK;
+
+ if ((*buf_cnt)-- > 0)
+ {
+ *next_char = **buf_p;
+ (*buf_p)++;
+ if (*buf_cnt > 0)
+ connection->input_pending = 1;
+ else
+ connection->input_pending = 0;
+
+#ifdef _DEBUG_GDB_IO_
+ LOG_DEBUG("returned char '%c' (0x%2.2x)", *next_char, *next_char);
+#endif
+
+ return ERROR_OK;
+ }
+
+ struct gdb_connection *gdb_con = connection->priv;
+ gdb_con->buf_p = *buf_p;
+ gdb_con->buf_cnt = *buf_cnt;
+ retval = gdb_get_char_inner(connection, next_char);
+ *buf_p = gdb_con->buf_p;
+ *buf_cnt = gdb_con->buf_cnt;
+
+ return retval;
+}
+
+
+int gdb_get_char(struct connection *connection, int* next_char)
+{
+ struct gdb_connection *gdb_con = connection->priv;
+ return gdb_get_char_fast(connection, next_char, &gdb_con->buf_p, &gdb_con->buf_cnt);
+}
+
+