Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH v2 1/3] Constify thread name return path
Date: Wed, 25 Nov 2015 21:49:00 -0000	[thread overview]
Message-ID: <1448488138-2360-2-git-send-email-simon.marchi@ericsson.com> (raw)
In-Reply-To: <1448488138-2360-1-git-send-email-simon.marchi@ericsson.com>

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/linux-nat.c           |  2 +-
 gdb/python/py-infthread.c |  2 +-
 gdb/target-delegates.c    | 10 +++++-----
 gdb/target.c              |  2 +-
 gdb/target.h              |  4 ++--
 gdb/thread.c              |  4 ++--
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 841ec39..2421687 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -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);
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 4d0a020..e5db354 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -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);
 
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index 253c9d7..b41b316 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -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;
 }
diff --git a/gdb/target.c b/gdb/target.c
index 2365cd3..b43c12a 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -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);
diff --git a/gdb/target.h b/gdb/target.h
index e80bee5..ac28a41 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -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.
diff --git a/gdb/thread.c b/gdb/thread.c
index b47d990..f8103bd 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -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')
-- 
2.5.1


  parent reply	other threads:[~2015-11-25 21:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-25 21:49 [PATCH v2 0/3] Remote thread name support Simon Marchi
2015-11-25 21:49 ` [PATCH v2 2/3] Display names of remote threads Simon Marchi
2015-11-26 11:32   ` Pedro Alves
2015-11-26 15:52     ` Simon Marchi
2015-11-26 16:30       ` Pedro Alves
2015-11-26 17:00         ` Simon Marchi
2015-11-27 14:37       ` Yao Qi
2015-11-27 15:16         ` Simon Marchi
2015-12-01 17:08       ` [commit] Fix build error (Re: [PATCH v2 2/3] Display names of remote threads) Ulrich Weigand
2015-12-01 17:54         ` Simon Marchi
2015-11-25 21:49 ` [PATCH v2 3/3] Add test for thread names Simon Marchi
2015-11-26 11:45   ` Pedro Alves
2015-11-26 16:00     ` Simon Marchi
2015-11-26 16:57       ` Pedro Alves
2015-11-26 18:21         ` Simon Marchi
2015-11-25 21:49 ` Simon Marchi [this message]
2015-11-26 11:21   ` [PATCH v2 1/3] Constify thread name return path Pedro Alves
2015-11-26 15:46     ` Simon Marchi
2015-11-27 13:31 ` gdb fails to build (was: Re: [PATCH v2 0/3] Remote thread name support) Tobias Burnus
2015-11-27 15:49   ` gdb fails to build Simon Marchi
2015-11-27 19:05     ` Simon Marchi
2015-11-27 22:36       ` Tobias Burnus
2015-11-27 22:47         ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1448488138-2360-2-git-send-email-simon.marchi@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox