How can I see a value of boost::any if I know the type with gdb
Asked Answered
A

1

8

I have a core dump and I am looking at the core dump with gdb.

I was wondering if there is a way to be able to examine the value of a boost::any value in gdb?

In the core, I had the address to the boost any and so I tried casting it to a placeholder to see if I could examine the value, but I fell short. I know that the type of the boost any is unsigned long so is there a way to view the any value knowing the type?

(gdb) print ('boost::any::placeholder')(*(('boost::any'*)0x00007f263fa27730).content)
warning: can't find linker symbol for virtual table for `boost::any::placeholder' value
warning:   found `boost::any::holder<bool>::~holder()' instead
$129 = warning: can't find linker symbol for virtual table for `boost::any::placeholder' value
warning:   found `boost::any::holder<bool>::~holder()' instead
warning: can't find linker symbol for virtual table for `boost::any::placeholder' value
warning:   found `boost::any::holder<bool>::~holder()' instead
{
  _vptr.placeholder = 0x7f2a9a662560
}

Any help with this matter would be much appreciated. Thanks!

Ancon answered 14/12, 2012 at 20:42 Comment(2)
Have you looked at the boost any source? A boost any contains a pointer to a holder, whose child type is templated on the held type, if I recall correctly. The boost any itself is not a dynamic type, it owns a dynamic type.Masseur
I wonder if one could write a gdb pretty printer for boost::any. After all, you don't even have to know the type of the content, since the vtable pointer of the held type knows what the content type is. We need more gdb pretty printers!Circumspect
F
1

boost::any has an internal class placeholder which holds the data content. Try using:

(gdb) print (*((boost::any::holder<unsigned long>*)((anyInstance).content))).held
Fealty answered 18/2, 2013 at 2:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.