Today I needed to see what happened in a Writer document. In order to do this I used gdb to explore the state of the SwDoc object. I was particularly interested in the nodes which where present, but checking the type, sub-type of all of them can be long. Then I created a small gdb define to help in this task. Here is the code, needing the functions defined on the wiki http://wiki.services.openoffice.org/wiki/Debugging#The_recommended_.gdbinit_file:

def pIndent
  set $level = $arg0
  set $iLevel = 0
  while ( $iLevel < $level )
    printf "\t"
    set $iLevel = $iLevel + 1
  end
end

def pNodes
  set $doc = $arg0
  set $size = $doc->aNodes->nSize
  set $iNodes = 0
  set $indent = 0
  while ( $iNodes++<$size && $iNodes<255 )
    set $node=$doc->aNodes[$iNodes-1]

    if ( $node->nNodeType == 1 )
        set $indent = $indent - 1
    end

    pIndent $indent

    printf "Node %d - Type: %d, SoS: %d", $iNodes - 1, $node->nNodeType, $node->pStartOfSection->nOffset

    if ( $node->nNodeType == 2 || $node->nNodeType == 6 )
        printf ", EoS: %d", $node->GetStartNode( )->pEndOfSection->nOffset
        set $indent = $indent + 1
    end

    if ( $node->IsTxtNode( ) )
        printf ", Text: "
        set $txt = $node->GetTxtNode( )->aText
        ptu $txt
    else
        printf "\n"
    end
  end
end

The values in this file are needed to better understand the ouput: http://svn.services.openoffice.org/opengrok/xref/DEV300_m40/sw/inc/ndtyp.hxx. This function has to be called with the instance of the SwDoc object as parameter.