Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/4] AMD GPU debugging support on Windows
@ 2026-05-08 17:53 Pedro Alves
  2026-05-08 17:53 ` [PATCH 1/4] gdb/amd-dbgapi-target: Move Linux code to amd-dbagapi-posix-hdep.c Pedro Alves
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Pedro Alves @ 2026-05-08 17:53 UTC (permalink / raw)
  To: gdb-patches

To support AMD GPU debugging on Windows, we need the following pieces:

 [x] Windows non-stop support

    Merged last week.  This is needed because the amd-dbgapi-target
    target requires working in coordination with a CPU/process_stratum
    target backend that always works in non-stop mode.

 [ ] Multiple solib providers at once

    This is needed because the way we hack into solib-svr4 for the GPU
    code loader does not work on Windows, as Windows uses
    solib-target.

    This is Simon's series at
    https://inbox.sourceware.org/gdb-patches/5b5fc6b8-a0b4-4346-88e1-4974a9eed31c@polymtl.ca/T/

 [ ] Windows tweaks for amd-dbgapi-target

    This is this series.  With this, you'll be able to build a GDB
    that links against a Windows build of the AMD Debug API library,
    and activate the amd-dbgapi-target target.

Technically, we also need support for gfx1200/gfx1201 in bfd as those
are the GPUs currently supported by the Windows GPU driver for
debugging, but I consider that a separate detail.  Bfd support for
those architectures is pending at
https://inbox.sourceware.org/binutils/20251031175411.1303161-1-luis.machado@amd.com/

I'm proposing adding a NEWS entry already, as I expect Simon's series
will land soon enough, and really the upstream support for AMD GPU
debugging is very limited, just like the Linux support is, so it won't
make much of a difference in practice either way.  This will get
better when DWARF 6 is further ahead and we're able to upstream the
location-on-the-stack changes, address spaces support, and more, that
come with it, which will unlock upstreaming a lot more downstream
ROCgdb code and enable full AMD GPU debugging support directly
upstream (on both Linux and Windows).

Lancelot SIX (3):
  gdb/amd-dbgapi-target: Move Linux code to amd-dbagapi-posix-hdep.c
  gdb/amd-dbgapi-target: Add amd-dbgapi-mingw-hdep.c for Windows
  gdb/amd-dbgapi-target: Update xfer_partial to always use dbgapi

Pedro Alves (1):
  gdb/NEWS: Add note about AMD GPU debugging on Windows

 gdb/Makefile.in             |   3 +
 gdb/NEWS                    |   5 ++
 gdb/amd-dbgapi-hdep.h       |  38 ++++++++
 gdb/amd-dbgapi-mingw-hdep.c | 172 ++++++++++++++++++++++++++++++++++++
 gdb/amd-dbgapi-posix-hdep.c |  55 ++++++++++++
 gdb/amd-dbgapi-target.c     |  76 +++++++++++-----
 gdb/configure               |  13 +++
 gdb/configure.ac            |  13 +++
 8 files changed, 351 insertions(+), 24 deletions(-)
 create mode 100644 gdb/amd-dbgapi-hdep.h
 create mode 100644 gdb/amd-dbgapi-mingw-hdep.c
 create mode 100644 gdb/amd-dbgapi-posix-hdep.c


base-commit: 7a15a5f571da8772765bfb17d1049a097205035e
-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] gdb/amd-dbgapi-target: Move Linux code to amd-dbagapi-posix-hdep.c
  2026-05-08 17:53 [PATCH 0/4] AMD GPU debugging support on Windows Pedro Alves
@ 2026-05-08 17:53 ` Pedro Alves
  2026-05-08 17:53 ` [PATCH 2/4] gdb/amd-dbgapi-target: Add amd-dbgapi-mingw-hdep.c for Windows Pedro Alves
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2026-05-08 17:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves

From: Lancelot SIX <lancelot.six@amd.com>

The current amd-dbgapi-target.c file contains some code that is Linux
specific.  This patch extracts such code to host dependent files, so
they can be replaced for other host platforms.

The code in question is related to the event loop.  The way dbgapi
notifies GDB that there is a pending event is platform specific.  For
Linux (the only platform supported so far), this is done using a file
descriptor GDB can use in its main event loop.

This patch introduces an overall host-dependency infrastructure and
moves the Linux-specific code to amd-dbgapi-posix-hdep.c.  The "posix"
naming is because even though only Linux is supported, the code is
really plain POSIX code that would work on other POSIX platforms.
This also follows the existing posix-hdep.c nomenclature.

Co-Authored-By: Pedro Alves <pedro@palves.net>
---
This is mostly Lancelot's work.  I mainly mixed and matched code that
was originally in different patches, and polished it a bit.

Change-Id: Id3d4b947176e5cfe91b0ab64376fca1a6a8c6fc9
commit-id: c203c87c
---
 gdb/Makefile.in             |  2 ++
 gdb/amd-dbgapi-hdep.h       | 34 ++++++++++++++++++++++++++
 gdb/amd-dbgapi-posix-hdep.c | 48 +++++++++++++++++++++++++++++++++++++
 gdb/amd-dbgapi-target.c     | 32 +++++++++++--------------
 gdb/configure               | 10 ++++++++
 gdb/configure.ac            | 10 ++++++++
 6 files changed, 118 insertions(+), 18 deletions(-)
 create mode 100644 gdb/amd-dbgapi-hdep.h
 create mode 100644 gdb/amd-dbgapi-posix-hdep.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index e38ba95eebd..97defd80ab1 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1289,6 +1289,7 @@ HFILES_NO_SRCDIR = \
 	amd64-nat.h \
 	amd64-ravenscar-thread.h \
 	amd64-tdep.h \
+	amd-dbgapi-hdep.h \
 	amd-dbgapi-target.h \
 	amdgpu-tdep.h \
 	annotate.h \
@@ -1795,6 +1796,7 @@ ALLDEPFILES = \
 	alpha-netbsd-tdep.c \
 	alpha-obsd-tdep.c \
 	alpha-tdep.c \
+	amd-dbgapi-posix-hdep.c \
 	amd-dbgapi-target.c \
 	amd64-bsd-nat.c \
 	amd64-darwin-tdep.c \
diff --git a/gdb/amd-dbgapi-hdep.h b/gdb/amd-dbgapi-hdep.h
new file mode 100644
index 00000000000..5d6fccb980c
--- /dev/null
+++ b/gdb/amd-dbgapi-hdep.h
@@ -0,0 +1,34 @@
+/* Host dependent utilities used by the amd-dbgapi target.
+
+   Copyright (C) 2024-2026 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/>.  */
+
+#ifndef GDB_AMD_DBGAPI_HDEP_H
+#define GDB_AMD_DBGAPI_HDEP_H
+
+#include <amd-dbgapi/amd-dbgapi.h>
+
+/* Null amd_dbgapi_notifier_t.  */
+extern const amd_dbgapi_notifier_t null_amd_dbgapi_notifier;
+
+/* Clear the notifier.  */
+extern void amd_dbgapi_notifier_clear (amd_dbgapi_notifier_t notifier);
+
+/* Get the file descriptor associated with the notifier.  */
+extern int amd_dbgapi_notifier_get_fd (amd_dbgapi_notifier_t notifier);
+
+#endif /* GDB_AMD_DBGAPI_HDEP_H */
diff --git a/gdb/amd-dbgapi-posix-hdep.c b/gdb/amd-dbgapi-posix-hdep.c
new file mode 100644
index 00000000000..b8f6b44987f
--- /dev/null
+++ b/gdb/amd-dbgapi-posix-hdep.c
@@ -0,0 +1,48 @@
+/* Host dependent utilities for the amd-dbgapi target on POSIX.
+
+   Copyright (C) 2019-2026 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 "amd-dbgapi-hdep.h"
+#include <amd-dbgapi/amd-dbgapi.h>
+
+/* See amd-dbgapi-hdep.h.  */
+const amd_dbgapi_notifier_t null_amd_dbgapi_notifier = -1;
+
+/* See amd-dbgapi-hdep.h.  */
+
+void
+amd_dbgapi_notifier_clear (amd_dbgapi_notifier_t notifier)
+{
+  int ret;
+
+  /* Drain the notifier pipe.  */
+  do
+    {
+      char buf;
+      ret = read (notifier, &buf, 1);
+    }
+  while (ret >= 0 || (ret == -1 && errno == EINTR));
+}
+
+/* See amd-dbgapi-hdep.h.  */
+
+int
+amd_dbgapi_notifier_get_fd (amd_dbgapi_notifier_t notifier)
+{
+  return notifier;
+}
diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c
index 811e22182c6..5bf1f4480b1 100644
--- a/gdb/amd-dbgapi-target.c
+++ b/gdb/amd-dbgapi-target.c
@@ -19,6 +19,7 @@
 
 
 #include "amd-dbgapi-target.h"
+#include "amd-dbgapi-hdep.h"
 #include "amdgpu-tdep.h"
 #include "async-event.h"
 #include "breakpoint.h"
@@ -203,7 +204,7 @@ struct amd_dbgapi_inferior_info
   amd_dbgapi_process_id_t process_id = AMD_DBGAPI_PROCESS_NONE;
 
   /* The amd_dbgapi_notifier_t for this inferior.  */
-  amd_dbgapi_notifier_t notifier = -1;
+  amd_dbgapi_notifier_t notifier = null_amd_dbgapi_notifier;
 
   /* The status of the inferior's runtime support.  */
   amd_dbgapi_runtime_state_t runtime_state = AMD_DBGAPI_RUNTIME_STATE_UNLOADED;
@@ -1203,15 +1204,8 @@ dbgapi_notifier_handler (int err, gdb_client_data client_data)
 {
   amd_dbgapi_inferior_info &info
     = *static_cast<amd_dbgapi_inferior_info *> (client_data);
-  int ret;
 
-  /* Drain the notifier pipe.  */
-  do
-    {
-      char buf;
-      ret = read (info.notifier, &buf, 1);
-    }
-  while (ret >= 0 || (ret == -1 && errno == EINTR));
+  amd_dbgapi_notifier_clear (info.notifier);
 
   if (info.inf->target_is_pushed (&the_amd_dbgapi_target))
     {
@@ -1313,8 +1307,9 @@ amd_dbgapi_target::async (bool enable)
 	{
 	  amd_dbgapi_inferior_info &info = get_amd_dbgapi_inferior_info (inf);
 
-	  if (info.notifier != -1)
-	    add_file_handler (info.notifier, dbgapi_notifier_handler, &info,
+	  if (info.notifier != null_amd_dbgapi_notifier)
+	    add_file_handler (amd_dbgapi_notifier_get_fd (info.notifier),
+			      dbgapi_notifier_handler, &info,
 			      string_printf ("amd-dbgapi notifier for pid %d",
 					     inf->pid));
 	}
@@ -1337,8 +1332,8 @@ amd_dbgapi_target::async (bool enable)
 	  const amd_dbgapi_inferior_info &info
 	    = get_amd_dbgapi_inferior_info (inf);
 
-	  if (info.notifier != -1)
-	    delete_file_handler (info.notifier);
+	  if (info.notifier != null_amd_dbgapi_notifier)
+	    delete_file_handler (amd_dbgapi_notifier_get_fd (info.notifier));
 	}
 
       delete_async_event_handler (&amd_dbgapi_async_event_handler);
@@ -1877,7 +1872,8 @@ attach_amd_dbgapi (inferior *inf)
     }
 
   amd_dbgapi_debug_printf ("process_id = %" PRIu64 ", notifier fd = %d",
-			   info.process_id.handle, info.notifier);
+			   info.process_id.handle,
+			   amd_dbgapi_notifier_get_fd (info.notifier));
 
   set_process_memory_precision (info);
 
@@ -1886,8 +1882,8 @@ attach_amd_dbgapi (inferior *inf)
      target.  */
   dbgapi_notifier_handler (0, &info);
 
-  add_file_handler (info.notifier, dbgapi_notifier_handler, &info,
-		    "amd-dbgapi notifier");
+  add_file_handler (amd_dbgapi_notifier_get_fd (info.notifier),
+		    dbgapi_notifier_handler, &info, "amd-dbgapi notifier");
 }
 
 static void maybe_reset_amd_dbgapi ();
@@ -1915,8 +1911,8 @@ detach_amd_dbgapi (inferior *inf)
     warning (_("amd-dbgapi: could not detach from process %d (%s)"),
 	     inf->pid, get_status_string (status));
 
-  gdb_assert (info.notifier != -1);
-  delete_file_handler (info.notifier);
+  gdb_assert (info.notifier != null_amd_dbgapi_notifier);
+  delete_file_handler (amd_dbgapi_notifier_get_fd (info.notifier));
 
   /* This is a noop if the target is not pushed.  */
   inf->unpush_target (&the_amd_dbgapi_target);
diff --git a/gdb/configure b/gdb/configure
index 2fc0b583702..c69c5acceea 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -25454,6 +25454,16 @@ $as_echo "#define HAVE_AMD_DBGAPI 1" >>confdefs.h
     if test "$all_targets" = true; then
       TARGET_OBS="$TARGET_OBS \$(ALL_AMD_DBGAPI_TARGET_OBS)"
     fi
+
+    # Add the host-specific objects.
+    case ${gdb_host} in
+      *linux*)
+	gdb_host_obs="${gdb_host_obs} amd-dbgapi-posix-hdep.o"
+	;;
+      *)
+	as_fn_error $? "amd-dbgapi not supported for host ${gdb_host}" "$LINENO" 5
+	;;
+    esac
   elif test "$gdb_require_amd_dbgapi" = true -o "$with_amd_dbgapi" = yes; then
     # amd-dbgapi was not found and...
     #
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 56ab86d9356..c2bda261fd7 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -341,6 +341,16 @@ if test "$gdb_require_amd_dbgapi" = true \
     if test "$all_targets" = true; then
       TARGET_OBS="$TARGET_OBS \$(ALL_AMD_DBGAPI_TARGET_OBS)"
     fi
+
+    # Add the host-specific objects.
+    case ${gdb_host} in
+      *linux*)
+	gdb_host_obs="${gdb_host_obs} amd-dbgapi-posix-hdep.o"
+	;;
+      *)
+	AC_MSG_ERROR([amd-dbgapi not supported for host ${gdb_host}])
+	;;
+    esac
   elif test "$gdb_require_amd_dbgapi" = true -o "$with_amd_dbgapi" = yes; then
     # amd-dbgapi was not found and...
     #
-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/4] gdb/amd-dbgapi-target: Add amd-dbgapi-mingw-hdep.c for Windows
  2026-05-08 17:53 [PATCH 0/4] AMD GPU debugging support on Windows Pedro Alves
  2026-05-08 17:53 ` [PATCH 1/4] gdb/amd-dbgapi-target: Move Linux code to amd-dbagapi-posix-hdep.c Pedro Alves
@ 2026-05-08 17:53 ` Pedro Alves
  2026-05-08 17:53 ` [PATCH 3/4] gdb/amd-dbgapi-target: Update xfer_partial to always use dbgapi Pedro Alves
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2026-05-08 17:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves

From: Lancelot SIX <lancelot.six@amd.com>

This patch adds amd-dbgapi-mingw-hdep.c which provides the
implementations for all the host specific interactions with dbgapi on
MinGW.

Co-Authored-By: Pedro Alves <pedro@palves.net>
---
Again, my contribution here is just polish.

Change-Id: Ie244f2606b1e0af8f85b9113c3d93585eda893ed
commit-id: 372ceffc
---
 gdb/Makefile.in             |   1 +
 gdb/amd-dbgapi-hdep.h       |   4 +
 gdb/amd-dbgapi-mingw-hdep.c | 172 ++++++++++++++++++++++++++++++++++++
 gdb/amd-dbgapi-posix-hdep.c |   7 ++
 gdb/amd-dbgapi-target.c     |   1 +
 gdb/configure               |   3 +
 gdb/configure.ac            |   3 +
 7 files changed, 191 insertions(+)
 create mode 100644 gdb/amd-dbgapi-mingw-hdep.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 97defd80ab1..12189660ea9 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1796,6 +1796,7 @@ ALLDEPFILES = \
 	alpha-netbsd-tdep.c \
 	alpha-obsd-tdep.c \
 	alpha-tdep.c \
