From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QHHGNzozK2g2NyoAWB0awg (envelope-from ) for ; Mon, 19 May 2025 09:33:46 -0400 Received: by simark.ca (Postfix, from userid 112) id DFC9E1E11C; Mon, 19 May 2025 09:33:46 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 739B11E102 for ; Mon, 19 May 2025 09:33:45 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26DF63857B91 for ; Mon, 19 May 2025 13:33:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26DF63857B91 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by sourceware.org (Postfix) with ESMTPS id 182AD3858D37 for ; Mon, 19 May 2025 13:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 182AD3858D37 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 182AD3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661086; cv=none; b=vpVAVyzeUYJ7zLNORltcQW31bFyIXFxdVNMTyDNFHwnRbu+FgO45YFMN1QVFqaknwi7/fQ2CU5LSQZHmZikWhoGoCK9KVWGoqhP/QSTDTgVBMm4Nw4qT30x40d+ObXcfIdPm1khryH7p0sn7FJNjOqmVIy8cH8HK7S3TXmc3dj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661086; c=relaxed/simple; bh=0pInhoMpZKtKpvc86fWLZXmvwmdtLJ1umskqAc0kBMU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=m0+uMgOTY5o+IMJQMWkDAE/H6q3MyreH8Ta2nEaSVIdTU3N/8vTvzwV8slZ5Jr5kom7egZKCdV1W7vDtOIe7vt3ddDjA7GWrwK4dR+ptsxfLZ6H6SxeSihoJU15aZLMjDbH+vPzj9DqcB99f0ydW47O6C0croVt1oycUE/VyvNU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 182AD3858D37 Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3a36efcadb8so864391f8f.0 for ; Mon, 19 May 2025 06:24:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747661085; x=1748265885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0/DSW+hSAPOYrq+TpLhnzWAcofSJTUNoNZ38vK2pdA0=; b=BQKwpzkhp+mfjT/jonJS4RhW4Yfl84+6IM7rz0y8E9m0nRXWkGa1x7XiIdX4UI66nV 2A6S2Q4S/jWfwffe5GSSAa5vDQJWkRz1DOSJrae6FrAOC3yILt2SlhhKf7Z5n8nCkxSO QjjMM6UWJgPgNMsMjBWk6l7XVYQvXHxEi40yUnLsf8eWAAHfjoSGogwfobVNDrJ/ekD/ syzXihS3MVHitV/YjVWjFry6KZ7c0kv28X4MbnY6usCbz7rn5R8fhzokrupnvvF71GkE K+gluZ4Az8MASGdvfESiBG8uV84HSSjRJiW4Em07SjwrnFTrx9VMDvKMrlM4UjpVRE6Q 1nZw== X-Gm-Message-State: AOJu0YxS9Bxcvy37yJVBuyeaNo0jWSs8HJkIaAiei1P8qtrBI5Jt2Pok 48uQn1hpeL0mAsiNL5c3SMzAiRpO3HKo80vjgthZPKQ+f7RIgpvhttsMHRheTnNm X-Gm-Gg: ASbGncticIFWyjQD8wTbTL+Pl7s8S2bKMFetkyfqvhKGFfVfe8PO2Ck1psmI2CUTZZl ff8qGC053KiAwGn+BAKhvzql0e1Uh2LemsVvehxRVy65HPO+G0eLWGzaoMPAAav8doWtytWXp5M 0kBO4uksU/Zl5OK8kHU8G0wS0fGJqVX3lf3HTvZbUkSHHyr/jWLyKO9PzRaqzS/dGiz+qYmXRdV h97tjB5UAWzn9Np7ThKW0E5G2ay94+0fBC9xLlUQw49pN+xjwLPgyxvZqTD1gzSWgsoc1kOedz6 et6ifI7tewrBCmVSfWhAqgDiYGgrlQSffY3BLaCOVL+xNl9g+oJsj+tlnXx59A== X-Google-Smtp-Source: AGHT+IFW9Sv2PomOG1AD9s9VbJrybkYN3k7OPmvMPA0e5R0CNopvmRMOBajmmSqWYux71g7xncEIRg== X-Received: by 2002:a05:6000:186c:b0:3a3:6a3f:bc85 with SMTP id ffacd0b85a97d-3a36a3fbee8mr4990148f8f.25.1747661084628; Mon, 19 May 2025 06:24:44 -0700 (PDT) Received: from localhost ([2001:8a0:4fe9:b400:8d90:6f0d:36bf:32df]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-442f3951adcsm215695945e9.19.2025.05.19.06.24.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 May 2025 06:24:44 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 30/47] Windows gdb+gdbserver: Share $_siginfo reading code Date: Mon, 19 May 2025 14:22:51 +0100 Message-ID: <20250519132308.3553663-31-pedro@palves.net> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250519132308.3553663-1-pedro@palves.net> References: <20250519132308.3553663-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 6128b83bea4..a548acc97d3 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 cba8098fb39..d0978f899fd 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 1ced313d7b1..bd3bc3701a6 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -3006,44 +3006,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 4e2d95bd059..834af706786 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -1285,45 +1285,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.49.0