From: Bernhard Heckel <bernhard.heckel@intel.com>
To: qiyaoltc@gmail.com, eliz@gnu.org, brobecker@adacore.com
Cc: gdb-patches@sourceware.org, Bernhard Heckel <bernhard.heckel@intel.com>
Subject: [PATCH V3 3/6] Typeprint: Resolve any dynamic target type of a pointer.
Date: Mon, 11 Jul 2016 15:12:00 -0000 [thread overview]
Message-ID: <1468249928-2169-4-git-send-email-bernhard.heckel@intel.com> (raw)
In-Reply-To: <1468249928-2169-1-git-send-email-bernhard.heckel@intel.com>
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 <bernhard.heckel@intel.com>
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 | 9 +++++++++
gdb/testsuite/gdb.cp/vla-cxx.exp | 5 +++++
gdb/typeprint.c | 19 +++++++++++++++++++
3 files changed, 33 insertions(+)
diff --git a/gdb/testsuite/gdb.cp/vla-cxx.cc b/gdb/testsuite/gdb.cp/vla-cxx.cc
index a1fd510..5f8f8ab 100644
--- a/gdb/testsuite/gdb.cp/vla-cxx.cc
+++ b/gdb/testsuite/gdb.cp/vla-cxx.cc
@@ -15,6 +15,10 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+extern "C" {
+#include <stddef.h>
+}
+
struct container;
struct element
@@ -40,11 +44,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..e3d84c7 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) == 1)
+ {
+ 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) == 0)
+ 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
next prev parent reply other threads:[~2016-07-11 15:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-11 15:12 [PATCH V3 0/6] Fortran: Resolve target types of pointers Bernhard Heckel
2016-07-11 15:12 ` [PATCH V3 4/6] Fortran: Typeprint, fix dangling types Bernhard Heckel
2016-07-11 15:12 ` [PATCH V3 2/6] Fortran: Resolve dynamic properties of pointer types Bernhard Heckel
2016-07-11 15:12 ` Bernhard Heckel [this message]
2016-07-11 15:12 ` [PATCH V3 1/6] Fortran: Testsuite, fix differences in type naming Bernhard Heckel
2016-07-15 14:03 ` Yao Qi
2016-07-11 15:12 ` [PATCH V3 5/6] Resolve dynamic target types of pointers Bernhard Heckel
2016-07-11 16:25 ` Eli Zaretskii
2016-07-11 15:12 ` [PATCH V3 6/6] Fortran: Testsuite, add cyclic pointers Bernhard Heckel
2016-08-08 11:19 ` [PING][PATCH V3 0/6] Fortran: Resolve target types of pointers Bernhard Heckel
2016-08-15 11:51 ` [PING 2][PATCH " Bernhard Heckel
2016-08-23 13:38 ` [PING 3][PATCH " Bernhard Heckel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1468249928-2169-4-git-send-email-bernhard.heckel@intel.com \
--to=bernhard.heckel@intel.com \
--cc=brobecker@adacore.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=qiyaoltc@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox