public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-muller-windows-multi:  * Revert environment changes from windows-nat.c
@ 2011-03-28 14:12 muller
  0 siblings, 0 replies; only message in thread
From: muller @ 2011-03-28 14:12 UTC (permalink / raw)
  To: archer-commits

The branch, archer-muller-windows-multi has been updated
       via  578a0c0b06a83b0f408772a873dd3effc089bf6a (commit)
       via  bd400badf05fa4a9a212f09970cdbebbd02dfd13 (commit)
      from  58fd2bf8ec3090fe702dfe1e18d8cd2fa93a1738 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 578a0c0b06a83b0f408772a873dd3effc089bf6a
Author: Pierre Muller <muller@ics.u-strasbg.fr>
Date:   Mon Mar 28 16:09:06 2011 +0200

     * Revert environment changes from windows-nat.c

commit bd400badf05fa4a9a212f09970cdbebbd02dfd13
Author: Pierre Muller <muller@ics.u-strasbg.fr>
Date:   Mon Mar 28 00:32:14 2011 +0200

     * Partial 32-bit on 64-bit GDB support, non functional :(

-----------------------------------------------------------------------

Summary of changes:
 gdb/amd64-windows-nat.c |  298 ++++++++++++++++++++++++++++++++++++++++++++++-
 gdb/i386-windows-nat.c  |   11 ++
 gdb/windows-nat.c       |  247 +++++++++++++++------------------------
 gdb/windows-nat.h       |   10 ++-
 gdb/windows-tdep.c      |   18 ++-
 5 files changed, 422 insertions(+), 162 deletions(-)

First 500 lines of diff:
diff --git a/gdb/amd64-windows-nat.c b/gdb/amd64-windows-nat.c
index f6334ae..c695e00 100644
--- a/gdb/amd64-windows-nat.c
+++ b/gdb/amd64-windows-nat.c
@@ -16,6 +16,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "gdbarch.h"
+#include "observer.h"
 #include "windows-nat.h"
 #include "i386-nat.h"
 #include <windows.h>
@@ -85,9 +87,303 @@ static const int mappings[] =
 };
 #undef context_offset
 
