From patchwork Tue Nov 27 18:31:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Basierski X-Patchwork-Id: 30325 Received: (qmail 13716 invoked by alias); 27 Nov 2018 19:40:14 -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 13566 invoked by uid 89); 27 Nov 2018 19:40:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_FAIL autolearn=ham version=3.3.2 spammy=2310 X-HELO: mga02.intel.com Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Nov 2018 19:40:11 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Nov 2018 11:40:10 -0800 Received: from ubuntu.imu.intel.com ([10.217.246.11]) by FMSMGA003.fm.intel.com with ESMTP; 27 Nov 2018 11:40:09 -0800 From: Sebastian Basierski To: gdb-patches@sourceware.org Subject: [PATCH 05/11] Typeprint: Resolve any dynamic target type of a pointer. Date: Tue, 27 Nov 2018 19:31:33 +0100 Message-Id: <20181127183139.71170-6-sbasierski@pl.sii.eu> In-Reply-To: <20181127183139.71170-1-sbasierski@pl.sii.eu> References: <20181127183139.71170-1-sbasierski@pl.sii.eu> From: Bernhard Heckel 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 | 4 ++++ gdb/testsuite/gdb.cp/vla-cxx.exp | 5 +++++ gdb/typeprint.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/gdb/testsuite/gdb.cp/vla-cxx.cc b/gdb/testsuite/gdb.cp/vla-cxx.cc index 1b5b27bf3d..fce8876e7d 100644 --- a/gdb/testsuite/gdb.cp/vla-cxx.cc +++ b/gdb/testsuite/gdb.cp/vla-cxx.cc @@ -40,6 +40,10 @@ int main(int argc, char **argv) typedef typeof (vla) &vlareftypedef; vlareftypedef vlaref2 (vla); container c; + typeof (vla) *ptr = nullptr; + + // Before pointer assignment + ptr = &vla; for (int i = 0; i < z; ++i) vla[i] = 5 + 2 * i; diff --git a/gdb/testsuite/gdb.cp/vla-cxx.exp b/gdb/testsuite/gdb.cp/vla-cxx.exp index ac87499d49..2cf2d9868f 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 393d825fe5..de8fbd7652 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -589,6 +589,23 @@ whatis_exp (const 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 (TYPE_DATA_LOCATION (TYPE_TARGET_TYPE(type)) != nullptr) + 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), nullptr, addr); + } + LA_PRINT_TYPE (type, "", gdb_stdout, show, 0, &flags); printf_filtered ("\n"); }