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.
+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>
PR 11786
/* 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);
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);
}
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"));
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 ();
/* 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);
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;
}
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)
{
}
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;
}
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;
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
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);
}
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;
&& 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",
}
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;
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)
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;
/* 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);
}
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);
/* 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);
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 *);
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);
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);
/* 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."));
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);
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);
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 ();
}
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);
}
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);
/* 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;
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;
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 *,
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). */
}
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;