From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by sourceware.org (Postfix) with ESMTPS id 664183858C35 for ; Tue, 7 May 2024 23:42:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 664183858C35 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 664183858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125382; cv=none; b=qgeHpyYmhvAlTWQoasrps7K/C49kNscOVoVNiuugyq5f4zMN6dYeSZxq1pAErc/FsdVS+5brnzk9RZVVR05ZhbmhNo2z8LotdtTfTuIs85wuxe8eDRZywZ0mN55o8433rw4mGDmpWMwA1fq5+cFVl9CSb5na4p87kJbuAJOkAMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125382; c=relaxed/simple; bh=s//awNJYpJt+sOLacmhiV7R3n5lqF6ygNm20+MH8L70=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=L2pX4waS4og2TsIZAY5+Qr0BJyx+eRbDlqsaNC5nwXHYmJSZcPvQ87xo580Iblpn0mf3uZMXnYZgCvP8PmZNNjfH/MoXYI/z7tcy4j/OS7gps+LFg5iDac3SUBAZ5M9L2DD2G0bR9yAtih2I6QA3zT3+pohk2DEzZl0DnXZtIaY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-41ba1ba5592so25497585e9.1 for ; Tue, 07 May 2024 16:42:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715125378; x=1715730178; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kucXCdGP35ZsCySn5EgX2Z53kTekItTHALRs4fq2ntI=; b=VO+gW19HyY1wjGYzipfpm7gh+XjIcJD9SkBJ4mUH9b3tzODJjRc52WhUHhSktjKM1D a04MlFuScHiqJFqiLizMyzzJ57hfw2Uk53x0ypvIuaia3GUzsLVw0raNmwMLAZ3Hkw5J e/3vUz3EjqHb20i3u3QsSUcjgNT9YCcz8JZ9DmE/KG814jUTz9WNzvH8w51OBtSgQeVu 1Dg0+S1E5xxrLJH/5d0n7QYw9t+iRt8bTBYZo/uKv+1oo4BiwjE7VeHYA1c52/LkCGwI Ca8V0ZnNbqu15Me8PAJTOVpsR6OTCkUPfnxw/h5FBTQISpt8wvWciX0q+SIbXCCfeFQP 03tA== X-Gm-Message-State: AOJu0Yxh5amommVFm/Ix/8UjUsWum77a+FBJFAgi37M4KjHCrU6l6Pqi rCgY3GrqNT9pXoiejNEAawbmv/E+Ov6Cu/zsf40R4VR7hAzpLdKPuIXrnIa1 X-Google-Smtp-Source: AGHT+IGym0eDoqy6nJ2KmKbcKKThDSQXpyaP4GzIrjsO4RGrNrGXbLmnftGbcRr121TEZ0URl73B7Q== X-Received: by 2002:a05:600c:444e:b0:418:792d:f8b4 with SMTP id 5b1f17b1804b1-41f71ec2a14mr9524905e9.23.1715125378030; Tue, 07 May 2024 16:42:58 -0700 (PDT) Received: from localhost ([2001:8a0:f908:4900:2dd1:1a0d:2b75:dc42]) by smtp.gmail.com with UTF8SMTPSA id a14-20020a05600c224e00b0041c012ca327sm188115wmm.45.2024.05.07.16.42.57 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 May 2024 16:42:57 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 06/34] Windows gdb+gdbserver: Eliminate thread_rec(INVALIDATE_CONTEXT) calls Date: Wed, 8 May 2024 00:42:05 +0100 Message-ID: <20240507234233.371123-7-pedro@palves.net> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240507234233.371123-1-pedro@palves.net> References: <20240507234233.371123-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Replace thread_rec(INVALIDATE_CONTEXT) calls with find_thread, and invalidate_context / suspend calls in the spots that might need those. I don't know why does the INVALIDATE_CONTEXT implementation in GDB avoid suspending the event thread: case INVALIDATE_CONTEXT: if (ptid.lwp () != current_event.dwThreadId) th->suspend (); Checks for a global "current_event" get in the way of non-stop support later in the series, as each thread will have its own "last debug event". Regardless, it should be fine to suspend the event thread. As a data point, the GDBserver implementation always suspends. So this patch does not try to avoid suspending the event thread on the native side either. Change-Id: I8d2f0a749d23329956e62362a7007189902dddb5 --- gdb/nat/windows-nat.h | 2 -- gdb/windows-nat.c | 38 ++++++++++++++++++++++---------------- gdbserver/win32-low.cc | 8 ++++---- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 41921aa653b..0e2093ee06d 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -103,8 +103,6 @@ enum thread_disposition_type { /* Invalidate the context, but do not suspend the thread. */ DONT_SUSPEND, - /* Invalidate the context and suspend the thread. */ - INVALIDATE_CONTEXT }; /* A single pending stop. See "pending_stops" for more diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 3888ab6a02c..f53a45f657f 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -547,11 +547,6 @@ windows_per_inferior::thread_rec { switch (disposition) { - case INVALIDATE_CONTEXT: - if (ptid.lwp () != current_event.dwThreadId) - th->suspend (); - invalidate_context (th); - break; case DONT_SUSPEND: th->suspended = -1; invalidate_context (th); @@ -724,8 +719,7 @@ windows_fetch_one_register (struct regcache *regcache, void windows_nat_target::fetch_registers (struct regcache *regcache, int r) { - windows_thread_info *th - = windows_process.thread_rec (regcache->ptid (), INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (regcache->ptid ()); /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -737,6 +731,7 @@ windows_nat_target::fetch_registers (struct regcache *regcache, int r) { if (th->wow64_context.ContextFlags == 0) { + th->suspend (); th->wow64_context.ContextFlags = CONTEXT_DEBUGGER_DR; CHECK (Wow64GetThreadContext (th->h, &th->wow64_context)); } @@ -746,6 +741,7 @@ windows_nat_target::fetch_registers (struct regcache *regcache, int r) { if (th->context.ContextFlags == 0) { + th->suspend (); th->context.ContextFlags = CONTEXT_DEBUGGER_DR; CHECK (GetThreadContext (th->h, &th->context)); } @@ -770,11 +766,23 @@ windows_store_one_register (const struct regcache *regcache, { gdb_assert (r >= 0); - char *context_ptr = (char *) &th->context; + DWORD context_flags; + char *context_ptr; + #ifdef __x86_64__ if (windows_process.wow64_process) - context_ptr = (char *) &th->wow64_context; + { + context_flags = th->wow64_context.ContextFlags; + context_ptr = (char *) &th->wow64_context; + } + else #endif + { + context_flags = th->context.ContextFlags; + context_ptr = (char *) &th->context; + } + + gdb_assert (context_flags != 0); struct gdbarch *gdbarch = regcache->arch (); i386_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); @@ -807,8 +815,7 @@ windows_store_one_register (const struct regcache *regcache, void windows_nat_target::store_registers (struct regcache *regcache, int r) { - windows_thread_info *th - = windows_process.thread_rec (regcache->ptid (), INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (regcache->ptid ()); /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -1544,7 +1551,8 @@ windows_nat_target::get_windows_debug_event *ourstatus = stop->status; ptid_t ptid (windows_process.current_event.dwProcessId, thread_id); - windows_process.thread_rec (ptid, INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (ptid); + windows_process.invalidate_context (th); return ptid; } @@ -1765,8 +1773,7 @@ windows_nat_target::get_windows_debug_event && windows_process.windows_initialization_done) { ptid_t ptid = ptid_t (current_event->dwProcessId, thread_id, 0); - windows_thread_info *th - = windows_process.thread_rec (ptid, INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (ptid); th->stopped_at_software_breakpoint = true; th->pc_adjusted = false; } @@ -1804,8 +1811,7 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, if (ourstatus->kind () != TARGET_WAITKIND_EXITED && ourstatus->kind () != TARGET_WAITKIND_SIGNALLED) { - windows_thread_info *th - = windows_process.thread_rec (result, INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (result); if (th != nullptr) { diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 5d3ad38cdbb..b693da583b0 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -463,8 +463,8 @@ child_fetch_inferior_registers (struct regcache *regcache, int r) { int regno; windows_thread_info *th - = windows_process.thread_rec (current_thread_ptid (), - INVALIDATE_CONTEXT); + = windows_process.find_thread (current_thread_ptid ()); + win32_require_context (th); if (r == -1 || r > NUM_REGS) child_fetch_inferior_registers (regcache, NUM_REGS); else @@ -479,8 +479,8 @@ child_store_inferior_registers (struct regcache *regcache, int r) { int regno; windows_thread_info *th - = windows_process.thread_rec (current_thread_ptid (), - INVALIDATE_CONTEXT); + = windows_process.find_thread (current_thread_ptid ()); + win32_require_context (th); if (r == -1 || r == 0 || r > NUM_REGS) child_store_inferior_registers (regcache, NUM_REGS); else -- 2.43.2