From patchwork Tue Feb 20 16:56:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 86042 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 E3E803858C39 for ; Tue, 20 Feb 2024 16:56:45 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by sourceware.org (Postfix) with ESMTPS id 5E4FD3858C5E for ; Tue, 20 Feb 2024 16:56:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E4FD3858C5E 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 5E4FD3858C5E 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=1708448178; cv=none; b=h7Pxdb8K1i4NI2MYVXjTf4iIjbOpXufLPDWyfxVJzdfWE2z6HM3seInqmQ6466vb54SwHUxb+pJnsi2Nfc/aTn7M3901MQuAY7OO2qQI6c5U5+DPJUbdM8Eb8l3qQFMVPmrh7lIfmxkeH7TnVlqphs1mSiMT9AYmxBZU7hHWJsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708448178; c=relaxed/simple; bh=/CVR481f56FjTbxdZJb47Dt5NrNIqL3+yPH2Y1DcicI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=c0fW2Ml1ZvOoZXU3fif9GaMn6uTrGw6C/xXng2KIt2h+tmDvMO4VChC4zkSJKbwj8DOeay75ysIY/shsEjaqei5vfiXP2Z765dsRYM8TJbBIKAp0sMwTWeZ+hW46ElmRwtDOfDIBjULE/jjTFHfS4+qQRBmiaJxWFkbuF2QLOLo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-33d2710f3acso2480915f8f.0 for ; Tue, 20 Feb 2024 08:56:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708448172; x=1709052972; 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=I+wQDV675fIayNW43gAwkkesVQWFmeuRjfFlKXfK7M0=; b=ltYZ31XqrZrcv1vHH+75gx5Hdf/Ayx3fGjKceI1RWy+Cw0mMIfmYplpRAN5FliiLFI ez9nRvgmzXAk21wPzIgeZU1KN0NU5ILl4Nw0NGxN4XqR8bPePcdYTFvV4JiIMN0hwFEm 9co2vT35gb2Gke48naeqIXdB2RpTEbbf86aShNELtN0LNBfk+VH+tou24PbKOenXA2Ro uuA1/xs8+Aaey2/oR1zCcSb3XYxWKrs5cTRdo8icjIJ+hR5OVpssjr7YzjXT0YlvoXkM ItWmptdvFdoaX994f+s+n9HSoXQEKCPbYmfTkfrUzmw7D9i6dMRrAr/wOEuvScaEfzd8 KrkQ== X-Gm-Message-State: AOJu0Ywzw+WphPJzuLfQQYlxjDFEGvxc6cbgdnqf6CQnWwRk/lWennQ5 zcxJ2Qoc/hImD5sAnt4R+hz8OcVztQxwTZt3uletL29nDebkYDJ0/0iHXHjqW6Y= X-Google-Smtp-Source: AGHT+IE84w3+L53VLUQptP04K59xFJ3NZb+AdcBUFJ5IEBK3Ywgdr6ngKSGTX25z57+RopEJzW+HqA== X-Received: by 2002:a5d:4404:0:b0:33d:e27:f053 with SMTP id z4-20020a5d4404000000b0033d0e27f053mr11627308wrq.6.1708448171881; Tue, 20 Feb 2024 08:56:11 -0800 (PST) Received: from localhost ([2001:8a0:f918:ab00:69e9:8530:3f47:315c]) by smtp.gmail.com with UTF8SMTPSA id p4-20020a5d4584000000b0033d66d51782sm3003117wrq.21.2024.02.20.08.56.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 08:56:11 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Drop special way of getting inferior context after a Cygwin signal Date: Tue, 20 Feb 2024 16:56:04 +0000 Message-ID: <20240220165605.563516-3-pedro@palves.net> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220165605.563516-1-pedro@palves.net> References: <20240220165605.563516-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 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, T_SCC_BODY_TEXT_LINE 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 From: Jon Turney Simplify Cygwin signal handling by dropping the special way of getting inferior context after a Cygwin signal. I think the reason this existed was because previously we were not able to unwind through the alternate stack used by _sigfe frames, so without the hint of the "user" code IP, the backtrace from a signal was unusable. Now we can unwind through _sigfe frames, drop all this complexity. (Restoring this specially obtained context to the inferior (as the code currently does) skips over the actual signal delivery and handling. Cygwin has carried for a long time a patch which clears the ContextFlags in the signal context, so we never attempt to restore it to the inferior, but that interfers with gdb's ability to modify that context e.g. if it decides it wants to turn on FLAG_TRACE_BIT.) Change-Id: I214edd5a99fd17c1a31ad18138d4a6cc420225e3 --- gdb/windows-nat.c | 52 ++++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 7f3044fc61d..a90388922e2 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -98,10 +98,6 @@ struct windows_per_inferior : public windows_process_info void handle_unload_dll () override; bool handle_access_violation (const EXCEPTION_RECORD *rec) override; - - int have_saved_context = 0; /* True if we've saved context from a - cygwin signal. */ - uintptr_t dr[8] {}; int windows_initialization_done = 0; @@ -140,9 +136,6 @@ struct windows_per_inferior : public windows_process_info std::vector solibs; #ifdef __CYGWIN__ - CONTEXT saved_context {}; /* Contains the saved context from a - cygwin signal. */ - /* The starting and ending address of the cygwin1.dll text segment. */ CORE_ADDR cygwin_load_start = 0; CORE_ADDR cygwin_load_end = 0; @@ -718,19 +711,6 @@ windows_nat_target::fetch_registers (struct regcache *regcache, int r) if (th->reload_context) { -#ifdef __CYGWIN__ - if (windows_process.have_saved_context) - { - /* Lie about where the program actually is stopped since - cygwin has informed us that we should consider the signal - to have occurred at another location which is stored in - "saved_context. */ - memcpy (&th->context, &windows_process.saved_context, - __COPY_CONTEXT_SIZE); - windows_process.have_saved_context = 0; - } - else -#endif #ifdef __x86_64__ if (windows_process.wow64_process) { @@ -1048,33 +1028,32 @@ windows_per_inferior::handle_output_debug_string #ifdef __CYGWIN__ else { - /* Got a cygwin signal marker. A cygwin signal is followed by - the signal number itself and then optionally followed by the - thread id and address to saved context within the DLL. If - these are supplied, then the given thread is assumed to have - issued the signal and the context from the thread is assumed - to be stored at the given address in the inferior. Tell gdb - to treat this like a real signal. */ + /* Got a cygwin signal marker. A cygwin signal marker is + followed by the signal number itself, and (since Cygwin 1.7) + the thread id, and the address of a saved context in the + inferior (That context has an IP which is the return address + in "user" code of the cygwin internal signal handling code, + but is not otherwise usable). + + Tell gdb to treat this like the given thread issued a real + signal. */ char *p; int sig = strtol (s.get () + sizeof (_CYGWIN_SIGNAL_STRING) - 1, &p, 0); gdb_signal gotasig = gdb_signal_from_host (sig); + LPCVOID x = 0; if (gotasig) { - LPCVOID x; - SIZE_T n; - ourstatus->set_stopped (gotasig); retval = strtoul (p, &p, 0); if (!retval) retval = current_event.dwThreadId; - else if ((x = (LPCVOID) (uintptr_t) strtoull (p, NULL, 0)) - && ReadProcessMemory (handle, x, - &saved_context, - __COPY_CONTEXT_SIZE, &n) - && n == __COPY_CONTEXT_SIZE) - have_saved_context = 1; + else + x = (LPCVOID) (uintptr_t) strtoull (p, NULL, 0); } + + DEBUG_EVENTS ("gdb: cygwin signal %d, thread 0x%x, CONTEXT @ %p", + gotasig, retval, x); } #endif @@ -1607,7 +1586,6 @@ windows_nat_target::get_windows_debug_event event_code = windows_process.current_event.dwDebugEventCode; ourstatus->set_spurious (); - windows_process.have_saved_context = 0; switch (event_code) {