[PATCH 20/22] [GDBserver] Multi-process + multi-arch: Windows

Pedro Alves
2013-05-30T12:16:03Z

This adjusts the Windows ports to new interfaces.

Previously cross built for i386 mingw32, and smoke tested under Wine.
(yep, GDBserver does work under Wine these days.) Rechecked that
GDBserver still builds.

2013-05-30 Pedro Alves <palves@redhat.com>

* win32-arm-low.c (tdesc_arm): Declare.
(arm_arch_setup): New function.
(the_low_target): Install arm_arch_setup instead of
init_registers_arm.
* win32-i386-low.c (tdesc_i386, tdesc_amd64): Declare.
(init_windows_x86): Rename to ...
(i386_arch_setup): ... this. Set `win32_tdesc'.
(the_low_target): Adjust.
* win32-low.c (win32_tdesc): New global.
(child_add_thread): Don't create the thread cache here.
(do_initial_child_stuff): Set the new process'es tdesc.
* win32-low.h (struct target_desc): Forward declare.
(win32_tdesc): Declare.
---
gdb/gdbserver/win32-arm-low.c | 11 +++++++++--
gdb/gdbserver/win32-i386-low.c | 8 ++++++--
gdb/gdbserver/win32-low.c | 10 ++++++----
gdb/gdbserver/win32-low.h | 6 ++++++
4 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/gdb/gdbserver/win32-arm-low.c b/gdb/gdbserver/win32-arm-low.c
index 09ac1da..0f93ef0 100644
--- a/gdb/gdbserver/win32-arm-low.c
+++ b/gdb/gdbserver/win32-arm-low.c
@@ -24,7 +24,7 @@

/* Defined in auto-generated file reg-arm.c. */
void init_registers_arm (void);
-
+extern const struct target_desc *tdesc_arm;

static void
arm_get_thread_context (win32_thread_info *th, DEBUG_EVENT* current_event)
@@ -108,12 +108,19 @@ arm_store_inferior_register (struct regcache *regcache,
collect_register (regcache, r, regptr (&th->context, r));
}

+static void
+arm_arch_setup (void)
+{
+ init_registers_arm ();
+ win32_tdesc = tdesc_arm;
+}
+
/* Correct in either endianness. We do not support Thumb yet. */
static const unsigned long arm_wince_breakpoint = 0xe6000010;
#define arm_wince_breakpoint_len 4

struct win32_target_ops the_low_target = {
- init_registers_arm,
+ arm_arch_setup,
sizeof (mappings) / sizeof (mappings[0]),
NULL, /* initial_stuff */
arm_get_thread_context,
diff --git a/gdb/gdbserver/win32-i386-low.c b/gdb/gdbserver/win32-i386-low.c
index 1db9393..049e8a2 100644
--- a/gdb/gdbserver/win32-i386-low.c
+++ b/gdb/gdbserver/win32-i386-low.c
@@ -31,9 +31,11 @@
#ifdef __x86_64__
/* Defined in auto-generated file reg-amd64.c. */
void init_registers_amd64 (void);
+extern const struct target_desc *tdesc_amd64;
#else
/* Defined in auto-generated file reg-i386.c. */
void init_registers_i386 (void);
+extern const struct target_desc *tdesc_i386;
#endif

static struct i386_debug_reg_state debug_reg_state;
@@ -399,17 +401,19 @@ static const unsigned char i386_win32_breakpoint = 0xcc;
#define i386_win32_breakpoint_len 1

static void
-init_windows_x86 (void)
+i386_arch_setup (void)
{
#ifdef __x86_64__
init_registers_amd64 ();
+ win32_tdesc = tdesc_amd64;
#else
init_registers_i386 ();
+ win32_tdesc = tdesc_i386;
#endif
}

struct win32_target_ops the_low_target = {
- init_windows_x86,
+ i386_arch_setup,
sizeof (mappings) / sizeof (mappings[0]),
i386_initial_stuff,
i386_get_thread_context,
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 2cb5465..d1caa73 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -87,6 +87,8 @@ static int soft_interrupt_requested = 0;
by suspending all the threads. */
static int faked_breakpoint = 0;

+const struct target_desc *win32_tdesc;
+
#define NUM_REGS (the_low_target.num_regs)

typedef BOOL WINAPI (*winapi_DebugActiveProcessStop) (DWORD dwProcessId);
@@ -193,9 +195,6 @@ child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb)
th->thread_local_base = (CORE_ADDR) (uintptr_t) tlb;

add_thread (ptid, th);
- set_inferior_regcache_data ((struct thread_info *)
- find_inferior_id (&all_threads, ptid),
- new_register_cache ());

if (the_low_target.thread_added != NULL)
(*the_low_target.thread_added) (th);
@@ -308,6 +307,8 @@ child_init_thread_list (void)
static void
do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
{
+ struct process_info *proc;
+
last_sig = GDB_SIGNAL_0;

current_process_handle = proch;
@@ -319,7 +320,8 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)

memset (&current_event, 0, sizeof (current_event));

- add_process (pid, attached);
+ proc = add_process (pid, attached);
+ proc->tdesc = win32_tdesc;
child_init_thread_list ();

if (the_low_target.initial_stuff != NULL)
diff --git a/gdb/gdbserver/win32-low.h b/gdb/gdbserver/win32-low.h
index 4f262c2..718362e 100644
--- a/gdb/gdbserver/win32-low.h
+++ b/gdb/gdbserver/win32-low.h
@@ -18,6 +18,12 @@

#include <windows.h>

+struct target_desc;
+
+/* The inferior's target description. This is a global because the
+ Windows ports support neither bi-arch nor multi-process. */
+extern const struct target_desc *win32_tdesc;
+
/* Thread information structure used to track extra information about
each thread. */
typedef struct win32_thread_info