Fix for PR gdb/209, PR gdb/156:
[deliverable/binutils-gdb.git] / gdb / fork-child.c
index 21e508939b6fb65076b514e3e80e030f43c0a97d..24cd00a5b1dbbcc0b589f0cd9a75bc769a2fd36e 100644 (file)
@@ -568,3 +568,74 @@ startup_inferior (int ntraps)
 #endif /* STARTUP_INFERIOR */
   stop_soon_quietly = 0;
 }
+
+/* Compute command-line string given argument vector.  This does the
+   same shell processing as fork_inferior.  */
+/* ARGSUSED */
+char *
+construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
+{
+  char *result;
+
+  if (STARTUP_WITH_SHELL)
+    {
+      /* This holds all the characters considered special to the
+        typical Unix shells.  We include `^' because the SunOS
+        /bin/sh treats it as a synonym for `|'.  */
+      char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
+      int i;
+      int length = 0;
+      char *out, *cp;
+
+      /* We over-compute the size.  It shouldn't matter.  */
+      for (i = 0; i < argc; ++i)
+       length += 2 * strlen (argv[i]) + 1;
+
+      result = (char *) xmalloc (length);
+      out = result;
+
+      for (i = 0; i < argc; ++i)
+       {
+         if (i > 0)
+           *out++ = ' ';
+
+         for (cp = argv[i]; *cp; ++cp)
+           {
+             if (strchr (special, *cp) != NULL)
+               *out++ = '\\';
+             *out++ = *cp;
+           }
+       }
+      *out = '\0';
+    }
+  else
+    {
+      /* In this case we can't handle arguments that contain spaces,
+        tabs, or newlines -- see breakup_args().  */
+      int i;
+      int length = 0;
+
+      for (i = 0; i < argc; ++i)
+       {
+         char *cp = strchr (argv[i], ' ');
+         if (cp == NULL)
+           cp = strchr (argv[i], '\t');
+         if (cp == NULL)
+           cp = strchr (argv[i], '\n');
+         if (cp != NULL)
+           error ("can't handle command-line argument containing whitespace");
+         length += strlen (argv[i]) + 1;
+       }
+
+      result = (char *) xmalloc (length);
+      result[0] = '\0';
+      for (i = 0; i < argc; ++i)
+       {
+         if (i > 0)
+           strcat (result, " ");
+         strcat (result, argv[i]);
+       }
+    }
+
+  return result;
+}
This page took 0.02639 seconds and 4 git commands to generate.