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


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

[binutils-gdb] Make target_waitstatus_to_string return an std::string


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=23fdd69e42180578b3e15ba8f053fadde965bfe8

commit 23fdd69e42180578b3e15ba8f053fadde965bfe8
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Sun Sep 3 10:23:31 2017 +0200

    Make target_waitstatus_to_string return an std::string
    
    A quite straightforward change.  It does "fix" leaks in record-btrace.c,
    although since this is only used in debug printing code, it has no real
    world impact.
    
    gdb/ChangeLog:
    
    	* target/waitstatus.h (target_waitstatus_to_string): Change
    	return type to std::string.
    	* target/waitstatus.c (target_waitstatus_to_string): Return
    	std::string.
    	* target.h (target_waitstatus_to_string): Remove declaration.
    	* infrun.c (resume, clear_proceed_status_thread,
    	print_target_wait_results, do_target_wait, save_waitstatus,
    	stop_all_threads): Adjust.
    	* record-btrace.c (record_btrace_wait): Adjust.
    	* target-debug.h
    	(target_debug_print_struct_target_waitstatus_p): Adjust.
    
    gdb/gdbserver/ChangeLog:
    
    	* linux-low.c (linux_wait_1): Adjust.
    	* server.c (queue_stop_reply_callback): Adjust.

Diff:
---
 gdb/ChangeLog             | 14 ++++++++++++++
 gdb/gdbserver/ChangeLog   |  5 +++++
 gdb/gdbserver/linux-low.c |  7 +++----
 gdb/gdbserver/server.c    |  6 ++----
 gdb/infrun.c              | 43 +++++++++++++++++-------------------------
 gdb/record-btrace.c       |  4 ++--
 gdb/target-debug.h        |  5 ++---
 gdb/target.h              |  4 ----
 gdb/target/waitstatus.c   | 48 +++++++++++++++++++++++------------------------
 gdb/target/waitstatus.h   |  5 ++---
 10 files changed, 71 insertions(+), 70 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 44dfe5b..71566bd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,17 @@
+2017-09-03  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* target/waitstatus.h (target_waitstatus_to_string): Change
+	return type to std::string.
+	* target/waitstatus.c (target_waitstatus_to_string): Return
+	std::string.
+	* target.h (target_waitstatus_to_string): Remove declaration.
+	* infrun.c (resume, clear_proceed_status_thread,
+	print_target_wait_results, do_target_wait, save_waitstatus,
+	stop_all_threads): Adjust.
+	* record-btrace.c (record_btrace_wait): Adjust.
+	* target-debug.h
+	(target_debug_print_struct_target_waitstatus_p): Adjust.
+
 2017-09-01  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	PR gdb/22046
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 492f0ab..e5635d8 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,8 @@
+2017-09-03  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* linux-low.c (linux_wait_1): Adjust.
+	* server.c (queue_stop_reply_callback): Adjust.
+
 2017-08-31  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	* server.c (handle_general_set): Handle QEnvironmentHexEncoded,
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index fd46d85..6f4b26a 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -3733,12 +3733,11 @@ linux_wait_1 (ptid_t ptid,
     {
       if (event_child->waitstatus.kind != TARGET_WAITKIND_IGNORE)
 	{
-	  char *str;
+	  std::string str
+	    = target_waitstatus_to_string (&event_child->waitstatus);
 
-	  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);
-	  xfree (str);
+			lwpid_of (get_lwp_thread (event_child)), str.c_str ());
 	}
       if (current_thread->last_resume_kind == resume_step)
 	{
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 88a5ddc..7210d1f 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3181,14 +3181,12 @@ queue_stop_reply_callback (struct inferior_list_entry *entry, void *arg)
 	{
 	  if (debug_threads)
 	    {
-	      char *status_string
+	      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 (entry->id),
-			    status_string);
-
-	      xfree (status_string);
+			    status_string.c_str ());
 	    }
 
 	  gdb_assert (thread->last_status.kind != TARGET_WAITKIND_IGNORE);
diff --git a/gdb/infrun.c b/gdb/infrun.c
index d0e4105..06b45b4 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -2409,15 +2409,14 @@ resume (enum gdb_signal sig)
     {
       if (debug_infrun)
 	{
-	  char *statstr;
+	  std::string statstr
+	    = target_waitstatus_to_string (&tp->suspend.waitstatus);
 
-	  statstr = target_waitstatus_to_string (&tp->suspend.waitstatus);
 	  fprintf_unfiltered (gdb_stdlog,
-			      "infrun: resume: thread %s has pending wait status %s "
-			      "(currently_stepping=%d).\n",
-			      target_pid_to_str (tp->ptid),  statstr,
+			      "infrun: resume: thread %s has pending wait "
+			      "status %s (currently_stepping=%d).\n",
+			      target_pid_to_str (tp->ptid), statstr.c_str (),
 			      currently_stepping (tp));
-	  xfree (statstr);
 	}
 
       tp->resumed = 1;
@@ -2820,16 +2819,15 @@ clear_proceed_status_thread (struct thread_info *tp)
 	}
       else if (debug_infrun)
 	{
-	  char *statstr;
+	  std::string statstr
+	    = target_waitstatus_to_string (&tp->suspend.waitstatus);
 
-	  statstr = target_waitstatus_to_string (&tp->suspend.waitstatus);
 	  fprintf_unfiltered (gdb_stdlog,
 			      "infrun: clear_proceed_status_thread: thread %s "
 			      "has pending wait status %s "
 			      "(currently_stepping=%d).\n",
-			      target_pid_to_str (tp->ptid), statstr,
+			      target_pid_to_str (tp->ptid), statstr.c_str (),
 			      currently_stepping (tp));
-	  xfree (statstr);
 	}
     }
 
