-Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info

-Wwrite-strings flagged a missing cast for example here:

   static char *
   ravenscar_extra_thread_info (struct target_ops *self, struct thread_info *tp)
   {
     return "Ravenscar task";

Since callers are not supposed to free the string returned by these
methods, change the methods' signature to return const strings.

gdb/ChangeLog:
2017-04-05  Pedro Alves  <palves@redhat.com>

	* aix-thread.c (aix_thread_pid_to_str)
	(aix_thread_extra_thread_info): Constify.
	* bsd-kvm.c (bsd_kvm_pid_to_str): Constify.
	* bsd-uthread.c (bsd_uthread_extra_thread_info)
	(bsd_uthread_pid_to_str): Constify.
	* corelow.c (core_pid_to_str): Constify.
	* darwin-nat.c (darwin_pid_to_str): Constify.
	* fbsd-nat.c (fbsd_pid_to_str): Constify.
	* fbsd-tdep.c (fbsd_core_pid_to_str, gdbarch_core_pid_to_str):
	Constify.
	* gnu-nat.c (gnu_pid_to_str): Constify.
	* go32-nat.c (go32_pid_to_str): Constify.
	* i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Constify.
	* inf-ptrace.c (inf_ptrace_pid_to_str): Constify.
	* inferior.c (inferior_pid_to_str): Constify.
	* linux-nat.c (linux_nat_pid_to_str): Constify.
	* linux-tdep.c (linux_core_pid_to_str): Constify.
	* linux-thread-db.c (thread_db_pid_to_str)
	(thread_db_extra_thread_info): Constify.
	* nto-tdep.c (nto_extra_thread_info): Constify.
	* nto-tdep.h (nto_extra_thread_info): Constify.
	* obsd-nat.c (obsd_pid_to_str): Constify.
	* procfs.c (procfs_pid_to_str): Constify.
	* ravenscar-thread.c (ravenscar_extra_thread_info)
	(ravenscar_pid_to_str): Constify.
	* remote-sim.c (gdbsim_pid_to_str): Constify.
	* remote.c (remote_threads_extra_info, remote_pid_to_str):
	Constify.
	* sol-thread.c (solaris_pid_to_str): Constify.
	* sol2-tdep.c (sol2_core_pid_to_str): Constify.
	* sol2-tdep.h (sol2_core_pid_to_str): Constify.
	* target.c (default_pid_to_str, target_pid_to_str)
	(normal_pid_to_str, default_pid_to_str): Constify.
	* target.h (target_ops::to_pid_to_str)
	(target_ops::to_extra_thread_info): Constify.
	(target_pid_to_str, normal_pid_to_str): Constify.
	* windows-nat.c (windows_pid_to_str): Constify.
	* gdbarch.sh (core_pid_to_str): Constify.
	* target-delegates.c: Regenerate.
	* gdbarch.h, gdbarch.c: Regenerate.
This commit is contained in:
Pedro Alves 2017-04-05 19:21:34 +01:00
parent 69bbf46523
commit 7a1149643d
33 changed files with 99 additions and 56 deletions

View File

@ -1,3 +1,46 @@
2017-04-05 Pedro Alves <palves@redhat.com>
* aix-thread.c (aix_thread_pid_to_str)
(aix_thread_extra_thread_info): Constify.
* bsd-kvm.c (bsd_kvm_pid_to_str): Constify.
* bsd-uthread.c (bsd_uthread_extra_thread_info)
(bsd_uthread_pid_to_str): Constify.
* corelow.c (core_pid_to_str): Constify.
* darwin-nat.c (darwin_pid_to_str): Constify.
* fbsd-nat.c (fbsd_pid_to_str): Constify.
* fbsd-tdep.c (fbsd_core_pid_to_str, gdbarch_core_pid_to_str):
Constify.
* gnu-nat.c (gnu_pid_to_str): Constify.
* go32-nat.c (go32_pid_to_str): Constify.
* i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Constify.
* inf-ptrace.c (inf_ptrace_pid_to_str): Constify.
* inferior.c (inferior_pid_to_str): Constify.
* linux-nat.c (linux_nat_pid_to_str): Constify.
* linux-tdep.c (linux_core_pid_to_str): Constify.
* linux-thread-db.c (thread_db_pid_to_str)
(thread_db_extra_thread_info): Constify.
* nto-tdep.c (nto_extra_thread_info): Constify.
* nto-tdep.h (nto_extra_thread_info): Constify.
* obsd-nat.c (obsd_pid_to_str): Constify.
* procfs.c (procfs_pid_to_str): Constify.
* ravenscar-thread.c (ravenscar_extra_thread_info)
(ravenscar_pid_to_str): Constify.
* remote-sim.c (gdbsim_pid_to_str): Constify.
* remote.c (remote_threads_extra_info, remote_pid_to_str):
Constify.
* sol-thread.c (solaris_pid_to_str): Constify.
* sol2-tdep.c (sol2_core_pid_to_str): Constify.
* sol2-tdep.h (sol2_core_pid_to_str): Constify.
* target.c (default_pid_to_str, target_pid_to_str)
(normal_pid_to_str, default_pid_to_str): Constify.
* target.h (target_ops::to_pid_to_str)
(target_ops::to_extra_thread_info): Constify.
(target_pid_to_str, normal_pid_to_str): Constify.
* windows-nat.c (windows_pid_to_str): Constify.
* gdbarch.sh (core_pid_to_str): Constify.
* target-delegates.c: Regenerate.
* gdbarch.h, gdbarch.c: Regenerate.
2017-04-05 Pedro Alves <palves@redhat.com>
* main.c (captured_main_1): Use gdb::unique_xmalloc_ptr to manage

View File

@ -1725,7 +1725,7 @@ aix_thread_thread_alive (struct target_ops *ops, ptid_t ptid)
/* Return a printable representation of composite PID for use in
"info threads" output. */
static char *
static const char *
aix_thread_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char *ret = NULL;
@ -1745,7 +1745,7 @@ aix_thread_pid_to_str (struct target_ops *ops, ptid_t ptid)
/* Return a printable representation of extra information about
THREAD, for use in "info threads" output. */
static char *
static const char *
aix_thread_extra_thread_info (struct target_ops *self,
struct thread_info *thread)
{

View File

@ -329,7 +329,7 @@ bsd_kvm_thread_alive (struct target_ops *ops,
return 1;
}
static char *
static const char *
bsd_kvm_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[64];

View File

@ -491,7 +491,7 @@ static char *bsd_uthread_state[] =
/* Return a string describing th state of the thread specified by
INFO. */
static char *
static const char *
bsd_uthread_extra_thread_info (struct target_ops *self,
struct thread_info *info)
{
@ -511,7 +511,7 @@ bsd_uthread_extra_thread_info (struct target_ops *self,
return NULL;
}
static char *
static const char *
bsd_uthread_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
if (ptid_get_tid (ptid) != 0)

View File

@ -965,7 +965,7 @@ core_read_description (struct target_ops *target)
return target->beneath->to_read_description (target->beneath);
}
static char *
static const char *
core_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[64];

View File

@ -107,7 +107,7 @@ static void darwin_create_inferior (struct target_ops *ops, char *exec_file,
static void darwin_files_info (struct target_ops *ops);
static char *darwin_pid_to_str (struct target_ops *ops, ptid_t tpid);
static const char *darwin_pid_to_str (struct target_ops *ops, ptid_t tpid);
static int darwin_thread_alive (struct target_ops *ops, ptid_t tpid);
@ -1970,7 +1970,7 @@ darwin_files_info (struct target_ops *ops)
{
}
static char *
static const char *
darwin_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[80];

View File

@ -368,7 +368,7 @@ fbsd_thread_alive (struct target_ops *ops, ptid_t ptid)
/* Convert PTID to a string. Returns the string in a static
buffer. */
static char *
static const char *
fbsd_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
lwpid_t lwp;

View File

@ -32,7 +32,7 @@
/* This is how we want PTIDs from core files to be printed. */
static char *
static const char *
fbsd_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
{
static char buf[80];

View File

@ -3691,7 +3691,7 @@ gdbarch_core_pid_to_str_p (struct gdbarch *gdbarch)
return gdbarch->core_pid_to_str != NULL;
}
char *
const char *
gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
{
gdb_assert (gdbarch != NULL);

View File

@ -906,8 +906,8 @@ extern void set_gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
extern int gdbarch_core_pid_to_str_p (struct gdbarch *gdbarch);
typedef char * (gdbarch_core_pid_to_str_ftype) (struct gdbarch *gdbarch, ptid_t ptid);
extern char * gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
typedef const char * (gdbarch_core_pid_to_str_ftype) (struct gdbarch *gdbarch, ptid_t ptid);
extern const char * gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
extern void set_gdbarch_core_pid_to_str (struct gdbarch *gdbarch, gdbarch_core_pid_to_str_ftype *core_pid_to_str);
/* How the core target extracts the name of a thread from a core file. */

View File

@ -745,7 +745,7 @@ M:ULONGEST:core_xfer_shared_libraries:gdb_byte *readbuf, ULONGEST offset, ULONGE
M:ULONGEST:core_xfer_shared_libraries_aix:gdb_byte *readbuf, ULONGEST offset, ULONGEST len:readbuf, offset, len
# How the core target converts a PTID from a core file to a string.
M:char *:core_pid_to_str:ptid_t ptid:ptid
M:const char *:core_pid_to_str:ptid_t ptid:ptid
# How the core target extracts the name of a thread from a core file.
M:const char *:core_thread_name:struct thread_info *thr:thr

View File

@ -2652,7 +2652,7 @@ proc_string (struct proc *proc)
return tid_str;
}
static char *
static const char *
gnu_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
struct inf *inf = gnu_current_inf;

View File

@ -941,7 +941,7 @@ go32_thread_alive (struct target_ops *ops, ptid_t ptid)
return !ptid_equal (ptid, null_ptid);
}
static char *
static const char *
go32_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
return normal_pid_to_str (ptid);

View File

@ -178,7 +178,7 @@ windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
/* This is how we want PTIDs from core files to be printed. */
static char *
static const char *
i386_windows_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
{
static char buf[80];

View File

@ -619,7 +619,7 @@ inf_ptrace_files_info (struct target_ops *ignore)
target_pid_to_str (inferior_ptid));
}
static char *
static const char *
inf_ptrace_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
return normal_pid_to_str (ptid);

View File

@ -542,7 +542,7 @@ number_of_inferiors (void)
/* Converts an inferior process id to a string. Like
target_pid_to_str, but special cases the null process. */
static char *
static const char *
inferior_pid_to_str (int pid)
{
if (pid != 0)

View File

@ -3940,7 +3940,7 @@ linux_nat_update_thread_list (struct target_ops *ops)
}
}
static char *
static const char *
linux_nat_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[64];

