This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfa/doc] Add monitor commands to gdbserver


Here's what I meant when I mentioned a while ago that monitor commands
should be used to enable/disable debugging output for gdbserver.  I
also added minimal tests for the new commands and some documentation for
them, even though they're only for debugging of gdbserver itself.

Eli, does the documentation look OK?

-- 
Daniel Jacobowitz
CodeSourcery

2007-02-19  Daniel Jacobowitz  <dan@codesourcery.com>

	* gdb.texinfo (Monitor commands for gdbserver): New subsection.

2007-02-19  Daniel Jacobowitz  <dan@codesourcery.com>

	* remote-utils.c (monitor_output): New function.
	* server.c (debug_threads): Define here.
	(monitor_show_help): New function.
	(handle_query): Handle qRcmd.
	(main): Do not handle 'd' packet.
	* server.h (debug_threads, remote_debug, monitor_output): Declare.
	* linux-low.c, spu-low.c, win32-i386-low.c: Remove definitions
	of debug_threads.

2007-02-19  Daniel Jacobowitz  <dan@codesourcery.com>

	* gdb.server/server-mon.exp: New test.

Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.386
diff -u -p -r1.386 gdb.texinfo
--- doc/gdb.texinfo	12 Feb 2007 23:53:02 -0000	1.386
+++ doc/gdb.texinfo	19 Feb 2007 15:48:56 -0000
@@ -12774,6 +12774,29 @@ already on the target.
 
 @end table
 
+@subsection Monitor commands for @code{gdbserver}
+@cindex monitor commands, for @code{gdbserver}
+
+During a @value{GDBN} session using @code{gdbserver}, you can use the
+@code{monitor} command to send special requests to @code{gdbserver}.
+Here are the available commands; they are only of interest when
+debugging @value{GDBN} or @code{gdbserver}.
+
+@table @code
+@item monitor help
+List the available monitor commands.
+
+@item monitor set debug 0
+@itemx monitor set debug 1
+Disable or enable general debugging messages.
+
+@item monitor set remote-debug 0
+@itemx monitor set remote-debug 1
+Disable or enable specific debugging messages associated with the remote
+protocol (@pxref{Remote Protocol}).
+
+@end table
+
 @node Remote configuration
 @section Remote configuration
 
Index: gdbserver/linux-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-low.c,v
retrieving revision 1.51
diff -u -p -r1.51 linux-low.c
--- gdbserver/linux-low.c	9 Jan 2007 22:55:10 -0000	1.51
+++ gdbserver/linux-low.c	19 Feb 2007 15:48:56 -0000
@@ -77,8 +77,6 @@ struct pending_signals
 static int use_regsets_p = 1;
 #endif
 
-int debug_threads = 0;
-
 #define pid_of(proc) ((proc)->head.id)
 
 /* FIXME: Delete eventually.  */
Index: gdbserver/remote-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/remote-utils.c,v
retrieving revision 1.38
diff -u -p -r1.38 remote-utils.c
--- gdbserver/remote-utils.c	16 Feb 2007 20:01:14 -0000	1.38
+++ gdbserver/remote-utils.c	19 Feb 2007 15:48:56 -0000
@@ -1074,3 +1074,15 @@ look_up_one_symbol (const char *name, CO
 
   return 1;
 }
+
+void
+monitor_output (char *msg)
+{
+  char *buf = malloc (strlen (msg) * 2 + 2);
+
+  buf[0] = 'O';
+  hexify (buf + 1, msg, 0);
+
+  putpkt (buf);
+  free (buf);
+}
Index: gdbserver/server.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.h,v
retrieving revision 1.28
diff -u -p -r1.28 server.h
--- gdbserver/server.h	9 Jan 2007 17:59:08 -0000	1.28
+++ gdbserver/server.h	19 Feb 2007 15:48:56 -0000
@@ -128,12 +128,14 @@ extern unsigned long step_thread;
 extern unsigned long thread_from_wait;
 extern unsigned long old_thread_from_wait;
 extern int server_waiting;
+extern int debug_threads;
 extern int pass_signals[];
 
 extern jmp_buf toplevel;
 
 /* From remote-utils.c */
 
+extern int remote_debug;
 extern int all_symbols_looked_up;
 
 int putpkt (char *buf);