@@ -3418,7 +3416,7 @@ void
 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
 			   const struct target_waitstatus *ws)
 {
-  char *status_string = target_waitstatus_to_string (ws);
+  std::string status_string = target_waitstatus_to_string (ws);
   string_file stb;
 
   /* The text is split over several lines because it was getting too long.
@@ -3438,13 +3436,11 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
 	      ptid_get_lwp (result_ptid),
 	      ptid_get_tid (result_ptid),
 	      target_pid_to_str (result_ptid));
-  stb.printf ("infrun:   %s\n", status_string);
+  stb.printf ("infrun:   %s\n", status_string.c_str ());
 
   /* This uses %s in part to handle %'s in the text, but also to avoid
      a gcc error: the format attribute requires a string literal.  */
   fprintf_unfiltered (gdb_stdlog, "%s", stb.c_str ());
-
-  xfree (status_string);
 }
 
 /* Select a thread at random, out of those which are resumed and have
@@ -3566,14 +3562,13 @@ do_target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
     {
       if (debug_infrun)
 	{
-	  char *statstr;
+	  std::string statstr
+	    = target_waitstatus_to_string (&tp->suspend.waitstatus);
 
-	  statstr = target_waitstatus_to_string (&tp->suspend.waitstatus);
 	  fprintf_unfiltered (gdb_stdlog,
 			      "infrun: Using pending wait status %s for %s.\n",
-			      statstr,
+			      statstr.c_str (),
 			      target_pid_to_str (tp->ptid));
-	  xfree (statstr);
 	}
 
       /* Now that we've selected our final event LWP, un-adjust its PC
@@ -4395,16 +4390,14 @@ save_waitstatus (struct thread_info *tp, struct target_waitstatus *ws)
 
   if (debug_infrun)
     {
-      char *statstr;
+      std::string statstr = target_waitstatus_to_string (ws);
 
-      statstr = target_waitstatus_to_string (ws);
       fprintf_unfiltered (gdb_stdlog,
 			  "infrun: saving status %s for %d.%ld.%ld\n",
-			  statstr,
+			  statstr.c_str (),
 			  ptid_get_pid (tp->ptid),
 			  ptid_get_lwp (tp->ptid),
 			  ptid_get_tid (tp->ptid));
-      xfree (statstr);
     }
 
   /* Record for later.  */
@@ -4634,17 +4627,15 @@ stop_all_threads (void)
 
 		  if (debug_infrun)
 		    {
-		      char *statstr;
+		      std::string statstr = target_waitstatus_to_string (&ws);
 
-		      statstr = target_waitstatus_to_string (&ws);
 		      fprintf_unfiltered (gdb_stdlog,
 					  "infrun: target_wait %s, saving "
 					  "status for %d.%ld.%ld\n",
-					  statstr,
+					  statstr.c_str (),
 					  ptid_get_pid (t->ptid),
 					  ptid_get_lwp (t->ptid),
 					  ptid_get_tid (t->ptid));
-		      xfree (statstr);
 		    }
 
 		  /* Record for later.  */
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index b216f1f..6ac8573 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -2478,7 +2478,7 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid,
       *status = btrace_step_no_resumed ();
 
       DEBUG ("wait ended by %s: %s", target_pid_to_str (null_ptid),
-	     target_waitstatus_to_string (status));
+	     target_waitstatus_to_string (status).c_str ());
 
       do_cleanups (cleanups);
       return null_ptid;
@@ -2570,7 +2570,7 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid,
   DEBUG ("wait ended by thread %s (%s): %s",
 	 print_thread_id (eventing),
 	 target_pid_to_str (eventing->ptid),
-	 target_waitstatus_to_string (status));
+	 target_waitstatus_to_string (status).c_str ());
 
   do_cleanups (cleanups);
   return eventing->ptid;
diff --git a/gdb/target-debug.h b/gdb/target-debug.h
index 6923608..532e98d 100644
--- a/gdb/target-debug.h
+++ b/gdb/target-debug.h
@@ -166,10 +166,9 @@
 static void
 target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
 {
-  char *str = target_waitstatus_to_string (status);
+  std::string str = target_waitstatus_to_string (status);
 
-  fputs_unfiltered (str, gdb_stdlog);
-  xfree (str);
+  fputs_unfiltered (str.c_str (), gdb_stdlog);
 }
 
 
diff --git a/gdb/target.h b/gdb/target.h
index c0155c1..5971151 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -108,10 +108,6 @@ struct syscall
     const char *name;
   };
 
