Fix test-cp-name-parser build, unused variable
[deliverable/binutils-gdb.git] / gdb / windows-nat.c
index 0047a264189b097feb3ba2897cc335f0a1e4670c..99bcedcc2cf9f16188cc767c79b66787ef97cd9a 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-vector operations for controlling windows child processes, for GDB.
 
-   Copyright (C) 1995-2018 Free Software Foundation, Inc.
+   Copyright (C) 1995-2019 Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions, A Red Hat Company.
 
@@ -67,7 +67,8 @@
 #include "x86-nat.h"
 #include "complaints.h"
 #include "inf-child.h"
-#include "gdb_tilde_expand.h"
+#include "common/gdb_tilde_expand.h"
+#include "common/pathstuff.h"
 
 #define AdjustTokenPrivileges          dyn_AdjustTokenPrivileges
 #define DebugActiveProcessStop         dyn_DebugActiveProcessStop
@@ -425,9 +426,16 @@ thread_rec (DWORD id, int get_context)
   return NULL;
 }
 
-/* Add a thread to the thread list.  */
+/* Add a thread to the thread list.
+
+   PTID is the ptid of the thread to be added.
+   H is its Windows handle.
+   TLB is its thread local base.
+   MAIN_THREAD_P should be true if the thread to be added is
+   the main thread, false otherwise.  */
+
 static windows_thread_info *
-windows_add_thread (ptid_t ptid, HANDLE h, void *tlb)
+windows_add_thread (ptid_t ptid, HANDLE h, void *tlb, bool main_thread_p)
 {
   windows_thread_info *th;
   DWORD id;
@@ -445,7 +453,17 @@ windows_add_thread (ptid_t ptid, HANDLE h, void *tlb)
   th->thread_local_base = (CORE_ADDR) (uintptr_t) tlb;
   th->next = thread_head.next;
   thread_head.next = th;
-  add_thread (ptid);
+
+  /* Add this new thread to the list of threads.
+
+     To be consistent with what's done on other platforms, we add
+     the main thread silently (in reality, this thread is really
+     more of a process to the user than a thread).  */
+  if (main_thread_p)
+    add_thread_silent (ptid);
+  else
+    add_thread (ptid);
+
   /* Set the debug registers for the new thread if they are used.  */
   if (debug_registers_used)
     {
@@ -482,9 +500,15 @@ windows_init_thread_list (void)
   thread_head.next = NULL;
 }
 
-/* Delete a thread from the list of threads.  */
+/* Delete a thread from the list of threads.
+
+   PTID is the ptid of the thread to be deleted.
+   EXIT_CODE is the thread's exit code.
+   MAIN_THREAD_P should be true if the thread to be deleted is
+   the main thread, false otherwise.  */
+
 static void
-windows_delete_thread (ptid_t ptid, DWORD exit_code)
+windows_delete_thread (ptid_t ptid, DWORD exit_code, bool main_thread_p)
 {
   windows_thread_info *th;
   DWORD id;
@@ -493,11 +517,19 @@ windows_delete_thread (ptid_t ptid, DWORD exit_code)
 
   id = ptid.tid ();
 
+  /* Emit a notification about the thread being deleted.
+
+     Note that no notification was printed when the main thread
+     was created, and thus, unless in verbose mode, we should be
+     symetrical, and avoid that notification for the main thread
+     here as well.  */
+
   if (info_verbose)
     printf_unfiltered ("[Deleting %s]\n", target_pid_to_str (ptid));
-  else if (print_thread_events && id != main_thread_id)
+  else if (print_thread_events && !main_thread_p)
     printf_unfiltered (_("[%s exited with code %u]\n"),
                       target_pid_to_str (ptid), (unsigned) exit_code);
+
   delete_thread (find_thread_ptid (ptid));
 
   for (th = &thread_head;
@@ -1374,11 +1406,12 @@ fake_create_process (void)
       /*  We can not debug anything in that case.  */
     }
   main_thread_id = current_event.dwThreadId;
-  current_thread = windows_add_thread (
-                    ptid_t (current_event.dwProcessId, 0,
-                            current_event.dwThreadId),
-                    current_event.u.CreateThread.hThread,
-                    current_event.u.CreateThread.lpThreadLocalBase);
+  current_thread
+    = windows_add_thread (ptid_t (current_event.dwProcessId, 0,
+                                 current_event.dwThreadId),
+                         current_event.u.CreateThread.hThread,
+                         current_event.u.CreateThread.lpThreadLocalBase,
+                         true /* main_thread_p */);
   return main_thread_id;
 }
 
@@ -1547,10 +1580,11 @@ get_windows_debug_event (struct target_ops *ops,
        }
       /* Record the existence of this thread.  */
       thread_id = current_event.dwThreadId;
-      th = windows_add_thread (ptid_t (current_event.dwProcessId, 0,
-                                      current_event.dwThreadId),
-                            current_event.u.CreateThread.hThread,
-                            current_event.u.CreateThread.lpThreadLocalBase);
+      th = windows_add_thread
+        (ptid_t (current_event.dwProcessId, 0, current_event.dwThreadId),
+        current_event.u.CreateThread.hThread,
+        current_event.u.CreateThread.lpThreadLocalBase,
+        false /* main_thread_p */);
 
       break;
 
@@ -1559,14 +1593,11 @@ get_windows_debug_event (struct target_ops *ops,
                     (unsigned) current_event.dwProcessId,
                     (unsigned) current_event.dwThreadId,
                     "EXIT_THREAD_DEBUG_EVENT"));
-
-      if (current_event.dwThreadId != main_thread_id)
-       {
-         windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
-                                        current_event.dwThreadId),
-                                current_event.u.ExitThread.dwExitCode);
-         th = &dummy_thread_info;
-       }
+      windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
+                                    current_event.dwThreadId),
+                            current_event.u.ExitThread.dwExitCode,
+                            false /* main_thread_p */);
+      th = &dummy_thread_info;
       break;
 
     case CREATE_PROCESS_DEBUG_EVENT:
@@ -1579,16 +1610,14 @@ get_windows_debug_event (struct target_ops *ops,
        break;
 
       current_process_handle = current_event.u.CreateProcessInfo.hProcess;
-      if (main_thread_id)
-       windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
-                                      main_thread_id),
-                              0);
       main_thread_id = current_event.dwThreadId;
       /* Add the main thread.  */
-      th = windows_add_thread (ptid_t (current_event.dwProcessId, 0,
-                                      current_event.dwThreadId),
-            current_event.u.CreateProcessInfo.hThread,
-            current_event.u.CreateProcessInfo.lpThreadLocalBase);
+      th = windows_add_thread
+        (ptid_t (current_event.dwProcessId, 0,
+                current_event.dwThreadId),
+        current_event.u.CreateProcessInfo.hThread,
+        current_event.u.CreateProcessInfo.lpThreadLocalBase,
+        true /* main_thread_p */);
       thread_id = current_event.dwThreadId;
       break;
 
@@ -1606,6 +1635,9 @@ get_windows_debug_event (struct target_ops *ops,
        }
       else if (saw_create == 1)
        {
+         windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
+                                        main_thread_id),
+                                0, true /* main_thread_p */);
          ourstatus->kind = TARGET_WAITKIND_EXITED;
          ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
          thread_id = main_thread_id;
@@ -1983,8 +2015,6 @@ windows_nat_target::attach (const char *args, int from_tty)
       else
        printf_unfiltered ("Attaching to %s\n",
                           target_pid_to_str (ptid_t (pid)));
-
-      gdb_flush (gdb_stdout);
     }
 
   do_initial_windows_stuff (this, pid, 1);
@@ -2014,7 +2044,6 @@ windows_nat_target::detach (inferior *inf, int from_tty)
        exec_file = "";
       printf_unfiltered ("Detaching from program: %s, Pid %u\n", exec_file,
                         (unsigned) current_event.dwProcessId);
-      gdb_flush (gdb_stdout);
     }
 
   x86_cleanup_dregs ();
@@ -2578,9 +2607,7 @@ windows_nat_target::create_inferior (const char *exec_file,
     }
   else
     {
-      sh = getenv ("SHELL");
-      if (!sh)
-       sh = "/bin/sh";
+      sh = get_shell ();
       if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, sh, shell, __PMAX) < 0)
        error (_("Error starting executable via shell: %d"), errno);
 #ifdef __USEWIDE
This page took 0.033199 seconds and 4 git commands to generate.