+#ifndef CONTEXT_EXTENDED_REGSITERS
+#define CONTEXT_EXTENDED_REGISTERS 0
+#endif
+
+#define CONTEXT_DEBUGGER_DR CONTEXT_FULL |CONTEXT_FLOATING_POINT \
+	| CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS
+
+/* 32-bit version of CONTEXT structure.  */
+#define SIZE_OF_80387_REGISTERS 80
+#define CONTEXT32_i386 0x00010000
+#define CONTEXT32_i486 0x00010000
+
+#define CONTEXT32_CONTROL (CONTEXT32_i386 | 0x00000001L)
+#define CONTEXT32_INTEGER (CONTEXT32_i386 | 0x00000002L)
+#define CONTEXT32_SEGMENTS (CONTEXT32_i386 | 0x00000004L)
+#define CONTEXT32_FLOATING_POINT (CONTEXT32_i386 | 0x00000008L)
+#define CONTEXT32_DEBUG_REGISTERS (CONTEXT32_i386 | 0x00000010L)
+#define CONTEXT32_EXTENDED_REGISTERS (CONTEXT32_i386 | 0x00000020L)
+
+#define CONTEXT32_FULL (CONTEXT32_CONTROL | CONTEXT32_INTEGER \
+			| CONTEXT32_SEGMENTS)
+
+#define CONTEXT32_ALL (CONTEXT32_CONTROL | CONTEXT32_INTEGER \
+		       | CONTEXT32_SEGMENTS | CONTEXT32_FLOATING_POINT \
+		       | CONTEXT32_DEBUG_REGISTERS \
+		       | CONTEXT32_EXTENDED_REGISTERS)
+#define CONTEXT32_DEBUGGER_DR CONTEXT32_ALL
+
+
+#define MAXIMUM_SUPPORTED_EXTENSION 512
+
+    typedef struct _FLOATING_SAVE_AREA {
+      DWORD ControlWord;
+      DWORD StatusWord;
+      DWORD TagWord;
+      DWORD ErrorOffset;
+      DWORD ErrorSelector;
+      DWORD DataOffset;
+      DWORD DataSelector;
+      BYTE RegisterArea[SIZE_OF_80387_REGISTERS];
+      DWORD Cr0NpxState;
+    } FLOATING_SAVE_AREA;
+
+    typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
+
+    typedef struct _CONTEXT32 {
+      DWORD ContextFlags;
+      DWORD Dr0;
+      DWORD Dr1;
+      DWORD Dr2;
+      DWORD Dr3;
+      DWORD Dr6;
+      DWORD Dr7;
+      FLOATING_SAVE_AREA FloatSave;
+      DWORD SegGs;
+      DWORD SegFs;
+      DWORD SegEs;
+      DWORD SegDs;
+
+      DWORD Edi;
+      DWORD Esi;
+      DWORD Ebx;
+      DWORD Edx;
+      DWORD Ecx;
+      DWORD Eax;
+      DWORD Ebp;
+      DWORD Eip;
+      DWORD SegCs;
+      DWORD EFlags;
+      DWORD Esp;
+      DWORD SegSs;
+      BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
+    } CONTEXT32;
+
+    typedef CONTEXT32 *PCONTEXT32;
+
+
+#ifndef _LDT_ENTRY_DEFINED
+#define _LDT_ENTRY_DEFINED
+
+    typedef struct _LDT_ENTRY {
+      WORD LimitLow;
+      WORD BaseLow;
+      union {
+	struct {
+	  BYTE BaseMid;
+	  BYTE Flags1;
+	  BYTE Flags2;
+	  BYTE BaseHi;
+	} Bytes;
+	struct {
+	  DWORD BaseMid : 8;
+	  DWORD Type : 5;
+	  DWORD Dpl : 2;
+	  DWORD Pres : 1;
+	  DWORD LimitHi : 4;
+	  DWORD Sys : 1;
+	  DWORD Reserved_0 : 1;
+	  DWORD Default_Big : 1;
+	  DWORD Granularity : 1;
+	  DWORD BaseHi : 8;
+	} Bits;
+      } HighWord;
+    } LDT_ENTRY,*PLDT_ENTRY;
+#endif /* _LDT_ENTRY_DEFINED */
+
+#define context32_offset(x) ((int)(uintptr_t)&(((CONTEXT32 *)NULL)->x))
+static const int mappings32[] =
+{
+  context32_offset (Eax),
+  context32_offset (Ecx),
+  context32_offset (Edx),
+  context32_offset (Ebx),
+  context32_offset (Esp),
+  context32_offset (Ebp),
+  context32_offset (Esi),
+  context32_offset (Edi),
+  context32_offset (Eip),
+  context32_offset (EFlags),
+  context32_offset (SegCs),
+  context32_offset (SegSs),
+  context32_offset (SegDs),
+  context32_offset (SegEs),
+  context32_offset (SegFs),
+  context32_offset (SegGs),
+  context32_offset (FloatSave.RegisterArea[0 * 10]),
+  context32_offset (FloatSave.RegisterArea[1 * 10]),
+  context32_offset (FloatSave.RegisterArea[2 * 10]),
+  context32_offset (FloatSave.RegisterArea[3 * 10]),
+  context32_offset (FloatSave.RegisterArea[4 * 10]),
+  context32_offset (FloatSave.RegisterArea[5 * 10]),
+  context32_offset (FloatSave.RegisterArea[6 * 10]),
+  context32_offset (FloatSave.RegisterArea[7 * 10]),
+  context32_offset (FloatSave.ControlWord),
+  context32_offset (FloatSave.StatusWord),
+  context32_offset (FloatSave.TagWord),
+  context32_offset (FloatSave.ErrorSelector),
+  context32_offset (FloatSave.ErrorOffset),
+  context32_offset (FloatSave.DataSelector),
+  context32_offset (FloatSave.DataOffset),
+  context32_offset (FloatSave.ErrorSelector)
+  /* XMM0-7 */ ,
+  context32_offset (ExtendedRegisters[10*16]),
+  context32_offset (ExtendedRegisters[11*16]),
+  context32_offset (ExtendedRegisters[12*16]),
+  context32_offset (ExtendedRegisters[13*16]),
+  context32_offset (ExtendedRegisters[14*16]),
+  context32_offset (ExtendedRegisters[15*16]),
+  context32_offset (ExtendedRegisters[16*16]),
+  context32_offset (ExtendedRegisters[17*16]),
+  /* MXCSR */
+  context32_offset (ExtendedRegisters[24])
+};
+#undef context32_offset
+
+#define context32_offset(x) ((int)(uintptr_t)&(((CONTEXT *)NULL)->x))
+static const int mappings32on64[] =
+{
+  context32_offset (Rax),
+  context32_offset (Rcx),
+  context32_offset (Rdx),
+  context32_offset (Rbx),
+  context32_offset (Rsp),
+  context32_offset (Rbp),
+  context32_offset (Rsi),
+  context32_offset (Rdi),
+  context32_offset (Rip),
+  context32_offset (EFlags),
+  context32_offset (SegCs),
+  context32_offset (SegSs),
+  context32_offset (SegDs),
+  context32_offset (SegEs),
+  context32_offset (SegFs),
+  context32_offset (SegGs),
+  context32_offset (FloatSave.FloatRegisters[0]),
+  context32_offset (FloatSave.FloatRegisters[1]),
+  context32_offset (FloatSave.FloatRegisters[2]),
+  context32_offset (FloatSave.FloatRegisters[3]),
+  context32_offset (FloatSave.FloatRegisters[4]),
+  context32_offset (FloatSave.FloatRegisters[5]),
+  context32_offset (FloatSave.FloatRegisters[6]),
+  context32_offset (FloatSave.FloatRegisters[7]),
+  context32_offset (FloatSave.ControlWord),
+  context32_offset (FloatSave.StatusWord),
+  context32_offset (FloatSave.TagWord),
+  context32_offset (FloatSave.ErrorSelector),
+  context32_offset (FloatSave.ErrorOffset),
+  context32_offset (FloatSave.DataSelector),
+  context32_offset (FloatSave.DataOffset),
+  context32_offset (FloatSave.ErrorSelector)
+  /* XMM0-7 */ ,
+  context32_offset (Xmm0),
+  context32_offset (Xmm1),
+  context32_offset (Xmm2),
+  context32_offset (Xmm3),
+  context32_offset (Xmm4),
+  context32_offset (Xmm5),
+  context32_offset (Xmm6),
+  context32_offset (Xmm7),
+  context32_offset (Xmm8),
+  context32_offset (Xmm9),
+  context32_offset (Xmm10),
+  context32_offset (Xmm11),
+  context32_offset (Xmm12),
+  context32_offset (Xmm13),
+  context32_offset (Xmm14),
+  context32_offset (Xmm15),
+  /* MXCSR */
+  context32_offset (FloatSave.MxCsr)
+  };
+#undef context32_offset
+
+static DWORD WINAPI (*Win32SuspendThread) (HANDLE);
+static BOOL WINAPI (*Win32GetThreadContext) (HANDLE, void *);
+static BOOL WINAPI (*Win32SetThreadContext) (HANDLE, void *);
+static BOOL WINAPI (*Win32GetThreadSelectorEntry) (HANDLE, DWORD, void *);
+static DWORD WINAPI (*Win64SuspendThread) (HANDLE);
+static BOOL WINAPI (*Win64GetThreadContext) (HANDLE, void *);
+static BOOL WINAPI (*Win64SetThreadContext) (HANDLE, void *);
+static BOOL WINAPI (*Win64GetThreadSelectorEntry) (HANDLE, DWORD, void *);
+
 void
