From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yVK9LKGZZ2rTeDAAWB0awg (envelope-from ) for ; Mon, 27 Jul 2026 13:47:13 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=yahoo.de header.i=@yahoo.de header.a=rsa-sha256 header.s=s2048 header.b=DhxLh1Yg; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id AE8441E09B; Mon, 27 Jul 2026 13:47: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=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 38D241E09B for ; Mon, 27 Jul 2026 13:47:12 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FA454BA79B3 for ; Mon, 27 Jul 2026 17:47:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FA454BA79B3 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=yahoo.de header.i=@yahoo.de header.a=rsa-sha256 header.s=s2048 header.b=DhxLh1Yg Received: from sonic305-20.consmr.mail.ir2.yahoo.com (sonic305-20.consmr.mail.ir2.yahoo.com [77.238.177.82]) by sourceware.org (Postfix) with ESMTPS id 875494BAE7DB for ; Mon, 27 Jul 2026 17:46:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 875494BAE7DB Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=yahoo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yahoo.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 875494BAE7DB Authentication-Results: sourceware.org; arc=none smtp.remote-ip=77.238.177.82 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785174388; cv=none; b=C7eigNZxv7Vo5oOiHsYNpKZR0Yry72Dbse3SOf0OOfpwKcL/X7TjrJRcn58C3lVltTvULLTfEz1SRMSbt0ZHaC6mL4OBR/XJqUlM4XiF9+bA1CbFeBvWpzKa0kPsWy1haNQze22gtXTNeulwbx9EXn4wzbFOHBsFia4DZqisFqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785174388; c=relaxed/simple; bh=YqR7Yi7BKb6p+2oRWkoSWVtFm5UQg6iC3FZval1rBKc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BlVvVGIwvRK723O/UqsUkhgYC8+s+ihb7MZy3bg++gwBLVHIeylUgPiSS28Sa6955X3CQQetRxEuBobsrEYPmjE6WRZNkgtT14Y6ougwBYFM3lxkCFLRe/78qGYZIbLCgIDTX0TpVGg7qjOOpwpdnODgSUM5XQ581UpkC6ibQYI= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=yahoo.de header.i=@yahoo.de header.a=rsa-sha256 header.s=s2048 header.b=DhxLh1Yg DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 875494BAE7DB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1785174387; bh=m3mnSKnXIp7uCHZDJhB1BWM07kRhuTcrT8WrJ895j+0=; h=From:To:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=DhxLh1YgDimkcLZDkxkOHFic0lFppA6tNhJvN9F2vGGD6SXc5nQrSlOrK1lLio3iaAMzWoU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5ydX4Wy9FZPv4jVClOmVWQbrNdFec88AGb7636. VF.4TJjoe3rHhtZgWBKcm3l637Gk15K.l5yf2aipEgWWBoxCvPfQPaWxnoTc6OK.Eq.sMYO13mtJ RbYuS8ZnUTDB6kvFURLhs5Jl2mZzsET2L3wAuuand4pRO5aH4EuH3MdvHwQ2Q1vW0A2hbWBpZcf. 81YoJZy0t_TbCto1lB1k2zSYG7LUfunPQxHV2ZsqlUVNPbtSbsQ0HKl53hJzQdHuWqoEvKEpUoaH BnxlXFnDgL5ckbwUM_.32XqTFDz9cUuTaD4oXGT9HimiFLApimCR7VjMe4KK2w0fXlzffkqoamuq g4Hny7XeXaiJxHKoB4cWxDk33DjVgma2.1zv89ndQeK0qcvEhSXNfGf4dieD4LY1XMSxGHa6zc_o p92ngmZI0.v81XOJgybg7m48r1B.vr5Wwm9eQ_V3RRi5Mv_9EHG9Qx8MezikAxfdBJWWdvvWoySk F9MEapHr0DC9WYltn5ZKk3iBoYTx8q2B8O42Ebg136N8hfI6NrNmgeHL2XUQNwlvSxY0kL91WEnH XZ9etB0mwrOR3UCXsYWTIzdllGXBWy8trEhjAkW1JOoaEhg6TTNcYnei5xaBP_HoDk5tHMVqL9UO 7BFEEVn4kErXlmPyK0uj98Nxqu_qtv6fthM8iUwtyhppu9O7j8tiagNsYBIeHSyXEdyhp2TqzuzK 6oJgwuysAl69oJDylxb4l0IUZB5zMX.gqJAt9jqAnvyAKTRouQKaq6HXVsmIcaQzj4K2i3KaoBYw 1KBifQoi._0ZP5yPTMu0bHrX7uyGInxyCij5IF7a0_5tPloTzgZrGyLlxTX.PmtOu7Oj8WPAGfpa HrmzRNmKHBwSAMe2lJ1GU X-Sonic-MF: X-Sonic-ID: e0b3511e-cc8d-4806-8121-baa886938d6a Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ir2.yahoo.com with HTTP; Mon, 27 Jul 2026 17:46:27 +0000 Received: by hermes--production-ir2-676cb4d88b-rslc6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0669d8fa15a3c4ff66838ce4fae4c373; Mon, 27 Jul 2026 17:46:24 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH v2 2/8] Windows gdb: Use allocated buffer for CONTEXT Date: Mon, 27 Jul 2026 19:42:26 +0200 Message-ID: <20260727174619.1089041-2-ssbssa@yahoo.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260727174619.1089041-1-ssbssa@yahoo.de> References: <20260727174619.1089041-1-ssbssa@yahoo.de> 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 This is done in preparation for the XState functions, because the extended registers are stored directly after the CONTEXT, and its actual size depends on the available XState features. --- gdb/aarch64-windows-nat.c | 16 ++++++++-------- gdb/nat/windows-nat.c | 19 +++++++++++++++++++ gdb/nat/windows-nat.h | 16 ++++++++++++---- gdb/windows-nat.c | 1 + gdbserver/win32-aarch64-low.cc | 10 +++++----- gdbserver/win32-low.cc | 1 + 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/gdb/aarch64-windows-nat.c b/gdb/aarch64-windows-nat.c index ff2c9762467..630704a8caf 100644 --- a/gdb/aarch64-windows-nat.c +++ b/gdb/aarch64-windows-nat.c @@ -185,7 +185,7 @@ aarch64_windows_nat_target::cleanup_windows_arch () void aarch64_windows_per_inferior::fill_thread_context (windows_thread_info *th) { - CONTEXT *context = &th->context; + CONTEXT *context = th->context; if (context->ContextFlags == 0) { @@ -199,7 +199,7 @@ aarch64_windows_per_inferior::fill_thread_context (windows_thread_info *th) void aarch64_windows_per_inferior::invalidate_thread_context (windows_thread_info *th) { - CONTEXT *context = &th->context; + CONTEXT *context = th->context; context->ContextFlags = 0; } @@ -209,7 +209,7 @@ void aarch64_windows_nat_target::thread_context_continue (windows_thread_info *th, int killed) { - CONTEXT *context = &th->context; + CONTEXT *context = th->context; if (th->debug_registers_changed) { @@ -250,9 +250,9 @@ aarch64_windows_nat_target::thread_context_step (windows_thread_info *th, bool enable) { if (enable) - th->context.Cpsr |= 0x200000; + th->context->Cpsr |= 0x200000; else - th->context.Cpsr &= ~0x200000; + th->context->Cpsr &= ~0x200000; } /* See windows-nat.h. */ @@ -263,7 +263,7 @@ aarch64_windows_nat_target::fetch_one_register (struct regcache *regcache, { gdb_assert (r >= 0); - char *context_ptr = (char *) &th->context; + char *context_ptr = (char *) th->context; char *context_offset = context_ptr + aarch64_windows_process.mappings[r]; struct gdbarch *gdbarch = regcache->arch (); @@ -292,9 +292,9 @@ aarch64_windows_nat_target::store_one_register (const struct regcache *regcache, windows_thread_info *th, int r) { gdb_assert (r >= 0); - gdb_assert (th->context.ContextFlags != 0); + gdb_assert (th->context->ContextFlags != 0); - char *context_ptr = (char *) &th->context; + char *context_ptr = (char *) th->context; regcache->raw_collect (r, context_ptr + aarch64_windows_process.mappings[r]); } diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index e975892f487..689601f3a82 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -291,6 +291,25 @@ windows_process_info::pid_to_exec_file (int pid) return path; } +/* See windows-nat.h. */ + +void windows_process_info::initialize_context (windows_thread_info *th) +{ +#ifdef __x86_64__ + if (wow64_process) + { + th->context_buffer.reset (xmalloc (sizeof (WOW64_CONTEXT))); + th->wow64_context = (WOW64_CONTEXT *) th->context_buffer.get (); + } + else +#endif + { + th->context_buffer.reset (xmalloc (sizeof (CONTEXT))); + th->context = (CONTEXT *) th->context_buffer.get (); + } + *context_flags_ptr (th) = 0; +} + /* Return the name of the DLL referenced by H at ADDRESS. UNICODE determines what sort of string is read from the inferior. Returns the name of the DLL, or NULL on error. If a name is returned, it diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 44b628c9bd1..76688fa90da 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -183,9 +183,9 @@ struct windows_thread_info /* The context of the thread, including any manipulations. */ union { - CONTEXT context {}; + CONTEXT *context = nullptr; #ifdef __x86_64__ - WOW64_CONTEXT wow64_context; + WOW64_CONTEXT *wow64_context; #endif }; @@ -204,6 +204,10 @@ struct windows_thread_info /* The name of the thread. */ gdb::unique_xmalloc_ptr name; + + /* The buffer for the thread context, including any XState registers if + available. */ + gdb::unique_xmalloc_ptr context_buffer; }; enum handle_exception_result @@ -313,15 +317,19 @@ struct windows_process_info const char *pid_to_exec_file (int); + /* Allocate the context buffer for this thread. */ + + void initialize_context (windows_thread_info *th); + template auto with_context (windows_thread_info *th, Function function) { #ifdef __x86_64__ if (wow64_process) - return function (th != nullptr ? &th->wow64_context : nullptr); + return function (th != nullptr ? th->wow64_context : nullptr); else #endif - return function (th != nullptr ? &th->context : nullptr); + return function (th != nullptr ? th->context : nullptr); } DWORD *context_flags_ptr (windows_thread_info *th) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index def8fa606f4..4cd301d4959 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -515,6 +515,7 @@ windows_nat_target::add_thread (ptid_t ptid, HANDLE h, void *tlb, #endif windows_private_thread_info *th = new windows_private_thread_info (windows_process, ptid.lwp (), h, base); + windows_process->initialize_context (th); /* Add this new thread to the list of threads. diff --git a/gdbserver/win32-aarch64-low.cc b/gdbserver/win32-aarch64-low.cc index 5a7b72155db..e94548b6fef 100644 --- a/gdbserver/win32-aarch64-low.cc +++ b/gdbserver/win32-aarch64-low.cc @@ -169,7 +169,7 @@ aarch64_initial_stuff (process_info *proc) static void aarch64_get_thread_context (windows_thread_info *th) { - CONTEXT *context = &th->context; + CONTEXT *context = th->context; context->ContextFlags = (WindowsContext::full | WindowsContext::floating @@ -193,7 +193,7 @@ aarch64_prepare_to_resume (windows_thread_info *th) { win32_require_context (th); - CONTEXT *context = &th->context; + CONTEXT *context = th->context; for (int i = 0; i < aarch64_num_bp_regs; i++) { @@ -223,7 +223,7 @@ aarch64_thread_added (windows_thread_info *th) static void aarch64_single_step (windows_thread_info *th) { - th->context.Cpsr |= 0x200000; + th->context->Cpsr |= 0x200000; } /* An array of offset mappings into a Win32 Context structure. @@ -322,7 +322,7 @@ aarch64_fetch_inferior_register (struct regcache *regcache, int mappings_count; get_mappings (mappings, mappings_count); - char *context_ptr = (char *) &th->context; + char *context_ptr = (char *) th->context; char *context_offset; if (r < mappings_count) context_offset = context_ptr + mappings[r]; @@ -341,7 +341,7 @@ aarch64_store_inferior_register (struct regcache *regcache, int mappings_count; get_mappings (mappings, mappings_count); - char *context_ptr = (char *) &th->context; + char *context_ptr = (char *) th->context; char *context_offset; if (r < mappings_count) context_offset = context_ptr + mappings[r]; diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 7629beca213..3d85faf0785 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -152,6 +152,7 @@ child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb) base += 2 * 4096; /* page size = 4096 */ #endif th = new windows_thread_info (&windows_process, tid, h, base); + windows_process.initialize_context (th); find_process_pid (pid)->add_thread (ptid, th); -- 2.54.0