2

I'm trying to enable xmethods as mentioned in this answer. However, info xmethod returns nothing even if I called enable xmethod beforehand:

(gdb) enable xmethod
(gdb) info xmethod
(gdb)

How can I import the xmethods into my GDB?

Note that this is not a duplicate of How is a GDB xmethod enabled?, since that question is about enabling custom xmethod definitions instead of built-in STL definitions.

J3soon
  • 3,013
  • 2
  • 29
  • 49

1 Answers1

0

You need to call register_libstdcxx_xmethods manually as mentioned in this thread. The set up is similar to pretty-printers.

More specifically, clone gcc to your home directory, and modify ~/.gdbinit: (assume your username is j3soon)

python
import sys
sys.path.insert(0, '/home/j3soon/gcc/libstdc++-v3/python')
# from libstdcxx.v6.printers import register_libstdcxx_printers
# register_libstdcxx_printers(None)
from libstdcxx.v6.xmethods import register_libstdcxx_xmethods
register_libstdcxx_xmethods(None)
end

You may also uncomment the 2 lines above to enable pretty printers. Then, relaunch gdb:

(gdb) info xmethod
Xmethods in global:
  libstdc++::shared_ptr
    get
    operator->
    operator*
    operator[]
    use_count
    unique
--Type <RET> for more, q to quit, c to continue without paging--

Note: Don't use -D_GLIBCXX_DEBUG when compiling. The xmethods seem to fail if the libcxx debug flag is used.

J3soon
  • 3,013
  • 2
  • 29
  • 49