Fix some K&R isms.
[deliverable/binutils-gdb.git] / gdb / windows-nat.c
index 610af6f74d2a3f6a720008ed4e16758d507d1106..e0377c5afe4098a4d5aaeb4a97e3d1fc43c04f2d 100644 (file)
@@ -123,7 +123,8 @@ static DEBUG_EVENT current_event;   /* The current debug event from
                                           WaitForDebugEvent */
 static HANDLE current_process_handle;  /* Currently executing process */
 static thread_info *current_thread;    /* Info on currently selected thread */
-static DWORD main_thread_id;   /* Thread ID of the main thread */
+static DWORD main_thread_id;           /* Thread ID of the main thread */
+static pid_t cygwin_pid;               /* pid of cygwin process */
 
 /* Counts of things. */
 static int exception_count = 0;
@@ -139,9 +140,6 @@ static int debug_memory = 0;                /* show target memory accesses */
 static int debug_exceptions = 0;       /* show target exceptions */
 static int useshell = 0;               /* use shell for subprocesses */
 
-/* Path to shell */
-static char shell[MAX_PATH + 1];
-
 /* This vector maps GDB's idea of a register's number into an address
    in the win32 exception context vector.
 
@@ -582,16 +580,21 @@ register_loaded_dll (const char *name, DWORD load_addr)
   HANDLE h = FindFirstFile(name, &w32_fd);
   size_t len;
 
-  FindClose (h);
-  strcpy (buf, name);
-  if (GetCurrentDirectory (MAX_PATH + 1, cwd))
+  if (h == INVALID_HANDLE_VALUE)
+    strcpy (buf, name);
+  else
     {
-      p = strrchr (buf, '\\');
-      if (p)
-       p[1] = '\0';
-      SetCurrentDirectory (buf);
-      GetFullPathName (w32_fd.cFileName, MAX_PATH, buf, &p);
-      SetCurrentDirectory (cwd);
+      FindClose (h);
+      strcpy (buf, name);
+      if (GetCurrentDirectory (MAX_PATH + 1, cwd))
+       {
+         p = strrchr (buf, '\\');
+         if (p)
+           p[1] = '\0';
+         SetCurrentDirectory (buf);
+         GetFullPathName (w32_fd.cFileName, MAX_PATH, buf, &p);
+         SetCurrentDirectory (cwd);
+       }
     }
 
   cygwin_conv_to_posix_path (buf, ppath);
@@ -1331,7 +1334,7 @@ static BOOL WINAPI (*DebugSetProcessKillOnExit)(BOOL);
 static BOOL WINAPI (*DebugActiveProcessStop)(DWORD);
 
 static int
-has_detach_ability ()
+has_detach_ability (void)
 {
   static HMODULE kernel32 = NULL;
 
@@ -1456,6 +1459,8 @@ child_create_inferior (char *exec_file, char *allargs, char **env)
   char *args;
   char real_path[MAXPATHLEN];
   char *toexec;
+  char shell[MAX_PATH + 1]; /* Path to shell */
+  const char *sh;
 
   if (!exec_file)
     error ("No executable specified, use `target exec'.\n");
@@ -1463,15 +1468,7 @@ child_create_inferior (char *exec_file, char *allargs, char **env)
   memset (&si, 0, sizeof (si));
   si.cb = sizeof (si);
 
-  flags = 0;
-
-  if (new_group)
-    flags |= CREATE_NEW_PROCESS_GROUP;
-
-  if (new_console)
-    flags |= CREATE_NEW_CONSOLE;
-
-  if (!useshell || !shell[0])
+  if (!useshell)
     {
       flags = DEBUG_ONLY_THIS_PROCESS;
       cygwin_conv_to_win32_path (exec_file, real_path);
@@ -1479,13 +1476,25 @@ child_create_inferior (char *exec_file, char *allargs, char **env)
     }
   else
     {
-      char *newallargs = alloca (sizeof (" -c 'exec  '") + strlen (exec_file) + strlen (allargs) + 2);
+      char *newallargs;
+      sh = getenv ("SHELL");
+      if (!sh)
+       sh = "/bin/sh";
+      cygwin_conv_to_win32_path (sh, shell);
+      newallargs = alloca (sizeof (" -c 'exec  '") + strlen (exec_file)
+                          + strlen (allargs) + 2);
       sprintf (newallargs, " -c 'exec %s %s'", exec_file, allargs);
       allargs = newallargs;
       toexec = shell;
       flags = DEBUG_PROCESS;
     }
 
+  if (new_group)
+    flags |= CREATE_NEW_PROCESS_GROUP;
+
+  if (new_console)
+    flags |= CREATE_NEW_CONSOLE;
+
   args = alloca (strlen (toexec) + strlen (allargs) + 2);
   strcpy (args, toexec);
   strcat (args, " ");
@@ -1493,7 +1502,7 @@ child_create_inferior (char *exec_file, char *allargs, char **env)
 
   /* Prepare the environment vars for CreateProcess.  */
   {
-    /* This code use to assume all env vars were file names and would
+    /* This code used to assume all env vars were file names and would
        translate them all to win32 style.  That obviously doesn't work in the
        general case.  The current rule is that we only translate PATH.
        We need to handle PATH because we're about to call CreateProcess and
@@ -1806,30 +1815,15 @@ init_child_ops (void)
 }
 
 void
-_initialize_inftarg (void)
+_initialize_win32_nat (void)
 {
   struct cmd_list_element *c;
-  const char *sh;
 
   init_child_ops ();
 
   c = add_com ("dll-symbols", class_files, dll_symbol_command,
               "Load dll library symbols from FILE.");
-  c->completer = filename_completer;
-
-  sh = getenv ("SHELL");
-  if (!sh)
-    sh = "/bin/sh";
-  if (access (sh, X_OK) != 0)
-    {
-      shell[0] = '\0';
-      useshell = 0;
-    }
-  else
-    {
-      cygwin_conv_to_win32_path (sh, shell);
-      useshell = 1;
-    }
+  set_cmd_completer (c, filename_completer);
 
   add_com_alias ("sharedlibrary", "dll-symbols", class_alias, 1);
 
This page took 0.03892 seconds and 4 git commands to generate.