From 52554a0e324951b5c58e71f2815e841377e9c50c Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 19 Mar 2013 09:23:17 -0600 Subject: [PATCH] constify to_detach This patch constifies the target_ops method to_detach. This is a small cleanup, but also, I think, a bug-prevention fix, since gdb already acts as if the "args" argument here was const. In particular, top.c:quit_force calls kill_or_detach via iterate_over_inferiors. kill_or_detach calls target_detach, passing the same argument each time. So, if one of these methods was not const-correct, then kill_or_detach would change its behavior in a strange way. I could not build every target I modified in this patch. I've inspected them all by hand, though. Many targets do not use the "args" parameter; a couple pass it to atoi; and a few pass it on to the to_detach method of the target beneath. The only code that required a real change was in linux-nat.c, and that only needed the introduction of a temporary variable for const-correctness. 2013-11-08 Tom Tromey * aix-thread.c (aix_thread_detach): Update. * corelow.c (core_detach): Update. * darwin-nat.c (darwin_detach): Update. * dec-thread.c (dec_thread_detach): Update. * gnu-nat.c (gnu_detach): Update. * go32-nat.c (go32_detach): Update. * inf-ptrace.c (inf_ptrace_detach): Update. * inf-ttrace.c (inf_ttrace_detach): Update. * linux-fork.c (linux_fork_detach): Update. * linux-fork.h (linux_fork_detach): Update. * linux-nat.c (linux_nat_detach): Update. Introduce "tem" local for const-correctness. * linux-thread-db.c (thread_db_detach): Update. * monitor.c (monitor_detach): Update. * nto-procfs.c (procfs_detach): Update. * procfs.c (procfs_detach): Update. * record.c (record_detach): Update. * record.h (record_detach): Update. * remote-m32r-sdi.c (m32r_detach): Update. * remote-mips.c (mips_detach): Update. * remote-sim.c (gdbsim_detach): Update. * remote.c (remote_detach_1, remote_detach) (extended_remote_detach): Update. * sol-thread.c (sol_thread_detach): Update. * target.c (target_detach): Make "args" const. (init_dummy_target): Update. * target.h (struct target_ops) : Make argument const. (target_detach): Likewise. * windows-nat.c (windows_detach): Update. --- gdb/ChangeLog | 32 ++++++++++++++++++++++++++++++++ gdb/aix-thread.c | 2 +- gdb/corelow.c | 4 +--- gdb/darwin-nat.c | 2 +- gdb/dec-thread.c | 2 +- gdb/gnu-nat.c | 2 +- gdb/go32-nat.c | 2 +- gdb/inf-ptrace.c | 2 +- gdb/inf-ttrace.c | 2 +- gdb/linux-fork.c | 2 +- gdb/linux-fork.h | 2 +- gdb/linux-nat.c | 9 ++++++--- gdb/linux-thread-db.c | 2 +- gdb/monitor.c | 2 +- gdb/nto-procfs.c | 2 +- gdb/procfs.c | 4 ++-- gdb/record.c | 2 +- gdb/record.h | 2 +- gdb/remote-m32r-sdi.c | 2 +- gdb/remote-mips.c | 4 +--- gdb/remote-sim.c | 2 +- gdb/remote.c | 8 +++----- gdb/sol-thread.c | 2 +- gdb/target.c | 4 ++-- gdb/target.h | 4 ++-- gdb/windows-nat.c | 2 +- 26 files changed, 67 insertions(+), 38 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1c23f962dcc..4d1c26d0167 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,35 @@ +2013-11-08 Tom Tromey + + * aix-thread.c (aix_thread_detach): Update. + * corelow.c (core_detach): Update. + * darwin-nat.c (darwin_detach): Update. + * dec-thread.c (dec_thread_detach): Update. + * gnu-nat.c (gnu_detach): Update. + * go32-nat.c (go32_detach): Update. + * inf-ptrace.c (inf_ptrace_detach): Update. + * inf-ttrace.c (inf_ttrace_detach): Update. + * linux-fork.c (linux_fork_detach): Update. + * linux-fork.h (linux_fork_detach): Update. + * linux-nat.c (linux_nat_detach): Update. Introduce "tem" + local for const-correctness. + * linux-thread-db.c (thread_db_detach): Update. + * monitor.c (monitor_detach): Update. + * nto-procfs.c (procfs_detach): Update. + * procfs.c (procfs_detach): Update. + * record.c (record_detach): Update. + * record.h (record_detach): Update. + * remote-m32r-sdi.c (m32r_detach): Update. + * remote-mips.c (mips_detach): Update. + * remote-sim.c (gdbsim_detach): Update. + * remote.c (remote_detach_1, remote_detach) + (extended_remote_detach): Update. + * sol-thread.c (sol_thread_detach): Update. + * target.c (target_detach): Make "args" const. + (init_dummy_target): Update. + * target.h (struct target_ops) : Make argument const. + (target_detach): Likewise. + * windows-nat.c (windows_detach): Update. + 2013-11-07 Doug Evans PR 11786 diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index 31758351361..373a09aabfd 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -967,7 +967,7 @@ aix_thread_attach (struct target_ops *ops, char *args, int from_tty) /* Detach from the process attached to by aix_thread_attach(). */ static void -aix_thread_detach (struct target_ops *ops, char *args, int from_tty) +aix_thread_detach (struct target_ops *ops, const char *args, int from_tty) { struct target_ops *beneath = find_target_beneath (ops); diff --git a/gdb/corelow.c b/gdb/corelow.c index d1e7f6ae7df..78f8120220c 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -85,8 +85,6 @@ static int gdb_check_format (bfd *); static void core_open (char *, int); -static void core_detach (struct target_ops *ops, char *, int); - static void core_close (void); static void core_close_cleanup (void *ignore); @@ -465,7 +463,7 @@ core_open (char *filename, int from_tty) } static void -core_detach (struct target_ops *ops, char *args, int from_tty) +core_detach (struct target_ops *ops, const char *args, int from_tty) { if (args) error (_("Too many arguments")); diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 6995c2565f5..a9157dbf069 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -1681,7 +1681,7 @@ darwin_attach (struct target_ops *ops, char *args, int from_tty) previously attached. It *might* work if the program was started via fork. */ static void -darwin_detach (struct target_ops *ops, char *args, int from_tty) +darwin_detach (struct target_ops *ops, const char *args, int from_tty) { pid_t pid = ptid_get_pid (inferior_ptid); struct inferior *inf = current_inferior (); diff --git a/gdb/dec-thread.c b/gdb/dec-thread.c index f07721d30dc..03768283f6f 100644 --- a/gdb/dec-thread.c +++ b/gdb/dec-thread.c @@ -444,7 +444,7 @@ resync_thread_list (struct target_ops *ops) /* The "to_detach" method of the dec_thread_ops. */ static void -dec_thread_detach (struct target_ops *ops, char *args, int from_tty) +dec_thread_detach (struct target_ops *ops, const char *args, int from_tty) { struct target_ops *beneath = find_target_beneath (ops); diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index 4a25759cfb8..659aa672820 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -2218,7 +2218,7 @@ gnu_attach (struct target_ops *ops, char *args, int from_tty) previously attached. It *might* work if the program was started via fork. */ static void -gnu_detach (struct target_ops *ops, char *args, int from_tty) +gnu_detach (struct target_ops *ops, const char *args, int from_tty) { int pid; diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c index 4dac617a7e8..a92a34f46e0 100644 --- a/gdb/go32-nat.c +++ b/gdb/go32-nat.c @@ -384,7 +384,7 @@ Use the `run' command to run DJGPP programs.")); } static void -go32_detach (struct target_ops *ops, char *args, int from_tty) +go32_detach (struct target_ops *ops, const char *args, int from_tty) { } diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index bdebe65f8fd..5e5e248352e 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -264,7 +264,7 @@ inf_ptrace_post_attach (int pid) specified by ARGS. If FROM_TTY is non-zero, be chatty about it. */ static void -inf_ptrace_detach (struct target_ops *ops, char *args, int from_tty) +inf_ptrace_detach (struct target_ops *ops, const char *args, int from_tty) { pid_t pid = ptid_get_pid (inferior_ptid); int sig = 0; diff --git a/gdb/inf-ttrace.c b/gdb/inf-ttrace.c index 36bf4cb722f..c715c7148f3 100644 --- a/gdb/inf-ttrace.c +++ b/gdb/inf-ttrace.c @@ -798,7 +798,7 @@ inf_ttrace_attach (struct target_ops *ops, char *args, int from_tty) } static void -inf_ttrace_detach (struct target_ops *ops, char *args, int from_tty) +inf_ttrace_detach (struct target_ops *ops, const char *args, int from_tty) { pid_t pid = ptid_get_pid (inferior_ptid); int sig = 0; diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index bff807e3ab6..754500f0a66 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -387,7 +387,7 @@ linux_fork_mourn_inferior (void) the first available. */ void -linux_fork_detach (char *args, int from_tty) +linux_fork_detach (const char *args, int from_tty) { /* OK, inferior_ptid is the one we are detaching from. We need to delete it from the fork_list, and switch to the next available diff --git a/gdb/linux-fork.h b/gdb/linux-fork.h index 5d924dec502..51b5112e525 100644 --- a/gdb/linux-fork.h +++ b/gdb/linux-fork.h @@ -22,6 +22,6 @@ extern struct fork_info *add_fork (pid_t); extern struct fork_info *find_fork_pid (pid_t); extern void linux_fork_killall (void); extern void linux_fork_mourn_inferior (void); -extern void linux_fork_detach (char *, int); +extern void linux_fork_detach (const char *, int); extern int forks_exist_p (void); extern int linux_fork_checkpointing_p (int); diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 4784a5e7db9..95064f74e73 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1557,7 +1557,7 @@ detach_callback (struct lwp_info *lp, void *data) } static void -linux_nat_detach (struct target_ops *ops, char *args, int from_tty) +linux_nat_detach (struct target_ops *ops, const char *args, int from_tty) { int pid; int status; @@ -1587,10 +1587,13 @@ linux_nat_detach (struct target_ops *ops, char *args, int from_tty) && get_pending_status (main_lwp, &status) != -1 && WIFSTOPPED (status)) { + char *tem; + /* Put the signal number in ARGS so that inf_ptrace_detach will pass it along with PTRACE_DETACH. */ - args = alloca (8); - sprintf (args, "%d", (int) WSTOPSIG (status)); + tem = alloca (8); + sprintf (tem, "%d", (int) WSTOPSIG (status)); + args = tem; if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "LND: Sending signal %s to %s\n", diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 593fc29b54e..4cc3a4cb64f 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1340,7 +1340,7 @@ detach_thread (ptid_t ptid) } static void -thread_db_detach (struct target_ops *ops, char *args, int from_tty) +thread_db_detach (struct target_ops *ops, const char *args, int from_tty) { struct target_ops *target_beneath = find_target_beneath (ops); struct thread_db_info *info; diff --git a/gdb/monitor.c b/gdb/monitor.c index 08153ddd68e..0f5d8ca2d97 100644 --- a/gdb/monitor.c +++ b/gdb/monitor.c @@ -875,7 +875,7 @@ monitor_close (void) when you want to detach and do something else with your gdb. */ static void -monitor_detach (struct target_ops *ops, char *args, int from_tty) +monitor_detach (struct target_ops *ops, const char *args, int from_tty) { unpush_target (ops); /* calls monitor_close to do the real work. */ if (from_tty) diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 1e6ec744b06..a9b427688cd 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -877,7 +877,7 @@ procfs_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int dowrite, on signals, etc. We'd better not have left any breakpoints in the program or it'll die when it hits one. */ static void -procfs_detach (struct target_ops *ops, char *args, int from_tty) +procfs_detach (struct target_ops *ops, const char *args, int from_tty) { int siggnal = 0; int pid; diff --git a/gdb/procfs.c b/gdb/procfs.c index e0130968b79..018a0d846b9 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -110,7 +110,7 @@ /* This module defines the GDB target vector and its methods. */ static void procfs_attach (struct target_ops *, char *, int); -static void procfs_detach (struct target_ops *, char *, int); +static void procfs_detach (struct target_ops *, const char *, int); static void procfs_resume (struct target_ops *, ptid_t, int, enum gdb_signal); static void procfs_stop (ptid_t); @@ -3071,7 +3071,7 @@ procfs_attach (struct target_ops *ops, char *args, int from_tty) } static void -procfs_detach (struct target_ops *ops, char *args, int from_tty) +procfs_detach (struct target_ops *ops, const char *args, int from_tty) { int sig = 0; int pid = ptid_get_pid (inferior_ptid); diff --git a/gdb/record.c b/gdb/record.c index 4078def1c38..ec2a0421075 100644 --- a/gdb/record.c +++ b/gdb/record.c @@ -141,7 +141,7 @@ record_disconnect (struct target_ops *t, char *args, int from_tty) /* See record.h. */ void -record_detach (struct target_ops *t, char *args, int from_tty) +record_detach (struct target_ops *t, const char *args, int from_tty) { gdb_assert (t->to_stratum == record_stratum); diff --git a/gdb/record.h b/gdb/record.h index 65d508fa05d..124c32be964 100644 --- a/gdb/record.h +++ b/gdb/record.h @@ -55,7 +55,7 @@ extern void cmd_record_goto (char *arg, int from_tty); extern void record_disconnect (struct target_ops *, char *, int); /* The default "to_detach" target method for record targets. */ -extern void record_detach (struct target_ops *, char *, int); +extern void record_detach (struct target_ops *, const char *, int); /* The default "to_mourn_inferior" target method for record targets. */ extern void record_mourn_inferior (struct target_ops *); diff --git a/gdb/remote-m32r-sdi.c b/gdb/remote-m32r-sdi.c index 81fea53955d..4ffb72df0fc 100644 --- a/gdb/remote-m32r-sdi.c +++ b/gdb/remote-m32r-sdi.c @@ -878,7 +878,7 @@ m32r_wait (struct target_ops *ops, Use this when you want to detach and do something else with your gdb. */ static void -m32r_detach (struct target_ops *ops, char *args, int from_tty) +m32r_detach (struct target_ops *ops, const char *args, int from_tty) { if (remote_debug) fprintf_unfiltered (gdb_stdlog, "m32r_detach(%d)\n", from_tty); diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c index bf6cce5357a..f8e6caca09b 100644 --- a/gdb/remote-mips.c +++ b/gdb/remote-mips.c @@ -86,8 +86,6 @@ static void lsi_open (char *name, int from_tty); static void mips_close (void); -static void mips_detach (struct target_ops *ops, char *args, int from_tty); - static int mips_map_regno (struct gdbarch *, int); static void mips_set_register (int regno, ULONGEST value); @@ -1749,7 +1747,7 @@ mips_close (void) /* Detach from the remote board. */ static void -mips_detach (struct target_ops *ops, char *args, int from_tty) +mips_detach (struct target_ops *ops, const char *args, int from_tty) { if (args) error (_("Argument given to \"detach\" when remotely debugging.")); diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index 3753c008571..e095035484a 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -817,7 +817,7 @@ gdbsim_close (void) Use this when you want to detach and do something else with your gdb. */ static void -gdbsim_detach (struct target_ops *ops, char *args, int from_tty) +gdbsim_detach (struct target_ops *ops, const char *args, int from_tty) { if (remote_debug) fprintf_unfiltered (gdb_stdlog, "gdbsim_detach: args \"%s\"\n", args); diff --git a/gdb/remote.c b/gdb/remote.c index 7bd9b2a3b4c..f4667e368cd 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -133,8 +133,6 @@ static int remote_is_async_p (void); static void remote_async (void (*callback) (enum inferior_event_type event_type, void *context), void *context); -static void remote_detach (struct target_ops *ops, char *args, int from_tty); - static void sync_remote_interrupt_twice (int signo); static void interrupt_query (void); @@ -4425,7 +4423,7 @@ remote_open_1 (char *name, int from_tty, die when it hits one. */ static void -remote_detach_1 (char *args, int from_tty, int extended) +remote_detach_1 (const char *args, int from_tty, int extended) { int pid = ptid_get_pid (inferior_ptid); struct remote_state *rs = get_remote_state (); @@ -4469,13 +4467,13 @@ remote_detach_1 (char *args, int from_tty, int extended) } static void -remote_detach (struct target_ops *ops, char *args, int from_tty) +remote_detach (struct target_ops *ops, const char *args, int from_tty) { remote_detach_1 (args, from_tty, 0); } static void -extended_remote_detach (struct target_ops *ops, char *args, int from_tty) +extended_remote_detach (struct target_ops *ops, const char *args, int from_tty) { remote_detach_1 (args, from_tty, 1); } diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c index 4a0de1fecc3..b20134c9d00 100644 --- a/gdb/sol-thread.c +++ b/gdb/sol-thread.c @@ -320,7 +320,7 @@ lwp_to_thread (ptid_t lwp) program was started via the normal ptrace (PTRACE_TRACEME). */ static void -sol_thread_detach (struct target_ops *ops, char *args, int from_tty) +sol_thread_detach (struct target_ops *ops, const char *args, int from_tty) { struct target_ops *beneath = find_target_beneath (ops); diff --git a/gdb/target.c b/gdb/target.c index 7aeab79e290..86a5572a55b 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2612,7 +2612,7 @@ target_preopen (int from_tty) /* Detach a target after doing deferred register stores. */ void -target_detach (char *args, int from_tty) +target_detach (const char *args, int from_tty) { struct target_ops* t; @@ -3748,7 +3748,7 @@ init_dummy_target (void) dummy_target.to_doc = ""; dummy_target.to_attach = find_default_attach; dummy_target.to_detach = - (void (*)(struct target_ops *, char *, int))target_ignore; + (void (*)(struct target_ops *, const char *, int))target_ignore; dummy_target.to_create_inferior = find_default_create_inferior; dummy_target.to_can_async_p = find_default_can_async_p; dummy_target.to_is_async_p = find_default_is_async_p; diff --git a/gdb/target.h b/gdb/target.h index 56ca40c8b1a..df17be5cb6d 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -359,7 +359,7 @@ struct target_ops void (*to_close) (void); void (*to_attach) (struct target_ops *ops, char *, int); void (*to_post_attach) (int); - void (*to_detach) (struct target_ops *ops, char *, int); + void (*to_detach) (struct target_ops *ops, const char *, int); void (*to_disconnect) (struct target_ops *, char *, int); void (*to_resume) (struct target_ops *, ptid_t, int, enum gdb_signal); ptid_t (*to_wait) (struct target_ops *, @@ -949,7 +949,7 @@ void target_attach (char *, int); typed by the user (e.g. a signal to send the process). FROM_TTY says whether to be verbose or not. */ -extern void target_detach (char *, int); +extern void target_detach (const char *, int); /* Disconnect from the current target without resuming it (leaving it waiting for a debugger). */ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 24b97abca8a..193a6d756b7 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1866,7 +1866,7 @@ windows_attach (struct target_ops *ops, char *args, int from_tty) } static void -windows_detach (struct target_ops *ops, char *args, int from_tty) +windows_detach (struct target_ops *ops, const char *args, int from_tty) { int detached = 1; -- 2.30.2