gdb, gdbserver: make status_to_str return std::string
authorSimon Marchi <simon.marchi@polymtl.ca>
Sun, 9 May 2021 01:06:41 +0000 (21:06 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sun, 9 May 2021 01:07:20 +0000 (21:07 -0400)
Instead of using a static buffer.  This is safer, and we don't really
mind about any extra dynamic allocation here, since it's only used for
debug purposes.

gdb/ChangeLog:

* nat/linux-waitpid.c (status_to_str): Return std::string.
* nat/linux-waitpid.h (status_to_str): Likewise.
* linux-nat.c (linux_nat_post_attach_wait): Adjust.
(linux_nat_target::attach): Adjust.
(linux_handle_extended_wait): Adjust.
(wait_lwp): Adjust.
(stop_wait_callback): Adjust.
(linux_nat_filter_event): Adjust.
(linux_nat_wait_1): Adjust.
* nat/linux-waitpid.c (status_to_str): Adjust.
* nat/linux-waitpid.h (status_to_str): Adjust.

gdbserver/ChangeLog:

* linux-low.cc (linux_process_target::wait_for_event_filtered):
Adjust to status_to_str returning std::string.

Change-Id: Ia8aead70270438a5690f243e6faafff6c38ff757

gdb/ChangeLog
gdb/linux-nat.c
gdb/nat/linux-waitpid.c
gdb/nat/linux-waitpid.h
gdbserver/ChangeLog
gdbserver/linux-low.cc

index e7e48f0cc3e2636692ddd7c848877a5de15e470e..75e344ff7073d3f843beeee0ff72587b9bdb459a 100644 (file)
@@ -1,3 +1,17 @@
+2021-05-08  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * nat/linux-waitpid.c (status_to_str): Return std::string.
+       * nat/linux-waitpid.h (status_to_str): Likewise.
+       * linux-nat.c (linux_nat_post_attach_wait): Adjust.
+       (linux_nat_target::attach): Adjust.
+       (linux_handle_extended_wait): Adjust.
+       (wait_lwp): Adjust.
+       (stop_wait_callback): Adjust.
+       (linux_nat_filter_event): Adjust.
+       (linux_nat_wait_1): Adjust.
+       * nat/linux-waitpid.c (status_to_str): Adjust.
+       * nat/linux-waitpid.h (status_to_str): Adjust.
+
 2021-05-08  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * infrun.h (infrun_debug_printf): Add missing space.
index e595c71c3d33028e5a5c7dc2b8d5bc3ac6d51017..34a2aee41d781ca7f1b448768c0491ac2a13f56e 100644 (file)
@@ -1061,7 +1061,7 @@ linux_nat_post_attach_wait (ptid_t ptid, int *signalled)
     {
       /* The pid we tried to attach has apparently just exited.  */
       linux_nat_debug_printf ("Failed to stop %d: %s", pid,
-                             status_to_str (status));
+                             status_to_str (status).c_str ());
       return status;
     }
 
@@ -1069,7 +1069,7 @@ linux_nat_post_attach_wait (ptid_t ptid, int *signalled)
     {
       *signalled = 1;
       linux_nat_debug_printf ("Received %s after attaching",
-                             status_to_str (status));
+                             status_to_str (status).c_str ());
     }
 
   return status;
@@ -1239,7 +1239,8 @@ linux_nat_target::attach (const char *args, int from_tty)
   /* Save the wait status to report later.  */
   lp->resumed = 1;
   linux_nat_debug_printf ("waitpid %ld, saving status %s",
-                         (long) lp->ptid.pid (), status_to_str (status));
+                         (long) lp->ptid.pid (),
+                         status_to_str (status).c_str ());
 
   lp->status = status;
 
@@ -2005,7 +2006,7 @@ linux_handle_extended_wait (struct lwp_info *lp, int status)
              /* Save the wait status to report later.  */
              linux_nat_debug_printf
                ("waitpid of new LWP %ld, saving status %s",
-                (long) new_lp->ptid.lwp (), status_to_str (status));
+                (long) new_lp->ptid.lwp (), status_to_str (status).c_str ());
              new_lp->status = status;
            }
          else if (report_thread_events)
@@ -2153,7 +2154,7 @@ wait_lwp (struct lwp_info *lp)
 
       linux_nat_debug_printf ("waitpid %s received %s",
                              target_pid_to_str (lp->ptid).c_str (),
-                             status_to_str (status));
+                             status_to_str (status).c_str ());
 
       /* Check if the thread has exited.  */
       if (WIFEXITED (status) || WIFSIGNALED (status))