-/* Return a pretty printed form of target_waitstatus.
-   Space for the result is malloc'd, caller must free.  */
-extern char *target_waitstatus_to_string (const struct target_waitstatus *);
-
 /* Return a pretty printed form of TARGET_OPTIONS.
    Space for the result is malloc'd, caller must free.  */
 extern char *target_options_to_string (int target_options);
diff --git a/gdb/target/waitstatus.c b/gdb/target/waitstatus.c
index c59d1b6..eede2d6 100644
--- a/gdb/target/waitstatus.c
+++ b/gdb/target/waitstatus.c
@@ -23,7 +23,7 @@
 /* Return a pretty printed form of target_waitstatus.
    Space for the result is malloc'd, caller must free.  */
 
-char *
+std::string
 target_waitstatus_to_string (const struct target_waitstatus *ws)
 {
   const char *kind_str = "status->kind = ";
@@ -31,44 +31,44 @@ target_waitstatus_to_string (const struct target_waitstatus *ws)
   switch (ws->kind)
     {
     case TARGET_WAITKIND_EXITED:
-      return xstrprintf ("%sexited, status = %d",
-			 kind_str, ws->value.integer);
+      return string_printf ("%sexited, status = %d",
+			    kind_str, ws->value.integer);
     case TARGET_WAITKIND_STOPPED:
-      return xstrprintf ("%sstopped, signal = %s",
-			 kind_str,
-			 gdb_signal_to_symbol_string (ws->value.sig));
+      return string_printf ("%sstopped, signal = %s",
+			    kind_str,
+			    gdb_signal_to_symbol_string (ws->value.sig));
     case TARGET_WAITKIND_SIGNALLED:
-      return xstrprintf ("%ssignalled, signal = %s",
-			 kind_str,
-			 gdb_signal_to_symbol_string (ws->value.sig));
+      return string_printf ("%ssignalled, signal = %s",
+			    kind_str,
+			    gdb_signal_to_symbol_string (ws->value.sig));
     case TARGET_WAITKIND_LOADED:
-      return xstrprintf ("%sloaded", kind_str);
+      return string_printf ("%sloaded", kind_str);
     case TARGET_WAITKIND_FORKED:
-      return xstrprintf ("%sforked", kind_str);
+      return string_printf ("%sforked", kind_str);
     case TARGET_WAITKIND_VFORKED:
-      return xstrprintf ("%svforked", kind_str);
+      return string_printf ("%svforked", kind_str);
     case TARGET_WAITKIND_EXECD:
-      return xstrprintf ("%sexecd", kind_str);
+      return string_printf ("%sexecd", kind_str);
     case TARGET_WAITKIND_VFORK_DONE:
-      return xstrprintf ("%svfork-done", kind_str);
+      return string_printf ("%svfork-done", kind_str);
     case TARGET_WAITKIND_SYSCALL_ENTRY:
-      return xstrprintf ("%sentered syscall", kind_str);
+      return string_printf ("%sentered syscall", kind_str);
     case TARGET_WAITKIND_SYSCALL_RETURN:
-      return xstrprintf ("%sexited syscall", kind_str);
+      return string_printf ("%sexited syscall", kind_str);
     case TARGET_WAITKIND_SPURIOUS:
-      return xstrprintf ("%sspurious", kind_str);
+      return string_printf ("%sspurious", kind_str);
     case TARGET_WAITKIND_IGNORE:
-      return xstrprintf ("%signore", kind_str);
+      return string_printf ("%signore", kind_str);
     case TARGET_WAITKIND_NO_HISTORY:
-      return xstrprintf ("%sno-history", kind_str);
+      return string_printf ("%sno-history", kind_str);
     case TARGET_WAITKIND_NO_RESUMED:
-      return xstrprintf ("%sno-resumed", kind_str);
+      return string_printf ("%sno-resumed", kind_str);
     case TARGET_WAITKIND_THREAD_CREATED:
-      return xstrprintf ("%sthread created", kind_str);
+      return string_printf ("%sthread created", kind_str);
     case TARGET_WAITKIND_THREAD_EXITED:
-      return xstrprintf ("%sthread exited, status = %d",
-			 kind_str, ws->value.integer);
+      return string_printf ("%sthread exited, status = %d",
+			    kind_str, ws->value.integer);
     default:
-      return xstrprintf ("%sunknown???", kind_str);
+      return string_printf ("%sunknown???", kind_str);
     }
 }
diff --git a/gdb/target/waitstatus.h b/gdb/target/waitstatus.h
index 52be390..8eee198 100644
--- a/gdb/target/waitstatus.h
+++ b/gdb/target/waitstatus.h
@@ -145,8 +145,7 @@ enum target_stop_reason
 
 /* Prototypes */
 
-/* Return a pretty printed form of target_waitstatus.
-   Space for the result is malloc'd, caller must free.  */
-extern char *target_waitstatus_to_string (const struct target_waitstatus *);
+/* Return a pretty printed form of target_waitstatus.  */
+std::string target_waitstatus_to_string (const struct target_waitstatus *);
 
 #endif /* WAITSTATUS_H */


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