bfd/
[deliverable/binutils-gdb.git] / gdb / win32-nat.c
index 51443a3d4ed0b44d6edb9c03ff9e7808e93228af..9a1a28cfd56ecaf309ccfe1a0df8dd65de4db6cf 100644 (file)
@@ -60,7 +60,8 @@
 #include "i386-tdep.h"
 #include "i387-tdep.h"
 
 #include "i386-tdep.h"
 #include "i387-tdep.h"
 
-#include "i386-cygwin-tdep.h"
+#include "win32-tdep.h"
+#include "win32-nat.h"
 
 static struct target_ops win32_ops;
 
 
 static struct target_ops win32_ops;
 
@@ -85,6 +86,12 @@ enum
 #endif
 #include <psapi.h>
 
 #endif
 #include <psapi.h>
 
+#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.  */
+#define CONTEXT_EXTENDED_REGISTERS 0
+#endif
+
 #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS \
        | CONTEXT_EXTENDED_REGISTERS
 
 #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS \
        | CONTEXT_EXTENDED_REGISTERS
 
@@ -155,11 +162,16 @@ 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 */
 
 static int debug_exceptions = 0;       /* show target exceptions */
 static int useshell = 0;               /* use shell for subprocesses */
 
-/* This vector maps GDB's idea of a register's number into an address
+/* This vector maps GDB's idea of a register's number into an offset
    in the win32 exception context vector.
 
    It also contains the bit mask needed to load the register in question.
 
    in the win32 exception context vector.
 
    It also contains the bit mask needed to load the register in question.
 
+   The contents of this table can only be computed by the units
+   that provide CPU-specific support for Windows native debugging.
+   These units should set the table by calling
+   win32_set_context_register_offsets.
+
    One day we could read a reg, we could inspect the context we
    already have loaded, if it doesn't have the bit set that we need,
    we read that set of registers in using GetThreadContext.  If the
    One day we could read a reg, we could inspect the context we
    already have loaded, if it doesn't have the bit set that we need,
    we read that set of registers in using GetThreadContext.  If the
@@ -168,55 +180,7 @@ static int useshell = 0;           /* use shell for subprocesses */
    the other regs of the group, and then we copy the info in and set
    out bit. */
 
    the other regs of the group, and then we copy the info in and set
    out bit. */
 
-#define context_offset(x) ((int)&(((CONTEXT *)NULL)->x))
-static const int mappings[] =
-{
-  context_offset (Eax),
-  context_offset (Ecx),
-  context_offset (Edx),
-  context_offset (Ebx),
-  context_offset (Esp),
-  context_offset (Ebp),
-  context_offset (Esi),
-  context_offset (Edi),
-  context_offset (Eip),
-  context_offset (EFlags),
-  context_offset (SegCs),
-  context_offset (SegSs),
-  context_offset (SegDs),
-  context_offset (SegEs),
-  context_offset (SegFs),
-  context_offset (SegGs),
-  context_offset (FloatSave.RegisterArea[0 * 10]),
-  context_offset (FloatSave.RegisterArea[1 * 10]),
-  context_offset (FloatSave.RegisterArea[2 * 10]),
-  context_offset (FloatSave.RegisterArea[3 * 10]),
-  context_offset (FloatSave.RegisterArea[4 * 10]),
-  context_offset (FloatSave.RegisterArea[5 * 10]),
-  context_offset (FloatSave.RegisterArea[6 * 10]),
-  context_offset (FloatSave.RegisterArea[7 * 10]),
-  context_offset (FloatSave.ControlWord),
-  context_offset (FloatSave.StatusWord),
-  context_offset (FloatSave.TagWord),
-  context_offset (FloatSave.ErrorSelector),
-  context_offset (FloatSave.ErrorOffset),
-  context_offset (FloatSave.DataSelector),
-  context_offset (FloatSave.DataOffset),
-  context_offset (FloatSave.ErrorSelector)
-  /* XMM0-7 */ ,
-  context_offset (ExtendedRegisters[10*16]),
-  context_offset (ExtendedRegisters[11*16]),
-  context_offset (ExtendedRegisters[12*16]),
-  context_offset (ExtendedRegisters[13*16]),
-  context_offset (ExtendedRegisters[14*16]),
-  context_offset (ExtendedRegisters[15*16]),
-  context_offset (ExtendedRegisters[16*16]),
-  context_offset (ExtendedRegisters[17*16]),
-  /* MXCSR */
-  context_offset (ExtendedRegisters[24])
-};
-
-#undef context_offset
+static const int *mappings;
 
 /* This vector maps the target's idea of an exception (extracted
    from the DEBUG_EVENT structure) to GDB's idea. */
 
 /* This vector maps the target's idea of an exception (extracted
    from the DEBUG_EVENT structure) to GDB's idea. */
