public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Fix gdbserver build for x86-64 Windows
Date: Wed, 27 Apr 2022 17:23:53 +0000 (GMT)	[thread overview]
Message-ID: <20220427172353.9A763385842B@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=801eb70f9aa916650b9ca03a1d54d426a3e99f17

commit 801eb70f9aa916650b9ca03a1d54d426a3e99f17
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed Apr 27 10:14:01 2022 -0600

    Fix gdbserver build for x86-64 Windows
    
    I broke the gdbserver build on x86-64 Windows a little while back.
    Previously, I could not build this configuration, but today I found
    out that if I configure with:
    
        --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32
    
    using the Fedora 34 tools, it will in fact build.  I'm not certain,
    but maybe the gnulib update helped with this.
    
    This patch fixes the build.  I'm checking it in.

Diff:
---
 gdbserver/win32-i386-low.cc | 20 ++++++++++----------
 gdbserver/win32-low.cc      | 41 +++++++++++++++++++++++------------------
 gdbserver/win32-low.h       |  3 +++
 3 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/gdbserver/win32-i386-low.cc b/gdbserver/win32-i386-low.cc
index 2b18c2cb1a3..856040801e8 100644
--- a/gdbserver/win32-i386-low.cc
+++ b/gdbserver/win32-i386-low.cc
@@ -85,7 +85,7 @@ win32_get_current_dr (int dr)
   case DR:					\
     return th->wow64_context.Dr ## DR
 