-_initialize_amd64_windows_nat (void)
+setup_i386_windows_nat (void)
+{
+  i386_set_debug_register_length (4);
+  context_all_registers = CONTEXT32_DEBUGGER_DR;
+  context_debug_registers_only = CONTEXT32_DEBUG_REGISTERS;
+  if (Win32SuspendThread && Win32SetThreadContext && Win32GetThreadContext)
+    {
+      windows_set_context_register_offsets (mappings32);
+      GdbSuspendThread = Win32SuspendThread;
+      GdbGetThreadContext = Win32GetThreadContext;
+      GdbSetThreadContext = Win32SetThreadContext;
+      GdbGetThreadSelectorEntry = Win32GetThreadSelectorEntry;
+    }
+  else
+    {
+      windows_set_context_register_offsets (mappings32on64);
+    }
+}
+
+void
+setup_amd64_windows_nat (void)
 {
   windows_set_context_register_offsets (mappings);
   i386_set_debug_register_length (8);
+  context_all_registers = CONTEXT_DEBUGGER_DR;
+  context_debug_registers_only = CONTEXT_DEBUG_REGISTERS;
+  GdbSuspendThread = Win64SuspendThread;
+  GdbGetThreadContext = Win64GetThreadContext;
+  GdbSetThreadContext = Win64SetThreadContext;
+  GdbGetThreadSelectorEntry = Win64GetThreadSelectorEntry;
 }