@@ -2440,7 +2441,7 @@ stop_wait_callback (struct lwp_info *lp)
          /* The thread was stopped with a signal other than SIGSTOP.  */
 
          linux_nat_debug_printf ("Pending event %s in %s",
-                                 status_to_str ((int) status),
+                                 status_to_str ((int) status).c_str (),
                                  target_pid_to_str (lp->ptid).c_str ());
 
          /* Save the sigtrap event.  */
@@ -2859,7 +2860,7 @@ linux_nat_filter_event (int lwpid, int status)
   if (WIFSTOPPED (status) && !lp)
     {
       linux_nat_debug_printf ("saving LWP %ld status %s in stopped_pids list",
-                             (long) lwpid, status_to_str (status));
+                             (long) lwpid, status_to_str (status).c_str ());
       add_to_pid_list (&stopped_pids, lwpid, status);
       return;
     }
@@ -3152,7 +3153,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
   if (lp != NULL)
     {
       linux_nat_debug_printf ("Using pending wait status %s for %s.",
-                             status_to_str (lp->status),
+                             status_to_str (lp->status).c_str (),
                              target_pid_to_str (lp->ptid).c_str ());
     }
 
@@ -3187,7 +3188,8 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
       if (lwpid > 0)
        {
          linux_nat_debug_printf ("waitpid %ld received %s",
-                                 (long) lwpid, status_to_str (status));
+                                 (long) lwpid,
+                                 status_to_str (status).c_str ());
 
          linux_nat_filter_event (lwpid, status);
          /* Retry until nothing comes out of waitpid.  A single
index 2d4c8eb58125913292eae149bf757f71a66555ff..f205df7a2464e0552d082449a8b2a3b6dc9f5194 100644 (file)
 #include "gdbsupport/gdb_wait.h"
 #include "gdbsupport/eintr.h"
 
-/* Convert wait status STATUS to a string.  Used for printing debug
-   messages only.  */
+/* See linux-waitpid.h.  */
 
-char *
+std::string
 status_to_str (int status)
 {
-  static char buf[64];
-
   if (WIFSTOPPED (status))
     {
       if (WSTOPSIG (status) == SYSCALL_SIGTRAP)
-       snprintf (buf, sizeof (buf), "%s (stopped at syscall)",
-                 strsignal (SIGTRAP));
+       return string_printf ("%s (stopped at syscall)",
+                             strsignal (SIGTRAP));
       else
-       snprintf (buf, sizeof (buf), "%s (stopped)",
-                 strsignal (WSTOPSIG (status)));
+       return string_printf ("%s (stopped)",
+                             strsignal (WSTOPSIG (status)));
     }
   else if (WIFSIGNALED (status))
-    snprintf (buf, sizeof (buf), "%s (terminated)",
-             strsignal (WTERMSIG (status)));
+    return string_printf ("%s (terminated)",
+                         strsignal (WTERMSIG (status)));
   else
-    snprintf (buf, sizeof (buf), "%d (exited)", WEXITSTATUS (status));
-
-  return buf;
+    return string_printf ("%d (exited)", WEXITSTATUS (status));
 }
 
 /* See linux-waitpid.h.  */
index 78056454da6d51c3573c2fba04344cae0b75af71..fe2383f1386c97c643fce1491b770bccffca6228 100644 (file)
@@ -25,6 +25,6 @@ extern int my_waitpid (int pid, int *status, int flags);
 
 /* Convert wait status STATUS to a string.  Used for printing debug
    messages only.  */
-extern char *status_to_str (int status);
+extern std::string status_to_str (int status);
 
 #endif /* NAT_LINUX_WAITPID_H */
index 6483d65700cd3b4ac1ad06177dea24e0e76558fa..7e7e3f2998043a7b2e21c4c74003511becd15b89 100644 (file)
@@ -1,3 +1,8 @@
+2021-05-08  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * linux-low.cc (linux_process_target::wait_for_event_filtered):
+       Adjust to status_to_str returning std::string.
+
 2021-05-08  Pedro Alves  <pedro@palves.net>
 
        * linux-low.cc:
index 9debe894eeb2b95dbf5b7f86b4f9188920a68a01..5c6191d941c3261d829198fc1ac451b050e7bc75 100644 (file)
@@ -2601,7 +2601,7 @@ linux_process_target::wait_for_event_filtered (ptid_t wait_ptid,
          if (debug_threads)
            {
              debug_printf ("LLW: waitpid %ld received %s\n",
-                           (long) ret, status_to_str (*wstatp));
+                           (long) ret, status_to_str (*wstatp).c_str ());
            }
 
          /* Filter all events.  IOW, leave all events pending.  We'll
This page took 0.036109 seconds and 4 git commands to generate.