This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project. See the GDB home page for more information.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
I sent this to bug-gdb, but perhaps this is a better place to send it. -David ---------- Forwarded message ---------- Date: Tue, 4 Aug 1998 12:49:32 -0700 (PDT) From: David Whedon <davidw@gordian.com> To: bug-gdb@prep.ai.mit.edu Subject: Simple Contribution to gdb Gdb Maintainers, I made some small changes to ser-tcp.c that I hope will be incorporated in the next release of gdb. Debugging remotely over the ethernet is a whole lot easier if UDP packets are sent rather than tcp packets since the code on the stub side ends up being simpler. All the changes were made in tcp_open(), in ser-tcp.c. I changed the function so that a UDP socket will be opened if: target remote hostname:port/udp is entered on the command line. Thanks for your time maintaining such a useful tool, David Whedon -------begin modified tcp_open() ------------- /* Open up a raw tcp socket */ static int tcp_open(scb, name) serial_t scb; const char *name; { /* this function has been modified to support UDP between the host and the remote target. UDP is specified by the command: target remote hostname:port/udp */ char *port_str; int port; struct hostent *hostent; struct sockaddr_in sockaddr; int tmp; char hostname[100]; struct protoent *protoent; int i; char protocol[16]; port_str = strchr (name, ':'); if (!port_str) error ("tcp_open: No colon in host name!"); /* Shouldn't ever happen */ tmp = min (port_str - name, (int) sizeof hostname - 1); strncpy (hostname, name, tmp); /* Don't want colon */ hostname[tmp] = '\000'; /* Tie off host name */ port = atoi (port_str + 1); if(strchr (name, '/')!= NULL){ strncpy(protocol , strchr (name, '/')+1, sizeof(protocol)); if( strncmp(protocol, "udp", sizeof("udp") )){ error("tcp_open: unknown protocol"); } } else strcpy(protocol, "tcp"); hostent = gethostbyname (hostname); if (!hostent) { fprintf_unfiltered (gdb_stderr, "%s: unknown host\n", hostname); errno = ENOENT; return -1; } for (i = 1; i <= 15; i++) { if(!strcmp(protocol, "udp")){ scb->fd = socket (PF_INET, SOCK_DGRAM, 0); if (scb->fd < 0) return -1; } else { /* if(!strcmp(protocol, "tcp")); */ scb->fd = socket (PF_INET, SOCK_STREAM, 0); if (scb->fd < 0) return -1; } /* Allow rapid reuse of this port. */ tmp = 1; setsockopt (scb->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&tmp, sizeof(tmp)); /* Enable TCP keep alive process. */ tmp = 1; setsockopt (scb->fd, SOL_SOCKET, SO_KEEPALIVE, (char *)&tmp, sizeof(tmp)); sockaddr.sin_family = PF_INET; sockaddr.sin_port = htons(port); memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); if (!connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) break; close (scb->fd); scb->fd = -1; /* We retry for ECONNREFUSED because that is often a temporary condition, which happens when the server is being restarted. */ if (errno != ECONNREFUSED) return -1; sleep (1); } if(!strcmp(protocol, "tcp")){ protoent = getprotobyname ("tcp"); if (!protoent) return -1; tmp = 1; if (setsockopt (scb->fd, protoent->p_proto, TCP_NODELAY, (char *)&tmp, sizeof(tmp))) return -1; } signal(SIGPIPE, SIG_IGN); /* If we don't do this, then GDB simply exits when the remote side dies. */ return 0; } ------------end tcp_open()---------------------