[PING,Python] Fix gdb.Value.dynamic_type for reference values
Commit Message
Original post: https://sourceware.org/ml/gdb-patches/2014-03/msg00542.html
gdb.Value.dynamic_type is supposed to work for reference and pointer
values. However, the value object in the function 'valpy_get_dynamic_type'
was being dereferenced using 'value_ind' irrespective of the value type
being TYPE_CODE_PTR or TYPE_CODE_REF. This patch fixes that to use
'coerce_ref' for TYPE_CODE_REF values.
ChangeLog:
2014-04-02 Siva Chandra Reddy <sivachandra@google.com>
* python/py-value.c (valpy_get_dynamic_type): Use coerce_ref to
dereference TYPE_CODE_REF values.
testsuite/
* gdb.python/py-value.c: Improve test case.
* gdb.python/py-value.exp: Add new test.
Comments
On Wed, Apr 2, 2014 at 1:46 PM, Siva Chandra <sivachandra@google.com> wrote:
> Original post: https://sourceware.org/ml/gdb-patches/2014-03/msg00542.html
>
> gdb.Value.dynamic_type is supposed to work for reference and pointer
> values. However, the value object in the function 'valpy_get_dynamic_type'
> was being dereferenced using 'value_ind' irrespective of the value type
> being TYPE_CODE_PTR or TYPE_CODE_REF. This patch fixes that to use
> 'coerce_ref' for TYPE_CODE_REF values.
>
> ChangeLog:
> 2014-04-02 Siva Chandra Reddy <sivachandra@google.com>
>
> * python/py-value.c (valpy_get_dynamic_type): Use coerce_ref to
> dereference TYPE_CODE_REF values.
>
> testsuite/
> * gdb.python/py-value.c: Improve test case.
> * gdb.python/py-value.exp: Add new test.
LGTM.
On Fri, Apr 4, 2014 at 12:12 PM, Doug Evans <dje@google.com> wrote:
>> ChangeLog:
>> 2014-04-02 Siva Chandra Reddy <sivachandra@google.com>
>>
>> * python/py-value.c (valpy_get_dynamic_type): Use coerce_ref to
>> dereference TYPE_CODE_REF values.
>>
>> testsuite/
>> * gdb.python/py-value.c: Improve test case.
>> * gdb.python/py-value.exp: Add new test.
>
> LGTM.
Thank you. Pushed: 7af389b892404edc76e1a60c59b354b785378fa5
@@ -309,7 +309,10 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
struct value *target;
int was_pointer = TYPE_CODE (type) == TYPE_CODE_PTR;
- target = value_ind (val);
+ if (was_pointer)
+ target = value_ind (val);
+ else
+ target = coerce_ref (val);
type = value_rtti_type (target, NULL, NULL, NULL);
if (type)
@@ -58,6 +58,8 @@ struct Derived : public Base {
};
Base *base = new Derived ();
+Derived derived;
+Base &base_ref = derived;
void ptr_ref(int*& rptr_int)
{
@@ -416,6 +416,8 @@ proc test_subscript_regression {exefile lang} {
# Likewise.
gdb_test "python print (gdb.parse_and_eval('base').dynamic_type)" \
"Derived \[*\]"
+ gdb_test "python print (gdb.parse_and_eval('base_ref').dynamic_type)" \
+ "Derived \[&\]"
# A static type case.
gdb_test "python print (gdb.parse_and_eval('5').dynamic_type)" \
"int"