Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Michal Ludvig <mludvig@suse.cz>
To: gdb-patches@sources.redhat.com
Subject: [RFA] remote debugging patches
Date: Sun, 10 Mar 2002 10:34:00 -0000	[thread overview]
Message-ID: <3C8BA71F.20807@suse.cz> (raw)

[-- Attachment #1: Type: text/plain, Size: 720 bytes --]

Hi,
Here are two patches for remote debugging. The first one is pretty 
straightforward and just makes use of the last parameter to getpkt().
The second one changes banner printed after successful connection to 
gdbserver from "Remote debugging using :1234" to more informational
"Remote debugging from host whatever.name.com". When debugging via 
serial line, nothing changes.

Index: ChangeLog

	* remote.c: Added WAIT_FOREVER_FLAG and changed all
	calls to getpkt() to respect it.
	* gdbserver/remote-utils.c (remote_open): After successful
	connection the remote host name is printed instead of local
	port number.


Michal Ludvig
-- 
* SuSE CR, s.r.o     * mludvig@suse.cz
* +420 2 9654 5373   * http://www.suse.cz

[-- Attachment #2: gdb-remote.diff --]
[-- Type: text/plain, Size: 12590 bytes --]

Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.77
diff -u -r1.77 remote.c
--- remote.c	2002/02/27 01:18:39	1.77
+++ remote.c	2002/03/10 18:13:05
@@ -55,6 +55,8 @@
 
 #include "gdbcore.h" /* for exec_bfd */
 
+#define WAIT_FOREVER_FLAG 0
+
 /* Prototypes for local functions */
 static void cleanup_sigint_signal_handler (void *dummy);
 static void initialize_sigint_signal_handler (void);
@@ -1032,7 +1034,7 @@
   else
     sprintf (&buf[2], "%x", th);
   putpkt (buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
   if (gen)
     general_thread = th;
   else
@@ -1052,7 +1054,7 @@
   else
     sprintf (buf, "T%08x", tid);
   putpkt (buf);
-  getpkt (buf, sizeof (buf), 0);
+  getpkt (buf, sizeof (buf), WAIT_FOREVER_FLAG);
   return (buf[0] == 'O' && buf[1] == 'K');
 }
 
@@ -1550,7 +1552,7 @@
 
   pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
   putpkt (threadinfo_pkt);
-  getpkt (threadinfo_pkt, (rs->remote_packet_size), 0);
+  getpkt (threadinfo_pkt, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
   result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
					       info);
   return result;
@@ -1630,7 +1632,7 @@
   pack_threadlist_request (threadlist_packet,
			   startflag, result_limit, nextthread);
   putpkt (threadlist_packet);
-  getpkt (t_response, (rs->remote_packet_size), 0);
+  getpkt (t_response, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
   *result_count =
     parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
@@ -1740,7 +1742,7 @@
   char *buf = alloca (rs->remote_packet_size);
 
   putpkt ("qC");
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
   if (buf[0] == 'Q' && buf[1] == 'C')
     return pid_to_ptid (strtol (&buf[2], NULL, 16));
   else
@@ -1782,7 +1784,7 @@
     {
       putpkt ("qfThreadInfo");
       bufp = buf;
-      getpkt (bufp, (rs->remote_packet_size), 0);
+      getpkt (bufp, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
       if (bufp[0] != '\0')		/* q packet recognized */
	{	
	  while (*bufp++ == 'm')	/* reply contains one or more TID */
@@ -1796,7 +1798,7 @@
	      while (*bufp++ == ',');	/* comma-separated list */
	      putpkt ("qsThreadInfo");
	      bufp = buf;
-	      getpkt (bufp, (rs->remote_packet_size), 0);
+	      getpkt (bufp, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
	    }
	  return;	/* done */
	}
@@ -1837,7 +1839,7 @@
     {
       sprintf (bufp, "qThreadExtraInfo,%x", PIDGET (tp->ptid));
       putpkt (bufp);
-      getpkt (bufp, (rs->remote_packet_size), 0);
+      getpkt (bufp, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
       if (bufp[0] != 0)
	{
	  n = min (strlen (bufp) / 2, sizeof (display_buf));
@@ -1893,7 +1895,7 @@
   /* Now query for status so this looks just like we restarted
      gdbserver from scratch.  */
   putpkt ("?");
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 }
 \f
 /* Clean up connection to a remote debugger.  */
@@ -1921,7 +1923,7 @@
 
   putpkt ("qOffsets");
 
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
   if (buf[0] == '\000')
     return;			/* Return silently.  Stub doesn't support
@@ -2202,7 +2204,7 @@
   /* Invite target to request symbol lookups. */
 
   putpkt ("qSymbol::");
-  getpkt (reply, (rs->remote_packet_size), 0);
+  getpkt (reply, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
   packet_ok (reply, &remote_protocol_qSymbol);
 
   while (strncmp (reply, "qSymbol:", 8) == 0)
@@ -2218,7 +2220,7 @@
		 paddr_nz (SYMBOL_VALUE_ADDRESS (sym)),
		 &reply[8]);
       putpkt (msg);
-      getpkt (reply, (rs->remote_packet_size), 0);
+      getpkt (reply, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
     }
 }
 
@@ -2304,7 +2306,7 @@
       /* Tell the remote that we are using the extended protocol.  */
       char *buf = alloca (rs->remote_packet_size);
       putpkt ("!");
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
     }
 #ifdef SOLIB_CREATE_INFERIOR_HOOK
   /* FIXME: need a master target_open vector from which all 
@@ -2418,7 +2420,7 @@
       /* Tell the remote that we are using the extended protocol.  */
       char *buf = alloca (rs->remote_packet_size);
       putpkt ("!");
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
     }
 #ifdef SOLIB_CREATE_INFERIOR_HOOK
   /* FIXME: need a master target_open vector from which all 
@@ -2601,7 +2603,7 @@
	      *p++ = 0;
 
	      putpkt (buf);
-	      getpkt (buf, (rs->remote_packet_size), 0);
+	      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
	      if (packet_ok (buf, &remote_protocol_E) == PACKET_OK)
		return;
@@ -2619,7 +2621,7 @@
	      *p++ = 0;
 
	      putpkt (buf);
-	      getpkt (buf, (rs->remote_packet_size), 0);
+	      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
	      if (packet_ok (buf, &remote_protocol_e) == PACKET_OK)
		return;
@@ -2690,7 +2692,7 @@
	      *p++ = 0;
 
	      putpkt (buf);
-	      getpkt (buf, (rs->remote_packet_size), 0);
+	      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
	      if (packet_ok (buf, &remote_protocol_E) == PACKET_OK)
		goto register_event_loop;
@@ -2708,7 +2710,7 @@
	      *p++ = 0;
 
	      putpkt (buf);
-	      getpkt (buf, (rs->remote_packet_size), 0);
+	      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
	      if (packet_ok (buf, &remote_protocol_e) == PACKET_OK)
		goto register_event_loop;
@@ -3439,7 +3441,7 @@
       if (remote_debug)
	fprintf_unfiltered (gdb_stdlog,
			    "Bad register packet; fetching a new packet\n");
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
     }
 
   /* Reply describes registers byte by byte, each byte encoded as two
@@ -3695,7 +3697,7 @@
	*p = '\0';
	
	putpkt_binary (buf, (int) (p - buf));
-	getpkt (buf, (rs->remote_packet_size), 0);
+	getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
	if (buf[0] == '\0')
	  {
@@ -3837,7 +3839,7 @@
     }
   
   putpkt_binary (buf, (int) (p - buf));
-  getpkt (buf, sizeof_buf, 0);
+  getpkt (buf, sizeof_buf, WAIT_FOREVER_FLAG);
   
   if (buf[0] == 'E')
     {
@@ -3902,7 +3904,7 @@
       *p = '\0';
 
       putpkt (buf);
-      getpkt (buf, sizeof_buf, 0);
+      getpkt (buf, sizeof_buf, WAIT_FOREVER_FLAG);
 
       if (buf[0] == 'E')
	{
@@ -3980,7 +3982,7 @@
       data_long = extract_unsigned_integer (data, len);
       sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
       putpkt (buf);
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
       if (buf[0] == '\0')
	{
	  /* The stub doesn't support the 't' request.	We might want to
@@ -4069,7 +4071,7 @@
	     long sizeof_buf)
 {
   putpkt (buf);
-  getpkt (buf, sizeof_buf, 0);
+  getpkt (buf, sizeof_buf, WAIT_FOREVER_FLAG);
 
   if (buf[0] == 'E')
     error ("Remote failure reply: %s", buf);
@@ -4658,7 +4660,7 @@
       sprintf (p, ",%d", bp_size);
       
       putpkt (buf);
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
       switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_SOFTWARE_BP]))
	{
@@ -4711,7 +4713,7 @@
       sprintf (p, ",%d", bp_size);
       
       putpkt (buf);
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
       return (buf[0] == 'E');
     }
@@ -4766,7 +4768,7 @@
   sprintf (p, ",%x", len);
   
   putpkt (buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
   switch (packet_ok (buf, &remote_protocol_Z[packet]))
     {
@@ -4802,7 +4804,7 @@
   p += hexnumstr (p, (ULONGEST) addr);
   sprintf (p, ",%x", len);
   putpkt (buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
   switch (packet_ok (buf, &remote_protocol_Z[packet]))
     {
@@ -4840,7 +4842,7 @@
   sprintf (p, ",%x", len);
 
   putpkt (buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
 
   switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
     {
@@ -4878,7 +4880,7 @@
   sprintf (p, ",%x", len);
 
   putpkt(buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
   
   switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
     {
@@ -5011,7 +5013,7 @@
       bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
       host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
 
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
       if (buf[0] == 'E')
	error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
	       sectname, lma, lma + size);
@@ -5102,7 +5104,7 @@
   if (i < 0)
     return i;
 
-  getpkt (outbuf, *bufsiz, 0);
+  getpkt (outbuf, *bufsiz, WAIT_FOREVER_FLAG);
 
   return 0;
 }
@@ -5141,7 +5143,7 @@
     {
       /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
       buf[0] = '\0';
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
       if (buf[0] == '\0')
	error ("Target does not support this command\n");
       if (buf[0] == 'O' && buf[1] != 'K')
@@ -5182,7 +5184,7 @@
   puts_filtered ("\n");
   putpkt (args);
 
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
   puts_filtered ("received: ");
   print_packet (buf);
   puts_filtered ("\n");
@@ -5430,7 +5432,7 @@
     error ("Command can only be used when connected to the remote target.");
 
   putpkt ("qfProcessInfo");
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
   if (buf[0] == 0)
     return;			/* Silently: target does not support this feature. */
 
@@ -5441,7 +5443,7 @@
     {
       remote_console_output (&buf[1]);
       putpkt ("qsProcessInfo");
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, (rs->remote_packet_size), WAIT_FOREVER_FLAG);
     }
 }
 

Index: gdbserver/remote-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/remote-utils.c,v
retrieving revision 1.8
diff -u -r1.8 remote-utils.c
--- remote-utils.c	2002/02/14 06:21:22	1.8
+++ remote-utils.c	2002/03/10 18:13:05
@@ -47,7 +47,10 @@
 void
 remote_open (char *name)
 {
-  int save_fcntl_flags;
+  int save_fcntl_flags, via_network=0;;
+  char namebuf[100];
+  
+  snprintf(namebuf, 100, "%s", name);
 
   if (!strchr (name, ':'))
     {
@@ -109,6 +112,7 @@
       int tmp;
       struct protoent *protoent;
       int tmp_desc;
+      struct hostent *hostent;
 
       port_str = strchr (name, ':');
 
@@ -154,6 +158,21 @@
 
       signal (SIGPIPE, SIG_IGN);	/* If we don't do this, then gdbserver simply
					   exits when the remote side dies.  */
+
+      /* Resolve peer's hostname or convert IP address to string.  */
+      hostent = gethostbyaddr ( (void *)&sockaddr.sin_addr.s_addr, 
+			 sizeof (sockaddr.sin_addr.s_addr), AF_INET);
+      if (hostent)
+	 snprintf(namebuf, 100, "%s", hostent->h_name);
+      else
+      {
+	 union { unsigned char ip_c[4]; int ip_i; } ip;
+	
+	 ip.ip_i = ntohl (sockaddr.sin_addr.s_addr);
+	 snprintf (namebuf, 100, "%u.%u.%u.%u", 
+	   ip.ip_c[3], ip.ip_c[2], ip.ip_c[1], ip.ip_c[0]);
+      }
+      via_network = 1;
     }
 
 #if defined(F_SETFL) && defined (FASYNC)
@@ -164,7 +184,8 @@
 #endif
 #endif
   disable_async_io ();
-  fprintf (stderr, "Remote debugging using %s\n", name);
+
+  fprintf (stderr, "Remote debugging %s %s\n", via_network?"from host":"using", namebuf);
 }
 
 void

             reply	other threads:[~2002-03-10 18:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-10 10:34 Michal Ludvig [this message]
2002-03-10 11:35 ` Daniel Jacobowitz
2002-03-10 11:43   ` Michal Ludvig
2002-03-10 14:30     ` Daniel Jacobowitz
2002-03-11  6:54       ` Michal Ludvig
2002-03-11  7:37         ` Daniel Jacobowitz
2002-03-11 18:22         ` Andrew Cagney
2002-03-11 18:47           ` Daniel Jacobowitz
2002-03-13  6:14             ` Michal Ludvig
2002-03-13  7:48               ` Andreas Schwab
2002-03-13  8:17                 ` Michal Ludvig
2002-03-13  8:34                   ` Andrew Cagney
2002-03-13  9:53                   ` Andreas Schwab
2002-03-13 11:09                     ` Michal Ludvig
2002-03-13 12:24                       ` Andreas Schwab
2002-03-13  9:07               ` Daniel Jacobowitz
2002-03-10 12:16 ` Andrew Cagney
2002-03-11  7:08   ` Michal Ludvig
2002-03-11  7:37     ` Daniel Jacobowitz
2002-03-11  8:06       ` Michal Ludvig
2002-03-11  8:12         ` Daniel Jacobowitz
2002-03-11  8:38           ` Michal Ludvig
2002-03-11  8:34         ` Andrew Cagney
2002-03-11  7:53     ` Andrew Cagney
2002-03-11  9:12       ` Michal Ludvig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3C8BA71F.20807@suse.cz \
    --to=mludvig@suse.cz \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox