aboutsummaryrefslogtreecommitdiff
path: root/gdb/cp-valprint.c
diff options
context:
space:
mode:
authorWeimin Pan <weimin.pan@oracle.com>2018-03-28 13:23:48 -0600
committerWeimin Pan <weimin.pan@oracle.com>2018-04-02 12:53:43 -0500
commit79f18731714e7f07af6e78b8da8a1ffacf4247b7 (patch)
tree9a6a543e23425bd7b9bc008b356d4308e48537a8 /gdb/cp-valprint.c
parent3d6b3b8221c97c58a2496dfc7dfff30ed07d911a (diff)
downloadgdb-79f18731714e7f07af6e78b8da8a1ffacf4247b7.zip
gdb-79f18731714e7f07af6e78b8da8a1ffacf4247b7.tar.gz
gdb-79f18731714e7f07af6e78b8da8a1ffacf4247b7.tar.bz2
Fix infinite recursion when printing static member with typedef
The original problem was fixed (see related PR 22242). But using a typedef as the declared type for a static member variable, as commented in this PR, is still causing gdb to get into infinite loop when printing the static member's value. This problem can be reproduced as follows: % cat t.cc class A { typedef A type; public: bool operator==(const type& other) { return true; } static const type INSTANCE; }; const A A::INSTANCE; int main() { A a; if (a == A::INSTANCE) { return -1; } return 0; } % g++ -g t.cc % gdb -ex "start" -ex "p a" a.out The fix is rather trivial - in cp_print_static_field(), should call check_typedef() to get the static member's real type and use it to check whether it's a struct or an array. As Simon suggested, I've added a new test case to the testsuite and am passing the original type, not the real type, as argument to both cp_print_value_fields() and val_print(). Re-tested on both aarch64-linux-gnu and amd64-linux-gnu. No regressions.
Diffstat (limited to 'gdb/cp-valprint.c')
-rw-r--r--gdb/cp-valprint.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 486653f..e019a60 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -633,7 +633,8 @@ cp_print_static_field (struct type *type,
return;
}
- if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+ struct type *real_type = check_typedef (type);
+ if (TYPE_CODE (real_type) == TYPE_CODE_STRUCT)
{
CORE_ADDR *first_dont_print;
CORE_ADDR addr;
@@ -658,7 +659,6 @@ cp_print_static_field (struct type *type,
addr = value_address (val);
obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
sizeof (CORE_ADDR));
- type = check_typedef (type);
cp_print_value_fields (type, value_enclosing_type (val),
value_embedded_offset (val), addr,
stream, recurse, val,
@@ -666,7 +666,7 @@ cp_print_static_field (struct type *type,
return;
}
- if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+ if (TYPE_CODE (real_type) == TYPE_CODE_ARRAY)
{
struct type **first_dont_print;
int i;