+
+static void
+windows_notify_architecture_changed (struct gdbarch *gdbarch)
+{
+  const struct bfd_arch_info *bfd_arch_info;
+
+  bfd_arch_info = gdbarch_bfd_arch_info (gdbarch);
+  if (bfd_arch_info->bits_per_address == 64)
+    {
+      i386_dr_low.debug_register_length = 0;
+      setup_amd64_windows_nat ();
+    }
+  else if (bfd_arch_info->bits_per_address == 32)
+    {
+      i386_dr_low.debug_register_length = 0;
+      setup_i386_windows_nat ();
+    }
+  else
+    error (_("Wrong architecture"));
+}
+
+void
+_initialize_amd64_windows_nat (void)
+{
+  HMODULE h = LoadLibrary ("kernel32.dll");
+
+  if (h != INVALID_HANDLE_VALUE)
+    {
+      Win64SuspendThread = (void *) GetProcAddress (h, "SuspendThread");
+      Win64GetThreadContext = (void *) GetProcAddress (h, "GetThreadContext");
+      Win64SetThreadContext = (void *) GetProcAddress (h, "SetThreadContext");
+      Win64GetThreadSelectorEntry = (void *) GetProcAddress (h,
+				      "GetThreadSelectorEntry");
+      Win32SuspendThread = (void *) GetProcAddress (h, "Wow64SuspendThread");
+      Win32GetThreadContext = (void *) GetProcAddress (h,
+			        "Wow64GetThreadContext");
+      Win32SetThreadContext = (void *) GetProcAddress (h,
+			        "Wow64SetThreadContext");
+      Win32GetThreadSelectorEntry = (void *) GetProcAddress (h,
+				      "Wow64GetThreadSelectorEntry");
+      Win32SuspendThread = (void *) GetProcAddress (h, "Wow64SuspendThread");
+      CloseHandle (h);
+    }
+  setup_amd64_windows_nat ();
+  observer_attach_architecture_changed (windows_notify_architecture_changed);
+}
+
diff --git a/gdb/i386-windows-nat.c b/gdb/i386-windows-nat.c
index 96b3fe7..045d0bf 100644
--- a/gdb/i386-windows-nat.c
+++ b/gdb/i386-windows-nat.c
@@ -73,6 +73,17 @@ static const int mappings[] =
 void
 _initialize_i386_windows_nat (void)
 {
+  HMODULE h = LoadLibrary ("kernel32.dll");
+
+  if (h != INVALID_HANDLE_VALUE)
+    {
+      GdbSuspendThread = (void *) GetProcAddress (h, "SuspendThread");
+      GdbGetThreadContext = (void *) GetProcAddress (h, "GetThreadContext");
+      GdbSetThreadContext = (void *) GetProcAddress (h, "SetThreadContext");
+      GdbGetThreadSelectorEntry = (void *) GetProcAddress (h,
+				    "GetThreadSelectorEntry");
+      CloseHandle (h);
+    }
   windows_set_context_register_offsets (mappings);
   i386_set_debug_register_length (4);
 }
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 6134e91..a7c4410 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -95,6 +95,11 @@ static BOOL WINAPI (*GetCurrentConsoleFont) (HANDLE, BOOL,
 static COORD WINAPI (*GetConsoleFontSize) (HANDLE, DWORD);
 static DWORD WINAPI (*GetModuleFileNameEx) (HANDLE, HMODULE, LPGSTR, DWORD);
 
+DWORD WINAPI (*GdbSuspendThread) (HANDLE);
+BOOL WINAPI (*GdbGetThreadContext) (HANDLE, void *);
+BOOL WINAPI (*GdbSetThreadContext) (HANDLE, void *);
+BOOL WINAPI (*GdbGetThreadSelectorEntry) (HANDLE, DWORD, void *);
+
 static struct target_ops windows_ops;
 
 #ifdef __CYGWIN__
@@ -119,6 +124,21 @@ enum
   };
 #endif
 