-  if (wow64_process)
+  if (windows_process.wow64_process)
     {
       switch (dr)
 	{
@@ -245,7 +245,7 @@ i386_get_thread_context (windows_thread_info *th)
 
  again:
 #ifdef __x86_64__
-  if (wow64_process)
+  if (windows_process.wow64_process)
     th->wow64_context.ContextFlags = (CONTEXT_FULL
 				      | CONTEXT_FLOATING_POINT
 				      | CONTEXT_DEBUG_REGISTERS
@@ -259,7 +259,7 @@ i386_get_thread_context (windows_thread_info *th)
 
   BOOL ret;
 #ifdef __x86_64__
-  if (wow64_process)
+  if (windows_process.wow64_process)
     ret = Wow64GetThreadContext (th->h, &th->wow64_context);
   else
 #endif
@@ -288,7 +288,7 @@ i386_prepare_to_resume (windows_thread_info *th)
       win32_require_context (th);
 
 #ifdef __x86_64__
-      if (wow64_process)
+      if (windows_process.wow64_process)
 	{
 	  th->wow64_context.Dr0 = dr->dr_mirror[0];
 	  th->wow64_context.Dr1 = dr->dr_mirror[1];
@@ -324,7 +324,7 @@ static void
 i386_single_step (windows_thread_info *th)
 {
 #ifdef __x86_64__
-  if (wow64_process)
+  if (windows_process.wow64_process)
     th->wow64_context.EFlags |= FLAG_TRACE_BIT;
   else
 #endif
@@ -466,7 +466,7 @@ i386_fetch_inferior_register (struct regcache *regcache,
 {
   const int *mappings;
 #ifdef __x86_64__
-  if (!wow64_process)
+  if (!windows_process.wow64_process)
     mappings = amd64_mappings;
   else
 #endif
@@ -474,7 +474,7 @@ i386_fetch_inferior_register (struct regcache *regcache,
 
   char *context_offset;
 #ifdef __x86_64__
-  if (wow64_process)
+  if (windows_process.wow64_process)
     context_offset = (char *) &th->wow64_context + mappings[r];
   else
 #endif
@@ -502,7 +502,7 @@ i386_store_inferior_register (struct regcache *regcache,
 {
   const int *mappings;
 #ifdef __x86_64__
-  if (!wow64_process)
+  if (!windows_process.wow64_process)
     mappings = amd64_mappings;
   else
 #endif
@@ -510,7 +510,7 @@ i386_store_inferior_register (struct regcache *regcache,
 
   char *context_offset;
 #ifdef __x86_64__
-  if (wow64_process)
+  if (windows_process.wow64_process)
     context_offset = (char *) &th->wow64_context + mappings[r];
   else
 #endif
@@ -550,7 +550,7 @@ i386_win32_num_regs (void)
 {
   int num_regs;
 #ifdef __x86_64__
-  if (!wow64_process)
+  if (!windows_process.wow64_process)
     num_regs = sizeof (amd64_mappings) / sizeof (amd64_mappings[0]);
   else
 #endif
diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index afeed1a9881..192ea465e69 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -38,7 +38,8 @@
 
 using namespace windows_nat;
 
-static windows_process_info windows_process;
+/* See win32-low.h.  */
+windows_process_info windows_process;
 
 #ifndef USE_WIN32API
 #include <sys/cygwin.h>
@@ -113,7 +114,7 @@ static void
 win32_get_thread_context (windows_thread_info *th)
 {
 #ifdef __x86_64__
-  if (wow64_process)
+  if (windows_process.wow64_process)
     memset (&th->wow64_context, 0, sizeof (WOW64_CONTEXT));
   else
 #endif
@@ -127,7 +128,7 @@ static void
 win32_set_thread_context (windows_thread_info *th)
 {
 #ifdef __x86_64__
-  if (wow64_process)
+  if (windows_process.wow64_process)
     Wow64SetThreadContext (th->h, &th->wow64_context);
   else
 #endif
@@ -150,7 +151,7 @@ win32_require_context (windows_thread_info *th)
 {
   DWORD context_flags;
 #ifdef __x86_64__
-  if (wow64_process)
+  if (windows_process.wow64_process)
     context_flags = th->wow64_context.ContextFlags;
   else
 #endif
@@ -192,7 +193,7 @@ child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb)
 #ifdef __x86_64__
   /* For WOW64 processes, this is actually the pointer to the 64bit TIB,
      and the 32bit TIB is exactly 2 pages after it.  */
-  if (wow64_process)
+  if (windows_process.wow64_process)
     base += 2 * 4096; /* page size = 4096 */
 #endif
   th = new windows_thread_info (tid, h, base);
@@ -354,19 +355,20 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
       error ("Check if WOW64 process failed (error %d): %s\n",
 	     (int) err, strwinerror (err));
     }
-  wow64_process = wow64;
+  windows_process.wow64_process = wow64;
 
-  if (wow64_process
+  if (windows_process.wow64_process
       && (Wow64GetThreadContext == nullptr
 	  || Wow64SetThreadContext == nullptr))
     error ("WOW64 debugging is not supported on this system.\n");
 
-  ignore_first_breakpoint = !attached && wow64_process;
+  windows_process.ignore_first_breakpoint
+    = !attached && windows_process.wow64_process;
 #endif
 
   proc = add_process (pid, attached);
 #ifdef __x86_64__
-  if (wow64_process)
+  if (windows_process.wow64_process)
     proc->tdesc = wow64_win32_tdesc;
   else
 #endif
@@ -440,7 +442,7 @@ continue_one_thread (thread_info *thread, int thread_id)
 	{
 	  DWORD *context_flags;
 #ifdef __x86_64__
-	  if (wow64_process)
+	  if (windows_process.wow64_process)
 	    context_flags = &th->wow64_context.ContextFlags;
 	  else
 #endif
@@ -913,7 +915,7 @@ win32_process_target::resume (thread_resume *resume_info, size_t n)
 
       DWORD *context_flags;
 #ifdef __x86_64__
-      if (wow64_process)
+      if (windows_process.wow64_process)
 	context_flags = &th->wow64_context.ContextFlags;
       else
 #endif
@@ -1419,19 +1421,22 @@ win32_process_target::qxfer_siginfo (const char *annex,
 
 #ifdef __x86_64__
   EXCEPTION_RECORD32 er32;
-  if (wow64_process)
+  if (windows_process.wow64_process)
     {
       buf = (char *) &er32;
       bufsize = sizeof (er32);
 
-      er32.ExceptionCode = siginfo_er.ExceptionCode;
-      er32.ExceptionFlags = siginfo_er.ExceptionFlags;
-      er32.ExceptionRecord = (uintptr_t) siginfo_er.ExceptionRecord;
-      er32.ExceptionAddress = (uintptr_t) siginfo_er.ExceptionAddress;
-      er32.NumberParameters = siginfo_er.NumberParameters;
+      er32.ExceptionCode = windows_process.siginfo_er.ExceptionCode;
+      er32.ExceptionFlags = windows_process.siginfo_er.ExceptionFlags;
+      er32.ExceptionRecord
+	= (uintptr_t) windows_process.siginfo_er.ExceptionRecord;
+      er32.ExceptionAddress
+	= (uintptr_t) windows_process.siginfo_er.ExceptionAddress;
+      er32.NumberParameters = windows_process.siginfo_er.NumberParameters;
       int i;
       for (i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++)
-	er32.ExceptionInformation[i] = siginfo_er.ExceptionInformation[i];
+	er32.ExceptionInformation[i]
+	  = windows_process.siginfo_er.ExceptionInformation[i];
     }
 #endif
 
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index a1d74573cc9..c5f40dd8d0a 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -162,6 +162,9 @@ public:
   const char *thread_name (ptid_t thread) override;
 };
 
+/* The sole Windows process.  */
+extern windows_nat::windows_process_info windows_process;
+
 /* Retrieve the context for this thread, if not already retrieved.  */
 extern void win32_require_context (windows_nat::windows_thread_info *th);


                 reply	other threads:[~2022-04-27 17:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220427172353.9A763385842B@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).