+	amd-dbgapi-mingw-hdep.c \
 	amd-dbgapi-posix-hdep.c \
 	amd-dbgapi-target.c \
 	amd64-bsd-nat.c \
diff --git a/gdb/amd-dbgapi-hdep.h b/gdb/amd-dbgapi-hdep.h
index 5d6fccb980c..795f94c81a6 100644
--- a/gdb/amd-dbgapi-hdep.h
+++ b/gdb/amd-dbgapi-hdep.h
@@ -31,4 +31,8 @@ extern void amd_dbgapi_notifier_clear (amd_dbgapi_notifier_t notifier);
 /* Get the file descriptor associated with the notifier.  */
 extern int amd_dbgapi_notifier_get_fd (amd_dbgapi_notifier_t notifier);
 
+/* Ensure that we do not keep a reference to NOTIFIER, which is about
+   to get invalidated.  */
+extern void amd_dbgapi_notifier_release (amd_dbgapi_notifier_t notifier);
+
 #endif /* GDB_AMD_DBGAPI_HDEP_H */
diff --git a/gdb/amd-dbgapi-mingw-hdep.c b/gdb/amd-dbgapi-mingw-hdep.c
new file mode 100644
index 00000000000..14cc614961a
--- /dev/null
+++ b/gdb/amd-dbgapi-mingw-hdep.c
@@ -0,0 +1,172 @@
+/* Host dependent utilities for the amd-dbgapi target on MinGW.
+
+   Copyright (C) 2024-2026 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 "amd-dbgapi-hdep.h"
+#include <amd-dbgapi/amd-dbgapi.h>
+
+#include <winsock2.h>
+#include <windows.h>
+#include <io.h>
+#include <cstdio>
+#include <unordered_map>
+#include <algorithm>
+
+#include "serial.h"
+
+/* See amd-dbgapi-hdep.h.  */
+const amd_dbgapi_notifier_t null_amd_dbgapi_notifier = nullptr;
+
+/* Use a custom implementation of serial for events from dbgapi.  This is
+   really similar to what is implemented in ser-event.c, except that here:
+   - The underlying event object is not managed by us, but by dbgapi
+     instead.
+   - We keep a handy mapping from event object handles to serial
+     events for lookup.
+*/
+
+struct amd_dbgapi_serial_event_state
+{
+  /* The Windows event handle, provided by dbgapi.  */
+  HANDLE event;
+};
+
+/* Mapping from event object handles to serial events for lookup.  */
+static std::unordered_map<HANDLE, serial *> serial_event_cache;
+
+/* serial_ops::open implementation for the amd-dbgapi serial
+   event.  */
+
+static void
+amd_dbgapi_serial_event_state_open (struct serial *scb,
+				    const char *name)
+{
+  auto *state = new amd_dbgapi_serial_event_state;
+  scb->state = state;
+
+  HANDLE dummy_file = CreateFile ("nul", 0, 0, nullptr, OPEN_EXISTING, 0,
+				  nullptr);
+  scb->fd = _open_osfhandle ((intptr_t) dummy_file, 0);
+};
+
+/* serial_ops::close implementation for the amd-dbgapi serial
+   event.  */
+
+static void
+amd_dbgapi_serial_event_state_close (struct serial *scb)
+{
+  scb->fd = -1;
+  delete (amd_dbgapi_serial_event_state *) scb->state;
+  scb->state = nullptr;
+}
+
+/* serial_ops::wait_handle implementation for the amd-dbgapi serial
+   event.  */
+
+static void
+amd_dbgapi_serial_event_state_wait_handle (struct serial *scb,
+					   HANDLE *read,
+					   HANDLE *except)
+{
+  auto *state = (amd_dbgapi_serial_event_state *) scb->state;
+  *read = state->event;
+}
+
+static const struct serial_ops amd_dbgapi_serial_event_ops =
+{
+  "amd-dbgapi-event",
+  amd_dbgapi_serial_event_state_open,
+  amd_dbgapi_serial_event_state_close,
+  nullptr, /* fdopen */
+  nullptr, /* readchar */
+  nullptr, /* write */
+  nullptr, /* flush_output */
+  nullptr, /* flush_input */
+  nullptr, /* send_break */
+  nullptr, /* go_raw */
+  nullptr, /* get_tty_state */
+  nullptr, /* copy_tty_state */
+  nullptr, /* set_tty_state */
+  nullptr, /* print_tty_state */
+  nullptr, /* setbaudrate */
+  nullptr, /* setstopbits */
+  nullptr, /* setparity */
+  nullptr, /* drain_output */
+  nullptr, /* async */
+  nullptr, /* read_prim */
+  nullptr, /* write_prim */
+  nullptr, /* avail */
+  amd_dbgapi_serial_event_state_wait_handle,
+  nullptr, /* done_wait_handle */
+};
+
+/* Return the serial object associated with EVENT_HANDLE, creating it
+   if necessary.  */
+
+static serial *
+get_serial_event (HANDLE event_handle)
+{
+  auto it = serial_event_cache.find (event_handle);
+
+  /* If we already have a FD for this event, return it.  */
+  if (it != serial_event_cache.end ())
+    return it->second;
+
+  serial *scb = serial_open_ops (&amd_dbgapi_serial_event_ops);
+
+  /* Set the underlying Windows event object.  */
+  auto *state = (amd_dbgapi_serial_event_state *) scb->state;
+  state->event = event_handle;
+  serial_event_cache.insert ({event_handle, scb});
+
+  /* Keep one reference for the cache.  This will be released by
+     amd_dbgapi_notifier_release.  */
+  serial_ref (scb);
+
+  return scb;
+}
+
+/* See amd-dbgapi-hdep.h.  */
+
+void
+amd_dbgapi_notifier_clear (amd_dbgapi_notifier_t notifier)
+{
+  ResetEvent (notifier);
+}
+
+/* See amd-dbgapi-hdep.h.  */
+
+int
+amd_dbgapi_notifier_get_fd (amd_dbgapi_notifier_t notifier)
+{
+  return get_serial_event (notifier)->fd;
+}
+
+/* See amd-dbgapi-hdep.h.  */
+
+void
+amd_dbgapi_notifier_release (amd_dbgapi_notifier_t notifier)
+{
+  /* Remove the serial from the cache.  */
+  auto it = serial_event_cache.find (notifier);
+  if (it != serial_event_cache.end ())
+    {
+      serial_event_cache.erase (it);
+      serial_unref (get_serial_event (notifier));
+    }
+}
diff --git a/gdb/amd-dbgapi-posix-hdep.c b/gdb/amd-dbgapi-posix-hdep.c
index b8f6b44987f..3a818ae3fc1 100644
--- a/gdb/amd-dbgapi-posix-hdep.c
+++ b/gdb/amd-dbgapi-posix-hdep.c
@@ -46,3 +46,10 @@ amd_dbgapi_notifier_get_fd (amd_dbgapi_notifier_t notifier)
 {
   return notifier;
 }
+
+/* See amd-dbgapi-hdep.h.  */
+void
+amd_dbgapi_notifier_release (amd_dbgapi_notifier_t notifier)
+{
+  /* Nothing to do.  */
+}
diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c
index 5bf1f4480b1..60013301c10 100644
--- a/gdb/amd-dbgapi-target.c
+++ b/gdb/amd-dbgapi-target.c
@@ -1913,6 +1913,7 @@ detach_amd_dbgapi (inferior *inf)
 
   gdb_assert (info.notifier != null_amd_dbgapi_notifier);
   delete_file_handler (amd_dbgapi_notifier_get_fd (info.notifier));
+  amd_dbgapi_notifier_release (info.notifier);
 
   /* This is a noop if the target is not pushed.  */
   inf->unpush_target (&the_amd_dbgapi_target);
diff --git a/gdb/configure b/gdb/configure
index c69c5acceea..12d14cca95f 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -25460,6 +25460,9 @@ $as_echo "#define HAVE_AMD_DBGAPI 1" >>confdefs.h
       *linux*)
 	gdb_host_obs="${gdb_host_obs} amd-dbgapi-posix-hdep.o"
 	;;
+      *mingw*)
+	gdb_host_obs="${gdb_host_obs} amd-dbgapi-mingw-hdep.o"
+	;;
       *)
 	as_fn_error $? "amd-dbgapi not supported for host ${gdb_host}" "$LINENO" 5
 	;;
