From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Cc: Pedro Alves <pedro@palves.net>
Subject: [PATCH 1/4] gdb/amd-dbgapi-target: Move Linux code to amd-dbagapi-posix-hdep.c
Date: Fri, 8 May 2026 18:53:35 +0100 [thread overview]
Message-ID: <20260508175338.536044-2-pedro@palves.net> (raw)
In-Reply-To: <20260508175338.536044-1-pedro@palves.net>
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
next prev parent reply other threads:[~2026-05-08 17:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 17:53 [PATCH 0/4] AMD GPU debugging support on Windows Pedro Alves
2026-05-08 17:53 ` Pedro Alves [this message]
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
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=20260508175338.536044-2-pedro@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@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