title: Socket read failing in gdb, OK when run outside gdb
body: <p>I have a problem where running some socket code in gdb is causing the socket read to fail, whereas it seems to work when run normally outside of gdb</p>
  
  <p>I need to be able to debug this, so I have to figure out what is going on.</p>
  
  <p>the code looks like this:</p>
  
  <pre><code>sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd &lt; 0) 
      error("ERROR opening socket");
  bzero((char *) &amp;serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(portno);
  if (bind(sockfd, (struct sockaddr *) &amp;serv_addr, sizeof(serv_addr)) &lt; 0) {
      error("ERROR on binding");
  }
  listen(sockfd,5);
  printf("Daemon listening on host %s port %d...\n\n",
         hostname, portno);
  clilen = sizeof(cli_addr);
  
  /* accept() blocks until a socket connection is found */
  newsockfd = accept(sockfd, (struct sockaddr *) &amp;cli_addr, &amp;clilen);
  
  if (newsockfd &lt; 0) 
      error("ERROR on accept");
  else
      printf("Daemon found socket connection "
             "(newsockfd = %d) ready to read...\n\n", newsockfd);
  
  bzero(buf,65536);
  buf_no = 1;
  while(1) {
      n = read(newsockfd, buf, MAX_TRACK_TABLE_SIZE);
      printf("read() returns %d, errno = %d\n", n, errno);
      perror("Error");
  ...
  </code></pre>
  
  <p>I run this in conjunction with a python script that just sends messages over the socket, for this c-code to receive and process</p>
  
  <p>When I run the C application from the cmd line I get expected results, i.e. n is set to no. of bytes recvd and the string coming over the socket is placed in buf.</p>
  
  <p>However, when I run the application in gdb, the call to read() returns -1, with an errno of 14 corresptonding to a 'Bad address' error</p>
  
  <p>I can't think what could be causing the difference in behaviour between running inside and outside of gdb?</p>