diff --git a/gdb/configure.ac b/gdb/configure.ac
index c2bda261fd7..6430500e95f 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -347,6 +347,9 @@ if test "$gdb_require_amd_dbgapi" = true \
       *linux*)
 	gdb_host_obs="${gdb_host_obs} amd-dbgapi-posix-hdep.o"
 	;;
+      *mingw*)
+	gdb_host_obs="${gdb_host_obs} amd-dbgapi-mingw-hdep.o"
+	;;
       *)
 	AC_MSG_ERROR([amd-dbgapi not supported for host ${gdb_host}])
 	;;
-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/4] gdb/amd-dbgapi-target: Update xfer_partial to always use dbgapi
  2026-05-08 17:53 [PATCH 0/4] AMD GPU debugging support on Windows Pedro Alves
  2026-05-08 17:53 ` [PATCH 1/4] gdb/amd-dbgapi-target: Move Linux code to amd-dbagapi-posix-hdep.c Pedro Alves
  2026-05-08 17:53 ` [PATCH 2/4] gdb/amd-dbgapi-target: Add amd-dbgapi-mingw-hdep.c for Windows Pedro Alves
@ 2026-05-08 17:53 ` Pedro Alves
  2026-05-08 17:53 ` [PATCH 4/4] gdb/NEWS: Add note about AMD GPU debugging on Windows Pedro Alves
  2026-06-12 13:39 ` [PATCH 0/4] AMD GPU debugging support " Pedro Alves
  4 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2026-05-08 17:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves

From: Lancelot SIX <lancelot.six@amd.com>

On the Windows platform, the entire "global" address space is not
mapped in the inferior memory.  For such configuration, part of the
global address space lives in GPU memory, and can only be accessed via
rocm-dbgapi.

This patch updates amd_dbgapi_target::xfer_partial so it always calls
into amd-dbgapi to access the global address space.  GDB will still be
called to access host memory using xfer_global_memory callback.

To be sure that the callback request is not routed back to dbgapi, the
xfer_global_memory callback is modified to route the request to
whichever target sits below the amd-dbgapi target on the target stack.

Co-Authored-By: Pedro Alves <pedro@palves.net>
---
This is mostly Lancelot's work.  I mainly tweaked the comments a bit
for clarity, and added a new comment to
amd_dbgapi_xfer_global_memory_callback, based on info from the commit
log.

Change-Id: I2d5ca46edf65e2dec3606d18f7ad1d22d0275a63
commit-id: 2e4a1e78
---
 gdb/amd-dbgapi-target.c | 43 +++++++++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c
index 60013301c10..caa3b32b9d6 100644
--- a/gdb/amd-dbgapi-target.c
+++ b/gdb/amd-dbgapi-target.c
@@ -695,9 +695,31 @@ amd_dbgapi_target::xfer_partial (enum target_object object, const char *annex,
 {
   std::optional<scoped_restore_current_thread> maybe_restore_thread;
 
-  if (!ptid_is_gpu (inferior_ptid))
-    return beneath ()->xfer_partial (object, annex, readbuf, writebuf, offset,
-				     requested_len, xfered_len);
+  /* We want to handle most of the memory requests using amd_dbgapi.
+     This is because on Windows, memory allocated on the GPUs cannot
+     be accessed using the Win32 ReadProcessMemory/WriteProcessMemory
+     calls, in the Windows native target (windows_nat_target).  Even
+     if the current thread is a host thread, we might still need to
+     access some memory on the GPU, for example to access code objects
+     loaded on the device to place breakpoints.
+
+     For everything that is available on the host address space,
+     amd_dbgapi uses the amd_dbgapi_xfer_global_memory_callback
+     callback to do the xfer operation, which calls into whatever is
+     beneath us on the target stack.
+
+     There is one case where we do not want to use dbgapi to perform
+     the memory operations: when removing breakpoints from the child
+     process after a fork.  When this happens, the child does not have
+     an inferior of its own, so instead current_inferior() refers to
+     the parent, and inferior_ptid has the child's PTID.  We can use
+     the parent's process_stratum_target (the one below us) to do the
+     memory operation, but dbgapi knows nothing about the child and
+     would try to update the parent's memory.  */
+  if ((!ptid_is_gpu (inferior_ptid) && object != TARGET_OBJECT_MEMORY)
+      || inferior_ptid.pid () != current_inferior ()->pid)
+    return beneath ()->xfer_partial (object, annex, readbuf, writebuf,
+				     offset, requested_len, xfered_len);
 
   gdb_assert (requested_len > 0);
   gdb_assert (xfered_len != nullptr);
@@ -707,7 +729,9 @@ amd_dbgapi_target::xfer_partial (enum target_object object, const char *annex,
 
   amd_dbgapi_process_id_t process_id
     = get_amd_dbgapi_process_id (current_inferior ());
-  amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (inferior_ptid);
+  amd_dbgapi_wave_id_t wave_id = (ptid_is_gpu (inferior_ptid)
+				  ? get_amd_dbgapi_wave_id (inferior_ptid)
+				  : AMD_DBGAPI_WAVE_NONE);
 
   size_t len = requested_len;
   amd_dbgapi_status_t status;
@@ -2485,9 +2509,16 @@ amd_dbgapi_xfer_global_memory_callback
   set_current_inferior (inf);
   set_current_program_space (inf->pspace);
 
+  /* To ensure that the callback request is not routed back to dbgapi,
+     route the request to whichever target sits below the amd-dbgapi
+     target on the target stack.  */
+  target_ops *handler = (inf->target_is_pushed (&the_amd_dbgapi_target)
+			 ? inf->find_target_beneath (&the_amd_dbgapi_target)
+			 : inf->top_target ());
+
   target_xfer_status status
-    = target_xfer_partial (inf->top_target (), TARGET_OBJECT_RAW_MEMORY,
-			   nullptr, static_cast<gdb_byte *> (read_buffer),
+    = target_xfer_partial (handler, TARGET_OBJECT_RAW_MEMORY, nullptr,
+			   static_cast<gdb_byte *> (read_buffer),
 			   static_cast<const gdb_byte *> (write_buffer),
 			   global_address, *value_size, value_size);
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/4] gdb/NEWS: Add note about AMD GPU debugging on Windows
  2026-05-08 17:53 [PATCH 0/4] AMD GPU debugging support on Windows Pedro Alves
                   ` (2 preceding siblings ...)
  2026-05-08 17:53 ` [PATCH 3/4] gdb/amd-dbgapi-target: Update xfer_partial to always use dbgapi Pedro Alves
@ 2026-05-08 17:53 ` Pedro Alves
  2026-05-08 18:29   ` Eli Zaretskii
  2026-06-12 13:39 ` [PATCH 0/4] AMD GPU debugging support " Pedro Alves
  4 siblings, 1 reply; 7+ messages in thread
