Constify thread name return path
authorSimon Marchi <simon.marchi@ericsson.com>
Thu, 26 Nov 2015 14:49:03 +0000 (09:49 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Thu, 26 Nov 2015 14:49:03 +0000 (09:49 -0500)
Since this code path returns a string owned by the target (we don't know how
it's allocated, could be a static read-only string), it's safer if we return
a constant string.  If, for some reasons, the caller wishes to modify the
string, it should make itself a copy.

gdb/ChangeLog:

* linux-nat.c (linux_nat_thread_name): Constify return value.
* target.h (struct target_ops) <to_thread_name>: Likewise.
(target_thread_name): Likewise.
* target.c (target_thread_name): Likewise.
* target-delegates.c (debug_thread_name): Regenerate.
* python/py-infthread.c (thpy_get_name): Constify local variables.
* thread.c (print_thread_info): Likewise.
(thread_find_command): Likewise.

gdb/ChangeLog
gdb/linux-nat.c
gdb/python/py-infthread.c
gdb/target-delegates.c
gdb/target.c
gdb/target.h
gdb/thread.c

index 9c8b9e7e364e0576c9449c1eebeead488f201fa6..1d9cb4f975ac95440d49b60aa36da94cacc0aabb 100644 (file)
@@ -1,3 +1,14 @@
+2015-11-26  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * linux-nat.c (linux_nat_thread_name): Constify return value.
+       * target.h (struct target_ops) <to_thread_name>: Likewise.
+       (target_thread_name): Likewise.
+       * target.c (target_thread_name): Likewise.
+       * target-delegates.c (debug_thread_name): Regenerate.
+       * python/py-infthread.c (thpy_get_name): Constify local variables.
+       * thread.c (print_thread_info): Likewise.
+       (thread_find_command): Likewise.
+
 2015-11-26  Markus Metzger  <markus.t.metzger@intel.com>
 
        PR 19297
index 841ec3949c37438dfba924d8db6b37ffc416dd29..24216876c247ba4dbd5109a1e5abde81ce950bc9 100644 (file)
@@ -4097,7 +4097,7 @@ linux_nat_pid_to_str (struct target_ops *ops, ptid_t ptid)
   return normal_pid_to_str (ptid);
 }
 
-static char *
+static const char *
 linux_nat_thread_name (struct target_ops *self, struct thread_info *thr)
 {
   int pid = ptid_get_pid (thr->ptid);
index 4d0a020ba2acb4ee9d45eb64f831e8623c6ad37f..e5db3540dbfff201f71d3ec55a5d743e0c1c872e 100644 (file)
@@ -62,7 +62,7 @@ static PyObject *
 thpy_get_name (PyObject *self, void *ignore)
 {
   thread_object *thread_obj = (thread_object *) self;
-  char *name;
+  const char *name;
 
   THPY_REQUIRE_VALID (thread_obj);
 
index 253c9d76a6ca032d20a2c481394dd007bfa82099..b41b3168c8a986691571442a6aa03057792be6f2 100644 (file)
@@ -1530,23 +1530,23 @@ debug_extra_thread_info (struct target_ops *self, struct thread_info *arg1)
   return result;
 }
 
-static char *
+static const char *
 delegate_thread_name (struct target_ops *self, struct thread_info *arg1)
 {
   self = self->beneath;
   return self->to_thread_name (self, arg1);
 }
 
-static char *
+static const char *
 tdefault_thread_name (struct target_ops *self, struct thread_info *arg1)
 {
   return NULL;
 }
 
-static char *
+static const char *
 debug_thread_name (struct target_ops *self, struct thread_info *arg1)
 {
-  char * result;
+  const char * result;
   fprintf_unfiltered (gdb_stdlog, "-> %s->to_thread_name (...)\n", debug_target.to_shortname);
   result = debug_target.to_thread_name (&debug_target, arg1);
   fprintf_unfiltered (gdb_stdlog, "<- %s->to_thread_name (", debug_target.to_shortname);
@@ -1554,7 +1554,7 @@ debug_thread_name (struct target_ops *self, struct thread_info *arg1)
   fputs_unfiltered (", ", gdb_stdlog);
   target_debug_print_struct_thread_info_p (arg1);
   fputs_unfiltered (") = ", gdb_stdlog);
-  target_debug_print_char_p (result);
+  target_debug_print_const_char_p (result);
   fputs_unfiltered ("\n", gdb_stdlog);
   return result;
 }
index 2365cd3bd3fc647cef48d8fe02175a5a2f674950..b43c12a34de8254d0d7396d8d0ce68ee85b401ca 100644 (file)
@@ -2265,7 +2265,7 @@ target_pid_to_str (ptid_t ptid)
   return (*current_target.to_pid_to_str) (&current_target, ptid);
 }
 
-char *
+const char *
 target_thread_name (struct thread_info *info)
 {
   return current_target.to_thread_name (&current_target, info);
index e80bee5d494ccf4de74e4eb9cb03efaa4449382b..ac28a4169d989c3c5d01def41d30918fdf7fbd07 100644 (file)
@@ -639,7 +639,7 @@ struct target_ops
       TARGET_DEFAULT_FUNC (default_pid_to_str);
     char *(*to_extra_thread_info) (struct target_ops *, struct thread_info *)
       TARGET_DEFAULT_RETURN (NULL);
-    char *(*to_thread_name) (struct target_ops *, struct thread_info *)
+    const char *(*to_thread_name) (struct target_ops *, struct thread_info *)
       TARGET_DEFAULT_RETURN (NULL);
     void (*to_stop) (struct target_ops *, ptid_t)
       TARGET_DEFAULT_IGNORE ();
@@ -1823,7 +1823,7 @@ extern char *normal_pid_to_str (ptid_t ptid);
 /* Return the thread's name.  A NULL result means that the target
    could not determine this thread's name.  */
 
-extern char *target_thread_name (struct thread_info *);
+extern const char *target_thread_name (struct thread_info *);
 
 /* Attempts to find the pathname of the executable file
    that was run to create a specified process.
index b47d9901a8bd6ba5d19144ed2cd8a0777587b69b..f8103bd531818d14cd024a08bcdd687c142eca60 100644 (file)
@@ -1122,7 +1122,7 @@ print_thread_info (struct ui_out *uiout, char *requested_threads, int pid)
   struct thread_info *tp;
   ptid_t current_ptid;
   struct cleanup *old_chain;
-  char *extra_info, *name, *target_id;
+  const char *extra_info, *name, *target_id;
   int current_thread = -1;
 
   update_thread_list ();
@@ -1781,7 +1781,7 @@ static void
 thread_find_command (char *arg, int from_tty)
 {
   struct thread_info *tp;
-  char *tmp;
+  const char *tmp;
   unsigned long match = 0;
 
   if (arg == NULL || *arg == '\0')
This page took 0.03713 seconds and 4 git commands to generate.