c++ - gdb类是不完整的类型,直到我在类构造函数中设置断点?

标签 c++ debugging

我在gdb中调试Chrome,并且一直遇到此问题:

如果我尝试打印某种类型的变量,则GDB不知道其内部:

(gdb) p current_child_.get()
$12 = (blink::NGBlockNode *) 0xc2f755c1830
(gdb) p *(current_child_.get())
$13 = <incomplete type>

但是,如果我只是在该类的构造函数中设置断点,则gdb会突然发现该类型的符号:
(gdb) br blink::NGBlockNode::NGBlockNode
Breakpoint 3 at 0x51db40 (4 locations)
(gdb) p *(current_child_.get())
$14 = {
  <blink::NGLayoutInputNode> = {
    <blink::GarbageCollectedFinalized<blink::NGLayoutInputNode>> = {
      <blink::GarbageCollected<blink::NGLayoutInputNode>> = {<No data fields>}, <No data fields>},

这太烦人了,我有一组宏可以在我通常打印的类中设置断点。还有其他解决方法吗?

最佳答案

我知道一种解决方法。如果知道定义该类型的文件,则可以通过“print'file.cc':: some_variable”强制加载该类型的调试信息。此“some_variable”是否实际存在并不重要。

例如

(gdb) p render_thread
$2 = (content::RenderThreadImpl *) 0x1261201f7920
(gdb) p *render_thread
$3 = <incomplete type>
(gdb) ptype render_thread
type = class content::RenderThreadImpl {
    <incomplete type>
} *
(gdb) p 'render_thread_impl.cc'::nonexist_variable
No symbol "nonexist_variable" in specified context.
(gdb) ptype render_thread
type = /* real type = content::RenderThreadImpl * */
class content::RenderThreadImpl : <snipped> {
  <snipped>
} *
(gdb) p *render_thread
$4 = (content::RenderThreadImpl) { <snipped> }
(gdb)

关于c++ - gdb类是不完整的类型,直到我在类构造函数中设置断点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41068557/

相关文章:

c++ - Qt - 没有匹配函数来调用 ‘QVariant::QVariant(MyClass&)’

C++:具有 `std::lock_guard` 的互斥量是否足以同步两个 `std::thread`?

java - 使用 Eclipse 的调试器理解 Java 递归

debugging - 带有嵌入式YouTube视频的Firebug扼流圈

c++ - 何时在 foo.cpp 中包含 foo.h

c++ - Visual Studio 2008 C++ - 远程调试 - "Could not load symbols"仅适用于主项目

c - 需要一个工具来检测 C 代码中的内存泄漏

python - 调试方法返回 None

php - firephp 输出中的彩色点是什么意思?

c++ - while循环跳过Cin