This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ virtual methods table printing does not work


Hi,

stransky (Firefox maintainer) daily facing GDB & C++ asked me about the
missing feature of C++ virtual methods table printing.

GCC Bug to provide proper type for `_vptr.CLASS' is:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11208

as currently it is just untyped pointer to the virtual methods table:
(gdb) p base1p->'_vptr.base1' 
$5 = (int (**)(void)) 0x400810

GCC DW_AT_artificial descriptor would be IMO more appropriate although GDB
could figure it even on its own from:
 <1><2d>: Abbrev Number: 2 (DW_TAG_class_type)
    <2e>   DW_AT_name        : (indirect string, offset: 0x40): derived 
 <2><7a>: Abbrev Number: 7 (DW_TAG_subprogram)
    <7c>   DW_AT_name        : (indirect string, offset: 0xb9): func1   
    <86>   DW_AT_type        : <0x1a6>  
    <8b>   DW_AT_vtable_elem_location: 2 byte block: 10 0       (DW_OP_constu: 0)
    <8e>   DW_AT_containing_type: <0x2d>        

Minor point is even if GCC would provide the info I would prefer the naming
`_vptr$CLASS' over `_vptr.CLASS' as currently it is not much intuitive:

20	  derived var;
21	  base1 *base1p = &var;

(gdb) p base1p->_vptr.base1 
There is no member or method named _vptr.
(gdb) p base1p->'_vptr.base1' 
$5 = (int (**)(void)) 0x400810

Unconvenient printing:
(gdb) p base1p->'_vptr.base1'[0]
$6 = (int (*)(void)) 0x40065c <derived::func1()>

as this one is buggy:
(gdb) p base1p->func1
$11 = {int (base1 *)} 0x40063c <base1::func1()>

Although the call works right:
(gdb) p base1p->func1()
$12 = 6
# 6 is returned by derived::func1(), not by base1::func1().

Virtual methods table handling is currently not listed at:
http://sourceware.org/gdb/wiki/ProjectArcher

Although GDB has a large support for even RTTI but these simple usecases fail.


Regards,
Jan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]