#define MAX_PACKET_LENGTH 4096
-#include "cpu.h"
#include "qemu/sockets.h"
#include "sysemu/kvm.h"
#include "exec/semihost.h"
int fd;
int running_state;
#else
- CharDriverState *chr;
+ CharBackend chr;
CharDriverState *mon_chr;
#endif
char syscall_buf[256];
if (ret < 0) {
if (errno == ECONNRESET)
s->fd = -1;
- if (errno != EINTR && errno != EAGAIN)
+ if (errno != EINTR)
return -1;
} else if (ret == 0) {
close(s->fd);
while (len > 0) {
ret = send(s->fd, buf, len, 0);
if (ret < 0) {
- if (errno != EINTR && errno != EAGAIN)
+ if (errno != EINTR)
return;
} else {
buf += ret;
}
}
#else
- qemu_chr_fe_write(s->chr, buf, len);
+ /* XXX this blocks entire thread. Rewrite to use
+ * qemu_chr_fe_write and background I/O callbacks */
+ qemu_chr_fe_write_all(&s->chr, buf, len);
#endif
}
{
GDBState *s;
char buf[4];
+#ifndef CONFIG_USER_ONLY
+ CharDriverState *chr;
+#endif
s = gdbserver_state;
if (!s) {
return;
}
#else
- if (!s->chr) {
+ chr = qemu_chr_fe_get_driver(&s->chr);
+ if (!chr) {
return;
}
#endif
put_packet(s, buf);
#ifndef CONFIG_USER_ONLY
- qemu_chr_delete(s->chr);
+ qemu_chr_fe_deinit(&s->chr);
+ qemu_chr_delete(chr);
#endif
}
#ifdef CONFIG_USER_ONLY
-int
-gdb_queuesig (void)
-{
- GDBState *s;
-
- s = gdbserver_state;
-
- if (gdbserver_fd < 0 || s->fd < 0)
- return 0;
- else
- return 1;
-}
-
int
gdb_handlesig(CPUState *cpu, int sig)
{
for (i = 0; i < n; i++) {
gdb_read_byte(s, buf[i]);
}
- } else if (n == 0 || errno != EAGAIN) {
+ } else {
/* XXX: Connection closed. Should probably wait for another
connection before continuing. */
+ if (n == 0) {
+ close(s->fd);
+ }
+ s->fd = -1;
return sig;
}
}
gdb_has_xml = false;
gdbserver_state = s;
-
- fcntl(fd, F_SETFL, O_NONBLOCK);
}
static int gdbserver_open(int port)
close(fd);
return -1;
}
- ret = listen(fd, 0);
+ ret = listen(fd, 1);
if (ret < 0) {
perror("listen");
close(fd);
sigaction(SIGINT, &act, NULL);
}
#endif
- chr = qemu_chr_new_noreplay("gdb", device, NULL);
+ chr = qemu_chr_new_noreplay("gdb", device);
if (!chr)
return -1;
-
- qemu_chr_fe_claim_no_fail(chr);
- qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive,
- gdb_chr_event, NULL);
}
s = gdbserver_state;
mon_chr->chr_write = gdb_monitor_write;
monitor_init(mon_chr, 0);
} else {
- if (s->chr)
- qemu_chr_delete(s->chr);
+ if (qemu_chr_fe_get_driver(&s->chr)) {
+ qemu_chr_delete(qemu_chr_fe_get_driver(&s->chr));
+ }
mon_chr = s->mon_chr;
memset(s, 0, sizeof(GDBState));
+ s->mon_chr = mon_chr;
}
s->c_cpu = first_cpu;
s->g_cpu = first_cpu;
- s->chr = chr;
+ if (chr) {
+ qemu_chr_fe_init(&s->chr, chr, &error_abort);
+ qemu_chr_fe_set_handlers(&s->chr, gdb_chr_can_receive, gdb_chr_receive,
+ gdb_chr_event, NULL, NULL, true);
+ }
s->state = chr ? RS_IDLE : RS_INACTIVE;
s->mon_chr = mon_chr;
s->current_syscall_cb = NULL;