+#ifndef EXCEPTION_DLL_NOT_FOUND
+#define EXCEPTION_DLL_NOT_FOUND 0xC0000135
+#endif
+#ifndef EXCEPTION_ENTRY_POINT_NOT_FOUND
+#define EXCEPTION_ENTRY_POINT_NOT_FOUND 0xC0000139
+#endif
+#ifdef _WIN64
+#ifndef STATUS_WX86_BREAKPOINT
+#define STATUS_WX86_BREAKPOINT 0x4000001F
+#endif
+#ifndef STATUS_WX86_SINGLE_STEP
+#define STATUS_WX86_SINGLE_STEP 0x4000001E
+#endif
+#endif
+
 #ifndef CONTEXT_EXTENDED_REGISTERS
 /* This macro is only defined on ia32.  It only makes sense on this target,
    so define it as zero if not already defined.  */
@@ -128,6 +148,9 @@ enum
 #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS \
 	| CONTEXT_EXTENDED_REGISTERS
 
+DWORD context_all_registers = CONTEXT_DEBUGGER_DR;
+DWORD context_debug_registers_only = CONTEXT_DEBUG_REGISTERS;
+
 static uintptr_t dr[8];
 static int debug_registers_changed;
 static int debug_registers_used;
@@ -239,6 +262,12 @@ static const struct xlate_exception
   {EXCEPTION_BREAKPOINT, TARGET_SIGNAL_TRAP},
   {DBG_CONTROL_C, TARGET_SIGNAL_INT},
   {EXCEPTION_SINGLE_STEP, TARGET_SIGNAL_TRAP},
+#ifdef STATUS_WX86_BREAKPOINT
+  {STATUS_WX86_BREAKPOINT, TARGET_SIGNAL_TRAP},
+#endif
+#ifdef STATUS_WX86_SINGLE_STEP
+  {STATUS_WX86_SINGLE_STEP, TARGET_SIGNAL_TRAP},
+#endif
   {STATUS_FLOAT_DIVIDE_BY_ZERO, TARGET_SIGNAL_FPE},
   {-1, -1}};
 
