[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 24/41] gdbstub: modernise DEBUG_GDB
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 24/41] gdbstub: modernise DEBUG_GDB |
Date: |
Thu, 13 Jul 2017 16:24:17 +0200 |
From: Alex Bennée <address@hidden>
Convert the a gdb_debug helper which compiles away to nothing when not
used but still ensures the format strings are checked. There is some
minor code motion for the incorrect checksum message to report it
before we attempt to send the reply.
Signed-off-by: Alex Bennée <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Greg Kurz <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
gdbstub.c | 77 +++++++++++++++++++++++++++------------------------------------
1 file changed, 33 insertions(+), 44 deletions(-)
diff --git a/gdbstub.c b/gdbstub.c
index e561244..3965980 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -272,7 +272,20 @@ static int gdb_signal_to_target (int sig)
return -1;
}
-//#define DEBUG_GDB
+/* #define DEBUG_GDB */
+
+#ifdef DEBUG_GDB
+# define DEBUG_GDB_GATE 1
+#else
+# define DEBUG_GDB_GATE 0
+#endif
+
+#define gdb_debug(fmt, ...) do { \
+ if (DEBUG_GDB_GATE) { \
+ fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); \
+ } \
+} while (0)
+
typedef struct GDBRegisterState {
int base_reg;
@@ -548,9 +561,7 @@ static int put_packet_binary(GDBState *s, const char *buf,
int len)
/* return -1 if error, 0 if OK */
static int put_packet(GDBState *s, const char *buf)
{
-#ifdef DEBUG_GDB
- printf("reply='%s'\n", buf);
-#endif
+ gdb_debug("reply='%s'\n", buf);
return put_packet_binary(s, buf, strlen(buf));
}
@@ -956,9 +967,9 @@ static int gdb_handle_packet(GDBState *s, const char
*line_buf)
uint8_t *registers;
target_ulong addr, len;
-#ifdef DEBUG_GDB
- printf("command='%s'\n", line_buf);
-#endif
+
+ gdb_debug("command='%s'\n", line_buf);
+
p = line_buf;
ch = *p++;
switch(ch) {
@@ -1519,17 +1530,14 @@ static void gdb_read_byte(GDBState *s, int ch)
/* Waiting for a response to the last packet. If we see the start
of a new command then abandon the previous response. */
if (ch == '-') {
-#ifdef DEBUG_GDB
- printf("Got NACK, retransmitting\n");
-#endif
+ gdb_debug("Got NACK, retransmitting\n");
put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len);
+ } else if (ch == '+') {
+ gdb_debug("Got ACK\n");
+ } else {
+ gdb_debug("Got '%c' when expecting ACK/NACK\n", ch);
}
-#ifdef DEBUG_GDB
- else if (ch == '+')
- printf("Got ACK\n");
- else
- printf("Got '%c' when expecting ACK/NACK\n", ch);
-#endif
+
if (ch == '+' || ch == '$')
s->last_packet_len = 0;
if (ch != '$')
@@ -1550,9 +1558,7 @@ static void gdb_read_byte(GDBState *s, int ch)
s->line_sum = 0;
s->state = RS_GETLINE;
} else {
-#ifdef DEBUG_GDB
- printf("gdbstub received garbage between packets: 0x%x\n", ch);
-#endif
+ gdb_debug("received garbage between packets: 0x%x\n", ch);
}
break;
case RS_GETLINE:
@@ -1568,9 +1574,7 @@ static void gdb_read_byte(GDBState *s, int ch)
/* end of command, start of checksum*/
s->state = RS_CHKSUM1;
} else if (s->line_buf_index >= sizeof(s->line_buf) - 1) {
-#ifdef DEBUG_GDB
- printf("gdbstub command buffer overrun, dropping command\n");
-#endif
+ gdb_debug("command buffer overrun, dropping command\n");
s->state = RS_IDLE;
} else {
/* unescaped command character */
@@ -1584,9 +1588,7 @@ static void gdb_read_byte(GDBState *s, int ch)
s->state = RS_CHKSUM1;
} else if (s->line_buf_index >= sizeof(s->line_buf) - 1) {
/* command buffer overrun */
-#ifdef DEBUG_GDB
- printf("gdbstub command buffer overrun, dropping command\n");
-#endif
+ gdb_debug("command buffer overrun, dropping command\n");
s->state = RS_IDLE;
} else {
/* parse escaped character and leave escape state */
@@ -1598,25 +1600,18 @@ static void gdb_read_byte(GDBState *s, int ch)
case RS_GETLINE_RLE:
if (ch < ' ') {
/* invalid RLE count encoding */
-#ifdef DEBUG_GDB
- printf("gdbstub got invalid RLE count: 0x%x\n", ch);
-#endif
+ gdb_debug("got invalid RLE count: 0x%x\n", ch);
s->state = RS_GETLINE;
} else {
/* decode repeat length */
int repeat = (unsigned char)ch - ' ' + 3;
if (s->line_buf_index + repeat >= sizeof(s->line_buf) - 1) {
/* that many repeats would overrun the command buffer */
-#ifdef DEBUG_GDB
- printf("gdbstub command buffer overrun,"
- " dropping command\n");
-#endif
+ gdb_debug("command buffer overrun, dropping command\n");
s->state = RS_IDLE;
} else if (s->line_buf_index < 1) {
/* got a repeat but we have nothing to repeat */
-#ifdef DEBUG_GDB
- printf("gdbstub got invalid RLE sequence\n");
-#endif
+ gdb_debug("got invalid RLE sequence\n");
s->state = RS_GETLINE;
} else {
/* repeat the last character */
@@ -1631,9 +1626,7 @@ static void gdb_read_byte(GDBState *s, int ch)
case RS_CHKSUM1:
/* get high hex digit of checksum */
if (!isxdigit(ch)) {
-#ifdef DEBUG_GDB
- printf("gdbstub got invalid command checksum digit\n");
-#endif
+ gdb_debug("got invalid command checksum digit\n");
s->state = RS_GETLINE;
break;
}
@@ -1644,21 +1637,17 @@ static void gdb_read_byte(GDBState *s, int ch)
case RS_CHKSUM2:
/* get low hex digit of checksum */
if (!isxdigit(ch)) {
-#ifdef DEBUG_GDB
- printf("gdbstub got invalid command checksum digit\n");
-#endif
+ gdb_debug("got invalid command checksum digit\n");
s->state = RS_GETLINE;
break;
}
s->line_csum |= fromhex(ch);
if (s->line_csum != (s->line_sum & 0xff)) {
+ gdb_debug("got command packet with incorrect checksum\n");
/* send NAK reply */
reply = '-';
put_buffer(s, &reply, 1);
-#ifdef DEBUG_GDB
- printf("gdbstub got command packet with incorrect checksum\n");
-#endif
s->state = RS_IDLE;
} else {
/* send ACK reply */
--
1.8.3.1
- [Qemu-devel] [PULL 28/41] chardev: fix parallel device can't be reconnect, (continued)
- [Qemu-devel] [PULL 28/41] chardev: fix parallel device can't be reconnect, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 34/41] nbd: Simplify trace of client flags in negotiation, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 35/41] nbd: Refactor reply to NBD_OPT_EXPORT_NAME, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 36/41] nbd: Implement NBD_OPT_GO on server, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 41/41] translate-all: remove redundant !tcg_enabled check in dump_exec_info, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 09/41] char: add backend hotswap handler, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 11/41] char: forbid direct chardevice access for hotswap devices, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 18/41] virtio-console: chardev hotswap support, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 20/41] serial: chardev hotswap support, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 22/41] Revert "exec.c: Fix breakpoint invalidation race", Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 24/41] gdbstub: modernise DEBUG_GDB,
Paolo Bonzini <=
- [Qemu-devel] [PULL 26/41] qom/cpu: remove host_tid field, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 29/41] memory/iommu: QOM'fy IOMMU MemoryRegion, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 30/41] memory/iommu: introduce IOMMUMemoryRegionClass, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 31/41] nbd: Create struct for tracking export info, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 32/41] nbd: Don't bother tracing an NBD_OPT_ABORT response failure, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 33/41] nbd: Expose and debug more NBD constants, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 39/41] nbd: Implement NBD_INFO_BLOCK_SIZE on client, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 38/41] nbd: Implement NBD_INFO_BLOCK_SIZE on server, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 37/41] nbd: Implement NBD_OPT_GO on client, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 40/41] vl: fix breakage of -tb-size, Paolo Bonzini, 2017/07/13