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]

[PATCH 4/6] gdbserver: Delimit debugging output for readability


Hi.

This patch adds some delimiters to the output of the major pieces
I found use for, namely linux_resume/wait, and stop/unstop_all_lwps.
These are important steps in the control of the inferior, and can
produce a lot of output: It's helpful to be able to identify
when these steps begin and when they end.

2013-12-17  Doug Evans  <dje@google.com>

	* linux-low.c (linux_wait_1): Surround debugging printf output with
	"====".  Ensure all exit paths have debugging printfs for result.
	(linux_wait): Delete debugging printf, duplicates one in linux_wait_1.
	(linux_resume): Surround debugging printf output with "====".
	(stop_all_lwps): Surround debugging printf output with "----".
	(unstop_all_lwps): Ditto.

---
 gdb/gdbserver/linux-low.c | 66 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 58 insertions(+), 8 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 3883e50..61744a3 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -16,6 +16,18 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* Notes:
+   Debugging printf output is delimited to make it easier to read.
+   There's a lot of it (which is good), but without the delimiters it's
+   hard to see where the entry and exit points are.  High level routines
+   that are useful enough to mark this way are delimited with "====".
+   Lower level routines that are useful enough to mark this way are
+   delimited with "----".
+   We could also use indentation, but that's adds more complexity.
+   Using ==== vs ---- vs nothing works well in practice.
+   Functions are free to use indentation internally, but there is no
+   convention yet for this.  */
+
 #include "server.h"
 #include "linux-low.h"
 #include "linux-osdata.h"
@@ -2268,6 +2278,10 @@ linux_wait_1 (ptid_t ptid,
   int trace_event;
   int in_step_range;
 
+  /* Debugging output is delimited with ==== to make it easier to read.  */
+  if (debug_threads)
+    fprintf (stderr, "====\nlinux_wait_1: [%s]\n", target_pid_to_str (ptid));
+
   /* Translate generic target options into linux options.  */
   options = __WALL;
   if (target_options & TARGET_WNOHANG)
@@ -2318,7 +2332,11 @@ retry:
     }
 
   if (pid == 0) /* only if TARGET_WNOHANG */
-    return null_ptid;
+    {
+      if (debug_threads)
+	fprintf (stderr, "linux_wait_1 ret = null_ptid\n====\n");
+      return null_ptid;
+    }
 
   event_child = get_thread_lwp (current_inferior);
 
@@ -2345,7 +2363,9 @@ retry:
 
 	      if (debug_threads)
 		fprintf (stderr,
-			 "\nChild exited with retcode = %x \n",
+			 "linux_wait_1 ret = %s, exited with retcode %d\n"
+			 "====\n",
+			 target_pid_to_str (ptid_of (event_child)),
 			 WEXITSTATUS (w));
 	    }
 	  else
@@ -2355,9 +2375,10 @@ retry:
 
 	      if (debug_threads)
 		fprintf (stderr,
-			 "\nChild terminated with signal = %x \n",
+			 "linux_wait_1 ret = %s, terminated with signal %d\n"
+			 "====\n",
+			 target_pid_to_str (ptid_of (event_child)),
 			 WTERMSIG (w));
-
 	    }
 
 	  return ptid_of (event_child);
@@ -2524,6 +2545,13 @@ Check if we're already there.\n",
 		{
 		  ourstatus->kind = TARGET_WAITKIND_STOPPED;
 		  ourstatus->value.sig = GDB_SIGNAL_0;
+
+		  if (debug_threads)
+		    fprintf (stderr,
+			     "linux_wait_1 ret = %s, stopped "
+			     "while stabilizing threads\n====\n",
+			     target_pid_to_str (ptid_of (event_child)));
+
 		  return ptid_of (event_child);
 		}
 	    }
@@ -2733,7 +2761,7 @@ Check if we're already there.\n",
   gdb_assert (ptid_equal (step_over_bkpt, null_ptid));
 
   if (debug_threads)
-    fprintf (stderr, "linux_wait ret = %s, %d, %d\n",
+    fprintf (stderr, "linux_wait_1 ret = %s, %d, %d\n====\n",
 	     target_pid_to_str (ptid_of (event_child)),
 	     ourstatus->kind,
 	     ourstatus->value.sig);
@@ -2775,9 +2803,6 @@ linux_wait (ptid_t ptid,
 {
   ptid_t event_ptid;
 
-  if (debug_threads)
-    fprintf (stderr, "linux_wait: [%s]\n", target_pid_to_str (ptid));
-
   /* Flush the async file first.  */
   if (target_is_async_p ())
     async_file_flush ();
@@ -3079,6 +3104,13 @@ stop_all_lwps (int suspend, struct lwp_info *except)
   /* Should not be called recursively.  */
   gdb_assert (stopping_threads == NOT_STOPPING_THREADS);
 
+  if (debug_threads)
+    {
+      fprintf (stderr, "----\nstop_all_lwps (%s, except=%s)\n",
+	       suspend ? "stop-and-suspend" : "stop",
+	       except != NULL ? target_pid_to_str (ptid_of (except)) : "none");
+    }
+
   stopping_threads = (suspend
 		      ? STOPPING_AND_SUSPENDING_THREADS
 		      : STOPPING_THREADS);
@@ -3089,6 +3121,13 @@ stop_all_lwps (int suspend, struct lwp_info *except)
     find_inferior (&all_lwps, send_sigstop_callback, except);
   for_each_inferior (&all_lwps, wait_for_sigstop);
   stopping_threads = NOT_STOPPING_THREADS;
+
+  if (debug_threads)
+    {
+      fprintf (stderr,
+	       "stop_all_lwps done, setting stopping_threads "
+	       "back to !stopping\n----\n");
+    }
 }
 
 /* Resume execution of the inferior process.
@@ -3792,6 +3831,10 @@ linux_resume (struct thread_resume *resume_info, size_t n)
   int any_pending;
   int leave_all_stopped;
 
+  /* Debugging output is delimited with ==== to make it easier to read.  */
+  if (debug_threads)
+    fprintf (stderr, "====\nlinux_resume:\n");
+
   find_inferior (&all_threads, linux_set_resume_request, &array);
 
   /* If there is a thread which would otherwise be resumed, which has
@@ -3835,6 +3878,9 @@ linux_resume (struct thread_resume *resume_info, size_t n)
 
   if (need_step_over)
     start_step_over (need_step_over);
+
+  if (debug_threads)
+    fprintf (stderr, "linux_resume done\n====\n");
 }
 
 /* This function is called once per thread.  We check the thread's
@@ -3984,6 +4030,7 @@ unstop_all_lwps (int unsuspend, struct lwp_info *except)
 {
   if (debug_threads)
     {
+      fprintf (stderr, "----\n");
       if (except)
 	fprintf (stderr,
 		 "unstopping all lwps, except=(LWP %ld)\n", lwpid_of (except));
@@ -3996,6 +4043,9 @@ unstop_all_lwps (int unsuspend, struct lwp_info *except)
     find_inferior (&all_lwps, unsuspend_and_proceed_one_lwp, except);
   else
     find_inferior (&all_lwps, proceed_one_lwp, except);
+
+  if (debug_threads)
+    fprintf (stderr, "unstop_all_lwps done\n----\n");
 }
 
 
-- 
1.8.5.1


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