@@ -274,7 +303,7 @@ thread_rec (DWORD id, int get_context)
 	  {
 	    if (get_context > 0 && id != current_event.dwThreadId)
 	      {
-		if (SuspendThread (th->h) == (DWORD) -1)
+		if (GdbSuspendThread (th->h) == (DWORD) -1)
 		  {
 		    DWORD err = GetLastError ();
 		    warning (_("SuspendThread failed. (winerr %d)"),
@@ -318,15 +347,15 @@ windows_add_thread (ptid_t ptid, HANDLE h, void *tlb)
   if (debug_registers_used)
     {
       /* Only change the value of the debug registers.  */
-      th->context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
-      CHECK (GetThreadContext (th->h, &th->context));
+      th->context.ContextFlags = context_debug_registers_only;
+      CHECK (GdbGetThreadContext (th->h, &th->context));
       th->context.Dr0 = dr[0];
       th->context.Dr1 = dr[1];
       th->context.Dr2 = dr[2];
       th->context.Dr3 = dr[3];
       th->context.Dr6 = DR6_CLEAR_VALUE;
       th->context.Dr7 = dr[7];
-      CHECK (SetThreadContext (th->h, &th->context));
+      CHECK (GdbSetThreadContext (th->h, &th->context));
       th->context.ContextFlags = 0;
     }
   return th;
@@ -407,8 +436,8 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, int r)
 #endif
 	{
 	  thread_info *th = current_thread;
-	  th->context.ContextFlags = CONTEXT_DEBUGGER_DR;
-	  GetThreadContext (th->h, &th->context);
+	  th->context.ContextFlags = context_all_registers;
+	  GdbGetThreadContext (th->h, &th->context);
 	  /* Copy dr values from that thread.
 	     But only if there were not modified since last stop.
 	     PR gdb/2388 */
@@ -507,7 +536,18 @@ get_module_name (LPVOID base_address, char *dll_name_ret)
 
   if (!EnumProcessModules (current_process_handle, DllHandle,
 			   sizeof (HMODULE), &cbNeeded) || !cbNeeded)
-    goto failed;
+    {
+      DWORD error = GetLastError ();
+      /* ERROR_PARTIAL_COPY is OK for 32-bit processes running on
+	 Windows 64-bit OS.  */
+      if (error != ERROR_PARTIAL_COPY)
+	{
+	  DEBUG_EVENTS (("Call to EnumProcessModules 0x%x failed, error=%d\n",
+			(unsigned int) (uintptr_t) current_process_handle,
+			(int) error));
+	  goto failed;
+	}
+    }
 
   /* Allocate correct amount of space for module list.  */
   DllHandle = (HMODULE *) alloca (cbNeeded);
@@ -517,7 +557,16 @@ get_module_name (LPVOID base_address, char *dll_name_ret)
   /* Get the list of modules.  */
   if (!EnumProcessModules (current_process_handle, DllHandle, cbNeeded,
 				 &cbNeeded))
-    goto failed;
+    {
+      DWORD error = GetLastError ();
+      if (error != ERROR_PARTIAL_COPY)
+	{
+	  DEBUG_EVENTS (("Call to EnumProcessModules 0x%x failed, error=%d\n",
+			(unsigned int) (uintptr_t) current_process_handle,
+			(int) error));
+	  goto failed;
+	}
+    }
 
   for (i = 0; i < (int) (cbNeeded / sizeof (HMODULE)); i++)
     {
@@ -940,7 +989,7 @@ static int
 display_selector (HANDLE thread, DWORD sel)
 {
   LDT_ENTRY info;
-  if (GetThreadSelectorEntry (thread, sel, &info))
+  if (GdbGetThreadSelectorEntry (thread, sel, &info))
     {
       int base, limit;
       printf_filtered ("0x%03lx: ", sel);
@@ -1143,6 +1192,12 @@ handle_exception (struct target_waitstatus *ourstatus)
       DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_BREAKPOINT");
       ourstatus->value.sig = TARGET_SIGNAL_TRAP;
       break;
+#ifdef  STATUS_WX86_BREAKPOINT
+    case STATUS_WX86_BREAKPOINT:
+      DEBUG_EXCEPTION_SIMPLE ("STATUS_WX86_BREAKPOINT");
+      ourstatus->value.sig = TARGET_SIGNAL_TRAP;
+      break;
+#endif
     case DBG_CONTROL_C:
       DEBUG_EXCEPTION_SIMPLE ("DBG_CONTROL_C");
       ourstatus->value.sig = TARGET_SIGNAL_INT;


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-03-28 14:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-28 14:12 [SCM] archer-muller-windows-multi: * Revert environment changes from windows-nat.c muller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).