2

I debug Chrome in gdb and I run into this problem all the time:

If I try to print a variable of certain type, GDB does not know its internals:

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

But, if I just set a breakpoint in a constructor of that class, gdb will suddenly discover that type's symbols:

(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>},

This is so annoying, I have a set of macros to set breakpoints in classes I usually print. Are there any other workarounds?

Aleksandar Totic
  • 2,557
  • 25
  • 27
  • Avoid optimizations (no -O2 flag). Also, if your code does not use current_child_.get() the compiler may get rid of it, so gdb can not find it. – Ripi2 Dec 09 '16 at 23:44
  • The code has not been optimized out, as gdb finds it after I set the breakpoint in class's constructor. It is as if for some reason gdb does not load the entire symbol table immediately. – Aleksandar Totic Dec 11 '16 at 11:29
  • 1
    Turns out that the root cause is my compile flags: using gcc --gdb-index and --split-dwarf options together results in corrupt debug information. – Aleksandar Totic May 22 '17 at 04:50

2 Answers2

2

I know one workaround. If you know the file which defines the type, you can force loading debug information of that type, by "print 'file.cc'::some_variable". If this "some_variable" actually exists or not does not really matter.

e.g.

(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)
  • This works with STL containers. Just do this trick **before** printing the container, or else GDB wont load its debug information. – Pavol Hanzel Mar 18 '20 at 21:09
1

Turns out that the root cause is my compile flags: using gcc --gdb-index and --split-dwarf options together results in corrupt debug information. – Aleksandar Totic

Armali
  • 18,255
  • 14
  • 57
  • 171