@@ -238,6 +202,15 @@ static const struct xlate_exception
   {STATUS_FLOAT_DIVIDE_BY_ZERO, TARGET_SIGNAL_FPE},
   {-1, -1}};
 
   {STATUS_FLOAT_DIVIDE_BY_ZERO, TARGET_SIGNAL_FPE},
   {-1, -1}};
 
+/* Set the MAPPINGS static global to OFFSETS.
+   See the description of MAPPINGS for more details.  */
+
+void
+win32_set_context_register_offsets (const int *offsets)
+{
+  mappings = offsets;
+}
+
 static void
 check (BOOL ok, const char *file, int line)
 {
 static void
 check (BOOL ok, const char *file, int line)
 {
@@ -475,7 +448,7 @@ static DWORD WINAPI (*psapi_GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR,
    is zero return the first loaded module (which is always the name of the
    executable).  */
 static int
    is zero return the first loaded module (which is always the name of the
    executable).  */
 static int
-get_module_name (DWORD base_address, char *dll_name_ret)
+get_module_name (LPVOID base_address, char *dll_name_ret)
 {
   DWORD len;
   MODULEINFO mi;
 {
   DWORD len;
   MODULEINFO mi;
@@ -518,7 +491,7 @@ get_module_name (DWORD base_address, char *dll_name_ret)
                                       &mi, sizeof (mi)))
        error (_("Can't get module info"));
 
                                       &mi, sizeof (mi)))
        error (_("Can't get module info"));
 
-      if (!base_address || (DWORD) (mi.lpBaseOfDll) == base_address)
+      if (!base_address || mi.lpBaseOfDll == base_address)
        {
          /* Try to find the name of the given module */
          len = psapi_GetModuleFileNameExA (current_process_handle,
        {
          /* Try to find the name of the given module */
          len = psapi_GetModuleFileNameExA (current_process_handle,
@@ -554,7 +527,7 @@ struct safe_symbol_file_add_args
 /* Maintain a linked list of "so" information. */
 struct lm_info
 {
 /* Maintain a linked list of "so" information. */
 struct lm_info
 {
-  DWORD load_addr;
+  LPVOID load_addr;
 };
 
 static struct so_list solib_start, *solib_end;
 };
 
 static struct so_list solib_start, *solib_end;
@@ -613,7 +586,7 @@ safe_symbol_file_add (char *name, int from_tty,
 }
 
 static struct so_list *
 }
 
 static struct so_list *
-win32_make_so (const char *name, DWORD load_addr)
+win32_make_so (const char *name, LPVOID load_addr)
 {
   struct so_list *so;
   char buf[MAX_PATH + 1];
 {
   struct so_list *so;
   char buf[MAX_PATH + 1];
@@ -740,7 +713,7 @@ handle_load_dll (void *dummy)
 
   dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0';
 
 
   dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0';
 
-  if (!get_module_name ((DWORD) event->lpBaseOfDll, dll_buf))
+  if (!get_module_name (event->lpBaseOfDll, dll_buf))
     dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0';
 
   dll_name = dll_buf;
     dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0';
 
   dll_name = dll_buf;
@@ -751,11 +724,11 @@ handle_load_dll (void *dummy)
   if (!dll_name)
     return 1;
 
   if (!dll_name)
     return 1;
 
-  solib_end->next = win32_make_so (dll_name, (DWORD) event->lpBaseOfDll);
+  solib_end->next = win32_make_so (dll_name, event->lpBaseOfDll);
   solib_end = solib_end->next;
 
   DEBUG_EVENTS (("gdb: Loading dll \"%s\" at 0x%lx.\n", solib_end->so_name,
   solib_end = solib_end->next;
 
   DEBUG_EVENTS (("gdb: Loading dll \"%s\" at 0x%lx.\n", solib_end->so_name,
-                (DWORD) solib_end->lm_info->load_addr));
+                solib_end->lm_info->load_addr));
 
   return 1;
 }
 
   return 1;
 }
@@ -771,7 +744,7 @@ win32_free_so (struct so_list *so)
 static int
 handle_unload_dll (void *dummy)
 {
 static int
 handle_unload_dll (void *dummy)
 {
-  DWORD lpBaseOfDll = (DWORD) current_event.u.UnloadDll.lpBaseOfDll;
+  LPVOID lpBaseOfDll = current_event.u.UnloadDll.lpBaseOfDll;
   struct so_list *so;
 
   for (so = &solib_start; so->next != NULL; so = so->next)
   struct so_list *so;
 
   for (so = &solib_start; so->next != NULL; so = so->next)
@@ -1594,11 +1567,11 @@ has_detach_ability (void)
   if (kernel32)
     {
       if (!kernel32_DebugSetProcessKillOnExit)
   if (kernel32)
     {
       if (!kernel32_DebugSetProcessKillOnExit)
-       kernel32_DebugSetProcessKillOnExit = GetProcAddress (kernel32,
-                                                "DebugSetProcessKillOnExit");
+       kernel32_DebugSetProcessKillOnExit =
+         (void *) GetProcAddress (kernel32, "DebugSetProcessKillOnExit");
       if (!kernel32_DebugActiveProcessStop)
       if (!kernel32_DebugActiveProcessStop)
-       kernel32_DebugActiveProcessStop = GetProcAddress (kernel32,
-                                                "DebugActiveProcessStop");
+       kernel32_DebugActiveProcessStop =
+         (void *) GetProcAddress (kernel32, "DebugActiveProcessStop");
       if (kernel32_DebugSetProcessKillOnExit
          && kernel32_DebugActiveProcessStop)
        return 1;
       if (kernel32_DebugSetProcessKillOnExit
          && kernel32_DebugActiveProcessStop)
        return 1;
@@ -1635,13 +1608,14 @@ set_process_privilege (const char *privilege, BOOL enable)
       if (!(advapi32 = LoadLibrary ("advapi32.dll")))
        goto out;
       if (!OpenProcessToken)
       if (!(advapi32 = LoadLibrary ("advapi32.dll")))
        goto out;
       if (!OpenProcessToken)
-       OpenProcessToken = GetProcAddress (advapi32, "OpenProcessToken");
+       OpenProcessToken =
+          (void *) GetProcAddress (advapi32, "OpenProcessToken");
       if (!LookupPrivilegeValue)
       if (!LookupPrivilegeValue)
-       LookupPrivilegeValue = GetProcAddress (advapi32,
-                                              "LookupPrivilegeValueA");
+       LookupPrivilegeValue =
+          (void *) GetProcAddress (advapi32, "LookupPrivilegeValueA");
       if (!AdjustTokenPrivileges)
       if (!AdjustTokenPrivileges)
-       AdjustTokenPrivileges = GetProcAddress (advapi32,
-                                               "AdjustTokenPrivileges");
+       AdjustTokenPrivileges =
+          (void *) GetProcAddress (advapi32, "AdjustTokenPrivileges");
       if (!OpenProcessToken || !LookupPrivilegeValue || !AdjustTokenPrivileges)
        {
          advapi32 = NULL;
       if (!OpenProcessToken || !LookupPrivilegeValue || !AdjustTokenPrivileges)
        {
          advapi32 = NULL;
@@ -2075,7 +2049,8 @@ win32_xfer_shared_libraries (struct target_ops *ops,
   obstack_init (&obstack);
   obstack_grow_str (&obstack, "<library-list>\n");
   for (so = solib_start.next; so; so = so->next)
   obstack_init (&obstack);
   obstack_grow_str (&obstack, "<library-list>\n");
   for (so = solib_start.next; so; so = so->next)
-    win32_xfer_shared_library (so->so_name, so->lm_info->load_addr, &obstack);
+    win32_xfer_shared_library (so->so_name, (CORE_ADDR) so->lm_info->load_addr,
+                               &obstack);
   obstack_grow_str0 (&obstack, "</library-list>\n");
 
   buf = obstack_finish (&obstack);
   obstack_grow_str0 (&obstack, "</library-list>\n");
 
   buf = obstack_finish (&obstack);
This page took 0.030004 seconds and 4 git commands to generate.