gdb 没有在线程中加载漂亮的打印机?

gdb not loading pretty printers in thread?

我目前正在尝试设置一个 VSCode 项目(任何感兴趣的人的 Godot 源代码),并进行编译和调试,但是我无法使用 GDB(8.1.1 版)的漂亮打印机来工作。

在常规应用程序(一个简单的 helloworld.cpp)中,如果我编译和调试,然后获取漂亮的打印机信息,我得到了傻瓜:

    (gdb) info pretty-printer 
global pretty-printers:
  builtin
    mpx_bound128
  objfile /usr/lib/x86_64-linux-gnu/libstdc++.so.6 pretty-printers:
  libstdc++-v6 [disabled]
    __gnu_cxx::_Slist_iterator
    __gnu_cxx::__8::_Slist_iterator
    __gnu_cxx::__8::__normal_iterator
    __gnu_cxx::__8::slist
    __gnu_cxx::__normal_iterator
    __gnu_cxx::slist
    __gnu_debug::_Safe_iterator
    std::_Deque_const_iterator
    std::_Deque_iterator
    std::_Fwd_list_const_iterator
    std::_Fwd_list_iterator
    std::_List_const_iterator
    std::_List_iterator
    std::_Node_handle
    std::_Rb_tree_const_iterator
    std::_Rb_tree_iterator
    std::__8::_Deque_const_iterator
    std::__8::_Deque_iterator
    std::__8::_Fwd_list_const_iterator
    std::__8::_Fwd_list_iterator
    std::__8::_List_const_iterator
    std::__8::_List_iterator
    std::__8::_Node_handle
    std::__8::_Rb_tree_const_iterator
    std::__8::_Rb_tree_iterator
    std::__8::__cxx11::__cxx1998::list
    std::__8::__cxx11::basic_string
    (...)

然而,在我的其他项目中,当我启动调试器并尝试获取有关漂亮打印机的信息时,我得到以下信息:

(gdb) info pretty-printer 
global pretty-printers:
  builtin
    mpx_bound128
  objfile /lib/x86_64-linux-gnu/libpthread.so.0 pretty-printers:
  glibc-pthread-locks
    pthread_cond_t
    pthread_condattr_t
    pthread_mutex_t
    pthread_mutexattr_t
    pthread_rwlock_t
    pthread_rwlockattr_t

仅此而已。如果我在程序中放置一个断点并获取数据,它不会得到漂亮的打印,例如:

 = {static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0xc9115d0 "salut mec ça va ?"}, _M_string_length = 18, {
    _M_local_buf = "2[=12=]0[=12=]0[=12=]0[=12=]0[=12=]0[=12=]0[=12=]0057777[=12=]0", _M_allocated_capacity = 18}}

在开始调试我的非工作示例时,我收到以下消息:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

这提示我由于使用了线程,漂亮的打印不起作用(与我的工作示例相比)?

为了确保 gdb 使用漂亮的打印机,我创建了一个包含以下内容的 ~/.gdbinit 文件:

python
import sys
sys.path.insert(0, '/usr/share/gcc-8/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
end

好像没有什么效果。

However, in my other project, when I launch the debugger and try to get info on the pretty printers, I get the following:

这很可能是因为您的其他项目没有 link libstdc++.so.6 -- 可能是因为您使用了 -static-libstdc++.

To ensure that gdb uses the pretty printer, I have created

您的文件导入 register_libstdcxx_printers 函数,但 调用它。要实际实例化所有 libstdc++ 打印机,请添加调用:

python
import sys
sys.path.insert(0, '/usr/share/gcc-8/python')
from libstdcxx.v6.printers import register_libstdcxx_printers

register_libstdcxx_printers(None)
end