From patchwork Fri Nov 21 03:59:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 3826 Received: (qmail 15859 invoked by alias); 21 Nov 2014 03:59:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 15845 invoked by uid 89); 21 Nov 2014 03:59:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 21 Nov 2014 03:59:50 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id B9BA62B732AE for ; Fri, 21 Nov 2014 04:59:45 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t7Dr4PHRCBVk for ; Fri, 21 Nov 2014 04:59:45 +0100 (CET) Received: from chelles.act-europe.fr (chelles.act-europe.fr [10.10.0.160]) by smtp.eu.adacore.com (Postfix) with ESMTP id A96582B732AA for ; Fri, 21 Nov 2014 04:59:45 +0100 (CET) Received: by chelles.act-europe.fr (Postfix, from userid 507) id A353A1EA37EE; Fri, 21 Nov 2014 04:59:45 +0100 (CET) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [PATCH] Lift DWARF unwinder restriction in dwarf2-frame.c::dwarf2_frame_cfa Date: Fri, 21 Nov 2014 04:59:35 +0100 Message-Id: <1416542375-742-1-git-send-email-brobecker@adacore.com> Hello, GDB is currently broken on all SPARC targets when using GCC 4.9. When trying to print any local variable: (gdb) p x can't compute CFA for this frame This is related to the fact that the compiler now generates DWARF 4 debugging info by default, and in particular that it now emits DW_OP_call_frame_cfa, which triggers a limitation in dwarf2_frame_cfa: /* This restriction could be lifted if other unwinders are known to compute the frame base in a way compatible with the DWARF unwinder. */ if (!frame_unwinder_is (this_frame, &dwarf2_frame_unwind) && !frame_unwinder_is (this_frame, &dwarf2_tailcall_frame_unwind)) error (_("can't compute CFA for this frame")); We couldn't append the dwarf2 unwinder to all SPARC targets because it does not work properly with StackGhost: https://www.sourceware.org/ml/gdb-patches/2014-07/msg00012.html We also later discovered that using the DWARF2 unwinder means using it for computing the function's return address, which is buggy when it comes to functions returning a struct (where the return address is saved-pc+12 instead of saved-pc+8). This is because GCC is emitting the info about the return address as %o7/%i7 instead of the actual return address. For functions that have debugging info, we compensate by looking at the function's return type and add the extra +4, but for function without debug info, we're stuck. EricB and I twisted the issue in all the directions we could think of, and unfortunately couldn't find a way to make it work without introduction one regression or another. But, stepping back a little, just removing the restriction seems to work well for us on all both sparc-elf and {sparc,sparc64}-solaris. After reviewing the previous discussions about this test, I could not figure out whether some unwinders were already known to have incompatible CFAs or if the concern was purely theoretical: https://www.sourceware.org/ml/gdb-patches/2009-06/msg00191.html https://www.sourceware.org/ml/gdb-patches/2009-07/msg00570.html https://www.sourceware.org/ml/gdb-patches/2009-09/msg00027.html At the moment, we took the approach of trying it out, and see what happens... gdb/ChangeLog: PR backtrace/16215: * dwarf2-frame.c (dwarf2_frame_cfa): Remove the restriction the frame unwinder must either be the dwarf2_frame_unwind or the dwarf2_tailcall_frame_unwind. Verify that this_frame's stack_addr is valid before calling get_frame_base. Throw an error if not valid. Tested on sparc-solaris and sparc-elf with AdaCore's testsuite (the FSF testsuite crashes all of AdaCore's solaris machines). OK to commit? Thank you, diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c index 80e5903..30a24c8 100644 --- a/gdb/dwarf2-frame.c +++ b/gdb/dwarf2-frame.c @@ -1512,12 +1512,12 @@ dwarf2_frame_cfa (struct frame_info *this_frame) throw_error (NOT_AVAILABLE_ERROR, _("can't compute CFA for this frame: " "required registers or memory are unavailable")); - /* This restriction could be lifted if other unwinders are known to - compute the frame base in a way compatible with the DWARF - unwinder. */ - if (!frame_unwinder_is (this_frame, &dwarf2_frame_unwind) - && !frame_unwinder_is (this_frame, &dwarf2_tailcall_frame_unwind)) - error (_("can't compute CFA for this frame")); + + if (get_frame_id (this_frame).stack_status != FID_STACK_VALID) + throw_error (NOT_AVAILABLE_ERROR, + _("can't compute CFA for this frame: " + "frame base not available")); + return get_frame_base (this_frame); }