From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2cyONUbX62m5UzkAWB0awg (envelope-from ) for ; Fri, 24 Apr 2026 16:49:10 -0400 Received: by simark.ca (Postfix, from userid 112) id D6FA71E0BA; Fri, 24 Apr 2026 16:49:10 -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 A35181E093 for ; Fri, 24 Apr 2026 16:49:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 4BCB84B920FE for ; Fri, 24 Apr 2026 20:49:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BCB84B920FE Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by sourceware.org (Postfix) with ESMTPS id 1AFA54B92093 for ; Fri, 24 Apr 2026 20:46:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1AFA54B92093 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 1AFA54B92093 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777063582; cv=none; b=PmhA8n9dsKNWt9RCsAI6EEK7YsaunPK+wnZ5FIvy4EpkfNnWn5x6E9pqDFQzNO5jrBgpiSAcB9AmbBtpnQCLiwpiIBUldU/2o9efw8bxACothXxbHFWNAZ3eizWpts5tJwwidCWbj3UcOXLwFDrx6heoBLL1+PxtU/5qSjDlJds= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777063582; c=relaxed/simple; bh=J7MkI1/pmpiaGTDnZN3qeXx8pxH2jaNriaPlV5ObFoo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kRazgO9uF3txf8QOucDHwkLqmTvLtqyZsISvltyDFe/lyYWPzcH1dAwK7g86HxpmmQ/PNcENqmvDyT9LiuDBtsYc5l4D+bzrzYenURjmLcgWYCntvF6q5JU8G+h/sv5evdKjNwXOPlhZFuPIcYJwTVw0b8HcSKiRSFoTp9f6NpQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AFA54B92093 Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4891f625344so69945325e9.0 for ; Fri, 24 Apr 2026 13:46:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777063581; x=1777668381; 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=Uh7Pgz0QB15Kv2IbMfuxqGyQ5Rj3L5QIaE37QhsZIRY=; b=RTCseBxYhutEixNKXk9fVal5rkb0Bk9weMOoOm8YdhLqWCOlx6pG8vbYZlTY9l6kRe aCjS/iJ3K7Tk5phR8aXBRyTLZMcYIQeh4Hi19httpvSYf+etufEbvV9H+Qlml58YDYjC F1DcD+/a2NVjYeK/EOMt+peR++KwVVbB0pNjckukhCJMW0EnnsYHyqJ3Xm/29Rn8kvY/ GDokMkEEmEqGvnZ9bZoa6qgTj85xaOIDNN0m/3np4un1ytUGILA7uVBW2iZZR7lJjdD4 kzMZxGeGnkjhHfM674pqg7LaNC0VMLe96xOS4IiFHt0f0XOiu95ckcbCBrR/NYOErWLZ 3VGg== X-Gm-Message-State: AOJu0YyVhTGY7E74drD1maDtIqvnAcUqDptcd/L9q/2KQjMvw0hmel7N npZlUG3xD0lhVp+S7CzfVUtQFb5U7UXuaO5ac5h8fbty2KF0AEcCZQX7WwBSylNB X-Gm-Gg: AeBDievHUq3z9M+J9jDu1eIih+qjUijA/4zRiZJxRcr9XhYZ6o9NoZOLQ77Z55Q80To vBPwmHCKOM0GlW6QRMgkqsFNHSVcwfLQ0Y320fElnQDYV80FO/i0pNtdBuDWxP7n0AaTKbnhiPq 6CIbtPub17ns+gRXDdz9Ng8sQ1yIBq5zYpkcw5Bb36Mn63YGrFs+iB9yCIdfNx1UdX5/FvGfw5l xt/mRibKEOns00dzdcff7Wrx4ZID/B/15389KiO6Sm/2YL1bW2gKgp8eCWQd7HkkcyF0JPKL9qc xRbCLJL+R8lQZrG0jQxxQXPDKCbN0RtMu5p01Kqm95tqrDFAM/UpkXXBCYCSobQzzWkdWgZzWB9 5iMwcyvWJ2FrX/WeEvciyMOEZNFbDyAhQV9veiR77j9+KGaufOsPZ+Gm6EigZ0xvZK0gRTwt9MV 8RNXv908iXoBcSmhAmyYXzO3yciupo12bi X-Received: by 2002:a05:600c:3150:b0:485:3cef:d6ea with SMTP id 5b1f17b1804b1-488fb8b9debmr18090715e9.13.1777063580635; Fri, 24 Apr 2026 13:46:20 -0700 (PDT) Received: from localhost ([2001:8a0:facb:a800:7315:8865:c664:fc06]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4891df9e50asm332168745e9.0.2026.04.24.13.46.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Apr 2026 13:46:20 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [pushed 23/28] Windows gdb+gdbserver: Share $_siginfo reading code Date: Fri, 24 Apr 2026 21:45:03 +0100 Message-ID: <20260424204508.1343973-24-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260424204508.1343973-1-pedro@palves.net> References: <20260424204508.1343973-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 Both GDB and GDBserver have similar code to read the $_siginfo data. This patch moves the bulk of it to gdb/nat/windows-nat.c so it can be shared. Approved-By: Tom Tromey Change-Id: I58f9074caf6362274453c78ed1fc9e31249f6854 --- gdb/nat/windows-nat.c | 49 ++++++++++++++++++++++++++++++++++++++++++ gdb/nat/windows-nat.h | 9 ++++++++ gdb/windows-nat.c | 40 +++------------------------------- gdbserver/win32-low.cc | 42 ++++-------------------------------- 4 files changed, 65 insertions(+), 75 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 1f8967dcd8d..c6434348607 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -153,6 +153,55 @@ windows_thread_info::thread_name () return name.get (); } +/* Read Windows signal info. See nat/windows-nat.h. */ + +bool +windows_thread_info::xfer_siginfo (gdb_byte *readbuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len) +{ + if (last_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) + return false; + + if (readbuf == nullptr) + return false; + + EXCEPTION_RECORD &er = last_event.u.Exception.ExceptionRecord; + + char *buf = (char *) &er; + size_t bufsize = sizeof (er); + +#ifdef __x86_64__ + EXCEPTION_RECORD32 er32; + if (proc->wow64_process) + { + buf = (char *) &er32; + bufsize = sizeof (er32); + + er32.ExceptionCode = er.ExceptionCode; + er32.ExceptionFlags = er.ExceptionFlags; + er32.ExceptionRecord + = (uintptr_t) er.ExceptionRecord; + er32.ExceptionAddress + = (uintptr_t) er.ExceptionAddress; + er32.NumberParameters = er.NumberParameters; + for (int i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++) + er32.ExceptionInformation[i] = er.ExceptionInformation[i]; + } +#endif + + if (offset > bufsize) + return false; + + if (offset + len > bufsize) + len = bufsize - offset; + + memcpy (readbuf, buf + offset, len); + *xfered_len = len; + + return true; +} + /* Try to determine the executable filename. EXE_NAME_RET is a pointer to a buffer whose size is EXE_NAME_MAX_LEN. diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 59662c3570c..cb7456c624e 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -76,6 +76,15 @@ struct windows_thread_info the next call. */ const char *thread_name (); + /* Read LEN bytes of the thread's $_siginfo into READBUF, starting + at OFFSET. Store the number of actually-read bytes in + XFERED_LEN. Returns true on success, false on failure. Passing + READBUF as NULL indicates that the caller is trying to write to + $_siginfo, which is a failure case. */ + bool xfer_siginfo (gdb_byte *readbuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len); + /* The process this thread belongs to. */ windows_process_info *const proc; diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 143a5e487fd..062ecf1e063 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2454,44 +2454,10 @@ windows_xfer_siginfo (gdb_byte *readbuf, ULONGEST offset, ULONGEST len, { windows_thread_info *th = windows_process->find_thread (inferior_ptid); - if (th->last_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) - return TARGET_XFER_E_IO; - - EXCEPTION_RECORD &er = th->last_event.u.Exception.ExceptionRecord; - - char *buf = (char *) &er; - size_t bufsize = sizeof (er); - -#ifdef __x86_64__ - EXCEPTION_RECORD32 er32; - if (windows_process->wow64_process) - { - buf = (char *) &er32; - bufsize = sizeof (er32); - - er32.ExceptionCode = er.ExceptionCode; - er32.ExceptionFlags = er.ExceptionFlags; - er32.ExceptionRecord = (uintptr_t) er.ExceptionRecord; - er32.ExceptionAddress = (uintptr_t) er.ExceptionAddress; - er32.NumberParameters = er.NumberParameters; - for (int i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++) - er32.ExceptionInformation[i] = er.ExceptionInformation[i]; - } -#endif - - if (readbuf == nullptr) - return TARGET_XFER_E_IO; - - if (offset > bufsize) + if (th->xfer_siginfo (readbuf, offset, len, xfered_len)) + return TARGET_XFER_OK; + else return TARGET_XFER_E_IO; - - if (offset + len > bufsize) - len = bufsize - offset; - - memcpy (readbuf, buf + offset, len); - *xfered_len = len; - - return TARGET_XFER_OK; } enum target_xfer_status diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index bf3490542e2..0741dd24ed5 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -1272,45 +1272,11 @@ win32_process_target::qxfer_siginfo (const char *annex, { windows_thread_info *th = windows_process.find_thread (current_thread->id); - if (th->last_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) - return -1; - - if (readbuf == nullptr) - return -1; - - EXCEPTION_RECORD &er = th->last_event.u.Exception.ExceptionRecord; - - char *buf = (char *) &er; - size_t bufsize = sizeof (er); - -#ifdef __x86_64__ - EXCEPTION_RECORD32 er32; - if (windows_process.wow64_process) - { - buf = (char *) &er32; - bufsize = sizeof (er32); - - er32.ExceptionCode = er.ExceptionCode; - er32.ExceptionFlags = er.ExceptionFlags; - er32.ExceptionRecord - = (uintptr_t) er.ExceptionRecord; - er32.ExceptionAddress - = (uintptr_t) er.ExceptionAddress; - er32.NumberParameters = er.NumberParameters; - for (int i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++) - er32.ExceptionInformation[i] = er.ExceptionInformation[i]; - } -#endif - - if (offset > bufsize) + ULONGEST xfered_len; + if (th->xfer_siginfo (readbuf, offset, len, &xfered_len)) + return xfered_len; + else return -1; - - if (offset + len > bufsize) - len = bufsize - offset; - - memcpy (readbuf, buf + offset, len); - - return len; } bool -- 2.53.0