echo " struct A { virtual ~A() {} int a; }; struct B : A {}; int main() { B b; A *b1 = &b; A &b2 = b; return b1->a + b2.a; } " | g++ -g -xc++ - ~/debugger/gdb-git-i586/gdb/gdb \ -ex "set confirm off" \ -ex "file ./a.out" \ -ex "b 10" \ -ex run \ -ex "python print 'Pointer static type : %s' % gdb.parse_and_eval('b1').type" \ -ex "python print 'Pointer dynamic type : %s' % gdb.parse_and_eval('b1').dynamic_type" \ -ex "python print 'Reference static type : %s' % gdb.parse_and_eval('b2').type" \ -ex "python print 'Reference dynamic type : %s' % gdb.parse_and_eval('b2').dynamic_type" yields: Pointer static type : A * Pointer dynamic type : B * Reference static type : A & Traceback (most recent call last): File "<string>", line 1, in <module> gdb.error: Attempt to take contents of a non-pointer value. Error while executing Python code. It would be convenient to see Reference dynamic type : B & in the last line
The following seems to fix the issue for me: diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 6f67bdb..bfb7260 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -310,7 +310,11 @@ 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)
Thread is here: http://sourceware.org/ml/gdb-patches/2012-05/msg00394.html
There has been another patch on the list, see https://sourceware.org/ml/gdb-patches/2014-03/msg00542.html
Fixed since version 7.8, with this commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=7af389b892404edc76e1a60c59b354b785378fa5