Monday, September 26, 2005

Setting breakpoints alters program behavior?

I've got a (C++, Carbon) command line tool that I'm debugging that uses libxml2 to generate XML.

Every now and then, it will print an error message "xmlEscapeEntities: char out of range" while it is processing input.

Since the input is fairly large, and I'm not sure exactly what input it is complaining about, I looked at the libxml sources, and discovered that there is a routine named "xmlGenericError" which is called to print out the error. So, when I was debugging the tool (in Xcode), I stopped at the beginning of the run, and set a breakpoint at xmlGenericError.

That certainly didn't work - now the tool crashes (about 1/2-way through the input) with an EXC_BAD_ACCESS error, deep in the bowels of libxml.

This is 100% reproducible - w/o the breakpoint the program runs, with one or two messages appearing on the console. With the breakpoint set, the program crashes.

What gives?

P.S. I once worked with a debugger that wouldn't let you set breakpoints in shared libraries until after "they had been loaded", so I set a second breakpoint in the program (after several calls to libxml had been made), and set the breakpoint on xmlGenericError at that point. No change.

Update (11/01) It turns out that "xmlGenericError" is a variable, not a function - it's a pointer to an error handling function.
Setting the breakpoint on the function made Xcode/GDB _much_ happier. I can't help but think that it could have _told me_ that I was trying to set a breakpoint on a variable, and maybe that wasn't what I meant.

Oh, well, this is Unix.

2 Comments:

At 1:34 AM, Blogger Olger Warnier said...

I did some debugging with LibXML2 and found it usefull to have formatted strings in the summary of the debugger for the xmlChar* and so on.

I have build a Xcode plugin for that that helps with the formatting. See XCodeXml2 on sourceforge. Might come in handy.

It is more of a sample project on how to create these extensions but it has some limited functionality for debugging with libxml2.

 
At 4:00 AM, Anonymous Anonymous said...

hello sir
i am in the search of a perfect name for my new theme blog for various stories of life , Discovery & many things i got your blog that you are not using if you favour me by giving your blog to me please dont delete it once it deleted it will gone for ever only provide me your access details if you like
thanks & regards
plz do a reply kainth56@gmail.com

 

Post a Comment

<< Home