From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cbgcJMF7U2q+NQQAWB0awg (envelope-from ) for ; Sun, 12 Jul 2026 07:34:25 -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=F365L0NV; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8E5471E098; Sun, 12 Jul 2026 07:34:25 -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 [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 DFA3A1E070 for ; Sun, 12 Jul 2026 07:34:24 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A93624BA2E05 for ; Sun, 12 Jul 2026 11:34:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A93624BA2E05 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=F365L0NV Received: from sonic305-19.consmr.mail.ir2.yahoo.com (sonic305-19.consmr.mail.ir2.yahoo.com [77.238.177.81]) by sourceware.org (Postfix) with ESMTPS id B0A8A4BA2E09 for ; Sun, 12 Jul 2026 11:32:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0A8A4BA2E09 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 B0A8A4BA2E09 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=77.238.177.81 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783855965; cv=none; b=nY/Ab6bWkckMdJBSf4L6C/PM3AosNr4PEFty+mZyLzxi/x7iaTEvM8OWo1mo9Ayj5jNV3qhn2BB3EFuDOXOtbIVe8fHoQRSv3GPFgZkLpnHzrq2xsuLQf8MWq6Br1wlbvH456hSc3esfCLPsKJxcY2ct4wMcT3qtrnedKMbUWWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783855965; c=relaxed/simple; bh=YqR7Yi7BKb6p+2oRWkoSWVtFm5UQg6iC3FZval1rBKc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BkCC1soYLzEwGysvkZbJHjSsS0gPt8r2jHWUAZTgkhVNDbXyRC+nriyQY9qQ/Y7Z47bdHjd0PGdXxxSrGd0/ZBDyxDIL2eTOlo5qDVspelmPBtyrh7P/j39q7NtvcE6CYLNxnOyFUe7dXtkKD7gI5n583WpXZXjSq2Co7S4OCVo= ARC-Authentication-Results: i=1; sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1783855962; bh=m3mnSKnXIp7uCHZDJhB1BWM07kRhuTcrT8WrJ895j+0=; h=From:To:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=F365L0NVImDAMaF4AosiRpsxDLr+xzhGZHIcTV703e9gAHDPOu7SeQnYXZrPOURwfatvh8Y/X8OVkW/lu8gx3OcSDMd+oHeeepHnsJ8cA/5WCaOCe5A7LEGID0JiP6QPMYU9uIql14PHDjKIcfSgevBkUtfJE0E7uqkdEDfZh/socOLVj7rAh2Yc5MpqH9YT5RVYA8t00YtTE4wG7Koy7PzUCMytPiYD4agzCLZ00EV55aNoMcaTatKCHXnUFGvQXX85GxjEFFV8JpJUK9l9P28jrT46iIxLI+sDUt0Ns+JzrGiVJ6xmTlDmmT5hz+N/EdaCk0NYS9akt9fkD0PKzA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1783855962; bh=Kz4YZdJlf0Nysk4E9NToTIczxgLpCQdt1JQXznTashT=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=Uyy8wHLrBoJ0TI9CMheT6rZvzWsXIn6Hh658TgjqhOnQNBFsaKz6ciqgU3qim2iN8JyOdJrItsk3wCrjNCLmQ3iOCzrZIjYH95urnidykIcRQkXT07efkF+VRcBhUGM9BToQ25OqFp4z9/dYdBTeepcyC9iXnDAV2LUES93bmSsjrmhpKMoLAxIjRGSBfnz2IQkswQw/CkVk9yxjfSrEJTMOo0JUFiXbs6TjnZv9do3eTaylqKEv6DAOF4JJOZOMO0T0mfQG1cGPmonfniikEITRkanrIC4IA2q/K4+bRF6ceFFdTSrZnMYozPMdVA97j/7QRibnWS4oQj8G/PUl3g== X-YMail-OSG: t5eFEqIVM1kItk_iBYRgvDrsmqbcPeSIO3I_gm50TstfQvCRFMmCnXE2o3XX8.2 7WE49.JH2_DqH9pM47RsbyRFZegEfdI83NLTZ6nqLrfuRUrTiAaIFp_qQq.9Jt5AAPrsZlFzgeiq TZ_k_7qTyxVDc3aIbQHUOSYVhqsHv5e3OEIwAUuoxX0ybrkaN8y6jBH65VG44pDVqmS_toAg1Of0 elpN2.36kBCBHpEISbUoblDibaYdAq.pJRGSaV3JppcmnrCYeh3eYReyTjbBm8D7wo4DrpqzVV_f 4ACXwXdIJT5Yf8Mmpr_bTSB3uyZiaAxBpT8hjk745w0bLK79IxojaMup_JQSGDs9mlwn8pIWTyW. 1tvQZ_IBWyzn28SuF7P73kjVzsfB_0Koka3PP74jfIvNU1XF1wBJRF6R92G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wv9JSFJRr.rTrjy.o9rNyh1E5QH9Lu6YKqjeo5Ovg1m9A90fh0WrSBYlqP gtHEb9yc6xnx_RYmvXBAKfkKFl3UPs6zAVca9ELPN80fYroy4cfpIUnCL3eJSVppx7OiE64XUPq. kTjFkfmv7LmSP7NByXsE9B5t.T_JKWjV5CZJzXEt6IjF_2UrMIz61S_qR6ojZ6ovRAmXQq9VTP.W 3ephzQkIXvbQGtEQlCHt_f8i6CRDFBdqCOUe6EQr4Vpk5dEkFYhUwXfUe5vfP7bY4PnmVNzHwfxs 7HEMaP6Ztd7zDm5L5eGddwEqJ_zRp1NjbGG4wSdRZj5D05OPrQ4pWC6AXiub6GygFlKceFvRb2xy rgbQQzC2c4RjldsraJtnsqbuEzbhb5pGjMOrLZjAHnDm4xnlBkpmWBFdy1BgqJhVBN43Uuo7FLl. KQbhual4PavrsvYxATcCGaa50m.1IlAp6SUJ.msSaRQdANzV70z8ZWukMXwjYNge.mJhrpUSvZsr XTwj7UGC4VzvMx4Zgl34O6a4pms1BXrwAJkc.4hcCZKqm3wJ1CV.9S.hatMhEbbT38I9t8_fN.wM 8IqIf5Ln_r1c.vbNHr7UYBXeHox8BH6z0eRcIpCJbozAiBDg_fhGmidT03h8Z35rUvkLcd5b1VBf 63Sr6yDFyD2URC4oh6zbgGyr.LnkFQ.D0kTNjxxSbBSDtZbByWonUDneu0Bx5.IE25aZdRliXblb hxJGqBah9ovvTB6a3uBIR_Hj8 X-Sonic-MF: X-Sonic-ID: 4d6d2930-4d19-4c15-9213-418faf02ae6d Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ir2.yahoo.com with HTTP; Sun, 12 Jul 2026 11:32:42 +0000 Received: by hermes--production-ir2-7b48fcd765-7kk6w (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8f842386f7843a8cccfcf644a1266621; Sun, 12 Jul 2026 11:32:38 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH 2/8] Windows gdb: Use allocated buffer for CONTEXT Date: Sun, 12 Jul 2026 13:32:23 +0200 Message-ID: <20260712113229.3695246-2-ssbssa@yahoo.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260712113229.3695246-1-ssbssa@yahoo.de> References: <20260712113229.3695246-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