This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC-v2] Mingw Windows 64-bit gdbserver
- From: "Pierre Muller" <pierre dot muller at ics-cnrs dot unistra dot fr>
- To: "'Pedro Alves'" <pedro at codesourcery dot com>
- Cc: <gdb-patches at sourceware dot org>
- Date: Sun, 18 Apr 2010 01:17:59 +0200
- Subject: [RFC-v2] Mingw Windows 64-bit gdbserver
- References: <000d01cadd79$efa9e2b0$cefda810$@muller@ics-cnrs.unistra.fr> <201004161659.37990.pedro@codesourcery.com> <001f01caddf0$6d4246b0$47c6d410$@muller@ics-cnrs.unistra.fr> <201004171158.08327.pedro@codesourcery.com>
> -----Message d'origine-----
> De?: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Pedro Alves
> Envoyé?: Saturday, April 17, 2010 12:58 PM
> À?: Pierre Muller
> Cc?: gdb-patches@sourceware.org
> Objet?: Re: [RFC] Mingw Windows 64-bit gdbserver
>
> On Saturday 17 April 2010 06:40:02, Pierre Muller wrote:
>
> > > How about instead merging the files, like
> > > linux-x86-low.c handles both 64-bit and 32-bit? There's
> > > a lot of common stuff between both archs support, it
> > > seems.
> >
> > Of course, I agree with you that the two files
> > share a very large common portion that is identical.
> > There are only two places where they really differ:
> > For the call to the init_registers_XXX
> > and for the register mappings array.
> >
> > The main question is how should we split these parts
> > off if we want to keep a common part:
> >
> > I would propose this:
> > rename win32-i386-low.c to win-x86-low.c
>
> Lets avoid someone reading this and getting religious
> against "win", and go with windows-*-low.c, just
> like gdb/windows-nat.c was renamed from win32-nat.c, and
> gdb has i386-windows-nat.c and amd64-windows-nat.c.
>
> > Create win32-i386-low.h and win64-amd64-low.h
> > that would have the register mappings and
> > a macro to define their local init_registers.
>
> Yes, much better, if nothing else because that's how
> gdb handles this as well. It's always good to have the
> code bases solve the same problem in the same way, so
> that we can more easily keep them in sync or merge them.
>
> Take a look at gdb/amd64-windows-nat.c, it also does something
> similar to handle the common stuff, though since we have
> a win32_target_ops in gdbserver, we can put the register mappings
> array pointer directly in win32_target_ops instead of making it
> a global.
>
> Let's avoid macros. Use for example the `arch_setup' callback
> in the win32_target_ops vector for this, keeping the arrays
> defined in the corresponding arch specific .c files.
Here is a new version of the patch:
I tried to minimize code duplication, but I
still needed one macro to decide which file
from win32-i386-low.c or win64-amd64-low.c
should be read.
The macro is named COMPILE_WIN64 and set
by configuration in config.h header.
I also change the regular expression used for
target matching to 'x86_64-*-mingw*' as is done in gdb directory.
mappings is now a pointer, that is set to
windows_i386_mappings or windows_amd64_mappings.
This should minimize problems if we later want to
support debugging windows 32-bit programs with
a 64-bit gdbserver.
The ChangeLog is a bit messy because I renamed a file
and reused the old name to create a new file...
but I didn't find another name that would fit better...
Unless I use windows- as a prefix everywhere...
Pierre
2010-04-18 Pierre Muller <muller@ics.u-strasbg.fr>
* configure.tgt (x86_64-*-mingw*): Mark building of
gdbserver for this target.
gdbserver ChangeLog entry:
2010-04-18 Pierre Muller <muller@ics.u-strasbg.fr>
* configure.ac (COMPILE_WIN64): New macro for config.h
defined if srv_mingw64 is set to `yes'.
* config.in: Regenerate.
* configure: Regenerate.
* configure.srv: Adapt to win32-i386-low.c to
windows-x86-low.c rename.
(x86_64-*-mingw*): New server target.
* win32-i386-low.c: Rename to ...
* windows-x86-low.c: New file name, reads in
`win32-i386-low.c' or `win64-amdd64-low.c'.
(mappings): New static variable.
(the_low_target): Change arch_setup field to init_windows_x86.
* win32-i386-low.c: New file.
(init_registers_i386): Declare external.
(windows_i386_mappings): Array moved from old win32-i386-low.c.
(init_windows_x86): New function.
* win64-amd64-low.c: New file.
(init_registers_amd64): Declare external.
(windows_amd64_mappings): New array.
(init_windows_x86): New function.
* win32-low.c: Adapt to support also 64-bit architecture.
(child_xfer_memory): Use uintptr_t type for local variable `addr'.
(get_image_name): Use SIZE_T type for local variable `done'.
(psapi_get_dll_name): Use uintptr_t type for parameter
`BaseAddress'.
(toolhelp_get_dll_name): Idem.
(handle_load_dll): Use uintptr_t type for local variable
`load_addr'.
(handle_unload_dll): Use unitptr_t typecast to avoid warning.
(handle_exception): Use phex_nz to avoid warning.
(win32_wait): Remove unused local variable `process'.
Index: configure.tgt
===================================================================
RCS file: /cvs/src/src/gdb/configure.tgt,v
retrieving revision 1.230
diff -u -p -r1.230 configure.tgt
--- configure.tgt 25 Feb 2010 20:30:58 -0000 1.230
+++ configure.tgt 17 Apr 2010 22:08:33 -0000
@@ -590,6 +590,7 @@ x86_64-*-mingw*)
gdb_target_obs="amd64-tdep.o amd64-windows-tdep.o \
i386-tdep.o i386-cygwin-tdep.o i387-tdep.o \
solib-target.o windows-tdep.o"
+ build_gdbserver=yes
;;
x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
# Target: NetBSD/amd64
Index: gdbserver/config.in
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/config.in,v
retrieving revision 1.26
diff -u -p -r1.26 config.in
--- gdbserver/config.in 21 Dec 2009 20:52:53 -0000 1.26
+++ gdbserver/config.in 17 Apr 2010 22:08:33 -0000
@@ -1,5 +1,8 @@
/* config.in. Generated from configure.ac by autoheader. */
+/* Define if we compile a Windows-64 bit program. */
+#undef COMPILE_WIN64
+
/* Define to 1 if you have the <arpa/inet.h> header file. */
#undef HAVE_ARPA_INET_H
@@ -33,6 +36,9 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
+/* Define to 1 if you have the `dl' library (-ldl). */
+#undef HAVE_LIBDL
+
/* Define to 1 if you have the <linux/elf.h> header file. */
#undef HAVE_LINUX_ELF_H
Index: gdbserver/configure
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure,v
retrieving revision 1.48
diff -u -p -r1.48 configure
--- gdbserver/configure 17 Apr 2010 20:43:13 -0000 1.48
+++ gdbserver/configure 17 Apr 2010 22:08:35 -0000
@@ -4067,6 +4067,12 @@ $as_echo "#define USE_WIN32API 1" >>conf
fi
+if test "${srv_mingw64}" = "yes"; then
+
+$as_echo "#define COMPILE_WIN64 1" >>confdefs.h
+
+fi
+
if test "${srv_linux_usrregs}" = "yes"; then
$as_echo "#define HAVE_LINUX_USRREGS 1" >>confdefs.h
Index: gdbserver/configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure.ac,v
retrieving revision 1.34
diff -u -p -r1.34 configure.ac
--- gdbserver/configure.ac 17 Apr 2010 20:43:13 -0000 1.34
+++ gdbserver/configure.ac 17 Apr 2010 22:08:35 -0000
@@ -131,6 +131,11 @@ if test "${srv_mingw}" = "yes"; then
for Cygwin.])
fi
+if test "${srv_mingw64}" = "yes"; then
+ AC_DEFINE(COMPILE_WIN64, 1,
+ [Define if we compile a Windows-64 bit program.])
+fi
+
if test "${srv_linux_usrregs}" = "yes"; then
AC_DEFINE(HAVE_LINUX_USRREGS, 1,
[Define if the target supports PTRACE_PEEKUSR for register ]
Index: gdbserver/configure.srv
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure.srv,v
retrieving revision 1.53
diff -u -p -r1.53 configure.srv
--- gdbserver/configure.srv 8 Apr 2010 22:32:38 -0000 1.53
+++ gdbserver/configure.srv 17 Apr 2010 22:08:35 -0000
@@ -24,7 +24,7 @@ srv_hostio_err_objs="hostio-errno.o"
srv_i386_regobj="i386.o i386-avx.o i386-mmx.o"
srv_i386_linux_regobj="i386-linux.o i386-avx-linux.o i386-mmx-linux.o"
-srv_amd64_regobj="amd64.o x86-64-avx.o"
+srv_amd64_regobj="amd64.o amd64-avx.o"
srv_amd64_linux_regobj="amd64-linux.o amd64-avx-linux.o"
srv_i386_32bit_xmlfiles="i386/32bit-core.xml i386/32bit-sse.xml
i386/32bit-avx.xml"
@@ -73,7 +73,7 @@ case "${target}" in
srv_linux_thread_db=yes
;;
i[34567]86-*-cygwin*) srv_regobj="$srv_i386_regobj"
- srv_tgtobj="i386-low.o win32-low.o win32-i386-low.o"
+ srv_tgtobj="i386-low.o win32-low.o
windows-x86-low.o"
srv_xmlfiles="$srv_i386_xmlfiles"
;;
i[34567]86-*-linux*) srv_regobj="$srv_i386_linux_regobj"
@@ -89,7 +89,7 @@ case "${target}" in
;;
i[34567]86-*-mingw32ce*)
srv_regobj="$srv_i386_regobj"
- srv_tgtobj="i386-low.o win32-low.o win32-i386-low.o"
+ srv_tgtobj="i386-low.o win32-low.o
windows-x86-low.o"
srv_tgtobj="${srv_tgtobj} wincecompat.o"
srv_xmlfiles="$srv_i386_xmlfiles"
# hostio_last_error implementation is in win32-low.c
@@ -98,7 +98,7 @@ case "${target}" in
srv_mingwce=yes
;;
i[34567]86-*-mingw*) srv_regobj="$srv_i386_regobj"
- srv_tgtobj="i386-low.o win32-low.o win32-i386-low.o"
+ srv_tgtobj="i386-low.o win32-low.o
windows-x86-low.o"
srv_xmlfiles="$srv_i386_xmlfiles"
srv_mingw=yes
;;
@@ -231,6 +231,13 @@ case "${target}" in
srv_linux_regsets=yes
srv_linux_thread_db=yes
;;
+ x86_64-*-mingw*) srv_regobj="$srv_amd64_regobj"
+ srv_tgtobj="i386-low.o win32-low.o
windows-x86-low.o"
+ srv_xmlfiles="$srv_amd64_xmlfiles"
+ srv_mingw64=yes
+ srv_mingw=yes
+ ;;
+
xscale*-*-linux*) srv_regobj=reg-arm.o
srv_tgtobj="linux-low.o linux-arm-low.o"
srv_linux_usrregs=yes
Index: gdbserver/win32-i386-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/win32-i386-low.c,v
retrieving revision 1.18
diff -u -p -r1.18 win32-i386-low.c
--- gdbserver/win32-i386-low.c 20 Jan 2010 22:55:38 -0000 1.18
+++ gdbserver/win32-i386-low.c 17 Apr 2010 22:08:35 -0000
@@ -15,205 +15,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "server.h"
-#include "win32-low.h"
-#include "i386-low.h"
-
-#define FCS_REGNUM 27
-#define FOP_REGNUM 31
-
-#define FLAG_TRACE_BIT 0x100
-
/* Defined in auto-generated file reg-i386.c. */
void init_registers_i386 (void);
-static struct i386_debug_reg_state debug_reg_state;
-
-static int debug_registers_changed = 0;
-static int debug_registers_used = 0;
-
-/* Update the inferior's debug register REGNUM from STATE. */
-
-void
-i386_dr_low_set_addr (const struct i386_debug_reg_state *state, int regnum)
-{
- if (! (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR))
- fatal ("Invalid debug register %d", regnum);
-
- /* debug_reg_state.dr_mirror is already set.
- Just notify i386_set_thread_context, i386_thread_added
- that the registers need to be updated. */
- debug_registers_changed = 1;
- debug_registers_used = 1;
-}
-
-/* Update the inferior's DR7 debug control register from STATE. */
-
-void
-i386_dr_low_set_control (const struct i386_debug_reg_state *state)
-{
- /* debug_reg_state.dr_control_mirror is already set.
- Just notify i386_set_thread_context, i386_thread_added
- that the registers need to be updated. */
- debug_registers_changed = 1;
- debug_registers_used = 1;
-}
-
-/* Get the value of the DR6 debug status register from the inferior
- and record it in STATE. */
-
-void
-i386_dr_low_get_status (struct i386_debug_reg_state *state)
-{
- /* We don't need to do anything here, the last call to thread_rec for
- current_event.dwThreadId id has already set it. */
-}
-
-/* Watchpoint support. */
-
-static int
-i386_insert_point (char type, CORE_ADDR addr, int len)
-{
- switch (type)
- {
- case '2':
- case '3':
- case '4':
- return i386_low_insert_watchpoint (&debug_reg_state,
- type, addr, len);
- default:
- /* Unsupported. */
- return 1;
- }
-}
-
-static int
-i386_remove_point (char type, CORE_ADDR addr, int len)
-{
- switch (type)
- {
- case '2':
- case '3':
- case '4':
- return i386_low_remove_watchpoint (&debug_reg_state,
- type, addr, len);
- default:
- /* Unsupported. */
- return 1;
- }
-}
-
-static int
-i386_stopped_by_watchpoint (void)
-{
- return i386_low_stopped_by_watchpoint (&debug_reg_state);
-}
-
-static CORE_ADDR
-i386_stopped_data_address (void)
-{
- CORE_ADDR addr;
- if (i386_low_stopped_data_address (&debug_reg_state, &addr))
- return addr;
- return 0;
-}
-
-static void
-i386_initial_stuff (void)
-{
- i386_low_init_dregs (&debug_reg_state);
- debug_registers_changed = 0;
- debug_registers_used = 0;
-}
-
-static void
-i386_get_thread_context (win32_thread_info *th, DEBUG_EVENT* current_event)
-{
- /* Requesting the CONTEXT_EXTENDED_REGISTERS register set fails if
- the system doesn't support extended registers. */
- static DWORD extended_registers = CONTEXT_EXTENDED_REGISTERS;
-
- again:
- th->context.ContextFlags = (CONTEXT_FULL
- | CONTEXT_FLOATING_POINT
- | CONTEXT_DEBUG_REGISTERS
- | extended_registers);
-
- if (!GetThreadContext (th->h, &th->context))
- {
- DWORD e = GetLastError ();
-
- if (extended_registers && e == ERROR_INVALID_PARAMETER)
- {
- extended_registers = 0;
- goto again;
- }
-
- error ("GetThreadContext failure %ld\n", (long) e);
- }
-
- debug_registers_changed = 0;
-
- if (th->tid == current_event->dwThreadId)
- {
- /* Copy dr values from the current thread. */
- struct i386_debug_reg_state *dr = &debug_reg_state;
- dr->dr_mirror[0] = th->context.Dr0;
- dr->dr_mirror[1] = th->context.Dr1;
- dr->dr_mirror[2] = th->context.Dr2;
- dr->dr_mirror[3] = th->context.Dr3;
- dr->dr_status_mirror = th->context.Dr6;
- dr->dr_control_mirror = th->context.Dr7;
- }
-}
-
-static void
-i386_set_thread_context (win32_thread_info *th, DEBUG_EVENT* current_event)
-{
- if (debug_registers_changed)
- {
- struct i386_debug_reg_state *dr = &debug_reg_state;
- th->context.Dr0 = dr->dr_mirror[0];
- th->context.Dr1 = dr->dr_mirror[1];
- th->context.Dr2 = dr->dr_mirror[2];
- th->context.Dr3 = dr->dr_mirror[3];
- /* th->context.Dr6 = dr->dr_status_mirror;
- FIXME: should we set dr6 also ?? */
- th->context.Dr7 = dr->dr_control_mirror;
- }
-
- SetThreadContext (th->h, &th->context);
-}
-
-static void
-i386_thread_added (win32_thread_info *th)
-{
- /* Set the debug registers for the new thread if they are used. */
- if (debug_registers_used)
- {
- struct i386_debug_reg_state *dr = &debug_reg_state;
- th->context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
- GetThreadContext (th->h, &th->context);
-
- th->context.Dr0 = dr->dr_mirror[0];
- th->context.Dr1 = dr->dr_mirror[1];
- th->context.Dr2 = dr->dr_mirror[2];
- th->context.Dr3 = dr->dr_mirror[3];
- /* th->context.Dr6 = dr->dr_status_mirror;
- FIXME: should we set dr6 also ?? */
- th->context.Dr7 = dr->dr_control_mirror;
-
- SetThreadContext (th->h, &th->context);
- th->context.ContextFlags = 0;
- }
-}
-
-static void
-i386_single_step (win32_thread_info *th)
-{
- th->context.EFlags |= FLAG_TRACE_BIT;
-}
-
/* An array of offset mappings into a Win32 Context structure.
This is a one-to-one mapping which is indexed by gdb's register
numbers. It retrieves an offset into the context structure where
@@ -222,7 +26,7 @@ i386_single_step (win32_thread_info *th)
register in it's CONTEXT structure. In this case regptr will return
a pointer into a dummy register. */
#define context_offset(x) ((int)&(((CONTEXT *)NULL)->x))
-static const int mappings[] = {
+static const int windows_i386_mappings[] = {
context_offset (Eax),
context_offset (Ecx),
context_offset (Edx),
@@ -269,54 +73,13 @@ static const int mappings[] = {
};
#undef context_offset
-/* Fetch register from gdbserver regcache data. */
-static void
-i386_fetch_inferior_register (struct regcache *regcache,
- win32_thread_info *th, int r)
-{
- char *context_offset = (char *) &th->context + mappings[r];
-
- long l;
- if (r == FCS_REGNUM)
- {
- l = *((long *) context_offset) & 0xffff;
- supply_register (regcache, r, (char *) &l);
- }
- else if (r == FOP_REGNUM)
- {
- l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1);
- supply_register (regcache, r, (char *) &l);
- }
- else
- supply_register (regcache, r, context_offset);
-}
-
-/* Store a new register value into the thread context of TH. */
static void
-i386_store_inferior_register (struct regcache *regcache,
- win32_thread_info *th, int r)
+init_windows_x86 ()
{
- char *context_offset = (char *) &th->context + mappings[r];
- collect_register (regcache, r, context_offset);
+ init_registers_i386 ();
+ mappings = windows_i386_mappings;
+ the_low_target.num_regs = sizeof (windows_i386_mappings)
+ / sizeof (windows_i386_mappings[0]);
}
-static const unsigned char i386_win32_breakpoint = 0xcc;
-#define i386_win32_breakpoint_len 1
-struct win32_target_ops the_low_target = {
- init_registers_i386,
- sizeof (mappings) / sizeof (mappings[0]),
- i386_initial_stuff,
- i386_get_thread_context,
- i386_set_thread_context,
- i386_thread_added,
- i386_fetch_inferior_register,
- i386_store_inferior_register,
- i386_single_step,
- &i386_win32_breakpoint,
- i386_win32_breakpoint_len,
- i386_insert_point,
- i386_remove_point,
- i386_stopped_by_watchpoint,
- i386_stopped_data_address
-};
Index: gdbserver/win32-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/win32-low.c,v
retrieving revision 1.46
diff -u -p -r1.46 win32-low.c
--- gdbserver/win32-low.c 16 Apr 2010 07:49:37 -0000 1.46
+++ gdbserver/win32-low.c 17 Apr 2010 22:08:36 -0000
@@ -280,7 +280,7 @@ child_xfer_memory (CORE_ADDR memaddr, ch
int write, struct target_ops *target)
{
SIZE_T done;
- long addr = (long) memaddr;
+ uintptr_t addr = (uintptr_t) memaddr;
if (write)
{
@@ -941,7 +941,7 @@ get_image_name (HANDLE h, void *address,
char *address_ptr;
int len = 0;
char b[2];
- DWORD done;
+ SIZE_T done;
/* Attempt to read the name of the dll that was detected.
This is documented to work only when actively debugging
@@ -1019,7 +1019,7 @@ load_psapi (void)
}
static int
-psapi_get_dll_name (DWORD BaseAddress, char *dll_name_ret)
+psapi_get_dll_name (uintptr_t BaseAddress, char *dll_name_ret)
{
DWORD len;
MODULEINFO mi;
@@ -1064,7 +1064,7 @@ psapi_get_dll_name (DWORD BaseAddress, c
(int) err, strwinerror (err));
}
- if ((DWORD) (mi.lpBaseOfDll) == BaseAddress)
+ if ((uintptr_t) (mi.lpBaseOfDll) == BaseAddress)
{
len = (*win32_GetModuleFileNameExA) (current_process_handle,
DllHandle[i],
@@ -1134,7 +1134,7 @@ load_toolhelp (void)
}
static int
-toolhelp_get_dll_name (DWORD BaseAddress, char *dll_name_ret)
+toolhelp_get_dll_name (uintptr_t BaseAddress, char *dll_name_ret)
{
HANDLE snapshot_module;
MODULEENTRY32 modEntry = { sizeof (MODULEENTRY32) };
@@ -1151,7 +1151,7 @@ toolhelp_get_dll_name (DWORD BaseAddress
/* Ignore the first module, which is the exe. */
if (win32_Module32First (snapshot_module, &modEntry))
while (win32_Module32Next (snapshot_module, &modEntry))
- if ((DWORD) modEntry.modBaseAddr == BaseAddress)
+ if ((uintptr_t) modEntry.modBaseAddr == BaseAddress)
{
#ifdef UNICODE
wcstombs (dll_name_ret, modEntry.szExePath, MAX_PATH + 1);
@@ -1176,21 +1176,21 @@ handle_load_dll (void)
LOAD_DLL_DEBUG_INFO *event = ¤t_event.u.LoadDll;
char dll_buf[MAX_PATH + 1];
char *dll_name = NULL;
- DWORD load_addr;
+ uintptr_t load_addr;
dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0';
/* Windows does not report the image name of the dlls in the debug
event on attaches. We resort to iterating over the list of
loaded dlls looking for a match by image base. */
- if (!psapi_get_dll_name ((DWORD) event->lpBaseOfDll, dll_buf))
+ if (!psapi_get_dll_name ((uintptr_t) event->lpBaseOfDll, dll_buf))
{
if (!server_waiting)
/* On some versions of Windows and Windows CE, we can't create
toolhelp snapshots while the inferior is stopped in a
LOAD_DLL_DEBUG_EVENT due to a dll load, but we can while
Windows is reporting the already loaded dlls. */
- toolhelp_get_dll_name ((DWORD) event->lpBaseOfDll, dll_buf);
+ toolhelp_get_dll_name ((uintptr_t) event->lpBaseOfDll, dll_buf);
}
dll_name = dll_buf;
@@ -1205,7 +1205,7 @@ handle_load_dll (void)
the offset from 0 of the first byte in an image - because
of the file header and the section alignment. */
- load_addr = (DWORD) event->lpBaseOfDll + 0x1000;
+ load_addr = (uintptr_t) event->lpBaseOfDll + 0x1000;
win32_add_one_solib (dll_name, load_addr);
}
@@ -1213,7 +1213,7 @@ static void
handle_unload_dll (void)
{
CORE_ADDR load_addr =
- (CORE_ADDR) (DWORD) current_event.u.UnloadDll.lpBaseOfDll;
+ (CORE_ADDR) (uintptr_t) current_event.u.UnloadDll.lpBaseOfDll;
load_addr += 0x1000;
unloaded_dll (NULL, load_addr);
}
@@ -1314,10 +1314,10 @@ handle_exception (struct target_waitstat
ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
return;
}
- OUTMSG2 (("gdbserver: unknown target exception 0x%08lx at 0x%08lx",
+ OUTMSG2 (("gdbserver: unknown target exception 0x%08lx at 0x%s",
current_event.u.Exception.ExceptionRecord.ExceptionCode,
- (DWORD) current_event.u.Exception.ExceptionRecord.
- ExceptionAddress));
+ phex_nz ((uintptr_t)
current_event.u.Exception.ExceptionRecord.
+ ExceptionAddress, sizeof(uintptr_t))));
ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
break;
}
@@ -1577,7 +1577,6 @@ get_child_debug_event (struct target_wai
static ptid_t
win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
- struct process_info *process;
struct regcache *regcache;
while (1)
Index: gdbserver/win64-amd64-low.c
===================================================================
RCS file: gdbserver/win64-amd64-low.c
diff -N gdbserver/win64-amd64-low.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdbserver/win64-amd64-low.c 17 Apr 2010 22:08:36 -0000
@@ -0,0 +1,98 @@
+/* Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
+/* Defined in auto-generated file reg-amd64.c. */
+void init_registers_amd64 (void);
+
+#ifndef CONTEXT_EXTENDED_REGISTERS
+#define CONTEXT_EXTENDED_REGISTERS 0
+#endif
+
+#define context_offset(x) (offsetof (CONTEXT, x))
+static const int windows_amd64_mappings[] =
+{
+ context_offset (Rax),
+ context_offset (Rbx),
+ context_offset (Rcx),
+ context_offset (Rdx),
+ context_offset (Rsi),
+ context_offset (Rdi),
+ context_offset (Rbp),
+ context_offset (Rsp),
+ context_offset (R8),
+ context_offset (R9),
+ context_offset (R10),
+ context_offset (R11),
+ context_offset (R12),
+ context_offset (R13),
+ context_offset (R14),
+ context_offset (R15),
+ context_offset (Rip),
+ context_offset (EFlags),
+ context_offset (SegCs),
+ context_offset (SegSs),
+ context_offset (SegDs),
+ context_offset (SegEs),
+ context_offset (SegFs),
+ context_offset (SegGs),
+ context_offset (FloatSave.FloatRegisters[0]),
+ context_offset (FloatSave.FloatRegisters[1]),
+ context_offset (FloatSave.FloatRegisters[2]),
+ context_offset (FloatSave.FloatRegisters[3]),
+ context_offset (FloatSave.FloatRegisters[4]),
+ context_offset (FloatSave.FloatRegisters[5]),
+ context_offset (FloatSave.FloatRegisters[6]),
+ context_offset (FloatSave.FloatRegisters[7]),
+ 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 (Xmm0),
+ context_offset (Xmm1),
+ context_offset (Xmm2),
+ context_offset (Xmm3),
+ context_offset (Xmm4),
+ context_offset (Xmm5),
+ context_offset (Xmm6),
+ context_offset (Xmm7),
+ context_offset (Xmm8),
+ context_offset (Xmm9),
+ context_offset (Xmm10),
+ context_offset (Xmm11),
+ context_offset (Xmm12),
+ context_offset (Xmm13),
+ context_offset (Xmm14),
+ context_offset (Xmm15),
+ /* MXCSR */
+ context_offset (FloatSave.MxCsr)
+};
+#undef context_offset
+
+static void
+init_windows_x86 ()
+{
+ init_registers_amd64 ();
+ mappings = windows_amd64_mappings;
+ the_low_target.num_regs = sizeof (windows_amd64_mappings)
+ / sizeof (windows_amd64_mappings[0]);
+}
+
Index: gdbserver/windows-x86-low.c
===================================================================
RCS file: gdbserver/windows-x86-low.c
diff -N gdbserver/windows-x86-low.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdbserver/windows-x86-low.c 17 Apr 2010 22:08:36 -0000
@@ -0,0 +1,272 @@
+/* Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
+#include "server.h"
+#include "win32-low.h"
+#include "i386-low.h"
+
+static const int *mappings;
+
+#ifdef COMPILE_WIN64
+#include "win64-amd64-low.c"
+#else
+#include "win32-i386-low.c"
+#endif
+
+#define FCS_REGNUM 27
+#define FOP_REGNUM 31
+
+#define FLAG_TRACE_BIT 0x100
+
+static struct i386_debug_reg_state debug_reg_state;
+
+static int debug_registers_changed = 0;
+static int debug_registers_used = 0;
+
+/* Update the inferior's debug register REGNUM from STATE. */
+
+void
+i386_dr_low_set_addr (const struct i386_debug_reg_state *state, int regnum)
+{
+ if (! (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR))
+ fatal ("Invalid debug register %d", regnum);
+
+ /* debug_reg_state.dr_mirror is already set.
+ Just notify i386_set_thread_context, i386_thread_added
+ that the registers need to be updated. */
+ debug_registers_changed = 1;
+ debug_registers_used = 1;
+}
+
+/* Update the inferior's DR7 debug control register from STATE. */
+
+void
+i386_dr_low_set_control (const struct i386_debug_reg_state *state)
+{
+ /* debug_reg_state.dr_control_mirror is already set.
+ Just notify i386_set_thread_context, i386_thread_added
+ that the registers need to be updated. */
+ debug_registers_changed = 1;
+ debug_registers_used = 1;
+}
+
+/* Get the value of the DR6 debug status register from the inferior
+ and record it in STATE. */
+
+void
+i386_dr_low_get_status (struct i386_debug_reg_state *state)
+{
+ /* We don't need to do anything here, the last call to thread_rec for
+ current_event.dwThreadId id has already set it. */
+}
+
+/* Watchpoint support. */
+
+static int
+i386_insert_point (char type, CORE_ADDR addr, int len)
+{
+ switch (type)
+ {
+ case '2':
+ case '3':
+ case '4':
+ return i386_low_insert_watchpoint (&debug_reg_state,
+ type, addr, len);
+ default:
+ /* Unsupported. */
+ return 1;
+ }
+}
+
+static int
+i386_remove_point (char type, CORE_ADDR addr, int len)
+{
+ switch (type)
+ {
+ case '2':
+ case '3':
+ case '4':
+ return i386_low_remove_watchpoint (&debug_reg_state,
+ type, addr, len);
+ default:
+ /* Unsupported. */
+ return 1;
+ }
+}
+
+static int
+i386_stopped_by_watchpoint (void)
+{
+ return i386_low_stopped_by_watchpoint (&debug_reg_state);
+}
+
+static CORE_ADDR
+i386_stopped_data_address (void)
+{
+ CORE_ADDR addr;
+ if (i386_low_stopped_data_address (&debug_reg_state, &addr))
+ return addr;
+ return 0;
+}
+
+static void
+i386_initial_stuff (void)
+{
+ i386_low_init_dregs (&debug_reg_state);
+ debug_registers_changed = 0;
+ debug_registers_used = 0;
+}
+
+static void
+i386_get_thread_context (win32_thread_info *th, DEBUG_EVENT* current_event)
+{
+ /* Requesting the CONTEXT_EXTENDED_REGISTERS register set fails if
+ the system doesn't support extended registers. */
+ static DWORD extended_registers = CONTEXT_EXTENDED_REGISTERS;
+
+ again:
+ th->context.ContextFlags = (CONTEXT_FULL
+ | CONTEXT_FLOATING_POINT
+ | CONTEXT_DEBUG_REGISTERS
+ | extended_registers);
+
+ if (!GetThreadContext (th->h, &th->context))
+ {
+ DWORD e = GetLastError ();
+
+ if (extended_registers && e == ERROR_INVALID_PARAMETER)
+ {
+ extended_registers = 0;
+ goto again;
+ }
+
+ error ("GetThreadContext failure %ld\n", (long) e);
+ }
+
+ debug_registers_changed = 0;
+
+ if (th->tid == current_event->dwThreadId)
+ {
+ /* Copy dr values from the current thread. */
+ struct i386_debug_reg_state *dr = &debug_reg_state;
+ dr->dr_mirror[0] = th->context.Dr0;
+ dr->dr_mirror[1] = th->context.Dr1;
+ dr->dr_mirror[2] = th->context.Dr2;
+ dr->dr_mirror[3] = th->context.Dr3;
+ dr->dr_status_mirror = th->context.Dr6;
+ dr->dr_control_mirror = th->context.Dr7;
+ }
+}
+
+static void
+i386_set_thread_context (win32_thread_info *th, DEBUG_EVENT* current_event)
+{
+ if (debug_registers_changed)
+ {
+ struct i386_debug_reg_state *dr = &debug_reg_state;
+ th->context.Dr0 = dr->dr_mirror[0];
+ th->context.Dr1 = dr->dr_mirror[1];
+ th->context.Dr2 = dr->dr_mirror[2];
+ th->context.Dr3 = dr->dr_mirror[3];
+ /* th->context.Dr6 = dr->dr_status_mirror;
+ FIXME: should we set dr6 also ?? */
+ th->context.Dr7 = dr->dr_control_mirror;
+ }
+
+ SetThreadContext (th->h, &th->context);
+}
+
+static void
+i386_thread_added (win32_thread_info *th)
+{
+ /* Set the debug registers for the new thread if they are used. */
+ if (debug_registers_used)
+ {
+ struct i386_debug_reg_state *dr = &debug_reg_state;
+ th->context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
+ GetThreadContext (th->h, &th->context);
+
+ th->context.Dr0 = dr->dr_mirror[0];
+ th->context.Dr1 = dr->dr_mirror[1];
+ th->context.Dr2 = dr->dr_mirror[2];
+ th->context.Dr3 = dr->dr_mirror[3];
+ /* th->context.Dr6 = dr->dr_status_mirror;
+ FIXME: should we set dr6 also ?? */
+ th->context.Dr7 = dr->dr_control_mirror;
+
+ SetThreadContext (th->h, &th->context);
+ th->context.ContextFlags = 0;
+ }
+}
+
+static void
+i386_single_step (win32_thread_info *th)
+{
+ th->context.EFlags |= FLAG_TRACE_BIT;
+}
+
+/* Fetch register from gdbserver regcache data. */
+static void
+i386_fetch_inferior_register (struct regcache *regcache,
+ win32_thread_info *th, int r)
+{
+ char *context_offset = (char *) &th->context + mappings[r];
+
+ long l;
+ if (r == FCS_REGNUM)
+ {
+ l = *((long *) context_offset) & 0xffff;
+ supply_register (regcache, r, (char *) &l);
+ }
+ else if (r == FOP_REGNUM)
+ {
+ l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1);
+ supply_register (regcache, r, (char *) &l);
+ }
+ else
+ supply_register (regcache, r, context_offset);
+}
+
+/* Store a new register value into the thread context of TH. */
+static void
+i386_store_inferior_register (struct regcache *regcache,
+ win32_thread_info *th, int r)
+{
+ char *context_offset = (char *) &th->context + mappings[r];
+ collect_register (regcache, r, context_offset);
+}
+
+static const unsigned char i386_win32_breakpoint = 0xcc;
+#define i386_win32_breakpoint_len 1
+
+struct win32_target_ops the_low_target = {
+ init_windows_x86,
+ 0, /* Filled in init_windows_x86 function. */
+ i386_initial_stuff,
+ i386_get_thread_context,
+ i386_set_thread_context,
+ i386_thread_added,
+ i386_fetch_inferior_register,
+ i386_store_inferior_register,
+ i386_single_step,
+ &i386_win32_breakpoint,
+ i386_win32_breakpoint_len,
+ i386_insert_point,
+ i386_remove_point,
+ i386_stopped_by_watchpoint,
+ i386_stopped_data_address
+};