From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qbHUEkUj/mlbQCQAWB0awg (envelope-from ) for ; Fri, 08 May 2026 13:54:13 -0400 Received: by simark.ca (Postfix, from userid 112) id 48D9D1E0BA; Fri, 08 May 2026 13:54:13 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 62CD21E067 for ; Fri, 08 May 2026 13:54:12 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 009C24BA2E37 for ; Fri, 8 May 2026 17:54:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 009C24BA2E37 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by sourceware.org (Postfix) with ESMTPS id A13F84BA2E14 for ; Fri, 8 May 2026 17:53:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A13F84BA2E14 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A13F84BA2E14 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778262825; cv=none; b=V0Pb9/j/EKdFd5FIMGL4OlQfcaZyx8P2Zn6EfEAPVchDQy5Z0LRAnT2M1Xx4teaYLK+qDYV96Dz8KTxvydMREC9Cv4lMW1BXP773ox0QHTU0/NNMxReocJxBf/u3jxLcRvJxxUI/EcUVTIckaK6UlwmBIK/+9X0Xva6xzhrkII0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778262825; c=relaxed/simple; bh=adGpVOJ2vqylbx6VhZAuO1AEpzE8IYz44/eDq04A1nc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VpKcqdLtu2ecm75Mp9Hm1KnLASNkz+szcWz6X4svc/nmm1MKivlfd3JU/vlb3uyyf6CRzX8riqOo6kGEkd+wqGOH0AlRjq2zuOhn5CkuPWWMa9MlXrZdSR/EOlQneHhCA+7uORj/NKZLCopBEHe18SI22iAxd7n2sl1/73kWRtU= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A13F84BA2E14 Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-48a563e4ef7so20918275e9.0 for ; Fri, 08 May 2026 10:53:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778262824; x=1778867624; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2ycfjT008GMkrsME7duysKSp9SThUCofXcQTQtCphLY=; b=HrY4WXRJgrzy9f+REOms3TAzVOCotW5k0xCwYysY3ucc4/wuxlDkB9HtbHR08prKBj 8xiAyi2VqqJoRSuhRLeWfFIQrQ7sNIwqlktJFpzzcemRD7nPqcQ4dRkwI/9okzKtsjhu 7PhmH4plvxZ/fmwVQtskQyTcaWoZsd2shxmrqegW/5cVYd/4haz+hUnkiWN4A29ZlKIY ZeZL2feVTBkUqNxmwJML3TPaQDsqxD02JapiCcilFPGBuxBhIurlsUPdOUtxUNy1g1YQ xTej8gXqLQYIlIJ2jvnJFD3crQwKSq9YI22tFa1tDzGyDv0UiZxPJ3+Gw5wrHyF4xmsr BYfA== X-Gm-Message-State: AOJu0YyVZLJ5f0f0N/aXqej/I3Uoxv06aaXb4y92KIfRZI846HNn6IjS WonsEiditZj5DIrb+AxqtBcEk3VDlPzOGzuY/dMdQWtOJ6adZKlyudE0Yin+/w== X-Gm-Gg: AeBDiet0PNpBXxuY+kpn4uF4rYAAFi5G/b1iirwxnihfhbWznbyhTEBMrOx1bjsO+Fb Sg0aPDHU//c63oyv9BI2tX/agUjP85hdHYbI0rscjyXqGtHe+D7XiOoykprvEEN546myGBqC6RD z9pCa2tbdumfg/FKRsVVB4erxj5YAkDT0hWIbp+9dd7D+zpOHsGnV45Bv9pllLnNpaFlnE+SqV2 jsGybq2+VXaMRigpQMTvWjCHk4te2aTKGU/l8qnfChbPXnxIdA6JwhKkydm2wqHzgRKZ6njOoNw GvXdAWNIpPeFtoydyUWaZSIIvzW87Zx9JbmvjKA59AdAZsJxL5o8KvUnrZ2/CC1UmXUSvBGfWND fx86rytNIWaMSRZl4MAb56wzf2Aiqx5+T6WbNS15y8mSKn/r1NtBEZh6T//M4OEv+gzCxFq2KLY zcCbM4rSOi9d3+dlh59B8/7w== X-Received: by 2002:a05:600c:3b17:b0:488:ffb1:494c with SMTP id 5b1f17b1804b1-48e51e1f0b2mr198995005e9.12.1778262823891; Fri, 08 May 2026 10:53:43 -0700 (PDT) Received: from localhost ([2001:8a0:facb:a800:8568:24f9:2e91:5bb5]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-48e6d89a9c5sm10227925e9.0.2026.05.08.10.53.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 May 2026 10:53:43 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Pedro Alves 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 Message-ID: <20260508175338.536044-2-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508175338.536044-1-pedro@palves.net> References: <20260508175338.536044-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Lancelot SIX 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 --- 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 . */ + +#ifndef GDB_AMD_DBGAPI_HDEP_H +#define GDB_AMD_DBGAPI_HDEP_H + +#include + +/* 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 . */ + +#include "amd-dbgapi-hdep.h" +#include + +/* 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 (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