From patchwork Thu Apr 30 17:30:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 466658 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 81848140320 for ; Fri, 1 May 2015 03:31:04 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=ZAe9o/WS; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=F7bcp4x9GiGnfQs5ng8k098KFu3qHa6IV4s9qz3QJwU5l5 2iCr2kvJVztEVHxEduZYBUBKJk/U2Z2Nco3aASJ29JuU0+AbMdWz7IHB6/HNKxDT fd0PLyPAlZHcms4vofMtfAnTYO3VIpHy++MU3rSWTFFIIs+y9JBCihcGpNg8g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=Rm8GXDq0LZgG4HwIipLUKILBLAQ=; b=ZAe9o/WS3db5MAhJ/i3R fVjsVrf45nVwKxUTy2Lq//pUKJQevt7g/Q0zzy4yhqQKmxDlUB3XiP1cVODD31F1 +kkl3Y1cYsrdzYe7ssh29Mea7ImcrZ6XDUaHHXK0CtR/uwsPHLRcn9uoTAhwg+X4 jJ2bL9Vc6RpPoMZRqGqs738= Received: (qmail 72377 invoked by alias); 30 Apr 2015 17:30:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 72365 invoked by uid 89); 30 Apr 2015 17:30:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 30 Apr 2015 17:30:53 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id B870B8E6F0 for ; Thu, 30 Apr 2015 17:30:52 +0000 (UTC) Received: from reynosa.quesejoda.com (vpn-59-57.rdu2.redhat.com [10.10.59.57]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3UHUpRK013522 for ; Thu, 30 Apr 2015 13:30:52 -0400 Message-ID: <554266CB.4040800@redhat.com> Date: Thu, 30 Apr 2015 10:30:51 -0700 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: gcc-patches Subject: [debug-early] document new world and fix non-dwarf debugging backends This patch adjusts the non-dwarf debugging back-ends to work in the new world. Particularly interesting is dbxout, which was generating specific debug information for constants not written to memory. For example, the following in C++: const int invisible = 0xC0FFEE; The new infrastructure never sees `invisible' because it doesn't make it to the symbol table, especially by the time late_global_decl runs. What I did for this case was to handle it through the early_global_decl() hook, which does see `invisible', though it lacks location information. However, since we don't need location information to represent this corner case, everything works fine and the pr23205-2.C stabs regression is fixed. I have also updated the documentation for the hooks to reflect reality. Committed to branch. Down to 3 sets of individual regressions in the testsuite. Yay. Aldy commit bb51ad83395536cc6efc151b6fe3f1fa0616d7a4 Author: Aldy Hernandez Date: Thu Apr 30 10:10:27 2015 -0700 Adjust non dwarf debugging backends for the debug-early infrastructure. diff --git a/gcc/dbxout.c b/gcc/dbxout.c index 0c9a327..9f555c3 100644 --- a/gcc/dbxout.c +++ b/gcc/dbxout.c @@ -1346,24 +1346,65 @@ dbxout_function_decl (tree decl) #endif /* DBX_DEBUGGING_INFO */ +/* Return true if a variable is really a constant and not written in + memory. */ + +static bool +decl_is_really_constant (tree decl) +{ + return ((TREE_CODE (decl) == VAR_DECL + || TREE_CODE (decl) == RESULT_DECL) + && !DECL_EXTERNAL (decl) + && TREE_STATIC (decl) + && TREE_READONLY (decl) + && DECL_INITIAL (decl) != 0 + && tree_fits_shwi_p (DECL_INITIAL (decl)) + && ! TREE_ASM_WRITTEN (decl) + && (DECL_FILE_SCOPE_P (decl) + || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK + || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL) + && TREE_PUBLIC (decl) == 0); +} + +/* Wrapper for dbxout_symbol that temporarily sets TREE_USED on the + DECL. */ + +static void +dbxout_symbol_used (tree decl) +{ + int saved_tree_used = TREE_USED (decl); + TREE_USED (decl) = 1; + dbxout_symbol (decl, 0); + TREE_USED (decl) = saved_tree_used; +} + +/* Output early debug information for a global DECL. Called from + rest_of_decl_compilation during parsing. */ + static void -dbxout_early_global_decl (tree decl ATTRIBUTE_UNUSED) +dbxout_early_global_decl (tree decl) { - /* NYI for non-dwarf. */ + /* True constant values may not appear in the symbol table, so they + will be missed by the late_global_decl hook. Handle these cases + now, since early_global_decl will get unoptimized symbols early + enough-- and besides, true constants don't need location + information, so it's ok to handle them earlier. */ + if (decl_is_really_constant (decl)) + dbxout_symbol_used (decl); } -/* Debug information for a global DECL. Called from toplev.c after - compilation proper has finished. */ +/* Output late debug information for a global DECL after location + information is available. */ + static void -dbxout_late_global_decl (tree decl) +dbxout_late_global_decl (tree decl ATTRIBUTE_UNUSED) { - if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)) - { - int saved_tree_used = TREE_USED (decl); - TREE_USED (decl) = 1; - dbxout_symbol (decl, 0); - TREE_USED (decl) = saved_tree_used; - } + if (TREE_CODE (decl) == VAR_DECL + && !DECL_EXTERNAL (decl) + /* Read-only constants were handled in + dbxout_early_global_decl. */ + && !decl_is_really_constant (decl)) + dbxout_symbol_used (decl); } /* This is just a function-type adapter; dbxout_symbol does exactly @@ -2904,14 +2945,7 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED) and not written in memory, inform the debugger. ??? Why do we skip emitting the type and location in this case? */ - if (TREE_STATIC (decl) && TREE_READONLY (decl) - && DECL_INITIAL (decl) != 0 - && tree_fits_shwi_p (DECL_INITIAL (decl)) - && ! TREE_ASM_WRITTEN (decl) - && (DECL_FILE_SCOPE_P (decl) - || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK - || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL) - && TREE_PUBLIC (decl) == 0) + if (decl_is_really_constant (decl)) { /* The sun4 assembler does not grok this. */ diff --git a/gcc/debug.h b/gcc/debug.h index 528ef3f..c360e5c 100644 --- a/gcc/debug.h +++ b/gcc/debug.h @@ -92,17 +92,37 @@ struct gcc_debug_hooks /* Debug information for a function DECL. This might include the function name (a symbol), its parameters, and the block that makes up the function's body, and the local variables of the - function. */ + function. + + This is only called for FUNCTION_DECLs. It is part of the late + debug pass and is called from rest_of_handle_final. + + Location information is available at this point. + + See the documentation for early_global_decl and late_global_decl + for other entry points into the debugging back-ends for DECLs. */ void (* function_decl) (tree decl); - /* Debug information for a global DECL. Called from the parser after - the parsing process has finished. */ + /* Debug information for a global DECL. Called from the parser + after the parsing process has finished. + + Location information is not available at this point, but it is a + good probe point to get access to symbols before they get + optimized away. + + This hook may be called on VAR_DECLs or FUNCTION_DECLs. It is up + to the hook to use what it needs. */ void (* early_global_decl) (tree decl); /* Augment debug information generated by early_global_decl with more complete debug info (if applicable). Called from toplev.c after the compilation proper has finished and cgraph information - is available. */ + is available. + + Location information is available at this point. + + This hook may be called on VAR_DECLs or FUNCTION_DECLs. It is up + to the hook to use what it needs. */ void (* late_global_decl) (tree decl); /* Debug information for a type DECL. Called from toplev.c after diff --git a/gcc/sdbout.c b/gcc/sdbout.c index be9c82e..1226f5b 100644 --- a/gcc/sdbout.c +++ b/gcc/sdbout.c @@ -1432,17 +1432,20 @@ sdbout_reg_parms (tree parms) } } +/* Output early debug information for a global DECL. Called from + rest_of_decl_compilation during parsing. */ + static void sdbout_early_global_decl (tree decl ATTRIBUTE_UNUSED) { /* NYI for non-dwarf. */ } -/* Output debug information for a global DECL. Called from toplev.c - after compilation proper has finished. */ +/* Output late debug information for a global DECL after location + information is available. */ static void -sdbout_late_global_decl (tree decl) +sdbout_late_global_decl (tree decl ATTRIBUTE_UNUSED) { if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl) diff --git a/gcc/vmsdbgout.c b/gcc/vmsdbgout.c index e18c5c3..7d70c1f 100644 --- a/gcc/vmsdbgout.c +++ b/gcc/vmsdbgout.c @@ -200,7 +200,7 @@ const struct gcc_debug_hooks vmsdbg_debug_hooks vmsdbgout_end_epilogue, vmsdbgout_begin_function, vmsdbgout_end_function, - vmsdbgout_decl, + vmsdbgout_function_decl, vmsdbgout_early_global_decl, vmsdbgout_late_global_decl, vmsdbgout_type_decl, /* type_decl */ @@ -1515,7 +1515,7 @@ vmsdbgout_undef (unsigned int lineno, const char *buffer) /* Not implemented in VMS Debug. */ static void -vmsdbgout_decl (tree decl) +vmsdbgout_function_decl (tree decl) { if (write_symbols == VMS_AND_DWARF2_DEBUG) (*dwarf2_debug_hooks.function_decl) (decl); @@ -1526,7 +1526,8 @@ vmsdbgout_decl (tree decl) static void vmsdbgout_early_global_decl (tree decl) { - /* NYI for non-dwarf. */ + if (write_symbols == VMS_AND_DWARF2_DEBUG) + (*dwarf2_debug_hooks.early_global_decl) (decl); } /* Not implemented in VMS Debug. */