Allow making GDB not automatically connect to the native target.
[deliverable/binutils-gdb.git] / gdb / target.c
index 71292d333a34bd21dc2d932523c673236f69129c..07e3c2b1af03535a124e0b7f00b532472b6e2b70 100644 (file)
@@ -2436,6 +2436,20 @@ target_require_runnable (void)
   internal_error (__FILE__, __LINE__, _("No targets found"));
 }
 
+/* Whether GDB is allowed to fall back to the default run target for
+   "run", "attach", etc. when no target is connected yet.  */
+static int auto_connect_native_target = 1;
+
+static void
+show_auto_connect_native_target (struct ui_file *file, int from_tty,
+                                struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file,
+                   _("Whether GDB may automatically connect to the "
+                     "native target is %s.\n"),
+                   value);
+}
+
 /* Look through the list of possible targets for a target that can
    execute a run or attach command without any other data.  This is
    used to locate the default process stratum.
@@ -2446,23 +2460,28 @@ target_require_runnable (void)
 static struct target_ops *
 find_default_run_target (char *do_mesg)
 {
-  struct target_ops **t;
   struct target_ops *runable = NULL;
-  int count;
 
-  count = 0;
-
-  for (t = target_structs; t < target_structs + target_struct_size;
-       ++t)
+  if (auto_connect_native_target)
     {
-      if ((*t)->to_can_run != delegate_can_run && target_can_run (*t))
+      struct target_ops **t;
+      int count = 0;
+
+      for (t = target_structs; t < target_structs + target_struct_size;
+          ++t)
        {
-         runable = *t;
-         ++count;
+         if ((*t)->to_can_run != delegate_can_run && target_can_run (*t))
+           {
+             runable = *t;
+             ++count;
+           }
        }
+
+      if (count != 1)
+       runable = NULL;
     }
 
-  if (count != 1)
+  if (runable == NULL)
     {
       if (do_mesg)
        error (_("Don't know how to %s.  Try \"help target\"."), do_mesg);
@@ -4270,4 +4289,13 @@ When this permission is on, GDB may interrupt/stop the target's execution.\n\
 Otherwise, any attempt to interrupt or stop will be ignored."),
                           set_target_permissions, NULL,
                           &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("auto-connect-native-target", class_support,
+                          &auto_connect_native_target, _("\
+Set whether GDB may automatically connect to the native target."), _("\
+Show whether GDB may automatically connect to the native target."), _("\
+When on, and GDB is not connected to a target yet, GDB\n\
+attempts \"run\" and other commands with the native target."),
+                          NULL, show_auto_connect_native_target,
+                          &setlist, &showlist);
 }
This page took 0.025128 seconds and 4 git commands to generate.