From patchwork Tue Sep 8 12:21:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Storsjo X-Patchwork-Id: 249298 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp4500729ilg; Tue, 8 Sep 2020 05:22:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhlmbwvKwvNUYLlpbeXfecWWqBv3lH2XKdWdO01okWc6dJGcIFd7iEoiDNROP5PdQfiqUb X-Received: by 2002:a17:907:270f:: with SMTP id w15mr26810862ejk.141.1599567721587; Tue, 08 Sep 2020 05:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599567721; cv=none; d=google.com; s=arc-20160816; b=INGUEE4oVcAi2N7C2Y3DrgRB8D08E4oP/dlDmYkhvQS4ewgBXsxnD62a40JEoC1Ey2 iV2Dc6lrGHA+Oj1iFcKQVt6J8e7NOnyfHasniWYaV8NEVSWVeuJObbjXjrH27kEMi8ai qexPwjPMz+e7na+WcWTlmF2e3s+X5JZJzJW1nXVfd+fk6pNxb/n1T939KOyEU+ciQFrt VSaIJz75gp7dkT06FRwaDvetrWQlcnqviWANaRBxHCa3utT5ohpAXwjAXex03unJGBNH a/tGy4XhX9ADGObaCF3yCamAhZSGzPT+nzClp1TL8ANbLbvMJj6c7YR+yjwj9YjQhneg vzUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:dmarc-filter:delivered-to; bh=kv5fr48k23osHxE+9bmVwQN57dSB3A6kxYkaQyFASCs=; b=qOnpxYCGQimicSVYmEuBILZbGc9Jci0jHDqVl/cs7oS3hUj6h3kuCP1ynQkCyk5b8S iSVFmpejJNIaOtKvpEDaCiOeJQjkb3lgpSY2emJJTxHGarjF0TYkIHgZP1/qqWkbWyil FIjKg8YXDZqQ6z5ePD6j/OmgTWYIdPWZUNDJIrXtsQJXRvVceQrWmDT3G3KPAtZTxWJm 6Ff/p29NDkv/ShMKrI4ryRuXt25rLfqRb1dVmlKWKZ5jX9X0J/kceOqViZ2JdfpWmx3v v/HkgYBadIF+gE+3mb+U2xtC7YPWH0b/vLCQxd9IKkLhpmTkJ3vFtim1vqE0c72x3W55 QsJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@martin-st.20150623.gappssmtp.com header.s=20150623 header.b=qQGkIi3N; spf=pass (google.com: domain of gcc-patches-bounces@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom=gcc-patches-bounces@gcc.gnu.org Return-Path: Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id cf14si4413941ejb.441.2020.09.08.05.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 05:22:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@martin-st.20150623.gappssmtp.com header.s=20150623 header.b=qQGkIi3N; spf=pass (google.com: domain of gcc-patches-bounces@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom=gcc-patches-bounces@gcc.gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00FBE3951471; Tue, 8 Sep 2020 12:22:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by sourceware.org (Postfix) with ESMTPS id BC68E3870904 for ; Tue, 8 Sep 2020 12:21:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BC68E3870904 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=martin.st Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=martin@martin.st Received: by mail-lj1-x243.google.com with SMTP id k25so7165983ljk.0 for ; Tue, 08 Sep 2020 05:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=kv5fr48k23osHxE+9bmVwQN57dSB3A6kxYkaQyFASCs=; b=qQGkIi3NyaU3Vw/WJW24llo+rIseR+UglLyyHzA4HX+OYmkXpFL/QIodP7yJpUQcZ9 w2Ts03nZRv5QeICym20uTeLDpHGZzPu0iKvudaBQveUzXx+ztosoNAEgxesEvVyfV8dr FJrLOMKe9vrgkYnEUUHAL/PktOd7kvq2ZbvbBWJcNtMmKlmlYDS4gQmHLDSqhrpWNR/T +6o5NOn7eesnXA3vVDzWo0qwGlHS5hqEj7DKLOLYJi+h8sDTmDlAs+mdE0V8e7G4p2t3 BUX7rqytypkpXeCXoAOmuhmiu6NYjgJG1UT7KFQ2OcUlLvuFNr+F8V1nY1Gg5LZ/92Jk FJRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kv5fr48k23osHxE+9bmVwQN57dSB3A6kxYkaQyFASCs=; b=Jl0LBJXdk+vHe+OBgi/eIFPmlOsj/7sKd1lyaP29GhU0TSn8kb19MEJhBx+42BuENI 5UsQMEy5nRY/lRCgNp4O/n4w710lgnlkkjNzNC5ipMHykEN83eBQcCiJsmp6+9XC/jZP E8qrYNIAQswvr3vnkeH3X5Dfy0Fkut5Pf6wAYZ9iDPXyzH/F4KmQcZ9J78l9lFZQmxzA YBm6b+8h8bQOStpX4wJas6nZlObUiVnGNxBu3+3p+pF3Y4KCSln6sv9T+T9p6LP9ocoz GmWd53SVtLbrsJYSXPCMbOff9JXdfG4JrX/yx3xOCwwgt1n2TRA/CH0w6HJTUp3DHO4Q byYg== X-Gm-Message-State: AOAM530YMQss1rHbOcvWHJVAbf51Rg6cnNW01PGjiX//grQBZj4+XTat kgv24o/vi8Fc/dkyZ435E7TmsBNF+AFWaRZ3 X-Received: by 2002:a05:651c:104:: with SMTP id a4mr13068298ljb.273.1599567714843; Tue, 08 Sep 2020 05:21:54 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id v14sm10398394lfe.79.2020.09.08.05.21.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 05:21:54 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] libgcc: Expose the instruction pointer and stack pointer in SEH _Unwind_Backtrace Date: Tue, 8 Sep 2020 15:21:51 +0300 Message-Id: <20200908122151.14025-1-martin@martin.st> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200901130126.6266-1-martin@martin.st> References: <20200901130126.6266-1-martin@martin.st> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Previously, the SEH version of _Unwind_Backtrace did unwind the stack and call the provided callback function as intended, but there was little the caller could do within the callback to actually get any info about that particular level in the unwind. Set the ra and cfa pointers, which are used by _Unwind_GetIP and _Unwind_GetCFA, to allow using these functions from the callacb to inspect the state at each stack frame. 2020-09-08 Martin Storsjö libgcc/Changelog: * unwind-seh.c (_Unwind_Backtrace): Set the ra and cfa pointers before calling the callback. --- libgcc/unwind-seh.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.17.1 diff --git a/libgcc/unwind-seh.c b/libgcc/unwind-seh.c index 1a70180cfaa..275d782903a 100644 --- a/libgcc/unwind-seh.c +++ b/libgcc/unwind-seh.c @@ -466,6 +466,11 @@ _Unwind_Backtrace(_Unwind_Trace_Fn trace, &gcc_context.disp->HandlerData, &gcc_context.disp->EstablisherFrame, NULL); + /* Set values that the callback can inspect via _Unwind_GetIP + * and _Unwind_GetCFA. */ + gcc_context.ra = ms_context.Rip; + gcc_context.cfa = ms_context.Rsp; + /* Call trace function. */ if (trace (&gcc_context, trace_argument) != _URC_NO_REASON) return _URC_FATAL_PHASE1_ERROR;