From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6W1pMWkj/mlbQCQAWB0awg (envelope-from ) for ; Fri, 08 May 2026 13:54:49 -0400 Received: by simark.ca (Postfix, from userid 112) id C54B61E0BA; Fri, 08 May 2026 13:54:49 -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 E75D91E067 for ; Fri, 08 May 2026 13:54:48 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1855C4BA2E1B for ; Fri, 8 May 2026 17:54:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1855C4BA2E1B Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by sourceware.org (Postfix) with ESMTPS id 6248B4BA23C0 for ; Fri, 8 May 2026 17:53:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6248B4BA23C0 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 6248B4BA23C0 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778262833; cv=none; b=AK0tjtHQ2o5gE80nijSShfvN+Ntz2CWoFhx/M71a3xP8rcPNVXsaeMMuq03II46XOU13lDWZzfrxo0dDNZycNiEt8sI6FERBJq2OSsiXPQ5N4e7Go89DblOIII0ZIMbQStLeRklUiukN9/mg1qyK2Gq5dYCWmi9TBjJeaSXCgsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778262833; c=relaxed/simple; bh=l4UX2kpvxa0k50F27ETWhkTOXWv3jd7WPcLvef5MZOg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GnzOcWq+90qs2Jor0bfLUjOCMqh4iwGnIGsM81IyW0O1UgcQbaEBkvMzowce80VMWZlpAED9+9g8C5TN/1P4OGfX08KBp8jCzZGhTXfHnUaAA9CzWLAfDxCrvJVhTR6tMDPkipTo2vp2zPPtXhrv2sPS+wY46ChcldRWxkCQyjo= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6248B4BA23C0 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-4526a8170ceso1288784f8f.2 for ; Fri, 08 May 2026 10:53:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778262832; x=1778867632; 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=XIwPOfFzl2qiDIdmRhoQ+efXsmkmpqCX6KR/By+OEic=; b=MVQH137fmRTI97f0UpmfMVJlBIrL/Ual5i8CEi/Sly99NU3EA3ggxrWYnXS4vkkeI6 feO6dVYSlfvl7+TrJD5rntm2TwHGxxz0zPjpZp5pQJr6Kk7xiLtMd0/QKqilNlIC30aM TVy/Ky6bqer9JCNXxBq0ocrvZ2p+xjLMutAd89Cj5D9+AEMJJ0HknJMpHjvZTBGlfUbp mpjnD3Ua56zLVg8S5JPiJusW0s8Ta95UVZOMKvUHB/crJupx2YPd1TWuEVBkfIkAWrLD d1tbbhHlD8JZsdasrBI0iIgl2MP/i6o4GABS2tM8FpzOwpD8uqk36GMHd+RdqHtFEVmw EY3g== X-Gm-Message-State: AOJu0YwKwayXW9zAYmXryfhOWMZzE/jAYHK4K+ewim/wziMvi9ct0qo6 kkq/KmG+EjGCZUZWJFK9KWASUSb73Nksy42GZoL0u8kkqvonjqD3eAhE3EzSsg== X-Gm-Gg: Acq92OHTKdFRn0Yty8Ho6T3Enyq/9qO6ofsSBvyMsQ7Q/2mfw4Irg5EW8CRgvHvMcJP 6flE5ItmoVYeSmgrYunCVptNPpbtugZv0C+OHmoVcV/hzV+g4qyNrbyP8HQJdPprsM9z1BsuTeS 4bqyuIlLDiPu9k7wIqrrZlEmOjK9uU+kGpr+/jQZIXg/wo6IWPVCfFyi8v9YZ4Qn+py/Tt9C3tf sHrXKNHrAov+igQzhq2LfXOy5JlgbuL7dvtc/SSinsSHK0dZmr/hJS/IhBb6wHc/JXut0xAjEe8 atjE/5eMnToNaRaqeN3dg0oODhA000m2bIxlfA9KZ06BK7w9ua0P2g9BkPGP8JeQN7feQQhVggg g8PwL6fCR49ElpOS7l/HqPLD2mlnUOQWshG5Us2e0bibJClBeiM9eck9+sBNMG2g2uaA70AS2n5 w3iY55GRGiFfsavlZ0MAjg4Q== X-Received: by 2002:adf:fe83:0:b0:452:6732:3560 with SMTP id ffacd0b85a97d-45267323578mr13823449f8f.13.1778262831347; Fri, 08 May 2026 10:53:51 -0700 (PDT) Received: from localhost ([2001:8a0:facb:a800:8568:24f9:2e91:5bb5]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-4548e6a6a64sm6380245f8f.6.2026.05.08.10.53.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 May 2026 10:53:50 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Pedro Alves Subject: [PATCH 2/4] gdb/amd-dbgapi-target: Add amd-dbgapi-mingw-hdep.c for Windows Date: Fri, 8 May 2026 18:53:36 +0100 Message-ID: <20260508175338.536044-3-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 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 --- 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 . */ + +#include "amd-dbgapi-hdep.h" +#include + +#include +#include +#include +#include +#include +#include + +#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 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