From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 62198 invoked by alias); 14 Oct 2016 11:54:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 62001 invoked by uid 89); 14 Oct 2016 11:54:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=wanna, 15,6, 15,8, Hx-spam-relays-external:10.253.24.26 X-HELO: mga09.intel.com Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Oct 2016 11:54:16 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP; 14 Oct 2016 04:54:14 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 14 Oct 2016 04:54:13 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u9EBsC3l014364; Fri, 14 Oct 2016 12:54:12 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id u9EBsC2N010699; Fri, 14 Oct 2016 13:54:12 +0200 Received: (from heckel@localhost) by ulvlx001.iul.intel.com with œ id u9EBsCWf010696; Fri, 14 Oct 2016 13:54:12 +0200 From: Bernhard Heckel To: qiyaoltc@gmail.com, brobecker@adacore.com Cc: gdb-patches@sourceware.org, Bernhard Heckel Subject: [PATCH V5 3/6] Typeprint: Resolve any dynamic target type of a pointer. Date: Fri, 14 Oct 2016 11:54:00 -0000 Message-Id: <1476446044-10408-4-git-send-email-bernhard.heckel@intel.com> In-Reply-To: <1476446044-10408-1-git-send-email-bernhard.heckel@intel.com> References: <1476446044-10408-1-git-send-email-bernhard.heckel@intel.com> X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00437.txt.bz2 Before continuing with language specific type printing we have to resolve the target type of a pointer as we might wanna print more details of the target like the dimension of an array. We have to resolve it here as we don't have any address information later on. 2016-07-08 Bernhard Heckel gdb/Changelog: * typeprint.c (whatis_exp): Resolve dynamic target type of pointers. gdb/Testsuite/Changelog: * gdb.cp/vla-cxx.cc: Added pointer to dynamic type. * gdb.cp/vla-cxx.exp: Test pointer to dynamic type. --- gdb/testsuite/gdb.cp/vla-cxx.cc | 7 +++++++ gdb/testsuite/gdb.cp/vla-cxx.exp | 5 +++++ gdb/typeprint.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/gdb/testsuite/gdb.cp/vla-cxx.cc b/gdb/testsuite/gdb.cp/vla-cxx.cc index a1fd510..2b01aa8 100644 --- a/gdb/testsuite/gdb.cp/vla-cxx.cc +++ b/gdb/testsuite/gdb.cp/vla-cxx.cc @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + struct container; struct element @@ -40,11 +42,16 @@ int main(int argc, char **argv) typedef typeof (vla) &vlareftypedef; vlareftypedef vlaref2 (vla); container c; + typeof (vla) *ptr = NULL; + + // Before pointer assignment + ptr = &vla; for (int i = 0; i < z; ++i) vla[i] = 5 + 2 * i; // vlas_filled vla[0] = 2 * vla[0]; + return vla[2]; } diff --git a/gdb/testsuite/gdb.cp/vla-cxx.exp b/gdb/testsuite/gdb.cp/vla-cxx.exp index f6224dc..babdfb7 100644 --- a/gdb/testsuite/gdb.cp/vla-cxx.exp +++ b/gdb/testsuite/gdb.cp/vla-cxx.exp @@ -23,6 +23,10 @@ if ![runto_main] { return -1 } +gdb_breakpoint [gdb_get_line_number "Before pointer assignment"] +gdb_continue_to_breakpoint "Before pointer assignment" +gdb_test "ptype ptr" "int \\(\\*\\)\\\[variable length\\\]" "ptype ptr, Before pointer assignment" + gdb_breakpoint [gdb_get_line_number "vlas_filled"] gdb_continue_to_breakpoint "vlas_filled" @@ -33,3 +37,4 @@ gdb_test "print vlaref" " = \\(int \\(&\\)\\\[3\\\]\\) @$hex: \\{5, 7, 9\\}" # bug being tested, it's better not to depend on the exact spelling. gdb_test "print vlaref2" " = \\(.*\\) @$hex: \\{5, 7, 9\\}" gdb_test "print c" " = \\{e = \\{c = @$hex\\}\\}" +gdb_test "ptype ptr" "int \\(\\*\\)\\\[3\\\]" diff --git a/gdb/typeprint.c b/gdb/typeprint.c index e77513e..e214942 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -485,6 +485,25 @@ whatis_exp (char *exp, int show) printf_filtered (" */\n"); } + /* Resolve any dynamic target type, as we might print + additional information about the target. + For example, in Fortran and C we are printing the dimension of the + dynamic array the pointer is pointing to. */ + if (TYPE_CODE (type) == TYPE_CODE_PTR + && is_dynamic_type (type)) + { + CORE_ADDR addr; + if (NULL != TYPE_DATA_LOCATION (TYPE_TARGET_TYPE(type))) + addr = value_address (val); + else + addr = value_as_address (val); + + if (addr != 0 + && !type_not_associated (type)) + TYPE_TARGET_TYPE (type) = resolve_dynamic_type (TYPE_TARGET_TYPE (type), + NULL, addr); + } + LA_PRINT_TYPE (type, "", gdb_stdout, show, 0, &flags); printf_filtered ("\n"); -- 2.7.1.339.g0233b80