From: Pedro Alves @ 2026-05-08 17:53 UTC (permalink / raw)
  To: gdb-patches

Change-Id: I03c28920f36412c506cf18861c97483d7fabfdd5
commit-id: 6b7fd462
---
 gdb/NEWS | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index 480e1854002..68f345dd9c6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -78,6 +78,11 @@
 * The Windows native target now supports non-stop mode.  This feature
   requires Windows 10 or later.
 
+* AMD GPU ROCm debugging support on Windows
+
+GDB now supports debugging programs offloaded to AMD GPUs using the
+ROCm platform, on Windows.  Previously only Linux was supported.
+
 * New targets
 
 GNU/Linux/MicroBlaze (gdbserver) microblazeel-*linux*
-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/4] gdb/NEWS: Add note about AMD GPU debugging on Windows
  2026-05-08 17:53 ` [PATCH 4/4] gdb/NEWS: Add note about AMD GPU debugging on Windows Pedro Alves
@ 2026-05-08 18:29   ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2026-05-08 18:29 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

> From: Pedro Alves <pedro@palves.net>
> Date: Fri,  8 May 2026 18:53:38 +0100
> 
> Change-Id: I03c28920f36412c506cf18861c97483d7fabfdd5
> commit-id: 6b7fd462
> ---
>  gdb/NEWS | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 480e1854002..68f345dd9c6 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -78,6 +78,11 @@
>  * The Windows native target now supports non-stop mode.  This feature
>    requires Windows 10 or later.
>  
> +* AMD GPU ROCm debugging support on Windows
> +
> +GDB now supports debugging programs offloaded to AMD GPUs using the
> +ROCm platform, on Windows.  Previously only Linux was supported.
> +
>  * New targets
>  
>  GNU/Linux/MicroBlaze (gdbserver) microblazeel-*linux*

Thanks, this is okay.

Approved-By: Eli Zaretskii <eliz@gnu.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] AMD GPU debugging support on Windows
  2026-05-08 17:53 [PATCH 0/4] AMD GPU debugging support on Windows Pedro Alves
                   ` (3 preceding siblings ...)
  2026-05-08 17:53 ` [PATCH 4/4] gdb/NEWS: Add note about AMD GPU debugging on Windows Pedro Alves
@ 2026-06-12 13:39 ` Pedro Alves
  4 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2026-06-12 13:39 UTC (permalink / raw)
  To: gdb-patches

FYI, I've merged patches #1 through #3 now.  

I didn't merge patch #4 (NEWS) because I realized there's still some missing
changes in gdb/windows-nat.c, needed when AMDGPU threads appear in the thread list.

I'll post those soon.

Pedro Alves


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-06-12 13:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-08 17:53 [PATCH 0/4] AMD GPU debugging support on Windows Pedro Alves
2026-05-08 17:53 ` [PATCH 1/4] gdb/amd-dbgapi-target: Move Linux code to amd-dbagapi-posix-hdep.c Pedro Alves
2026-05-08 17:53 ` [PATCH 2/4] gdb/amd-dbgapi-target: Add amd-dbgapi-mingw-hdep.c for Windows Pedro Alves
2026-05-08 17:53 ` [PATCH 3/4] gdb/amd-dbgapi-target: Update xfer_partial to always use dbgapi Pedro Alves
2026-05-08 17:53 ` [PATCH 4/4] gdb/NEWS: Add note about AMD GPU debugging on Windows Pedro Alves
2026-05-08 18:29   ` Eli Zaretskii
2026-06-12 13:39 ` [PATCH 0/4] AMD GPU debugging support " Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox