RenderObject::showTree only dumps DOM tree and we cannot see anonymous render nodes. WebCore::externalRepresentation dumps a render tree. But it has two issues: 1. it calls RenderObject::layout() as a side effect. This may cause crash in some contexts and 2. it returns the tree as a String instead of outputting to stderr, which isn't so convenient.
So, it would be OK to add another function to dump the render tree.
Created attachment 42851 [details]
Here is the sample output of this function. Any comments will be appreciated.
(gdb) p showRenderTree(this, this->parent())
RenderView 0xe4cf1c #document 0x8872600
RenderBlock 0xe4d46c HTML 0xe4b660
RenderBody 0xeb797c BODY 0xeb7460
RenderBlock 0xeb9e6c P 0xeb7a00
RenderText 0xeb9efc #text 0xebc410 "This is the WebKit version of "
RenderInline 0xebc69c A 0xeba060
RenderText 0xebc77c #text 0xeba120 "CSS 2.1 Test Suite: dynamic changes to 'counter-increment'"
RenderText 0xebc7fc #text 0xebc7c0 "."
RenderBlock 0xebc9ac DIV 0xebc900
RenderBlock 0xebcbdc P 0xebca60
RenderText 0xebccec #text 0xebcb00 "The following two lines should be the same:"
RenderBlock 0xebb7bc DIV 0xebcde0
RenderInline 0xebbabc SPAN 0xebb8e0 CLASS=increment
- RenderInline (generated) 0xebbcec
* RenderCounter 0xebbc8c
RenderInline 0xebbffc SPAN 0xebbe20 CLASS=increment
RenderInline (generated) 0xebc0bc
RenderInline 0xebd29c SPAN 0xebd0c0 CLASS=increment
RenderInline (generated) 0xebd45c
RenderBlock 0xebd64c DIV 0xebd5a0
RenderText 0xebd72c #text 0xebd570 "1-2-new-3-4-"
RenderBlock 0xebd93c DIV 0xebd890
RenderInline 0xe1e1fc SPAN 0xec1850
RenderText 0xe672dc #text 0xec4230 "Before the dynamic change:"
RenderBR 0xe98d7c BR 0xec4260
Comment on attachment 42851 [details]
I'm not sure what "outputted" is supposed to mean. I guess it's printedCharacters? Can it just default to 0, with = 0?
Created attachment 44009 [details]
Thanks for the review! I really want to use this function for my debugging.
> I'm not sure what "outputted" is supposed to mean. I guess it's
Yes, and thanks for the comment, printedCharacters is definitely better naming. I changed the name.
> Can it just default to 0, with = 0?
Unfortunately, gdb cannot handle default parameters. If we make it a default parameter, we always need to pass 0 for RenderObject::showRenderObject when debugging with GDB. That's why I created two overloaded functions.
Also, I've noticed we may call showRenderObject() for a NULL RenderObject while we are debugging. I added NULL checks for this pointers. This looks a bit weird to check if this pointer is NULL. If you don't like this, I may make showRenderObject a global function.
style-queue ran check-webkit-style on attachment 44009 [details] without any errors.
Comment on attachment 44009 [details]
> + for (const WebCore::RenderObject* child = firstChild(); child; child = child->nextSibling())
I don't think the WebCore prefix is needed here.
> I don't think the WebCore prefix is needed here.
Fixed and landed, thanks!