]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
constify to_detach
authorTom Tromey <tromey@redhat.com>
Tue, 19 Mar 2013 15:23:17 +0000 (09:23 -0600)
committerTom Tromey <tromey@redhat.com>
Fri, 8 Nov 2013 16:38:41 +0000 (09:38 -0700)
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.

26 files changed:
gdb/ChangeLog
gdb/aix-thread.c
gdb/corelow.c
gdb/darwin-nat.c
gdb/dec-thread.c
gdb/gnu-nat.c
gdb/go32-nat.c
gdb/inf-ptrace.c
gdb/inf-ttrace.c
gdb/linux-fork.c
gdb/linux-fork.h
gdb/linux-nat.c
gdb/linux-thread-db.c
gdb/monitor.c
gdb/nto-procfs.c
gdb/procfs.c
gdb/record.c
gdb/record.h
gdb/remote-m32r-sdi.c
gdb/remote-mips.c
gdb/remote-sim.c
gdb/remote.c
gdb/sol-thread.c
gdb/target.c
gdb/target.h
gdb/windows-nat.c

index 1c23f962dcc2a24f51c611a99ab320df4cb06369..4d1c26d01676c79c3ce4ca6f717e72cf2fe061b2 100644 (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>
 
        PR 11786
index 31758351361f952be7e75e61fdb300fc586dea9d..373a09aabfdb0c5fe3fcbc717207ed40755930d3 100644 (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().  */
 
 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);
 
index d1e7f6ae7df6c285a3e3b6dd404483fade0a651d..78f8120220c7a3d84a9ffc26e2e8406eb5fe4878 100644 (file)
@@ -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"));
index 6995c2565f56d3dc7f8015c6b6358e7f50597b71..a9157dbf0690c24af594e9f08543303756a29366 100644 (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
    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 ();
index f07721d30dcfb437485a691aa8f939d38075f9be..03768283f6fc7cf114841d1341a5b319a6eed839 100644 (file)
@@ -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);
 
index 4a25759cfb8fc3be75026f6a1f54767c5c644289..659aa67282081882f97a7d2392103307f69722b3 100644 (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
    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;
 
index 4dac617a7e806d3cde19fc5e097978e26bb9607f..a92a34f46e04c0a5cf5687a07548430893524a1a 100644 (file)
@@ -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)
 {
 }
 
index bdebe65f8fd04f012982a4906347c24250026188..5e5e248352e38290f2ddb24ca16d90b13d38b446 100644 (file)
@@ -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;
index 36bf4cb722f6f4ee52cdd4dbc33a06d2e8d4721d..c715c7148f312b726f94fcaf05976f9064e90ffd 100644 (file)
@@ -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;
index bff807e3ab6d890f2723a6362b4e25c21d9bbefb..754500f0a667e87b9b43c5643907529fa8601934 100644 (file)
@@ -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
index 5d924dec5026777cf10d57ed4b636d34676ec32f..51b5112e5255b9ce488a3d3b86584d4215d600c7 100644 (file)
@@ -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);
index 4784a5e7db9ba152d5d7420eb2e807a8e983bec6..95064f74e735d50f6ee8b1247e23f14a5a153987 100644 (file)
@@ -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",
index 593fc29b54e5c0d4361982e7d2f8ec4e94c98056..4cc3a4cb64f346341ab1865d1215046a5bf4a26c 100644 (file)
@@ -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;
index 08153ddd68e63e545bfae90cc91e3563548b0436..0f5d8ca2d9743ae73920878601dae2c2e7118f36 100644 (file)
@@ -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)
index 1e6ec744b0698ce8f608841608151c2bf4c280a2..a9b427688cd35ef437d2582ecc84faf3b137e92b 100644 (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
    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;
index e0130968b796dcb59e31a3d684f0f416bf6e9db9..018a0d846b9e2fc4267542d9ffe24bd55de7ee77 100644 (file)
 /* 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);
index 4078def1c38548bbdb41b4113c6a214b84aa181e..ec2a0421075bb7c5dfb339cbc531eb9c5b1db22a 100644 (file)
@@ -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);
 
index 65d508fa05d0b40939e09c0c28f935c03dc325bb..124c32be964c24efc34b4d84403ca8796eda4e98 100644 (file)
@@ -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 *);
index 81fea53955d5e773926e3cc56580813b19304296..4ffb72df0fcd592cc27b843324aec90560ec3077 100644 (file)
@@ -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);
index bf6cce5357af7236b11f4002386670466aeb34fb..f8e6caca09babccf6bc4fcf042a3c9973d7a2bbf 100644 (file)
@@ -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."));
index 3753c00857129dda4190a97caeb4511b108b833e..e095035484a9f8fc40114799a4e769cf721cca47 100644 (file)
@@ -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);
index 7bd9b2a3b4cd98d95f534296fd397c02c0325c61..f4667e368cdbc70dfbd0cb559d0dd6d5b5afa61f 100644 (file)
@@ -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);
 }
index 4a0de1fecc3498161237609549bd8937bbfd7541..b20134c9d009b818524497f0b2a2b94a6ff15441 100644 (file)
@@ -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);
 
index 7aeab79e2902a29f1c40e1a5eb591a987938a002..86a5572a55b5bbaa8416e4cafd7b300c1f61d19a 100644 (file)
@@ -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;
index 56ca40c8b1ae4ffa78afc69a08ff6319fdeb7108..df17be5cb6d2beb0e79eabfa5762e4448b5ba75a 100644 (file)
@@ -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).  */
index 24b97abca8aceaa7f145604229d8d3832810f72c..193a6d756b78a82cc11d0094047d9c73470d0d73 100644 (file)
@@ -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;