@@ -170,6 +172,8 @@ int remote_escape_output (const gdb_byte
 
 int look_up_one_symbol (const char *name, CORE_ADDR *addrp);
 
+void monitor_output (char *msg);
+
 /* Functions from ``signals.c''.  */
 enum target_signal target_signal_from_host (int hostsig);
 int target_signal_to_host_p (enum target_signal oursig);
Index: gdbserver/spu-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/spu-low.c,v
retrieving revision 1.2
diff -u -p -r1.2 spu-low.c
--- gdbserver/spu-low.c	9 Jan 2007 17:59:08 -0000	1.2
+++ gdbserver/spu-low.c	19 Feb 2007 15:48:57 -0000
@@ -58,7 +58,6 @@
 
 /* These are used in remote-utils.c.  */
 int using_threads = 0;
-int debug_threads = 0;
 
 
 /* Fetch PPU register REGNO.  */
Index: gdbserver/win32-i386-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/win32-i386-low.c,v
retrieving revision 1.3
diff -u -p -r1.3 win32-i386-low.c
--- gdbserver/win32-i386-low.c	9 Jan 2007 17:59:08 -0000	1.3
+++ gdbserver/win32-i386-low.c	19 Feb 2007 15:48:57 -0000
@@ -44,7 +44,6 @@
 #define OUTMSG2(X)
 #endif
 
-int debug_threads;
 int using_threads = 1;
 
 /* Globals.  */
Index: testsuite/gdb.server/server-mon.exp
===================================================================
RCS file: testsuite/gdb.server/server-mon.exp
diff -N testsuite/gdb.server/server-mon.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.server/server-mon.exp	19 Feb 2007 15:48:57 -0000
@@ -0,0 +1,55 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# Test gdbserver monitor commands.
+
+load_lib gdbserver-support.exp
+
+set testfile "server"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if { [skip_gdbserver_tests] } {
+    return 0
+}
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    return -1
+}
+
+gdb_exit
+gdb_start
+
+gdbserver_load $binfile ""
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_test_multiple "monitor help" "" {
+    -re "Unknown monitor command.*$gdb_prompt $" {
+	fail "monitor help"
+    }
+    -re "The following monitor commands.*$gdb_prompt $" {
+	pass "monitor help"
+    }
+}
+
+gdb_test "monitor" "Unknown monitor command.*Protocol error.*"
+
+gdb_test "monitor set debug 1" "Debug output enabled\\."
+gdb_test "monitor set debug 0" "Debug output disabled\\."
+gdb_test "monitor set remote-debug 1" "Protocol debug output enabled\\."
+gdb_test "monitor set remote-debug 0" "Protocol debug output disabled\\."
Index: gdbserver/server.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.c,v
retrieving revision 1.46
diff -u -p -r1.46 server.c
--- gdbserver/server.c	8 Feb 2007 21:39:04 -0000	1.46
+++ gdbserver/server.c	19 Feb 2007 15:51:52 -0000
@@ -35,6 +35,10 @@ unsigned long old_thread_from_wait;
 int extended_protocol;
 int server_waiting;
 
+/* Enable miscellaneous debugging output.  The name is historical - it
+   was originally used to debug LinuxThreads support.  */
+int debug_threads;
+
 int pass_signals[TARGET_SIGNAL_LAST];
 
 jmp_buf toplevel;
@@ -233,6 +237,16 @@ get_features_xml (const char *annex)
   return document;
 }
 
+void
+monitor_show_help (void)
+{
+  monitor_output ("The following monitor commands are supported:\n");
+  monitor_output ("  set debug <0|1>\n");
+  monitor_output ("    Enable general debugging messages\n");  
+  monitor_output ("  set remote-debug <0|1>\n");
+  monitor_output ("    Enable remote protocol debugging messages\n");
+}
+
 /* Handle all of the extended 'q' packets.  */
 void
 handle_query (char *own_buf, int *new_packet_len_p)
@@ -440,6 +454,55 @@ handle_query (char *own_buf, int *new_pa
       /* Otherwise, pretend we do not understand this packet.  */
     }
 
+  /* Handle "monitor" commands.  */
+  if (strncmp ("qRcmd,", own_buf, 6) == 0)
+    {
+      char *mon = malloc (PBUFSIZ);
+      int len = strlen (own_buf + 6);
+
+      if ((len % 1) != 0 || unhexify (mon, own_buf + 6, len / 2) != len / 2)
+	{
+	  write_enn (own_buf);
+	  free (mon);
+	  return;
+	}
+      mon[len / 2] = '\0';
+
+      write_ok (own_buf);
+
+      if (strcmp (mon, "set debug 1") == 0)
+	{
+	  debug_threads = 1;
+	  monitor_output ("Debug output enabled.\n");
+	}
+      else if (strcmp (mon, "set debug 0") == 0)
+	{
+	  debug_threads = 0;
+	  monitor_output ("Debug output disabled.\n");
+	}
+      else if (strcmp (mon, "set remote-debug 1") == 0)
+	{
+	  remote_debug = 1;
+	  monitor_output ("Protocol debug output enabled.\n");
+	}
+      else if (strcmp (mon, "set remote-debug 0") == 0)
+	{
+	  remote_debug = 0;
+	  monitor_output ("Protocol debug output disabled.\n");
+	}
+      else if (strcmp (mon, "help") == 0)
+	monitor_show_help ();
+      else
+	{
+	  monitor_output ("Unknown monitor command.\n\n");
+	  monitor_show_help ();
+	  write_enn (own_buf);
+	}
+
+      free (mon);
+      return;
+    }
+
   /* Otherwise we didn't know what packet it was.  Say we didn't
      understand it.  */
   own_buf[0] = 0;
@@ -736,9 +799,6 @@ main (int argc, char *argv[])
 	    case 'Q':
 	      handle_general_set (own_buf);
 	      break;
-	    case 'd':
-	      remote_debug = !remote_debug;
-	      break;
 #ifndef USE_WIN32API
 	    /* Skip "detach" support on mingw32, since we don't have
 	       waitpid.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]