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  <tromey@redhat.com>

	* 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) <to_detach>: Make argument const.
	(target_detach): Likewise.
	* windows-nat.c (windows_detach): Update.
This commit is contained in:
Tom Tromey 2013-03-19 09:23:17 -06:00
parent 79600f4f1b
commit 52554a0e32
26 changed files with 67 additions and 38 deletions

View file

@ -1,3 +1,35 @@
2013-11-08 Tom Tromey <tromey@redhat.com>
* 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) <to_detach>: Make argument const.
(target_detach): Likewise.
* windows-nat.c (windows_detach): Update.
2013-11-07 Doug Evans <dje@google.com> 2013-11-07 Doug Evans <dje@google.com>
PR 11786 PR 11786

View file

@ -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(). */ /* Detach from the process attached to by aix_thread_attach(). */
static void 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); struct target_ops *beneath = find_target_beneath (ops);

View file

@ -85,8 +85,6 @@ static int gdb_check_format (bfd *);
static void core_open (char *, int); 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 (void);
static void core_close_cleanup (void *ignore); static void core_close_cleanup (void *ignore);
@ -465,7 +463,7 @@ core_open (char *filename, int from_tty)
} }
static void 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) if (args)
error (_("Too many arguments")); error (_("Too many arguments"));

View file

@ -1681,7 +1681,7 @@ darwin_attach (struct target_ops *ops, char *args, int from_tty)
previously attached. It *might* work if the program was previously attached. It *might* work if the program was
started via fork. */ started via fork. */
static void 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); pid_t pid = ptid_get_pid (inferior_ptid);
struct inferior *inf = current_inferior (); struct inferior *inf = current_inferior ();

View file

@ -444,7 +444,7 @@ resync_thread_list (struct target_ops *ops)
/* The "to_detach" method of the dec_thread_ops. */ /* The "to_detach" method of the dec_thread_ops. */
static void 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); struct target_ops *beneath = find_target_beneath (ops);

View file

@ -2218,7 +2218,7 @@ gnu_attach (struct target_ops *ops, char *args, int from_tty)
previously attached. It *might* work if the program was previously attached. It *might* work if the program was
started via fork. */ started via fork. */
static void 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; int pid;

View file

