[PATCH] gdb fbsd-nat: Use new-style debug macros

John Baldwin jhb@FreeBSD.org
Wed Apr 14 23:26:35 GMT 2021


gdb/ChangeLog:

	* fbsd-nat.c (fbsd_lwp_debug_printf, fbsd_nat_debug_printf): New,
	use throughout file.
---
 gdb/ChangeLog  |  5 +++++
 gdb/fbsd-nat.c | 58 ++++++++++++++++++++------------------------------
 2 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3d3e94eebb6..cc24c3d2466 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-14  John Baldwin  <jhb@FreeBSD.org>
+
+	* fbsd-nat.c (fbsd_lwp_debug_printf, fbsd_nat_debug_printf): New,
+	use throughout file.
+
 2021-04-14  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
 	* dwarf2/read.c (inherit_abstract_dies): Keep a reference to the
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index 0f0822f0d55..581c04d5f83 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -721,6 +721,13 @@ show_fbsd_nat_debug (struct ui_file *file, int from_tty,
 		    value);
 }
 
+#define fbsd_lwp_debug_printf(fmt, ...) \
+  debug_prefixed_printf_cond (debug_fbsd_lwp, "fbsd-lwp", fmt, ##__VA_ARGS__)
+
+#define fbsd_nat_debug_printf(fmt, ...) \
+  debug_prefixed_printf_cond (debug_fbsd_nat, "fbsd-nat", fmt, ##__VA_ARGS__)
+
+
 /*
   FreeBSD's first thread support was via a "reentrant" version of libc
   (libc_r) that first shipped in 2.2.7.  This library multiplexed all
@@ -893,10 +900,7 @@ fbsd_add_threads (fbsd_nat_target *target, pid_t pid)
 	  if (pl.pl_flags & PL_FLAG_EXITED)
 	    continue;
 #endif
-	  if (debug_fbsd_lwp)
-	    fprintf_unfiltered (gdb_stdlog,
-				"FLWP: adding thread for LWP %u\n",
-				lwps[i]);
+	  fbsd_lwp_debug_printf ("adding thread for LWP %u", lwps[i]);
 	  add_thread (target, ptid);
 	}
     }
@@ -1037,11 +1041,8 @@ fbsd_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
     return;
 #endif
 
-  if (debug_fbsd_lwp)
-    fprintf_unfiltered (gdb_stdlog,
-			"FLWP: fbsd_resume for ptid (%d, %ld, %ld)\n",
-			ptid.pid (), ptid.lwp (),
-			ptid.tid ());
+  fbsd_lwp_debug_printf ("ptid (%d, %ld, %ld)", ptid.pid (), ptid.lwp (),
+			 ptid.tid ());
   if (ptid.lwp_p ())
     {
       /* If ptid is a specific LWP, suspend all other LWPs in the process.  */
@@ -1129,9 +1130,7 @@ fbsd_handle_debug_trap (fbsd_nat_target *target, ptid_t ptid,
      breakpoint.  */
   if (pl.pl_siginfo.si_code == TRAP_TRACE)
     {
-      if (debug_fbsd_nat)
-	fprintf_unfiltered (gdb_stdlog,
-			    "FNAT: trace trap for LWP %ld\n", ptid.lwp ());
+      fbsd_nat_debug_printf ("trace trap for LWP %ld", ptid.lwp ());
       return true;
     }
 
@@ -1142,10 +1141,7 @@ fbsd_handle_debug_trap (fbsd_nat_target *target, ptid_t ptid,
       struct gdbarch *gdbarch = regcache->arch ();
       int decr_pc = gdbarch_decr_pc_after_break (gdbarch);
 
-      if (debug_fbsd_nat)
-	fprintf_unfiltered (gdb_stdlog,
-			    "FNAT: sw breakpoint trap for LWP %ld\n",
-			    ptid.lwp ());
+      fbsd_nat_debug_printf ("sw breakpoint trap for LWP %ld", ptid.lwp ());
       if (decr_pc != 0)
 	{
 	  CORE_ADDR pc;
@@ -1195,14 +1191,12 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 
 	  if (debug_fbsd_nat)
 	    {
-	      fprintf_unfiltered (gdb_stdlog,
-				  "FNAT: stop for LWP %u event %d flags %#x\n",
-				  pl.pl_lwpid, pl.pl_event, pl.pl_flags);
+	      fbsd_nat_debug_printf ("stop for LWP %u event %d flags %#x",
+				     pl.pl_lwpid, pl.pl_event, pl.pl_flags);
 	      if (pl.pl_flags & PL_FLAG_SI)
-		fprintf_unfiltered (gdb_stdlog,
-				    "FNAT: si_signo %u si_code %u\n",
-				    pl.pl_siginfo.si_signo,
-				    pl.pl_siginfo.si_code);
+		fbsd_nat_debug_printf ("si_signo %u si_code %u",
+				       pl.pl_siginfo.si_signo,
+				       pl.pl_siginfo.si_code);
 	    }
 
 #ifdef PT_LWP_EVENTS
@@ -1215,10 +1209,8 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 	      thread_info *thr = find_thread_ptid (this, wptid);
 	      if (thr != nullptr)
 		{
-		  if (debug_fbsd_lwp)
-		    fprintf_unfiltered (gdb_stdlog,
-					"FLWP: deleting thread for LWP %u\n",
-					pl.pl_lwpid);
+		  fbsd_lwp_debug_printf ("deleting thread for LWP %u",
+					 pl.pl_lwpid);
 		  if (print_thread_events)
 		    printf_unfiltered (_("[%s exited]\n"),
 				       target_pid_to_str (wptid).c_str ());
@@ -1238,10 +1230,8 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 	     event.  */
 	  if (in_thread_list (this, ptid_t (pid)))
 	    {
-	      if (debug_fbsd_lwp)
-		fprintf_unfiltered (gdb_stdlog,
-				    "FLWP: using LWP %u for first thread\n",
-				    pl.pl_lwpid);
+	      fbsd_lwp_debug_printf ("using LWP %u for first thread",
+				     pl.pl_lwpid);
 	      thread_change_ptid (this, ptid_t (pid), wptid);
 	    }
 
@@ -1254,10 +1244,8 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 		 BORN events for an already-known LWP.  */
 	      if (!in_thread_list (this, wptid))
 		{
-		  if (debug_fbsd_lwp)
-		    fprintf_unfiltered (gdb_stdlog,
-					"FLWP: adding thread for LWP %u\n",
-					pl.pl_lwpid);
+		  fbsd_lwp_debug_printf ("adding thread for LWP %u",
+					 pl.pl_lwpid);
 		  add_thread (this, wptid);
 		}
 	      ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
-- 
2.30.1



More information about the Gdb-patches mailing list