Commit c636bb66cc9043032caf20cb067bf9c818b7d17e

Authored by bellard
1 parent 84f2e8ef

gdbserver fix


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2393 c046a42c-6fe2-441c-8c8c-71466251a162
gdbstub.c
@@ -1234,4 +1234,18 @@ int gdbserver_start(CharDriverState *chr) @@ -1234,4 +1234,18 @@ int gdbserver_start(CharDriverState *chr)
1234 qemu_add_vm_stop_handler(gdb_vm_stopped, s); 1234 qemu_add_vm_stop_handler(gdb_vm_stopped, s);
1235 return 0; 1235 return 0;
1236 } 1236 }
  1237 +
  1238 +int gdbserver_start_port(int port)
  1239 +{
  1240 + CharDriverState *chr;
  1241 + char gdbstub_port_name[128];
  1242 +
  1243 + snprintf(gdbstub_port_name, sizeof(gdbstub_port_name),
  1244 + "tcp::%d,nowait,nodelay,server", port);
  1245 + chr = qemu_chr_open(gdbstub_port_name);
  1246 + if (!chr)
  1247 + return -EIO;
  1248 + return gdbserver_start(chr);
  1249 +}
  1250 +
1237 #endif 1251 #endif
gdbstub.h
@@ -14,6 +14,7 @@ void gdb_exit(CPUState *, int); @@ -14,6 +14,7 @@ void gdb_exit(CPUState *, int);
14 int gdbserver_start(int); 14 int gdbserver_start(int);
15 #else 15 #else
16 int gdbserver_start(CharDriverState *chr); 16 int gdbserver_start(CharDriverState *chr);
  17 +int gdbserver_start_port(int port);
17 #endif 18 #endif
18 19
19 #endif 20 #endif
monitor.c
@@ -423,7 +423,7 @@ static void do_gdbserver(int has_port, int port) @@ -423,7 +423,7 @@ static void do_gdbserver(int has_port, int port)
423 { 423 {
424 if (!has_port) 424 if (!has_port)
425 port = DEFAULT_GDBSTUB_PORT; 425 port = DEFAULT_GDBSTUB_PORT;
426 - if (gdbserver_start(port) < 0) { 426 + if (gdbserver_start_port(port) < 0) {
427 qemu_printf("Could not open gdbserver socket on port %d\n", port); 427 qemu_printf("Could not open gdbserver socket on port %d\n", port);
428 } else { 428 } else {
429 qemu_printf("Waiting gdb connection on port %d\n", port); 429 qemu_printf("Waiting gdb connection on port %d\n", port);
@@ -6499,8 +6499,7 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type) @@ -6499,8 +6499,7 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
6499 int main(int argc, char **argv) 6499 int main(int argc, char **argv)
6500 { 6500 {
6501 #ifdef CONFIG_GDBSTUB 6501 #ifdef CONFIG_GDBSTUB
6502 - int use_gdbstub;  
6503 - char gdbstub_port_name[128]; 6502 + int use_gdbstub, gdbstub_port;
6504 #endif 6503 #endif
6505 int i, cdrom_index; 6504 int i, cdrom_index;
6506 int snapshot, linux_boot; 6505 int snapshot, linux_boot;
@@ -6568,7 +6567,7 @@ int main(int argc, char **argv) @@ -6568,7 +6567,7 @@ int main(int argc, char **argv)
6568 bios_size = BIOS_SIZE; 6567 bios_size = BIOS_SIZE;
6569 #ifdef CONFIG_GDBSTUB 6568 #ifdef CONFIG_GDBSTUB
6570 use_gdbstub = 0; 6569 use_gdbstub = 0;
6571 - sprintf(gdbstub_port_name, "%d", DEFAULT_GDBSTUB_PORT); 6570 + gdbstub_port = DEFAULT_GDBSTUB_PORT;
6572 #endif 6571 #endif
6573 snapshot = 0; 6572 snapshot = 0;
6574 nographic = 0; 6573 nographic = 0;
@@ -6812,7 +6811,7 @@ int main(int argc, char **argv) @@ -6812,7 +6811,7 @@ int main(int argc, char **argv)
6812 use_gdbstub = 1; 6811 use_gdbstub = 1;
6813 break; 6812 break;
6814 case QEMU_OPTION_p: 6813 case QEMU_OPTION_p:
6815 - pstrcpy(gdbstub_port_name, sizeof(gdbstub_port_name), optarg); 6814 + gdbstub_port = atoi(optarg);
6816 break; 6815 break;
6817 #endif 6816 #endif
6818 case QEMU_OPTION_L: 6817 case QEMU_OPTION_L:
@@ -7220,19 +7219,13 @@ int main(int argc, char **argv) @@ -7220,19 +7219,13 @@ int main(int argc, char **argv)
7220 7219
7221 #ifdef CONFIG_GDBSTUB 7220 #ifdef CONFIG_GDBSTUB
7222 if (use_gdbstub) { 7221 if (use_gdbstub) {
7223 - CharDriverState *chr;  
7224 - int port;  
7225 -  
7226 - port = atoi(gdbstub_port_name);  
7227 - if (port != 0)  
7228 - sprintf(gdbstub_port_name, "tcp::%d,nowait,nodelay,server", port);  
7229 - chr = qemu_chr_open(gdbstub_port_name);  
7230 - if (!chr) {  
7231 - fprintf(stderr, "qemu: could not open gdbstub device '%s'\n",  
7232 - gdbstub_port_name); 7222 + /* XXX: use standard host:port notation and modify options
  7223 + accordingly. */
  7224 + if (gdbserver_start_port(gdbstub_port) < 0) {
  7225 + fprintf(stderr, "qemu: could not open gdbstub device on port '%d'\n",
  7226 + gdbstub_port);
7233 exit(1); 7227 exit(1);
7234 } 7228 }
7235 - gdbserver_start(chr);  
7236 } else 7229 } else
7237 #endif 7230 #endif
7238 if (loadvm) 7231 if (loadvm)