- NMAKE (MSVC toolkit 2003) doesn't like structure type and member having the
[bochs-mirror.git] / gdbstub.cc
blobd73360dbc2a85812686a52cb9b64f7e2761bf078
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: gdbstub.cc,v 1.33 2008/08/16 12:29:30 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2002-2006 The Bochs Project Team
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/types.h>
24 #ifdef __MINGW32__
25 #include <winsock2.h>
26 #define SIGTRAP 5
27 #else
28 #include <sys/socket.h>
29 #include <netinet/in.h>
30 #include <netinet/tcp.h>
31 #include <arpa/inet.h>
32 #include <signal.h>
33 #include <netdb.h>
34 #endif
36 #define NEED_CPU_REG_SHORTCUTS 1
38 #include "bochs.h"
39 #include "cpu/cpu.h"
40 #include "iodev/iodev.h"
42 #define LOG_THIS gdbstublog->
43 #define IFDBG(x) x
45 static int last_stop_reason = GDBSTUB_STOP_NO_REASON;
47 #define GDBSTUB_EXECUTION_BREAKPOINT (0xac1)
48 #define GDBSTUB_TRACE (0xac2)
49 #define GDBSTUB_USER_BREAK (0xac3)
51 static bx_list_c *gdbstub_list;
52 static int listen_socket_fd;
53 static int socket_fd;
54 static logfunctions *gdbstublog;
56 static int hex(char ch)
58 if ((ch >= 'a') && (ch <= 'f')) return(ch - 'a' + 10);
59 if ((ch >= '0') && (ch <= '9')) return(ch - '0');
60 if ((ch >= 'A') && (ch <= 'F')) return(ch - 'A' + 10);
61 return(-1);
64 static char buf[4096], *bufptr = buf;
66 static void flush_debug_buffer()
68 char *p = buf;
69 while (p != bufptr) {
70 int n = send(socket_fd, p, bufptr-p, 0);
71 if (n == -1) {
72 BX_ERROR(("error on debug socket: %m"));
73 break;
75 p += n;
77 bufptr = buf;
80 static void put_debug_char(char ch)
82 if (bufptr == buf + sizeof buf)
83 flush_debug_buffer();
84 *bufptr++ = ch;
87 static char get_debug_char(void)
89 char ch;
91 recv(socket_fd, &ch, 1, 0);
93 return(ch);
96 static const char hexchars[]="0123456789abcdef";
98 static void put_reply(char* buffer)
100 unsigned char csum;
101 int i;
103 BX_DEBUG(("put_buffer '%s'", buffer));
105 do {
106 put_debug_char('$');
108 csum = 0;
110 i = 0;
111 while (buffer[i] != 0)
113 put_debug_char(buffer[i]);
114 csum = csum + buffer[i];
115 i++;
118 put_debug_char('#');
119 put_debug_char(hexchars[csum >> 4]);
120 put_debug_char(hexchars[csum % 16]);
121 flush_debug_buffer();
122 } while (get_debug_char() != '+');
125 static void get_command(char* buffer)
127 unsigned char checksum;
128 unsigned char xmitcsum;
129 char ch;
130 unsigned int count;
131 unsigned int i;
133 do {
134 while ((ch = get_debug_char()) != '$');
136 checksum = 0;
137 xmitcsum = 0;
138 count = 0;
140 while (1)
142 ch = get_debug_char();
143 if (ch == '#') break;
144 checksum = checksum + ch;
145 buffer[count] = ch;
146 count++;
148 buffer[count] = 0;
150 if (ch == '#')
152 xmitcsum = hex(get_debug_char()) << 4;
153 xmitcsum += hex(get_debug_char());
154 if (checksum != xmitcsum)
156 BX_INFO(("Bad checksum"));
160 if (checksum != xmitcsum)
162 put_debug_char('-');
163 flush_debug_buffer();
165 else
167 put_debug_char('+');
168 if (buffer[2] == ':')
170 put_debug_char(buffer[0]);
171 put_debug_char(buffer[1]);
172 count = strlen(buffer);
173 for (i = 3; i <= count; i++)
175 buffer[i - 3] = buffer[i];
178 flush_debug_buffer();
180 } while (checksum != xmitcsum);
183 void hex2mem(char* buf, unsigned char* mem, int count)
185 unsigned char ch;
187 for (int i = 0; i<count; i++)
189 ch = hex(*buf++) << 4;
190 ch = ch + hex(*buf++);
191 *mem++ = ch;
195 char* mem2hex(char* mem, char* buf, int count)
197 unsigned char ch;
199 for (int i = 0; i<count; i++)
201 ch = *mem++;
202 *buf++ = hexchars[ch >> 4];
203 *buf++ = hexchars[ch % 16];
205 *buf = 0;
206 return(buf);
209 int hexdigit(char c)
211 if (isdigit(c))
212 return c - '0';
213 else if (isupper(c))
214 return c - 'A' + 10;
215 else
216 return c - 'a' + 10;
219 Bit64u read_little_endian_hex(char *&buf)
221 int byte;
222 Bit64u ret = 0;
223 int n = 0;
224 while (isxdigit(*buf)) {
225 byte = hexdigit(*buf++);
226 if (isxdigit(*buf))
227 byte = (byte << 4) | hexdigit(*buf++);
228 ret |= (unsigned long long)byte << (n*8);
229 ++n;
231 return ret;
234 static int continue_thread = -1;
235 static int other_thread = 0;
237 #if !BX_SUPPORT_X86_64
238 #define NUMREGS (16)
239 #define NUMREGSBYTES (NUMREGS * 4)
240 static int registers[NUMREGS];
241 #endif
243 #define MAX_BREAKPOINTS (255)
244 static unsigned int breakpoints[MAX_BREAKPOINTS] = {0,};
245 static unsigned int nr_breakpoints = 0;
247 static int stub_trace_flag = 0;
248 static int instr_count = 0;
249 static int saved_eip = 0;
250 static int bx_enter_gdbstub = 0;
252 void bx_gdbstub_break(void)
254 bx_enter_gdbstub = 1;
257 int bx_gdbstub_check(unsigned int eip)
259 unsigned int i;
260 unsigned char ch;
261 long arg;
262 int r;
263 #if defined(__CYGWIN__) || defined(__MINGW32__)
264 fd_set fds;
265 struct timeval tv = {0, 0};
266 #endif
268 if (bx_enter_gdbstub)
270 bx_enter_gdbstub = 0;
271 last_stop_reason = GDBSTUB_EXECUTION_BREAKPOINT;
272 return GDBSTUB_EXECUTION_BREAKPOINT;
275 instr_count++;
277 if ((instr_count % 500) == 0)
279 #if !defined(__CYGWIN__) && !defined(__MINGW32__)
280 arg = fcntl(socket_fd, F_GETFL);
281 fcntl(socket_fd, F_SETFL, arg | O_NONBLOCK);
282 r = recv(socket_fd, &ch, 1, 0);
283 fcntl(socket_fd, F_SETFL, arg);
284 #else
285 FD_ZERO(&fds);
286 FD_SET(socket_fd, &fds);
287 r = select(socket_fd + 1, &fds, NULL, NULL, &tv);
288 if (r == 1)
290 r = recv(socket_fd, (char *)&ch, 1, 0);
292 #endif
293 if (r == 1)
295 BX_INFO(("Got byte %x", (unsigned int)ch));
296 last_stop_reason = GDBSTUB_USER_BREAK;
297 return GDBSTUB_USER_BREAK;
301 for (i = 0; i < nr_breakpoints; i++)
303 if (eip == breakpoints[i])
305 BX_INFO(("found breakpoint at %x", eip));
306 last_stop_reason = GDBSTUB_EXECUTION_BREAKPOINT;
307 return GDBSTUB_EXECUTION_BREAKPOINT;
311 if (stub_trace_flag == 1)
313 last_stop_reason = GDBSTUB_TRACE;
314 return GDBSTUB_TRACE;
316 last_stop_reason = GDBSTUB_STOP_NO_REASON;
317 return GDBSTUB_STOP_NO_REASON;
320 static int remove_breakpoint(unsigned int addr, int len)
322 unsigned int i;
324 if (len != 1)
326 return(0);
329 for (i = 0; i < MAX_BREAKPOINTS; i++)
331 if (breakpoints[i] == addr)
333 BX_INFO(("Removing breakpoint at %x", addr));
334 breakpoints[i] = 0;
335 return(1);
338 return(0);
341 static void insert_breakpoint(unsigned int addr)
343 unsigned int i;
345 BX_INFO(("setting breakpoint at %x", addr));
347 for (i = 0; i < (unsigned)MAX_BREAKPOINTS; i++)
349 if (breakpoints[i] == 0)
351 breakpoints[i] = addr;
352 if (i >= nr_breakpoints)
354 nr_breakpoints = i + 1;
356 return;
359 BX_INFO(("No slot for breakpoint"));
362 static void do_pc_breakpoint(int insert, unsigned long long addr, int len)
364 for (int i = 0; i < len; ++i)
365 if (insert)
366 insert_breakpoint(addr+i);
367 else
368 remove_breakpoint(addr+i, 1);
371 static void do_breakpoint(int insert, char* buffer)
373 char* ebuf;
374 unsigned long type = strtoul(buffer, &ebuf, 16);
375 unsigned long long addr = strtoull(ebuf+1, &ebuf, 16);
376 unsigned long len = strtoul(ebuf+1, &ebuf, 16);
377 switch (type) {
378 case 0:
379 case 1:
380 do_pc_breakpoint(insert, addr, len);
381 put_reply("OK");
382 break;
383 default:
384 put_reply("");
385 break;
389 static void write_signal(char* buf, int signal)
391 buf[0] = hexchars[signal >> 4];
392 buf[1] = hexchars[signal % 16];
393 buf[2] = 0;
396 static int access_linear(Bit64u laddress,
397 unsigned len,
398 unsigned int rw,
399 Bit8u* data)
401 bx_phy_address phys;
402 bx_bool valid;
404 if (((laddress & 0xfff) + len) > 4096)
406 valid = access_linear(laddress,
407 4096 - (laddress & 0xfff),
409 data);
410 if (!valid) return(0);
412 valid = access_linear(laddress,
413 len + (laddress & 0xfff) - 4096,
415 (Bit8u *)((unsigned long)data +
416 4096 - (laddress & 0xfff)));
417 return(valid);
420 valid = BX_CPU(0)->dbg_xlate_linear2phy(laddress, (bx_phy_address*)&phys);
421 if (!valid) return(0);
423 if (rw == BX_READ) {
424 valid = BX_MEM(0)->dbg_fetch_mem(BX_CPU(0), phys, len, data);
425 } else {
426 valid = BX_MEM(0)->dbg_set_mem(phys, len, data);
429 return(valid);
432 static void debug_loop(void)
434 char buffer[255];
435 char obuf[255];
436 int ne = 0;
437 unsigned char mem[255];
439 while (ne == 0)
441 get_command(buffer);
442 BX_DEBUG(("get_buffer '%s'", buffer));
444 switch (buffer[0])
446 case 'c':
448 char buf[255];
449 Bit32u new_eip;
451 if (buffer[1] != 0)
453 new_eip = (Bit32u) atoi(buffer + 1);
455 BX_INFO(("continuing at %x", new_eip));
457 for (int i=0; i<BX_SMP_PROCESSORS; i++) {
458 BX_CPU(i)->invalidate_prefetch_q();
461 saved_eip = EIP;
462 BX_CPU_THIS_PTR gen_reg[BX_32BIT_REG_EIP].dword.erx = new_eip;
465 stub_trace_flag = 0;
466 bx_cpu.cpu_loop(0);
468 DEV_vga_refresh();
470 if (buffer[1] != 0)
472 bx_cpu.invalidate_prefetch_q();
473 BX_CPU_THIS_PTR gen_reg[BX_32BIT_REG_EIP].dword.erx = saved_eip;
476 BX_INFO(("stopped with %x", last_stop_reason));
477 buf[0] = 'S';
478 if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT ||
479 last_stop_reason == GDBSTUB_TRACE)
481 write_signal(&buf[1], SIGTRAP);
483 else
485 write_signal(&buf[1], 0);
487 put_reply(buf);
488 break;
491 case 's':
493 char buf[255];
495 BX_INFO(("stepping"));
496 stub_trace_flag = 1;
497 bx_cpu.cpu_loop(0);
498 DEV_vga_refresh();
499 stub_trace_flag = 0;
500 BX_INFO(("stopped with %x", last_stop_reason));
501 buf[0] = 'S';
502 if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT ||
503 last_stop_reason == GDBSTUB_TRACE)
505 write_signal(&buf[1], SIGTRAP);
507 else
509 write_signal(&buf[1], SIGTRAP);
511 put_reply(buf);
512 break;
515 case 'M':
517 Bit64u addr;
518 int len;
519 unsigned char mem[255];
520 char* ebuf;
522 addr = strtoull(&buffer[1], &ebuf, 16);
523 len = strtoul(ebuf + 1, &ebuf, 16);
524 hex2mem(ebuf + 1, mem, len);
526 if (len == 1 && mem[0] == 0xcc)
528 insert_breakpoint(addr);
529 put_reply("OK");
531 else if (remove_breakpoint(addr, len))
533 put_reply("OK");
535 else
537 if (access_linear(addr, len, BX_WRITE, mem))
539 put_reply("OK");
541 else
543 put_reply("Eff");
546 break;
549 case 'm':
551 Bit64u addr;
552 int len;
553 char* ebuf;
555 addr = strtoull(&buffer[1], &ebuf, 16);
556 len = strtoul(ebuf + 1, NULL, 16);
557 BX_INFO(("addr %Lx len %x", addr, len));
559 access_linear(addr, len, BX_READ, mem);
560 mem2hex((char *)mem, obuf, len);
561 put_reply(obuf);
562 break;
565 case 'P':
567 int reg;
568 unsigned long long value;
569 char* ebuf;
571 reg = strtoul(&buffer[1], &ebuf, 16);
572 ++ebuf;
573 value = read_little_endian_hex(ebuf);
575 BX_INFO(("reg %d set to %Lx", reg, value));
576 #if !BX_SUPPORT_X86_64
577 switch (reg)
579 case 1:
580 EAX = value;
581 break;
583 case 2:
584 ECX = value;
585 break;
587 case 3:
588 EBX = value;
589 break;
591 case 4:
592 ESP = value;
593 break;
595 case 5:
596 EBP = value;
597 break;
599 case 6:
600 ESI = value;
601 break;
603 case 7:
604 EDI = value;
605 break;
607 case 8:
608 EIP = value;
609 BX_CPU_THIS_PTR invalidate_prefetch_q();
610 break;
612 default:
613 break;
615 #else
616 switch (reg)
618 case 0:
619 RAX = value;
620 break;
622 case 1:
623 RBX = value;
624 break;
626 case 2:
627 RCX = value;
628 break;
630 case 3:
631 RDX = value;
632 break;
634 case 4:
635 RSI = value;
636 break;
638 case 5:
639 RDI = value;
640 break;
642 case 6:
643 ESP = value;
644 break;
646 case 7:
647 RBP = value;
648 break;
650 case 8:
651 R8 = value;
652 break;
654 case 9:
655 R9 = value;
656 break;
658 case 10:
659 R10 = value;
660 break;
662 case 11:
663 R11 = value;
664 break;
666 case 12:
667 R12 = value;
668 break;
670 case 13:
671 R13 = value;
672 break;
674 case 14:
675 R15 = value;
676 break;
678 case 15:
679 R15 = value;
680 break;
682 case 16:
683 RIP = value;
684 BX_CPU_THIS_PTR invalidate_prefetch_q();
685 break;
687 default:
688 break;
690 #endif
691 put_reply("OK");
693 break;
696 case 'g':
697 #if !BX_SUPPORT_X86_64
698 registers[0] = EAX;
699 registers[1] = ECX;
700 registers[2] = EDX;
701 registers[3] = EBX;
702 registers[4] = ESP;
703 registers[5] = EBP;
704 registers[6] = ESI;
705 registers[7] = EDI;
706 if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT)
708 registers[8] = EIP + 1;
710 else
712 registers[8] = EIP;
714 registers[9] = BX_CPU_THIS_PTR read_eflags();
715 registers[10] =
716 BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value;
717 registers[11] =
718 BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value;
719 registers[12] =
720 BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value;
721 registers[13] =
722 BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value;
723 registers[14] =
724 BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value;
725 registers[15] =
726 BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value;
727 mem2hex((char *)registers, obuf, NUMREGSBYTES);
728 #else
729 #define PUTREG(buf, val, len) do { \
730 Bit64u u = (val); \
731 (buf) = mem2hex((char*)&u, (buf), (len)); \
732 } while (0)
733 char* buf;
734 buf = obuf;
735 PUTREG(buf, RAX, 8);
736 PUTREG(buf, RBX, 8);
737 PUTREG(buf, RCX, 8);
738 PUTREG(buf, RDX, 8);
739 PUTREG(buf, RSI, 8);
740 PUTREG(buf, RDI, 8);
741 PUTREG(buf, RBP, 8);
742 PUTREG(buf, RSP, 8);
743 PUTREG(buf, R8, 8);
744 PUTREG(buf, R9, 8);
745 PUTREG(buf, R10, 8);
746 PUTREG(buf, R11, 8);
747 PUTREG(buf, R12, 8);
748 PUTREG(buf, R13, 8);
749 PUTREG(buf, R14, 8);
750 PUTREG(buf, R15, 8);
751 Bit64u rip;
752 rip = RIP;
753 if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT)
755 ++rip;
757 PUTREG(buf, rip, 8);
758 PUTREG(buf, BX_CPU_THIS_PTR read_eflags(), 4);
759 PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value, 4);
760 PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value, 4);
761 PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value, 4);
762 PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value, 4);
763 PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value, 4);
764 PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value, 4);
765 #endif
766 put_reply(obuf);
767 break;
769 case '?':
770 sprintf(obuf, "S%02x", SIGTRAP);
771 put_reply(obuf);
772 break;
774 case 'H':
775 if (buffer[1] == 'c')
777 continue_thread = strtol(&buffer[2], NULL, 16);
778 put_reply("OK");
780 else if (buffer[1] == 'g')
782 other_thread = strtol(&buffer[2], NULL, 16);
783 put_reply("OK");
785 else
787 put_reply("Eff");
789 break;
791 case 'q':
792 if (buffer[1] == 'C')
794 sprintf(obuf,"%Lx", (Bit64u)1);
795 put_reply(obuf);
797 else if (strncmp(&buffer[1], "Offsets", strlen("Offsets")) == 0)
799 sprintf(obuf, "Text=%x;Data=%x;Bss=%x",
800 SIM->get_param_num("text_base", gdbstub_list)->get(),
801 SIM->get_param_num("data_base", gdbstub_list)->get(),
802 SIM->get_param_num("bss_base", gdbstub_list)->get());
803 put_reply(obuf);
805 else if (strncmp(&buffer[1], "Supported", strlen("Supported")) == 0)
807 put_reply("");
809 else
811 put_reply("Eff");
813 break;
815 case 'Z':
816 do_breakpoint(1, buffer+1);
817 break;
818 case 'z':
819 do_breakpoint(0, buffer+1);
820 break;
821 case 'k':
822 BX_PANIC(("Debugger asked us to quit"));
823 break;
825 default:
826 put_reply("");
827 break;
832 static void wait_for_connect(int portn)
834 struct sockaddr_in sockaddr;
835 socklen_t sockaddr_len;
836 struct protoent *protoent;
837 int r;
838 int opt;
840 listen_socket_fd = socket(PF_INET, SOCK_STREAM, 0);
841 if (listen_socket_fd == -1)
843 BX_PANIC(("Failed to create socket"));
844 exit(1);
847 /* Allow rapid reuse of this port */
848 opt = 1;
849 #if __MINGW32__
850 r = setsockopt(listen_socket_fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(opt));
851 #else
852 r = setsockopt(listen_socket_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
853 #endif
854 if (r == -1)
856 BX_INFO(("setsockopt(SO_REUSEADDR) failed"));
859 memset (&sockaddr, '\000', sizeof sockaddr);
860 #if BX_HAVE_SOCKADDR_IN_SIN_LEN
861 // if you don't have sin_len change that to #if 0. This is the subject of
862 // bug [ 626840 ] no 'sin_len' in 'struct sockaddr_in'.
863 sockaddr.sin_len = sizeof sockaddr;
864 #endif
865 sockaddr.sin_family = AF_INET;
866 sockaddr.sin_port = htons(portn);
867 sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
869 r = bind(listen_socket_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
870 if (r == -1)
872 BX_PANIC(("Failed to bind socket"));
875 r = listen(listen_socket_fd, 0);
876 if (r == -1)
878 BX_PANIC(("Failed to listen on socket"));
881 sockaddr_len = sizeof sockaddr;
882 socket_fd = accept(listen_socket_fd, (struct sockaddr *)&sockaddr, &sockaddr_len);
883 if (socket_fd == -1)
885 BX_PANIC(("Failed to accept on socket"));
887 close(listen_socket_fd);
889 protoent = getprotobyname ("tcp");
890 if (!protoent)
892 BX_INFO(("getprotobyname (\"tcp\") failed"));
893 return;
896 /* Disable Nagle - allow small packets to be sent without delay. */
897 opt = 1;
898 #ifdef __MINGW32__
899 r = setsockopt (socket_fd, protoent->p_proto, TCP_NODELAY, (const char *)&opt, sizeof(opt));
900 #else
901 r = setsockopt (socket_fd, protoent->p_proto, TCP_NODELAY, &opt, sizeof(opt));
902 #endif
903 if (r == -1)
905 BX_INFO(("setsockopt(TCP_NODELAY) failed"));
907 Bit32u ip = sockaddr.sin_addr.s_addr;
908 printf("Connected to %d.%d.%d.%d\n", ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & 0xff, (ip >> 24) & 0xff);
911 void bx_gdbstub_init(void)
913 gdbstublog = new logfunctions();
914 gdbstublog->put("GDBST");
915 gdbstublog->setonoff(LOGLEV_PANIC, ACT_FATAL);
917 gdbstub_list = (bx_list_c*) SIM->get_param(BXPN_GDBSTUB);
918 int portn = SIM->get_param_num("port", gdbstub_list)->get();
920 #ifdef __MINGW32__
921 WSADATA wsaData;
922 WSAStartup(2, &wsaData);
923 #endif
925 /* Wait for connect */
926 printf("Waiting for gdb connection on port %d\n", portn);
927 wait_for_connect(portn);
929 /* Do debugger command loop */
930 debug_loop();
932 /* CPU loop */
933 bx_cpu.cpu_loop(0);