]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Windows gdb+gdbserver: Share $_siginfo reading code
authorPedro Alves <pedro@palves.net>
Mon, 22 May 2023 17:17:54 +0000 (18:17 +0100)
committerPedro Alves <pedro@palves.net>
Mon, 9 Jun 2025 17:09:15 +0000 (18:09 +0100)
Both GDB and GDBserver have similar code to read the $_siginfo data.
This patch moves the bulk of it to gdb/nat/windows-nat.c so it can be
shared.

Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I58f9074caf6362274453c78ed1fc9e31249f6854

gdb/nat/windows-nat.c
gdb/nat/windows-nat.h
gdb/windows-nat.c
gdbserver/win32-low.cc

index 6128b83bea4e15e041176613df8c8dfc94819b05..a548acc97d366d38295dbc4efe5ce06d95db02d5 100644 (file)
@@ -153,6 +153,55 @@ windows_thread_info::thread_name ()
   return name.get ();
 }
 
+/* Read Windows signal info.  See nat/windows-nat.h.  */
+
+bool
+windows_thread_info::xfer_siginfo (gdb_byte *readbuf,
+                                  ULONGEST offset, ULONGEST len,
+                                  ULONGEST *xfered_len)
+{
+  if (last_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT)
+    return false;
+
+  if (readbuf == nullptr)
+    return false;
+
+  EXCEPTION_RECORD &er = last_event.u.Exception.ExceptionRecord;
+
+  char *buf = (char *) &er;
+  size_t bufsize = sizeof (er);
+
+#ifdef __x86_64__
+  EXCEPTION_RECORD32 er32;
+  if (proc->wow64_process)
+    {
+      buf = (char *) &er32;
+      bufsize = sizeof (er32);
+
+      er32.ExceptionCode = er.ExceptionCode;
+      er32.ExceptionFlags = er.ExceptionFlags;
+      er32.ExceptionRecord
+       = (uintptr_t) er.ExceptionRecord;
+      er32.ExceptionAddress
+       = (uintptr_t) er.ExceptionAddress;
+      er32.NumberParameters = er.NumberParameters;
+      for (int i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++)
+       er32.ExceptionInformation[i] = er.ExceptionInformation[i];
+    }
+#endif
+
+  if (offset > bufsize)
+    return false;
+
+  if (offset + len > bufsize)
+    len = bufsize - offset;
+
+  memcpy (readbuf, buf + offset, len);
+  *xfered_len = len;
+
+  return true;
+}
+
 /* Try to determine the executable filename.
 
    EXE_NAME_RET is a pointer to a buffer whose size is EXE_NAME_MAX_LEN.
index cba8098fb391a05d9ace9f112f17581759118541..d0978f899fd372442605076e77d66c9d1c476272 100644 (file)
@@ -76,6 +76,15 @@ struct windows_thread_info
      the next call.  */
   const char *thread_name ();
 
+  /* Read LEN bytes of the thread's $_siginfo into READBUF, starting
+     at OFFSET.  Store the number of actually-read bytes in
+     XFERED_LEN.  Returns true on success, false on failure.  Passing
+     READBUF as NULL indicates that the caller is trying to write to
+     $_siginfo, which is a failure case.  */
+  bool xfer_siginfo (gdb_byte *readbuf,
+                    ULONGEST offset, ULONGEST len,
+                    ULONGEST *xfered_len);
+
   /* The process this thread belongs to.  */
   windows_process_info *const proc;
 
index 2eabf222861cac7deda0d96be3c1f0d521b1bd31..af0ef8da8d9acf4c331ce428e791e4d399c6d53a 100644 (file)
@@ -3010,44 +3010,10 @@ windows_xfer_siginfo (gdb_byte *readbuf, ULONGEST offset, ULONGEST len,
 {
   windows_thread_info *th = windows_process.find_thread (inferior_ptid);
 
-  if (th->last_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT)
-    return TARGET_XFER_E_IO;
-
-  EXCEPTION_RECORD &er = th->last_event.u.Exception.ExceptionRecord;
-
-  char *buf = (char *) &er;
-  size_t bufsize = sizeof (er);
-
-#ifdef __x86_64__
-  EXCEPTION_RECORD32 er32;
-  if (windows_process.wow64_process)
-    {
-      buf = (char *) &er32;
-      bufsize = sizeof (er32);
-
-      er32.ExceptionCode = er.ExceptionCode;
-      er32.ExceptionFlags = er.ExceptionFlags;
-      er32.ExceptionRecord = (uintptr_t) er.ExceptionRecord;
-      er32.ExceptionAddress = (uintptr_t) er.ExceptionAddress;
-      er32.NumberParameters = er.NumberParameters;
-      for (int i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++)
-       er32.ExceptionInformation[i] = er.ExceptionInformation[i];
-    }
-#endif
-
-  if (readbuf == nullptr)
-    return TARGET_XFER_E_IO;
-
-  if (offset > bufsize)
+  if (th->xfer_siginfo (readbuf, offset, len, xfered_len))
+    return TARGET_XFER_OK;
+  else
     return TARGET_XFER_E_IO;
-
-  if (offset + len > bufsize)
-    len = bufsize - offset;
-
-  memcpy (readbuf, buf + offset, len);
-  *xfered_len = len;
-
-  return TARGET_XFER_OK;
 }
 
 enum target_xfer_status
index 4e2d95bd059e6851a83b3ff84acf7baa2e4f3285..834af70678624db33a5e1f0dc35f8f07faf56e9a 100644 (file)
@@ -1285,45 +1285,11 @@ win32_process_target::qxfer_siginfo (const char *annex,
 {
   windows_thread_info *th = windows_process.find_thread (current_thread->id);
 
-  if (th->last_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT)
-    return -1;
-
-  if (readbuf == nullptr)
-    return -1;
-
-  EXCEPTION_RECORD &er = th->last_event.u.Exception.ExceptionRecord;
-
-  char *buf = (char *) &er;
-  size_t bufsize = sizeof (er);
-
-#ifdef __x86_64__
-  EXCEPTION_RECORD32 er32;
-  if (windows_process.wow64_process)
-    {
-      buf = (char *) &er32;
-      bufsize = sizeof (er32);
-
-      er32.ExceptionCode = er.ExceptionCode;
-      er32.ExceptionFlags = er.ExceptionFlags;
-      er32.ExceptionRecord
-       = (uintptr_t) er.ExceptionRecord;
-      er32.ExceptionAddress
-       = (uintptr_t) er.ExceptionAddress;
-      er32.NumberParameters = er.NumberParameters;
-      for (int i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++)
-       er32.ExceptionInformation[i] = er.ExceptionInformation[i];
-    }
-#endif
-
-  if (offset > bufsize)
+  ULONGEST xfered_len;
+  if (th->xfer_siginfo (readbuf, offset, len, &xfered_len))
+    return xfered_len;
+  else
     return -1;
-
-  if (offset + len > bufsize)
-    len = bufsize - offset;
-
-  memcpy (readbuf, buf + offset, len);
-
-  return len;
 }
 
 bool