* [PATCH 1/4] testcase - pointer to member function
2012-11-22 7:32 [PATCH 0/4] Fix member pointer bugs Yao Qi
@ 2012-11-22 7:32 ` Yao Qi
2012-11-26 16:32 ` Tom Tromey
2012-11-22 7:33 ` [PATCH 4/4] Handle TYPE_CODE_MEMBERPTR Yao Qi
` (3 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: Yao Qi @ 2012-11-22 7:32 UTC (permalink / raw)
To: gdb-patches
Hi,
The new test cases expose some problem in GDB on handling member
pointers, and there are two fails shown below on current GDB trunk.
print (diamond.*diamond_pfunc_ptr) (20)^M
Non-pointer-to-member value used in pointer-to-member construct^M
FAIL: gdb.cp/member-ptr.exp: print (diamond.*diamond_pfunc_ptr)(20)
ptype (a.*pmf)(3)^M
type = int (A * const, int)^M
FAIL: gdb.cp/member-ptr.exp: ptype (a.*pmf)(3)
The following patches will fix them.
gdb/testsuite:
2012-11-22 Daniel Jacobowitz <dan@codesourcery.com>
* gdb.cp/member-ptr.cc (class Diamond): Add func_ptr.
(func): New function.
(main): Initialize diamond.func_ptr and add diamond_pfunc_ptr.
* gdb.cp/member-ptr.exp: Add new tests for ptype and for
pointers to members with pointer-to-function type.
---
gdb/testsuite/gdb.cp/member-ptr.cc | 17 +++++++++++++++++
gdb/testsuite/gdb.cp/member-ptr.exp | 28 ++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/gdb/testsuite/gdb.cp/member-ptr.cc b/gdb/testsuite/gdb.cp/member-ptr.cc
index 17f022c..6cb87ef 100644
--- a/gdb/testsuite/gdb.cp/member-ptr.cc
+++ b/gdb/testsuite/gdb.cp/member-ptr.cc
@@ -137,6 +137,7 @@ class Diamond : public Padding, public Left, public Right
{
public:
virtual int vget_base ();
+ int (*func_ptr) (int);
};
int Diamond::vget_base ()
@@ -144,6 +145,12 @@ int Diamond::vget_base ()
return this->Left::x + 2000;
}
+int
+func (int x)
+{
+ return 19 + x;
+}
+
int main ()
{
A a;
@@ -161,6 +168,7 @@ int main ()
int (Diamond::*right_vpmf) ();
int (Base::*base_vpmf) ();
int Diamond::*diamond_pmi;
+ int (* Diamond::*diamond_pfunc_ptr) (int);
PMI null_pmi;
PMF null_pmf;
@@ -178,6 +186,7 @@ int main ()
diamond.Left::x = 77;
diamond.Right::x = 88;
+ diamond.func_ptr = func;
/* Some valid pointer to members from a base class. */
left_pmf = (int (Diamond::*) ()) (int (Left::*) ()) (&Base::get_x);
@@ -192,11 +201,19 @@ int main ()
/* A pointer to data member from a base class. */
diamond_pmi = (int Diamond::*) (int Left::*) &Base::x;
+ /* A pointer to data member, where the member is itself a pointer to
+ a function. */
+ diamond_pfunc_ptr = (int (* Diamond::*) (int)) &Diamond::func_ptr;
+
null_pmi = NULL;
null_pmf = NULL;
pmi = NULL; /* Breakpoint 1 here. */
+ // Invalid (uses diamond_pfunc_ptr as a function):
+ // diamond.*diamond_pfunc_ptr (20);
+ (diamond.*diamond_pfunc_ptr) (20);
+
k = (a.*pmf)(3);
pmi = &A::jj;
diff --git a/gdb/testsuite/gdb.cp/member-ptr.exp b/gdb/testsuite/gdb.cp/member-ptr.exp
index f569ca9..ae2b8b4 100644
--- a/gdb/testsuite/gdb.cp/member-ptr.exp
+++ b/gdb/testsuite/gdb.cp/member-ptr.exp
@@ -376,6 +376,33 @@ gdb_test_multiple "print ((int) pmi) == ((char *) &a.j - (char *) & a)" $name {
}
}
+# Check pointers to data members, which are themselves pointers to
+# functions. These behave like data members, not like pointers to
+# member functions.
+
+gdb_test "ptype diamond_pfunc_ptr" \
+ "type = int \\(\\*Diamond::\\*\\)\\(int\\)"
+
+gdb_test "ptype diamond.*diamond_pfunc_ptr" \
+ "type = int \\(\\*\\)\\(int\\)"
+
+# This one is invalid; () binds more tightly than .*, so it tries to
+# call the member pointer as a normal pointer-to-function.
+
+gdb_test "print diamond.*diamond_pfunc_ptr (20)" \
+ "Invalid data type for function to be called."
+
+# With parentheses, it is valid.
+
+gdb_test "print (diamond.*diamond_pfunc_ptr) (20)" \
+ "$vhn = 39"
+
+# Make sure that we do not interpret this as either a member pointer
+# call or a member function call.
+
+gdb_test "print diamond.func_ptr (20)" \
+ "$vhn = 39"
+
# ==========================
# pointer to member function
# ==========================
@@ -595,6 +622,7 @@ gdb_test_multiple "print (a.*pmf)(3)" $name {
}
gdb_test "ptype a.*pmf" "type = int \\(A \\*( const)?, int\\)"
+gdb_test "ptype (a.*pmf)(3)" "type = int"
# Print out a pointer to data member which requires looking into
# a base class.
--
1.7.7.6
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 4/4] Handle TYPE_CODE_MEMBERPTR
2012-11-22 7:32 [PATCH 0/4] Fix member pointer bugs Yao Qi
2012-11-22 7:32 ` [PATCH 1/4] testcase - pointer to member function Yao Qi
@ 2012-11-22 7:33 ` Yao Qi
2012-11-22 8:07 ` Yao Qi
2012-11-22 7:33 ` [PATCH 2/4] factor code Yao Qi
` (2 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: Yao Qi @ 2012-11-22 7:33 UTC (permalink / raw)
To: gdb-patches
This patch handles TYPE_CODE_MEMBERPTR and fixes this fail,
FAIL: gdb.cp/member-ptr.exp: print (diamond.*diamond_pfunc_ptr) (20)
gdb:
2012-11-22 Daniel Jacobowitz <dan@codesourcery.com>
* eval.c (evaluate_subexp_standard): Handle
TYPE_CODE_MEMBERPTR.
---
gdb/eval.c | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/gdb/eval.c b/gdb/eval.c
index 82ea81b..3c8ec55 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1400,6 +1400,19 @@ evaluate_subexp_standard (struct type *expect_type,
tem = 2;
argvec[1] = arg2;
}
+ else if (TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
+ {
+ /* Now, convert these values to an address. */
+ arg2 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
+ arg2);
+
+ mem_offset = value_as_long (arg1);
+
+ arg1 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
+ value_as_long (arg2) + mem_offset);
+ arg1 = value_ind (arg1);
+ tem = 1;
+ }
else
error (_("Non-pointer-to-member value used in pointer-to-member "
"construct"));
--
1.7.7.6
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 4/4] Handle TYPE_CODE_MEMBERPTR
2012-11-22 7:33 ` [PATCH 4/4] Handle TYPE_CODE_MEMBERPTR Yao Qi
@ 2012-11-22 8:07 ` Yao Qi
2012-11-26 16:42 ` Tom Tromey
0 siblings, 1 reply; 14+ messages in thread
From: Yao Qi @ 2012-11-22 8:07 UTC (permalink / raw)
To: gdb-patches
On 11/22/2012 03:32 PM, Yao Qi wrote:
> + arg2 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
> + arg2);
> +
> + mem_offset = value_as_long (arg1);
> +
> + arg1 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
These two lines are too long. Fixed in the updated patch.
--
Yao (é½å°§)
gdb:
2012-11-22 Daniel Jacobowitz <dan@codesourcery.com>
* eval.c (evaluate_subexp_standard): Handle
TYPE_CODE_MEMBERPTR.
---
gdb/eval.c | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/gdb/eval.c b/gdb/eval.c
index 82ea81b..55582e0 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1400,6 +1400,21 @@ evaluate_subexp_standard (struct type *expect_type,
tem = 2;
argvec[1] = arg2;
}
+ else if (TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
+ {
+ struct type *type_ptr
+ = lookup_pointer_type (TYPE_DOMAIN_TYPE (type));
+
+ /* Now, convert these values to an address. */
+ arg2 = value_cast (type_ptr, arg2);
+
+ mem_offset = value_as_long (arg1);
+
+ arg1 = value_from_pointer (type_ptr,
+ value_as_long (arg2) + mem_offset);
+ arg1 = value_ind (arg1);
+ tem = 1;
+ }
else
error (_("Non-pointer-to-member value used in pointer-to-member "
"construct"));
--
1.7.7.6
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 2/4] factor code
2012-11-22 7:32 [PATCH 0/4] Fix member pointer bugs Yao Qi
2012-11-22 7:32 ` [PATCH 1/4] testcase - pointer to member function Yao Qi
2012-11-22 7:33 ` [PATCH 4/4] Handle TYPE_CODE_MEMBERPTR Yao Qi
@ 2012-11-22 7:33 ` Yao Qi
2012-11-22 7:33 ` [PATCH 3/4] Use TYPE_TARGET_TYPE Yao Qi
2012-11-27 8:03 ` [committed]: [PATCH 0/4] Fix member pointer bugs Yao Qi
4 siblings, 0 replies; 14+ messages in thread
From: Yao Qi @ 2012-11-22 7:33 UTC (permalink / raw)
To: gdb-patches
This is a code refactor to pave the way for the following patches.
Functionality of GDB is not affected.
gdb:
2012-11-22 Daniel Jacobowitz <dan@codesourcery.com>
Yao Qi <yao@codesourcery.com>
* eval.c (evaluate_subexp_standard): Code factor.
---
gdb/eval.c | 27 +++++++++++++--------------
1 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/gdb/eval.c b/gdb/eval.c
index f655957..9957d02 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1364,7 +1364,6 @@ evaluate_subexp_standard (struct type *expect_type,
alloca (sizeof (struct value *) * (nargs + 3));
if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
{
- nargs++;
/* First, evaluate the structure into arg2. */
pc2 = (*pos)++;
@@ -1388,22 +1387,22 @@ evaluate_subexp_standard (struct type *expect_type,
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
- if (TYPE_CODE (check_typedef (value_type (arg1)))
- != TYPE_CODE_METHODPTR)
- error (_("Non-pointer-to-member value used in pointer-to-member "
- "construct"));
-
- if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ type = check_typedef (value_type (arg1));
+ if (TYPE_CODE (type) == TYPE_CODE_METHODPTR)
{
- struct type *method_type = check_typedef (value_type (arg1));
+ if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ arg1 = value_zero (type, not_lval);
+ else
+ arg1 = cplus_method_ptr_to_value (&arg2, arg1);
- arg1 = value_zero (method_type, not_lval);
+ /* Now, say which argument to start evaluating from. */
+ nargs++;
+ tem = 2;
+ argvec[1] = arg2;
}
else
- arg1 = cplus_method_ptr_to_value (&arg2, arg1);
-
- /* Now, say which argument to start evaluating from. */
- tem = 2;
+ error (_("Non-pointer-to-member value used in pointer-to-member "
+ "construct"));
}
else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
{
@@ -1654,7 +1653,7 @@ evaluate_subexp_standard (struct type *expect_type,
}
else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
{
- argvec[1] = arg2;
+ /* Pointer to member. argvec[1] is already set up. */
argvec[0] = arg1;
}
else if (op == OP_VAR_VALUE || (op == OP_SCOPE && function != NULL))
--
1.7.7.6
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 3/4] Use TYPE_TARGET_TYPE.
2012-11-22 7:32 [PATCH 0/4] Fix member pointer bugs Yao Qi
` (2 preceding siblings ...)
2012-11-22 7:33 ` [PATCH 2/4] factor code Yao Qi
@ 2012-11-22 7:33 ` Yao Qi
2012-11-26 16:41 ` Tom Tromey
2012-11-27 8:03 ` [committed]: [PATCH 0/4] Fix member pointer bugs Yao Qi
4 siblings, 1 reply; 14+ messages in thread
From: Yao Qi @ 2012-11-22 7:33 UTC (permalink / raw)
To: gdb-patches
For TYPE_CODE_METHODPTR, we should use TYPE_TARGET_TYPE to get the
type of function. This patch fixes this fail
FAIL: gdb.cp/member-ptr.exp: ptype (a.*pmf)(3)
gdb:
2012-11-22 Daniel Jacobowitz <dan@codesourcery.com>
* eval.c (evaluate_subexp_standard): Use TYPE_TARGET_TYPE.
---
gdb/eval.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gdb/eval.c b/gdb/eval.c
index 9957d02..82ea81b 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1391,7 +1391,7 @@ evaluate_subexp_standard (struct type *expect_type,
if (TYPE_CODE (type) == TYPE_CODE_METHODPTR)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- arg1 = value_zero (type, not_lval);
+ arg1 = value_zero (TYPE_TARGET_TYPE (type), not_lval);
else
arg1 = cplus_method_ptr_to_value (&arg2, arg1);
--
1.7.7.6
^ permalink raw reply [flat|nested] 14+ messages in thread* [committed]: [PATCH 0/4] Fix member pointer bugs
2012-11-22 7:32 [PATCH 0/4] Fix member pointer bugs Yao Qi
` (3 preceding siblings ...)
2012-11-22 7:33 ` [PATCH 3/4] Use TYPE_TARGET_TYPE Yao Qi
@ 2012-11-27 8:03 ` Yao Qi
2012-11-28 14:47 ` Tom Tromey
4 siblings, 1 reply; 14+ messages in thread
From: Yao Qi @ 2012-11-27 8:03 UTC (permalink / raw)
To: gdb-patches
On 11/22/2012 03:32 PM, Yao Qi wrote:
> Hello,
> This patch set fixes GDB bugs on member pointers. This patch was
> written by Daniel, I took it, and split it to four patches to make
> each one more readable. Each one is quite self-explained, so I don't
> put much words here.
>
> Regression tested on x86_64-linux. Is it OK?
>
Thanks for the review. This whole series are checked in in one commit.
--
Yao (é½å°§)
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [committed]: [PATCH 0/4] Fix member pointer bugs
2012-11-27 8:03 ` [committed]: [PATCH 0/4] Fix member pointer bugs Yao Qi
@ 2012-11-28 14:47 ` Tom Tromey
2012-11-28 15:14 ` Yao Qi
0 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey @ 2012-11-28 14:47 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
>>>>> "Yao" == Yao Qi <yao@codesourcery.com> writes:
Yao> Thanks for the review. This whole series are checked in in one commit.
Thanks.
I see one failure now:
FAIL: gdb.cp/member-ptr.exp: print (diamond.*diamond_pfunc_ptr) (20)
From gdb.log:
print (diamond.*diamond_pfunc_ptr) (20)
warning: can't find linker symbol for virtual table for `Diamond' value
warning: found `Diamond::vget_base()' instead
Invalid data type for function to be called.
Is this expected?
Tom
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [committed]: [PATCH 0/4] Fix member pointer bugs
2012-11-28 14:47 ` Tom Tromey
@ 2012-11-28 15:14 ` Yao Qi
2012-11-28 16:37 ` Tom Tromey
0 siblings, 1 reply; 14+ messages in thread
From: Yao Qi @ 2012-11-28 15:14 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 11/28/2012 10:46 PM, Tom Tromey wrote:
> FAIL: gdb.cp/member-ptr.exp: print (diamond.*diamond_pfunc_ptr) (20)
>
> From gdb.log:
>
> print (diamond.*diamond_pfunc_ptr) (20)
> warning: can't find linker symbol for virtual table for `Diamond' value
> warning: found `Diamond::vget_base()' instead
> Invalid data type for function to be called.
>
> Is this expected?
No, I didn't see this warning before. I'll have a look.
--
Yao (é½å°§)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [committed]: [PATCH 0/4] Fix member pointer bugs
2012-11-28 15:14 ` Yao Qi
@ 2012-11-28 16:37 ` Tom Tromey
2012-11-29 7:46 ` Yao Qi
0 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey @ 2012-11-28 16:37 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
>>>>> "Yao" == Yao Qi <yao@codesourcery.com> writes:
Yao> No, I didn't see this warning before. I'll have a look.
This fixes it for me. What do you think? I mean aside from the line
break problem...
Tom
diff --git a/gdb/eval.c b/gdb/eval.c
index 55582e0..faad9e3 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1410,7 +1410,7 @@ evaluate_subexp_standard (struct type *expect_type,
mem_offset = value_as_long (arg1);
- arg1 = value_from_pointer (type_ptr,
+ arg1 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
value_as_long (arg2) + mem_offset);
arg1 = value_ind (arg1);
tem = 1;
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [committed]: [PATCH 0/4] Fix member pointer bugs
2012-11-28 16:37 ` Tom Tromey
@ 2012-11-29 7:46 ` Yao Qi
0 siblings, 0 replies; 14+ messages in thread
From: Yao Qi @ 2012-11-29 7:46 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 11/29/2012 12:37 AM, Tom Tromey wrote:
> index 55582e0..faad9e3 100644
> --- a/gdb/eval.c
> +++ b/gdb/eval.c
> @@ -1410,7 +1410,7 @@ evaluate_subexp_standard (struct type *expect_type,
>
> mem_offset = value_as_long (arg1);
>
> - arg1 = value_from_pointer (type_ptr,
> + arg1 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
> value_as_long (arg2) + mem_offset);
> arg1 = value_ind (arg1);
> tem = 1;
TYPE_TARGET_TYPE (type) was used in my first post, but it was replaced
by TYPE_DOMAIN_TYPE (type) by mistake in my follow-up patch, which is
to shorten the line. I didn't run regression test again after the change.
Thanks for pointing this out.
The patch below is the same to yours, but shorten the line by defining a
new local variable. Regression tested on x86_64-linux. Committed.
--
Yao (é½å°§)
gdb:
2012-11-29 Yao Qi <yao@codesourcery.com>
Tom Tromey <tromey@redhat.com>
* eval.c (evaluate_subexp_standard): Get the correct pointer
type for TYPE_CODE_MEMBERPTR.
---
gdb/eval.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/gdb/eval.c b/gdb/eval.c
index 55582e0..7d48d7e 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1404,13 +1404,15 @@ evaluate_subexp_standard (struct type *expect_type,
{
struct type *type_ptr
= lookup_pointer_type (TYPE_DOMAIN_TYPE (type));
+ struct type *target_type_ptr
+ = lookup_pointer_type (TYPE_TARGET_TYPE (type));
/* Now, convert these values to an address. */
arg2 = value_cast (type_ptr, arg2);
mem_offset = value_as_long (arg1);
- arg1 = value_from_pointer (type_ptr,
+ arg1 = value_from_pointer (target_type_ptr,
value_as_long (arg2) + mem_offset);
arg1 = value_ind (arg1);
tem = 1;
--
1.7.7.6
^ permalink raw reply [flat|nested] 14+ messages in thread