From patchwork Thu Sep 30 16:43:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1534955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=jiixG3Ix; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HKzfz0Pb0z9sRf for ; Fri, 1 Oct 2021 02:47:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3162385842B for ; Thu, 30 Sep 2021 16:47:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3162385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633020424; bh=/nQLqLJaP08T/uSvHRksNvxF3E4UOrVFbgHQh3TdQ9A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jiixG3IxgLHmJqmRkUkSV11FFGetKYK4pXZ/EsWpRpEISAmgTEl53jG4EbeDO+NXK tFQOMkjsSPxxH6yYJg7+FltjvtH35tOc10hzlHwSFFtpOVUS7if88uflk6fepuzvzi l+SCoGMWV020k9+PB/f1vgPhdpWhn5ikoaio93EE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by sourceware.org (Postfix) with ESMTPS id 9E6E0385842F for ; Thu, 30 Sep 2021 16:43:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E6E0385842F Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4HKzb55VKBzQlXv; Thu, 30 Sep 2021 18:43:45 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de To: gcc-patches@gcc.gnu.org Subject: [committed] libphobos: Print stacktrace before terminating program due to uncaught exception. Date: Thu, 30 Sep 2021 18:43:41 +0200 Message-Id: <20210930164341.2838182-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: AA0AC18B8 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch adds adjusts the `throw' entrypoint to print the stacktrace of an uncaught exception before terminating. By default, D run-time has a top level exception handler to catch anything that was uncaught by user code. However when the `rt_trapExceptions' flag is cleared, this handler would not be enabled, and this termination would occur, aborting the program, but without any information about the exception. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and committed to mainline. Regards Iain --- libphobos/ChangeLog: * libdruntime/gcc/deh.d (_d_print_throwable): Declare. (_d_throw): Print stacktrace before terminating program due to uncaught exception. --- libphobos/libdruntime/gcc/deh.d | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libphobos/libdruntime/gcc/deh.d b/libphobos/libdruntime/gcc/deh.d index eb83751c59d..a7eb37cfd9e 100644 --- a/libphobos/libdruntime/gcc/deh.d +++ b/libphobos/libdruntime/gcc/deh.d @@ -34,6 +34,7 @@ extern(C) { int _d_isbaseof(ClassInfo, ClassInfo); void _d_createTrace(Object, void*); + void _d_print_throwable(Throwable t); } /** @@ -510,7 +511,11 @@ extern(C) void _d_throw(Throwable object) // things, almost certainly we will have crashed before now, rather than // actually being able to diagnose the problem. if (r == _URC_END_OF_STACK) + { + __gdc_begin_catch(&eh.unwindHeader); + _d_print_throwable(object); terminate("uncaught exception", __LINE__); + } terminate("unwind error", __LINE__); }