From patchwork Tue May 7 23:42:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 89694 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1C0F3849AD1 for ; Tue, 7 May 2024 23:46:48 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by sourceware.org (Postfix) with ESMTPS id 9BFB83846079 for ; Tue, 7 May 2024 23:43:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BFB83846079 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 9BFB83846079 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125398; cv=none; b=nc7v0bBDbE1vwvu6jSKckB/+6T1McHLiNoO2BpTfx1oDlb+EwQQzmbao0OMD52DUWeTkK5tGJQKAcP2ISQop68j8UGCFccePnc65NrS5VUG0XYtiGuxQj9oSpazA92nupX7HpRRJKoVQonfakBA7m9Kf40DhJ+8Q95J6x52R43w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125398; c=relaxed/simple; bh=YQSCfTpQRF45pPJ2kH+uVHmXIYzU3f0zBnmIap+k6ZI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fqHVrQRAeWxkRnLKP5OFrIFt0VQTbMCht50AuYr7bnTzKT7xE+al4bYS+3rET4am3Woblp6KJZ9EFEXAKgrdY2PEySP3wRqQxCnPORVQmhLbiSfOduGuyV5g8TXKk127ZgimXWfNp7ljHtp1A7RQfZxZjIgcC6c1BQUtANtcFhA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-34da35cd01cso3418211f8f.2 for ; Tue, 07 May 2024 16:43:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715125394; x=1715730194; 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=dcSHXAbYgSrhpYAOj/mn2wtFT91gX3XpfwpVu4ifOy8=; b=vy9+1iLj6iwLxNzcap/9wGg0+N1jfKF9ZrZUVLinXqKCRB/UDYoems6Ccxp/nOK2i0 jB+Pe2gBNjxJvNeBnBZZsMM3jdrYcO5l+BXiy3AdFzcTFfm41WIXUww0nIjIKydRTWrb g8bui/TW7ouEJUV0HzRQev1taEuU5b928n7EQnkY55iF9+uPwJ4cVcMKTvN6N8gCC3KG 5laIjS9uT9E1mqAO1yBzA+3mSDbnR7OvLqqusQ7/NN7q2F1mD8jOuQ0+9HfI0G64I2Dt r+APjRUGd8Qwr2GVrob0nmZO/wh7uHoNtX4F5+p6xAg7Ta8HXWnYByqTEhp93NU1o2GU rImg== X-Gm-Message-State: AOJu0YwiUM77Iesw5sCMQW5c0QtylUz3kTvLEFhHf61Zg0uuFz3Sa0Rw qKE/Sdgtd8khk2+cArVgwiFVWIvUG8+MEX9DC6gnIdtQKn6yovOpedwJOumn X-Google-Smtp-Source: AGHT+IFbREQZeAWDS/StVM1TkP9Ft4RScN4V1v/FKMIeI7P0IZWsrWke/oaPF5f4WwDBp/hcgVryEQ== X-Received: by 2002:adf:fc8e:0:b0:34d:b634:9033 with SMTP id ffacd0b85a97d-34fca621da5mr932566f8f.51.1715125394226; Tue, 07 May 2024 16:43:14 -0700 (PDT) Received: from localhost ([2001:8a0:f908:4900:2dd1:1a0d:2b75:dc42]) by smtp.gmail.com with UTF8SMTPSA id u17-20020a5d4351000000b0034fda441600sm333426wrr.39.2024.05.07.16.43.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 May 2024 16:43:13 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 12/34] Windows gdb: Introduce windows_continue_flags Date: Wed, 8 May 2024 00:42:11 +0100 Message-ID: <20240507234233.371123-13-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 X-Spam-Status: No, score=-10.7 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 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+patchwork=sourceware.org@sourceware.org windows_continue already has two boolean parameters: (..., int killed, bool last_call = false) A patch later in the series would need a third. Instead, convert windows_continue to use an optional enum-flags parameter instead of multiple booleans. Change-Id: I17c4d8a12b662190f972c380f838cb3317bd2e1e --- gdb/windows-nat.c | 48 ++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 93ba7850c88..3993820ddab 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -88,6 +88,22 @@ struct windows_solib std::string name; }; +/* Flags that can be passed to windows_continue. */ + +enum windows_continue_flag + { + /* This means we have killed the inferior, so windows_continue + should ignore weird errors due to threads shutting down. */ + WCONT_KILLED = 1, + + /* This means we expect this windows_continue call to be the last + call to continue the inferior -- we are either mourning it or + detaching. */ + WCONT_LAST_CALL = 2, + }; + +DEF_ENUM_FLAGS_TYPE (windows_continue_flag, windows_continue_flags); + struct windows_per_inferior : public windows_process_info { windows_thread_info *find_thread (ptid_t ptid) override; @@ -332,8 +348,8 @@ struct windows_nat_target final : public x86_nat_target void delete_thread (ptid_t ptid, DWORD exit_code, bool main_thread_p); DWORD fake_create_process (); - BOOL windows_continue (DWORD continue_status, int id, int killed, - bool last_call = false); + BOOL windows_continue (DWORD continue_status, int id, + windows_continue_flags cont_flags = 0); /* Helper function to start process_thread. */ static DWORD WINAPI process_thread_starter (LPVOID self); @@ -1258,14 +1274,12 @@ windows_per_inferior::handle_access_violation } /* Resume thread specified by ID, or all artificially suspended - threads, if we are continuing execution. KILLED non-zero means we - have killed the inferior, so we should ignore weird errors due to - threads shutting down. LAST_CALL is true if we expect this to be - the last call to continue the inferior -- we are either mourning it - or detaching. */ + threads, if we are continuing execution. See + windows_continue_flags' description for CONT_FLAGS. */ + BOOL windows_nat_target::windows_continue (DWORD continue_status, int id, - int killed, bool last_call) + windows_continue_flags cont_flags) { windows_process.desired_stop_thread_id = id; @@ -1308,7 +1322,7 @@ windows_nat_target::windows_continue (DWORD continue_status, int id, BOOL status = Wow64SetThreadContext (th->h, &th->wow64_context); - if (!killed) + if ((cont_flags & WCONT_KILLED) == 0) CHECK (status); } th->wow64_context.ContextFlags = 0; @@ -1337,7 +1351,7 @@ windows_nat_target::windows_continue (DWORD continue_status, int id, { BOOL status = SetThreadContext (th->h, &th->context); - if (!killed) + if ((cont_flags & WCONT_KILLED) == 0) CHECK (status); } th->context.ContextFlags = 0; @@ -1348,7 +1362,7 @@ windows_nat_target::windows_continue (DWORD continue_status, int id, continue_last_debug_event_main_thread (_("Failed to resume program execution"), continue_status, - last_call); + cont_flags & WCONT_LAST_CALL); return TRUE; } @@ -1464,9 +1478,9 @@ windows_nat_target::resume (ptid_t ptid, int step, enum gdb_signal sig) Otherwise complain. */ if (resume_all) - windows_continue (continue_status, -1, 0); + windows_continue (continue_status, -1); else - windows_continue (continue_status, ptid.lwp (), 0); + windows_continue (continue_status, ptid.lwp ()); } /* Interrupt the inferior. */ @@ -2174,7 +2188,7 @@ windows_nat_target::detach (inferior *inf, int from_tty) if (m_continued) break_out_process_thread (process_alive); - windows_continue (DBG_CONTINUE, -1, 0, true); + windows_continue (DBG_CONTINUE, -1, WCONT_LAST_CALL); std::optional err; if (process_alive) @@ -2922,13 +2936,13 @@ windows_nat_target::create_inferior (const char *exec_file, do_initial_windows_stuff (pi.dwProcessId, 0); - /* windows_continue (DBG_CONTINUE, -1, 0); */ + /* windows_continue (DBG_CONTINUE, -1); */ } void windows_nat_target::mourn_inferior () { - (void) windows_continue (DBG_CONTINUE, -1, 0, true); + windows_continue (DBG_CONTINUE, -1, WCONT_LAST_CALL); x86_cleanup_dregs(); if (windows_process.open_process_used) { @@ -2986,7 +3000,7 @@ windows_nat_target::kill () for (;;) { - if (!windows_continue (DBG_CONTINUE, -1, 1)) + if (!windows_continue (DBG_CONTINUE, -1, WCONT_KILLED)) break; wait_for_debug_event_main_thread (&windows_process.current_event); if (windows_process.current_event.dwDebugEventCode