[python] Fix gdb.Value.dynamic_type for reference values.
authorSiva Chandra <sivachandra@chromium.org>
Fri, 21 Mar 2014 13:42:50 +0000 (06:42 -0700)
committerSiva Chandra <sivachandra@chromium.org>
Mon, 7 Apr 2014 21:18:44 +0000 (14:18 -0700)
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:

* 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.

gdb/ChangeLog
gdb/python/py-value.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-value.c
gdb/testsuite/gdb.python/py-value.exp

index e97559311ed014bc65bac71ac06a4cf5ad42c11f..e2962c97de0643bb5f3c2baf53962845b5ab21fe 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-07  Siva Chandra Reddy  <sivachandra@google.com>
+
+       * python/py-value.c (valpy_get_dynamic_type): Use coerce_ref to
+       dereference TYPE_CODE_REF values.
+
 2014-04-07  Joel Brobecker  <brobecker@adacore.com>
 
        * darwin-nat.c (darwin_decode_message): Remove trailing '\n' at
index a118f6ca73940b71251bd99ab536e8d76b66b94d..54da67a226ee238250c2d8e3767d64883725ad7c 100644 (file)
@@ -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)
index 991c4e81485035e9d80621de2c0e55897a06c1b4..6826ec4bf65478033c152a8af27b2966f3daa7f6 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-07  Siva Chandra Reddy  <sivachandra@google.com>
+
+       * gdb.python/py-value.c: Improve test case.
+       * gdb.python/py-value.exp: Add new test.
+
 2014-04-07  David Blaikie  <dblaikie@gmail.com>
 
        * lib/compiler.c: Identify the clang compiler.
index 90dc055564e24e7b9925e24824045ed845fa0654..4d1c9c6cb50e9f7251fbe2e5ea7922e99871fc7a 100644 (file)
@@ -58,6 +58,8 @@ struct Derived : public Base {
 };
 
 Base *base = new Derived ();
+Derived derived;
+Base &base_ref = derived;
 
 void ptr_ref(int*& rptr_int)
 {
index ed332db92aa6f3076ce1a484aa62f12d23d6b93f..13433fd93379be7eaa953af983e7a3687a7981b4 100644 (file)
@@ -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"