ODR warnings for "struct coff_symbol"
[binutils-gdb.git] / gdb / windows-nat.c
index 646ddda7328fd0e7367006520bf5084687a7605d..8631a1b45698e34aea3b1783512dc97116e579c9 100644 (file)
@@ -79,11 +79,9 @@ static windows_process_info windows_process;
 
 #undef STARTUPINFO
 #undef CreateProcess
-#undef GetModuleFileNameEx
 
 #ifndef __CYGWIN__
 # define __PMAX        (MAX_PATH + 1)
-# define GetModuleFileNameEx GetModuleFileNameExA
 # define STARTUPINFO STARTUPINFOA
 # define CreateProcess CreateProcessA
 #else
@@ -93,7 +91,6 @@ static windows_process_info windows_process;
   static CORE_ADDR cygwin_load_end;
 #   define __USEWIDE
     typedef wchar_t cygwin_buf_t;
-#   define GetModuleFileNameEx GetModuleFileNameExW
 #   define STARTUPINFO STARTUPINFOW
 #   define CreateProcess CreateProcessW
 #endif
@@ -276,7 +273,7 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target>
 
   void interrupt () override;
 
-  char *pid_to_exec_file (int pid) override;
+  const char *pid_to_exec_file (int pid) override;
 
   ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
 
