From patchwork Tue Aug 31 00:13:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petter Tomner X-Patchwork-Id: 1522377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: 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=FmfFmTBE; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Gz7Nn3WStz9sW8 for ; Tue, 31 Aug 2021 10:29:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EF84F385843D for ; Tue, 31 Aug 2021 00:29:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF84F385843D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1630369765; bh=bf6biB8RGYFLug1T2vQ4BdpWxcz1xIVckx7dxd5Xo8M=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FmfFmTBEKercYs5UpP278k3W+0MmORHaV2FtG6Lh2aRb/p951lae8kOA1l/3DDkWV QxWaisYLWV84vIxh62b09utq1fGfvEq+OyXf4SwrOUi5q41Z5bTrSNXqh6hzzs19ax vLoyITV6B55ugLWoX3iBdveWFHBJRXpXCwGkY3v0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-3.sys.kth.se (smtp-3.sys.kth.se [IPv6:2001:6b0:1:1300:250:56ff:fea6:2de2]) by sourceware.org (Postfix) with ESMTPS id 907B03858C3A; Tue, 31 Aug 2021 00:13:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 907B03858C3A Received: from smtp-3.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-3.sys.kth.se (Postfix) with ESMTP id B6D8D35A5; Tue, 31 Aug 2021 02:13:54 +0200 (CEST) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-3.sys.kth.se ([127.0.0.1]) by smtp-3.sys.kth.se (smtp-3.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id OUEjdcnQbgJd; Tue, 31 Aug 2021 02:13:50 +0200 (CEST) Received: from exdb5.ug.kth.se (exdb5.ug.kth.se [192.168.32.60]) by smtp-3.sys.kth.se (Postfix) with ESMTPS id 879CD3308; Tue, 31 Aug 2021 02:13:50 +0200 (CEST) Received: from exdb6.ug.kth.se (192.168.32.61) by exdb5.ug.kth.se (192.168.32.60) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.15; Tue, 31 Aug 2021 02:13:49 +0200 Received: from exdb6.ug.kth.se ([192.168.32.61]) by exdb6.ug.kth.se ([192.168.32.61]) with mapi id 15.02.0858.015; Tue, 31 Aug 2021 02:13:49 +0200 To: "gcc-patches@gcc.gnu.org" , "jit@gcc.gnu.org" Subject: [PATCH] jit : Generate debug info for variables Thread-Topic: [PATCH] jit : Generate debug info for variables Thread-Index: Aded81/JZTEbZr3kQEGb7a1Uc9O/Ow== Date: Tue, 31 Aug 2021 00:13:49 +0000 Message-ID: <005bad3cb21745d591cea63567d08d08@kth.se> Accept-Language: sv-SE, en-US Content-Language: sv-SE X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-originating-ip: [192.168.32.250] MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, 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: Petter Tomner via Gcc-patches From: Petter Tomner Reply-To: Petter Tomner Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This is a patch to generate debug info for local variables as well as globals. With this, "ptype foo", "info variables", "info locals" etc works when debugging in GDB. Finalizing of global variable declares are moved to after locations are handled and done as Fortran, C, Go etc do it. Also, primitive types have their TYPE_NAME set for debug info on types to work. Below are the patch, and I attached a testcase. Since it requires GDB to run it might not be suitable? Make check-jit runs fine on Debian x64. Regards, From d77e77104024c7ae9ce31b419dad1f0a5801fda7 Mon Sep 17 00:00:00 2001 From: Petter Tomner Date: Mon, 30 Aug 2021 01:44:07 +0200 Subject: [PATCH 1/2] libgccjit: Generate debug info for variables Finalize declares via available helpers after location is set. Set TYPE_NAME of primitives and friends to "int" etc. Debug info is now set properly for variables. 2021-08-31 Petter Tomner gcc/jit jit-playback.c jit-playback.h gcc/testsuite/jit.dg/ test-error-array-bounds.c: Array is not unsigned --- gcc/jit/jit-playback.c | 76 ++++++++++++++----- gcc/jit/jit-playback.h | 5 ++ .../jit.dg/test-error-array-bounds.c | 2 +- 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index 79ac525e5df..74321b0946a 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -165,7 +165,8 @@ gt_ggc_mx () /* Given an enum gcc_jit_types value, get a "tree" type. */ -static tree +tree +playback::context:: get_tree_node_for_type (enum gcc_jit_types type_) { switch (type_) @@ -192,11 +193,7 @@ get_tree_node_for_type (enum gcc_jit_types type_) return short_unsigned_type_node; case GCC_JIT_TYPE_CONST_CHAR_PTR: - { - tree const_char = build_qualified_type (char_type_node, - TYPE_QUAL_CONST); - return build_pointer_type (const_char); - } + return m_const_char_ptr; case GCC_JIT_TYPE_INT: return integer_type_node; @@ -579,10 +576,6 @@ playback::lvalue * playback::context:: global_finalize_lvalue (tree inner) { - varpool_node::get_create (inner); - - varpool_node::finalize_decl (inner); - m_globals.safe_push (inner); return new lvalue (this, inner); @@ -2952,9 +2945,7 @@ replay () { JIT_LOG_SCOPE (get_logger ()); - m_const_char_ptr - = build_pointer_type (build_qualified_type (char_type_node, - TYPE_QUAL_CONST)); + init_types (); /* Replay the recorded events: */ timevar_push (TV_JIT_REPLAY); @@ -2984,15 +2975,22 @@ replay () { int i; function *func; - + tree global; /* No GC can happen yet; process the cached source locations. */ handle_locations (); + /* Finalize globals. See how FORTRAN 95 does it in gfc_be_parse_file() + for a simple reference. */ + FOR_EACH_VEC_ELT (m_globals, i, global) + rest_of_decl_compilation (global, true, true); + + wrapup_global_declarations (m_globals.address(), m_globals.length()); + /* We've now created tree nodes for the stmts in the various blocks - in each function, but we haven't built each function's single stmt - list yet. Do so now. */ + in each function, but we haven't built each function's single stmt + list yet. Do so now. */ FOR_EACH_VEC_ELT (m_functions, i, func) - func->build_stmt_list (); + func->build_stmt_list (); /* No GC can have happened yet. */ @@ -3081,6 +3079,50 @@ location_comparator (const void *lhs, const void *rhs) return loc_lhs->get_column_num () - loc_rhs->get_column_num (); } +/* Initialize the NAME_TYPE of the primitive types as well as some + others. */ +void +playback::context:: +init_types () +{ + /* See lto_init() in lto-lang.c or void visit (TypeBasic *t) in D's types.cc + for reference. If TYPE_NAME is not set, debug info will not contain types */ +#define NAME_TYPE(t,n) \ +if (t) \ + TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \ + get_identifier (n), t) + + NAME_TYPE (integer_type_node, "int"); + NAME_TYPE (char_type_node, "char"); + NAME_TYPE (long_integer_type_node, "long int"); + NAME_TYPE (unsigned_type_node, "unsigned int"); + NAME_TYPE (long_unsigned_type_node, "long unsigned int"); + NAME_TYPE (long_long_integer_type_node, "long long int"); + NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int"); + NAME_TYPE (short_integer_type_node, "short int"); + NAME_TYPE (short_unsigned_type_node, "short unsigned int"); + if (signed_char_type_node != char_type_node) + NAME_TYPE (signed_char_type_node, "signed char"); + if (unsigned_char_type_node != char_type_node) + NAME_TYPE (unsigned_char_type_node, "unsigned char"); + NAME_TYPE (float_type_node, "float"); + NAME_TYPE (double_type_node, "double"); + NAME_TYPE (long_double_type_node, "long double"); + NAME_TYPE (void_type_node, "void"); + NAME_TYPE (boolean_type_node, "bool"); + NAME_TYPE (complex_float_type_node, "complex float"); + NAME_TYPE (complex_double_type_node, "complex double"); + NAME_TYPE (complex_long_double_type_node, "complex long double"); + + m_const_char_ptr = build_pointer_type( + build_qualified_type (char_type_node, TYPE_QUAL_CONST)); + + NAME_TYPE (m_const_char_ptr, "char"); + NAME_TYPE (size_type_node, "size_t"); + NAME_TYPE (fileptr_type_node, "FILE"); +#undef NAME_TYPE +} + /* Our API allows locations to be created in arbitrary orders, but the linemap API requires locations to be created in ascending order as if we were tokenizing files. diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index 825a3e172e9..f670c9e81df 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -271,8 +271,13 @@ private: source_file * get_source_file (const char *filename); + tree + get_tree_node_for_type (enum gcc_jit_types type_); + void handle_locations (); + void init_types (); + const char * get_path_c_file () const; const char * get_path_s_file () const; const char * get_path_so_file () const; diff --git a/gcc/testsuite/jit.dg/test-error-array-bounds.c b/gcc/testsuite/jit.dg/test-error-array-bounds.c index cd9361fba1d..b6c0ee526d4 100644 --- a/gcc/testsuite/jit.dg/test-error-array-bounds.c +++ b/gcc/testsuite/jit.dg/test-error-array-bounds.c @@ -70,5 +70,5 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) /* ...and that the message was captured by the API. */ CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), "array subscript 10 is above array bounds of" - " 'unsigned char[10]' [-Warray-bounds]"); + " 'char[10]' [-Warray-bounds]"); }