View File

@ -407,7 +407,7 @@ linux_has_shared_address_space (struct gdbarch *gdbarch)
/* This is how we want PTIDs from core files to be printed. */
static char *
static const char *
linux_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
{
static char buf[80];

View File

@ -1372,7 +1372,7 @@ thread_db_update_thread_list (struct target_ops *ops)
ops->beneath->to_update_thread_list (ops->beneath);
}
static char *
static const char *
thread_db_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
struct thread_info *thread_info = find_thread_ptid (ptid);
@ -1397,7 +1397,7 @@ thread_db_pid_to_str (struct target_ops *ops, ptid_t ptid)
/* Return a string describing the state of the thread specified by
INFO. */
static char *
static const char *
thread_db_extra_thread_info (struct target_ops *self,
struct thread_info *info)
{

View File

@ -408,7 +408,7 @@ static const char *nto_thread_state_str[] =
"NET_REPLY" /* 20 0x14 */
};
char *
const char *
nto_extra_thread_info (struct target_ops *self, struct thread_info *ti)
{
if (ti && ti->priv

View File

@ -176,7 +176,7 @@ void nto_dummy_supply_regset (struct regcache *regcache, char *regs);
int nto_in_dynsym_resolve_code (CORE_ADDR pc);
char *nto_extra_thread_info (struct target_ops *self, struct thread_info *);
const char *nto_extra_thread_info (struct target_ops *self, struct thread_info *);
LONGEST nto_read_auxv_from_initial_stack (CORE_ADDR inital_stack,
gdb_byte *readbuf,

View File

@ -35,7 +35,7 @@
#ifdef PT_GET_THREAD_FIRST
static char *
static const char *
obsd_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
if (ptid_get_lwp (ptid) != 0)

View File

@ -135,7 +135,7 @@ static target_xfer_partial_ftype procfs_xfer_partial;
static int procfs_thread_alive (struct target_ops *ops, ptid_t);
static void procfs_update_thread_list (struct target_ops *ops);
static char *procfs_pid_to_str (struct target_ops *, ptid_t);
static const char *procfs_pid_to_str (struct target_ops *, ptid_t);
static int proc_find_memory_regions (struct target_ops *self,
find_memory_region_ftype, void *);
@ -4691,7 +4691,7 @@ procfs_thread_alive (struct target_ops *ops, ptid_t ptid)
/* Convert PTID to a string. Returns the string in a static
buffer. */
static char *
static const char *
procfs_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[80];

View File

@ -54,8 +54,8 @@ static const char ravenscar_runtime_initializer[] =
static void ravenscar_update_thread_list (struct target_ops *ops);
static ptid_t ravenscar_running_thread (void);
static char *ravenscar_extra_thread_info (struct target_ops *self,
struct thread_info *tp);
static const char *ravenscar_extra_thread_info (struct target_ops *self,
struct thread_info *tp);
static int ravenscar_thread_alive (struct target_ops *ops, ptid_t ptid);
static void ravenscar_fetch_registers (struct target_ops *ops,
struct regcache *regcache, int regnum);
@ -241,7 +241,7 @@ ravenscar_running_thread (void)
return ptid_build (ptid_get_pid (base_ptid), 0, tid);
}
static char *
static const char *
ravenscar_extra_thread_info (struct target_ops *self, struct thread_info *tp)
{
return "Ravenscar task";
@ -254,7 +254,7 @@ ravenscar_thread_alive (struct target_ops *ops, ptid_t ptid)
return 1;
}
static char *
static const char *
ravenscar_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[30];

View File

@ -1270,7 +1270,7 @@ gdbsim_thread_alive (struct target_ops *ops, ptid_t ptid)
/* Convert a thread ID to a string. Returns the string in a static
buffer. */
static char *
static const char *
gdbsim_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
return normal_pid_to_str (ptid);

View File

@ -3354,7 +3354,7 @@ remote_update_thread_list (struct target_ops *ops)
* Optional: targets are not required to implement this function.
*/
static char *
static const char *
remote_threads_extra_info (struct target_ops *self, struct thread_info *tp)
{
struct remote_state *rs = get_remote_state ();
@ -10946,7 +10946,7 @@ init_remote_threadtests (void)
/* Convert a thread ID to a string. Returns the string in a static
buffer. */
static char *
static const char *
remote_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[64];

View File

@ -1021,7 +1021,7 @@ ps_lgetLDT (gdb_ps_prochandle_t ph, lwpid_t lwpid,
/* Convert PTID to printable form. */
static char *
static const char *
solaris_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[100];

View File

@ -40,7 +40,7 @@ sol2_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
/* This is how we want PTIDs from Solaris core files to be
printed. */
char *
const char *
sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
{
static char buf[80];

View File

@ -24,6 +24,6 @@ struct gdbarch;
CORE_ADDR sol2_skip_solib_resolver (struct gdbarch *, CORE_ADDR);
char *sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
const char *sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
#endif /* sol2-tdep.h */

View File

@ -1502,17 +1502,17 @@ debug_update_thread_list (struct target_ops *self)
fputs_unfiltered (")\n", gdb_stdlog);
}
static char *
static const char *
delegate_pid_to_str (struct target_ops *self, ptid_t arg1)
{
self = self->beneath;
return self->to_pid_to_str (self, arg1);
}
static char *
static const char *
debug_pid_to_str (struct target_ops *self, ptid_t arg1)
{
char * result;
const char * result;
fprintf_unfiltered (gdb_stdlog, "-> %s->to_pid_to_str (...)\n", debug_target.to_shortname);
result = debug_target.to_pid_to_str (&debug_target, arg1);
fprintf_unfiltered (gdb_stdlog, "<- %s->to_pid_to_str (", debug_target.to_shortname);
@ -1520,28 +1520,28 @@ debug_pid_to_str (struct target_ops *self, ptid_t arg1)
fputs_unfiltered (", ", gdb_stdlog);
target_debug_print_ptid_t (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;
}
static char *
static const char *
delegate_extra_thread_info (struct target_ops *self, struct thread_info *arg1)
{
self = self->beneath;
return self->to_extra_thread_info (self, arg1);
}
static char *
static const char *
tdefault_extra_thread_info (struct target_ops *self, struct thread_info *arg1)
{
return NULL;
}
static char *
static const char *
debug_extra_thread_info (struct target_ops *self, struct thread_info *arg1)
{
char * result;
const char * result;
fprintf_unfiltered (gdb_stdlog, "-> %s->to_extra_thread_info (...)\n", debug_target.to_shortname);
result = debug_target.to_extra_thread_info (&debug_target, arg1);
fprintf_unfiltered (gdb_stdlog, "<- %s->to_extra_thread_info (", debug_target.to_shortname);
@ -1549,7 +1549,7 @@ debug_extra_thread_info (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;
}

View File

@ -103,7 +103,7 @@ static int dummy_find_memory_regions (struct target_ops *self,
static char *dummy_make_corefile_notes (struct target_ops *self,
bfd *ignore1, int *ignore2);
static char *default_pid_to_str (struct target_ops *ops, ptid_t ptid);
static const char *default_pid_to_str (struct target_ops *ops, ptid_t ptid);
static enum exec_direction_kind default_execution_direction
(struct target_ops *self);
@ -2303,7 +2303,7 @@ default_target_wait (struct target_ops *ops,
return minus_one_ptid;
}
char *
const char *
target_pid_to_str (ptid_t ptid)
{
return (*current_target.to_pid_to_str) (&current_target, ptid);
@ -3344,7 +3344,7 @@ generic_mourn_inferior (void)
/* Convert a normal process ID to a string. Returns the string in a
static buffer. */
char *
const char *
normal_pid_to_str (ptid_t ptid)
{
static char buf[32];
@ -3353,7 +3353,7 @@ normal_pid_to_str (ptid_t ptid)
return buf;
}
static char *
static const char *
default_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
return normal_pid_to_str (ptid);

View File

@ -639,9 +639,9 @@ struct target_ops
TARGET_DEFAULT_RETURN (0);
void (*to_update_thread_list) (struct target_ops *)
TARGET_DEFAULT_IGNORE ();
char *(*to_pid_to_str) (struct target_ops *, ptid_t)
const char *(*to_pid_to_str) (struct target_ops *, ptid_t)
TARGET_DEFAULT_FUNC (default_pid_to_str);
char *(*to_extra_thread_info) (struct target_ops *, struct thread_info *)
const char *(*to_extra_thread_info) (struct target_ops *, struct thread_info *)
TARGET_DEFAULT_RETURN (NULL);
const char *(*to_thread_name) (struct target_ops *, struct thread_info *)
TARGET_DEFAULT_RETURN (NULL);
@ -1851,9 +1851,9 @@ extern int target_is_non_stop_p (void);
`process xyz', but on some systems it may contain
`process xyz thread abc'. */
extern char *target_pid_to_str (ptid_t ptid);
extern const char *target_pid_to_str (ptid_t ptid);
extern char *normal_pid_to_str (ptid_t ptid);
extern const char *normal_pid_to_str (ptid_t ptid);
/* Return a short string describing extra information about PID,
e.g. "sleeping", "runnable", "running on LWP 3". Null return value

View File

@ -2807,7 +2807,7 @@ windows_close (struct target_ops *self)
}
/* Convert pid to printable format. */
static char *
static const char *
windows_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[80];