@@ -657,8 +654,8 @@ static std::vector<windows_solib> solibs;
 static windows_solib *
 windows_make_so (const char *name, LPVOID load_addr)
 {
-  char *p;
 #ifndef __CYGWIN__
+  char *p;
   char buf[__PMAX];
   char cwd[__PMAX];
   WIN32_FIND_DATA w32_fd;
@@ -714,10 +711,10 @@ windows_make_so (const char *name, LPVOID load_addr)
 #else
   if (buf[0])
     {
-      char name[SO_NAME_MAX_PATH_SIZE];
-      cygwin_conv_path (CCP_WIN_W_TO_POSIX, buf, name,
+      char cname[SO_NAME_MAX_PATH_SIZE];
+      cygwin_conv_path (CCP_WIN_W_TO_POSIX, buf, cname,
                        SO_NAME_MAX_PATH_SIZE);
-      so->name = name;
+      so->name = cname;
     }
   else
     {
@@ -741,7 +738,7 @@ windows_make_so (const char *name, LPVOID load_addr)
     {
       asection *text = NULL;
 
-      gdb_bfd_ref_ptr abfd (gdb_bfd_open (so->name, "pei-i386"));
+      gdb_bfd_ref_ptr abfd (gdb_bfd_open (so->name.c_str(), "pei-i386"));
 
       if (abfd == NULL)
        return so;
@@ -887,7 +884,7 @@ windows_nat::windows_process_info::handle_output_debug_string
          if (!retval)
            retval = current_event.dwThreadId;
          else if ((x = (LPCVOID) (uintptr_t) strtoull (p, NULL, 0))
-                  && ReadProcessMemory (current_process_handle, x,
+                  && ReadProcessMemory (handle, x,
                                         &saved_context,
                                         __COPY_CONTEXT_SIZE, &n)
                   && n == __COPY_CONTEXT_SIZE)
@@ -1054,46 +1051,6 @@ display_selectors (const char * args, int from_tty)
 
 /* See nat/windows-nat.h.  */
 
-bool
-windows_nat::windows_process_info::handle_ms_vc_exception
-     (const EXCEPTION_RECORD *rec)
-{
-  if (rec->NumberParameters >= 3
-      && (rec->ExceptionInformation[0] & 0xffffffff) == 0x1000)
-    {
-      DWORD named_thread_id;
-      windows_thread_info *named_thread;
-      CORE_ADDR thread_name_target;
-
-      thread_name_target = rec->ExceptionInformation[1];
-      named_thread_id = (DWORD) (0xffffffff & rec->ExceptionInformation[2]);
-
-      if (named_thread_id == (DWORD) -1)
-       named_thread_id = current_event.dwThreadId;
-
-      named_thread = thread_rec (ptid_t (current_event.dwProcessId,
-                                        named_thread_id, 0),
-                                DONT_INVALIDATE_CONTEXT);
-      if (named_thread != NULL)
-       {
-         int thread_name_len;
-         gdb::unique_xmalloc_ptr<char> thread_name
-           = target_read_string (thread_name_target, 1025, &thread_name_len);
-         if (thread_name_len > 0)
-           {
-             thread_name.get ()[thread_name_len - 1] = '\0';
-             named_thread->name = std::move (thread_name);
-           }
-       }
-
-      return true;
-    }
-
-  return false;
-}
-
-/* See nat/windows-nat.h.  */
-
 bool
 windows_nat::windows_process_info::handle_access_violation
      (const EXCEPTION_RECORD *rec)
@@ -1977,98 +1934,12 @@ windows_nat_target::detach (inferior *inf, int from_tty)
   maybe_unpush_target ();
 }
 
-/* Try to determine the executable filename.
-
-   EXE_NAME_RET is a pointer to a buffer whose size is EXE_NAME_MAX_LEN.
-
-   Upon success, the filename is stored inside EXE_NAME_RET, and
-   this function returns nonzero.
-
-   Otherwise, this function returns zero and the contents of
-   EXE_NAME_RET is undefined.  */
-
-static int
-windows_get_exec_module_filename (char *exe_name_ret, size_t exe_name_max_len)
-{
-  DWORD len;
-  HMODULE dh_buf;
-  DWORD cbNeeded;
-
-  cbNeeded = 0;
-#ifdef __x86_64__
-  if (windows_process.wow64_process)
-    {
-      if (!EnumProcessModulesEx (windows_process.handle,
-                                &dh_buf, sizeof (HMODULE), &cbNeeded,
-                                LIST_MODULES_32BIT)
-         || !cbNeeded)
-       return 0;
-    }
-  else
-#endif
-    {
-      if (!EnumProcessModules (windows_process.handle,
-                              &dh_buf, sizeof (HMODULE), &cbNeeded)
-         || !cbNeeded)
-       return 0;
-    }
-
-  /* We know the executable is always first in the list of modules,
-     which we just fetched.  So no need to fetch more.  */
-
-#ifdef __CYGWIN__
-  {
-    /* Cygwin prefers that the path be in /x/y/z format, so extract
-       the filename into a temporary buffer first, and then convert it
-       to POSIX format into the destination buffer.  */
-    cygwin_buf_t *pathbuf = (cygwin_buf_t *) alloca (exe_name_max_len * sizeof (cygwin_buf_t));
-
-    len = GetModuleFileNameEx (current_process_handle,
-                              dh_buf, pathbuf, exe_name_max_len);
-    if (len == 0)
-      error (_("Error getting executable filename: %u."),
-            (unsigned) GetLastError ());
-    if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, pathbuf, exe_name_ret,
-                         exe_name_max_len) < 0)
-      error (_("Error converting executable filename to POSIX: %d."), errno);
-  }
-#else
-  len = GetModuleFileNameEx (windows_process.handle,
-                            dh_buf, exe_name_ret, exe_name_max_len);
-  if (len == 0)
-    error (_("Error getting executable filename: %u."),
-          (unsigned) GetLastError ());
-#endif
-
-    return 1;  /* success */
-}
-
 /* The pid_to_exec_file target_ops method for this platform.  */
 
-char *
+const char *
 windows_nat_target::pid_to_exec_file (int pid)
 {
-  static char path[__PMAX];
-#ifdef __CYGWIN__
-  /* Try to find exe name as symlink target of /proc/<pid>/exe.  */
-  int nchars;
-  char procexe[sizeof ("/proc/4294967295/exe")];
-
-  xsnprintf (procexe, sizeof (procexe), "/proc/%u/exe", pid);
-  nchars = readlink (procexe, path, sizeof(path));
-  if (nchars > 0 && nchars < sizeof (path))
-    {
-      path[nchars] = '\0';     /* Got it */
-      return path;
-    }
-#endif
-
-  /* If we get here then either Cygwin is hosed, this isn't a Cygwin version
-     of gdb, or we're trying to debug a non-Cygwin windows executable.  */
-  if (!windows_get_exec_module_filename (path, sizeof (path)))
-    path[0] = '\0';
-
-  return path;
+  return windows_process.pid_to_exec_file (pid);
 }
 
 /* Print status information about what we're accessing.  */
@@ -3037,8 +2908,10 @@ windows_nat_target::get_ada_task_ptid (long lwp, ULONGEST thread)
 const char *
 windows_nat_target::thread_name (struct thread_info *thr)
 {
-  return windows_process.thread_rec (thr->ptid,
-                                    DONT_INVALIDATE_CONTEXT)->name.get ();
+  windows_thread_info *th
+    = windows_process.thread_rec (thr->ptid,
+                                 DONT_INVALIDATE_CONTEXT);
+  return th->thread_name ();
 }