|
Jan Kratochvil |
7306e88 |
From d2fd5fea2c06052c53d99bfa25fdaed9cf5dd217 Mon Sep 17 00:00:00 2001
|
|
Jan Kratochvil |
7306e88 |
From: Bernhard Heckel <bernhard.heckel@intel.com>
|
|
Jan Kratochvil |
7306e88 |
Date: Tue, 12 Jul 2016 08:19:34 +0200
|
|
Jan Kratochvil |
7306e88 |
Subject: [PATCH 3/7] Typeprint: Resolve any dynamic target type of a pointer.
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
Before continuing with language specific type printing
|
|
Jan Kratochvil |
7306e88 |
we have to resolve the target type of a pointer
|
|
Jan Kratochvil |
7306e88 |
as we might wanna print more details of the target
|
|
Jan Kratochvil |
7306e88 |
like the dimension of an array. We have to resolve it here
|
|
Jan Kratochvil |
7306e88 |
as we don't have any address information later on.
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
2016-07-08 Bernhard Heckel <bernhard.heckel@intel.com>
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
gdb/Changelog:
|
|
Jan Kratochvil |
7306e88 |
* typeprint.c (whatis_exp): Resolve dynamic target type
|
|
Jan Kratochvil |
7306e88 |
of pointers.
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
gdb/Testsuite/Changelog:
|
|
Jan Kratochvil |
7306e88 |
* gdb.cp/vla-cxx.cc: Added pointer to dynamic type.
|
|
Jan Kratochvil |
7306e88 |
* gdb.cp/vla-cxx.exp: Test pointer to dynamic type.
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
Change-Id: Idff0d6dd0eab3125b45d470a12b5e66b392e42c3
|
|
Jan Kratochvil |
7306e88 |
---
|
|
Jan Kratochvil |
7306e88 |
gdb/testsuite/gdb.cp/vla-cxx.cc | 9 +++++++++
|
|
Jan Kratochvil |
7306e88 |
gdb/testsuite/gdb.cp/vla-cxx.exp | 5 +++++
|
|
Jan Kratochvil |
7306e88 |
gdb/typeprint.c | 19 +++++++++++++++++++
|
|
Jan Kratochvil |
7306e88 |
3 files changed, 33 insertions(+)
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
diff --git a/gdb/testsuite/gdb.cp/vla-cxx.cc b/gdb/testsuite/gdb.cp/vla-cxx.cc
|
|
Jan Kratochvil |
7306e88 |
index a1fd510..5f8f8ab 100644
|
|
Jan Kratochvil |
7306e88 |
--- a/gdb/testsuite/gdb.cp/vla-cxx.cc
|
|
Jan Kratochvil |
7306e88 |
+++ b/gdb/testsuite/gdb.cp/vla-cxx.cc
|
|
Jan Kratochvil |
7306e88 |
@@ -15,6 +15,10 @@
|
|
Jan Kratochvil |
7306e88 |
You should have received a copy of the GNU General Public License
|
|
Jan Kratochvil |
7306e88 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
+extern "C" {
|
|
Jan Kratochvil |
7306e88 |
+#include <stddef.h>
|
|
Jan Kratochvil |
7306e88 |
+}
|
|
Jan Kratochvil |
7306e88 |
+
|
|
Jan Kratochvil |
7306e88 |
struct container;
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
struct element
|
|
Jan Kratochvil |
7306e88 |
@@ -40,11 +44,16 @@ int main(int argc, char **argv)
|
|
Jan Kratochvil |
7306e88 |
typedef typeof (vla) &vlareftypedef;
|
|
Jan Kratochvil |
7306e88 |
vlareftypedef vlaref2 (vla);
|
|
Jan Kratochvil |
7306e88 |
container c;
|
|
Jan Kratochvil |
7306e88 |
+ typeof (vla) *ptr = NULL;
|
|
Jan Kratochvil |
7306e88 |
+
|
|
Jan Kratochvil |
7306e88 |
+ // Before pointer assignment
|
|
Jan Kratochvil |
7306e88 |
+ ptr = &vla;
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
for (int i = 0; i < z; ++i)
|
|
Jan Kratochvil |
7306e88 |
vla[i] = 5 + 2 * i;
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
// vlas_filled
|
|
Jan Kratochvil |
7306e88 |
vla[0] = 2 * vla[0];
|
|
Jan Kratochvil |
7306e88 |
+
|
|
Jan Kratochvil |
7306e88 |
return vla[2];
|
|
Jan Kratochvil |
7306e88 |
}
|
|
Jan Kratochvil |
7306e88 |
diff --git a/gdb/testsuite/gdb.cp/vla-cxx.exp b/gdb/testsuite/gdb.cp/vla-cxx.exp
|
|
Jan Kratochvil |
7306e88 |
index f6224dc..babdfb7 100644
|
|
Jan Kratochvil |
7306e88 |
--- a/gdb/testsuite/gdb.cp/vla-cxx.exp
|
|
Jan Kratochvil |
7306e88 |
+++ b/gdb/testsuite/gdb.cp/vla-cxx.exp
|
|
Jan Kratochvil |
7306e88 |
@@ -23,6 +23,10 @@ if ![runto_main] {
|
|
Jan Kratochvil |
7306e88 |
return -1
|
|
Jan Kratochvil |
7306e88 |
}
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
+gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
|
|
Jan Kratochvil |
7306e88 |
+gdb_continue_to_breakpoint "Before pointer assignment"
|
|
Jan Kratochvil |
7306e88 |
+gdb_test "ptype ptr" "int \\(\\*\\)\\\[variable length\\\]" "ptype ptr, Before pointer assignment"
|
|
Jan Kratochvil |
7306e88 |
+
|
|
Jan Kratochvil |
7306e88 |
gdb_breakpoint [gdb_get_line_number "vlas_filled"]
|
|
Jan Kratochvil |
7306e88 |
gdb_continue_to_breakpoint "vlas_filled"
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
@@ -33,3 +37,4 @@ gdb_test "print vlaref" " = \\(int \\(&\\)\\\[3\\\]\\) @$hex: \\{5, 7, 9\\}"
|
|
Jan Kratochvil |
7306e88 |
# bug being tested, it's better not to depend on the exact spelling.
|
|
Jan Kratochvil |
7306e88 |
gdb_test "print vlaref2" " = \\(.*\\) @$hex: \\{5, 7, 9\\}"
|
|
Jan Kratochvil |
7306e88 |
gdb_test "print c" " = \\{e = \\{c = @$hex\\}\\}"
|
|
Jan Kratochvil |
7306e88 |
+gdb_test "ptype ptr" "int \\(\\*\\)\\\[3\\\]"
|
|
Jan Kratochvil |
7306e88 |
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
|
|
Jan Kratochvil |
7306e88 |
index e77513e..e3d84c7 100644
|
|
Jan Kratochvil |
7306e88 |
--- a/gdb/typeprint.c
|
|
Jan Kratochvil |
7306e88 |
+++ b/gdb/typeprint.c
|
|
Jan Kratochvil |
7306e88 |
@@ -485,6 +485,25 @@ whatis_exp (char *exp, int show)
|
|
Jan Kratochvil |
7306e88 |
printf_filtered (" */\n");
|
|
Jan Kratochvil |
7306e88 |
}
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
+ /* Resolve any dynamic target type, as we might print
|
|
Jan Kratochvil |
7306e88 |
+ additional information about the target.
|
|
Jan Kratochvil |
7306e88 |
+ For example, in Fortran and C we are printing the dimension of the
|
|
Jan Kratochvil |
7306e88 |
+ dynamic array the pointer is pointing to. */
|
|
Jan Kratochvil |
7306e88 |
+ if (TYPE_CODE (type) == TYPE_CODE_PTR
|
|
Jan Kratochvil |
7306e88 |
+ && is_dynamic_type (type) == 1)
|
|
Jan Kratochvil |
7306e88 |
+ {
|
|
Jan Kratochvil |
7306e88 |
+ CORE_ADDR addr;
|
|
Jan Kratochvil |
7306e88 |
+ if (NULL != TYPE_DATA_LOCATION (TYPE_TARGET_TYPE(type)))
|
|
Jan Kratochvil |
7306e88 |
+ addr = value_address (val);
|
|
Jan Kratochvil |
7306e88 |
+ else
|
|
Jan Kratochvil |
7306e88 |
+ addr = value_as_address (val);
|
|
Jan Kratochvil |
7306e88 |
+
|
|
Jan Kratochvil |
7306e88 |
+ if (addr != 0
|
|
Jan Kratochvil |
7306e88 |
+ && type_not_associated (type) == 0)
|
|
Jan Kratochvil |
7306e88 |
+ TYPE_TARGET_TYPE (type) = resolve_dynamic_type (TYPE_TARGET_TYPE (type),
|
|
Jan Kratochvil |
7306e88 |
+ NULL, addr);
|
|
Jan Kratochvil |
7306e88 |
+ }
|
|
Jan Kratochvil |
7306e88 |
+
|
|
Jan Kratochvil |
7306e88 |
LA_PRINT_TYPE (type, "", gdb_stdout, show, 0, &flags);
|
|
Jan Kratochvil |
7306e88 |
printf_filtered ("\n");
|
|
Jan Kratochvil |
7306e88 |
|
|
Jan Kratochvil |
7306e88 |
--
|
|
Jan Kratochvil |
7306e88 |
2.7.4
|
|
Jan Kratochvil |
7306e88 |
|