From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ycvQIlAj/mlbQCQAWB0awg (envelope-from ) for ; Fri, 08 May 2026 13:54:24 -0400 Received: by simark.ca (Postfix, from userid 112) id 89BF51E067; Fri, 08 May 2026 13:54:24 -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 CC0F41E067 for ; Fri, 08 May 2026 13:54:23 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F9A44BA2E11 for ; Fri, 8 May 2026 17:54:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F9A44BA2E11 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by sourceware.org (Postfix) with ESMTPS id E73894BA2E32 for ; Fri, 8 May 2026 17:53:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E73894BA2E32 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 E73894BA2E32 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.160.174 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778262838; cv=none; b=R4AmRHfaUyUOQqRZsXMsKg3U1V9uw3TMXZiK4z/2Fz9Rdw6rh8PESIzegpDZKJc39QDEl2n+DT12HVEy+rHs7QOdnTdh0CyDTH9bv+KjrFiZvmeK99lmqo0ntS2YamwI1Gi2QgQmgdczjZwMH29ojgE/hBRE1/j98kpkYidfoy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778262838; c=relaxed/simple; bh=bcgwMsmxTmryXIKMDrYCHWRrWn2KsCwwMWQ8L/i8mgI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NsbMF5uux55wqZaKYMm+dn95Mij+eLv3IbwL6D+mKpyHZq6pApwH5nVQuTe8AN0wDzyk3kGMBc2P84x4M7A9hBsvk9NuTFZNq/mUq2Nuho2e6DMjTug+CGOq/aFDqxgSzX2iG7Y7QxlavbuZH3l8C1tngyw4tANjFttnp0osDm8= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E73894BA2E32 Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-50d876329bbso20712511cf.2 for ; Fri, 08 May 2026 10:53:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778262837; x=1778867637; 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=Lle31Z1eRTMiwK1BwrlHK3LRjkkCovdAnnbO9ym3guY=; b=a99QXinRgEe4ZvBad8cAndUiVLjMtxhls+26LS/Yff+N4EBL8ToBvMiQdUdMAPHbHr MlBWJq+GP/9Rh5FWGoXJE57ClXKO/F9EGhe6op8Lz08rOOPwD+/GnUtoNRfpFmBhUto1 9QvBPU+AkBHzs98ijJ+Mw8RVfNME5nAG/U8U77+v4YxBmqeD1H2w12mtmgquIsOJ//Af gqxMbb+UBIKUuC44yFDE6jXc7kGY/LAqdkKlRV7X5IkOgkg080UAzai9YcU9y6CZbpas 7NymI313D/kuK2DMGz1+ItZVeggYSWHYyRMMh+GuzFGvWiaTmPtkdVpWCOMxtY847qCO rjBA== X-Gm-Message-State: AOJu0Yy3pvb1Hxx7iRu4BNZVNqypy/st9d7ONCc17Rteh04KSsOscJLY rNqkxVO8bbmAeA291yR3Si95Oox78Qt2AdN1bIs9Grv8bcsNyMCnpsZ3oTZ9pQ== X-Gm-Gg: AeBDievQvQUuXIDwnBZBh5qWYKqSVsTqglBUNdo6QNnWg20E1VA5iOZs5pSpwYSALEg ZgFJMEc6qUV7RjicOYUdz79zcxRrqz1mIVzxqQs+z9be+7ScqodpAl3AAxZdOpOrVBzG/K/B+LF GGSLO8II0pXYDra3fhvv5SEQFKuy+cViuOpNkm1ULAFaw1C89GXGtVMuXUE4RtyyiVfm/IzlFSH dCPZvR1o1F1P7yCzXXUrntHwV2vk2SXpBLf2nAgjNGMLX1ebdCtjGVEspmv+9SBhR1Ec1Y8H0q6 Xx7qDuEJEkKhHdRn1vERE/fm7qt/JHgRg9oNf146VTvufPKHzZujfmwyisDC0cXgY3vSszdhrnK ZDVW72DOka/TkC6+J3vr+kH4T2JGzyMpNTyXhaG2eSyFDD28ry2+L/8JWhflQoOWn2bBrpMdYRS fcC4OZp4f4FTB7MZGbBmvQowHBDIuHLqRl X-Received: by 2002:ac8:5c89:0:b0:50e:fcbc:6b7e with SMTP id d75a77b69052e-51461f9e45amr185204521cf.29.1778262836649; Fri, 08 May 2026 10:53:56 -0700 (PDT) Received: from localhost ([2001:8a0:facb:a800:8568:24f9:2e91:5bb5]) by smtp.gmail.com with UTF8SMTPSA id d75a77b69052e-5148e7c0fa5sm25174121cf.16.2026.05.08.10.53.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 May 2026 10:53:56 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Pedro Alves Subject: [PATCH 3/4] gdb/amd-dbgapi-target: Update xfer_partial to always use dbgapi Date: Fri, 8 May 2026 18:53:37 +0100 Message-ID: <20260508175338.536044-4-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 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 --- 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 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 (read_buffer), + = target_xfer_partial (handler, TARGET_OBJECT_RAW_MEMORY, nullptr, + static_cast (read_buffer), static_cast (write_buffer), global_address, *value_size, value_size); -- 2.53.0