public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] gdb: rename target_waitstatus_to_string to target_waitstatus::to_string
@ 2021-11-22 16:27 Simon Marchi
  2021-11-22 16:27 ` [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Simon Marchi @ 2021-11-22 16:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Make target_waitstatus_to_string a "to_string" method of
target_waitstatus, a bit like we have ptid_t::to_string already.  This
will save a bit of typing.

Change-Id: Id261b7a09fa9fa3c738abac131c191a6f9c13905
---
 gdb/gnu-nat.c           |  2 +-
 gdb/infrun.c            | 17 ++++++++---------
 gdb/record-btrace.c     |  4 ++--
 gdb/target-debug.h      |  4 +---
 gdb/target/waitstatus.c | 18 +++++++++---------
 gdb/target/waitstatus.h | 11 ++++++-----
 gdbserver/linux-low.cc  | 10 +++-------
 gdbserver/server.cc     | 11 +++--------
 8 files changed, 33 insertions(+), 44 deletions(-)

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index c6cecff0686..216d178424f 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -1619,7 +1619,7 @@ gnu_nat_target::wait (ptid_t ptid, struct target_waitstatus *status,
 
   inf_debug (inf, "returning ptid = %s, %s",
 	     target_pid_to_str (ptid).c_str (),
-	     target_waitstatus_to_string (status).c_str ());
+	     status->to_string ().c_str ());
 
   return ptid;
 }
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 89a98c20df4..dba4f33a327 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -2214,7 +2214,7 @@ resume_1 (enum gdb_signal sig)
 	("thread %s has pending wait "
 	 "status %s (currently_stepping=%d).",
 	 tp->ptid.to_string ().c_str (),
-	 target_waitstatus_to_string (&tp->pending_waitstatus ()).c_str (),
+	 tp->pending_waitstatus ().to_string ().c_str (),
 	 currently_stepping (tp));
 
       tp->inf->process_target ()->threads_executing = true;
@@ -2632,7 +2632,7 @@ clear_proceed_status_thread (struct thread_info *tp)
 	  infrun_debug_printf
 	    ("thread %s has pending wait status %s (currently_stepping=%d).",
 	     tp->ptid.to_string ().c_str (),
-	     target_waitstatus_to_string (&tp->pending_waitstatus ()).c_str (),
+	     tp->pending_waitstatus ().to_string ().c_str (),
 	     currently_stepping (tp));
 	}
     }
@@ -3478,7 +3478,7 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
   infrun_debug_printf ("  %s [%s],",
 		       result_ptid.to_string ().c_str (),
 		       target_pid_to_str (result_ptid).c_str ());
-  infrun_debug_printf ("  %s", target_waitstatus_to_string (ws).c_str ());
+  infrun_debug_printf ("  %s", ws->to_string ().c_str ());
 }
 
 /* Select a thread at random, out of those which are resumed and have
@@ -3584,8 +3584,7 @@ do_target_wait_1 (inferior *inf, ptid_t ptid,
   if (tp != NULL)
     {
       infrun_debug_printf ("Using pending wait status %s for %s.",
-			   target_waitstatus_to_string
-			     (&tp->pending_waitstatus ()).c_str (),
+			   tp->pending_waitstatus ().to_string ().c_str (),
 			   tp->ptid.to_string ().c_str ());
 
       /* Now that we've selected our final event LWP, un-adjust its PC
@@ -4678,7 +4677,7 @@ static void
 save_waitstatus (struct thread_info *tp, const target_waitstatus *ws)
 {
   infrun_debug_printf ("saving status %s for %s",
-		       target_waitstatus_to_string (ws).c_str (),
+		       ws->to_string ().c_str (),
 		       tp->ptid.to_string ().c_str ());
 
   /* Record for later.  */
@@ -4769,7 +4768,7 @@ static bool
 handle_one (const wait_one_event &event)
 {
   infrun_debug_printf
-    ("%s %s", target_waitstatus_to_string (&event.ws).c_str (),
+    ("%s %s", event.ws.to_string ().c_str (),
      event.ptid.to_string ().c_str ());
 
   if (event.ws.kind () == TARGET_WAITKIND_NO_RESUMED)
@@ -4875,7 +4874,7 @@ handle_one (const wait_one_event &event)
 
 	  infrun_debug_printf
 	    ("target_wait %s, saving status for %s",
-	     target_waitstatus_to_string (&event.ws).c_str (),
+	     event.ws.to_string ().c_str (),
 	     t->ptid.to_string ().c_str ());
 
 	  /* Record for later.  */
@@ -5181,7 +5180,7 @@ handle_inferior_event (struct execution_control_state *ecs)
      end.  */
   scoped_value_mark free_values;
 
-  infrun_debug_printf ("%s", target_waitstatus_to_string (&ecs->ws).c_str ());
+  infrun_debug_printf ("%s", ecs->ws.to_string ().c_str ());
 
   if (ecs->ws.kind () == TARGET_WAITKIND_IGNORE)
     {
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index a9518d57bcb..3fcfd6a4761 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -2556,7 +2556,7 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status,
       *status = btrace_step_no_resumed ();
 
       DEBUG ("wait ended by %s: %s", target_pid_to_str (null_ptid).c_str (),
-	     target_waitstatus_to_string (status).c_str ());
+	     status->to_string ().c_str ());
 
       return null_ptid;
     }
@@ -2647,7 +2647,7 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status,
   DEBUG ("wait ended by thread %s (%s): %s",
 	 print_thread_id (eventing),
 	 target_pid_to_str (eventing->ptid).c_str (),
-	 target_waitstatus_to_string (status).c_str ());
+	 status->to_string ().c_str ());
 
   return eventing->ptid;
 }
diff --git a/gdb/target-debug.h b/gdb/target-debug.h
index 5949441bc66..c9bc68b7826 100644
--- a/gdb/target-debug.h
+++ b/gdb/target-debug.h
@@ -180,9 +180,7 @@
 static void
 target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
 {
-  std::string str = target_waitstatus_to_string (status);
-
-  fputs_unfiltered (str.c_str (), gdb_stdlog);
+  fputs_unfiltered (status->to_string ().c_str (), gdb_stdlog);
 }
 
 \f
diff --git a/gdb/target/waitstatus.c b/gdb/target/waitstatus.c
index dc3d75eef6e..2293d83230d 100644
--- a/gdb/target/waitstatus.c
+++ b/gdb/target/waitstatus.c
@@ -23,40 +23,40 @@
 /* Return a pretty printed form of target_waitstatus.  */
 
 std::string
-target_waitstatus_to_string (const struct target_waitstatus *ws)
+target_waitstatus::to_string () const
 {
   const char *kind_str = "status->kind = ";
 
-  switch (ws->kind ())
+  switch (this->kind ())
     {
     case TARGET_WAITKIND_EXITED:
       return string_printf ("%sexited, status = %d",
-			    kind_str, ws->exit_status ());
+			    kind_str, this->exit_status ());
 
     case TARGET_WAITKIND_STOPPED:
       return string_printf ("%sstopped, signal = %s",
 			    kind_str,
-			    gdb_signal_to_symbol_string (ws->sig ()));
+			    gdb_signal_to_symbol_string (this->sig ()));
 
     case TARGET_WAITKIND_SIGNALLED:
       return string_printf ("%ssignalled, signal = %s",
 			    kind_str,
-			    gdb_signal_to_symbol_string (ws->sig ()));
+			    gdb_signal_to_symbol_string (this->sig ()));
 
     case TARGET_WAITKIND_LOADED:
       return string_printf ("%sloaded", kind_str);
 
     case TARGET_WAITKIND_FORKED:
       return string_printf ("%sforked, child_ptid = %s", kind_str,
-			    ws->child_ptid ().to_string ().c_str ());
+			    this->child_ptid ().to_string ().c_str ());
 
     case TARGET_WAITKIND_VFORKED:
       return string_printf ("%svforked, child_ptid = %s", kind_str,
-			    ws->child_ptid ().to_string ().c_str ());
+			    this->child_ptid ().to_string ().c_str ());
 
     case TARGET_WAITKIND_EXECD:
       return string_printf ("%sexecd, execd_pathname = %s", kind_str,
-			    ws->execd_pathname ());
+			    this->execd_pathname ());
 
     case TARGET_WAITKIND_VFORK_DONE:
       return string_printf ("%svfork-done", kind_str);
@@ -84,7 +84,7 @@ target_waitstatus_to_string (const struct target_waitstatus *ws)
 
     case TARGET_WAITKIND_THREAD_EXITED:
       return string_printf ("%sthread exited, status = %d",
-			    kind_str, ws->exit_status ());
+			    kind_str, this->exit_status ());
 
     default:
       return string_printf ("%sunknown???", kind_str);
diff --git a/gdb/target/waitstatus.h b/gdb/target/waitstatus.h
index 333863e6d6e..f5b050b8b82 100644
--- a/gdb/target/waitstatus.h
+++ b/gdb/target/waitstatus.h
@@ -321,6 +321,12 @@ struct target_waitstatus
     return m_value.syscall_number;
   }
 
+  /* Return a pretty printed form of target_waitstatus.
+
+     This is only meant to be used in debug messages, not for user-visible
+     messages.  */
+  std::string to_string () const;
+
 private:
   /* Reset the wait status to its original state.  */
   void reset ()
@@ -371,9 +377,4 @@ enum target_stop_reason
   TARGET_STOPPED_BY_SINGLE_STEP
 };
 
-/* Prototypes */
-
-/* Return a pretty printed form of target_waitstatus.  */
-std::string target_waitstatus_to_string (const struct target_waitstatus *);
-
 #endif /* TARGET_WAITSTATUS_H */
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 34ede238d19..d214aff7051 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -3445,13 +3445,9 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus,
   if (debug_threads)
     {
       if (event_child->waitstatus.kind () != TARGET_WAITKIND_IGNORE)
-	{
-	  std::string str
-	    = target_waitstatus_to_string (&event_child->waitstatus);
-
-	  debug_printf ("LWP %ld: extended event with waitstatus %s\n",
-			lwpid_of (get_lwp_thread (event_child)), str.c_str ());
-	}
+	debug_printf ("LWP %ld: extended event with waitstatus %s\n",
+		      lwpid_of (get_lwp_thread (event_child)),
+		      event_child->waitstatus.to_string ().c_str ());
       if (current_thread->last_resume_kind == resume_step)
 	{
 	  if (event_child->step_range_start == event_child->step_range_end)
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index c58f7e01d8d..2807525d11c 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -3305,14 +3305,9 @@ queue_stop_reply_callback (thread_info *thread)
       if (target_thread_stopped (thread))
 	{
 	  if (debug_threads)
-	    {
-	      std::string status_string
-		= target_waitstatus_to_string (&thread->last_status);
-
-	      debug_printf ("Reporting thread %s as already stopped with %s\n",
-			    target_pid_to_str (thread->id).c_str (),
-			    status_string.c_str ());
-	    }
+	    debug_printf ("Reporting thread %s as already stopped with %s\n",
+			  target_pid_to_str (thread->id).c_str (),
+			  thread->last_status.to_string ().c_str ());
 
 	  gdb_assert (thread->last_status.kind () != TARGET_WAITKIND_IGNORE);
 
-- 
2.33.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string
  2021-11-22 16:27 [PATCH 1/3] gdb: rename target_waitstatus_to_string to target_waitstatus::to_string Simon Marchi
@ 2021-11-22 16:27 ` Simon Marchi
  2021-11-22 18:53   ` Andrew Burgess
  2021-11-25 14:38   ` Vaseeharan Vinayagamoorthy
  2021-11-22 16:27 ` [PATCH 3/3] gdb: pass more const target_waitstatus by reference Simon Marchi
  2021-11-22 18:48 ` [PATCH 1/3] gdb: rename target_waitstatus_to_string to target_waitstatus::to_string Andrew Burgess
  2 siblings, 2 replies; 9+ messages in thread
From: Simon Marchi @ 2021-11-22 16:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

I would like to print target_waitkind values in debug messages, so I
think that a target_waitkind-to-string function would be useful.  While
at it, use it in target_waitstatus::to_string.  This changes the output
of target_waitstatus::to_string a bit, but I think it is for the better.
The debug messages will show a string matching exactly the
target_waitkind enumerator (minus the TARGET_WAITKIND prefix).

As a convenience, make string_appendf return the same reference to
string it got as a parameter.  This allows doing this:

  return string_appendf (str, "foo");

... keeping the code concise.

Change-Id: I383dffc9c78614e7d0668b1516073905e798eef7
---
 gdb/target/waitstatus.c                | 66 +++++++++-----------------
 gdb/target/waitstatus.h                | 49 +++++++++++++++++++
 gdb/unittests/common-utils-selftests.c |  7 ++-
 gdbsupport/common-utils.cc             |  8 +++-
 gdbsupport/common-utils.h              |  4 +-
 5 files changed, 84 insertions(+), 50 deletions(-)

diff --git a/gdb/target/waitstatus.c b/gdb/target/waitstatus.c
index 2293d83230d..a7209e3f2b7 100644
--- a/gdb/target/waitstatus.c
+++ b/gdb/target/waitstatus.c
@@ -20,73 +20,51 @@
 #include "gdbsupport/common-defs.h"
 #include "waitstatus.h"
 
-/* Return a pretty printed form of target_waitstatus.  */
+/* See waitstatus.h.  */
 
 std::string
 target_waitstatus::to_string () const
 {
-  const char *kind_str = "status->kind = ";
+  std::string str = string_printf
+    ("status->kind = %s", target_waitkind_str (this->kind ()));
 
+/* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added
+   but not handled here.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic error "-Wswitch"
   switch (this->kind ())
     {
     case TARGET_WAITKIND_EXITED:
-      return string_printf ("%sexited, status = %d",
-			    kind_str, this->exit_status ());
+    case TARGET_WAITKIND_THREAD_EXITED:
+      return string_appendf (str, ", exit_status = %d", this->exit_status ());
 
     case TARGET_WAITKIND_STOPPED:
-      return string_printf ("%sstopped, signal = %s",
-			    kind_str,
-			    gdb_signal_to_symbol_string (this->sig ()));
-
     case TARGET_WAITKIND_SIGNALLED:
-      return string_printf ("%ssignalled, signal = %s",
-			    kind_str,
-			    gdb_signal_to_symbol_string (this->sig ()));
-
-    case TARGET_WAITKIND_LOADED:
-      return string_printf ("%sloaded", kind_str);
+      return string_appendf (str, ", sig = %s",
+			     gdb_signal_to_symbol_string (this->sig ()));
 
     case TARGET_WAITKIND_FORKED:
-      return string_printf ("%sforked, child_ptid = %s", kind_str,
-			    this->child_ptid ().to_string ().c_str ());
-
     case TARGET_WAITKIND_VFORKED:
-      return string_printf ("%svforked, child_ptid = %s", kind_str,
-			    this->child_ptid ().to_string ().c_str ());
+      return string_appendf (str, ", child_ptid = %s",
+			     this->child_ptid ().to_string ().c_str ());
 
     case TARGET_WAITKIND_EXECD:
-      return string_printf ("%sexecd, execd_pathname = %s", kind_str,
-			    this->execd_pathname ());
+      return string_appendf (str, ", execd_pathname = %s",
+			     this->execd_pathname ());
 
+    case TARGET_WAITKIND_LOADED:
     case TARGET_WAITKIND_VFORK_DONE:
-      return string_printf ("%svfork-done", kind_str);
-
+    case TARGET_WAITKIND_SPURIOUS:
     case TARGET_WAITKIND_SYSCALL_ENTRY:
-      return string_printf ("%sentered syscall", kind_str);
-
     case TARGET_WAITKIND_SYSCALL_RETURN:
-      return string_printf ("%sexited syscall", kind_str);
-
-    case TARGET_WAITKIND_SPURIOUS:
-      return string_printf ("%sspurious", kind_str);
-
     case TARGET_WAITKIND_IGNORE:
-      return string_printf ("%signore", kind_str);
-
     case TARGET_WAITKIND_NO_HISTORY:
-      return string_printf ("%sno-history", kind_str);
-
     case TARGET_WAITKIND_NO_RESUMED:
-      return string_printf ("%sno-resumed", kind_str);
-
     case TARGET_WAITKIND_THREAD_CREATED:
-      return string_printf ("%sthread created", kind_str);
-
-    case TARGET_WAITKIND_THREAD_EXITED:
-      return string_printf ("%sthread exited, status = %d",
-			    kind_str, this->exit_status ());
-
-    default:
-      return string_printf ("%sunknown???", kind_str);
+      return str;
     }
+#pragma GCC diagnostic pop
+
+  gdb_assert_not_reached ("invalid target_waitkind value: %d",
+			  (int) this->kind ());
 }
diff --git a/gdb/target/waitstatus.h b/gdb/target/waitstatus.h
index f5b050b8b82..48405d222f4 100644
--- a/gdb/target/waitstatus.h
+++ b/gdb/target/waitstatus.h
@@ -101,6 +101,55 @@ enum target_waitkind
   TARGET_WAITKIND_THREAD_EXITED,
 };
 
+/* Return KIND as a string.  */
+
+static inline const char *
+target_waitkind_str (target_waitkind kind)
+{
+/* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added
+   but not handled here.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic error "-Wswitch"
+  switch (kind)
+  {
+    case TARGET_WAITKIND_EXITED:
+      return "EXITED";
+    case TARGET_WAITKIND_STOPPED:
+      return "STOPPED";
+    case TARGET_WAITKIND_SIGNALLED:
+      return "SIGNALLED";
+    case TARGET_WAITKIND_LOADED:
+      return "LOADED";
+    case TARGET_WAITKIND_FORKED:
+      return "FORKED";
+    case TARGET_WAITKIND_VFORKED:
+      return "VFORKED";
+    case TARGET_WAITKIND_EXECD:
+      return "EXECD";
+    case TARGET_WAITKIND_VFORK_DONE:
+      return "VFORK_DONE";
+    case TARGET_WAITKIND_SYSCALL_ENTRY:
+      return "SYSCALL_ENTRY";
+    case TARGET_WAITKIND_SYSCALL_RETURN:
+      return "SYSCALL_RETURN";
+    case TARGET_WAITKIND_SPURIOUS:
+      return "SPURIOUS";
+    case TARGET_WAITKIND_IGNORE:
+      return "IGNORE";
+    case TARGET_WAITKIND_NO_HISTORY:
+      return "NO_HISTORY";
+    case TARGET_WAITKIND_NO_RESUMED:
+      return "NO_RESUMED";
+    case TARGET_WAITKIND_THREAD_CREATED:
+      return "THREAD_CREATED";
+    case TARGET_WAITKIND_THREAD_EXITED:
+      return "THREAD_EXITED";
+  };
+#pragma GCC diagnostic pop
+
+  gdb_assert_not_reached ("invalid target_waitkind value: %d\n", (int) kind);
+}
+
 struct target_waitstatus
 {
   /* Default constructor.  */
diff --git a/gdb/unittests/common-utils-selftests.c b/gdb/unittests/common-utils-selftests.c
index 26d313fd329..aa0f45241b9 100644
--- a/gdb/unittests/common-utils-selftests.c
+++ b/gdb/unittests/common-utils-selftests.c
@@ -80,7 +80,8 @@ string_vprintf_tests ()
 /* Type of both 'string_appendf' and the 'string_vappendf_wrapper'
    function below.  Used to run the same tests against both
    string_appendf and string_vappendf.  */
-typedef void (string_appendf_func) (std::string &str, const char *fmt, ...)
+typedef std::string &(string_appendf_func) (std::string &str, const char *fmt,
+					    ...)
   ATTRIBUTE_PRINTF (2, 3);
 
 static void
@@ -101,7 +102,7 @@ test_appendf_func (string_appendf_func *func)
   SELF_CHECK (str == "test23foo 45 bar");
 }
 
-static void ATTRIBUTE_PRINTF (2, 3)
+static std::string & ATTRIBUTE_PRINTF (2, 3)
 string_vappendf_wrapper (std::string &str, const char *fmt, ...)
 {
   va_list vp;
@@ -109,6 +110,8 @@ string_vappendf_wrapper (std::string &str, const char *fmt, ...)
   va_start (vp, fmt);
   string_vappendf (str, fmt, vp);
   va_end (vp);
+
+  return str;
 }
 
 static void
diff --git a/gdbsupport/common-utils.cc b/gdbsupport/common-utils.cc
index 42bce36e535..b591537e62e 100644
--- a/gdbsupport/common-utils.cc
+++ b/gdbsupport/common-utils.cc
@@ -119,7 +119,7 @@ string_vprintf (const char* fmt, va_list args)
 
 /* See documentation in common-utils.h.  */
 
-void
+std::string &
 string_appendf (std::string &str, const char *fmt, ...)
 {
   va_list vp;
@@ -127,12 +127,14 @@ string_appendf (std::string &str, const char *fmt, ...)
   va_start (vp, fmt);
   string_vappendf (str, fmt, vp);
   va_end (vp);
+
+  return str;
 }
 
 
 /* See documentation in common-utils.h.  */
 
-void
+std::string &
 string_vappendf (std::string &str, const char *fmt, va_list args)
 {
   va_list vp;
@@ -148,6 +150,8 @@ string_vappendf (std::string &str, const char *fmt, va_list args)
   /* C++11 and later guarantee std::string uses contiguous memory and
      always includes the terminating '\0'.  */
   vsprintf (&str[curr_size], fmt, args); /* ARI: vsprintf */
+
+  return str;
 }
 
 char *
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index af078475780..98a9dc72f36 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -54,11 +54,11 @@ std::string string_vprintf (const char* fmt, va_list args)
 
 /* Like string_printf, but appends to DEST instead of returning a new
    std::string.  */
-void string_appendf (std::string &dest, const char* fmt, ...)
+std::string &string_appendf (std::string &dest, const char* fmt, ...)
   ATTRIBUTE_PRINTF (2, 3);
 
 /* Like string_appendf, but takes a va_list.  */
-void string_vappendf (std::string &dest, const char* fmt, va_list args)
+std::string &string_vappendf (std::string &dest, const char* fmt, va_list args)
   ATTRIBUTE_PRINTF (2, 0);
 
 /* Make a copy of the string at PTR with LEN characters
-- 
2.33.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/3] gdb: pass more const target_waitstatus by reference
  2021-11-22 16:27 [PATCH 1/3] gdb: rename target_waitstatus_to_string to target_waitstatus::to_string Simon Marchi
  2021-11-22 16:27 ` [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string Simon Marchi
@ 2021-11-22 16:27 ` Simon Marchi
  2021-11-22 18:56   ` Andrew Burgess
  2021-11-22 18:48 ` [PATCH 1/3] gdb: rename target_waitstatus_to_string to target_waitstatus::to_string Andrew Burgess
  2 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2021-11-22 16:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

While working on target_waitstatus changes, I noticed a few places where
const target_waitstatus objects could be passed by reference instead of
by pointers.  And in some cases, places where a target_waitstatus could
be passed as const, but was not.  Convert them as much as possible.

Change-Id: Ied552d464be5d5b87489913b95f9720a5ad50c5a
---
 gdb/break-catch-sig.c     |  6 ++--
 gdb/break-catch-syscall.c |  8 ++---
 gdb/breakpoint.c          | 52 ++++++++++++++++----------------
 gdb/breakpoint.h          | 10 +++----
 gdb/infrun.c              | 62 +++++++++++++++++++--------------------
 gdb/infrun.h              |  2 +-
 gdb/remote.c              | 36 +++++++++++------------
 gdbserver/remote-utils.cc | 45 ++++++++++++++--------------
 gdbserver/remote-utils.h  |  2 +-
 gdbserver/server.cc       | 26 ++++++++--------
 10 files changed, 124 insertions(+), 125 deletions(-)

diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c
index 0998aa95c4f..7fe35dcdb0c 100644
--- a/gdb/break-catch-sig.c
+++ b/gdb/break-catch-sig.c
@@ -149,16 +149,16 @@ static int
 signal_catchpoint_breakpoint_hit (const struct bp_location *bl,
 				  const address_space *aspace,
 				  CORE_ADDR bp_addr,
-				  const struct target_waitstatus *ws)
+				  const target_waitstatus &ws)
 {
   const struct signal_catchpoint *c
     = (const struct signal_catchpoint *) bl->owner;
   gdb_signal signal_number;
 
-  if (ws->kind () != TARGET_WAITKIND_STOPPED)
+  if (ws.kind () != TARGET_WAITKIND_STOPPED)
     return 0;
 
-  signal_number = ws->sig ();
+  signal_number = ws.sig ();
 
   /* If we are catching specific signals in this breakpoint, then we
      must guarantee that the called signal is the same signal we are
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index cb2d77643ca..02123736ff4 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -143,7 +143,7 @@ remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason)
 static int
 breakpoint_hit_catch_syscall (const struct bp_location *bl,
 			      const address_space *aspace, CORE_ADDR bp_addr,
-			      const struct target_waitstatus *ws)
+			      const target_waitstatus &ws)
 {
   /* We must check if we are catching specific syscalls in this
      breakpoint.  If we are, then we must guarantee that the called
@@ -152,11 +152,11 @@ breakpoint_hit_catch_syscall (const struct bp_location *bl,
   const struct syscall_catchpoint *c
     = (const struct syscall_catchpoint *) bl->owner;
 
-  if (ws->kind () != TARGET_WAITKIND_SYSCALL_ENTRY
-      && ws->kind () != TARGET_WAITKIND_SYSCALL_RETURN)
+  if (ws.kind () != TARGET_WAITKIND_SYSCALL_ENTRY
+      && ws.kind () != TARGET_WAITKIND_SYSCALL_RETURN)
     return 0;
 
-  syscall_number = ws->syscall_number ();
+  syscall_number = ws.syscall_number ();
 
   /* Now, checking if the syscall is the same.  */
   if (!c->syscalls_to_be_caught.empty ())
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index d98c3a7cf0f..b1eae3af634 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4771,7 +4771,7 @@ bpstat::bpstat ()
    watchpoints have triggered, according to the target.  */
 
 int
-watchpoints_triggered (struct target_waitstatus *ws)
+watchpoints_triggered (const target_waitstatus &ws)
 {
   bool stopped_by_watchpoint = target_stopped_by_watchpoint ();
   CORE_ADDR addr;
@@ -5014,7 +5014,7 @@ watchpoint_check (bpstat *bs)
 static int
 bpstat_check_location (const struct bp_location *bl,
 		       const address_space *aspace, CORE_ADDR bp_addr,
-		       const struct target_waitstatus *ws)
+		       const target_waitstatus &ws)
 {
   struct breakpoint *b = bl->owner;
 
@@ -5349,7 +5349,7 @@ need_moribund_for_location_type (struct bp_location *loc)
 
 bpstat *
 build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
-		    const struct target_waitstatus *ws)
+		    const target_waitstatus &ws)
 {
   bpstat *bs_head = nullptr, **bs_link = &bs_head;
 
@@ -5425,7 +5425,7 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
 bpstat *
 bpstat_stop_status (const address_space *aspace,
 		    CORE_ADDR bp_addr, thread_info *thread,
-		    const struct target_waitstatus *ws,
+		    const target_waitstatus &ws,
 		    bpstat *stop_chain)
 {
   struct breakpoint *b = NULL;
@@ -7760,14 +7760,14 @@ remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
 static int
 breakpoint_hit_catch_fork (const struct bp_location *bl,
 			   const address_space *aspace, CORE_ADDR bp_addr,
-			   const struct target_waitstatus *ws)
+			   const target_waitstatus &ws)
 {
   struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
 
-  if (ws->kind () != TARGET_WAITKIND_FORKED)
+  if (ws.kind () != TARGET_WAITKIND_FORKED)
     return 0;
 
-  c->forked_inferior_pid = ws->child_ptid ();
+  c->forked_inferior_pid = ws.child_ptid ();
   return 1;
 }
 
@@ -7876,14 +7876,14 @@ remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
 static int
 breakpoint_hit_catch_vfork (const struct bp_location *bl,
 			    const address_space *aspace, CORE_ADDR bp_addr,
-			    const struct target_waitstatus *ws)
+			    const target_waitstatus &ws)
 {
   struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
 
-  if (ws->kind () != TARGET_WAITKIND_VFORKED)
+  if (ws.kind () != TARGET_WAITKIND_VFORKED)
     return 0;
 
-  c->forked_inferior_pid = ws->child_ptid ();
+  c->forked_inferior_pid = ws.child_ptid ();
   return 1;
 }
 
@@ -7998,11 +7998,11 @@ static int
 breakpoint_hit_catch_solib (const struct bp_location *bl,
 			    const address_space *aspace,
 			    CORE_ADDR bp_addr,
-			    const struct target_waitstatus *ws)
+			    const target_waitstatus &ws)
 {
   struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
 
-  if (ws->kind () == TARGET_WAITKIND_LOADED)
+  if (ws.kind () == TARGET_WAITKIND_LOADED)
     return 1;
 
   for (breakpoint *other : all_breakpoints ())
@@ -8274,14 +8274,14 @@ remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
 static int
 breakpoint_hit_catch_exec (const struct bp_location *bl,
 			   const address_space *aspace, CORE_ADDR bp_addr,
-			   const struct target_waitstatus *ws)
+			   const target_waitstatus &ws)
 {
   struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
 
-  if (ws->kind () != TARGET_WAITKIND_EXECD)
+  if (ws.kind () != TARGET_WAITKIND_EXECD)
     return 0;
 
-  c->exec_pathname = make_unique_xstrdup (ws->execd_pathname ());
+  c->exec_pathname = make_unique_xstrdup (ws.execd_pathname ());
   return 1;
 }
 
@@ -9781,10 +9781,10 @@ static int
 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
 				  const address_space *aspace,
 				  CORE_ADDR bp_addr,
-				  const struct target_waitstatus *ws)
+				  const target_waitstatus &ws)
 {
-  if (ws->kind () != TARGET_WAITKIND_STOPPED
-      || ws->sig () != GDB_SIGNAL_TRAP)
+  if (ws.kind () != TARGET_WAITKIND_STOPPED
+      || ws.sig () != GDB_SIGNAL_TRAP)
     return 0;
 
   return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
@@ -10125,7 +10125,7 @@ remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
 static int
 breakpoint_hit_watchpoint (const struct bp_location *bl,
 			   const address_space *aspace, CORE_ADDR bp_addr,
-			   const struct target_waitstatus *ws)
+			   const target_waitstatus &ws)
 {
   struct breakpoint *b = bl->owner;
   struct watchpoint *w = (struct watchpoint *) b;
@@ -12280,7 +12280,7 @@ static int
 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
 				const address_space *aspace,
 				CORE_ADDR bp_addr,
-				const struct target_waitstatus *ws)
+				const target_waitstatus &ws)
 {
   internal_error_pure_virtual_called ();
 }
@@ -12447,10 +12447,10 @@ bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
 static int
 bkpt_breakpoint_hit (const struct bp_location *bl,
 		     const address_space *aspace, CORE_ADDR bp_addr,
-		     const struct target_waitstatus *ws)
+		     const target_waitstatus &ws)
 {
-  if (ws->kind () != TARGET_WAITKIND_STOPPED
-      || ws->sig () != GDB_SIGNAL_TRAP)
+  if (ws.kind () != TARGET_WAITKIND_STOPPED
+      || ws.sig () != GDB_SIGNAL_TRAP)
     return 0;
 
   if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
@@ -12468,7 +12468,7 @@ bkpt_breakpoint_hit (const struct bp_location *bl,
 static int
 dprintf_breakpoint_hit (const struct bp_location *bl,
 			const address_space *aspace, CORE_ADDR bp_addr,
-			const struct target_waitstatus *ws)
+			const target_waitstatus &ws)
 {
   if (dprintf_style == dprintf_style_agent
       && target_can_run_breakpoint_commands ())
@@ -12822,7 +12822,7 @@ tracepoint_re_set (struct breakpoint *b)
 static int
 tracepoint_breakpoint_hit (const struct bp_location *bl,
 			   const address_space *aspace, CORE_ADDR bp_addr,
-			   const struct target_waitstatus *ws)
+			   const target_waitstatus &ws)
 {
   /* By definition, the inferior does not report stops at
      tracepoints.  */
@@ -15194,7 +15194,7 @@ is_non_inline_function (struct breakpoint *b)
 
 int
 pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
-			   const struct target_waitstatus *ws)
+			   const target_waitstatus &ws)
 {
   for (breakpoint *b : all_breakpoints ())
     {
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index c9048d33816..1704d6a3fd7 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -587,7 +587,7 @@ struct breakpoint_ops
   int (*breakpoint_hit) (const struct bp_location *bl,
 			 const address_space *aspace,
 			 CORE_ADDR bp_addr,
-			 const struct target_waitstatus *ws);
+			 const target_waitstatus &ws);
 
   /* Check internal conditions of the breakpoint referred to by BS.
      If we should not stop for this breakpoint, set BS->stop to 0.  */
@@ -948,7 +948,7 @@ extern bpstat *bpstat_copy (bpstat *);
 
 extern bpstat *build_bpstat_chain (const address_space *aspace,
 				  CORE_ADDR bp_addr,
-				  const struct target_waitstatus *ws);
+				  const target_waitstatus &ws);
 
 /* Get a bpstat associated with having just stopped at address
    BP_ADDR in thread PTID.  STOP_CHAIN may be supplied as a previously
@@ -972,7 +972,7 @@ extern bpstat *build_bpstat_chain (const address_space *aspace,
 
 extern bpstat *bpstat_stop_status (const address_space *aspace,
 				  CORE_ADDR pc, thread_info *thread,
-				  const struct target_waitstatus *ws,
+				  const target_waitstatus &ws,
 				  bpstat *stop_chain = nullptr);
 \f
 /* This bpstat_what stuff tells wait_for_inferior what to do with a
@@ -1609,7 +1609,7 @@ extern int insert_single_step_breakpoints (struct gdbarch *);
 
 /* Check if any hardware watchpoints have triggered, according to the
    target.  */
-int watchpoints_triggered (struct target_waitstatus *);
+int watchpoints_triggered (const target_waitstatus &);
 
 /* Helper for transparent breakpoint hiding for memory read and write
    routines.
@@ -1745,7 +1745,7 @@ const std::vector<bp_location *> &all_bp_locations ();
 
 extern int pc_at_non_inline_function (const address_space *aspace,
 				      CORE_ADDR pc,
-				      const struct target_waitstatus *ws);
+				      const target_waitstatus &ws);
 
 extern int user_breakpoint_p (struct breakpoint *);
 
diff --git a/gdb/infrun.c b/gdb/infrun.c
index dba4f33a327..e4739ed14f6 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3470,7 +3470,7 @@ delete_just_stopped_threads_single_step_breakpoints (void)
 
 void
 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
-			   const struct target_waitstatus *ws)
+			   const struct target_waitstatus &ws)
 {
   infrun_debug_printf ("target_wait (%s [%s], status) =",
 		       waiton_ptid.to_string ().c_str (),
@@ -3478,7 +3478,7 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
   infrun_debug_printf ("  %s [%s],",
 		       result_ptid.to_string ().c_str (),
 		       target_pid_to_str (result_ptid).c_str ());
-  infrun_debug_printf ("  %s", ws->to_string ().c_str ());
+  infrun_debug_printf ("  %s", ws.to_string ().c_str ());
 }
 
 /* Select a thread at random, out of those which are resumed and have
@@ -3833,7 +3833,7 @@ prepare_for_detach (void)
 	  event.ptid = do_target_wait_1 (inf, pid_ptid, &event.ws, 0);
 
 	  if (debug_infrun)
-	    print_target_wait_results (pid_ptid, event.ptid, &event.ws);
+	    print_target_wait_results (pid_ptid, event.ptid, event.ws);
 
 	  handle_one (event);
 	}
@@ -3880,7 +3880,7 @@ wait_for_inferior (inferior *inf)
       ecs->target = inf->process_target ();
 
       if (debug_infrun)
-	print_target_wait_results (minus_one_ptid, ecs->ptid, &ecs->ws);
+	print_target_wait_results (minus_one_ptid, ecs->ptid, ecs->ws);
 
       /* Now figure out what to do with the result of the result.  */
       handle_inferior_event (ecs);
@@ -4070,7 +4070,7 @@ fetch_inferior_event ()
     switch_to_target_no_thread (ecs->target);
 
     if (debug_infrun)
-      print_target_wait_results (minus_one_ptid, ecs->ptid, &ecs->ws);
+      print_target_wait_results (minus_one_ptid, ecs->ptid, ecs->ws);
 
     /* If an error happens while handling the event, propagate GDB's
        knowledge of the executing state to the frontend/user running
@@ -4257,7 +4257,7 @@ context_switch (execution_control_state *ecs)
 
 static void
 adjust_pc_after_break (struct thread_info *thread,
-		       const target_waitstatus *ws)
+		       const target_waitstatus &ws)
 {
   struct regcache *regcache;
   struct gdbarch *gdbarch;
@@ -4284,10 +4284,10 @@ adjust_pc_after_break (struct thread_info *thread,
      target with both of these set in GDB history, and it seems unlikely to be
      correct, so gdbarch_have_nonsteppable_watchpoint is not checked here.  */
 
-  if (ws->kind () != TARGET_WAITKIND_STOPPED)
+  if (ws.kind () != TARGET_WAITKIND_STOPPED)
     return;
 
-  if (ws->sig () != GDB_SIGNAL_TRAP)
+  if (ws.sig () != GDB_SIGNAL_TRAP)
     return;
 
   /* In reverse execution, when a breakpoint is hit, the instruction
@@ -4494,7 +4494,7 @@ handle_syscall_event (struct execution_control_state *ecs)
       ecs->event_thread->control.stop_bpstat
 	= bpstat_stop_status (regcache->aspace (),
 			      ecs->event_thread->stop_pc (),
-			      ecs->event_thread, &ecs->ws);
+			      ecs->event_thread, ecs->ws);
 
       if (handle_stop_requested (ecs))
 	return false;
@@ -4593,7 +4593,7 @@ poll_one_curr_target (struct target_waitstatus *ws)
     event_ptid = target_wait (minus_one_ptid, ws, TARGET_WNOHANG);
 
   if (debug_infrun)
-    print_target_wait_results (minus_one_ptid, event_ptid, ws);
+    print_target_wait_results (minus_one_ptid, event_ptid, *ws);
 
   return event_ptid;
 }
@@ -4674,23 +4674,23 @@ wait_one ()
 /* Save the thread's event and stop reason to process it later.  */
 
 static void
-save_waitstatus (struct thread_info *tp, const target_waitstatus *ws)
+save_waitstatus (struct thread_info *tp, const target_waitstatus &ws)
 {
   infrun_debug_printf ("saving status %s for %s",
-		       ws->to_string ().c_str (),
+		       ws.to_string ().c_str (),
 		       tp->ptid.to_string ().c_str ());
 
   /* Record for later.  */
-  tp->set_pending_waitstatus (*ws);
+  tp->set_pending_waitstatus (ws);
 
-  if (ws->kind () == TARGET_WAITKIND_STOPPED
-      && ws->sig () == GDB_SIGNAL_TRAP)
+  if (ws.kind () == TARGET_WAITKIND_STOPPED
+      && ws.sig () == GDB_SIGNAL_TRAP)
     {
       struct regcache *regcache = get_thread_regcache (tp);
       const address_space *aspace = regcache->aspace ();
       CORE_ADDR pc = regcache_read_pc (regcache);
 
-      adjust_pc_after_break (tp, &tp->pending_waitstatus ());
+      adjust_pc_after_break (tp, tp->pending_waitstatus ());
 
       scoped_restore_current_thread restore_thread;
       switch_to_thread (tp);
@@ -4824,7 +4824,7 @@ handle_one (const wait_one_event &event)
 	  switch_to_thread_no_regs (t);
 	  mark_non_executing_threads (event.target, event.ptid,
 				      event.ws);
-	  save_waitstatus (t, &event.ws);
+	  save_waitstatus (t, event.ws);
 	  t->stop_requested = false;
 	}
     }
@@ -4878,7 +4878,7 @@ handle_one (const wait_one_event &event)
 	     t->ptid.to_string ().c_str ());
 
 	  /* Record for later.  */
-	  save_waitstatus (t, &event.ws);
+	  save_waitstatus (t, event.ws);
 
 	  sig = (event.ws.kind () == TARGET_WAITKIND_STOPPED
 		 ? event.ws.sig () : GDB_SIGNAL_0);
@@ -5236,7 +5236,7 @@ handle_inferior_event (struct execution_control_state *ecs)
     }
 
   /* Dependent on valid ECS->EVENT_THREAD.  */
-  adjust_pc_after_break (ecs->event_thread, &ecs->ws);
+  adjust_pc_after_break (ecs->event_thread, ecs->ws);
 
   /* Dependent on the current PC value modified by adjust_pc_after_break.  */
   reinit_frame_cache ();
@@ -5295,7 +5295,7 @@ handle_inferior_event (struct execution_control_state *ecs)
 	    ecs->event_thread->control.stop_bpstat
 	      = bpstat_stop_status (regcache->aspace (),
 				    ecs->event_thread->stop_pc (),
-				    ecs->event_thread, &ecs->ws);
+				    ecs->event_thread, ecs->ws);
 
 	    if (handle_stop_requested (ecs))
 	      return;
@@ -5538,7 +5538,7 @@ handle_inferior_event (struct execution_control_state *ecs)
       ecs->event_thread->control.stop_bpstat
 	= bpstat_stop_status (get_current_regcache ()->aspace (),
 			      ecs->event_thread->stop_pc (),
-			      ecs->event_thread, &ecs->ws);
+			      ecs->event_thread, ecs->ws);
 
       if (handle_stop_requested (ecs))
 	return;
@@ -5649,7 +5649,7 @@ handle_inferior_event (struct execution_control_state *ecs)
       ecs->event_thread->control.stop_bpstat
 	= bpstat_stop_status (get_current_regcache ()->aspace (),
 			      ecs->event_thread->stop_pc (),
-			      ecs->event_thread, &ecs->ws);
+			      ecs->event_thread, ecs->ws);
 
       if (handle_stop_requested (ecs))
 	return;
@@ -5886,7 +5886,7 @@ finish_step_over (struct execution_control_state *ecs)
 	  gdb_assert (pending != tp);
 
 	  /* Record the event thread's event for later.  */
-	  save_waitstatus (tp, &ecs->ws);
+	  save_waitstatus (tp, ecs->ws);
 	  /* This was cleared early, by handle_inferior_event.  Set it
 	     so this pending event is considered by
 	     do_target_wait.  */
@@ -6061,7 +6061,7 @@ handle_signal_stop (struct execution_control_state *ecs)
       && ecs->event_thread->stepping_over_watchpoint)
     stopped_by_watchpoint = 0;
   else
-    stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
+    stopped_by_watchpoint = watchpoints_triggered (ecs->ws);
 
   /* If necessary, step over this watchpoint.  We'll be back to display
      it in a moment.  */
@@ -6134,16 +6134,16 @@ handle_signal_stop (struct execution_control_state *ecs)
 	 that's an extremely unlikely scenario.  */
       if (!pc_at_non_inline_function (aspace,
 				      ecs->event_thread->stop_pc (),
-				      &ecs->ws)
+				      ecs->ws)
 	  && !(ecs->event_thread->stop_signal () == GDB_SIGNAL_TRAP
 	       && ecs->event_thread->control.trap_expected
 	       && pc_at_non_inline_function (aspace,
 					     ecs->event_thread->prev_pc,
-					     &ecs->ws)))
+					     ecs->ws)))
 	{
 	  stop_chain = build_bpstat_chain (aspace,
 					   ecs->event_thread->stop_pc (),
-					   &ecs->ws);
+					   ecs->ws);
 	  skip_inline_frames (ecs->event_thread, stop_chain);
 
 	  /* Re-fetch current thread's frame in case that invalidated
@@ -6195,7 +6195,7 @@ handle_signal_stop (struct execution_control_state *ecs)
   ecs->event_thread->control.stop_bpstat
     = bpstat_stop_status (get_current_regcache ()->aspace (),
 			  ecs->event_thread->stop_pc (),
-			  ecs->event_thread, &ecs->ws, stop_chain);
+			  ecs->event_thread, ecs->ws, stop_chain);
 
   /* Following in case break condition called a
      function.  */
@@ -8258,14 +8258,14 @@ print_no_history_reason (struct ui_out *uiout)
    based on the event(s) that just occurred.  */
 
 static void
-print_stop_location (struct target_waitstatus *ws)
+print_stop_location (const target_waitstatus &ws)
 {
   int bpstat_ret;
   enum print_what source_flag;
   int do_frame_printing = 1;
   struct thread_info *tp = inferior_thread ();
 
-  bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws->kind ());
+  bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws.kind ());
   switch (bpstat_ret)
     {
     case PRINT_UNKNOWN:
@@ -8325,7 +8325,7 @@ print_stop_event (struct ui_out *uiout, bool displays)
   {
     scoped_restore save_uiout = make_scoped_restore (&current_uiout, uiout);
 
-    print_stop_location (&last);
+    print_stop_location (last);
 
     /* Display the auto-display expressions.  */
     if (displays)
diff --git a/gdb/infrun.h b/gdb/infrun.h
index c5f98d9d305..644e57f0bca 100644
--- a/gdb/infrun.h
+++ b/gdb/infrun.h
@@ -209,7 +209,7 @@ extern void print_stop_event (struct ui_out *uiout, bool displays = true);
 /* Pretty print the results of target_wait, for debugging purposes.  */
 
 extern void print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
-				       const struct target_waitstatus *ws);
+				       const struct target_waitstatus &ws);
 
 extern int signal_stop_state (int);
 
diff --git a/gdb/remote.c b/gdb/remote.c
index 61bde5aaa94..724386e0916 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -762,7 +762,7 @@ class remote_target : public process_stratum_target
 			     target_waitstatus *status);
 
   ptid_t select_thread_for_ambiguous_stop_reply
-    (const struct target_waitstatus *status);
+    (const struct target_waitstatus &status);
 
   void remote_notice_new_inferior (ptid_t currthread, bool executing);
 
@@ -4542,7 +4542,7 @@ remote_target::process_initial_stop_replies (int from_tty)
 
       event_ptid = target_wait (waiton_ptid, &ws, TARGET_WNOHANG);
       if (remote_debug)
-	print_target_wait_results (waiton_ptid, event_ptid, &ws);
+	print_target_wait_results (waiton_ptid, event_ptid, ws);
 
       switch (ws.kind ())
 	{
@@ -7224,11 +7224,11 @@ struct notif_client notif_client_stop =
    -1 if we want to check all threads.  */
 
 static int
-is_pending_fork_parent (const target_waitstatus *ws, int event_pid,
+is_pending_fork_parent (const target_waitstatus &ws, int event_pid,
 			ptid_t thread_ptid)
 {
-  if (ws->kind () == TARGET_WAITKIND_FORKED
-      || ws->kind () == TARGET_WAITKIND_VFORKED)
+  if (ws.kind () == TARGET_WAITKIND_FORKED
+      || ws.kind () == TARGET_WAITKIND_VFORKED)
     {
       if (event_pid == -1 || event_pid == thread_ptid.pid ())
 	return 1;
@@ -7240,13 +7240,13 @@ is_pending_fork_parent (const target_waitstatus *ws, int event_pid,
 /* Return the thread's pending status used to determine whether the
    thread is a fork parent stopped at a fork event.  */
 
-static const target_waitstatus *
+static const target_waitstatus &
 thread_pending_fork_status (struct thread_info *thread)
 {
   if (thread->has_pending_waitstatus ())
-    return &thread->pending_waitstatus ();
+    return thread->pending_waitstatus ();
   else
-    return &thread->pending_follow;
+    return thread->pending_follow;
 }
 
 /* Determine if THREAD is a pending fork parent thread.  */
@@ -7254,7 +7254,7 @@ thread_pending_fork_status (struct thread_info *thread)
 static int
 is_pending_fork_parent_thread (struct thread_info *thread)
 {
-  const target_waitstatus *ws = thread_pending_fork_status (thread);
+  const target_waitstatus &ws = thread_pending_fork_status (thread);
   int pid = -1;
 
   return is_pending_fork_parent (ws, pid, thread->ptid);
@@ -7276,10 +7276,10 @@ remote_target::remove_new_fork_children (threads_listing_context *context)
      fork child threads from the CONTEXT list.  */
   for (thread_info *thread : all_non_exited_threads (this))
     {
-      const target_waitstatus *ws = thread_pending_fork_status (thread);
+      const target_waitstatus &ws = thread_pending_fork_status (thread);
 
       if (is_pending_fork_parent (ws, pid, thread->ptid))
-	context->remove_thread (ws->child_ptid ());
+	context->remove_thread (ws.child_ptid ());
     }
 
   /* Check for any pending fork events (not reported or processed yet)
@@ -7940,15 +7940,15 @@ remote_notif_get_pending_events (remote_target *remote, notif_client *nc)
 
 ptid_t
 remote_target::select_thread_for_ambiguous_stop_reply
-  (const struct target_waitstatus *status)
+  (const target_waitstatus &status)
 {
   REMOTE_SCOPED_DEBUG_ENTER_EXIT;
 
   /* Some stop events apply to all threads in an inferior, while others
      only apply to a single thread.  */
   bool process_wide_stop
-    = (status->kind () == TARGET_WAITKIND_EXITED
-       || status->kind () == TARGET_WAITKIND_SIGNALLED);
+    = (status.kind () == TARGET_WAITKIND_EXITED
+       || status.kind () == TARGET_WAITKIND_SIGNALLED);
 
   remote_debug_printf ("process_wide_stop = %d", process_wide_stop);
 
@@ -8030,7 +8030,7 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
   /* If no thread/process was reported by the stub then select a suitable
      thread/process.  */
   if (ptid == null_ptid)
-    ptid = select_thread_for_ambiguous_stop_reply (status);
+    ptid = select_thread_for_ambiguous_stop_reply (*status);
   gdb_assert (ptid != null_ptid);
 
   if (status->kind () != TARGET_WAITKIND_EXITED
@@ -10056,11 +10056,11 @@ remote_target::kill_new_fork_children (int pid)
      that are stopped at a fork event.  */
   for (thread_info *thread : all_non_exited_threads (this))
     {
-      struct target_waitstatus *ws = &thread->pending_follow;
+      const target_waitstatus &ws = thread->pending_follow;
 
       if (is_pending_fork_parent (ws, pid, thread->ptid))
 	{
-	  int child_pid = ws->child_ptid ().pid ();
+	  int child_pid = ws.child_ptid ().pid ();
 	  int res;
 
 	  res = remote_vkill (child_pid);
@@ -10073,7 +10073,7 @@ remote_target::kill_new_fork_children (int pid)
      in process PID and kill those fork child threads as well.  */
   remote_notif_get_pending_events (notif);
   for (auto &event : rs->stop_reply_queue)
-    if (is_pending_fork_parent (&event->ws, pid, event->ptid))
+    if (is_pending_fork_parent (event->ws, pid, event->ptid))
       {
 	int child_pid = event->ws.child_ptid ().pid ();
 	int res;
diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
index 5bc261a9c7b..8202365350a 100644
--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -1081,15 +1081,14 @@ outreg (struct regcache *regcache, int regno, char *buf)
 }
 
 void
-prepare_resume_reply (char *buf, ptid_t ptid,
-		      struct target_waitstatus *status)
+prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
 {
   client_state &cs = get_client_state ();
   if (debug_threads)
     debug_printf ("Writing resume reply for %s:%d\n",
-		  target_pid_to_str (ptid).c_str (), status->kind ());
+		  target_pid_to_str (ptid).c_str (), status.kind ());
 
-  switch (status->kind ())
+  switch (status.kind ())
     {
     case TARGET_WAITKIND_STOPPED:
     case TARGET_WAITKIND_FORKED:
@@ -1104,27 +1103,27 @@ prepare_resume_reply (char *buf, ptid_t ptid,
 	const char **regp;
 	struct regcache *regcache;
 
-	if ((status->kind () == TARGET_WAITKIND_FORKED && cs.report_fork_events)
-	    || (status->kind () == TARGET_WAITKIND_VFORKED
+	if ((status.kind () == TARGET_WAITKIND_FORKED && cs.report_fork_events)
+	    || (status.kind () == TARGET_WAITKIND_VFORKED
 		&& cs.report_vfork_events))
 	  {
 	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
-	    const char *event = (status->kind () == TARGET_WAITKIND_FORKED
+	    const char *event = (status.kind () == TARGET_WAITKIND_FORKED
 				 ? "fork" : "vfork");
 
 	    sprintf (buf, "T%02x%s:", signal, event);
 	    buf += strlen (buf);
-	    buf = write_ptid (buf, status->child_ptid ());
+	    buf = write_ptid (buf, status.child_ptid ());
 	    strcat (buf, ";");
 	  }
-	else if (status->kind () == TARGET_WAITKIND_VFORK_DONE
+	else if (status.kind () == TARGET_WAITKIND_VFORK_DONE
 		 && cs.report_vfork_events)
 	  {
 	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
 
 	    sprintf (buf, "T%02xvforkdone:;", signal);
 	  }
-	else if (status->kind () == TARGET_WAITKIND_EXECD && cs.report_exec_events)
+	else if (status.kind () == TARGET_WAITKIND_EXECD && cs.report_exec_events)
 	  {
 	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
 	    const char *event = "exec";
@@ -1134,32 +1133,32 @@ prepare_resume_reply (char *buf, ptid_t ptid,
 	    buf += strlen (buf);
 
 	    /* Encode pathname to hexified format.  */
-	    bin2hex ((const gdb_byte *) status->execd_pathname (),
+	    bin2hex ((const gdb_byte *) status.execd_pathname (),
 		     hexified_pathname,
-		     strlen (status->execd_pathname ()));
+		     strlen (status.execd_pathname ()));
 
 	    sprintf (buf, "%s;", hexified_pathname);
 	    buf += strlen (buf);
 	  }
-	else if (status->kind () == TARGET_WAITKIND_THREAD_CREATED
+	else if (status.kind () == TARGET_WAITKIND_THREAD_CREATED
 		 && cs.report_thread_events)
 	  {
 	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
 
 	    sprintf (buf, "T%02xcreate:;", signal);
 	  }
-	else if (status->kind () == TARGET_WAITKIND_SYSCALL_ENTRY
-		 || status->kind () == TARGET_WAITKIND_SYSCALL_RETURN)
+	else if (status.kind () == TARGET_WAITKIND_SYSCALL_ENTRY
+		 || status.kind () == TARGET_WAITKIND_SYSCALL_RETURN)
 	  {
 	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
-	    const char *event = (status->kind () == TARGET_WAITKIND_SYSCALL_ENTRY
+	    const char *event = (status.kind () == TARGET_WAITKIND_SYSCALL_ENTRY
 				 ? "syscall_entry" : "syscall_return");
 
 	    sprintf (buf, "T%02x%s:%x;", signal, event,
-		     status->syscall_number ());
+		     status.syscall_number ());
 	  }
 	else
-	  sprintf (buf, "T%02x", status->sig ());
+	  sprintf (buf, "T%02x", status.sig ());
 
 	if (disable_packet_T)
 	  {
@@ -1281,19 +1280,19 @@ prepare_resume_reply (char *buf, ptid_t ptid,
     case TARGET_WAITKIND_EXITED:
       if (cs.multi_process)
 	sprintf (buf, "W%x;process:%x",
-		 status->exit_status (), ptid.pid ());
+		 status.exit_status (), ptid.pid ());
       else
-	sprintf (buf, "W%02x", status->exit_status ());
+	sprintf (buf, "W%02x", status.exit_status ());
       break;
     case TARGET_WAITKIND_SIGNALLED:
       if (cs.multi_process)
 	sprintf (buf, "X%x;process:%x",
-		 status->sig (), ptid.pid ());
+		 status.sig (), ptid.pid ());
       else
-	sprintf (buf, "X%02x", status->sig ());
+	sprintf (buf, "X%02x", status.sig ());
       break;
     case TARGET_WAITKIND_THREAD_EXITED:
-      sprintf (buf, "w%x;", status->exit_status ());
+      sprintf (buf, "w%x;", status.exit_status ());
       buf += strlen (buf);
       buf = write_ptid (buf, ptid);
       break;
diff --git a/gdbserver/remote-utils.h b/gdbserver/remote-utils.h
index 25074bcc2b9..b856862d367 100644
--- a/gdbserver/remote-utils.h
+++ b/gdbserver/remote-utils.h
@@ -41,7 +41,7 @@ void enable_async_io (void);
 void disable_async_io (void);
 void check_remote_input_interrupt_request (void);
 void prepare_resume_reply (char *buf, ptid_t ptid,
-			   struct target_waitstatus *status);
+			   const target_waitstatus &status);
 
 const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start);
 void decode_address (CORE_ADDR *addrp, const char *start, int len);
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 2807525d11c..b1d4c92b3d9 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -173,12 +173,12 @@ get_client_state ()
 /* Put a stop reply to the stop reply queue.  */
 
 static void
-queue_stop_reply (ptid_t ptid, struct target_waitstatus *status)
+queue_stop_reply (ptid_t ptid, const target_waitstatus &status)
 {
   struct vstop_notif *new_notif = new struct vstop_notif;
 
   new_notif->ptid = ptid;
-  new_notif->status = *status;
+  new_notif->status = status;
 
   notif_event_enque (&notif_stop, new_notif);
 }
@@ -225,7 +225,7 @@ vstop_notif_reply (struct notif_event *event, char *own_buf)
 {
   struct vstop_notif *vstop = (struct vstop_notif *) event;
 
-  prepare_resume_reply (own_buf, vstop->ptid, &vstop->status);
+  prepare_resume_reply (own_buf, vstop->ptid, vstop->status);
 }
 
 /* Helper for in_queued_stop_replies.  */
@@ -2795,7 +2795,7 @@ handle_pending_status (const struct thread_resume *resumption,
 
       cs.last_status = thread->last_status;
       cs.last_ptid = thread->id;
-      prepare_resume_reply (cs.own_buf, cs.last_ptid, &cs.last_status);
+      prepare_resume_reply (cs.own_buf, cs.last_ptid, cs.last_status);
       return 1;
     }
   return 0;
@@ -2963,7 +2963,7 @@ resume (struct thread_resume *actions, size_t num_actions)
 	 so by now).  Tag all threads as "want-stopped", so we don't
 	 resume them implicitly without the client telling us to.  */
       gdb_wants_all_threads_stopped ();
-      prepare_resume_reply (cs.own_buf, cs.last_ptid, &cs.last_status);
+      prepare_resume_reply (cs.own_buf, cs.last_ptid, cs.last_status);
       disable_async_io ();
 
       if (cs.last_status.kind () == TARGET_WAITKIND_EXITED
@@ -2996,7 +2996,7 @@ handle_v_attach (char *own_buf)
 	  write_ok (own_buf);
 	}
       else
-	prepare_resume_reply (own_buf, cs.last_ptid, &cs.last_status);
+	prepare_resume_reply (own_buf, cs.last_ptid, cs.last_status);
     }
   else
     write_enn (own_buf);
@@ -3114,7 +3114,7 @@ handle_v_run (char *own_buf)
 
   if (cs.last_status.kind () == TARGET_WAITKIND_STOPPED)
     {
-      prepare_resume_reply (own_buf, cs.last_ptid, &cs.last_status);
+      prepare_resume_reply (own_buf, cs.last_ptid, cs.last_status);
 
       /* In non-stop, sending a resume reply doesn't set the general
 	 thread, but GDB assumes a vRun sets it (this is so GDB can
@@ -3313,7 +3313,7 @@ queue_stop_reply_callback (thread_info *thread)
 
 	  /* Pass the last stop reply back to GDB, but don't notify
 	     yet.  */
-	  queue_stop_reply (thread->id, &thread->last_status);
+	  queue_stop_reply (thread->id, thread->last_status);
 	}
     }
 }
@@ -3436,7 +3436,7 @@ handle_status (char *own_buf)
 	  set_desired_thread ();
 
 	  gdb_assert (tp->last_status.kind () != TARGET_WAITKIND_IGNORE);
-	  prepare_resume_reply (own_buf, tp->id, &tp->last_status);
+	  prepare_resume_reply (own_buf, tp->id, tp->last_status);
 	}
       else
 	strcpy (own_buf, "W00");
@@ -4562,11 +4562,11 @@ handle_serial_event (int err, gdb_client_data client_data)
 /* Push a stop notification on the notification queue.  */
 
 static void
-push_stop_notification (ptid_t ptid, struct target_waitstatus *status)
+push_stop_notification (ptid_t ptid, const target_waitstatus &status)
 {
   struct vstop_notif *vstop_notif = new struct vstop_notif;
 
-  vstop_notif->status = *status;
+  vstop_notif->status = status;
   vstop_notif->ptid = ptid;
   /* Push Stop notification.  */
   notif_push (&notif_stop, vstop_notif);
@@ -4587,7 +4587,7 @@ handle_target_event (int err, gdb_client_data client_data)
   if (cs.last_status.kind () == TARGET_WAITKIND_NO_RESUMED)
     {
       if (gdb_connected () && report_no_resumed)
-	push_stop_notification (null_ptid, &cs.last_status);
+	push_stop_notification (null_ptid, cs.last_status);
     }
   else if (cs.last_status.kind () != TARGET_WAITKIND_IGNORE)
     {
@@ -4645,7 +4645,7 @@ handle_target_event (int err, gdb_client_data client_data)
 	    }
 	}
       else
-	push_stop_notification (cs.last_ptid, &cs.last_status);
+	push_stop_notification (cs.last_ptid, cs.last_status);
     }
 
   /* Be sure to not change the selected thread behind GDB's back.
-- 
2.33.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] gdb: rename target_waitstatus_to_string to target_waitstatus::to_string
  2021-11-22 16:27 [PATCH 1/3] gdb: rename target_waitstatus_to_string to target_waitstatus::to_string Simon Marchi
  2021-11-22 16:27 ` [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string Simon Marchi
  2021-11-22 16:27 ` [PATCH 3/3] gdb: pass more const target_waitstatus by reference Simon Marchi
@ 2021-11-22 18:48 ` Andrew Burgess
  2 siblings, 0 replies; 9+ messages in thread
From: Andrew Burgess @ 2021-11-22 18:48 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

* Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-11-22 11:27:29 -0500]:

> Make target_waitstatus_to_string a "to_string" method of
> target_waitstatus, a bit like we have ptid_t::to_string already.  This
> will save a bit of typing.

LGTM.

Thanks,
Andrew


> 
> Change-Id: Id261b7a09fa9fa3c738abac131c191a6f9c13905
> ---
>  gdb/gnu-nat.c           |  2 +-
>  gdb/infrun.c            | 17 ++++++++---------
>  gdb/record-btrace.c     |  4 ++--
>  gdb/target-debug.h      |  4 +---
>  gdb/target/waitstatus.c | 18 +++++++++---------
>  gdb/target/waitstatus.h | 11 ++++++-----
>  gdbserver/linux-low.cc  | 10 +++-------
>  gdbserver/server.cc     | 11 +++--------
>  8 files changed, 33 insertions(+), 44 deletions(-)
> 
> diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
> index c6cecff0686..216d178424f 100644
> --- a/gdb/gnu-nat.c
> +++ b/gdb/gnu-nat.c
> @@ -1619,7 +1619,7 @@ gnu_nat_target::wait (ptid_t ptid, struct target_waitstatus *status,
>  
>    inf_debug (inf, "returning ptid = %s, %s",
>  	     target_pid_to_str (ptid).c_str (),
> -	     target_waitstatus_to_string (status).c_str ());
> +	     status->to_string ().c_str ());
>  
>    return ptid;
>  }
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index 89a98c20df4..dba4f33a327 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -2214,7 +2214,7 @@ resume_1 (enum gdb_signal sig)
>  	("thread %s has pending wait "
>  	 "status %s (currently_stepping=%d).",
>  	 tp->ptid.to_string ().c_str (),
> -	 target_waitstatus_to_string (&tp->pending_waitstatus ()).c_str (),
> +	 tp->pending_waitstatus ().to_string ().c_str (),
>  	 currently_stepping (tp));
>  
>        tp->inf->process_target ()->threads_executing = true;
> @@ -2632,7 +2632,7 @@ clear_proceed_status_thread (struct thread_info *tp)
>  	  infrun_debug_printf
>  	    ("thread %s has pending wait status %s (currently_stepping=%d).",
>  	     tp->ptid.to_string ().c_str (),
> -	     target_waitstatus_to_string (&tp->pending_waitstatus ()).c_str (),
> +	     tp->pending_waitstatus ().to_string ().c_str (),
>  	     currently_stepping (tp));
>  	}
>      }
> @@ -3478,7 +3478,7 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
>    infrun_debug_printf ("  %s [%s],",
>  		       result_ptid.to_string ().c_str (),
>  		       target_pid_to_str (result_ptid).c_str ());
> -  infrun_debug_printf ("  %s", target_waitstatus_to_string (ws).c_str ());
> +  infrun_debug_printf ("  %s", ws->to_string ().c_str ());
>  }
>  
>  /* Select a thread at random, out of those which are resumed and have
> @@ -3584,8 +3584,7 @@ do_target_wait_1 (inferior *inf, ptid_t ptid,
>    if (tp != NULL)
>      {
>        infrun_debug_printf ("Using pending wait status %s for %s.",
> -			   target_waitstatus_to_string
> -			     (&tp->pending_waitstatus ()).c_str (),
> +			   tp->pending_waitstatus ().to_string ().c_str (),
>  			   tp->ptid.to_string ().c_str ());
>  
>        /* Now that we've selected our final event LWP, un-adjust its PC
> @@ -4678,7 +4677,7 @@ static void
>  save_waitstatus (struct thread_info *tp, const target_waitstatus *ws)
>  {
>    infrun_debug_printf ("saving status %s for %s",
> -		       target_waitstatus_to_string (ws).c_str (),
> +		       ws->to_string ().c_str (),
>  		       tp->ptid.to_string ().c_str ());
>  
>    /* Record for later.  */
> @@ -4769,7 +4768,7 @@ static bool
>  handle_one (const wait_one_event &event)
>  {
>    infrun_debug_printf
> -    ("%s %s", target_waitstatus_to_string (&event.ws).c_str (),
> +    ("%s %s", event.ws.to_string ().c_str (),
>       event.ptid.to_string ().c_str ());
>  
>    if (event.ws.kind () == TARGET_WAITKIND_NO_RESUMED)
> @@ -4875,7 +4874,7 @@ handle_one (const wait_one_event &event)
>  
>  	  infrun_debug_printf
>  	    ("target_wait %s, saving status for %s",
> -	     target_waitstatus_to_string (&event.ws).c_str (),
> +	     event.ws.to_string ().c_str (),
>  	     t->ptid.to_string ().c_str ());
>  
>  	  /* Record for later.  */
> @@ -5181,7 +5180,7 @@ handle_inferior_event (struct execution_control_state *ecs)
>       end.  */
>    scoped_value_mark free_values;
>  
> -  infrun_debug_printf ("%s", target_waitstatus_to_string (&ecs->ws).c_str ());
> +  infrun_debug_printf ("%s", ecs->ws.to_string ().c_str ());
>  
>    if (ecs->ws.kind () == TARGET_WAITKIND_IGNORE)
>      {
> diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
> index a9518d57bcb..3fcfd6a4761 100644
> --- a/gdb/record-btrace.c
> +++ b/gdb/record-btrace.c
> @@ -2556,7 +2556,7 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status,
>        *status = btrace_step_no_resumed ();
>  
>        DEBUG ("wait ended by %s: %s", target_pid_to_str (null_ptid).c_str (),
> -	     target_waitstatus_to_string (status).c_str ());
> +	     status->to_string ().c_str ());
>  
>        return null_ptid;
>      }
> @@ -2647,7 +2647,7 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status,
>    DEBUG ("wait ended by thread %s (%s): %s",
>  	 print_thread_id (eventing),
>  	 target_pid_to_str (eventing->ptid).c_str (),
> -	 target_waitstatus_to_string (status).c_str ());
> +	 status->to_string ().c_str ());
>  
>    return eventing->ptid;
>  }
> diff --git a/gdb/target-debug.h b/gdb/target-debug.h
> index 5949441bc66..c9bc68b7826 100644
> --- a/gdb/target-debug.h
> +++ b/gdb/target-debug.h
> @@ -180,9 +180,7 @@
>  static void
>  target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
>  {
> -  std::string str = target_waitstatus_to_string (status);
> -
> -  fputs_unfiltered (str.c_str (), gdb_stdlog);
> +  fputs_unfiltered (status->to_string ().c_str (), gdb_stdlog);
>  }
>  
>  \f
> diff --git a/gdb/target/waitstatus.c b/gdb/target/waitstatus.c
> index dc3d75eef6e..2293d83230d 100644
> --- a/gdb/target/waitstatus.c
> +++ b/gdb/target/waitstatus.c
> @@ -23,40 +23,40 @@
>  /* Return a pretty printed form of target_waitstatus.  */
>  
>  std::string
> -target_waitstatus_to_string (const struct target_waitstatus *ws)
> +target_waitstatus::to_string () const
>  {
>    const char *kind_str = "status->kind = ";
>  
> -  switch (ws->kind ())
> +  switch (this->kind ())
>      {
>      case TARGET_WAITKIND_EXITED:
>        return string_printf ("%sexited, status = %d",
> -			    kind_str, ws->exit_status ());
> +			    kind_str, this->exit_status ());
>  
>      case TARGET_WAITKIND_STOPPED:
>        return string_printf ("%sstopped, signal = %s",
>  			    kind_str,
> -			    gdb_signal_to_symbol_string (ws->sig ()));
> +			    gdb_signal_to_symbol_string (this->sig ()));
>  
>      case TARGET_WAITKIND_SIGNALLED:
>        return string_printf ("%ssignalled, signal = %s",
>  			    kind_str,
> -			    gdb_signal_to_symbol_string (ws->sig ()));
> +			    gdb_signal_to_symbol_string (this->sig ()));
>  
>      case TARGET_WAITKIND_LOADED:
>        return string_printf ("%sloaded", kind_str);
>  
>      case TARGET_WAITKIND_FORKED:
>        return string_printf ("%sforked, child_ptid = %s", kind_str,
> -			    ws->child_ptid ().to_string ().c_str ());
> +			    this->child_ptid ().to_string ().c_str ());
>  
>      case TARGET_WAITKIND_VFORKED:
>        return string_printf ("%svforked, child_ptid = %s", kind_str,
> -			    ws->child_ptid ().to_string ().c_str ());
> +			    this->child_ptid ().to_string ().c_str ());
>  
>      case TARGET_WAITKIND_EXECD:
>        return string_printf ("%sexecd, execd_pathname = %s", kind_str,
> -			    ws->execd_pathname ());
> +			    this->execd_pathname ());
>  
>      case TARGET_WAITKIND_VFORK_DONE:
>        return string_printf ("%svfork-done", kind_str);
> @@ -84,7 +84,7 @@ target_waitstatus_to_string (const struct target_waitstatus *ws)
>  
>      case TARGET_WAITKIND_THREAD_EXITED:
>        return string_printf ("%sthread exited, status = %d",
> -			    kind_str, ws->exit_status ());
> +			    kind_str, this->exit_status ());
>  
>      default:
>        return string_printf ("%sunknown???", kind_str);
> diff --git a/gdb/target/waitstatus.h b/gdb/target/waitstatus.h
> index 333863e6d6e..f5b050b8b82 100644
> --- a/gdb/target/waitstatus.h
> +++ b/gdb/target/waitstatus.h
> @@ -321,6 +321,12 @@ struct target_waitstatus
>      return m_value.syscall_number;
>    }
>  
> +  /* Return a pretty printed form of target_waitstatus.
> +
> +     This is only meant to be used in debug messages, not for user-visible
> +     messages.  */
> +  std::string to_string () const;
> +
>  private:
>    /* Reset the wait status to its original state.  */
>    void reset ()
> @@ -371,9 +377,4 @@ enum target_stop_reason
>    TARGET_STOPPED_BY_SINGLE_STEP
>  };
>  
> -/* Prototypes */
> -
> -/* Return a pretty printed form of target_waitstatus.  */
> -std::string target_waitstatus_to_string (const struct target_waitstatus *);
> -
>  #endif /* TARGET_WAITSTATUS_H */
> diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
> index 34ede238d19..d214aff7051 100644
> --- a/gdbserver/linux-low.cc
> +++ b/gdbserver/linux-low.cc
> @@ -3445,13 +3445,9 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus,
>    if (debug_threads)
>      {
>        if (event_child->waitstatus.kind () != TARGET_WAITKIND_IGNORE)
> -	{
> -	  std::string str
> -	    = target_waitstatus_to_string (&event_child->waitstatus);
> -
> -	  debug_printf ("LWP %ld: extended event with waitstatus %s\n",
> -			lwpid_of (get_lwp_thread (event_child)), str.c_str ());
> -	}
> +	debug_printf ("LWP %ld: extended event with waitstatus %s\n",
> +		      lwpid_of (get_lwp_thread (event_child)),
> +		      event_child->waitstatus.to_string ().c_str ());
>        if (current_thread->last_resume_kind == resume_step)
>  	{
>  	  if (event_child->step_range_start == event_child->step_range_end)
> diff --git a/gdbserver/server.cc b/gdbserver/server.cc
> index c58f7e01d8d..2807525d11c 100644
> --- a/gdbserver/server.cc
> +++ b/gdbserver/server.cc
> @@ -3305,14 +3305,9 @@ queue_stop_reply_callback (thread_info *thread)
>        if (target_thread_stopped (thread))
>  	{
>  	  if (debug_threads)
> -	    {
> -	      std::string status_string
> -		= target_waitstatus_to_string (&thread->last_status);
> -
> -	      debug_printf ("Reporting thread %s as already stopped with %s\n",
> -			    target_pid_to_str (thread->id).c_str (),
> -			    status_string.c_str ());
> -	    }
> +	    debug_printf ("Reporting thread %s as already stopped with %s\n",
> +			  target_pid_to_str (thread->id).c_str (),
> +			  thread->last_status.to_string ().c_str ());
>  
>  	  gdb_assert (thread->last_status.kind () != TARGET_WAITKIND_IGNORE);
>  
> -- 
> 2.33.1
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string
  2021-11-22 16:27 ` [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string Simon Marchi
@ 2021-11-22 18:53   ` Andrew Burgess
  2021-11-25 14:38   ` Vaseeharan Vinayagamoorthy
  1 sibling, 0 replies; 9+ messages in thread
From: Andrew Burgess @ 2021-11-22 18:53 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

* Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-11-22 11:27:30 -0500]:

> I would like to print target_waitkind values in debug messages, so I
> think that a target_waitkind-to-string function would be useful.  While
> at it, use it in target_waitstatus::to_string.  This changes the output
> of target_waitstatus::to_string a bit, but I think it is for the better.
> The debug messages will show a string matching exactly the
> target_waitkind enumerator (minus the TARGET_WAITKIND prefix).
> 
> As a convenience, make string_appendf return the same reference to
> string it got as a parameter.  This allows doing this:
> 
>   return string_appendf (str, "foo");
> 
> ... keeping the code concise.

LGTM.

Thanks,
Andrew

> 
> Change-Id: I383dffc9c78614e7d0668b1516073905e798eef7
> ---
>  gdb/target/waitstatus.c                | 66 +++++++++-----------------
>  gdb/target/waitstatus.h                | 49 +++++++++++++++++++
>  gdb/unittests/common-utils-selftests.c |  7 ++-
>  gdbsupport/common-utils.cc             |  8 +++-
>  gdbsupport/common-utils.h              |  4 +-
>  5 files changed, 84 insertions(+), 50 deletions(-)
> 
> diff --git a/gdb/target/waitstatus.c b/gdb/target/waitstatus.c
> index 2293d83230d..a7209e3f2b7 100644
> --- a/gdb/target/waitstatus.c
> +++ b/gdb/target/waitstatus.c
> @@ -20,73 +20,51 @@
>  #include "gdbsupport/common-defs.h"
>  #include "waitstatus.h"
>  
> -/* Return a pretty printed form of target_waitstatus.  */
> +/* See waitstatus.h.  */
>  
>  std::string
>  target_waitstatus::to_string () const
>  {
> -  const char *kind_str = "status->kind = ";
> +  std::string str = string_printf
> +    ("status->kind = %s", target_waitkind_str (this->kind ()));
>  
> +/* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added
> +   but not handled here.  */
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic error "-Wswitch"
>    switch (this->kind ())
>      {
>      case TARGET_WAITKIND_EXITED:
> -      return string_printf ("%sexited, status = %d",
> -			    kind_str, this->exit_status ());
> +    case TARGET_WAITKIND_THREAD_EXITED:
> +      return string_appendf (str, ", exit_status = %d", this->exit_status ());
>  
>      case TARGET_WAITKIND_STOPPED:
> -      return string_printf ("%sstopped, signal = %s",
> -			    kind_str,
> -			    gdb_signal_to_symbol_string (this->sig ()));
> -
>      case TARGET_WAITKIND_SIGNALLED:
> -      return string_printf ("%ssignalled, signal = %s",
> -			    kind_str,
> -			    gdb_signal_to_symbol_string (this->sig ()));
> -
> -    case TARGET_WAITKIND_LOADED:
> -      return string_printf ("%sloaded", kind_str);
> +      return string_appendf (str, ", sig = %s",
> +			     gdb_signal_to_symbol_string (this->sig ()));
>  
>      case TARGET_WAITKIND_FORKED:
> -      return string_printf ("%sforked, child_ptid = %s", kind_str,
> -			    this->child_ptid ().to_string ().c_str ());
> -
>      case TARGET_WAITKIND_VFORKED:
> -      return string_printf ("%svforked, child_ptid = %s", kind_str,
> -			    this->child_ptid ().to_string ().c_str ());
> +      return string_appendf (str, ", child_ptid = %s",
> +			     this->child_ptid ().to_string ().c_str ());
>  
>      case TARGET_WAITKIND_EXECD:
> -      return string_printf ("%sexecd, execd_pathname = %s", kind_str,
> -			    this->execd_pathname ());
> +      return string_appendf (str, ", execd_pathname = %s",
> +			     this->execd_pathname ());
>  
> +    case TARGET_WAITKIND_LOADED:
>      case TARGET_WAITKIND_VFORK_DONE:
> -      return string_printf ("%svfork-done", kind_str);
> -
> +    case TARGET_WAITKIND_SPURIOUS:
>      case TARGET_WAITKIND_SYSCALL_ENTRY:
> -      return string_printf ("%sentered syscall", kind_str);
> -
>      case TARGET_WAITKIND_SYSCALL_RETURN:
> -      return string_printf ("%sexited syscall", kind_str);
> -
> -    case TARGET_WAITKIND_SPURIOUS:
> -      return string_printf ("%sspurious", kind_str);
> -
>      case TARGET_WAITKIND_IGNORE:
> -      return string_printf ("%signore", kind_str);
> -
>      case TARGET_WAITKIND_NO_HISTORY:
> -      return string_printf ("%sno-history", kind_str);
> -
>      case TARGET_WAITKIND_NO_RESUMED:
> -      return string_printf ("%sno-resumed", kind_str);
> -
>      case TARGET_WAITKIND_THREAD_CREATED:
> -      return string_printf ("%sthread created", kind_str);
> -
> -    case TARGET_WAITKIND_THREAD_EXITED:
> -      return string_printf ("%sthread exited, status = %d",
> -			    kind_str, this->exit_status ());
> -
> -    default:
> -      return string_printf ("%sunknown???", kind_str);
> +      return str;
>      }
> +#pragma GCC diagnostic pop
> +
> +  gdb_assert_not_reached ("invalid target_waitkind value: %d",
> +			  (int) this->kind ());
>  }
> diff --git a/gdb/target/waitstatus.h b/gdb/target/waitstatus.h
> index f5b050b8b82..48405d222f4 100644
> --- a/gdb/target/waitstatus.h
> +++ b/gdb/target/waitstatus.h
> @@ -101,6 +101,55 @@ enum target_waitkind
>    TARGET_WAITKIND_THREAD_EXITED,
>  };
>  
> +/* Return KIND as a string.  */
> +
> +static inline const char *
> +target_waitkind_str (target_waitkind kind)
> +{
> +/* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added
> +   but not handled here.  */
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic error "-Wswitch"
> +  switch (kind)
> +  {
> +    case TARGET_WAITKIND_EXITED:
> +      return "EXITED";
> +    case TARGET_WAITKIND_STOPPED:
> +      return "STOPPED";
> +    case TARGET_WAITKIND_SIGNALLED:
> +      return "SIGNALLED";
> +    case TARGET_WAITKIND_LOADED:
> +      return "LOADED";
> +    case TARGET_WAITKIND_FORKED:
> +      return "FORKED";
> +    case TARGET_WAITKIND_VFORKED:
> +      return "VFORKED";
> +    case TARGET_WAITKIND_EXECD:
> +      return "EXECD";
> +    case TARGET_WAITKIND_VFORK_DONE:
> +      return "VFORK_DONE";
> +    case TARGET_WAITKIND_SYSCALL_ENTRY:
> +      return "SYSCALL_ENTRY";
> +    case TARGET_WAITKIND_SYSCALL_RETURN:
> +      return "SYSCALL_RETURN";
> +    case TARGET_WAITKIND_SPURIOUS:
> +      return "SPURIOUS";
> +    case TARGET_WAITKIND_IGNORE:
> +      return "IGNORE";
> +    case TARGET_WAITKIND_NO_HISTORY:
> +      return "NO_HISTORY";
> +    case TARGET_WAITKIND_NO_RESUMED:
> +      return "NO_RESUMED";
> +    case TARGET_WAITKIND_THREAD_CREATED:
> +      return "THREAD_CREATED";
> +    case TARGET_WAITKIND_THREAD_EXITED:
> +      return "THREAD_EXITED";
> +  };
> +#pragma GCC diagnostic pop
> +
> +  gdb_assert_not_reached ("invalid target_waitkind value: %d\n", (int) kind);
> +}
> +
>  struct target_waitstatus
>  {
>    /* Default constructor.  */
> diff --git a/gdb/unittests/common-utils-selftests.c b/gdb/unittests/common-utils-selftests.c
> index 26d313fd329..aa0f45241b9 100644
> --- a/gdb/unittests/common-utils-selftests.c
> +++ b/gdb/unittests/common-utils-selftests.c
> @@ -80,7 +80,8 @@ string_vprintf_tests ()
>  /* Type of both 'string_appendf' and the 'string_vappendf_wrapper'
>     function below.  Used to run the same tests against both
>     string_appendf and string_vappendf.  */
> -typedef void (string_appendf_func) (std::string &str, const char *fmt, ...)
> +typedef std::string &(string_appendf_func) (std::string &str, const char *fmt,
> +					    ...)
>    ATTRIBUTE_PRINTF (2, 3);
>  
>  static void
> @@ -101,7 +102,7 @@ test_appendf_func (string_appendf_func *func)
>    SELF_CHECK (str == "test23foo 45 bar");
>  }
>  
> -static void ATTRIBUTE_PRINTF (2, 3)
> +static std::string & ATTRIBUTE_PRINTF (2, 3)
>  string_vappendf_wrapper (std::string &str, const char *fmt, ...)
>  {
>    va_list vp;
> @@ -109,6 +110,8 @@ string_vappendf_wrapper (std::string &str, const char *fmt, ...)
>    va_start (vp, fmt);
>    string_vappendf (str, fmt, vp);
>    va_end (vp);
> +
> +  return str;
>  }
>  
>  static void
> diff --git a/gdbsupport/common-utils.cc b/gdbsupport/common-utils.cc
> index 42bce36e535..b591537e62e 100644
> --- a/gdbsupport/common-utils.cc
> +++ b/gdbsupport/common-utils.cc
> @@ -119,7 +119,7 @@ string_vprintf (const char* fmt, va_list args)
>  
>  /* See documentation in common-utils.h.  */
>  
> -void
> +std::string &
>  string_appendf (std::string &str, const char *fmt, ...)
>  {
>    va_list vp;
> @@ -127,12 +127,14 @@ string_appendf (std::string &str, const char *fmt, ...)
>    va_start (vp, fmt);
>    string_vappendf (str, fmt, vp);
>    va_end (vp);
> +
> +  return str;
>  }
>  
>  
>  /* See documentation in common-utils.h.  */
>  
> -void
> +std::string &
>  string_vappendf (std::string &str, const char *fmt, va_list args)
>  {
>    va_list vp;
> @@ -148,6 +150,8 @@ string_vappendf (std::string &str, const char *fmt, va_list args)
>    /* C++11 and later guarantee std::string uses contiguous memory and
>       always includes the terminating '\0'.  */
>    vsprintf (&str[curr_size], fmt, args); /* ARI: vsprintf */
> +
> +  return str;
>  }
>  
>  char *
> diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
> index af078475780..98a9dc72f36 100644
> --- a/gdbsupport/common-utils.h
> +++ b/gdbsupport/common-utils.h
> @@ -54,11 +54,11 @@ std::string string_vprintf (const char* fmt, va_list args)
>  
>  /* Like string_printf, but appends to DEST instead of returning a new
>     std::string.  */
> -void string_appendf (std::string &dest, const char* fmt, ...)
> +std::string &string_appendf (std::string &dest, const char* fmt, ...)
>    ATTRIBUTE_PRINTF (2, 3);
>  
>  /* Like string_appendf, but takes a va_list.  */
> -void string_vappendf (std::string &dest, const char* fmt, va_list args)
> +std::string &string_vappendf (std::string &dest, const char* fmt, va_list args)
>    ATTRIBUTE_PRINTF (2, 0);
>  
>  /* Make a copy of the string at PTR with LEN characters
> -- 
> 2.33.1
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] gdb: pass more const target_waitstatus by reference
  2021-11-22 16:27 ` [PATCH 3/3] gdb: pass more const target_waitstatus by reference Simon Marchi
@ 2021-11-22 18:56   ` Andrew Burgess
  2021-11-22 18:58     ` Simon Marchi
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Burgess @ 2021-11-22 18:56 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

* Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-11-22 11:27:31 -0500]:

> While working on target_waitstatus changes, I noticed a few places where
> const target_waitstatus objects could be passed by reference instead of
> by pointers.  And in some cases, places where a target_waitstatus could
> be passed as const, but was not.  Convert them as much as possible.

LGTM.

Thanks,
Andrew

> 
> Change-Id: Ied552d464be5d5b87489913b95f9720a5ad50c5a
> ---
>  gdb/break-catch-sig.c     |  6 ++--
>  gdb/break-catch-syscall.c |  8 ++---
>  gdb/breakpoint.c          | 52 ++++++++++++++++----------------
>  gdb/breakpoint.h          | 10 +++----
>  gdb/infrun.c              | 62 +++++++++++++++++++--------------------
>  gdb/infrun.h              |  2 +-
>  gdb/remote.c              | 36 +++++++++++------------
>  gdbserver/remote-utils.cc | 45 ++++++++++++++--------------
>  gdbserver/remote-utils.h  |  2 +-
>  gdbserver/server.cc       | 26 ++++++++--------
>  10 files changed, 124 insertions(+), 125 deletions(-)
> 
> diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c
> index 0998aa95c4f..7fe35dcdb0c 100644
> --- a/gdb/break-catch-sig.c
> +++ b/gdb/break-catch-sig.c
> @@ -149,16 +149,16 @@ static int
>  signal_catchpoint_breakpoint_hit (const struct bp_location *bl,
>  				  const address_space *aspace,
>  				  CORE_ADDR bp_addr,
> -				  const struct target_waitstatus *ws)
> +				  const target_waitstatus &ws)
>  {
>    const struct signal_catchpoint *c
>      = (const struct signal_catchpoint *) bl->owner;
>    gdb_signal signal_number;
>  
> -  if (ws->kind () != TARGET_WAITKIND_STOPPED)
> +  if (ws.kind () != TARGET_WAITKIND_STOPPED)
>      return 0;
>  
> -  signal_number = ws->sig ();
> +  signal_number = ws.sig ();
>  
>    /* If we are catching specific signals in this breakpoint, then we
>       must guarantee that the called signal is the same signal we are
> diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
> index cb2d77643ca..02123736ff4 100644
> --- a/gdb/break-catch-syscall.c
> +++ b/gdb/break-catch-syscall.c
> @@ -143,7 +143,7 @@ remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason)
>  static int
>  breakpoint_hit_catch_syscall (const struct bp_location *bl,
>  			      const address_space *aspace, CORE_ADDR bp_addr,
> -			      const struct target_waitstatus *ws)
> +			      const target_waitstatus &ws)
>  {
>    /* We must check if we are catching specific syscalls in this
>       breakpoint.  If we are, then we must guarantee that the called
> @@ -152,11 +152,11 @@ breakpoint_hit_catch_syscall (const struct bp_location *bl,
>    const struct syscall_catchpoint *c
>      = (const struct syscall_catchpoint *) bl->owner;
>  
> -  if (ws->kind () != TARGET_WAITKIND_SYSCALL_ENTRY
> -      && ws->kind () != TARGET_WAITKIND_SYSCALL_RETURN)
> +  if (ws.kind () != TARGET_WAITKIND_SYSCALL_ENTRY
> +      && ws.kind () != TARGET_WAITKIND_SYSCALL_RETURN)
>      return 0;
>  
> -  syscall_number = ws->syscall_number ();
> +  syscall_number = ws.syscall_number ();
>  
>    /* Now, checking if the syscall is the same.  */
>    if (!c->syscalls_to_be_caught.empty ())
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index d98c3a7cf0f..b1eae3af634 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -4771,7 +4771,7 @@ bpstat::bpstat ()
>     watchpoints have triggered, according to the target.  */
>  
>  int
> -watchpoints_triggered (struct target_waitstatus *ws)
> +watchpoints_triggered (const target_waitstatus &ws)
>  {
>    bool stopped_by_watchpoint = target_stopped_by_watchpoint ();
>    CORE_ADDR addr;
> @@ -5014,7 +5014,7 @@ watchpoint_check (bpstat *bs)
>  static int
>  bpstat_check_location (const struct bp_location *bl,
>  		       const address_space *aspace, CORE_ADDR bp_addr,
> -		       const struct target_waitstatus *ws)
> +		       const target_waitstatus &ws)
>  {
>    struct breakpoint *b = bl->owner;
>  
> @@ -5349,7 +5349,7 @@ need_moribund_for_location_type (struct bp_location *loc)
>  
>  bpstat *
>  build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
> -		    const struct target_waitstatus *ws)
> +		    const target_waitstatus &ws)
>  {
>    bpstat *bs_head = nullptr, **bs_link = &bs_head;
>  
> @@ -5425,7 +5425,7 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
>  bpstat *
>  bpstat_stop_status (const address_space *aspace,
>  		    CORE_ADDR bp_addr, thread_info *thread,
> -		    const struct target_waitstatus *ws,
> +		    const target_waitstatus &ws,
>  		    bpstat *stop_chain)
>  {
>    struct breakpoint *b = NULL;
> @@ -7760,14 +7760,14 @@ remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
>  static int
>  breakpoint_hit_catch_fork (const struct bp_location *bl,
>  			   const address_space *aspace, CORE_ADDR bp_addr,
> -			   const struct target_waitstatus *ws)
> +			   const target_waitstatus &ws)
>  {
>    struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
>  
> -  if (ws->kind () != TARGET_WAITKIND_FORKED)
> +  if (ws.kind () != TARGET_WAITKIND_FORKED)
>      return 0;
>  
> -  c->forked_inferior_pid = ws->child_ptid ();
> +  c->forked_inferior_pid = ws.child_ptid ();
>    return 1;
>  }
>  
> @@ -7876,14 +7876,14 @@ remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
>  static int
>  breakpoint_hit_catch_vfork (const struct bp_location *bl,
>  			    const address_space *aspace, CORE_ADDR bp_addr,
> -			    const struct target_waitstatus *ws)
> +			    const target_waitstatus &ws)
>  {
>    struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
>  
> -  if (ws->kind () != TARGET_WAITKIND_VFORKED)
> +  if (ws.kind () != TARGET_WAITKIND_VFORKED)
>      return 0;
>  
> -  c->forked_inferior_pid = ws->child_ptid ();
> +  c->forked_inferior_pid = ws.child_ptid ();
>    return 1;
>  }
>  
> @@ -7998,11 +7998,11 @@ static int
>  breakpoint_hit_catch_solib (const struct bp_location *bl,
>  			    const address_space *aspace,
>  			    CORE_ADDR bp_addr,
> -			    const struct target_waitstatus *ws)
> +			    const target_waitstatus &ws)
>  {
>    struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
>  
> -  if (ws->kind () == TARGET_WAITKIND_LOADED)
> +  if (ws.kind () == TARGET_WAITKIND_LOADED)
>      return 1;
>  
>    for (breakpoint *other : all_breakpoints ())
> @@ -8274,14 +8274,14 @@ remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
>  static int
>  breakpoint_hit_catch_exec (const struct bp_location *bl,
>  			   const address_space *aspace, CORE_ADDR bp_addr,
> -			   const struct target_waitstatus *ws)
> +			   const target_waitstatus &ws)
>  {
>    struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
>  
> -  if (ws->kind () != TARGET_WAITKIND_EXECD)
> +  if (ws.kind () != TARGET_WAITKIND_EXECD)
>      return 0;
>  
> -  c->exec_pathname = make_unique_xstrdup (ws->execd_pathname ());
> +  c->exec_pathname = make_unique_xstrdup (ws.execd_pathname ());
>    return 1;
>  }
>  
> @@ -9781,10 +9781,10 @@ static int
>  breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
>  				  const address_space *aspace,
>  				  CORE_ADDR bp_addr,
> -				  const struct target_waitstatus *ws)
> +				  const target_waitstatus &ws)
>  {
> -  if (ws->kind () != TARGET_WAITKIND_STOPPED
> -      || ws->sig () != GDB_SIGNAL_TRAP)
> +  if (ws.kind () != TARGET_WAITKIND_STOPPED
> +      || ws.sig () != GDB_SIGNAL_TRAP)
>      return 0;
>  
>    return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
> @@ -10125,7 +10125,7 @@ remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
>  static int
>  breakpoint_hit_watchpoint (const struct bp_location *bl,
>  			   const address_space *aspace, CORE_ADDR bp_addr,
> -			   const struct target_waitstatus *ws)
> +			   const target_waitstatus &ws)
>  {
>    struct breakpoint *b = bl->owner;
>    struct watchpoint *w = (struct watchpoint *) b;
> @@ -12280,7 +12280,7 @@ static int
>  base_breakpoint_breakpoint_hit (const struct bp_location *bl,
>  				const address_space *aspace,
>  				CORE_ADDR bp_addr,
> -				const struct target_waitstatus *ws)
> +				const target_waitstatus &ws)
>  {
>    internal_error_pure_virtual_called ();
>  }
> @@ -12447,10 +12447,10 @@ bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
>  static int
>  bkpt_breakpoint_hit (const struct bp_location *bl,
>  		     const address_space *aspace, CORE_ADDR bp_addr,
> -		     const struct target_waitstatus *ws)
> +		     const target_waitstatus &ws)
>  {
> -  if (ws->kind () != TARGET_WAITKIND_STOPPED
> -      || ws->sig () != GDB_SIGNAL_TRAP)
> +  if (ws.kind () != TARGET_WAITKIND_STOPPED
> +      || ws.sig () != GDB_SIGNAL_TRAP)
>      return 0;
>  
>    if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
> @@ -12468,7 +12468,7 @@ bkpt_breakpoint_hit (const struct bp_location *bl,
>  static int
>  dprintf_breakpoint_hit (const struct bp_location *bl,
>  			const address_space *aspace, CORE_ADDR bp_addr,
> -			const struct target_waitstatus *ws)
> +			const target_waitstatus &ws)
>  {
>    if (dprintf_style == dprintf_style_agent
>        && target_can_run_breakpoint_commands ())
> @@ -12822,7 +12822,7 @@ tracepoint_re_set (struct breakpoint *b)
>  static int
>  tracepoint_breakpoint_hit (const struct bp_location *bl,
>  			   const address_space *aspace, CORE_ADDR bp_addr,
> -			   const struct target_waitstatus *ws)
> +			   const target_waitstatus &ws)
>  {
>    /* By definition, the inferior does not report stops at
>       tracepoints.  */
> @@ -15194,7 +15194,7 @@ is_non_inline_function (struct breakpoint *b)
>  
>  int
>  pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
> -			   const struct target_waitstatus *ws)
> +			   const target_waitstatus &ws)
>  {
>    for (breakpoint *b : all_breakpoints ())
>      {
> diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
> index c9048d33816..1704d6a3fd7 100644
> --- a/gdb/breakpoint.h
> +++ b/gdb/breakpoint.h
> @@ -587,7 +587,7 @@ struct breakpoint_ops
>    int (*breakpoint_hit) (const struct bp_location *bl,
>  			 const address_space *aspace,
>  			 CORE_ADDR bp_addr,
> -			 const struct target_waitstatus *ws);
> +			 const target_waitstatus &ws);
>  
>    /* Check internal conditions of the breakpoint referred to by BS.
>       If we should not stop for this breakpoint, set BS->stop to 0.  */
> @@ -948,7 +948,7 @@ extern bpstat *bpstat_copy (bpstat *);
>  
>  extern bpstat *build_bpstat_chain (const address_space *aspace,
>  				  CORE_ADDR bp_addr,
> -				  const struct target_waitstatus *ws);
> +				  const target_waitstatus &ws);
>  
>  /* Get a bpstat associated with having just stopped at address
>     BP_ADDR in thread PTID.  STOP_CHAIN may be supplied as a previously
> @@ -972,7 +972,7 @@ extern bpstat *build_bpstat_chain (const address_space *aspace,
>  
>  extern bpstat *bpstat_stop_status (const address_space *aspace,
>  				  CORE_ADDR pc, thread_info *thread,
> -				  const struct target_waitstatus *ws,
> +				  const target_waitstatus &ws,
>  				  bpstat *stop_chain = nullptr);
>  \f
>  /* This bpstat_what stuff tells wait_for_inferior what to do with a
> @@ -1609,7 +1609,7 @@ extern int insert_single_step_breakpoints (struct gdbarch *);
>  
>  /* Check if any hardware watchpoints have triggered, according to the
>     target.  */
> -int watchpoints_triggered (struct target_waitstatus *);
> +int watchpoints_triggered (const target_waitstatus &);
>  
>  /* Helper for transparent breakpoint hiding for memory read and write
>     routines.
> @@ -1745,7 +1745,7 @@ const std::vector<bp_location *> &all_bp_locations ();
>  
>  extern int pc_at_non_inline_function (const address_space *aspace,
>  				      CORE_ADDR pc,
> -				      const struct target_waitstatus *ws);
> +				      const target_waitstatus &ws);
>  
>  extern int user_breakpoint_p (struct breakpoint *);
>  
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index dba4f33a327..e4739ed14f6 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -3470,7 +3470,7 @@ delete_just_stopped_threads_single_step_breakpoints (void)
>  
>  void
>  print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
> -			   const struct target_waitstatus *ws)
> +			   const struct target_waitstatus &ws)
>  {
>    infrun_debug_printf ("target_wait (%s [%s], status) =",
>  		       waiton_ptid.to_string ().c_str (),
> @@ -3478,7 +3478,7 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
>    infrun_debug_printf ("  %s [%s],",
>  		       result_ptid.to_string ().c_str (),
>  		       target_pid_to_str (result_ptid).c_str ());
> -  infrun_debug_printf ("  %s", ws->to_string ().c_str ());
> +  infrun_debug_printf ("  %s", ws.to_string ().c_str ());
>  }
>  
>  /* Select a thread at random, out of those which are resumed and have
> @@ -3833,7 +3833,7 @@ prepare_for_detach (void)
>  	  event.ptid = do_target_wait_1 (inf, pid_ptid, &event.ws, 0);
>  
>  	  if (debug_infrun)
> -	    print_target_wait_results (pid_ptid, event.ptid, &event.ws);
> +	    print_target_wait_results (pid_ptid, event.ptid, event.ws);
>  
>  	  handle_one (event);
>  	}
> @@ -3880,7 +3880,7 @@ wait_for_inferior (inferior *inf)
>        ecs->target = inf->process_target ();
>  
>        if (debug_infrun)
> -	print_target_wait_results (minus_one_ptid, ecs->ptid, &ecs->ws);
> +	print_target_wait_results (minus_one_ptid, ecs->ptid, ecs->ws);
>  
>        /* Now figure out what to do with the result of the result.  */
>        handle_inferior_event (ecs);
> @@ -4070,7 +4070,7 @@ fetch_inferior_event ()
>      switch_to_target_no_thread (ecs->target);
>  
>      if (debug_infrun)
> -      print_target_wait_results (minus_one_ptid, ecs->ptid, &ecs->ws);
> +      print_target_wait_results (minus_one_ptid, ecs->ptid, ecs->ws);
>  
>      /* If an error happens while handling the event, propagate GDB's
>         knowledge of the executing state to the frontend/user running
> @@ -4257,7 +4257,7 @@ context_switch (execution_control_state *ecs)
>  
>  static void
>  adjust_pc_after_break (struct thread_info *thread,
> -		       const target_waitstatus *ws)
> +		       const target_waitstatus &ws)
>  {
>    struct regcache *regcache;
>    struct gdbarch *gdbarch;
> @@ -4284,10 +4284,10 @@ adjust_pc_after_break (struct thread_info *thread,
>       target with both of these set in GDB history, and it seems unlikely to be
>       correct, so gdbarch_have_nonsteppable_watchpoint is not checked here.  */
>  
> -  if (ws->kind () != TARGET_WAITKIND_STOPPED)
> +  if (ws.kind () != TARGET_WAITKIND_STOPPED)
>      return;
>  
> -  if (ws->sig () != GDB_SIGNAL_TRAP)
> +  if (ws.sig () != GDB_SIGNAL_TRAP)
>      return;
>  
>    /* In reverse execution, when a breakpoint is hit, the instruction
> @@ -4494,7 +4494,7 @@ handle_syscall_event (struct execution_control_state *ecs)
>        ecs->event_thread->control.stop_bpstat
>  	= bpstat_stop_status (regcache->aspace (),
>  			      ecs->event_thread->stop_pc (),
> -			      ecs->event_thread, &ecs->ws);
> +			      ecs->event_thread, ecs->ws);
>  
>        if (handle_stop_requested (ecs))
>  	return false;
> @@ -4593,7 +4593,7 @@ poll_one_curr_target (struct target_waitstatus *ws)
>      event_ptid = target_wait (minus_one_ptid, ws, TARGET_WNOHANG);
>  
>    if (debug_infrun)
> -    print_target_wait_results (minus_one_ptid, event_ptid, ws);
> +    print_target_wait_results (minus_one_ptid, event_ptid, *ws);
>  
>    return event_ptid;
>  }
> @@ -4674,23 +4674,23 @@ wait_one ()
>  /* Save the thread's event and stop reason to process it later.  */
>  
>  static void
> -save_waitstatus (struct thread_info *tp, const target_waitstatus *ws)
> +save_waitstatus (struct thread_info *tp, const target_waitstatus &ws)
>  {
>    infrun_debug_printf ("saving status %s for %s",
> -		       ws->to_string ().c_str (),
> +		       ws.to_string ().c_str (),
>  		       tp->ptid.to_string ().c_str ());
>  
>    /* Record for later.  */
> -  tp->set_pending_waitstatus (*ws);
> +  tp->set_pending_waitstatus (ws);
>  
> -  if (ws->kind () == TARGET_WAITKIND_STOPPED
> -      && ws->sig () == GDB_SIGNAL_TRAP)
> +  if (ws.kind () == TARGET_WAITKIND_STOPPED
> +      && ws.sig () == GDB_SIGNAL_TRAP)
>      {
>        struct regcache *regcache = get_thread_regcache (tp);
>        const address_space *aspace = regcache->aspace ();
>        CORE_ADDR pc = regcache_read_pc (regcache);
>  
> -      adjust_pc_after_break (tp, &tp->pending_waitstatus ());
> +      adjust_pc_after_break (tp, tp->pending_waitstatus ());
>  
>        scoped_restore_current_thread restore_thread;
>        switch_to_thread (tp);
> @@ -4824,7 +4824,7 @@ handle_one (const wait_one_event &event)
>  	  switch_to_thread_no_regs (t);
>  	  mark_non_executing_threads (event.target, event.ptid,
>  				      event.ws);
> -	  save_waitstatus (t, &event.ws);
> +	  save_waitstatus (t, event.ws);
>  	  t->stop_requested = false;
>  	}
>      }
> @@ -4878,7 +4878,7 @@ handle_one (const wait_one_event &event)
>  	     t->ptid.to_string ().c_str ());
>  
>  	  /* Record for later.  */
> -	  save_waitstatus (t, &event.ws);
> +	  save_waitstatus (t, event.ws);
>  
>  	  sig = (event.ws.kind () == TARGET_WAITKIND_STOPPED
>  		 ? event.ws.sig () : GDB_SIGNAL_0);
> @@ -5236,7 +5236,7 @@ handle_inferior_event (struct execution_control_state *ecs)
>      }
>  
>    /* Dependent on valid ECS->EVENT_THREAD.  */
> -  adjust_pc_after_break (ecs->event_thread, &ecs->ws);
> +  adjust_pc_after_break (ecs->event_thread, ecs->ws);
>  
>    /* Dependent on the current PC value modified by adjust_pc_after_break.  */
>    reinit_frame_cache ();
> @@ -5295,7 +5295,7 @@ handle_inferior_event (struct execution_control_state *ecs)
>  	    ecs->event_thread->control.stop_bpstat
>  	      = bpstat_stop_status (regcache->aspace (),
>  				    ecs->event_thread->stop_pc (),
> -				    ecs->event_thread, &ecs->ws);
> +				    ecs->event_thread, ecs->ws);
>  
>  	    if (handle_stop_requested (ecs))
>  	      return;
> @@ -5538,7 +5538,7 @@ handle_inferior_event (struct execution_control_state *ecs)
>        ecs->event_thread->control.stop_bpstat
>  	= bpstat_stop_status (get_current_regcache ()->aspace (),
>  			      ecs->event_thread->stop_pc (),
> -			      ecs->event_thread, &ecs->ws);
> +			      ecs->event_thread, ecs->ws);
>  
>        if (handle_stop_requested (ecs))
>  	return;
> @@ -5649,7 +5649,7 @@ handle_inferior_event (struct execution_control_state *ecs)
>        ecs->event_thread->control.stop_bpstat
>  	= bpstat_stop_status (get_current_regcache ()->aspace (),
>  			      ecs->event_thread->stop_pc (),
> -			      ecs->event_thread, &ecs->ws);
> +			      ecs->event_thread, ecs->ws);
>  
>        if (handle_stop_requested (ecs))
>  	return;
> @@ -5886,7 +5886,7 @@ finish_step_over (struct execution_control_state *ecs)
>  	  gdb_assert (pending != tp);
>  
>  	  /* Record the event thread's event for later.  */
> -	  save_waitstatus (tp, &ecs->ws);
> +	  save_waitstatus (tp, ecs->ws);
>  	  /* This was cleared early, by handle_inferior_event.  Set it
>  	     so this pending event is considered by
>  	     do_target_wait.  */
> @@ -6061,7 +6061,7 @@ handle_signal_stop (struct execution_control_state *ecs)
>        && ecs->event_thread->stepping_over_watchpoint)
>      stopped_by_watchpoint = 0;
>    else
> -    stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
> +    stopped_by_watchpoint = watchpoints_triggered (ecs->ws);
>  
>    /* If necessary, step over this watchpoint.  We'll be back to display
>       it in a moment.  */
> @@ -6134,16 +6134,16 @@ handle_signal_stop (struct execution_control_state *ecs)
>  	 that's an extremely unlikely scenario.  */
>        if (!pc_at_non_inline_function (aspace,
>  				      ecs->event_thread->stop_pc (),
> -				      &ecs->ws)
> +				      ecs->ws)
>  	  && !(ecs->event_thread->stop_signal () == GDB_SIGNAL_TRAP
>  	       && ecs->event_thread->control.trap_expected
>  	       && pc_at_non_inline_function (aspace,
>  					     ecs->event_thread->prev_pc,
> -					     &ecs->ws)))
> +					     ecs->ws)))
>  	{
>  	  stop_chain = build_bpstat_chain (aspace,
>  					   ecs->event_thread->stop_pc (),
> -					   &ecs->ws);
> +					   ecs->ws);
>  	  skip_inline_frames (ecs->event_thread, stop_chain);
>  
>  	  /* Re-fetch current thread's frame in case that invalidated
> @@ -6195,7 +6195,7 @@ handle_signal_stop (struct execution_control_state *ecs)
>    ecs->event_thread->control.stop_bpstat
>      = bpstat_stop_status (get_current_regcache ()->aspace (),
>  			  ecs->event_thread->stop_pc (),
> -			  ecs->event_thread, &ecs->ws, stop_chain);
> +			  ecs->event_thread, ecs->ws, stop_chain);
>  
>    /* Following in case break condition called a
>       function.  */
> @@ -8258,14 +8258,14 @@ print_no_history_reason (struct ui_out *uiout)
>     based on the event(s) that just occurred.  */
>  
>  static void
> -print_stop_location (struct target_waitstatus *ws)
> +print_stop_location (const target_waitstatus &ws)
>  {
>    int bpstat_ret;
>    enum print_what source_flag;
>    int do_frame_printing = 1;
>    struct thread_info *tp = inferior_thread ();
>  
> -  bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws->kind ());
> +  bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws.kind ());
>    switch (bpstat_ret)
>      {
>      case PRINT_UNKNOWN:
> @@ -8325,7 +8325,7 @@ print_stop_event (struct ui_out *uiout, bool displays)
>    {
>      scoped_restore save_uiout = make_scoped_restore (&current_uiout, uiout);
>  
> -    print_stop_location (&last);
> +    print_stop_location (last);
>  
>      /* Display the auto-display expressions.  */
>      if (displays)
> diff --git a/gdb/infrun.h b/gdb/infrun.h
> index c5f98d9d305..644e57f0bca 100644
> --- a/gdb/infrun.h
> +++ b/gdb/infrun.h
> @@ -209,7 +209,7 @@ extern void print_stop_event (struct ui_out *uiout, bool displays = true);
>  /* Pretty print the results of target_wait, for debugging purposes.  */
>  
>  extern void print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
> -				       const struct target_waitstatus *ws);
> +				       const struct target_waitstatus &ws);
>  
>  extern int signal_stop_state (int);
>  
> diff --git a/gdb/remote.c b/gdb/remote.c
> index 61bde5aaa94..724386e0916 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -762,7 +762,7 @@ class remote_target : public process_stratum_target
>  			     target_waitstatus *status);
>  
>    ptid_t select_thread_for_ambiguous_stop_reply
> -    (const struct target_waitstatus *status);
> +    (const struct target_waitstatus &status);
>  
>    void remote_notice_new_inferior (ptid_t currthread, bool executing);
>  
> @@ -4542,7 +4542,7 @@ remote_target::process_initial_stop_replies (int from_tty)
>  
>        event_ptid = target_wait (waiton_ptid, &ws, TARGET_WNOHANG);
>        if (remote_debug)
> -	print_target_wait_results (waiton_ptid, event_ptid, &ws);
> +	print_target_wait_results (waiton_ptid, event_ptid, ws);
>  
>        switch (ws.kind ())
>  	{
> @@ -7224,11 +7224,11 @@ struct notif_client notif_client_stop =
>     -1 if we want to check all threads.  */
>  
>  static int
> -is_pending_fork_parent (const target_waitstatus *ws, int event_pid,
> +is_pending_fork_parent (const target_waitstatus &ws, int event_pid,
>  			ptid_t thread_ptid)
>  {
> -  if (ws->kind () == TARGET_WAITKIND_FORKED
> -      || ws->kind () == TARGET_WAITKIND_VFORKED)
> +  if (ws.kind () == TARGET_WAITKIND_FORKED
> +      || ws.kind () == TARGET_WAITKIND_VFORKED)
>      {
>        if (event_pid == -1 || event_pid == thread_ptid.pid ())
>  	return 1;
> @@ -7240,13 +7240,13 @@ is_pending_fork_parent (const target_waitstatus *ws, int event_pid,
>  /* Return the thread's pending status used to determine whether the
>     thread is a fork parent stopped at a fork event.  */
>  
> -static const target_waitstatus *
> +static const target_waitstatus &
>  thread_pending_fork_status (struct thread_info *thread)
>  {
>    if (thread->has_pending_waitstatus ())
> -    return &thread->pending_waitstatus ();
> +    return thread->pending_waitstatus ();
>    else
> -    return &thread->pending_follow;
> +    return thread->pending_follow;
>  }
>  
>  /* Determine if THREAD is a pending fork parent thread.  */
> @@ -7254,7 +7254,7 @@ thread_pending_fork_status (struct thread_info *thread)
>  static int
>  is_pending_fork_parent_thread (struct thread_info *thread)
>  {
> -  const target_waitstatus *ws = thread_pending_fork_status (thread);
> +  const target_waitstatus &ws = thread_pending_fork_status (thread);
>    int pid = -1;
>  
>    return is_pending_fork_parent (ws, pid, thread->ptid);
> @@ -7276,10 +7276,10 @@ remote_target::remove_new_fork_children (threads_listing_context *context)
>       fork child threads from the CONTEXT list.  */
>    for (thread_info *thread : all_non_exited_threads (this))
>      {
> -      const target_waitstatus *ws = thread_pending_fork_status (thread);
> +      const target_waitstatus &ws = thread_pending_fork_status (thread);
>  
>        if (is_pending_fork_parent (ws, pid, thread->ptid))
> -	context->remove_thread (ws->child_ptid ());
> +	context->remove_thread (ws.child_ptid ());
>      }
>  
>    /* Check for any pending fork events (not reported or processed yet)
> @@ -7940,15 +7940,15 @@ remote_notif_get_pending_events (remote_target *remote, notif_client *nc)
>  
>  ptid_t
>  remote_target::select_thread_for_ambiguous_stop_reply
> -  (const struct target_waitstatus *status)
> +  (const target_waitstatus &status)
>  {
>    REMOTE_SCOPED_DEBUG_ENTER_EXIT;
>  
>    /* Some stop events apply to all threads in an inferior, while others
>       only apply to a single thread.  */
>    bool process_wide_stop
> -    = (status->kind () == TARGET_WAITKIND_EXITED
> -       || status->kind () == TARGET_WAITKIND_SIGNALLED);
> +    = (status.kind () == TARGET_WAITKIND_EXITED
> +       || status.kind () == TARGET_WAITKIND_SIGNALLED);
>  
>    remote_debug_printf ("process_wide_stop = %d", process_wide_stop);
>  
> @@ -8030,7 +8030,7 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
>    /* If no thread/process was reported by the stub then select a suitable
>       thread/process.  */
>    if (ptid == null_ptid)
> -    ptid = select_thread_for_ambiguous_stop_reply (status);
> +    ptid = select_thread_for_ambiguous_stop_reply (*status);
>    gdb_assert (ptid != null_ptid);
>  
>    if (status->kind () != TARGET_WAITKIND_EXITED
> @@ -10056,11 +10056,11 @@ remote_target::kill_new_fork_children (int pid)
>       that are stopped at a fork event.  */
>    for (thread_info *thread : all_non_exited_threads (this))
>      {
> -      struct target_waitstatus *ws = &thread->pending_follow;
> +      const target_waitstatus &ws = thread->pending_follow;
>  
>        if (is_pending_fork_parent (ws, pid, thread->ptid))
>  	{
> -	  int child_pid = ws->child_ptid ().pid ();
> +	  int child_pid = ws.child_ptid ().pid ();
>  	  int res;
>  
>  	  res = remote_vkill (child_pid);
> @@ -10073,7 +10073,7 @@ remote_target::kill_new_fork_children (int pid)
>       in process PID and kill those fork child threads as well.  */
>    remote_notif_get_pending_events (notif);
>    for (auto &event : rs->stop_reply_queue)
> -    if (is_pending_fork_parent (&event->ws, pid, event->ptid))
> +    if (is_pending_fork_parent (event->ws, pid, event->ptid))
>        {
>  	int child_pid = event->ws.child_ptid ().pid ();
>  	int res;
> diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
> index 5bc261a9c7b..8202365350a 100644
> --- a/gdbserver/remote-utils.cc
> +++ b/gdbserver/remote-utils.cc
> @@ -1081,15 +1081,14 @@ outreg (struct regcache *regcache, int regno, char *buf)
>  }
>  
>  void
> -prepare_resume_reply (char *buf, ptid_t ptid,
> -		      struct target_waitstatus *status)
> +prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
>  {
>    client_state &cs = get_client_state ();
>    if (debug_threads)
>      debug_printf ("Writing resume reply for %s:%d\n",
> -		  target_pid_to_str (ptid).c_str (), status->kind ());
> +		  target_pid_to_str (ptid).c_str (), status.kind ());
>  
> -  switch (status->kind ())
> +  switch (status.kind ())
>      {
>      case TARGET_WAITKIND_STOPPED:
>      case TARGET_WAITKIND_FORKED:
> @@ -1104,27 +1103,27 @@ prepare_resume_reply (char *buf, ptid_t ptid,
>  	const char **regp;
>  	struct regcache *regcache;
>  
> -	if ((status->kind () == TARGET_WAITKIND_FORKED && cs.report_fork_events)
> -	    || (status->kind () == TARGET_WAITKIND_VFORKED
> +	if ((status.kind () == TARGET_WAITKIND_FORKED && cs.report_fork_events)
> +	    || (status.kind () == TARGET_WAITKIND_VFORKED
>  		&& cs.report_vfork_events))
>  	  {
>  	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
> -	    const char *event = (status->kind () == TARGET_WAITKIND_FORKED
> +	    const char *event = (status.kind () == TARGET_WAITKIND_FORKED
>  				 ? "fork" : "vfork");
>  
>  	    sprintf (buf, "T%02x%s:", signal, event);
>  	    buf += strlen (buf);
> -	    buf = write_ptid (buf, status->child_ptid ());
> +	    buf = write_ptid (buf, status.child_ptid ());
>  	    strcat (buf, ";");
>  	  }
> -	else if (status->kind () == TARGET_WAITKIND_VFORK_DONE
> +	else if (status.kind () == TARGET_WAITKIND_VFORK_DONE
>  		 && cs.report_vfork_events)
>  	  {
>  	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
>  
>  	    sprintf (buf, "T%02xvforkdone:;", signal);
>  	  }
> -	else if (status->kind () == TARGET_WAITKIND_EXECD && cs.report_exec_events)
> +	else if (status.kind () == TARGET_WAITKIND_EXECD && cs.report_exec_events)
>  	  {
>  	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
>  	    const char *event = "exec";
> @@ -1134,32 +1133,32 @@ prepare_resume_reply (char *buf, ptid_t ptid,
>  	    buf += strlen (buf);
>  
>  	    /* Encode pathname to hexified format.  */
> -	    bin2hex ((const gdb_byte *) status->execd_pathname (),
> +	    bin2hex ((const gdb_byte *) status.execd_pathname (),
>  		     hexified_pathname,
> -		     strlen (status->execd_pathname ()));
> +		     strlen (status.execd_pathname ()));
>  
>  	    sprintf (buf, "%s;", hexified_pathname);
>  	    buf += strlen (buf);
>  	  }
> -	else if (status->kind () == TARGET_WAITKIND_THREAD_CREATED
> +	else if (status.kind () == TARGET_WAITKIND_THREAD_CREATED
>  		 && cs.report_thread_events)
>  	  {
>  	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
>  
>  	    sprintf (buf, "T%02xcreate:;", signal);
>  	  }
> -	else if (status->kind () == TARGET_WAITKIND_SYSCALL_ENTRY
> -		 || status->kind () == TARGET_WAITKIND_SYSCALL_RETURN)
> +	else if (status.kind () == TARGET_WAITKIND_SYSCALL_ENTRY
> +		 || status.kind () == TARGET_WAITKIND_SYSCALL_RETURN)
>  	  {
>  	    enum gdb_signal signal = GDB_SIGNAL_TRAP;
> -	    const char *event = (status->kind () == TARGET_WAITKIND_SYSCALL_ENTRY
> +	    const char *event = (status.kind () == TARGET_WAITKIND_SYSCALL_ENTRY
>  				 ? "syscall_entry" : "syscall_return");
>  
>  	    sprintf (buf, "T%02x%s:%x;", signal, event,
> -		     status->syscall_number ());
> +		     status.syscall_number ());
>  	  }
>  	else
> -	  sprintf (buf, "T%02x", status->sig ());
> +	  sprintf (buf, "T%02x", status.sig ());
>  
>  	if (disable_packet_T)
>  	  {
> @@ -1281,19 +1280,19 @@ prepare_resume_reply (char *buf, ptid_t ptid,
>      case TARGET_WAITKIND_EXITED:
>        if (cs.multi_process)
>  	sprintf (buf, "W%x;process:%x",
> -		 status->exit_status (), ptid.pid ());
> +		 status.exit_status (), ptid.pid ());
>        else
> -	sprintf (buf, "W%02x", status->exit_status ());
> +	sprintf (buf, "W%02x", status.exit_status ());
>        break;
>      case TARGET_WAITKIND_SIGNALLED:
>        if (cs.multi_process)
>  	sprintf (buf, "X%x;process:%x",
> -		 status->sig (), ptid.pid ());
> +		 status.sig (), ptid.pid ());
>        else
> -	sprintf (buf, "X%02x", status->sig ());
> +	sprintf (buf, "X%02x", status.sig ());
>        break;
>      case TARGET_WAITKIND_THREAD_EXITED:
> -      sprintf (buf, "w%x;", status->exit_status ());
> +      sprintf (buf, "w%x;", status.exit_status ());
>        buf += strlen (buf);
>        buf = write_ptid (buf, ptid);
>        break;
> diff --git a/gdbserver/remote-utils.h b/gdbserver/remote-utils.h
> index 25074bcc2b9..b856862d367 100644
> --- a/gdbserver/remote-utils.h
> +++ b/gdbserver/remote-utils.h
> @@ -41,7 +41,7 @@ void enable_async_io (void);
>  void disable_async_io (void);
>  void check_remote_input_interrupt_request (void);
>  void prepare_resume_reply (char *buf, ptid_t ptid,
> -			   struct target_waitstatus *status);
> +			   const target_waitstatus &status);
>  
>  const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start);
>  void decode_address (CORE_ADDR *addrp, const char *start, int len);
> diff --git a/gdbserver/server.cc b/gdbserver/server.cc
> index 2807525d11c..b1d4c92b3d9 100644
> --- a/gdbserver/server.cc
> +++ b/gdbserver/server.cc
> @@ -173,12 +173,12 @@ get_client_state ()
>  /* Put a stop reply to the stop reply queue.  */
>  
>  static void
> -queue_stop_reply (ptid_t ptid, struct target_waitstatus *status)
> +queue_stop_reply (ptid_t ptid, const target_waitstatus &status)
>  {
>    struct vstop_notif *new_notif = new struct vstop_notif;
>  
>    new_notif->ptid = ptid;
> -  new_notif->status = *status;
> +  new_notif->status = status;
>  
>    notif_event_enque (&notif_stop, new_notif);
>  }
> @@ -225,7 +225,7 @@ vstop_notif_reply (struct notif_event *event, char *own_buf)
>  {
>    struct vstop_notif *vstop = (struct vstop_notif *) event;
>  
> -  prepare_resume_reply (own_buf, vstop->ptid, &vstop->status);
> +  prepare_resume_reply (own_buf, vstop->ptid, vstop->status);
>  }
>  
>  /* Helper for in_queued_stop_replies.  */
> @@ -2795,7 +2795,7 @@ handle_pending_status (const struct thread_resume *resumption,
>  
>        cs.last_status = thread->last_status;
>        cs.last_ptid = thread->id;
> -      prepare_resume_reply (cs.own_buf, cs.last_ptid, &cs.last_status);
> +      prepare_resume_reply (cs.own_buf, cs.last_ptid, cs.last_status);
>        return 1;
>      }
>    return 0;
> @@ -2963,7 +2963,7 @@ resume (struct thread_resume *actions, size_t num_actions)
>  	 so by now).  Tag all threads as "want-stopped", so we don't
>  	 resume them implicitly without the client telling us to.  */
>        gdb_wants_all_threads_stopped ();
> -      prepare_resume_reply (cs.own_buf, cs.last_ptid, &cs.last_status);
> +      prepare_resume_reply (cs.own_buf, cs.last_ptid, cs.last_status);
>        disable_async_io ();
>  
>        if (cs.last_status.kind () == TARGET_WAITKIND_EXITED
> @@ -2996,7 +2996,7 @@ handle_v_attach (char *own_buf)
>  	  write_ok (own_buf);
>  	}
>        else
> -	prepare_resume_reply (own_buf, cs.last_ptid, &cs.last_status);
> +	prepare_resume_reply (own_buf, cs.last_ptid, cs.last_status);
>      }
>    else
>      write_enn (own_buf);
> @@ -3114,7 +3114,7 @@ handle_v_run (char *own_buf)
>  
>    if (cs.last_status.kind () == TARGET_WAITKIND_STOPPED)
>      {
> -      prepare_resume_reply (own_buf, cs.last_ptid, &cs.last_status);
> +      prepare_resume_reply (own_buf, cs.last_ptid, cs.last_status);
>  
>        /* In non-stop, sending a resume reply doesn't set the general
>  	 thread, but GDB assumes a vRun sets it (this is so GDB can
> @@ -3313,7 +3313,7 @@ queue_stop_reply_callback (thread_info *thread)
>  
>  	  /* Pass the last stop reply back to GDB, but don't notify
>  	     yet.  */
> -	  queue_stop_reply (thread->id, &thread->last_status);
> +	  queue_stop_reply (thread->id, thread->last_status);
>  	}
>      }
>  }
> @@ -3436,7 +3436,7 @@ handle_status (char *own_buf)
>  	  set_desired_thread ();
>  
>  	  gdb_assert (tp->last_status.kind () != TARGET_WAITKIND_IGNORE);
> -	  prepare_resume_reply (own_buf, tp->id, &tp->last_status);
> +	  prepare_resume_reply (own_buf, tp->id, tp->last_status);
>  	}
>        else
>  	strcpy (own_buf, "W00");
> @@ -4562,11 +4562,11 @@ handle_serial_event (int err, gdb_client_data client_data)
>  /* Push a stop notification on the notification queue.  */
>  
>  static void
> -push_stop_notification (ptid_t ptid, struct target_waitstatus *status)
> +push_stop_notification (ptid_t ptid, const target_waitstatus &status)
>  {
>    struct vstop_notif *vstop_notif = new struct vstop_notif;
>  
> -  vstop_notif->status = *status;
> +  vstop_notif->status = status;
>    vstop_notif->ptid = ptid;
>    /* Push Stop notification.  */
>    notif_push (&notif_stop, vstop_notif);
> @@ -4587,7 +4587,7 @@ handle_target_event (int err, gdb_client_data client_data)
>    if (cs.last_status.kind () == TARGET_WAITKIND_NO_RESUMED)
>      {
>        if (gdb_connected () && report_no_resumed)
> -	push_stop_notification (null_ptid, &cs.last_status);
> +	push_stop_notification (null_ptid, cs.last_status);
>      }
>    else if (cs.last_status.kind () != TARGET_WAITKIND_IGNORE)
>      {
> @@ -4645,7 +4645,7 @@ handle_target_event (int err, gdb_client_data client_data)
>  	    }
>  	}
>        else
> -	push_stop_notification (cs.last_ptid, &cs.last_status);
> +	push_stop_notification (cs.last_ptid, cs.last_status);
>      }
>  
>    /* Be sure to not change the selected thread behind GDB's back.
> -- 
> 2.33.1
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] gdb: pass more const target_waitstatus by reference
  2021-11-22 18:56   ` Andrew Burgess
@ 2021-11-22 18:58     ` Simon Marchi
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Marchi @ 2021-11-22 18:58 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On 2021-11-22 1:56 p.m., Andrew Burgess wrote:
> * Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-11-22 11:27:31 -0500]:
> 
>> While working on target_waitstatus changes, I noticed a few places where
>> const target_waitstatus objects could be passed by reference instead of
>> by pointers.  And in some cases, places where a target_waitstatus could
>> be passed as const, but was not.  Convert them as much as possible.
> 
> LGTM.
> 
> Thanks,
> Andrew

Thanks, pushed all three patches.

Simon


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string
  2021-11-22 16:27 ` [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string Simon Marchi
  2021-11-22 18:53   ` Andrew Burgess
@ 2021-11-25 14:38   ` Vaseeharan Vinayagamoorthy
  2021-11-25 15:33     ` Simon Marchi
  1 sibling, 1 reply; 9+ messages in thread
From: Vaseeharan Vinayagamoorthy @ 2021-11-25 14:38 UTC (permalink / raw)
  To: gdb-patches, Simon Marchi

After this commit, I am seeing this error, when using gcc 4.8.5:
gdb/ada-tasks.c:998:10: error: enumeration value ‘ADA_TASKS_UNKNOWN’ not handled in switch [-Werror=switch]
   switch (data->known_tasks_kind)
          ^

The build/host/target setup is:
Build: x86_64 (Linux), using gcc 4.8.5
Host: x86_64 (Linux)
Target: arm-none-eabi / aarch64-none-elf / aarch64_be-none-elf


Kind regards
Vasee

________________________________
From: Gdb-patches <gdb-patches-bounces+vvinayag=arm.com@sourceware.org> on behalf of Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Sent: 22 November 2021 16:27
To: gdb-patches@sourceware.org <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string

I would like to print target_waitkind values in debug messages, so I
think that a target_waitkind-to-string function would be useful.  While
at it, use it in target_waitstatus::to_string.  This changes the output
of target_waitstatus::to_string a bit, but I think it is for the better.
The debug messages will show a string matching exactly the
target_waitkind enumerator (minus the TARGET_WAITKIND prefix).

As a convenience, make string_appendf return the same reference to
string it got as a parameter.  This allows doing this:

  return string_appendf (str, "foo");

... keeping the code concise.

Change-Id: I383dffc9c78614e7d0668b1516073905e798eef7
---
 gdb/target/waitstatus.c                | 66 +++++++++-----------------
 gdb/target/waitstatus.h                | 49 +++++++++++++++++++
 gdb/unittests/common-utils-selftests.c |  7 ++-
 gdbsupport/common-utils.cc             |  8 +++-
 gdbsupport/common-utils.h              |  4 +-
 5 files changed, 84 insertions(+), 50 deletions(-)

diff --git a/gdb/target/waitstatus.c b/gdb/target/waitstatus.c
index 2293d83230d..a7209e3f2b7 100644
--- a/gdb/target/waitstatus.c
+++ b/gdb/target/waitstatus.c
@@ -20,73 +20,51 @@
 #include "gdbsupport/common-defs.h"
 #include "waitstatus.h"

-/* Return a pretty printed form of target_waitstatus.  */
+/* See waitstatus.h.  */

 std::string
 target_waitstatus::to_string () const
 {
-  const char *kind_str = "status->kind = ";
+  std::string str = string_printf
+    ("status->kind = %s", target_waitkind_str (this->kind ()));

+/* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added
+   but not handled here.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic error "-Wswitch"
   switch (this->kind ())
     {
     case TARGET_WAITKIND_EXITED:
-      return string_printf ("%sexited, status = %d",
-                           kind_str, this->exit_status ());
+    case TARGET_WAITKIND_THREAD_EXITED:
+      return string_appendf (str, ", exit_status = %d", this->exit_status ());

     case TARGET_WAITKIND_STOPPED:
-      return string_printf ("%sstopped, signal = %s",
-                           kind_str,
-                           gdb_signal_to_symbol_string (this->sig ()));
-
     case TARGET_WAITKIND_SIGNALLED:
-      return string_printf ("%ssignalled, signal = %s",
-                           kind_str,
-                           gdb_signal_to_symbol_string (this->sig ()));
-
-    case TARGET_WAITKIND_LOADED:
-      return string_printf ("%sloaded", kind_str);
+      return string_appendf (str, ", sig = %s",
+                            gdb_signal_to_symbol_string (this->sig ()));

     case TARGET_WAITKIND_FORKED:
-      return string_printf ("%sforked, child_ptid = %s", kind_str,
-                           this->child_ptid ().to_string ().c_str ());
-
     case TARGET_WAITKIND_VFORKED:
-      return string_printf ("%svforked, child_ptid = %s", kind_str,
-                           this->child_ptid ().to_string ().c_str ());
+      return string_appendf (str, ", child_ptid = %s",
+                            this->child_ptid ().to_string ().c_str ());

     case TARGET_WAITKIND_EXECD:
-      return string_printf ("%sexecd, execd_pathname = %s", kind_str,
-                           this->execd_pathname ());
+      return string_appendf (str, ", execd_pathname = %s",
+                            this->execd_pathname ());

+    case TARGET_WAITKIND_LOADED:
     case TARGET_WAITKIND_VFORK_DONE:
-      return string_printf ("%svfork-done", kind_str);
-
+    case TARGET_WAITKIND_SPURIOUS:
     case TARGET_WAITKIND_SYSCALL_ENTRY:
-      return string_printf ("%sentered syscall", kind_str);
-
     case TARGET_WAITKIND_SYSCALL_RETURN:
-      return string_printf ("%sexited syscall", kind_str);
-
-    case TARGET_WAITKIND_SPURIOUS:
-      return string_printf ("%sspurious", kind_str);
-
     case TARGET_WAITKIND_IGNORE:
-      return string_printf ("%signore", kind_str);
-
     case TARGET_WAITKIND_NO_HISTORY:
-      return string_printf ("%sno-history", kind_str);
-
     case TARGET_WAITKIND_NO_RESUMED:
-      return string_printf ("%sno-resumed", kind_str);
-
     case TARGET_WAITKIND_THREAD_CREATED:
-      return string_printf ("%sthread created", kind_str);
-
-    case TARGET_WAITKIND_THREAD_EXITED:
-      return string_printf ("%sthread exited, status = %d",
-                           kind_str, this->exit_status ());
-
-    default:
-      return string_printf ("%sunknown???", kind_str);
+      return str;
     }
+#pragma GCC diagnostic pop
+
+  gdb_assert_not_reached ("invalid target_waitkind value: %d",
+                         (int) this->kind ());
 }
diff --git a/gdb/target/waitstatus.h b/gdb/target/waitstatus.h
index f5b050b8b82..48405d222f4 100644
--- a/gdb/target/waitstatus.h
+++ b/gdb/target/waitstatus.h
@@ -101,6 +101,55 @@ enum target_waitkind
   TARGET_WAITKIND_THREAD_EXITED,
 };

+/* Return KIND as a string.  */
+
+static inline const char *
+target_waitkind_str (target_waitkind kind)
+{
+/* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added
+   but not handled here.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic error "-Wswitch"
+  switch (kind)
+  {
+    case TARGET_WAITKIND_EXITED:
+      return "EXITED";
+    case TARGET_WAITKIND_STOPPED:
+      return "STOPPED";
+    case TARGET_WAITKIND_SIGNALLED:
+      return "SIGNALLED";
+    case TARGET_WAITKIND_LOADED:
+      return "LOADED";
+    case TARGET_WAITKIND_FORKED:
+      return "FORKED";
+    case TARGET_WAITKIND_VFORKED:
+      return "VFORKED";
+    case TARGET_WAITKIND_EXECD:
+      return "EXECD";
+    case TARGET_WAITKIND_VFORK_DONE:
+      return "VFORK_DONE";
+    case TARGET_WAITKIND_SYSCALL_ENTRY:
+      return "SYSCALL_ENTRY";
+    case TARGET_WAITKIND_SYSCALL_RETURN:
+      return "SYSCALL_RETURN";
+    case TARGET_WAITKIND_SPURIOUS:
+      return "SPURIOUS";
+    case TARGET_WAITKIND_IGNORE:
+      return "IGNORE";
+    case TARGET_WAITKIND_NO_HISTORY:
+      return "NO_HISTORY";
+    case TARGET_WAITKIND_NO_RESUMED:
+      return "NO_RESUMED";
+    case TARGET_WAITKIND_THREAD_CREATED:
+      return "THREAD_CREATED";
+    case TARGET_WAITKIND_THREAD_EXITED:
+      return "THREAD_EXITED";
+  };
+#pragma GCC diagnostic pop
+
+  gdb_assert_not_reached ("invalid target_waitkind value: %d\n", (int) kind);
+}
+
 struct target_waitstatus
 {
   /* Default constructor.  */
diff --git a/gdb/unittests/common-utils-selftests.c b/gdb/unittests/common-utils-selftests.c
index 26d313fd329..aa0f45241b9 100644
--- a/gdb/unittests/common-utils-selftests.c
+++ b/gdb/unittests/common-utils-selftests.c
@@ -80,7 +80,8 @@ string_vprintf_tests ()
 /* Type of both 'string_appendf' and the 'string_vappendf_wrapper'
    function below.  Used to run the same tests against both
    string_appendf and string_vappendf.  */
-typedef void (string_appendf_func) (std::string &str, const char *fmt, ...)
+typedef std::string &(string_appendf_func) (std::string &str, const char *fmt,
+                                           ...)
   ATTRIBUTE_PRINTF (2, 3);

 static void
@@ -101,7 +102,7 @@ test_appendf_func (string_appendf_func *func)
   SELF_CHECK (str == "test23foo 45 bar");
 }

-static void ATTRIBUTE_PRINTF (2, 3)
+static std::string & ATTRIBUTE_PRINTF (2, 3)
 string_vappendf_wrapper (std::string &str, const char *fmt, ...)
 {
   va_list vp;
@@ -109,6 +110,8 @@ string_vappendf_wrapper (std::string &str, const char *fmt, ...)
   va_start (vp, fmt);
   string_vappendf (str, fmt, vp);
   va_end (vp);
+
+  return str;
 }

 static void
diff --git a/gdbsupport/common-utils.cc b/gdbsupport/common-utils.cc
index 42bce36e535..b591537e62e 100644
--- a/gdbsupport/common-utils.cc
+++ b/gdbsupport/common-utils.cc
@@ -119,7 +119,7 @@ string_vprintf (const char* fmt, va_list args)

 /* See documentation in common-utils.h.  */

-void
+std::string &
 string_appendf (std::string &str, const char *fmt, ...)
 {
   va_list vp;
@@ -127,12 +127,14 @@ string_appendf (std::string &str, const char *fmt, ...)
   va_start (vp, fmt);
   string_vappendf (str, fmt, vp);
   va_end (vp);
+
+  return str;
 }


 /* See documentation in common-utils.h.  */

-void
+std::string &
 string_vappendf (std::string &str, const char *fmt, va_list args)
 {
   va_list vp;
@@ -148,6 +150,8 @@ string_vappendf (std::string &str, const char *fmt, va_list args)
   /* C++11 and later guarantee std::string uses contiguous memory and
      always includes the terminating '\0'.  */
   vsprintf (&str[curr_size], fmt, args); /* ARI: vsprintf */
+
+  return str;
 }

 char *
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index af078475780..98a9dc72f36 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -54,11 +54,11 @@ std::string string_vprintf (const char* fmt, va_list args)

 /* Like string_printf, but appends to DEST instead of returning a new
    std::string.  */
-void string_appendf (std::string &dest, const char* fmt, ...)
+std::string &string_appendf (std::string &dest, const char* fmt, ...)
   ATTRIBUTE_PRINTF (2, 3);

 /* Like string_appendf, but takes a va_list.  */
-void string_vappendf (std::string &dest, const char* fmt, va_list args)
+std::string &string_vappendf (std::string &dest, const char* fmt, va_list args)
   ATTRIBUTE_PRINTF (2, 0);

 /* Make a copy of the string at PTR with LEN characters
--
2.33.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string
  2021-11-25 14:38   ` Vaseeharan Vinayagamoorthy
@ 2021-11-25 15:33     ` Simon Marchi
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Marchi @ 2021-11-25 15:33 UTC (permalink / raw)
  To: Vaseeharan Vinayagamoorthy, gdb-patches, Simon Marchi

On 2021-11-25 9:38 a.m., Vaseeharan Vinayagamoorthy via Gdb-patches wrote:
> After this commit, I am seeing this error, when using gcc 4.8.5:
> gdb/ada-tasks.c:998:10: error: enumeration value ‘ADA_TASKS_UNKNOWN’ not handled in switch [-Werror=switch]
>    switch (data->known_tasks_kind)
>           ^
> 
> The build/host/target setup is:
> Build: x86_64 (Linux), using gcc 4.8.5
> Host: x86_64 (Linux)
> Target: arm-none-eabi / aarch64-none-elf / aarch64_be-none-elf

This would be fixed by this patch series, but it's waiting for review:

https://sourceware.org/pipermail/gdb-patches/2021-November/183732.html

Simon

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-11-25 15:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 16:27 [PATCH 1/3] gdb: rename target_waitstatus_to_string to target_waitstatus::to_string Simon Marchi
2021-11-22 16:27 ` [PATCH 2/3] gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string Simon Marchi
2021-11-22 18:53   ` Andrew Burgess
2021-11-25 14:38   ` Vaseeharan Vinayagamoorthy
2021-11-25 15:33     ` Simon Marchi
2021-11-22 16:27 ` [PATCH 3/3] gdb: pass more const target_waitstatus by reference Simon Marchi
2021-11-22 18:56   ` Andrew Burgess
2021-11-22 18:58     ` Simon Marchi
2021-11-22 18:48 ` [PATCH 1/3] gdb: rename target_waitstatus_to_string to target_waitstatus::to_string Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).