@ -384,7 +384,7 @@ Use the `run' command to run DJGPP programs."));
} }
static void 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)
{ {
} }

View file

@ -264,7 +264,7 @@ inf_ptrace_post_attach (int pid)
specified by ARGS. If FROM_TTY is non-zero, be chatty about it. */ specified by ARGS. If FROM_TTY is non-zero, be chatty about it. */
static void 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); pid_t pid = ptid_get_pid (inferior_ptid);
int sig = 0; int sig = 0;

View file

@ -798,7 +798,7 @@ inf_ttrace_attach (struct target_ops *ops, char *args, int from_tty)
} }
static void 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); pid_t pid = ptid_get_pid (inferior_ptid);
int sig = 0; int sig = 0;

View file

@ -387,7 +387,7 @@ linux_fork_mourn_inferior (void)
the first available. */ the first available. */
void 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 /* 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 delete it from the fork_list, and switch to the next available

View file

@ -22,6 +22,6 @@ extern struct fork_info *add_fork (pid_t);
extern struct fork_info *find_fork_pid (pid_t); extern struct fork_info *find_fork_pid (pid_t);
extern void linux_fork_killall (void); extern void linux_fork_killall (void);
extern void linux_fork_mourn_inferior (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 forks_exist_p (void);
extern int linux_fork_checkpointing_p (int); extern int linux_fork_checkpointing_p (int);

View file

@ -1557,7 +1557,7 @@ detach_callback (struct lwp_info *lp, void *data)
} }
static void 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 pid;
int status; 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 && get_pending_status (main_lwp, &status) != -1
&& WIFSTOPPED (status)) && WIFSTOPPED (status))
{ {
char *tem;
/* Put the signal number in ARGS so that inf_ptrace_detach will /* Put the signal number in ARGS so that inf_ptrace_detach will
pass it along with PTRACE_DETACH. */ pass it along with PTRACE_DETACH. */
args = alloca (8); tem = alloca (8);
sprintf (args, "%d", (int) WSTOPSIG (status)); sprintf (tem, "%d", (int) WSTOPSIG (status));
args = tem;
if (debug_linux_nat) if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, fprintf_unfiltered (gdb_stdlog,
"LND: Sending signal %s to %s\n", "LND: Sending signal %s to %s\n",

View file

@ -1340,7 +1340,7 @@ detach_thread (ptid_t ptid)
} }
static void 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 target_ops *target_beneath = find_target_beneath (ops);
struct thread_db_info *info; struct thread_db_info *info;

View file

@ -875,7 +875,7 @@ monitor_close (void)
when you want to detach and do something else with your gdb. */ when you want to detach and do something else with your gdb. */
static void 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. */ unpush_target (ops); /* calls monitor_close to do the real work. */
if (from_tty) if (from_tty)

View file

@ -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 on signals, etc. We'd better not have left any breakpoints
in the program or it'll die when it hits one. */ in the program or it'll die when it hits one. */
static void 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 siggnal = 0;
int pid; int pid;

View file

@ -110,7 +110,7 @@
/* This module defines the GDB target vector and its methods. */ /* This module defines the GDB target vector and its methods. */
static void procfs_attach (struct target_ops *, char *, int); 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 *, static void procfs_resume (struct target_ops *,
ptid_t, int, enum gdb_signal); ptid_t, int, enum gdb_signal);
static void procfs_stop (ptid_t); static void procfs_stop (ptid_t);
@ -3071,7 +3071,7 @@ procfs_attach (struct target_ops *ops, char *args, int from_tty)
} }
static void 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 sig = 0;
int pid = ptid_get_pid (inferior_ptid); int pid = ptid_get_pid (inferior_ptid);

View file

@ -141,7 +141,7 @@ record_disconnect (struct target_ops *t, char *args, int from_tty)
/* See record.h. */ /* See record.h. */
void 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); gdb_assert (t->to_stratum == record_stratum);

View file

@ -55,7 +55,7 @@ extern void cmd_record_goto (char *arg, int from_tty);
extern void record_disconnect (struct target_ops *, char *, int); extern void record_disconnect (struct target_ops *, char *, int);
/* The default "to_detach" target method for record targets. */ /* 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. */ /* The default "to_mourn_inferior" target method for record targets. */
extern void record_mourn_inferior (struct target_ops *); extern void record_mourn_inferior (struct target_ops *);

View file

@ -878,7 +878,7 @@ m32r_wait (struct target_ops *ops,
Use this when you want to detach and do something else Use this when you want to detach and do something else
with your gdb. */ with your gdb. */
static void 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) if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "m32r_detach(%d)\n", from_tty); fprintf_unfiltered (gdb_stdlog, "m32r_detach(%d)\n", from_tty);

View file

@ -86,8 +86,6 @@ static void lsi_open (char *name, int from_tty);
static void mips_close (void); 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 int mips_map_regno (struct gdbarch *, int);
static void mips_set_register (int regno, ULONGEST value); static void mips_set_register (int regno, ULONGEST value);
@ -1749,7 +1747,7 @@ mips_close (void)
/* Detach from the remote board. */ /* Detach from the remote board. */
static void 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) if (args)
error (_("Argument given to \"detach\" when remotely debugging.")); error (_("Argument given to \"detach\" when remotely debugging."));

View file

@ -817,7 +817,7 @@ gdbsim_close (void)
Use this when you want to detach and do something else with your gdb. */ Use this when you want to detach and do something else with your gdb. */
static void 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) if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "gdbsim_detach: args \"%s\"\n", args); fprintf_unfiltered (gdb_stdlog, "gdbsim_detach: args \"%s\"\n", args);

View file

@ -133,8 +133,6 @@ static int remote_is_async_p (void);
static void remote_async (void (*callback) (enum inferior_event_type event_type, static void remote_async (void (*callback) (enum inferior_event_type event_type,
void *context), void *context); 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 sync_remote_interrupt_twice (int signo);
static void interrupt_query (void); static void interrupt_query (void);
@ -4425,7 +4423,7 @@ remote_open_1 (char *name, int from_tty,
die when it hits one. */ die when it hits one. */
static void 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); int pid = ptid_get_pid (inferior_ptid);
struct remote_state *rs = get_remote_state (); struct remote_state *rs = get_remote_state ();
@ -4469,13 +4467,13 @@ remote_detach_1 (char *args, int from_tty, int extended)
} }
static void 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); remote_detach_1 (args, from_tty, 0);
} }
static void 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); remote_detach_1 (args, from_tty, 1);
} }

View file

@ -320,7 +320,7 @@ lwp_to_thread (ptid_t lwp)
program was started via the normal ptrace (PTRACE_TRACEME). */ program was started via the normal ptrace (PTRACE_TRACEME). */
static void 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); struct target_ops *beneath = find_target_beneath (ops);

View file

@ -2612,7 +2612,7 @@ target_preopen (int from_tty)
/* Detach a target after doing deferred register stores. */ /* Detach a target after doing deferred register stores. */
void void
target_detach (char *args, int from_tty) target_detach (const char *args, int from_tty)
{ {
struct target_ops* t; struct target_ops* t;
@ -3748,7 +3748,7 @@ init_dummy_target (void)
dummy_target.to_doc = ""; dummy_target.to_doc = "";
dummy_target.to_attach = find_default_attach; dummy_target.to_attach = find_default_attach;
dummy_target.to_detach = 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_create_inferior = find_default_create_inferior;
dummy_target.to_can_async_p = find_default_can_async_p; dummy_target.to_can_async_p = find_default_can_async_p;
dummy_target.to_is_async_p = find_default_is_async_p; dummy_target.to_is_async_p = find_default_is_async_p;

View file

@ -359,7 +359,7 @@ struct target_ops
void (*to_close) (void); void (*to_close) (void);
void (*to_attach) (struct target_ops *ops, char *, int); void (*to_attach) (struct target_ops *ops, char *, int);
void (*to_post_attach) (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_disconnect) (struct target_ops *, char *, int);
void (*to_resume) (struct target_ops *, ptid_t, int, enum gdb_signal); void (*to_resume) (struct target_ops *, ptid_t, int, enum gdb_signal);
ptid_t (*to_wait) (struct target_ops *, 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 typed by the user (e.g. a signal to send the process). FROM_TTY
says whether to be verbose or not. */ 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 /* Disconnect from the current target without resuming it (leaving it
waiting for a debugger). */ waiting for a debugger). */

View file

@ -1866,7 +1866,7 @@ windows_attach (struct target_ops *ops, char *args, int from_tty)
} }
static void 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; int detached = 1;