Hello!

During work on bug https://bugs.documentfoundation.org/show_bug.cgi?id=108124 I 
found dumpAsXml methods in different classes (i.e. SwNode, SwNodes, SwDoc, 
SwPaM, SwPosition, etc.)
I've created separate function which creates XML writer, calls dumpAsXml from 
some class and outputs result to debugger output. This is useful, as I can call 
such function from debugger (using .call in WinDbg) and immediately get class 
contents as xml (i.e SwNodes as xml). This function accepts only one parameter 
- pointer to class. Such pointer can be found in locals window in debugger. So 
dumping any class to debug output become easy and quick task, without rewriting 
and recompiling code.

The code itself is at the end of this message (this is draft code, written 
quickly).

I can make this code better (add cross-platform'ness as it depends on 
OutputDebugStringA and I'm not sure that it exists in any other OS than 
Windows), and submit as patch to master. Also I can add several lines here on 
how to use my function to get xml dump during debugging 
https://wiki.documentfoundation.org/Development/How_to_debug#Debugging_options

If all this makes sense and can be useful not only for me?

---------------------------- Dumper function code 
----------------------------------------

 template <typename ClassWithDumpAsXml>
void DumpXmlToDebug(ClassWithDumpAsXml& tDumpedToDebug)
{

xmlDocPtr doc;
xmlChar *xmlbuff;
int buffersize;

xmlTextWriterPtr xmlWrt = xmlNewTextWriterDoc(&doc, 0);
assert(xmlWrt);

if (xmlTextWriterStartDocument(xmlWrt, NULL, "ISO-8859-1", NULL) < 0)
OutputDebugStringA("\n\nerror in xmlTextWriterStartDocument \n\n");

tDumpedToDebug.dumpAsXml(xmlWrt);

if (xmlTextWriterEndDocument(xmlWrt) < 0)
OutputDebugStringA("\n\nerror in xmlTextWriterEndDocument \n\n");

xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);

std::stringstream dbg;
dbg << "\n !!!!!!-------- !!!!!!!\n !! Called for " << 
typeid(ClassWithDumpAsXml).name() << " !!\n " << (char *)xmlbuff << "\n\n\n";

OutputDebugStringA(dbg.str().c_str());

xmlFreeTextWriter(xmlWrt);
xmlFree(xmlbuff);
xmlFreeDoc(doc);
}


_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to