Commit cfc3475a8df6d03dfbffa813d7d919eda409c85b
1 parent
7bcc17dc
Allow gdbstub to connect over any serial device.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2448 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
4 changed files
with
32 additions
and
30 deletions
gdbstub.c
| @@ -1216,10 +1216,26 @@ static void gdb_chr_event(void *opaque, int event) | @@ -1216,10 +1216,26 @@ static void gdb_chr_event(void *opaque, int event) | ||
| 1216 | } | 1216 | } |
| 1217 | } | 1217 | } |
| 1218 | 1218 | ||
| 1219 | -int gdbserver_start(CharDriverState *chr) | 1219 | +int gdbserver_start(const char *port) |
| 1220 | { | 1220 | { |
| 1221 | GDBState *s; | 1221 | GDBState *s; |
| 1222 | + char gdbstub_port_name[128]; | ||
| 1223 | + int port_num; | ||
| 1224 | + char *p; | ||
| 1225 | + CharDriverState *chr; | ||
| 1226 | + | ||
| 1227 | + if (!port || !*port) | ||
| 1228 | + return -1; | ||
| 1222 | 1229 | ||
| 1230 | + port_num = strtol(port, &p, 10); | ||
| 1231 | + if (*p == 0) { | ||
| 1232 | + /* A numeric value is interpreted as a port number. */ | ||
| 1233 | + snprintf(gdbstub_port_name, sizeof(gdbstub_port_name), | ||
| 1234 | + "tcp::%d,nowait,nodelay,server", port_num); | ||
| 1235 | + port = gdbstub_port_name; | ||
| 1236 | + } | ||
| 1237 | + | ||
| 1238 | + chr = qemu_chr_open(port); | ||
| 1223 | if (!chr) | 1239 | if (!chr) |
| 1224 | return -1; | 1240 | return -1; |
| 1225 | 1241 | ||
| @@ -1234,18 +1250,4 @@ int gdbserver_start(CharDriverState *chr) | @@ -1234,18 +1250,4 @@ int gdbserver_start(CharDriverState *chr) | ||
| 1234 | qemu_add_vm_stop_handler(gdb_vm_stopped, s); | 1250 | qemu_add_vm_stop_handler(gdb_vm_stopped, s); |
| 1235 | return 0; | 1251 | return 0; |
| 1236 | } | 1252 | } |
| 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 | - | ||
| 1251 | #endif | 1253 | #endif |
gdbstub.h
| 1 | #ifndef GDBSTUB_H | 1 | #ifndef GDBSTUB_H |
| 2 | #define GDBSTUB_H | 2 | #define GDBSTUB_H |
| 3 | 3 | ||
| 4 | -#define DEFAULT_GDBSTUB_PORT 1234 | 4 | +#define DEFAULT_GDBSTUB_PORT "1234" |
| 5 | 5 | ||
| 6 | typedef void (*gdb_syscall_complete_cb)(CPUState *env, | 6 | typedef void (*gdb_syscall_complete_cb)(CPUState *env, |
| 7 | target_ulong ret, target_ulong err); | 7 | target_ulong ret, target_ulong err); |
| @@ -13,8 +13,7 @@ int gdb_handlesig (CPUState *, int); | @@ -13,8 +13,7 @@ int gdb_handlesig (CPUState *, int); | ||
| 13 | void gdb_exit(CPUState *, int); | 13 | 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); | ||
| 17 | -int gdbserver_start_port(int port); | 16 | +int gdbserver_start(const char *port); |
| 18 | #endif | 17 | #endif |
| 19 | 18 | ||
| 20 | #endif | 19 | #endif |
monitor.c
| @@ -423,14 +423,14 @@ static void do_cont(void) | @@ -423,14 +423,14 @@ static void do_cont(void) | ||
| 423 | } | 423 | } |
| 424 | 424 | ||
| 425 | #ifdef CONFIG_GDBSTUB | 425 | #ifdef CONFIG_GDBSTUB |
| 426 | -static void do_gdbserver(int has_port, int port) | 426 | +static void do_gdbserver(const char *port) |
| 427 | { | 427 | { |
| 428 | - if (!has_port) | 428 | + if (!port) |
| 429 | port = DEFAULT_GDBSTUB_PORT; | 429 | port = DEFAULT_GDBSTUB_PORT; |
| 430 | - if (gdbserver_start_port(port) < 0) { | ||
| 431 | - qemu_printf("Could not open gdbserver socket on port %d\n", port); | 430 | + if (gdbserver_start(port) < 0) { |
| 431 | + qemu_printf("Could not open gdbserver socket on port '%s'\n", port); | ||
| 432 | } else { | 432 | } else { |
| 433 | - qemu_printf("Waiting gdb connection on port %d\n", port); | 433 | + qemu_printf("Waiting gdb connection on port '%s'\n", port); |
| 434 | } | 434 | } |
| 435 | } | 435 | } |
| 436 | #endif | 436 | #endif |
| @@ -1216,7 +1216,7 @@ static term_cmd_t term_cmds[] = { | @@ -1216,7 +1216,7 @@ static term_cmd_t term_cmds[] = { | ||
| 1216 | { "c|cont", "", do_cont, | 1216 | { "c|cont", "", do_cont, |
| 1217 | "", "resume emulation", }, | 1217 | "", "resume emulation", }, |
| 1218 | #ifdef CONFIG_GDBSTUB | 1218 | #ifdef CONFIG_GDBSTUB |
| 1219 | - { "gdbserver", "i?", do_gdbserver, | 1219 | + { "gdbserver", "s?", do_gdbserver, |
| 1220 | "[port]", "start gdbserver session (default port=1234)", }, | 1220 | "[port]", "start gdbserver session (default port=1234)", }, |
| 1221 | #endif | 1221 | #endif |
| 1222 | { "x", "/l", do_memory_dump, | 1222 | { "x", "/l", do_memory_dump, |
vl.c
| @@ -6422,8 +6422,8 @@ void help(void) | @@ -6422,8 +6422,8 @@ void help(void) | ||
| 6422 | "-parallel dev redirect the parallel port to char device 'dev'\n" | 6422 | "-parallel dev redirect the parallel port to char device 'dev'\n" |
| 6423 | "-pidfile file Write PID to 'file'\n" | 6423 | "-pidfile file Write PID to 'file'\n" |
| 6424 | "-S freeze CPU at startup (use 'c' to start execution)\n" | 6424 | "-S freeze CPU at startup (use 'c' to start execution)\n" |
| 6425 | - "-s wait gdb connection to port %d\n" | ||
| 6426 | - "-p port change gdb connection port\n" | 6425 | + "-s wait gdb connection to port\n" |
| 6426 | + "-p port set gdb connection port [default=%s]\n" | ||
| 6427 | "-d item1,... output log to %s (use -d ? for a list of log items)\n" | 6427 | "-d item1,... output log to %s (use -d ? for a list of log items)\n" |
| 6428 | "-hdachs c,h,s[,t] force hard disk 0 physical geometry and the optional BIOS\n" | 6428 | "-hdachs c,h,s[,t] force hard disk 0 physical geometry and the optional BIOS\n" |
| 6429 | " translation (t=none or lba) (usually qemu can guess them)\n" | 6429 | " translation (t=none or lba) (usually qemu can guess them)\n" |
| @@ -6829,7 +6829,8 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type) | @@ -6829,7 +6829,8 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type) | ||
| 6829 | int main(int argc, char **argv) | 6829 | int main(int argc, char **argv) |
| 6830 | { | 6830 | { |
| 6831 | #ifdef CONFIG_GDBSTUB | 6831 | #ifdef CONFIG_GDBSTUB |
| 6832 | - int use_gdbstub, gdbstub_port; | 6832 | + int use_gdbstub; |
| 6833 | + const char *gdbstub_port; | ||
| 6833 | #endif | 6834 | #endif |
| 6834 | int i, cdrom_index; | 6835 | int i, cdrom_index; |
| 6835 | int snapshot, linux_boot; | 6836 | int snapshot, linux_boot; |
| @@ -7143,7 +7144,7 @@ int main(int argc, char **argv) | @@ -7143,7 +7144,7 @@ int main(int argc, char **argv) | ||
| 7143 | use_gdbstub = 1; | 7144 | use_gdbstub = 1; |
| 7144 | break; | 7145 | break; |
| 7145 | case QEMU_OPTION_p: | 7146 | case QEMU_OPTION_p: |
| 7146 | - gdbstub_port = atoi(optarg); | 7147 | + gdbstub_port = optarg; |
| 7147 | break; | 7148 | break; |
| 7148 | #endif | 7149 | #endif |
| 7149 | case QEMU_OPTION_L: | 7150 | case QEMU_OPTION_L: |
| @@ -7571,8 +7572,8 @@ int main(int argc, char **argv) | @@ -7571,8 +7572,8 @@ int main(int argc, char **argv) | ||
| 7571 | if (use_gdbstub) { | 7572 | if (use_gdbstub) { |
| 7572 | /* XXX: use standard host:port notation and modify options | 7573 | /* XXX: use standard host:port notation and modify options |
| 7573 | accordingly. */ | 7574 | accordingly. */ |
| 7574 | - if (gdbserver_start_port(gdbstub_port) < 0) { | ||
| 7575 | - fprintf(stderr, "qemu: could not open gdbstub device on port '%d'\n", | 7575 | + if (gdbserver_start(gdbstub_port) < 0) { |
| 7576 | + fprintf(stderr, "qemu: could not open gdbstub device on port '%s'\n", | ||
| 7576 | gdbstub_port); | 7577 | gdbstub_port); |
| 7577 | exit(1); | 7578 | exit(1); |
| 7578 | } | 7579 | } |